summaryrefslogtreecommitdiffstats
path: root/4a-hal
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-05-26 19:42:50 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:51:00 +0200
commitbb13f7376e40119d08bb4c2b6a291f49a3432e59 (patch)
treebb7305c03de6ba1853a627c0b02762e9bf6e97e8 /4a-hal
parentb1734993fee173ca854dc4396c85c0766d01bbb8 (diff)
Parse controller config to get halmixer json object
Parse controller configuration to get halmixer json object, this object is inside 'halmixer' section of controller configuration file. Use streams defined in this 'halmixer' section to get available streams of this hal, store them, and declare them as hal api verbs. Change-Id: I47adb2756f89f2a84c8d651ba38ecea5b84079c3 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c2
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c97
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h7
-rw-r--r--4a-hal/4a-hal-utilities/4a-hal-utilities-data.h2
4 files changed, 107 insertions, 1 deletions
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 bf7ccbe..0b6a919 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
@@ -45,6 +45,8 @@ static CtlSectionT ctrlSections[] =
{.key="onload" , .loadCB= OnloadConfig},
{.key="controls", .loadCB= ControlConfig},
{.key="events" , .loadCB= EventConfig},
+ // TODO JAI: create a new section parser to get 'halmap' and store them into hal structure
+ {.key="halmixer", .loadCB= HalCtlsHalMixerConfig},
{.key=NULL}
};
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
index bc8339c..c05059d 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -23,12 +23,107 @@
#include <wrap-json.h>
+#include "../4a-hal-utilities/4a-hal-utilities-data.h"
+#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h"
+
#include "4a-hal-controllers-cb.h"
/*******************************************************************************
- * HAL Manager verbs functions *
+ * HAL controllers sections parsing functions *
******************************************************************************/
+int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_object *MixerJ)
+{
+ unsigned int streamCount, idx;
+ char *currentStreamName;
+
+ CtlConfigT *ctrlConfig;
+ struct SpecificHalData *currentHalData;
+
+ json_object *streamsArray, *currentStream;
+
+ struct HalUtlApiVerb *CtlHalDynApiStreamVerbs;
+
+ if(! apiHandle || ! section)
+ return -1;
+
+ if(MixerJ) {
+ ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(apiHandle);
+ if(! ctrlConfig)
+ return -2;
+
+ currentHalData = (struct SpecificHalData *) ctrlConfig->external;
+ if(! currentHalData)
+ return -3;
+
+ if(json_object_is_type(MixerJ, json_type_object))
+ currentHalData->ctlHalSpecificData->halMixerJ = MixerJ;
+ else
+ return -4;
+
+ if(wrap_json_unpack(MixerJ, "{s:s}", "mixerapi", &currentHalData->ctlHalSpecificData->mixerApiName))
+ return -5;
+
+ if(! json_object_object_get_ex(MixerJ, "streams", &streamsArray))
+ return -6;
+
+ switch(json_object_get_type(streamsArray)) {
+ case json_type_object:
+ streamCount = 1;
+ break;
+ case json_type_array:
+ streamCount = json_object_array_length(streamsArray);
+ break;
+ default:
+ return -7;
+ }
+
+ currentHalData->ctlHalSpecificData->ctlHalStreamsData.count = streamCount;
+ currentHalData->ctlHalSpecificData->ctlHalStreamsData.data =
+ (struct CtlHalStreamData *) calloc(streamCount, sizeof (struct CtlHalStreamData *));
+
+ CtlHalDynApiStreamVerbs = alloca((streamCount + 1) * sizeof(struct HalUtlApiVerb));
+ memset(CtlHalDynApiStreamVerbs, '\0', (streamCount + 1) * sizeof(struct HalUtlApiVerb));
+ CtlHalDynApiStreamVerbs[streamCount + 1].verb = NULL;
+
+ for(idx = 0; idx < streamCount; idx++) {
+ if(streamCount > 1)
+ currentStream = json_object_array_get_idx(streamsArray, (int) idx);
+ else
+ currentStream = streamsArray;
+
+ if(wrap_json_unpack(currentStream, "{s:s}", "uid", &currentStreamName))
+ return -9-idx;
+
+ currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].name = strdup(currentStreamName);
+ currentHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId = NULL;
+
+ CtlHalDynApiStreamVerbs[idx].verb = currentStreamName;
+ CtlHalDynApiStreamVerbs[idx].callback = HalCtlsActionOnStream;
+ CtlHalDynApiStreamVerbs[idx].info = "Peform action on this stream";
+ }
+
+ if(HalUtlLoadVerbs(apiHandle, CtlHalDynApiStreamVerbs))
+ return -8;
+ }
+
+ return 0;
+}
+
+// TODO JAI: create a new section parser to get 'halmap' and store them into hal structure
+
+/*******************************************************************************
+ * HAL controllers verbs functions *
+ ******************************************************************************/
+
+// TODO JAI : to implement
+void HalCtlsActionOnStream(afb_request *request)
+{
+ AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__);
+
+ afb_request_success(request, json_object_new_boolean(false), NULL);
+}
+
// TODO JAI : to implement
void HalCtlsListVerbs(afb_request *request)
{
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
index 7bd6434..765001e 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
@@ -23,6 +23,13 @@
#define AFB_BINDING_VERSION dyn
#include <afb/afb-binding.h>
+#include <ctl-config.h>
+
+// HAL controllers sections parsing functions
+int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_object *MixerJ);
+
+// HAL controllers verbs functions
+void HalCtlsActionOnStream(afb_request *request);
void HalCtlsListVerbs(afb_request *request);
#endif /* _HALMGR_CB_INCLUDE_ */ \ No newline at end of file
diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
index 9514571..f9b9b36 100644
--- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h
@@ -20,6 +20,8 @@
#include <stdio.h>
+#include <wrap-json.h>
+
#define AFB_BINDING_VERSION dyn
#include <afb/afb-binding.h>