aboutsummaryrefslogtreecommitdiffstats
path: root/alsa-binding/Alsa-SetGet.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-08-19 11:26:47 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-08-19 11:48:24 +0200
commitb30eb2b2d8f83f29874e2d63dd752e9cf296da37 (patch)
tree3aa0841eb34c5c6820233aa367d7e6d9d35520a2 /alsa-binding/Alsa-SetGet.c
parent9340d0d65822ece34aa8fd7cabac0315ae7c93c3 (diff)
Make a function to get card number from card path
Make a function to get card number from card path, will be needed to for added/removed card events. Bug-AGL: SPEC-2749 Change-Id: Ic0cc6fd84a54432c696892772f2f66d1bde59a65 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'alsa-binding/Alsa-SetGet.c')
-rw-r--r--alsa-binding/Alsa-SetGet.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c
index e8c6563..8c189de 100644
--- a/alsa-binding/Alsa-SetGet.c
+++ b/alsa-binding/Alsa-SetGet.c
@@ -345,14 +345,43 @@ STATIC json_object *decodeTlv(unsigned int *tlv, unsigned int tlv_size, int mode
return (decodeTlvJson);
}
-STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardToProbe)
-{
- int err, cardPathFileId;
+PUBLIC int getCardNbFromCardPath(char *cardPath) {
+ int err, cardPathFileFd, fileCardId;
snd_ctl_card_info_t *currentCardInfo;
+ if (! cardPath)
+ return -1;
+
+ cardPathFileFd = open(cardPath, O_RDONLY);
+ if (cardPathFileFd < 0) {
+ AFB_ERROR("CardPath '%s' error %i during open", cardPath, cardPathFileFd);
+ return -2;
+ }
+
snd_ctl_card_info_alloca(&currentCardInfo);
+ err = ioctl(cardPathFileFd, SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), currentCardInfo);
+ close(cardPathFileFd);
+ if (err < 0) {
+ AFB_ERROR("CardPath '%s' error %i during ioctl", cardPath, err);
+ return -3;
+ }
+
+ fileCardId = snd_ctl_card_info_get_card(currentCardInfo);
+
+ if (fileCardId < 0 || fileCardId >= MAX_SND_CARD) {
+ AFB_ERROR("CardPath '%s' returned an incorrect card number %i", cardPath, fileCardId);
+ return -4;
+ }
+
+ return fileCardId;
+}
+
+STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardToProbe)
+{
+ int err;
+
if(! queryInfo) {
AFB_ERROR("Structure to look for an ALSA card is NULL");
return -1;
@@ -381,31 +410,18 @@ STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardTo
}
if(queryInfo->cardPath) {
- cardPathFileId = open(queryInfo->cardPath, O_RDONLY);
- if(cardPathFileId < 0) {
- AFB_ERROR("CardPath '%s' error %i during open", queryInfo->cardPath, cardPathFileId);
- return -4;
- }
+ *cardToProbe = getCardNbFromCardPath(queryInfo->cardPath);
- err = ioctl(cardPathFileId, SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), currentCardInfo);
- close(cardPathFileId);
-
- *cardToProbe = snd_ctl_card_info_get_card(currentCardInfo);
-
- if(err < 0) {
- AFB_ERROR("CardPath '%s' error %i during ioctl", queryInfo->cardPath, err);
- return -5;
- }
- else if(*cardToProbe < 0 || *cardToProbe >= MAX_SND_CARD) {
+ if(*cardToProbe < 0 || *cardToProbe >= MAX_SND_CARD) {
AFB_ERROR("CardPath '%s' returned an incorrect card number %i", queryInfo->cardPath, *cardToProbe);
- return -6;
+ return -4;
}
else if(queryInfo->cardNb != NO_CARD_SELECTED && *cardToProbe != queryInfo->cardNb) {
AFB_WARNING("CardPath '%s' (id %i) is not corresponding to the requested card number %i",
queryInfo->cardPath,
*cardToProbe,
queryInfo->cardNb);
- return -7;
+ return -5;
}
queryInfo->cardNb = *cardToProbe;
@@ -417,12 +433,12 @@ STATIC int searchInQueryForAlsaCardToProbe(queryCardInfo *queryInfo, int *cardTo
err = snd_card_next(cardToProbe);
if(err < 0) {
AFB_ERROR("Error %i happened when tried to get next ALSA card number", err);
- return -8;
+ return -6;
}
if(*cardToProbe < 0) {
AFB_NOTICE("No ALSA card connected");
- return -9;
+ return -7;
}
return 1;