aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c50
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h38
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c8
3 files changed, 49 insertions, 47 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
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
index 0c24e4f..bae8291 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
@@ -1,22 +1,22 @@
/*
- * Copyright (C) 2018 "IoT.bzh"
- * Author Jonathan Aillet <jonathan.aillet@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright (C) 2018 "IoT.bzh"
+* Author Jonathan Aillet <jonathan.aillet@iot.bzh>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
-#ifndef HAL_CTLS_ALSACORE_LINK_INCLUDE_
-#define HAL_CTLS_ALSACORE_LINK_INCLUDE_
+#ifndef _HAL_CTLS_ALSACORE_LINK_INCLUDE_
+#define _HAL_CTLS_ALSACORE_LINK_INCLUDE_
#include <stdio.h>
#include <stdbool.h>
@@ -25,6 +25,6 @@
#define ALSACORE_GETINFO_VERB "infoget"
// HAL controllers alsacore calls funtions
-bool HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, struct SpecificHalData *currentCtlHalData);
+int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath);
-#endif /* HAL_CTLS_ALSACORE_LINK_INCLUDE_ */ \ No newline at end of file
+#endif /* _HAL_CTLS_ALSACORE_LINK_INCLUDE_ */ \ No newline at end of file
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
index e634521..e11f989 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c
@@ -105,10 +105,12 @@ static int HalCtlsInitOneApi(AFB_ApiT apiHandle)
currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.count = 0;
- if(HalCtlsGetCardIdByCardPath(apiHandle, currentCtlHalData))
- currentCtlHalData->status = HAL_STATUS_AVAILABLE;
- else
+ currentCtlHalData->sndCardId = HalCtlsGetCardIdByCardPath(apiHandle, currentCtlHalData->sndCard);
+
+ if(currentCtlHalData->sndCardId < 0)
currentCtlHalData->status = HAL_STATUS_UNAVAILABLE;
+ else
+ currentCtlHalData->status = HAL_STATUS_AVAILABLE;
// TBD JAI: handle refresh of hal status for dynamic card (/dev/by-id)