summaryrefslogtreecommitdiffstats
path: root/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-08 10:34:32 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:52:51 +0200
commitbb223de50300ff4fcf2e7063bdf5e64334cf26fb (patch)
treead234e38c7a73f380c838402ad4adc339e8b9c53 /4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
parentb04d49861f2f2960c467e85d0719e1b4857b6722 (diff)
Change the way to get card id using its path
Change the way to get card id using its path by returning directly the found card id. Corrects a typo in alsa core link header. Change-Id: Ib202632e049921a57428b31a29f7def4d9e78aaa Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c50
1 files changed, 25 insertions, 25 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 366de0f..f3c1388 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
@@ -30,50 +30,50 @@
* HAL controllers alsacore calls funtions *
******************************************************************************/
-bool HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, struct SpecificHalData *currentCtlHalData)
+int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath)
{
- int *cardId;
+ int cardId = -1;
- char *cardIdString = NULL;
- char **returnedStatus, **returnedInfo;
+ char *returnedStatus = NULL, *returnedInfo = NULL, *cardIdString = NULL;
enum CallError returnedError;
json_object *toSendJ, *returnJ, *responsJ, *devidJ;
- cardId = alloca(sizeof(int));
- *cardId = -1;
+ if(! apiHandle) {
+ AFB_ApiError(apiHandle, "%s: api handle not available", __func__);
+ return -1;
+ }
+
+ if(! devPath) {
+ AFB_ApiError(apiHandle, "%s: dev path is not available", __func__);
+ return -2;
+ }
- wrap_json_pack(&toSendJ, "{s:s}", "devpath", currentCtlHalData->sndCard);
+ wrap_json_pack(&toSendJ, "{s:s}", "devpath", devPath);
if(AFB_ServiceSync(apiHandle, ALSACORE_API, ALSACORE_GETINFO_VERB, toSendJ, &returnJ)) {
- returnedStatus = alloca(sizeof(char *));
- returnedInfo = alloca(sizeof(char *));
-
- returnedError = HalUtlHandleAppFwCallError(apiHandle, ALSACORE_API, ALSACORE_GETINFO_VERB, returnJ, returnedStatus, returnedInfo);
+ returnedError = HalUtlHandleAppFwCallError(apiHandle, ALSACORE_API, ALSACORE_GETINFO_VERB, returnJ, &returnedStatus, &returnedInfo);
AFB_ApiWarning(apiHandle,
- "Error %i during call to verb %s of %s api",
- (int) returnedError,
- ALSACORE_GETINFO_VERB,
- ALSACORE_API);
+ "Error %i during call to verb %s of %s api with status '%s' and info '%s'",
+ (int) returnedError,
+ ALSACORE_GETINFO_VERB,
+ ALSACORE_API,
+ returnedStatus ? returnedStatus : "not returned",
+ returnedInfo ? returnedInfo : "not returned");
}
else if(json_object_object_get_ex(returnJ, "response", &responsJ)) {
if(json_object_object_get_ex(responsJ, "devid", &devidJ) && json_object_is_type(devidJ, json_type_string)) {
cardIdString = (char *) json_object_get_string(devidJ);
- if(sscanf(cardIdString, "hw:%i", cardId) <= 0)
+ if(sscanf(cardIdString, "hw:%i", &cardId) <= 0) {
AFB_ApiWarning(apiHandle, "Couldn't get valid devid from string: '%s'", cardIdString);
+ cardId = -2;
+ }
}
else {
AFB_ApiWarning(apiHandle, "Response devid is not present/valid");
}
-
- currentCtlHalData->sndCardId = *cardId;
-
- return true;
}
- currentCtlHalData->sndCardId = *cardId;
-
- return false;
-}
-
+ return cardId;
+} \ No newline at end of file