diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-04-18 16:25:24 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-05-24 16:28:53 +0200 |
commit | 9cb51ee3170262d8720d47708f483b4b38fd38e6 (patch) | |
tree | f4bf3940f3da01dd8e5f141becb97f96b074c33c | |
parent | be68761ad6b10555ce410f1f0e42976014f7b259 (diff) |
Normalize coding style among repository
Normalize coding style among project :
- When possible, set the variable outside test in 'if' statement.
- Remove fanciful returns.
- Split too long lines.
- Remove unnecessary '\n' into prints.
- Normalize use of tabulation.
- Use 'afb_req_fail' instead of 'afb_req_fail_f' when possible.
- Add some error prints.
BUG-AGL: SPEC-2329
Change-Id: I14867e05e02b4c4c0389108c335fec2d2aa27495
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | lib/4a-hal-utilities/4a-hal-utilities-data.c | 20 | ||||
-rw-r--r-- | lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c | 24 | ||||
-rw-r--r-- | plugins/lib/bluealsa/hal-bluealsa-transports.c | 4 | ||||
-rw-r--r-- | plugins/lib/bluealsa/hal-bluealsa.c | 313 | ||||
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager-cb.c | 19 | ||||
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager.c | 18 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-alsacore-link.c | 33 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-api-loader.c | 34 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-cb.c | 95 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-mixer-link.c | 22 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-value-handler.c | 26 |
11 files changed, 321 insertions, 287 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c index 314190f..26bbd23 100644 --- a/lib/4a-hal-utilities/4a-hal-utilities-data.c +++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c @@ -96,16 +96,14 @@ int8_t HalUtlRemoveSelectedMixerData(struct InternalHalMixerData **mixerDataList int64_t HalUtlRemoveAllMixerData(struct InternalHalMixerData **mixerDataList) { - int8_t ret; int64_t mixerDataRemoved = 0; if(! mixerDataList) return -1; while(*mixerDataList) { - ret = HalUtlRemoveSelectedMixerData(mixerDataList, *mixerDataList); - if(ret) - return (int64_t) ret; + if(HalUtlRemoveSelectedMixerData(mixerDataList, *mixerDataList)) + return -2; mixerDataRemoved++; } @@ -134,11 +132,10 @@ struct InternalHalMixerData *HalUtlSearchMixerDataByProperties(struct InternalHa { struct InternalHalMixerData *currentMixerData; - if(! mixerDataList || ! verb) + if(! mixerDataList || ! *mixerDataList || ! verb) return NULL; currentMixerData = *mixerDataList; - while(currentMixerData) { if((! strcmp(verb, currentMixerData->verb)) && (! strcmp(verbToCall, currentMixerData->verbToCall)) && @@ -152,7 +149,7 @@ struct InternalHalMixerData *HalUtlSearchMixerDataByProperties(struct InternalHa } /******************************************************************************* - * Hal data handling functions * + * Hal data handling functions * ******************************************************************************/ struct HalData *HalUtlAddHalToHalList(struct HalData **halDataList) @@ -233,16 +230,14 @@ int8_t HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalD int64_t HalUtlRemoveAllHalFromList(struct HalData **halDataList) { - int8_t ret; int64_t halRemoved = 0; if(! halDataList) return -1; while(*halDataList) { - ret = HalUtlRemoveSelectedHalFromList(halDataList, *halDataList); - if(ret) - return (int64_t) ret; + if(HalUtlRemoveSelectedHalFromList(halDataList, *halDataList)) + return -2; halRemoved++; } @@ -259,7 +254,6 @@ int64_t HalUtlGetNumberOfHalInList(struct HalData **halDataList) return -1; currentHalData = *halDataList; - while(currentHalData) { currentHalData = currentHalData->next; numberOfHal++; @@ -276,7 +270,6 @@ struct HalData *HalUtlSearchHalDataByApiName(struct HalData **halDataList, char return NULL; currentHalData = *halDataList; - while(currentHalData) { if(! strcmp(apiName, currentHalData->apiName)) return currentHalData; @@ -295,7 +288,6 @@ struct HalData *HalUtlSearchReadyHalDataByCardId(struct HalData **halDataList, i return NULL; currentHalData = *halDataList; - while(currentHalData) { if(currentHalData->status == HAL_STATUS_READY && currentHalData->sndCardId == cardId) return currentHalData; diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c index ed06b27..2960537 100644 --- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c +++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c @@ -45,23 +45,26 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType) json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL; - if(! (apiHandle = afb_req_get_api(request))) { - afb_req_fail(request, "api_handle", "Can't get current hal controller api handle"); + apiHandle = afb_req_get_api(request); + if(! apiHandle) { + afb_req_fail(request, "api_handle", "Can't get current hal api handle"); return; } - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { - afb_req_fail(request, "hal_controller_config", "Can't get current hal controller config"); + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { + afb_req_fail(request, "hal_controller_config", "Can't get current internal hal controller config"); return; } currentHalData = (struct HalData *) getExternalData(ctrlConfig); if(! currentHalData) { - afb_req_fail(request, "hal_controller_data", "Can't get current hal controller data"); + afb_req_fail(request, "hal_controller_data", "Can't get current internal hal controller data"); return; } - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { afb_req_fail(request, "request_json", "Can't get request json"); return; } @@ -261,14 +264,15 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap createdStreamData->verbToCall = strdup(verbToCall); createdStreamData->streamCardId = strdup(streamCardId); - if((! createdStreamData->verb) || - (! createdStreamData->verbToCall) || - (! createdStreamData->streamCardId)) { + if(! createdStreamData->verb || + ! createdStreamData->verbToCall || + ! createdStreamData->streamCardId) { HalUtlRemoveSelectedMixerData(¤tHalData->internalHalData->streamsData, createdStreamData); return NULL; } - if(! (createdStreamData->event = afb_api_make_event(apiHandle, createdStreamData->verb))) { + createdStreamData->event = afb_api_make_event(apiHandle, createdStreamData->verb); + if(! createdStreamData->event) { HalUtlRemoveSelectedMixerData(¤tHalData->internalHalData->streamsData, createdStreamData); return NULL; } diff --git a/plugins/lib/bluealsa/hal-bluealsa-transports.c b/plugins/lib/bluealsa/hal-bluealsa-transports.c index b528212..341fb6b 100644 --- a/plugins/lib/bluealsa/hal-bluealsa-transports.c +++ b/plugins/lib/bluealsa/hal-bluealsa-transports.c @@ -107,8 +107,8 @@ int halBlueAlsaTransportUpdate( char transportS[HAL_BLUEALSA_TRANSPORT_LEN_MAX]; AFB_API_INFO(watch->plugin->api, - "Unregister transport %s", - halBlueAlsaTransportAsString(transportS, HAL_BLUEALSA_TRANSPORT_LEN_MAX, &transport->transport)); + "Unregister transport %s", + halBlueAlsaTransportAsString(transportS, HAL_BLUEALSA_TRANSPORT_LEN_MAX, &transport->transport)); cds_list_del(&transport->list); if (destructor) { diff --git a/plugins/lib/bluealsa/hal-bluealsa.c b/plugins/lib/bluealsa/hal-bluealsa.c index 58c4b54..efce322 100644 --- a/plugins/lib/bluealsa/hal-bluealsa.c +++ b/plugins/lib/bluealsa/hal-bluealsa.c @@ -70,7 +70,8 @@ CTLP_INIT(plugin, callbacks) CtlConfigT *ctrlConfig; struct HalData *currentHalData; - if (!(ctrlConfig = (CtlConfigT *) afb_api_get_userdata(plugin->api))) { + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(plugin->api); + if (!ctrlConfig) { AFB_API_ERROR(plugin->api, "Can't get current internal hal controller config"); goto fail; } @@ -83,7 +84,7 @@ CTLP_INIT(plugin, callbacks) if (currentHalData->status != HAL_STATUS_AVAILABLE) { AFB_API_WARNING(plugin->api, - "Controller initialization of %s plugin cannot be done because hal is not ready to be used", HAL_BLUEALSA_PLUGIN_NAME); + "Controller initialization of %s plugin cannot be done because hal is not ready to be used", HAL_BLUEALSA_PLUGIN_NAME); goto done; } @@ -127,17 +128,17 @@ CTLP_CAPI(init, source, argsJ, queryJ) int error; /* - * "params": { - "sco": { - "mic": "2CH-GENERIC-USB", - "zone": "full-stereo", - "delayms": 300 - }, - "a2dp": { - "zone": "full-stereo", - "delayms": 1000 - } - } + "params": { + "sco": { + "mic": "2CH-GENERIC-USB", + "zone": "full-stereo", + "delayms": 300 + }, + "a2dp": { + "zone": "full-stereo", + "delayms": 1000 + } + } */ json_object * scoParamsJ = NULL; @@ -184,7 +185,7 @@ CTLP_CAPI(init, source, argsJ, queryJ) return 0; fail: - return -1; + return -1; } @@ -228,104 +229,100 @@ done: * * A2DP Case: * - * { - "uid":"a2dp_F6:32:15:2A:80:70", - "captures": - { - "uid":"a2dp_listen_capture", - "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp", - "source" : { - "channels": [ - { - "uid": "a2dp-right", - "port": 0 - }, - { - "uid": "a2dp-left", - "port": 1 - } - ] - } - }, - "streams": - { - "uid" : "a2dp_listen_stream", - "source":"a2dp_listen_capture", - "zone": "full-stereo" - } - } +{ + "uid":"a2dp_F6:32:15:2A:80:70", + "captures": { + "uid":"a2dp_listen_capture", + "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=a2dp", + "source" : { + "channels": [ + { + "uid": "a2dp-right", + "port": 0 + }, + { + "uid": "a2dp-left", + "port": 1 + } + ] + } + }, + "streams": { + "uid" : "a2dp_listen_stream", + "source":"a2dp_listen_capture", + "zone": "full-stereo" + } +} * *----------------------------------------------------------------------------------- * * SCO Case: * - * { - "uid":"sco_F6:32:15:2A:80:70",", - "captures": - { - "uid":"sco_listen_capture", - "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco", - "source" : { - "channels": [ - { - "uid": "sco-right", - "port": 0 - }, - { - "uid": "sco-left", - "port": 1 - } - ] - } - }, - "playbacks" : - { - "uid"="sco_talk_playback", - "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco", - "params": { - "rate": 44100, - "format": "S16_LE", - }, - "sink": { - "channels": [ - { - "uid": "sco-mono" - } - ] - } - }, - "zones" : [ - { - "uid": "sco_talk_zone", - "sink": [ - { - "target": "sco-mono", - "channel": 0, - "volume": 0.5 - }, - { - "target": "sco-mono", - "channel": 1, - "volume": 0.5 - } - ] - } - ] , - "streams": [ - { - "uid" : "sco_listen_stream", - "source":"sco_listen_capture", - "zone": "full-stereo", - "delayms": 300 - }, - { - "uid" : "sco_talk_stream", - "source": "2CH-GENERIC-USB", - "zone": "sco_talk_zone", - "delayms": 300 - } - ] - } +{ + "uid":"sco_F6:32:15:2A:80:70",", + "captures": { + "uid":"sco_listen_capture", + "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco", + "source" : { + "channels": [ + { + "uid": "sco-right", + "port": 0 + }, + { + "uid": "sco-left", + "port": 1 + } + ] + } + }, + "playbacks" : { + "uid"="sco_talk_playback", + "pcmplug_params" : "bluealsa:HCI=hci0,DEV=F6:32:15:2A:80:70,PROFILE=sco", + "params": { + "rate": 44100, + "format": "S16_LE", + }, + "sink": { + "channels": [ + { + "uid": "sco-mono" + } + ] + } + }, + "zones" : [ + { + "uid": "sco_talk_zone", + "sink": [ + { + "target": "sco-mono", + "channel": 0, + "volume": 0.5 + }, + { + "target": "sco-mono", + "channel": 1, + "volume": 0.5 + } + ] + } + ], + "streams": [ + { + "uid" : "sco_listen_stream", + "source":"sco_listen_capture", + "zone": "full-stereo", + "delayms": 300 + }, + { + "uid" : "sco_talk_stream", + "source": "2CH-GENERIC-USB", + "zone": "sco_talk_zone", + "delayms": 300 + } + ] +} * * */ @@ -566,7 +563,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) { json_object_object_add(streamJ, "uid", json_object_new_string(streamS)); json_object_object_add(streamJ, "source", json_object_new_string(captureS)); json_object_object_add(streamJ, "zone", json_object_new_string(playbackZoneS)); - if (delayms != 0) { + if (delayms) { json_object_object_add(streamJ, "delayms", json_object_new_int(delayms)); } @@ -582,7 +579,7 @@ static int halBlueAlsaAttachTransportStreams(bluealsa_transport_t * transport) { json_object_object_add(streamJ, "uid", json_object_new_string(streamS)); json_object_object_add(streamJ, "source", json_object_new_string(pluginData->sco.mic)); json_object_object_add(streamJ, "zone", json_object_new_string(SCO_TALK_ZONE)); - if (delayms != 0) + if (delayms) json_object_object_add(streamJ, "delayms", json_object_new_int(delayms)); json_object_array_add(streamsJ, streamJ); } @@ -614,7 +611,7 @@ static int halBluezAlsaRemoveTransportStream(bluealsa_transport_t * transport) { json_object* requestJ = NULL; AFB_API_INFO(plugin->api, "Call transaction detach verb %s", transport->transactionUidS); - if (transport->transactionUidS == NULL) + if (!transport->transactionUidS) goto fail; requestJ = json_object_new_object(); @@ -642,7 +639,8 @@ static int halBlueAlsaFetchTransports(bluealsa_watch * watch) { AFB_API_DEBUG(plugin->api, "Fetching available transports of interface %s", watch->interface); - if ((nbTransports = bluealsa_get_transports(watch->fd, &transports)) == -1) { + nbTransports = bluealsa_get_transports(watch->fd, &transports); + if (nbTransports == -1) { AFB_API_ERROR(plugin->api, "Couldn't get transports: %s", strerror(errno)); goto done; } @@ -676,7 +674,7 @@ static int halBlueAlsaFetchTransports(bluealsa_watch * watch) { AFB_API_INFO(plugin->api, "Registering transport type %s, dev %s", typeS, addr); transport = halBlueAlsaTransportsAdd(watch, transport_list, ba_transport); - if (transport == NULL) { + if (!transport) { AFB_API_ERROR(plugin->api, "Failed to register this transport"); goto done; } @@ -738,47 +736,49 @@ static int halBlueAlsaUnregister(CtlPluginT * plugin, const char * dbus_name) { static int halBlueAlsaRegister(CtlPluginT* plugin, const char * dbus_name) { int ret; - sd_event * sdLoop; - sd_event_source * evtsrc; + sd_event * sdLoop; + sd_event_source * evtsrc; - const char * interface = dbus_name + strlen(BLUEZALSA_DBUS_NAME_PREFIX) +1 ; + const char * interface = dbus_name + strlen(BLUEZALSA_DBUS_NAME_PREFIX) +1 ; - sdLoop = afb_api_get_event_loop(plugin->api); + sdLoop = afb_api_get_event_loop(plugin->api); - enum ba_event transport_mask = BA_EVENT_TRANSPORT_ADDED | - BA_EVENT_TRANSPORT_CHANGED | - BA_EVENT_TRANSPORT_REMOVED; + enum ba_event transport_mask = BA_EVENT_TRANSPORT_ADDED | + BA_EVENT_TRANSPORT_CHANGED | + BA_EVENT_TRANSPORT_REMOVED; - bluealsa_watch * watch = (bluealsa_watch *)malloc(sizeof(bluealsa_watch)); - if (watch == NULL) - goto fail; + bluealsa_watch * watch = (bluealsa_watch *)malloc(sizeof(bluealsa_watch)); + if (!watch) + goto fail; - watch->interface = strdup(interface); - if (!watch->interface) { - AFB_API_ERROR(plugin->api, "%s: Insufficient memory", __func__); + watch->interface = strdup(interface); + if (!watch->interface) { + AFB_API_ERROR(plugin->api, "%s: Insufficient memory", __func__); goto fail; } - watch->plugin = plugin; + watch->plugin = plugin; - if ((watch->fd = bluealsa_open(interface)) == -1) { - AFB_API_ERROR(plugin->api, "BlueALSA connection failed: %s", strerror(errno)); - goto fail; - } + watch->fd = bluealsa_open(interface); + if (watch->fd == -1) { + AFB_API_ERROR(plugin->api, "BlueALSA connection failed: %s", strerror(errno)); + goto fail; + } halBlueAlsaFetchTransports(watch); - if (bluealsa_event_subscribe(watch->fd, transport_mask) == -1) { - AFB_API_ERROR(plugin->api, "BlueALSA subscription failed: %s", strerror(errno)); - goto fail; - } + if (bluealsa_event_subscribe(watch->fd, transport_mask) == -1) { + AFB_API_ERROR(plugin->api, "BlueALSA subscription failed: %s", strerror(errno)); + goto fail; + } - // Register transport change event to the main loop of the binder - if ((ret = sd_event_add_io(sdLoop, &evtsrc, watch->fd, EPOLLIN, halBlueAlsaTransportEventCB, watch)) < 0) { - AFB_API_ERROR(plugin->api, - "%s: Failed to register event fd to io loop", - __func__); - goto fail; - } + // Register transport change event to the main loop of the binder + ret = sd_event_add_io(sdLoop, &evtsrc, watch->fd, EPOLLIN, halBlueAlsaTransportEventCB, watch); + if (ret < 0) { + AFB_API_ERROR(plugin->api, + "%s: Failed to register event fd to io loop", + __func__); + goto fail; + } return 0; @@ -812,7 +812,7 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret } if (strcmp(signature,"sss") != 0) { - AFB_API_ERROR(plugin->api, "%s: wrong message signature '%s'", __func__, signature); + AFB_API_ERROR(plugin->api, "%s: wrong message signature '%s'", __func__, signature); goto done; } @@ -821,7 +821,7 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret const char *owner_new; if (sd_bus_message_read(m, "sss", &name, &owner_old, &owner_new) < 0) { - AFB_API_ERROR(plugin->api, "%s: failed to read message parameters", __func__); + AFB_API_ERROR(plugin->api, "%s: failed to read message parameters", __func__); goto done; } @@ -829,12 +829,12 @@ static int name_changed_cb(sd_bus_message *m, void *userdata, sd_bus_error * ret goto done; if (owner_old != NULL && owner_old[0] != '\0') { - AFB_API_INFO(plugin->api, "bluez-alsa: %s disappeared", name); + AFB_API_INFO(plugin->api, "bluez-alsa: %s disappeared", name); halBlueAlsaUnregister(plugin, name); } if (owner_new != NULL && owner_new[0] != '\0') { - AFB_API_INFO(plugin->api, "bluez-alsa %s appeared", name); + AFB_API_INFO(plugin->api, "bluez-alsa %s appeared", name); halBlueAlsaRegister(plugin, name); } @@ -865,8 +865,9 @@ static int sd_bus_list_message_handler (sd_bus_message *m, void *userdata, sd_bu const char * string = NULL; - if ( (ret = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s")) < 0) { - AFB_API_ERROR(plugin->api, "failed to enter container, err=%s\n", strerror(-ret)); + ret = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); + if (ret < 0) { + AFB_API_ERROR(plugin->api, "failed to enter container, err=%s", strerror(-ret)); goto failed; } @@ -877,7 +878,7 @@ static int sd_bus_list_message_handler (sd_bus_message *m, void *userdata, sd_bu goto done; } - if (ret == 0) + if (!ret) break; if (strstr(string, BLUEZALSA_DBUS_NAME_PREFIX) != 0) { @@ -906,14 +907,14 @@ static int halBlueAlsaRegisterAll(CtlPluginT* plugin) { AFB_API_INFO(plugin->api, "Ask DBus for the list of services"); ret = sd_bus_call_method_async(bus, - &slot, - ORG_FREEDESKTOP_DBUS_NAME, - ORG_FREEDESKTOP_DBUS_PATH, - ORG_FREEDESKTOP_DBUS_INTERFACE, - "ListNames", - sd_bus_list_message_handler, - plugin, - NULL); + &slot, + ORG_FREEDESKTOP_DBUS_NAME, + ORG_FREEDESKTOP_DBUS_PATH, + ORG_FREEDESKTOP_DBUS_INTERFACE, + "ListNames", + sd_bus_list_message_handler, + plugin, + NULL); if (ret < 0) { AFB_API_ERROR(plugin->api, "Unable to request service list from DBus: %s", strerror(-ret)); goto failed; diff --git a/src/4a-hal-manager/4a-hal-manager-cb.c b/src/4a-hal-manager/4a-hal-manager-cb.c index 32fbb25..022bda8 100644 --- a/src/4a-hal-manager/4a-hal-manager-cb.c +++ b/src/4a-hal-manager/4a-hal-manager-cb.c @@ -67,7 +67,8 @@ void HalMgrLoaded(afb_req_t request) json_object *requestJson, *requestAnswer, *apiObject; - if(! (apiHandle = afb_req_get_api(request))) { + apiHandle = afb_req_get_api(request); + if(! apiHandle) { afb_req_fail(request, "api_handle", "Can't get hal manager api handle"); return; } @@ -79,7 +80,6 @@ void HalMgrLoaded(afb_req_t request) } currentHalData = halMgrData->halDataList; - if(! currentHalData) { afb_req_success(request, NULL, "No Hal Api loaded"); return; @@ -91,7 +91,8 @@ void HalMgrLoaded(afb_req_t request) return; } - if(! (requestJson = afb_req_json(request))) + requestJson = afb_req_json(request); + if(! requestJson) AFB_REQ_NOTICE(request, "Can't get request json"); else requestJsonErr = wrap_json_unpack(requestJson, "{s?:b s?:b}", "all", &allHal, "verbose", &verbose); @@ -142,7 +143,8 @@ void HalMgrLoad(afb_req_t request) json_object *requestJson, *apiReceivedMetadata; - if(! (apiHandle = afb_req_get_api(request))) { + apiHandle = afb_req_get_api(request); + if(! apiHandle) { afb_req_fail(request, "api_handle", "Can't get hal manager api handle"); return; } @@ -153,7 +155,8 @@ void HalMgrLoad(afb_req_t request) return; } - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { afb_req_fail(request, "request_json", "Can't get request json"); return; } @@ -214,7 +217,8 @@ void HalMgrUnload(afb_req_t request) json_object *requestJson; - if(! (apiHandle = afb_req_get_api(request))) { + apiHandle = afb_req_get_api(request); + if(! apiHandle) { afb_req_fail(request, "api_handle", "Can't get hal manager api handle"); return; } @@ -225,7 +229,8 @@ void HalMgrUnload(afb_req_t request) return; } - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { afb_req_fail(request, "request_json", "Can't get request json"); return; } diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c index 4d2fbf1..20103cb 100644 --- a/src/4a-hal-manager/4a-hal-manager.c +++ b/src/4a-hal-manager/4a-hal-manager.c @@ -54,7 +54,7 @@ afb_verb_t HalManagerApiStaticVerbs[] = }; /******************************************************************************* - * HAL Manager get 'HalData' linked list * + * HAL Manager get 'HalData' linked list * from HAL list function * ******************************************************************************/ @@ -87,7 +87,6 @@ static int HalMgrInitApi(afb_api_t apiHandle) return -3; currentHalData = halMgrData->halDataList; - while(currentHalData) { if(! currentHalData->apiName) return -4; @@ -115,7 +114,7 @@ static int HalMgrLoadApi(void *cbdata, afb_api_t apiHandle) // Add static controls verbs if(HalUtlLoadVerbs(apiHandle, HalManagerApiStaticVerbs)) { AFB_API_ERROR(apiHandle, "Load section : fail to register static verbs"); - return 1; + return -2; } // Declare an event manager for Hal Manager @@ -144,7 +143,6 @@ int HalMgrCreateApi(afb_api_t apiHandle, struct HalMgrData *halMgrData) int afbBindingEntry(afb_api_t apiHandle) { - int status = 0, rc; if(! apiHandle) return -1; @@ -155,14 +153,12 @@ int afbBindingEntry(afb_api_t apiHandle) AFB_API_NOTICE(apiHandle, "Binding start"); // Load Hal-Manager using Api v3 - rc = HalMgrCreateApi(apiHandle, &localHalMgrGlobalData); - if(rc < 0) - status--; + if(HalMgrCreateApi(apiHandle, &localHalMgrGlobalData)) + return -3; // Load internals Hal using Api v3 - rc = InternalHalCreateAllApi(apiHandle, &localHalMgrGlobalData); - if(rc < 0) - status -= rc; + if(InternalHalCreateAllApi(apiHandle, &localHalMgrGlobalData)) + return -4; - return status; + return 0; }
\ No newline at end of file diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c index d092ddf..6eda170 100644 --- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c +++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c @@ -39,13 +39,13 @@ ******************************************************************************/ static const char *const snd_ctl_elem_type_names[] = { - [SND_CTL_ELEM_TYPE_NONE]= "NONE", - [SND_CTL_ELEM_TYPE_BOOLEAN]= "BOOLEAN", - [SND_CTL_ELEM_TYPE_INTEGER]="INTEGER", - [SND_CTL_ELEM_TYPE_ENUMERATED]="ENUMERATED", - [SND_CTL_ELEM_TYPE_BYTES]="BYTES", - [SND_CTL_ELEM_TYPE_IEC958]="IEC958", - [SND_CTL_ELEM_TYPE_INTEGER64]="INTEGER64", + [SND_CTL_ELEM_TYPE_NONE] = "NONE", + [SND_CTL_ELEM_TYPE_BOOLEAN] = "BOOLEAN", + [SND_CTL_ELEM_TYPE_INTEGER] = "INTEGER", + [SND_CTL_ELEM_TYPE_ENUMERATED] = "ENUMERATED", + [SND_CTL_ELEM_TYPE_BYTES] = "BYTES", + [SND_CTL_ELEM_TYPE_IEC958] = "IEC958", + [SND_CTL_ELEM_TYPE_INTEGER64] = "INTEGER64", }; /******************************************************************************* @@ -481,19 +481,21 @@ void InternalHalActionOnAlsaCtl(afb_req_t request) *appliedControlValuesJ, *normalizedAppliedControlValuesJ; - if(! (apiHandle = afb_req_get_api(request))) { - afb_req_fail(request, "api_handle", "Can't get current hal controller api handle"); + apiHandle = afb_req_get_api(request); + if(! apiHandle) { + afb_req_fail(request, "api_handle", "Can't get current internal hal api handle"); return; } - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { - afb_req_fail(request, "hal_controller_config", "Can't get current hal controller config"); + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { + afb_req_fail(request, "hal_controller_config", "Can't get current internal hal controller config"); return; } currentHalData = (struct HalData *) getExternalData(ctrlConfig); if(! currentHalData) { - afb_req_fail(request, "hal_controller_data", "Can't get current hal controller data"); + afb_req_fail(request, "hal_controller_data", "Can't get current internal hal controller data"); return; } @@ -516,7 +518,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request) snprintf(cardIdString, 6, "hw:%i", currentHalData->sndCardId); if(InternalHalGetAlsaCtlValues(apiHandle, cardIdString, ¤tAlsaCtl->ctl, &previousControlValuesJ)) { - afb_req_fail_f(request, "previous_values", "Error when trying to get unchanged alsa control values"); + afb_req_fail(request, "previous_values", "Error when trying to get unchanged alsa control values"); return; } else if(InternalHalConvertJsonValues(apiHandle, @@ -532,7 +534,8 @@ void InternalHalActionOnAlsaCtl(afb_req_t request) return; } - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { wrap_json_pack(&answerJ, "{s:o}", "current", normalizedPreviousControlValuesJ); @@ -604,7 +607,7 @@ void InternalHalActionOnAlsaCtl(afb_req_t request) json_object_put(convertedJ); if(InternalHalGetAlsaCtlValues(apiHandle, cardIdString, ¤tAlsaCtl->ctl, &appliedControlValuesJ)) { - afb_req_fail_f(request, "applied_values", "Error when trying to get applied alsa control values"); + afb_req_fail(request, "applied_values", "Error when trying to get applied alsa control values"); json_object_put(normalizedPreviousControlValuesJ); return; } diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.c b/src/4a-internals-hal/4a-internals-hal-api-loader.c index 94891b8..d70019e 100644 --- a/src/4a-internals-hal/4a-internals-hal-api-loader.c +++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c @@ -82,7 +82,8 @@ static int InternalHalInitOneApi(afb_api_t apiHandle) AFB_default = apiHandle; // Retrieve section config from api handle - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) return -2; currentHalData = (struct HalData *) getExternalData(ctrlConfig); @@ -135,15 +136,18 @@ static int InternalHalLoadOneApi(void *cbdata, afb_api_t apiHandle) // Add static controls verbs if(HalUtlLoadVerbs(apiHandle, InternalHalApiStaticVerbs)) { AFB_API_ERROR(apiHandle, "Load Section : fail to register static V2 verbs"); - return 1; + return -2; } ctrlCurrentSections = malloc(sizeof(ctrlSectionsDefault)); memcpy(ctrlCurrentSections, ctrlSectionsDefault, sizeof(ctrlSectionsDefault)); // Load section for corresponding Api - if((err = CtlLoadSections(apiHandle, ctrlConfig, ctrlCurrentSections))) - return err; + err = CtlLoadSections(apiHandle, ctrlConfig, ctrlCurrentSections); + if(err) { + AFB_API_ERROR(apiHandle, "Didn't succeed to load current internal hal controller section"); + return -4; + } // Declare an event manager for this Api afb_api_on_event(apiHandle, InternalHalDispatchApiEvent); @@ -165,19 +169,21 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal // Create one Api per file ctrlConfig = CtlLoadMetaData(apiHandle, path); if(! ctrlConfig) { - AFB_API_ERROR(apiHandle, "No valid control config file in:\n-- %s", path); + AFB_API_ERROR(apiHandle, "No valid internal hal config file in : '%s'", path); return -2; } if(! ctrlConfig->api) { - AFB_API_ERROR(apiHandle, "API Missing from metadata in:\n-- %s", path); + AFB_API_ERROR(apiHandle, "API Missing from metadata in : '%s'", path); return -3; } - // Allocation of current hal controller data + // Allocation of current internal hal data currentHalData = HalUtlAddHalToHalList(&halMgrData->halDataList); - if(! currentHalData) + if(! currentHalData) { + AFB_API_ERROR(apiHandle, "Didn't succeed to add hal to hal list"); return -4; + } currentHalData->apiName = (char *) ctrlConfig->api; @@ -188,15 +194,17 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal currentHalData->internalHalData = calloc(1, sizeof(struct InternalHalData)); // Create one API - if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) - return -5; + if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) { + AFB_API_ERROR(apiHandle, "An error occurred at '%s' internal hal api creation", ctrlConfig->api); + return -6; + } return 0; } int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData) { - int index, status = 0; + int index; char *dirList, *fileName, *fullPath; char filePath[CONTROL_MAXPATH_LEN]; @@ -236,8 +244,8 @@ int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData) strncat(filePath, fileName, sizeof(filePath) - 1); if(InternalHalCreateApi(apiHandle, filePath, halMgrData) < 0) - status--; + return -3; } - return status; + return 0; }
\ No newline at end of file diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c index 0102d8d..c4934a4 100644 --- a/src/4a-internals-hal/4a-internals-hal-cb.c +++ b/src/4a-internals-hal/4a-internals-hal-cb.c @@ -49,7 +49,8 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json AFB_API_DEBUG(apiHandle, "Evtname=%s [msg=%s]", evtLabel, json_object_get_string(eventJ)); - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { AFB_API_ERROR(apiHandle, "Can't get current internal hal controller config"); return; } @@ -74,7 +75,7 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json currentHalAlsaCtlsT = currentHalData->internalHalData->alsaMapT; - // Search for corresponding numid in halCtls, if found, launch callback (if available) + // Search for corresponding numid in ALSA controls list, if found, launch callback (if available) for(idx = 0; idx < currentHalAlsaCtlsT->ctlsCount; idx++) { if(currentHalAlsaCtlsT->ctls[idx].ctl.numid == numid) { if(currentHalAlsaCtlsT->ctls[idx].action) { @@ -90,7 +91,7 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json numid); } - if((! currentHalAlsaCtlsT->ctls[idx].alsaControlEvent) || + if(! currentHalAlsaCtlsT->ctls[idx].alsaControlEvent || InternalHalConvertJsonValues(apiHandle, ¤tHalAlsaCtlsT->ctls[idx].ctl.alsaCtlProperties, valuesJ, @@ -138,7 +139,8 @@ int InternalHalHalMixerConfig(afb_api_t apiHandle, CtlSectionT *section, json_ob if(! apiHandle || ! section) return -1; - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) return -2; currentHalData = (struct HalData *) getExternalData(ctrlConfig); @@ -184,7 +186,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls "info", &alsaMap->info, "alsa", &alsaJ, "action", &action)) { - AFB_API_ERROR(apiHandle, "Parsing error, map should only contains [label]|[uid]|[tag]|[info]|[alsa]|[action] in:\n-- %s", json_object_get_string(AlsaMapJ)); + AFB_API_ERROR(apiHandle, "Parsing error, map should only contains [label]|[uid]|[tag]|[info]|[alsa]|[action] in : '%s'", json_object_get_string(AlsaMapJ)); return -1; } @@ -193,7 +195,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls "numid", &alsaMap->ctl.numid, "value", &alsaMap->ctl.value, "create", &createAlsaCtlJ)) { - AFB_API_ERROR(apiHandle, "Parsing error, alsa json should only contains [name]|[numid]||[value]|[create] in:\n-- %s", json_object_get_string(alsaJ)); + AFB_API_ERROR(apiHandle, "Parsing error, alsa json should only contains [name]|[numid]||[value]|[create] in : '%s'", json_object_get_string(alsaJ)); return -2; } @@ -207,14 +209,17 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls "minval", &alsaMap->ctl.alsaCtlCreation->minval, "maxval", &alsaMap->ctl.alsaCtlCreation->maxval, "step", &alsaMap->ctl.alsaCtlCreation->step)) { - AFB_API_ERROR(apiHandle, "Parsing error, alsa creation json should only contains [type]|[count]|[minval]|[maxval]|[step] in:\n-- %s", json_object_get_string(alsaJ)); + AFB_API_ERROR(apiHandle, "Parsing error, alsa creation json should only contains [type]|[count]|[minval]|[maxval]|[step] in : '%s'", json_object_get_string(alsaJ)); return -3; } if(typename) { alsaMap->ctl.alsaCtlCreation->type = InternalHalMapsAlsaTypeToEnum(typename); if(alsaMap->ctl.alsaCtlCreation->type == SND_CTL_ELEM_TYPE_NONE) { - AFB_API_ERROR(apiHandle, "Couldn't get alsa type from string %s in:\n-- %s", typename, json_object_get_string(alsaJ)); + AFB_API_ERROR(apiHandle, + "Couldn't get alsa type from string %s in : '%s'", + typename, + json_object_get_string(alsaJ)); return -4; } } @@ -224,7 +229,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls } else if(alsaMap->ctl.name && alsaMap->ctl.numid > 0) { AFB_API_ERROR(apiHandle, - "Can't have both a control name (%s) and a control uid (%i) in alsa object:\n-- %s", + "Can't have both a control name (%s) and a control uid (%i) in alsa object : '%s'", alsaMap->ctl.name, alsaMap->ctl.numid, json_object_get_string(alsaJ)); @@ -232,7 +237,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls } else if(! alsaMap->ctl.name && alsaMap->ctl.numid <= 0) { AFB_API_ERROR(apiHandle, - "Need at least a control name or a control uid in alsa object:\n-- %s", + "Need at least a control name or a control uid in alsa object : '%s'", json_object_get_string(alsaJ)); return -6; } @@ -249,9 +254,10 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I json_object *valueJ, *convertedValueJ = NULL; - if(! (alsaMap->alsaControlEvent = afb_api_make_event(apiHandle, alsaMap->uid))) { + alsaMap->alsaControlEvent = afb_api_make_event(apiHandle, alsaMap->uid); + if(! alsaMap->alsaControlEvent) { AFB_API_ERROR(apiHandle, - "Didn't succeed to create event for current alsa control to load action using alsa object:\n-- %s", + "Didn't succeed to create event for current alsa control to load action using alsa object : '%s'", json_object_get_string(alsaMap->actionJ)); return -1; } @@ -298,7 +304,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I alsaMap->action = calloc(1, sizeof(CtlActionT)); if(ActionLoadOne(apiHandle, alsaMap->action, alsaMap->actionJ, 0)) { AFB_API_ERROR(apiHandle, - "Didn't succeed to load action using alsa object:\n-- %s", + "Didn't succeed to load action using alsa object : '%s'", json_object_get_string(alsaMap->actionJ)); return -6; } @@ -306,7 +312,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I if(afb_api_add_verb(apiHandle, alsaMap->uid, alsaMap->info, InternalHalActionOnAlsaCtl, (void *) alsaMap, NULL, 0, 0)) { AFB_API_ERROR(apiHandle, - "Didn't succeed to create verb for current alsa control to load action using alsa object:\n-- %s", + "Didn't succeed to create verb for current alsa control to load action using alsa object : '%s'", json_object_get_string(alsaMap->actionJ)); return -7; } @@ -335,7 +341,7 @@ int InternalHalProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, stru default: currentInternalHalAlsaMapT->ctlsCount = 0; currentInternalHalAlsaMapT->ctls = NULL; - AFB_API_WARNING(apiHandle, "Couldn't get content of 'halmap' section in : '%s'", json_object_get_string(AlsaMapJ)); + AFB_API_ERROR(apiHandle, "Content of 'halmap' section is not valid ('%s')", json_object_get_string(AlsaMapJ)); return -1; } @@ -370,7 +376,8 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje CtlConfigT *ctrlConfig; struct HalData *currentHalData; - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) return -1; currentHalData = (struct HalData *) getExternalData(ctrlConfig); @@ -391,7 +398,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje } else if(currentHalData->sndCardId < 0) { AFB_API_ERROR(apiHandle, "Hal alsa card id is not valid, 'halmap' section data can't be handle"); - return -6; + return -4; } else if(! currentHalData->internalHalData->alsaMapT) { AFB_API_WARNING(apiHandle, "'halmap' section data is empty"); @@ -403,7 +410,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje } else if(InternalHalHandleAllHalMap(apiHandle, currentHalData->sndCardId, currentHalData->internalHalData->alsaMapT)) { AFB_API_ERROR(apiHandle, "Failed to handle 'halmap' section"); - return -9; + return -5; } return 0; @@ -428,12 +435,11 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle, mixerDataArrayJ = json_object_new_array(); if(! mixerDataArrayJ) { - AFB_API_ERROR(apiHandle, "Can't generate json mixer data array"); + AFB_API_ERROR(apiHandle, "Didn't succeed to allocate requested mixer data json array"); return NULL; } currentMixerData = *mixerDataList; - while(currentMixerData) { switch(dataType) { case MIXER_DATA_STREAMS: @@ -480,8 +486,9 @@ json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct Inte return NULL; } - if(! (alsaMapDataArray = json_object_new_array())) { - AFB_API_ERROR(apiHandle, "Can't generate json mixer data array"); + alsaMapDataArray = json_object_new_array(); + if(! alsaMapDataArray) { + AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA controls data json array"); return NULL; } @@ -506,14 +513,22 @@ void InternalHalInfo(afb_req_t request) struct HalData *currentHalData; - json_object *requestJson, *toReturnJ = NULL, *requestAnswer, *streamsArray, *playbacksArray, *capturesArray, *controlsArray; + json_object *requestJson, + *toReturnJ = NULL, + *requestAnswer, + *streamsArray, + *playbacksArray, + *capturesArray, + *controlsArray; - if(! (apiHandle = afb_req_get_api(request))) { + apiHandle = afb_req_get_api(request); + if(! apiHandle) { afb_req_fail(request, "api_handle", "Can't get current internal hal api handle"); return; } - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { afb_req_fail(request, "hal_controller_config", "Can't get current internal hal controller config"); return; } @@ -524,7 +539,8 @@ void InternalHalInfo(afb_req_t request) return; } - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { AFB_REQ_NOTICE(request, "Can't get request json"); } else if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0) { @@ -604,12 +620,14 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL; json_type requestJsonType; - if(! (apiHandle = afb_req_get_api(request))) { + apiHandle = afb_req_get_api(request); + if(! apiHandle) { afb_req_fail(request, "api_handle", "Can't get current internal hal api handle"); return; } - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { afb_req_fail(request, "hal_controller_config", "Can't get current internal hal controller config"); return; } @@ -627,7 +645,8 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib InternalHalAlsaMapT = currentHalData->internalHalData->alsaMapT; - if(! (requestJson = afb_req_json(request))) { + requestJson = afb_req_json(request); + if(! requestJson) { afb_req_fail(request, "request_json", "Can't get request json"); return; } @@ -669,17 +688,17 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib if(currentHalData->internalHalData->streamUpdates && subscribeUnsubscribeType == SUBSCRIPTION && afb_req_subscribe(request, currentHalData->internalHalData->streamUpdates)) { - afb_req_fail_f(request, - "request_stream_list_updates_event", - "Error while trying to subscribe to stream list updates event"); + afb_req_fail(request, + "request_stream_list_updates_event", + "Error while trying to subscribe to stream list updates event"); return; } else if(currentHalData->internalHalData->streamUpdates && subscribeUnsubscribeType == UNSUBSCRIPTION && afb_req_unsubscribe(request, currentHalData->internalHalData->streamUpdates)) { - afb_req_fail_f(request, - "request_stream_list_updates_event", - "Error while trying to unsubscribe to stream list updates event"); + afb_req_fail(request, + "request_stream_list_updates_event", + "Error while trying to unsubscribe to stream list updates event"); return; } @@ -689,7 +708,7 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib currentStreamData = currentHalData->internalHalData->streamsData; while(currentStreamData && - (! subscriptionFound)) { + ! subscriptionFound) { if(! strcasecmp(currentSubscriptionString, currentStreamData->verb)) { if(currentStreamData->event && subscribeUnsubscribeType == SUBSCRIPTION && @@ -712,7 +731,6 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib subscriptionFound = 1; subscriptionDoneNb++; - break; } @@ -721,7 +739,7 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib searchIdx = 0; while((searchIdx < (InternalHalAlsaMapT ? InternalHalAlsaMapT->ctlsCount : 0)) && - (! subscriptionFound)) { + ! subscriptionFound) { if(! strcasecmp(currentSubscriptionString, InternalHalAlsaMapT->ctls[searchIdx].uid)) { if(InternalHalAlsaMapT->ctls[searchIdx].alsaControlEvent && subscribeUnsubscribeType == SUBSCRIPTION && @@ -744,7 +762,6 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib subscriptionFound = 1; subscriptionDoneNb++; - break; } diff --git a/src/4a-internals-hal/4a-internals-hal-mixer-link.c b/src/4a-internals-hal/4a-internals-hal-mixer-link.c index 95e9099..4e0398e 100644 --- a/src/4a-internals-hal/4a-internals-hal-mixer-link.c +++ b/src/4a-internals-hal/4a-internals-hal-mixer-link.c @@ -58,9 +58,11 @@ int InternalHalHandleMixerData(afb_api_t apiHandle, case json_type_object: mixerDataNb = 1; break; + case json_type_array: mixerDataNb = (unsigned int) json_object_array_length(currentDataJ); break; + default: mixerDataNb = 0; AFB_API_ERROR(apiHandle, "No data returned"); @@ -104,7 +106,6 @@ int InternalHalHandleMixerData(afb_api_t apiHandle, currentDataVerbName); err += (int) MIXER_ERROR_STREAM_NOT_ADDED; } - break; case MIXER_DATA_PLAYBACKS: @@ -114,8 +115,8 @@ int InternalHalHandleMixerData(afb_api_t apiHandle, currentMixerData->verb = strdup((dataType == MIXER_DATA_PLAYBACKS) ? HAL_PLAYBACK_ID : HAL_CAPTURE_ID); currentMixerData->verbToCall = strdup(currentDataVerbName); - if((! currentMixerData->verb) || - (! currentMixerData->verbToCall)) { + if(! currentMixerData->verb || + ! currentMixerData->verbToCall) { HalUtlRemoveSelectedMixerData(mixerDataList, currentMixerData); err += (int) MIXER_ERROR_STREAM_ALLOCATION_FAILED; } @@ -169,7 +170,11 @@ int InternalHalHandleMixerAttachResponse(afb_api_t apiHandle, struct InternalHal return (int) MIXER_ERROR_API_UNAVAILABLE; } - if(wrap_json_unpack(mixerResponseJ, "{s?:o s?:o s?:o}", "streams", &mixerStreamsJ, "playbacks", &mixerPlaybacksJ, "captures", &mixerCapturesJ)) { + if(wrap_json_unpack(mixerResponseJ, + "{s?:o s?:o s?:o}", + "streams", &mixerStreamsJ, + "playbacks", &mixerPlaybacksJ, + "captures", &mixerCapturesJ)) { AFB_API_ERROR(apiHandle, "Can't get streams|playbacks|captures object in '%s'", json_object_get_string(mixerResponseJ)); return (int) MIXER_ERROR_DATA_UNAVAILABLE; } @@ -227,14 +232,15 @@ int InternalHalAttachToMixer(afb_api_t apiHandle) return -1; } - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { - AFB_API_ERROR(apiHandle, "Can't get current hal controller config"); + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) { + AFB_API_ERROR(apiHandle, "Can't get current internal hal controller config"); return -2; } currentHalData = (struct HalData *) getExternalData(ctrlConfig); if(! currentHalData) { - AFB_API_ERROR(apiHandle, "Can't get current hal controller data"); + AFB_API_ERROR(apiHandle, "Can't get current internal hal controller data"); return -3; } @@ -386,4 +392,4 @@ int InternalHalGetInfoFromMixer(afb_api_t apiHandle, } return 0; -}
\ No newline at end of file +} diff --git a/src/4a-internals-hal/4a-internals-hal-value-handler.c b/src/4a-internals-hal/4a-internals-hal-value-handler.c index 64083a9..98e29ab 100644 --- a/src/4a-internals-hal/4a-internals-hal-value-handler.c +++ b/src/4a-internals-hal/4a-internals-hal-value-handler.c @@ -229,7 +229,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle, idx, json_object_get_string(toConvertObjectJ)); json_object_put(convertedArrayJ); - return -(idx + 1); + return -1; } break; @@ -246,7 +246,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle, idx, json_object_get_string(toConvertObjectJ)); json_object_put(convertedArrayJ); - return -(idx + 1); + return -2; } break; @@ -255,7 +255,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle, "Conversion not handle for the alsa control type %i", (int) alsaCtlProperties->type); json_object_put(convertedArrayJ); - return -(idx + 1); + return -3; } json_object_array_put_idx(convertedArrayJ, idx, convertedValueJ); @@ -285,8 +285,8 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle, requestedPercentageVariation = (int) strtol(requestedPercentageVariationString, &conversionEnd, 10); if(conversionEnd == requestedPercentageVariationString) { AFB_API_ERROR(apiHandle, - "Tried to increase/decrease an integer control \ - but string sent in json is not a increase/decrease string : '%s'", + "Tried to increase/decrease an integer control" + "but string sent in json is not a increase/decrease string : '%s'", json_object_get_string(requestedPercentageVariationJ)); return -1; } @@ -294,16 +294,16 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle, if(alsaCtlProperties->type != SND_CTL_ELEM_TYPE_INTEGER && alsaCtlProperties->type != SND_CTL_ELEM_TYPE_INTEGER64) { AFB_API_ERROR(apiHandle, - "Tried to increase/decrease values on a incompatible \ - control type (%i), control type must be an integer", + "Tried to increase/decrease values on a incompatible" + "control type (%i), control type must be an integer", alsaCtlProperties->type); return -2; } if(requestedPercentageVariation < -100 || requestedPercentageVariation > 100) { AFB_API_ERROR(apiHandle, - "Tried to increase/decrease values but specified change is \ - not a valid percentage, it should be between -100 and 100"); + "Tried to increase/decrease values but specified change is" + "not a valid percentage, it should be between -100 and 100"); return -3; } @@ -331,9 +331,11 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle, if(! json_object_is_type(toChangeObjectJ, json_type_int)) { AFB_API_ERROR(apiHandle, - "Current json object %s is not an integer", - json_object_get_string(toChangeObjectJ)); - return -(10 + idx); + "Current json object %s is not an integer (object %i out of %i)", + json_object_get_string(toChangeObjectJ), + idx, + count); + return -5; } toChangeValue = json_object_get_int(toChangeObjectJ); |