summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c108
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.h1
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c27
-rw-r--r--src/4a-internals-hal/4a-internals-hal-mixer-link.c36
-rw-r--r--src/4a-internals-hal/4a-internals-hal-mixer-link.h12
5 files changed, 131 insertions, 53 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
index 806387a..9e03f33 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
@@ -291,14 +291,66 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
return createdStreamData;
}
+int HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(afb_api_t apiHandle,
+ struct InternalHalMixerData *toRemoveStreamData)
+{
+ int returnedErr, wrapRet;
+
+ json_object *streamRemovedEventJ;
+
+ CtlConfigT *ctrlConfig;
+
+ struct HalData *currentHalData;
+
+ if(! apiHandle || ! toRemoveStreamData)
+ return -1;
+
+ ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle);
+ if(! ctrlConfig)
+ return -2;
+
+ currentHalData = (struct HalData *) getExternalData(ctrlConfig);
+ if((! currentHalData) ||
+ (! currentHalData->internalHalData) ||
+ (! currentHalData->internalHalData->streamsData) ||
+ (! currentHalData->internalHalData->streamUpdates))
+ return -3;
+
+ if(afb_api_del_verb(apiHandle, toRemoveStreamData->verb, NULL)) {
+ AFB_API_ERROR(apiHandle,"Error while deleting verb for stream : '%s'", toRemoveStreamData->verb);
+ return -4;
+ }
+
+ wrapRet = wrap_json_pack(&streamRemovedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "removed",
+ "name", toRemoveStreamData->verb,
+ "cardId", toRemoveStreamData->streamCardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,"Didn't succeed to allocate removed stream event json object");
+ return -5;
+ }
+
+ returnedErr = HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, toRemoveStreamData);
+ if(returnedErr) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i while removing data for stream",
+ returnedErr);
+ json_object_put(streamRemovedEventJ);
+ return -6;
+ }
+
+ afb_event_push(currentHalData->internalHalData->streamUpdates, streamRemovedEventJ);
+
+ return 0;
+}
+
int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
char *verb,
char *verbToCall,
char *streamCardId)
{
- int returnedErr = 0, wrapRet;
-
- json_object *streamRemovedEventJ;
+ int returnedErr;
CtlConfigT *ctrlConfig;
@@ -324,30 +376,42 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
if(! toRemoveStreamData)
return -4;
- if(afb_api_del_verb(apiHandle, verb, NULL)) {
- AFB_API_ERROR(apiHandle,"Error while deleting verb for stream : '%s'", verb);
- json_object_put(streamRemovedEventJ);
+ returnedErr = HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(apiHandle,
+ toRemoveStreamData);
+ if(returnedErr) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i while removing verb and data for stream : '%s'",
+ returnedErr,
+ verb);
return -5;
}
- returnedErr = HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, toRemoveStreamData);
- if(returnedErr) {
- AFB_API_ERROR(apiHandle,"Error %i while removing data for stream : '%s'", returnedErr, verb);
- json_object_put(streamRemovedEventJ);
- return -6;
- }
+ return 0;
+}
- wrapRet = wrap_json_pack(&streamRemovedEventJ,
- "{s:s, s:s, s:s}",
- "action", "removed",
- "name", toRemoveStreamData->verb,
- "cardId", toRemoveStreamData->streamCardId);
- if(wrapRet) {
- AFB_API_ERROR(apiHandle,"Didn't succeed to allocate removed stream event json object");
- return -7;
- }
+int HalUtlRemoveAllStreamsDataAndDeleteAllStreamsVerb(afb_api_t apiHandle)
+{
+ CtlConfigT *ctrlConfig;
- afb_event_push(currentHalData->internalHalData->streamUpdates, streamRemovedEventJ);
+ struct HalData *currentHalData;
+
+ if(! apiHandle)
+ return -1;
+
+ ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle);
+ if(! ctrlConfig)
+ return -2;
+
+ currentHalData = (struct HalData *) getExternalData(ctrlConfig);
+ if((! currentHalData) ||
+ (! currentHalData->internalHalData))
+ return -3;
+
+ while(currentHalData->internalHalData->streamsData) {
+ if(HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(apiHandle,
+ currentHalData->internalHalData->streamsData))
+ return -4;
+ }
return 0;
} \ No newline at end of file
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.h b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.h
index e6f0d99..3345da3 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.h
@@ -43,5 +43,6 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
char *verb,
char *verbToCall,
char *streamCardId);
+int HalUtlRemoveAllStreamsDataAndDeleteAllStreamsVerb(afb_api_t apiHandle);
#endif /* _HAL_UTILITIES_HAL_STREAMS_CREATION_INCLUDE_ */ \ No newline at end of file
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 4c5fb68..10ed6c0 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -338,6 +338,7 @@ int InternalHalProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, stru
struct InternalHalAlsaMap *ctlMaps;
+ json_object *currentAlsaMapJ;
json_type alsaMapType;
alsaMapType = json_object_get_type(AlsaMapJ);
@@ -363,8 +364,18 @@ int InternalHalProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, stru
return -2;
}
- for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++)
- err += InternalHalProcessOneHalMapObject(apiHandle, &ctlMaps[idx], alsaMapType == json_type_array ? json_object_array_get_idx(AlsaMapJ, idx) : AlsaMapJ);
+ for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++) {
+ currentAlsaMapJ = (alsaMapType == json_type_array) ? json_object_array_get_idx(AlsaMapJ, idx) : AlsaMapJ;
+ err = InternalHalProcessOneHalMapObject(apiHandle, &ctlMaps[idx], currentAlsaMapJ);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to proccess halmap object %i ('%s')",
+ idx,
+ json_object_get_string(currentAlsaMapJ));
+ HalUtlFreeAlsaCtlsMap(currentInternalHalAlsaMapT);
+ return -3;
+ }
+ }
currentInternalHalAlsaMapT->ctls = ctlMaps;
@@ -381,8 +392,16 @@ int InternalHalHandleAllHalMap(afb_api_t apiHandle, int sndCardId, struct Intern
InternalHalSubscribeToAlsaCardEvent(apiHandle, cardIdString);
- for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++)
- err += InternalHalHandleOneHalMapObject(apiHandle, cardIdString, &currentInternalHalAlsaMapT->ctls[idx]);
+ for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++) {
+ err = InternalHalHandleOneHalMapObject(apiHandle, cardIdString, &currentInternalHalAlsaMapT->ctls[idx]);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to handle halmap object %i ('%s')",
+ idx,
+ json_object_get_string(currentInternalHalAlsaMapT->ctls[idx].actionJ));
+ return -3;
+ }
+ }
return err;
}
diff --git a/src/4a-internals-hal/4a-internals-hal-mixer-link.c b/src/4a-internals-hal/4a-internals-hal-mixer-link.c
index 96f3e89..d5b9be9 100644
--- a/src/4a-internals-hal/4a-internals-hal-mixer-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-mixer-link.c
@@ -40,7 +40,6 @@ int InternalHalHandleMixerData(afb_api_t apiHandle,
json_object *currentDataJ)
{
int idx, mixerDataNb, verbStart, size;
- int err = (int) MIXER_NO_ERROR;
char *currentDataVerbName, *currentStreamCardId;
@@ -60,7 +59,7 @@ int InternalHalHandleMixerData(afb_api_t apiHandle,
default:
mixerDataNb = 0;
AFB_API_ERROR(apiHandle, "No data returned");
- return (int) MIXER_ERROR_DATA_EMPTY;
+ return -1;
}
for(idx = 0; idx < mixerDataNb; idx++) {
@@ -71,11 +70,11 @@ int InternalHalHandleMixerData(afb_api_t apiHandle,
if(wrap_json_unpack(currentJ, "{s:s}", "verb", &currentDataVerbName)) {
AFB_API_ERROR(apiHandle, "Can't find verb in current data object");
- err += (int) MIXER_ERROR_DATA_NAME_UNAVAILABLE;
+ return -2;
}
else if(wrap_json_unpack(currentJ, "{s:s}", "alsa", &currentStreamCardId)) {
AFB_API_ERROR(apiHandle, "Can't find card id in current data object");
- err += (int) MIXER_ERROR_DATA_CARDID_UNAVAILABLE;
+ return -3;
}
else {
size = (int) strlen(currentDataVerbName);
@@ -96,36 +95,43 @@ int InternalHalHandleMixerData(afb_api_t apiHandle,
AFB_API_ERROR(apiHandle,
"Error while adding stream '%s'",
currentDataVerbName);
- err += (int) MIXER_ERROR_STREAM_NOT_ADDED;
+ HalUtlRemoveAllStreamsDataAndDeleteAllStreamsVerb(apiHandle);
+ return -4;
}
}
}
- return err;
+ return 0;
}
int InternalHalHandleMixerAttachResponse(afb_api_t apiHandle, struct InternalHalData *currentHalSpecificData, json_object *mixerResponseJ)
{
- int err = (int) MIXER_NO_ERROR;
+ int err;
json_object *mixerStreamsJ = NULL;
if(! apiHandle) {
AFB_API_ERROR(apiHandle, "Can't get current hal api handle");
- return (int) MIXER_ERROR_API_UNAVAILABLE;
+ return -1;
}
if(wrap_json_unpack(mixerResponseJ,
"{s?:o}",
"streams", &mixerStreamsJ)) {
AFB_API_ERROR(apiHandle, "Can't get streams object in '%s'", json_object_get_string(mixerResponseJ));
- return (int) MIXER_ERROR_DATA_UNAVAILABLE;
+ return -2;
}
if(mixerStreamsJ) {
- err += InternalHalHandleMixerData(apiHandle, &currentHalSpecificData->streamsData, mixerStreamsJ);
- if(err)
- AFB_API_ERROR(apiHandle, "Error during handling response mixer streams data '%s'", json_object_get_string(mixerStreamsJ));
+ err = InternalHalHandleMixerData(apiHandle, &currentHalSpecificData->streamsData, mixerStreamsJ);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i during handling response mixer streams data '%s'",
+ err,
+ json_object_get_string(mixerStreamsJ));
+ HalUtlRemoveAllMixerData(&currentHalSpecificData->streamsData);
+ return -3;
+ }
}
if(! currentHalSpecificData->streamsData) {
@@ -140,10 +146,10 @@ int InternalHalHandleMixerAttachResponse(afb_api_t apiHandle, struct InternalHal
0,
0)) {
AFB_API_ERROR(apiHandle, "Error while creating verb for all streams : '%s'", HAL_ALL_STREAMS_VERB);
- return (int) MIXER_ERROR_ALL_STREAMS_VERB_NOT_CREATED;
+ return -4;
}
- return err;
+ return 0;
}
int InternalHalAttachToMixer(afb_api_t apiHandle)
@@ -218,7 +224,7 @@ int InternalHalAttachToMixer(afb_api_t apiHandle)
}
else {
mixerError = InternalHalHandleMixerAttachResponse(apiHandle, currentHalData->internalHalData, responseJ);
- if(mixerError != (int) MIXER_NO_ERROR) {
+ if(mixerError) {
AFB_API_ERROR(apiHandle,
"Seems that %s call to api %s succeed but this warning was risen by response decoder : %i '%s'",
MIXER_ATTACH_VERB,
diff --git a/src/4a-internals-hal/4a-internals-hal-mixer-link.h b/src/4a-internals-hal/4a-internals-hal-mixer-link.h
index cc069fc..7132aca 100644
--- a/src/4a-internals-hal/4a-internals-hal-mixer-link.h
+++ b/src/4a-internals-hal/4a-internals-hal-mixer-link.h
@@ -33,18 +33,6 @@
#define HAL_ALL_STREAMS_VERB "all-streams"
-// Enum for the type of error detected
-enum MixerStatus {
- MIXER_NO_ERROR=0,
- MIXER_ERROR_API_UNAVAILABLE=-1,
- MIXER_ERROR_DATA_UNAVAILABLE=-2,
- MIXER_ERROR_DATA_EMPTY =-3,
- MIXER_ERROR_ALL_STREAMS_VERB_NOT_CREATED =-4,
- MIXER_ERROR_DATA_NAME_UNAVAILABLE=-10,
- MIXER_ERROR_DATA_CARDID_UNAVAILABLE=-100,
- MIXER_ERROR_STREAM_NOT_ADDED =-1000
-};
-
// Internals HAL handle mixer calls functions
int InternalHalAttachToMixer(afb_api_t apiHandle);
int InternalHalGetInfoFromMixer(afb_api_t apiHandle,