summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c144
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.h26
2 files changed, 142 insertions, 28 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 65ff96d..c1078a9 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -546,7 +546,7 @@ int InternalHalHandleOneHalDependencies(afb_api_t apiHandle, struct InternalHalP
int InternalHalHandleHalDependencies(afb_api_t apiHandle,
struct HalData *currentHalData,
struct cds_list_head *halDevicesToProbeListHead,
- enum DependenciesHandlingType dependenciesHandlingType,
+ enum DependencySelectionType dependencySelectionType,
char *uid)
{
int ret, validatedDepedency, validatedDependenciesNumber = 0;
@@ -563,7 +563,7 @@ int InternalHalHandleHalDependencies(afb_api_t apiHandle,
return 0;
}
- if(dependenciesHandlingType == UID_CORRESPONDING_DEPENDENCIES &&
+ if(dependencySelectionType == UID_CORRESPONDING_DEPENDENCIES &&
! uid) {
AFB_API_ERROR(apiHandle, "Invalid uid");
return -2;
@@ -572,7 +572,7 @@ int InternalHalHandleHalDependencies(afb_api_t apiHandle,
cds_list_for_each_entry(halCurrentDeviceToProbe, halDevicesToProbeListHead, node) {
validatedDepedency = 0;
- switch(dependenciesHandlingType) {
+ switch(dependencySelectionType) {
case ALL_DEPENDENCIES:
validatedDepedency = 1;
break;
@@ -1117,22 +1117,71 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, struct InternalHalAlsa
return 0;
}
-int InternalHalHandleSelectedHalMapWithValidatedDependency(afb_api_t apiHandle,
- struct cds_list_head *halMapListHead,
- struct cds_list_head *halDevicesToProbeListHead,
- char *targetedDependency,
- enum DependenciesHandlingType halMapHandlingType)
+int InternalHalUnmanageOneHalMapObject(afb_api_t apiHandle, struct InternalHalAlsaMap *halMapData)
+{
+ int err;
+
+ char cardNbString[6];
+
+ if(! apiHandle || ! halMapData) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ snprintf(cardNbString, sizeof(cardNbString), "hw:%i", halMapData->cardNb);
+
+ err = afb_api_del_verb(apiHandle, halMapData->uid, NULL);
+ if(err)
+ AFB_API_WARNING(apiHandle,
+ "Error %i returned when tried to remove halmap verb %s, "
+ "verb may have not been added before",
+ err,
+ halMapData->uid);
+
+ free(halMapData->action);
+ halMapData->action = NULL;
+
+ if(halMapData->ctl.alsaCtlCreation) {
+ err = InternalHalDeleteAlsaCtl(apiHandle, cardNbString, &halMapData->ctl);
+ if(err)
+ AFB_API_WARNING(apiHandle,
+ "Error %i returned when tried to custom ALSA control '%s', "
+ "custom control may have not been added before",
+ err,
+ halMapData->ctl.name);
+ }
+ else {
+ free(halMapData->ctl.alsaCtlProperties);
+ halMapData->ctl.alsaCtlProperties = NULL;
+ }
+
+ if(afb_event_is_valid(halMapData->alsaControlEvent)) {
+ afb_event_unref(halMapData->alsaControlEvent);
+ halMapData->alsaControlEvent = NULL;
+ }
+
+ halMapData->cardNb = HAL_UNKNOWN_DEVICE;
+
+ return 0;
+}
+
+int InternalHalProcessDependencyRelatedHalmap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead,
+ char *targetedDependency,
+ enum DependencySelectionType halMapSelectionType,
+ enum HalMapProcessingType halMapProcessingType)
{
int err = 0, validatedHalMap;
struct InternalHalAlsaMap *currentHalMapData;
if(cds_list_empty(halMapListHead)) {
- AFB_API_ERROR(apiHandle, "HalMap list is empty, nothing to handle");
+ AFB_API_ERROR(apiHandle, "HalMap list is empty, nothing to process");
return 0;
}
- if(halMapHandlingType == UID_CORRESPONDING_DEPENDENCIES &&
+ if(halMapSelectionType == UID_CORRESPONDING_DEPENDENCIES &&
! targetedDependency) {
AFB_API_ERROR(apiHandle, "Invalid targeted dependency");
return -1;
@@ -1140,7 +1189,7 @@ int InternalHalHandleSelectedHalMapWithValidatedDependency(afb_api_t apiHandle,
cds_list_for_each_entry(currentHalMapData, halMapListHead, node) {
validatedHalMap = 0;
- switch(halMapHandlingType) {
+ switch(halMapSelectionType) {
case ALL_DEPENDENCIES:
validatedHalMap = 1;
break;
@@ -1160,18 +1209,24 @@ int InternalHalHandleSelectedHalMapWithValidatedDependency(afb_api_t apiHandle,
currentHalMapData->targetedDependency);
if(currentHalMapData->cardNb == HAL_UNKNOWN_DEVICE) {
AFB_API_WARNING(apiHandle,
- "Current halmap control %s can't be handled because corresponding "
+ "Current halmap control %s can't be %s because corresponding "
"dependency ('%s') card is not available at the moment",
currentHalMapData->uid,
+ (halMapProcessingType == HANDLE_SELECTED_HALMAP) ? "handled" : "unmanaged",
currentHalMapData->targetedDependency);
continue;
}
- err = InternalHalHandleOneHalMapObject(apiHandle, currentHalMapData);
+ if(halMapProcessingType == HANDLE_SELECTED_HALMAP)
+ err = InternalHalHandleOneHalMapObject(apiHandle, currentHalMapData);
+ else
+ err = InternalHalUnmanageOneHalMapObject(apiHandle, currentHalMapData);
+
if(err) {
AFB_API_ERROR(apiHandle,
- "Error %i was returned when tried to handle halmap control with uid %s",
+ "Error %i was returned when tried to %s halmap control with uid %s",
err,
+ (halMapProcessingType == HANDLE_SELECTED_HALMAP) ? "handle" : "unmanage",
currentHalMapData->uid);
return -3;
}
@@ -1181,15 +1236,54 @@ int InternalHalHandleSelectedHalMapWithValidatedDependency(afb_api_t apiHandle,
return 0;
}
-int InternalHalHandleAllHalMapWithValidatedDependency(afb_api_t apiHandle,
- struct cds_list_head *halMapListHead,
- struct cds_list_head *halDevicesToProbeListHead)
+int InternalHalHandleDependencyRelatedHalmap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead,
+ char *targetedDependency)
+{
+ return InternalHalProcessDependencyRelatedHalmap(apiHandle,
+ halMapListHead,
+ halDevicesToProbeListHead,
+ targetedDependency,
+ UID_CORRESPONDING_DEPENDENCIES,
+ HANDLE_SELECTED_HALMAP);
+}
+
+int InternalHalUnmanageDependencyRelatedHalmap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead,
+ char *targetedDependency)
+{
+ return InternalHalProcessDependencyRelatedHalmap(apiHandle,
+ halMapListHead,
+ halDevicesToProbeListHead,
+ targetedDependency,
+ UID_CORRESPONDING_DEPENDENCIES,
+ UNMANAGE_SELECTED_HALMAP);
+}
+
+int InternalHalHandleAllHalMap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead)
+{
+ return InternalHalProcessDependencyRelatedHalmap(apiHandle,
+ halMapListHead,
+ halDevicesToProbeListHead,
+ NULL,
+ ALL_DEPENDENCIES,
+ HANDLE_SELECTED_HALMAP);
+}
+
+int InternalHalUnmanageAllHalMap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead)
{
- return InternalHalHandleSelectedHalMapWithValidatedDependency(apiHandle,
- halMapListHead,
- halDevicesToProbeListHead,
- NULL,
- ALL_DEPENDENCIES);
+ return InternalHalProcessDependencyRelatedHalmap(apiHandle,
+ halMapListHead,
+ halDevicesToProbeListHead,
+ NULL,
+ ALL_DEPENDENCIES,
+ UNMANAGE_SELECTED_HALMAP);
}
int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *AlsaMapJ)
@@ -1219,9 +1313,9 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
AFB_API_WARNING(apiHandle, "No alsa controls defined in 'halmap' section");
return 1;
}
- else if(InternalHalHandleAllHalMapWithValidatedDependency(apiHandle,
- &currentHalData->internalHalData->halMapListHead,
- &currentHalData->internalHalData->probedDevicesListHead)) {
+ else if(InternalHalHandleAllHalMap(apiHandle,
+ &currentHalData->internalHalData->halMapListHead,
+ &currentHalData->internalHalData->probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Failed to handle 'halmap' section");
return -5;
}
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.h b/src/4a-internals-hal/4a-internals-hal-cb.h
index 48e3c35..2224046 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.h
+++ b/src/4a-internals-hal/4a-internals-hal-cb.h
@@ -24,12 +24,18 @@
#include <ctl-config.h>
-// Enum for the type of dependencies handling
-enum DependenciesHandlingType {
+// Enum for to define which type of dependency selection we want to use
+enum DependencySelectionType {
ALL_DEPENDENCIES = 0,
UID_CORRESPONDING_DEPENDENCIES = 1
};
+// Enum to define if to to handle or to unmanage a selected halmap
+enum HalMapProcessingType {
+ HANDLE_SELECTED_HALMAP = 0,
+ UNMANAGE_SELECTED_HALMAP = 1
+};
+
// Enum for the type of subscription
enum SubscribeUnsubscribeType {
SUBSCRIPTION = 0,
@@ -43,7 +49,7 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json
int InternalHalHandleHalDependencies(afb_api_t apiHandle,
struct HalData *currentHalData,
struct cds_list_head *halDevicesToProbeListHead,
- enum DependenciesHandlingType dependenciesHandlingType,
+ enum DependencySelectionType dependenciesSelectionType,
char *uid);
int InternalHalHalDependenciesConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *DependenciesJ);
@@ -51,6 +57,20 @@ int InternalHalHalDependenciesConfig(afb_api_t apiHandle, CtlSectionT *section,
int InternalHalHalMixerConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *MixerJ);
// Internals HAL - 'halmap' section parsing/handling functions
+int InternalHalHandleDependencyRelatedHalmap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead,
+ char *targetedDependency);
+int InternalHalUnmanageDependencyRelatedHalmap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead,
+ char *targetedDependency);
+int InternalHalHandleAllHalMap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead);
+int InternalHalUnmanageAllHalMap(afb_api_t apiHandle,
+ struct cds_list_head *halMapListHead,
+ struct cds_list_head *halDevicesToProbeListHead);
int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *halMapJ);
// Internals HAL verbs functions