summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 16:27:38 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 16:27:38 +0200
commit3bc5eb3c4da0565fd4138344363207eab62fff9a (patch)
tree84a66de50e9876f8de7d7ca8d142b8107aab1737
parent6a572877593e592dbaaba6f5649bc7744cd714c7 (diff)
Add a function to handle selected dependency
Add a function to handle selected dependency using its uid. BUG-AGL: SPEC-2329 Change-Id: I0e92448f9102bc5e6e0f19d1598d75c1ba782863 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c68
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.h18
2 files changed, 67 insertions, 19 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 199fc5a..1e920c3 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -939,9 +939,12 @@ int InternalHalHandleOneHalDependencies(afb_api_t apiHandle, struct InternalHalP
return 0;
}
-int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct cds_list_head *halDevicesToProbeListHead)
+int InternalHalHandleHalDependencies(afb_api_t apiHandle,
+ struct cds_list_head *halDevicesToProbeListHead,
+ enum DependenciesHandlingType dependenciesHandlingType,
+ char *uid)
{
- int ret;
+ int ret, validatedDepedency;
struct InternalHalProbedDevice *halCurrentDeviceToProbe;
@@ -955,30 +958,61 @@ int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct cds_list_hea
return 0;
}
+ if(dependenciesHandlingType == UID_CORRESPONDING_DEPENDENCIES &&
+ ! uid) {
+ AFB_API_ERROR(apiHandle, "Invalid uid");
+ return -2;
+ }
+
cds_list_for_each_entry(halCurrentDeviceToProbe, halDevicesToProbeListHead, node) {
- ret = InternalHalHandleOneHalDependencies(apiHandle, &halCurrentDeviceToProbe);
- if(ret < 0) {
- AFB_API_ERROR(apiHandle,
- "Error %i happened when tried to handle device to probe with uid:'%s' and request:'%s'",
- ret,
- halCurrentDeviceToProbe->uid,
- json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
- return -2;
+ validatedDepedency = 0;
+
+ switch(dependenciesHandlingType) {
+ case ALL_DEPENDENCIES:
+ validatedDepedency = 1;
+ break;
+
+ case UID_CORRESPONDING_DEPENDENCIES:
+ if(! strcmp(uid, halCurrentDeviceToProbe->uid))
+ validatedDepedency = 1;
+ break;
+
+ default:
+ AFB_API_ERROR(apiHandle, "Invalid dependencies enum type");
+ return -3;
}
- if(halCurrentDeviceToProbe->deviceClass == MANDATORY_PROBED_DEVICE &&
- ! halCurrentDeviceToProbe->deviceData) {
- AFB_API_WARNING(apiHandle,
- "Mandatory device to probe not found, uid:'%s' and request:'%s'",
- halCurrentDeviceToProbe->uid,
- json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
- return -3;
+ // If no uid is specified, handle all dependencies
+ if(validatedDepedency) {
+ ret = InternalHalHandleOneHalDependencies(apiHandle, &halCurrentDeviceToProbe);
+ if(ret < 0) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened when tried to handle device to probe with uid:'%s' and request:'%s'",
+ ret,
+ halCurrentDeviceToProbe->uid,
+ json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
+ return -4;
+ }
+
+ if(halCurrentDeviceToProbe->deviceClass == MANDATORY_PROBED_DEVICE &&
+ ! halCurrentDeviceToProbe->deviceData) {
+ AFB_API_WARNING(apiHandle,
+ "Mandatory device to probe not found, uid:'%s' and request:'%s'",
+ halCurrentDeviceToProbe->uid,
+ json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
+ return -5;
+ }
}
}
return 0;
}
+int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct cds_list_head *halDevicesToProbeListHead)
+{
+ return InternalHalHandleHalDependencies(apiHandle, halDevicesToProbeListHead, ALL_DEPENDENCIES, NULL);
+}
+
int InternalHalHalDependenciesConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *DependenciesJ)
{
CtlConfigT *ctrlConfig;
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.h b/src/4a-internals-hal/4a-internals-hal-cb.h
index 68bf76c..ac09ef1 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.h
+++ b/src/4a-internals-hal/4a-internals-hal-cb.h
@@ -24,7 +24,13 @@
#include <ctl-config.h>
-// Enum for the type of subscription/subscription
+// Enum for the type of dependencies handling
+enum DependenciesHandlingType {
+ ALL_DEPENDENCIES = 0,
+ UID_CORRESPONDING_DEPENDENCIES = 1
+};
+
+// Enum for the type of subscription
enum SubscribeUnsubscribeType {
SUBSCRIPTION = 0,
UNSUBSCRIPTION = 1
@@ -33,9 +39,17 @@ enum SubscribeUnsubscribeType {
// Internals HAL event handler function
void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_object *eventJ);
-// Internals HAL sections parsing functions
+// Internals HAL - 'halmixer' section parsing/handling functions
int InternalHalHalMixerConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *MixerJ);
+
+// Internals HAL - 'halmap' section parsing/handling functions
int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *AlsaMapJ);
+
+// Internals HAL - 'haldependencies' section parsing/handling functions
+int InternalHalHandleHalDependencies(afb_api_t apiHandle,
+ struct cds_list_head *halDevicesToProbeListHead,
+ enum DependenciesHandlingType dependenciesHandlingType,
+ char *uid);
int InternalHalHalDependenciesConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *DependenciesJ);
// Internals HAL verbs functions