diff options
author | Tobias Jahnke <tobias.jahnke@microchip.com> | 2018-11-20 14:59:48 +0100 |
---|---|---|
committer | Tobias Jahnke <tobias.jahnke@microchip.com> | 2018-12-18 13:01:13 +0100 |
commit | eecae0a0a32d5783424d37515c8522661471cdfe (patch) | |
tree | ee452402e228e8ad41297fd77f99364e17b8bb40 /plugin | |
parent | 3b4582fd7bbac25c1b8577d76b538e4e3fe8978c (diff) |
hal-unicens: code cosmetics, remove unused code
Bug-AGL: SPEC-1505
Signed-off-by: Tobias Jahnke <tobias.jahnke@microchip.com>
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/most_unicens.c | 286 |
1 files changed, 101 insertions, 185 deletions
diff --git a/plugin/most_unicens.c b/plugin/most_unicens.c index 610a9f9..1e03545 100644 --- a/plugin/most_unicens.c +++ b/plugin/most_unicens.c @@ -39,221 +39,137 @@ AFB_ApiT unicensHalApiHandle; static uint8_t initialized = 0; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + // Call at initialization time CTLP_ONLOAD(plugin, callbacks) { - pthread_mutex_lock(&mutex); - unicensHalApiHandle = plugin->api; - AFB_ApiNotice(unicensHalApiHandle, "4A-HAL-UNICENS: Plugin Register: uid='%s' 'info='%s'", plugin->uid, plugin->info); - pthread_mutex_unlock(&mutex); - - return 0; + pthread_mutex_lock(&mutex); + unicensHalApiHandle = plugin->api; + AFB_ApiNotice(unicensHalApiHandle, "4A-HAL-UNICENS: Plugin Register: uid='%s' 'info='%s'", plugin->uid, plugin->info); + pthread_mutex_unlock(&mutex); + + return 0; } -CTLP_CAPI(MasterVol, source, argsJ, queryJ) + +/* initializes ALSA sound card, UNICENS API */ +CTLP_CAPI(Init, source, argsJ, queryJ) { - int master_volume; - json_object *valueJ; - int err = 0; - - pthread_mutex_lock(&mutex); - - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: MasterVolume=%s", json_object_to_json_string(queryJ)); - - if(! initialized) { - AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set master volume, value=%s", __func__, json_object_get_string(queryJ)); - err = -1; - goto Abort_Exit; - } - - if(! json_object_is_type(queryJ, json_type_array) || json_object_array_length(queryJ) <= 0) { - AFB_ApiError(source->api, "%s: invalid json (should be a non empty json array) value=%s", __func__, json_object_get_string(queryJ)); - err = -2; - goto Abort_Exit; - } - - valueJ = json_object_array_get_idx(queryJ, 0); - if(! json_object_is_type(valueJ, json_type_int)) { - AFB_ApiError(source->api, "%s: invalid json (should be an array of int) value=%s", __func__, json_object_get_string(queryJ)); - err = -3; - goto Abort_Exit; - } - - master_volume = json_object_get_int(valueJ); - wrap_volume_master(source->api, master_volume); - -Abort_Exit: - pthread_mutex_unlock(&mutex); + int err = 0; + int pcm_volume[PCM_MAX_CHANNELS] = { 100, 100, 100, 100, 100, 100 }; - return err; -} + pthread_mutex_lock(&mutex); + AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Initializing 4a plugin"); -#if 0 -CTLP_CAPI(MasterSwitch, source, argsJ, queryJ) -{ - json_bool master_switch; - json_object *valueJ; - int err = 0; - - pthread_mutex_lock(&mutex); - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: MasterSwitch=%s", json_object_to_json_string(queryJ)); - - if(! initialized) { - AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set master switch, value=%s", __func__, json_object_get_string(queryJ)); - err = -1; - goto Abort_Exit; - } - - if(! json_object_is_type(queryJ, json_type_array) || json_object_array_length(queryJ) <= 0) { - AFB_ApiError(source->api, "%s: invalid json (should be a non empty json array) value=%s", __func__, json_object_get_string(queryJ)); - err = -2; - goto Abort_Exit; - } - - // In case if alsa doesn't return a proper json boolean - valueJ = json_object_array_get_idx(queryJ, 0); - switch(json_object_get_type(valueJ)) { - case json_type_boolean: - master_switch = json_object_get_boolean(valueJ); - break; - - case json_type_int: - master_switch = json_object_get_int(valueJ); - break; - - default: - AFB_ApiError(source->api, "%s: invalid json (should be an array of boolean/int) value=%s", __func__, json_object_get_string(queryJ)); - err = -3; - goto Abort_Exit; - } - - // TBD: implement pause action for Unicens - AFB_ApiWarning(source->api, "%s: Try to set master switch to %i, but function is not implemented", __func__, (int) master_switch); + if((err = wrap_volume_init())) { + AFB_ApiError(source->api, "Failed to initialize wrapper for volume library"); + goto Abort_Exit; + } + + if((err = wrap_ucs_subscribe_sync(source->api))) { + AFB_ApiError(source->api, "Failed to subscribe to UNICENS binding"); + goto Abort_Exit; + } + + // Set output volume to pre-defined level in order to + // avoid muted volume to be persistent after boot. + //wrap_volume_master(source->api, 80); + wrap_volume_pcm(source->api, pcm_volume, PCM_MAX_CHANNELS); + initialized = 1; Abort_Exit: - pthread_mutex_unlock(&mutex); - - return err; + pthread_mutex_unlock(&mutex); + AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Initializing plugin done, err=%d", err); + return err; } -#endif -CTLP_CAPI(PCMVol, source, argsJ, queryJ) -{ - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: PCMVolume=%s", json_object_to_json_string(queryJ)); - return 0; -} -#if 0 -// PCM volume not provided yet -CTLP_CAPI(PCMVol, source, argsJ, queryJ) +CTLP_CAPI(MasterVol, source, argsJ, queryJ) { - int idx; - int pcm_volume[PCM_MAX_CHANNELS]; - json_object *valueJ; + int master_volume; + json_object *valueJ; + int err = 0; - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: PCMVolume=%s", json_object_to_json_string(queryJ)); + pthread_mutex_lock(&mutex); - if(! initialized) { - AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set PCM volume, value=%s", __func__, json_object_get_string(queryJ)); - return -1; - } + AFB_ApiNotice(source->api, "4A-HAL-UNICENS: MasterVolume=%s", json_object_to_json_string(queryJ)); - if(! json_object_is_type(queryJ, json_type_array) || json_object_array_length(queryJ) <= 0) { - AFB_ApiError(source->api, "%s: invalid json (should be a non empty json array) value=%s", __func__, json_object_get_string(queryJ)); - return -1; - } + if(! initialized) { + AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set master volume, value=%s", __func__, json_object_get_string(queryJ)); + err = -1; + goto Abort_Exit; + } - for(idx = 0; idx < json_object_array_length(queryJ); idx++) { - valueJ = json_object_array_get_idx(queryJ, idx); - if(! json_object_is_type(valueJ, json_type_int)) { - AFB_ApiError(source->api, "%s: invalid json (should be an array of int) value=%s", __func__, json_object_get_string(queryJ)); - return -2; - } + if(! json_object_is_type(queryJ, json_type_array) || json_object_array_length(queryJ) <= 0) { + AFB_ApiError(source->api, "%s: invalid json (should be a non empty json array) value=%s", __func__, json_object_get_string(queryJ)); + err = -2; + goto Abort_Exit; + } - pcm_volume[idx] = json_object_get_int(valueJ); - } + valueJ = json_object_array_get_idx(queryJ, 0); + if(! json_object_is_type(valueJ, json_type_int)) { + AFB_ApiError(source->api, "%s: invalid json (should be an array of int) value=%s", __func__, json_object_get_string(queryJ)); + err = -3; + goto Abort_Exit; + } - // If control only has one value, then replicate the first value - for(idx = idx; idx < 6; idx ++) - pcm_volume[idx] = pcm_volume[0]; + master_volume = json_object_get_int(valueJ); + wrap_volume_master(source->api, master_volume); - wrap_volume_pcm(source->api, pcm_volume, PCM_MAX_CHANNELS); +Abort_Exit: + pthread_mutex_unlock(&mutex); - return 0; + return err; } -#endif -/* initializes ALSA sound card, UNICENS API */ -CTLP_CAPI(Init, source, argsJ, queryJ) + +CTLP_CAPI(PCMVol, source, argsJ, queryJ) { - int err = 0; - int pcm_volume[PCM_MAX_CHANNELS] = { 100, 100, 100, 100, 100, 100 }; - - pthread_mutex_lock(&mutex); - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Initializing 4a plugin"); - - if((err = wrap_volume_init())) { - AFB_ApiError(source->api, "Failed to initialize wrapper for volume library"); - goto Abort_Exit; - } - - if((err = wrap_ucs_subscribe_sync(source->api))) { - AFB_ApiError(source->api, "Failed to subscribe to UNICENS binding"); - goto Abort_Exit; - } - - // Set output volume to pre-defined level in order to - // avoid muted volume to be persistent after boot. - //wrap_volume_master(source->api, 80); - wrap_volume_pcm(source->api, pcm_volume, PCM_MAX_CHANNELS); - initialized = 1; - -Abort_Exit: - pthread_mutex_unlock(&mutex); - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Initializing plugin done, err=%d", err); - return err; + AFB_ApiNotice(source->api, "4A-HAL-UNICENS: PCMVolume=%s", json_object_to_json_string(queryJ)); + return 0; } + // This receive UNICENS events CTLP_CAPI(Events, source, argsJ, queryJ) { - uint16_t node = 0U; - bool available = false; - int err = 0; - json_object *j_tmp = NULL; - - pthread_mutex_lock(&mutex); - - if (initialized == 0) { - AFB_ApiError(source->api, "4A-HAL-UNICENS: Not initialized while receiving event query=%s", json_object_to_json_string(queryJ)); - err = 0; - goto Abort_Exit; - } - - if (json_object_object_get_ex(queryJ, "node", &j_tmp)) { - node = (uint16_t)json_object_get_int(j_tmp); - } - else { - err = -1; - } - - if (json_object_object_get_ex(queryJ, "available", &j_tmp)) { - available = (bool)json_object_get_boolean(j_tmp); - } - else { - err = -2; - } - - if(err == 0) { - AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Node-Availability: node=0x%03X, available=%d", node, available); - wrap_volume_node_avail(source->api, node, available); - } - else { - AFB_ApiError(source->api, "4A-HAL-UNICENS: Failed to parse events query=%s", json_object_to_json_string(queryJ)); - } - + uint16_t node = 0U; + bool available = false; + int err = 0; + json_object *j_tmp = NULL; + + pthread_mutex_lock(&mutex); + + if (initialized == 0) { + AFB_ApiError(source->api, "4A-HAL-UNICENS: Not initialized while receiving event query=%s", json_object_to_json_string(queryJ)); + err = 0; + goto Abort_Exit; + } + + if (json_object_object_get_ex(queryJ, "node", &j_tmp)) { + node = (uint16_t)json_object_get_int(j_tmp); + } + else { + err = -1; + } + + if (json_object_object_get_ex(queryJ, "available", &j_tmp)) { + available = (bool)json_object_get_boolean(j_tmp); + } + else { + err = -2; + } + + if(err == 0) { + AFB_ApiNotice(source->api, "4A-HAL-UNICENS: Node-Availability: node=0x%03X, available=%d", node, available); + wrap_volume_node_avail(source->api, node, available); + } + else { + AFB_ApiError(source->api, "4A-HAL-UNICENS: Failed to parse events query=%s", json_object_to_json_string(queryJ)); + } + Abort_Exit: - pthread_mutex_unlock(&mutex); + pthread_mutex_unlock(&mutex); - return err; + return err; } |