diff options
author | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-08-09 14:14:50 +0200 |
---|---|---|
committer | Tobias Jahnke <tjahnk@users.noreply.github.com> | 2017-08-16 16:00:50 +0200 |
commit | e94c8800c515dc64a7d7ae275e607e23591b8498 (patch) | |
tree | 9c5fd8fc819e13b57061b62ffc6e0b1dccb1b9e7 /HAL-afb/hal-most-unicens | |
parent | 1d36fcd6461a106711725642e7dc6d89c3473b3e (diff) |
introduced automatic connection/start of unicens2-binding
Diffstat (limited to 'HAL-afb/hal-most-unicens')
-rw-r--r-- | HAL-afb/hal-most-unicens/hal_most_unicens.c | 120 |
1 files changed, 110 insertions, 10 deletions
diff --git a/HAL-afb/hal-most-unicens/hal_most_unicens.c b/HAL-afb/hal-most-unicens/hal_most_unicens.c index 3ab7ace..a1a1e66 100644 --- a/HAL-afb/hal-most-unicens/hal_most_unicens.c +++ b/HAL-afb/hal-most-unicens/hal_most_unicens.c @@ -19,6 +19,7 @@ #include "hal-interface.h" #include "audio-interface.h" #include "wrap-json.h" +#include "string.h" static int master_volume; static json_bool master_switch; @@ -64,13 +65,13 @@ void unicens_pcm_vol_cb(halCtlsEnumT tag, alsaHalCtlMapT *control, void* handle, /* declare ALSA mixer controls */ STATIC alsaHalMapT alsaHalMap[]= { { .tag=Master_Playback_Volume, .cb={.callback=unicens_master_vol_cb, .handle=&master_volume}, .info="Sets master playback volume", - .ctl={.numid=0, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=1, .minval=0, .maxval=100, .step=1, .value=50, .name="Master Playback Volume"} + .ctl={.numid=1, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=1, .minval=0, .maxval=100, .step=1, .value=50, .name="Master Playback Volume"} }, - { .tag=Master_OnOff_Switch, .cb={.callback=unicens_master_switch_cb, .handle=&master_switch}, .info="Sets master playback switch", - .ctl={.numid=0, .type=SND_CTL_ELEM_TYPE_BOOLEAN, .count=1, .minval=0, .maxval=1, .step=1, .value=1, .name="Master Playback Switch"} - }, + /*{ .tag=Master_OnOff_Switch, .cb={.callback=unicens_master_switch_cb, .handle=&master_switch}, .info="Sets master playback switch", + .ctl={.numid=2, .type=SND_CTL_ELEM_TYPE_BOOLEAN, .count=1, .minval=0, .maxval=1, .step=1, .value=1, .name="Master Playback Switch"} + },*/ { .tag=PCM_Playback_Volume, .cb={.callback=unicens_pcm_vol_cb, .handle=&pcm_volume}, .info="Sets PCM playback volume", - .ctl={.numid=0, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=6, .minval=0, .maxval=100, .step=1, .value=100, .name="PCM Playback Volume"} + .ctl={.numid=3, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=6, .minval=0, .maxval=100, .step=1, .value=100, .name="PCM Playback Volume"} }, { .tag=EndHalCrlTag} /* marker for end of the array */ } ; @@ -83,18 +84,117 @@ STATIC alsaHalSndCardT alsaHalSndCard = { .volumeCB = NULL, /* use default volume normalization function */ }; -STATIC int sndServiceInit () { +STATIC int unicens_start_binding() { + + json_object *j_response, *j_query = NULL; int err; - AFB_DEBUG ("Initializing HAL-MOST-UNICENS-BINDING"); - err = halServiceInit (afbBindingV2.api, &alsaHalSndCard); + /* Build an empty JSON object */ + err = wrap_json_pack(&j_query, "{}"); + if (err) { + AFB_ERROR("Failed to create subscribe json object"); + goto OnErrorExit; + } + + err = afb_service_call_sync("UNICENS", "subscribe", j_query, &j_response); + if (err) { + AFB_ERROR("Fail subscribing to UNICENS events"); + goto OnErrorExit; + } + else { + AFB_NOTICE("Subscribed to UNICENS events, res=%s", json_object_to_json_string(j_response)); + json_object_put(j_response); + } + json_object_put(j_query); +#if 0 + /* Build JSON object to retrieve UNICENS configuration */ + err = wrap_json_pack(&j_query, "{}"); + if (err) { + AFB_ERROR("Failed to create listconfig json object"); + goto OnErrorExit; + } + + err = afb_service_call_sync("UNICENS", "listconfig", j_query, &j_response); + if (err) { + AFB_ERROR("Failed to call listconfig"); + goto OnErrorExit; + } + else { + AFB_NOTICE("UNICENS listconfig result, res=%s", json_object_to_json_string(j_response)); + json_object_put(j_response); + } + json_object_put(j_query); +#endif + + /* Build JSON object to initialize UNICENS */ + err = wrap_json_pack(&j_query, "{s:s}", "filename", "/home/agluser/DEVELOPMENT/AGL/BINDING/unicens2-binding/data/config_multichannel_audio_kit.xml"); + if (err) { + AFB_ERROR("Failed to create initialize json object"); + goto OnErrorExit; + } + err = afb_service_call_sync("UNICENS", "initialise", j_query, &j_response); + if (err) { + AFB_ERROR("Failed to initialize UNICENS"); + goto OnErrorExit; + } + else { + AFB_NOTICE("Initialized UNICENS, res=%s", json_object_to_json_string(j_response)); + json_object_put(j_response); + } + json_object_put(j_query); + + + j_query = NULL; + OnErrorExit: + if (j_query) + json_object_put(j_query); + return NULL; +} + +STATIC int unicens_service_init() { + int err; + AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING"); + + err = halServiceInit(afbBindingV2.api, &alsaHalSndCard); + if (err) { + AFB_ERROR("Cannot initialize hal-most-unicens binding."); + goto OnErrorExit; + } + + err= afb_daemon_require_api("UNICENS", 1); + if (err) { + AFB_ERROR("UNICENS is missing or not initialized"); + goto OnErrorExit; + } + + unicens_start_binding(); + + +OnErrorExit: + AFB_NOTICE("Initializing HAL-MOST-UNICENS-BINDING done.."); return err; } +// This receive all event this binding subscribe to +PUBLIC void unicens_event_cb(const char *evtname, json_object *j_event) { + + if (strncmp(evtname, "alsacore/", 9) == 0) { + halServiceEvent(evtname, j_event); + return; + } + + if (strncmp(evtname, "UNICENS/", 8) == 0) { + AFB_NOTICE("unicens_event_cb: evtname=%s [msg=%s]", evtname, json_object_get_string(j_event)); + return; + } + + AFB_NOTICE("unicens_event_cb: UNHANDLED EVENT, evtname=%s [msg=%s]", evtname, json_object_get_string(j_event)); +} + /* API prefix should be unique for each snd card */ PUBLIC const struct afb_binding_v2 afbBindingV2 = { .api = "hal-most-unicens", - .init = sndServiceInit, + .init = unicens_service_init, .verbs = halServiceApi, - .onevent = halServiceEvent, + .onevent = unicens_event_cb, }; |