diff options
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-alsacore-link.c | 58 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-alsacore-link.h | 1 |
2 files changed, 37 insertions, 22 deletions
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 db9e9b4..902e5ad 100644 --- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c +++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c @@ -69,12 +69,43 @@ snd_ctl_elem_type_t InternalHalMapsAlsaTypeToEnum(const char *label) * Internals HAL - Alsacore calls funtions * ******************************************************************************/ -int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath) +int InternalHalGetCardInfo(afb_api_t apiHandle, json_object *requestJ, json_object **responseJ) { - int errorToReturn, cardId, wrapRet; + int errorToReturn = 0; char *returnedError = NULL, *returnedInfo = NULL; + if(! apiHandle || ! requestJ || ! responseJ) { + AFB_API_ERROR(apiHandle, "Invalid argument(s)"); + return -1; + } + + if(afb_api_call_sync(apiHandle, + ALSACORE_API, + ALSACORE_GETINFO_VERB, + requestJ, + responseJ, + &returnedError, + &returnedInfo)) { + AFB_API_ERROR(apiHandle, + "Something went wrong during call to verb '%s' of api '%s' with error '%s' and info '%s'", + ALSACORE_GETINFO_VERB, + ALSACORE_API, + returnedError ? returnedError : "none", + returnedInfo ? returnedInfo : "none"); + errorToReturn = -2; + } + + free(returnedError); + free(returnedInfo); + + return errorToReturn; +} + +int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath) +{ + int errorToReturn, cardId, wrapRet; + json_object *toSendJ, *responseJ = NULL; if(! apiHandle) { @@ -93,26 +124,12 @@ int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath) return -3; } - if(afb_api_call_sync(apiHandle, - ALSACORE_API, - ALSACORE_GETINFO_VERB, - toSendJ, - &responseJ, - &returnedError, - &returnedInfo)) { - AFB_API_ERROR(apiHandle, - "Something went wrong during call to verb '%s' of api '%s' with error '%s' and info '%s'", - ALSACORE_GETINFO_VERB, - ALSACORE_API, - returnedError ? returnedError : "not returned", - returnedInfo ? returnedInfo : "not returned"); + if(InternalHalGetCardInfo(apiHandle, toSendJ, &responseJ)) { + AFB_API_ERROR(apiHandle, "Something went tried to get card information (using devpath : '%s')", devPath); errorToReturn = -4; } else if(! responseJ) { - AFB_API_ERROR(apiHandle, - "Seems that %s call to api %s succeed but no response was returned", - ALSACORE_GETINFO_VERB, - ALSACORE_API); + AFB_API_ERROR(apiHandle, "Seems that no response was returned when tried to get card info"); errorToReturn = -5; } else if(! json_object_is_type(responseJ, json_type_object)) { @@ -133,9 +150,6 @@ int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath) if(responseJ) json_object_put(responseJ); - free(returnedError); - free(returnedInfo); - return errorToReturn; } diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.h b/src/4a-internals-hal/4a-internals-hal-alsacore-link.h index 065e017..9641c7c 100644 --- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.h +++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.h @@ -41,6 +41,7 @@ snd_ctl_elem_type_t InternalHalMapsAlsaTypeToEnum(const char *label); // Internals HAL alsacore calls funtions +int InternalHalGetCardInfo(afb_api_t apiHandle, json_object *requestJ, json_object **responseJ); int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath); int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId); int InternalHalUpdateAlsaCtlProperties(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *currentAlsaCtl); |