diff options
Diffstat (limited to '4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c')
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 342 |
1 files changed, 164 insertions, 178 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c index cfe921d..d648103 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -22,7 +22,7 @@ #include <wrap-json.h> -#include <afb-definitions.h> +#include <afb/afb-binding.h> #include "4a-hal-utilities-data.h" #include "4a-hal-utilities-appfw-responses-handler.h" @@ -36,7 +36,7 @@ * HAL controller event handler function * ******************************************************************************/ -void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_object *eventJ) +void HalCtlsDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_object *eventJ) { int numid, idx = 0, cardidx; @@ -48,17 +48,15 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje json_object *valuesJ, *normalizedValuesJ; - AFB_ApiDebug(apiHandle, "Evtname=%s [msg=%s]", evtLabel, json_object_get_string(eventJ)); + AFB_API_DEBUG(apiHandle, "Evtname=%s [msg=%s]", evtLabel, json_object_get_string(eventJ)); - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) { - AFB_ApiError(apiHandle, "Can't get current hal controller config"); + if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + AFB_API_ERROR(apiHandle, "Can't get current hal controller config"); return; } - currentHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); - if(! currentHalData) { - AFB_ApiWarning(apiHandle, "Can't get current hal controller data"); + if(! (currentHalData = (struct SpecificHalData *) getExternalData(ctrlConfig))) { + AFB_API_WARNING(apiHandle, "Can't get current hal controller data"); return; } @@ -70,7 +68,7 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje sscanf(&evtLabel[idx + 1], "%d", &cardidx) == 1 && currentHalData->sndCardId == cardidx) { if(wrap_json_unpack(eventJ, "{s:i s:o !}", "id", &numid, "val", &valuesJ)) { - AFB_ApiError(apiHandle, "Invalid Alsa Event label=%s value=%s", evtLabel, json_object_get_string(eventJ)); + AFB_API_ERROR(apiHandle, "Invalid Alsa Event label=%s value=%s", evtLabel, json_object_get_string(eventJ)); return; } @@ -87,9 +85,9 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje (void) ActionExecOne(&source, currentHalAlsaCtlsT->ctls[idx].action, valuesJ); } else { - AFB_ApiNotice(apiHandle, - "The alsa control id '%i' is corresponding to a known control but without any action registered", - numid); + AFB_API_NOTICE(apiHandle, + "The alsa control id '%i' is corresponding to a known control but without any action registered", + numid); } if((! currentHalAlsaCtlsT->ctls[idx].alsaControlEvent) || @@ -98,29 +96,30 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje valuesJ, &normalizedValuesJ, CONVERSION_ALSACORE_TO_NORMALIZED) || - (AFB_EventPush(currentHalAlsaCtlsT->ctls[idx].alsaControlEvent, normalizedValuesJ) < 0)) { - AFB_ApiError(apiHandle, - "Couldn't generate an event for known halmap %s (alsa control id %i)", - currentHalAlsaCtlsT->ctls[idx].uid, - currentHalAlsaCtlsT->ctls[idx].ctl.numid); + (afb_event_push(currentHalAlsaCtlsT->ctls[idx].alsaControlEvent, normalizedValuesJ) < 0)) { + AFB_API_ERROR(apiHandle, + "Couldn't generate an event for known halmap %s (alsa control id %i)", + currentHalAlsaCtlsT->ctls[idx].uid, + currentHalAlsaCtlsT->ctls[idx].ctl.numid); } return; } } - AFB_ApiWarning(apiHandle, "Alsacore event with an unrecognized numid: %i, evtname=%s [msg=%s]", - numid, - evtLabel, - json_object_get_string(eventJ)); + AFB_API_WARNING(apiHandle, + "Alsacore event with an unrecognized numid: %i, evtname=%s [msg=%s]", + numid, + evtLabel, + json_object_get_string(eventJ)); return; } - AFB_ApiInfo(apiHandle, - "Not an alsacore event '%s' [msg=%s]", - evtLabel, - json_object_get_string(eventJ)); + AFB_API_INFO(apiHandle, + "Not an alsacore event '%s' [msg=%s]", + evtLabel, + json_object_get_string(eventJ)); CtrlDispatchApiEvent(apiHandle, evtLabel, eventJ); } @@ -129,7 +128,7 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje * HAL controllers sections parsing functions * ******************************************************************************/ -int HalCtlsHalMixerConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *MixerJ) +int HalCtlsHalMixerConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *MixerJ) { int err = 0; @@ -139,12 +138,10 @@ int HalCtlsHalMixerConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object if(! apiHandle || ! section) return -1; - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) + if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) return -2; - currentHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); - if(! currentHalData) + if(! (currentHalData = (struct SpecificHalData *) getExternalData(ctrlConfig))) return -3; if(MixerJ) { @@ -160,27 +157,27 @@ int HalCtlsHalMixerConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object } else if(currentHalData->status == HAL_STATUS_AVAILABLE && (err = HalCtlsAttachToMixer(apiHandle))) { - AFB_ApiError(apiHandle, "%s: Error %i while attaching to mixer", __func__, err); + AFB_API_ERROR(apiHandle, "%s: Error %i while attaching to mixer", __func__, err); return -6; } return 0; } -int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsaMap, json_object *AlsaMapJ) +int HalCtlsProcessOneHalMapObject(afb_api_t apiHandle, struct CtlHalAlsaMap *alsaMap, json_object *AlsaMapJ) { char *action = NULL, *typename = NULL; json_object *alsaJ = NULL, *createAlsaCtlJ = NULL; - AFB_ApiDebug(apiHandle, "AlsaMapJ=%s", json_object_get_string(AlsaMapJ)); + AFB_API_DEBUG(apiHandle, "AlsaMapJ=%s", json_object_get_string(AlsaMapJ)); if(wrap_json_unpack(AlsaMapJ, "{s:s s?:s s:o s?:s !}", "uid", &alsaMap->uid, "info", &alsaMap->info, "alsa", &alsaJ, "action", &action)) { - AFB_ApiError(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:\n-- %s", json_object_get_string(AlsaMapJ)); return -1; } @@ -189,7 +186,7 @@ int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsa "numid", &alsaMap->ctl.numid, "value", &alsaMap->ctl.value, "create", &createAlsaCtlJ)) { - AFB_ApiError(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:\n-- %s", json_object_get_string(alsaJ)); return -2; } @@ -203,12 +200,12 @@ int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsa "minval", &alsaMap->ctl.alsaCtlCreation->minval, "maxval", &alsaMap->ctl.alsaCtlCreation->maxval, "step", &alsaMap->ctl.alsaCtlCreation->step)) { - AFB_ApiError(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:\n-- %s", json_object_get_string(alsaJ)); return -3; } if(typename && (alsaMap->ctl.alsaCtlCreation->type = HalCtlsMapsAlsaTypeToEnum(typename)) == SND_CTL_ELEM_TYPE_NONE) { - AFB_ApiError(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:\n-- %s", typename, json_object_get_string(alsaJ)); return -4; } @@ -216,17 +213,17 @@ int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsa alsaMap->ctl.name = (char *) alsaMap->uid; } else if(alsaMap->ctl.name && alsaMap->ctl.numid > 0) { - AFB_ApiError(apiHandle, - "Can't have both a control name (%s) and a control uid (%i) in alsa object:\n-- %s", - alsaMap->ctl.name, - alsaMap->ctl.numid, - json_object_get_string(alsaJ)); + AFB_API_ERROR(apiHandle, + "Can't have both a control name (%s) and a control uid (%i) in alsa object:\n-- %s", + alsaMap->ctl.name, + alsaMap->ctl.numid, + json_object_get_string(alsaJ)); return -5; } else if(! alsaMap->ctl.name && alsaMap->ctl.numid <= 0) { - AFB_ApiError(apiHandle, - "Need at least a control name or a control uid in alsa object:\n-- %s", - json_object_get_string(alsaJ)); + AFB_API_ERROR(apiHandle, + "Need at least a control name or a control uid in alsa object:\n-- %s", + json_object_get_string(alsaJ)); return -6; } @@ -236,28 +233,27 @@ int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsa return 0; } -int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaMap *alsaMap) +int HalCtlsHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct CtlHalAlsaMap *alsaMap) { int err; json_object *valueJ, *convertedValueJ = NULL; - alsaMap->alsaControlEvent = AFB_EventMake(apiHandle, alsaMap->uid); - if(! AFB_EventIsValid(alsaMap->alsaControlEvent)) { - AFB_ApiError(apiHandle, - "Didn't succeed to create event for halmap ALSA control '%s'", - alsaMap->uid); + if(! (alsaMap->alsaControlEvent = afb_api_make_event(apiHandle, alsaMap->uid))) { + AFB_API_ERROR(apiHandle, + "Didn't succeed to create event for current alsa control to load action using alsa object:\n-- %s", + json_object_get_string(alsaMap->actionJ)); return -1; } if(alsaMap->ctl.alsaCtlCreation) { if(HalCtlsCreateAlsaCtl(apiHandle, cardId, &alsaMap->ctl)) { - AFB_ApiError(apiHandle, "An error happened when trying to create a new alsa control"); + AFB_API_ERROR(apiHandle, "An error happened when trying to create a new alsa control"); return -2; } } else if(HalCtlsUpdateAlsaCtlProperties(apiHandle, cardId, &alsaMap->ctl)) { - AFB_ApiError(apiHandle, "An error happened when trying to get existing alsa control info"); + AFB_API_ERROR(apiHandle, "An error happened when trying to get existing alsa control info"); return -3; } @@ -267,15 +263,15 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal err = 0; if(HalCtlsConvertJsonValues(apiHandle, &alsaMap->ctl.alsaCtlProperties, valueJ, &convertedValueJ, CONVERSION_NORMALIZED_TO_ALSACORE)) { - AFB_ApiError(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ)); + AFB_API_ERROR(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ)); err = -4; } else if(HalCtlsSetAlsaCtlValue(apiHandle, cardId, alsaMap->ctl.numid, convertedValueJ)) { - AFB_ApiError(apiHandle, - "Error while trying to set initial value on alsa control %i, device '%s', value '%s'", - alsaMap->ctl.numid, - cardId, - json_object_get_string(valueJ)); + AFB_API_ERROR(apiHandle, + "Error while trying to set initial value on alsa control %i, device '%s', value '%s'", + alsaMap->ctl.numid, + cardId, + json_object_get_string(valueJ)); err = -5; } @@ -291,24 +287,24 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal if(alsaMap->actionJ) { alsaMap->action = calloc(1, sizeof(CtlActionT)); if(ActionLoadOne(apiHandle, alsaMap->action, alsaMap->actionJ, 0)) { - AFB_ApiError(apiHandle, - "Didn't succeed to load action using alsa object:\n-- %s", - json_object_get_string(alsaMap->actionJ)); + AFB_API_ERROR(apiHandle, + "Didn't succeed to load action using alsa object:\n-- %s", + json_object_get_string(alsaMap->actionJ)); return -6; } } - if(AFB_ApiAddVerb(apiHandle, alsaMap->uid, alsaMap->info, HalCtlsActionOnAlsaCtl, (void *) alsaMap, NULL, 0, 0)) { - AFB_ApiError(apiHandle, - "Didn't succeed to create verb for current alsa control to load action using alsa object:\n-- %s", - json_object_get_string(alsaMap->actionJ)); + if(afb_api_add_verb(apiHandle, alsaMap->uid, alsaMap->info, HalCtlsActionOnAlsaCtl, (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", + json_object_get_string(alsaMap->actionJ)); return -7; } return 0; } -int HalCtlsProcessAllHalMap(AFB_ApiT apiHandle, json_object *AlsaMapJ, struct CtlHalAlsaMapT *currentCtlHalAlsaMapT) +int HalCtlsProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, struct CtlHalAlsaMapT *currentCtlHalAlsaMapT) { int idx, err = 0; @@ -329,7 +325,7 @@ int HalCtlsProcessAllHalMap(AFB_ApiT apiHandle, json_object *AlsaMapJ, struct Ct default: currentCtlHalAlsaMapT->ctlsCount = 0; currentCtlHalAlsaMapT->ctls = NULL; - AFB_ApiWarning(apiHandle, "Couldn't get content of 'halmap' section in:\n-- %s", json_object_get_string(AlsaMapJ)); + AFB_API_WARNING(apiHandle, "Couldn't get content of 'halmap' section in:\n-- %s", json_object_get_string(AlsaMapJ)); return -1; } @@ -343,7 +339,7 @@ int HalCtlsProcessAllHalMap(AFB_ApiT apiHandle, json_object *AlsaMapJ, struct Ct return err; } -int HalCtlsHandleAllHalMap(AFB_ApiT apiHandle, int sndCardId, struct CtlHalAlsaMapT *currentCtlHalAlsaMapT) +int HalCtlsHandleAllHalMap(afb_api_t apiHandle, int sndCardId, struct CtlHalAlsaMapT *currentCtlHalAlsaMapT) { int idx, err = 0; @@ -359,13 +355,12 @@ int HalCtlsHandleAllHalMap(AFB_ApiT apiHandle, int sndCardId, struct CtlHalAlsaM return err; } -int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *AlsaMapJ) +int HalCtlsHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *AlsaMapJ) { CtlConfigT *ctrlConfig; struct SpecificHalData *currentHalData; - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) + if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) return -1; currentHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); @@ -376,28 +371,28 @@ int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *A currentHalData->ctlHalSpecificData->ctlHalAlsaMapT = calloc(1, sizeof(struct CtlHalAlsaMapT)); if(HalCtlsProcessAllHalMap(apiHandle, AlsaMapJ, currentHalData->ctlHalSpecificData->ctlHalAlsaMapT)) { - AFB_ApiError(apiHandle, "Failed to process 'halmap' section"); + AFB_API_ERROR(apiHandle, "Failed to process 'halmap' section"); return -3; } } else if(currentHalData->status == HAL_STATUS_UNAVAILABLE) { - AFB_ApiWarning(apiHandle, "Hal is unavailable, 'halmap' section data can't be handle"); + AFB_API_WARNING(apiHandle, "Hal is unavailable, 'halmap' section data can't be handle"); return 1; } else if(currentHalData->sndCardId < 0) { - AFB_ApiError(apiHandle, "Hal alsa card id is not valid, 'halmap' section data can't be handle"); + AFB_API_ERROR(apiHandle, "Hal alsa card id is not valid, 'halmap' section data can't be handle"); return -6; } else if(! currentHalData->ctlHalSpecificData->ctlHalAlsaMapT) { - AFB_ApiWarning(apiHandle, "'halmap' section data is empty"); + AFB_API_WARNING(apiHandle, "'halmap' section data is empty"); return 2; } else if(! (currentHalData->ctlHalSpecificData->ctlHalAlsaMapT->ctlsCount > 0)) { - AFB_ApiWarning(apiHandle, "No alsa controls defined in 'halmap' section"); + AFB_API_WARNING(apiHandle, "No alsa controls defined in 'halmap' section"); return 3; } else if(HalCtlsHandleAllHalMap(apiHandle, currentHalData->sndCardId, currentHalData->ctlHalSpecificData->ctlHalAlsaMapT)) { - AFB_ApiError(apiHandle, "Failed to handle 'halmap' section"); + AFB_API_ERROR(apiHandle, "Failed to handle 'halmap' section"); return -9; } @@ -408,20 +403,20 @@ int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *A * HAL controllers verbs functions * ******************************************************************************/ -json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct CtlHalMixerData **firstMixerData, enum MixerDataType dataType) +json_object *HalCtlsGetJsonArrayForMixerDataTable(afb_api_t apiHandle, struct CtlHalMixerData **firstMixerData, enum MixerDataType dataType) { json_object *mixerDataArrayJ, *currentMixerDataJ; struct CtlHalMixerData *currentMixerData; if(! apiHandle) { - AFB_ApiError(apiHandle, "Can't get current hal controller api handle"); + AFB_API_ERROR(apiHandle, "Can't get current hal controller api handle"); return NULL; } mixerDataArrayJ = json_object_new_array(); if(! mixerDataArrayJ) { - AFB_ApiError(apiHandle, "Can't generate json mixer data array"); + AFB_API_ERROR(apiHandle, "Can't generate json mixer data array"); return NULL; } @@ -457,25 +452,24 @@ json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct Ctl return mixerDataArrayJ; } -json_object *HalCtlsGetJsonArrayForControls(AFB_ApiT apiHandle, struct CtlHalAlsaMapT *currentAlsaMapDataT) +json_object *HalCtlsGetJsonArrayForControls(afb_api_t apiHandle, struct CtlHalAlsaMapT *currentAlsaMapDataT) { unsigned int idx; json_object *alsaMapDataArray, *currentAlsaMapData; if(! apiHandle) { - AFB_ApiError(apiHandle, "Can't get current hal controller api handle"); + AFB_API_ERROR(apiHandle, "Can't get current hal controller api handle"); return NULL; } if(! currentAlsaMapDataT) { - AFB_ApiError(apiHandle, "Can't get Alsa map data table to handle"); + AFB_API_ERROR(apiHandle, "Can't get Alsa map data table to handle"); return NULL; } - alsaMapDataArray = json_object_new_array(); - if(! alsaMapDataArray) { - AFB_ApiError(apiHandle, "Can't generate json mixer data array"); + if(! (alsaMapDataArray = json_object_new_array())) { + AFB_API_ERROR(apiHandle, "Can't generate json mixer data array"); return NULL; } @@ -491,88 +485,84 @@ json_object *HalCtlsGetJsonArrayForControls(AFB_ApiT apiHandle, struct CtlHalAls return alsaMapDataArray; } -void HalCtlsInfo(AFB_ReqT request) +void HalCtlsInfo(afb_req_t request) { char *apiToCall, *returnedStatus = NULL, *returnedInfo = NULL; - AFB_ApiT apiHandle; + afb_api_t apiHandle; CtlConfigT *ctrlConfig; struct SpecificHalData *currentCtlHalData; json_object *requestJson, *toReturnJ = NULL, *requestAnswer, *streamsArray, *playbacksArray, *capturesArray, *controlsArray; - apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); - if(! apiHandle) { - AFB_ReqFail(request, "api_handle", "Can't get current hal controller api handle"); + if(! (apiHandle = afb_req_get_api(request))) { + afb_req_fail(request, "api_handle", "Can't get current hal controller api handle"); return; } - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) { - AFB_ReqFail(request, "hal_controller_config", "Can't get current hal controller config"); + if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + afb_req_fail(request, "hal_controller_config", "Can't get current hal controller config"); return; } - currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); - if(! currentCtlHalData) { - AFB_ReqFail(request, "hal_controller_data", "Can't get current hal controller data"); + if(! (currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig))) { + afb_req_fail(request, "hal_controller_data", "Can't get current hal controller data"); return; } - requestJson = AFB_ReqJson(request); - if(! requestJson) { - AFB_ReqNotice(request, "Can't get request json"); + if(! (requestJson = afb_req_json(request))) { + 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) { apiToCall = currentCtlHalData->ctlHalSpecificData->mixerApiName; if(! apiToCall) { - AFB_ReqFail(request, "mixer_api", "Can't get mixer api"); + afb_req_fail(request, "mixer_api", "Can't get mixer api"); return; } if(HalCtlsGetInfoFromMixer(apiHandle, apiToCall, requestJson, &toReturnJ, &returnedStatus, &returnedInfo)) { if(returnedStatus && returnedInfo) { - AFB_ReqFailF(request, - "mixer_info", - "Call to mixer info verb didn't succeed with status '%s' and info '%s'", - returnedStatus, - returnedInfo); + afb_req_fail_f(request, + "mixer_info", + "Call to mixer info verb didn't succeed with status '%s' and info '%s'", + returnedStatus, + returnedInfo); } else { - AFB_ReqFail(request, "mixer_info", "Call to mixer info verb didn't succeed"); + afb_req_fail(request, "mixer_info", "Call to mixer info verb didn't succeed"); } return; } - AFB_ReqSuccess(request, toReturnJ, "Mixer requested data"); + afb_req_success(request, toReturnJ, "Mixer requested data"); return; } if(! (streamsArray = HalCtlsGetJsonArrayForMixerDataTable(apiHandle, ¤tCtlHalData->ctlHalSpecificData->ctlHalStreamsData, MIXER_DATA_STREAMS))) { - AFB_ReqFail(request, "streams_data", "Didn't succeed to generate streams data array"); + afb_req_fail(request, "streams_data", "Didn't succeed to generate streams data array"); return; } if(! (playbacksArray = HalCtlsGetJsonArrayForMixerDataTable(apiHandle, ¤tCtlHalData->ctlHalSpecificData->ctlHalPlaybacksData, MIXER_DATA_PLAYBACKS))) { - AFB_ReqFail(request, "playbacks_data", "Didn't succeed to generate playbacks data array"); + afb_req_fail(request, "playbacks_data", "Didn't succeed to generate playbacks data array"); return; } if(! (capturesArray = HalCtlsGetJsonArrayForMixerDataTable(apiHandle, ¤tCtlHalData->ctlHalSpecificData->ctlHalCapturesData, MIXER_DATA_CAPTURES))) { - AFB_ReqFail(request, "captures_data", "Didn't succeed to generate captures data array"); + afb_req_fail(request, "captures_data", "Didn't succeed to generate captures data array"); return; } if(! (controlsArray = HalCtlsGetJsonArrayForControls(apiHandle, currentCtlHalData->ctlHalSpecificData->ctlHalAlsaMapT))) { - AFB_ReqFail(request, "controls_data", "Didn't succeed to generate controls data array"); + afb_req_fail(request, "controls_data", "Didn't succeed to generate controls data array"); return; } @@ -583,16 +573,16 @@ void HalCtlsInfo(AFB_ReqT request) "captures", capturesArray, "controls", controlsArray); - AFB_ReqSuccess(request, requestAnswer, "Requested data"); + afb_req_success(request, requestAnswer, "Requested data"); } -void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType subscribeUnsubscribeType) +void HalCtlsSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscribeType subscribeUnsubscribeType) { int arrayIdx, searchIdx, count, subscriptionFound, subscriptionDoneNb = 0; char *currentSubscriptionString; - AFB_ApiT apiHandle; + afb_api_t apiHandle; CtlConfigT *ctrlConfig; struct SpecificHalData *currentCtlHalData; @@ -602,39 +592,35 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL; json_type requestJsonType; - apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); - if(! apiHandle) { - AFB_ReqFail(request, "api_handle", "Can't get current hal controller api handle"); + if(! (apiHandle = afb_req_get_api(request))) { + afb_req_fail(request, "api_handle", "Can't get current hal controller api handle"); return; } - ctrlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle); - if(! ctrlConfig) { - AFB_ReqFail(request, "hal_controller_config", "Can't get current hal controller config"); + if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) { + afb_req_fail(request, "hal_controller_config", "Can't get current hal controller config"); return; } - currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig); - if(! currentCtlHalData) { - AFB_ReqFail(request, "hal_controller_data", "Can't get current hal controller data"); + if(! (currentCtlHalData = (struct SpecificHalData *) getExternalData(ctrlConfig))) { + afb_req_fail(request, "hal_controller_data", "Can't get current hal controller data"); return; } if(! currentCtlHalData->ctlHalSpecificData) { - AFB_ReqFail(request, "hal_controller_data", "Can't get current hal specific data"); + afb_req_fail(request, "hal_controller_data", "Can't get current hal specific data"); return; } halAlsaMapT = currentCtlHalData->ctlHalSpecificData->ctlHalAlsaMapT; - requestJson = AFB_ReqJson(request); - if(! requestJson) { - AFB_ReqFail(request, "request_json", "Can't get request json"); + if(! (requestJson = afb_req_json(request))) { + afb_req_fail(request, "request_json", "Can't get request json"); return; } if(wrap_json_unpack(requestJson, "{s:o}", "events", &requestedSubscriptionsJ)) { - AFB_ReqFail(request, "request_json", "Request json invalid"); + afb_req_fail(request, "request_json", "Request json invalid"); return; } @@ -650,7 +636,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType break; default: - AFB_ReqFail(request, "request_json", "Request json invalid"); + afb_req_fail(request, "request_json", "Request json invalid"); return; } @@ -658,7 +644,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType if(requestJsonType == json_type_array) { requestedSubscriptionJ = json_object_array_get_idx(requestedSubscriptionsJ, arrayIdx); if(! json_object_is_type(requestedSubscriptionJ, json_type_string)) { - AFB_ReqFailF(request, "request_json", "Request json number %i in array invalid", arrayIdx); + afb_req_fail_f(request, "request_json", "Request json number %i in array invalid", arrayIdx); return; } } @@ -670,17 +656,17 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType if(currentCtlHalData->ctlHalSpecificData->streamUpdates && subscribeUnsubscribeType == SUBSCRIPTION && afb_req_subscribe(request, currentCtlHalData->ctlHalSpecificData->streamUpdates)) { - AFB_ReqFailF(request, - "request_stream_list_updates_event", - "Error while trying to subscribe to stream list updates event"); + afb_req_fail_f(request, + "request_stream_list_updates_event", + "Error while trying to subscribe to stream list updates event"); return; } else if(currentCtlHalData->ctlHalSpecificData->streamUpdates && subscribeUnsubscribeType == UNSUBSCRIPTION && afb_req_unsubscribe(request, currentCtlHalData->ctlHalSpecificData->streamUpdates)) { - AFB_ReqFailF(request, - "request_stream_list_updates_event", - "Error while trying to unsubscribe to stream list updates event"); + afb_req_fail_f(request, + "request_stream_list_updates_event", + "Error while trying to unsubscribe to stream list updates event"); return; } @@ -695,19 +681,19 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType if(currentStreamData->event && subscribeUnsubscribeType == SUBSCRIPTION && afb_req_subscribe(request, currentStreamData->event)) { - AFB_ReqFailF(request, - "request_stream_event", - "Error while trying to subscribe to %s stream events", - currentStreamData->verb); + afb_req_fail_f(request, + "request_stream_event", + "Error while trying to subscribe to %s stream events", + currentStreamData->verb); return; } else if(currentStreamData->event && subscribeUnsubscribeType == UNSUBSCRIPTION && afb_req_unsubscribe(request, currentStreamData->event)) { - AFB_ReqFailF(request, - "request_stream_event", - "Error while trying to unsubscribe to %s stream events", - currentStreamData->verb); + afb_req_fail_f(request, + "request_stream_event", + "Error while trying to unsubscribe to %s stream events", + currentStreamData->verb); return; } @@ -727,19 +713,19 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType if(halAlsaMapT->ctls[searchIdx].alsaControlEvent && subscribeUnsubscribeType == SUBSCRIPTION && afb_req_subscribe(request, halAlsaMapT->ctls[searchIdx].alsaControlEvent)) { - AFB_ReqFailF(request, - "request_control_event", - "Error while trying to subscribe to %s halmap controls events", - halAlsaMapT->ctls[searchIdx].uid); + afb_req_fail_f(request, + "request_control_event", + "Error while trying to subscribe to %s halmap controls events", + halAlsaMapT->ctls[searchIdx].uid); return; } else if(halAlsaMapT->ctls[searchIdx].alsaControlEvent && subscribeUnsubscribeType == UNSUBSCRIPTION && afb_req_unsubscribe(request, halAlsaMapT->ctls[searchIdx].alsaControlEvent)) { - AFB_ReqFailF(request, - "request_stream_event", - "Error while trying to unsubscribe to %s halmap controls events", - halAlsaMapT->ctls[searchIdx].uid); + afb_req_fail_f(request, + "request_stream_event", + "Error while trying to unsubscribe to %s halmap controls events", + halAlsaMapT->ctls[searchIdx].uid); return; } @@ -754,38 +740,38 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType } if(subscriptionDoneNb == 0) - AFB_ReqFailF(request, - "events_not_found", - "%s failed, event(s) were not found", - subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription"); + afb_req_fail_f(request, + "events_not_found", + "%s failed, event(s) were not found", + subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription"); if(subscriptionDoneNb == count) - AFB_ReqSuccessF(request, - json_object_new_int(subscriptionDoneNb), - "%s succeed for all the %i events requested", - subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", - subscriptionDoneNb); + afb_req_success_f(request, + json_object_new_int(subscriptionDoneNb), + "%s succeed for all the %i events requested", + subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", + subscriptionDoneNb); else if(subscriptionDoneNb < count) - AFB_ReqSuccessF(request, - json_object_new_int(subscriptionDoneNb), - "%s succeed but only to %i events requested out of %i", - subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", - subscriptionDoneNb, - count); + afb_req_success_f(request, + json_object_new_int(subscriptionDoneNb), + "%s succeed but only to %i events requested out of %i", + subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", + subscriptionDoneNb, + count); else - AFB_ReqSuccessF(request, - json_object_new_int(subscriptionDoneNb), - "%s succeed but to more events than requested (%i out of %i)", - subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", - subscriptionDoneNb, - count); + afb_req_success_f(request, + json_object_new_int(subscriptionDoneNb), + "%s succeed but to more events than requested (%i out of %i)", + subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription", + subscriptionDoneNb, + count); } -void HalCtlsSubscribe(AFB_ReqT request) +void HalCtlsSubscribe(afb_req_t request) { HalCtlsSubscribeUnsubscribe(request, SUBSCRIPTION); } -void HalCtlsUnsubscribe(AFB_ReqT request) +void HalCtlsUnsubscribe(afb_req_t request) { HalCtlsSubscribeUnsubscribe(request, UNSUBSCRIPTION); }
\ No newline at end of file |