summaryrefslogtreecommitdiffstats
path: root/4a-hal
diff options
context:
space:
mode:
Diffstat (limited to '4a-hal')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c96
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c29
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c82
-rw-r--r--4a-hal/4a-hal-utilities/4a-hal-utilities-data.h2
4 files changed, 123 insertions, 86 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
index 7825f75..d49a8ba 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
@@ -103,7 +103,7 @@ int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath)
enum CallError returnedError;
- json_object *toSendJ, *returnJ, *responsJ, *devidJ;
+ json_object *toSendJ, *returnJ = NULL, *responsJ, *devidJ;
if(! apiHandle) {
AFB_ApiError(apiHandle, "%s: api handle not available", __func__);
@@ -140,16 +140,21 @@ int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath)
}
}
+ if(returnJ)
+ json_object_put(returnJ);
+
return cardId;
}
int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId)
{
+ int err = 0;
+
char *returnedStatus = NULL, *returnedInfo = NULL;
enum CallError returnedError;
- json_object *subscribeQueryJ, *returnedJ, *returnedWarningJ;
+ json_object *subscribeQueryJ, *returnedJ = NULL, *returnedWarningJ;
wrap_json_pack(&subscribeQueryJ, "{s:s}", "devid", cardId);
if(AFB_ServiceSync(apiHandle, ALSACORE_API, ALSACORE_SUBSCRIBE_VERB, subscribeQueryJ, &returnedJ)) {
@@ -161,7 +166,7 @@ int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId)
ALSACORE_API,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- return -1;
+ err = -1;
}
else if(! wrap_json_unpack(returnedJ, "{s:{s:o}}", "info", &returnedWarningJ)) {
AFB_ApiError(apiHandle,
@@ -169,19 +174,24 @@ int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId)
ALSACORE_SUBSCRIBE_VERB,
ALSACORE_API,
json_object_get_string(returnedWarningJ));
- return -2;
+ err = -2;
}
- return 0;
+ if(returnedJ)
+ json_object_put(returnedJ);
+
+ return err;
}
int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl)
{
+ int err = 0;
+
char *returnedStatus = NULL, *returnedInfo = NULL;
enum CallError returnedError;
- json_object *queryJ, *returnedJ;
+ json_object *queryJ, *returnedJ = NULL;
if(! apiHandle) {
AFB_ApiError(apiHandle, "%s: api handle not available", __func__);
@@ -226,45 +236,48 @@ int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
ALSACORE_API,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- return -6;
+ err = -6;
}
-
- if(currentAlsaCtl->name && wrap_json_unpack(returnedJ, "{s:{s:i}}", "response", "id", &currentAlsaCtl->numid)) {
+ else if(currentAlsaCtl->name && wrap_json_unpack(returnedJ, "{s:{s:i}}", "response", "id", &currentAlsaCtl->numid)) {
AFB_ApiError(apiHandle, "Can't find alsa control 'id' from control 'name': '%s' on device '%s'", currentAlsaCtl->name, cardId);
- return -7;
+ err = -7;
}
else if(! json_object_object_get_ex(returnedJ, "response", NULL)) {
AFB_ApiError(apiHandle, "Can't find alsa control 'id': %i on device '%s'", currentAlsaCtl->numid, cardId);
- return -8;
+ err = -8;
}
-
// TBD JAI : get dblinear/dbminmax/... values
- if(wrap_json_unpack(returnedJ, "{s:{s:{s?:i s?:i s?:i s?:i s?:i}}}",
- "response",
- "ctl",
- "type", (int *) &currentAlsaCtl->alsaCtlProperties.type,
- "count", &currentAlsaCtl->alsaCtlProperties.count,
- "min", &currentAlsaCtl->alsaCtlProperties.minval,
- "max", &currentAlsaCtl->alsaCtlProperties.maxval,
- "step", &currentAlsaCtl->alsaCtlProperties.step)) {
+ else if(wrap_json_unpack(returnedJ, "{s:{s:{s?:i s?:i s?:i s?:i s?:i}}}",
+ "response",
+ "ctl",
+ "type", (int *) &currentAlsaCtl->alsaCtlProperties.type,
+ "count", &currentAlsaCtl->alsaCtlProperties.count,
+ "min", &currentAlsaCtl->alsaCtlProperties.minval,
+ "max", &currentAlsaCtl->alsaCtlProperties.maxval,
+ "step", &currentAlsaCtl->alsaCtlProperties.step)) {
AFB_ApiError(apiHandle,
"Didn't succeed to get control %i properties on device '%s' : '%s'",
currentAlsaCtl->numid,
cardId,
json_object_get_string(returnedJ));
- return -9;
+ err = -9;
}
- return 0;
+ if(returnedJ)
+ json_object_put(returnedJ);
+
+ return err;
}
int HalCtlsSetAlsaCtlValue(AFB_ApiT apiHandle, char *cardId, int ctlId, json_object *valuesJ)
{
+ int err = 0;
+
char *returnedStatus = NULL, *returnedInfo = NULL;
enum CallError returnedError;
- json_object *queryJ, *returnedJ, *returnedWarningJ;
+ json_object *queryJ, *returnedJ = NULL, *returnedWarningJ;
if(! apiHandle) {
AFB_ApiError(apiHandle, "%s: api handle not available", __func__);
@@ -297,28 +310,32 @@ int HalCtlsSetAlsaCtlValue(AFB_ApiT apiHandle, char *cardId, int ctlId, json_obj
ALSACORE_API,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- return 1;
+ err = 1;
}
-
- if(! wrap_json_unpack(returnedJ, "{s:{s:o}}", "request", "info", &returnedWarningJ)) {
+ else if(! wrap_json_unpack(returnedJ, "{s:{s:o}}", "request", "info", &returnedWarningJ)) {
AFB_ApiError(apiHandle,
"Warning raised during call to verb %s of %s api : '%s'",
ALSACORE_CTLSET_VERB,
ALSACORE_API,
json_object_get_string(returnedWarningJ));
- return 2;
+ err = 2;
}
- return 0;
+ if(returnedJ)
+ json_object_put(returnedJ);
+
+ return err;
}
int HalCtlsCreateAlsaCtl(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *alsaCtlToCreate)
{
+ int err = 0;
+
char *returnedStatus = NULL, *returnedInfo = NULL;
enum CallError returnedError;
- json_object *queryJ, *returnedJ, *returnedWarningJ, *responseJ;
+ json_object *queryJ, *returnedJ = NULL, *returnedWarningJ, *responseJ;
if(! apiHandle) {
AFB_ApiError(apiHandle, "%s: api handle not available", __func__);
@@ -360,16 +377,15 @@ int HalCtlsCreateAlsaCtl(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
ALSACORE_API,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- return -5;
+ err = -5;
}
-
- if(! wrap_json_unpack(returnedJ, "{s:{s:o}}", "request", "info", &returnedWarningJ)) {
+ else if(! wrap_json_unpack(returnedJ, "{s:{s:o}}", "request", "info", &returnedWarningJ)) {
AFB_ApiError(apiHandle,
"Warning raised during call to verb %s of %s api : '%s'",
ALSACORE_GETINFO_VERB,
ALSACORE_API,
json_object_get_string(returnedWarningJ));
- return -6;
+ err = -6;
}
else if(wrap_json_unpack(returnedJ, "{s:o}", "response", &responseJ)) {
AFB_ApiError(apiHandle,
@@ -377,20 +393,23 @@ int HalCtlsCreateAlsaCtl(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
ALSACORE_GETINFO_VERB,
ALSACORE_API,
json_object_get_string(returnedJ));
- return -7;
+ err = -7;
}
else if(wrap_json_unpack(responseJ, "{s:i}", "id", &alsaCtlToCreate->numid)) {
AFB_ApiError(apiHandle,
"Can't get create id from %s of %s api",
ALSACORE_GETINFO_VERB,
ALSACORE_API);
- return -8;
+ err = -8;
}
else if(wrap_json_unpack(responseJ, "{s:o}", "ctl", NULL)) {
AFB_ApiWarning(apiHandle, "Control %s was already present but has been updated", alsaCtlToCreate->name);
}
- return 0;
+ if(returnedJ)
+ json_object_put(returnedJ);
+
+ return err;
}
/*******************************************************************************
@@ -481,10 +500,11 @@ void HalCtlsActionOnAlsaCtl(AFB_ReqT request)
currentAlsaCtl->ctl.numid,
cardIdString,
json_object_get_string(requestJson));
+ json_object_put(convertedJ);
return;
}
- json_object_put(convertedJ);
-
AFB_ReqSuccess(request, NULL, "Action on alsa control correclty done");
+
+ json_object_put(convertedJ);
} \ No newline at end of file
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 07ec9cc..f560c7c 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -222,7 +222,9 @@ int HalCtlsProcessOneHalMapObject(AFB_ApiT apiHandle, struct CtlHalAlsaMap *alsa
int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaMap *alsaMap)
{
- json_object *valueJ, *convertedValueJ;
+ int err;
+
+ json_object *valueJ, *convertedValueJ = NULL;
if(alsaMap->ctl.alsaCtlCreation) {
if(HalCtlsCreateAlsaCtl(apiHandle, cardId, &alsaMap->ctl)) {
@@ -242,20 +244,28 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal
if(alsaMap->ctl.value) {
// TBD JAI : handle alsa controls type
valueJ = json_object_new_int(alsaMap->ctl.value);
+ err = 0;
if(HalCtlsNormalizeJsonValues(apiHandle, &alsaMap->ctl.alsaCtlProperties, valueJ, &convertedValueJ)) {
AFB_ApiError(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ));
- return -3;
+ err = -3;
}
-
- if(HalCtlsSetAlsaCtlValue(apiHandle, cardId, alsaMap->ctl.numid, convertedValueJ)) {
+ 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));
- return -4;
+ err = -4;
}
+
+ json_object_put(valueJ);
+
+ if(convertedValueJ)
+ json_object_put(convertedValueJ);
+
+ if(err)
+ return err;
}
if(alsaMap->actionJ) {
@@ -390,7 +400,7 @@ void HalCtlsActionOnCall(AFB_ReqT request)
struct SpecificHalData *currentCtlHalData;
struct CtlHalMixerData *currentMixerData;
- json_object *requestJson, *returnJ, *toReturnJ;
+ json_object *requestJson, *returnJ = NULL, *toReturnJ;
apiHandle = (AFB_ApiT) afb_request_get_dynapi(request);
if(! apiHandle) {
@@ -443,7 +453,7 @@ void HalCtlsActionOnCall(AFB_ReqT request)
}
else if(wrap_json_unpack(returnJ, "{s:o}", "response", &toReturnJ)) {
AFB_ReqSuccessF(request,
- returnJ,
+ json_object_get(returnJ),
"%s: Seems that %s call to api %s succeed, but no response was found : '%s'",
__func__,
currentMixerData->verbToCall,
@@ -452,11 +462,14 @@ void HalCtlsActionOnCall(AFB_ReqT request)
}
else {
AFB_ReqSuccessF(request,
- toReturnJ,
+ json_object_get(toReturnJ),
"Action %s correctly transferred to %s without any error raised",
currentMixerData->verbToCall,
apiToCall);
}
+
+ if(returnJ)
+ json_object_put(returnJ);
}
json_object *HalCtlsGetJsonArrayForMixerDataTable(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentMixerDataT, enum MixerDataType dataType)
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
index 082de3a..b192374 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
@@ -177,7 +177,7 @@ int HalCtlsHandleMixerAttachResponse(AFB_ApiT apiHandle, struct CtlHalSpecificDa
int HalCtlsAttachToMixer(AFB_ApiT apiHandle)
{
- unsigned int err;
+ int err = 0, mixerError;
char *apiToCall, *returnedStatus = NULL, *returnedInfo = NULL;
@@ -188,7 +188,7 @@ int HalCtlsAttachToMixer(AFB_ApiT apiHandle)
struct SpecificHalData *currentCtlHalData, *concurentHalData = NULL;
struct SpecificHalData **firstHalData;
- json_object *returnJ, *toReturnJ;
+ json_object *returnJ = NULL, *toReturnJ;
if(! apiHandle) {
AFB_ApiError(apiHandle, "%s: Can't get current hal api handle", __func__);
@@ -246,21 +246,28 @@ int HalCtlsAttachToMixer(AFB_ApiT apiHandle)
MIXER_ATTACH_VERB,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- return -7;
+ err = -7;
}
- else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)) {
- err = HalCtlsHandleMixerAttachResponse(apiHandle, currentCtlHalData->ctlHalSpecificData, toReturnJ);
- if(err != (int) MIXER_NO_ERROR) {
- AFB_ApiError(apiHandle,
- "%s: Seems that %s call to api %s succeed but this warning was risen by response decoder : %i '%s'",
- __func__,
- MIXER_ATTACH_VERB,
- apiToCall,
- err,
- json_object_get_string(toReturnJ));
- return -8;
- }
-
+ else if(! json_object_object_get_ex(returnJ, "response", &toReturnJ)) {
+ AFB_ApiError(apiHandle,
+ "%s: Seems that %s call to api %s succeed, but response is not valid : '%s'",
+ __func__,
+ MIXER_ATTACH_VERB,
+ apiToCall,
+ json_object_get_string(returnJ));
+ err = -8;
+ }
+ else if((mixerError = HalCtlsHandleMixerAttachResponse(apiHandle, currentCtlHalData->ctlHalSpecificData, toReturnJ)) != (int) MIXER_NO_ERROR) {
+ AFB_ApiError(apiHandle,
+ "%s: Seems that %s call to api %s succeed but this warning was risen by response decoder : %i '%s'",
+ __func__,
+ MIXER_ATTACH_VERB,
+ apiToCall,
+ mixerError,
+ json_object_get_string(toReturnJ));
+ err = -9;
+ }
+ else {
AFB_ApiNotice(apiHandle,
"%s: Seems that %s call to api %s succeed with no warning raised : '%s'",
__func__,
@@ -270,21 +277,17 @@ int HalCtlsAttachToMixer(AFB_ApiT apiHandle)
currentCtlHalData->status = HAL_STATUS_READY;
}
- else {
- AFB_ApiError(apiHandle,
- "%s: Seems that %s call to api %s succeed, but response is not valid : '%s'",
- __func__,
- MIXER_ATTACH_VERB,
- apiToCall,
- json_object_get_string(returnJ));
- return -9;
- }
- return 0;
+ if(returnJ)
+ json_object_put(returnJ);
+
+ return err;
}
int HalCtlsGetInfoFromMixer(AFB_ApiT apiHandle, char *apiToCall, json_object *requestJson, json_object **toReturnJ, char **returnedStatus, char **returnedInfo)
{
+ int err = 0;
+
enum CallError returnedError;
json_object *returnJ, *responseJ;
@@ -313,9 +316,18 @@ int HalCtlsGetInfoFromMixer(AFB_ApiT apiHandle, char *apiToCall, json_object *re
MIXER_INFO_VERB,
*returnedStatus ? *returnedStatus : "not returned",
*returnedInfo ? *returnedInfo : "not returned");
- return -4;
+ err = -4;
+ }
+ else if(! json_object_object_get_ex(returnJ, "response", &responseJ)) {
+ AFB_ApiError(apiHandle,
+ "%s: Seems that %s call to api %s succeed, but response is not valid : '%s'",
+ __func__,
+ MIXER_INFO_VERB,
+ apiToCall,
+ json_object_get_string(returnJ));
+ err = -5;
}
- else if(json_object_object_get_ex(returnJ, "response", &responseJ)) {
+ else {
AFB_ApiNotice(apiHandle,
"%s: Seems that %s call to api %s succeed with no warning raised : '%s'",
__func__,
@@ -323,17 +335,9 @@ int HalCtlsGetInfoFromMixer(AFB_ApiT apiHandle, char *apiToCall, json_object *re
apiToCall,
json_object_get_string(responseJ));
- *toReturnJ = responseJ;
- }
- else {
- AFB_ApiError(apiHandle,
- "%s: Seems that %s call to api %s succeed, but response is not valid : '%s'",
- __func__,
- MIXER_INFO_VERB,
- apiToCall,
- json_object_get_string(returnJ));
- return -8;
+ *toReturnJ = json_object_get(responseJ);
}
- return 0;
+ json_object_put(returnJ);
+ return err;
} \ No newline at end of file
diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
index c33f90d..364c492 100644
--- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
@@ -49,7 +49,7 @@ struct CtlHalMixerDataT {
unsigned int count;
};
-// Structure to store specific controller hal data
+// Structure to store specific controller hal data
struct CtlHalSpecificData {
char *mixerApiName;
char *prefix;