aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-07 09:26:41 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 11:29:21 +0200
commit6a6ff77ec19edf8f41aeb69d88e4bdf32b351ce3 (patch)
treef5884dcafd054b15bae62cf416485a8ef92f9c36
parent1b07640d75f5a3c70655c629340e0263a21a2ff8 (diff)
Add verbose level to json hal info verb
Add verbose level to specify the requested information level when calling a json hal 'info' verb. Also, move into a function the code that allows to get information about json hal. BUG-AGL: SPEC-2889 Change-Id: I9d5cbc6cfa550f4f7c8033dad0f3ec66d1268ea5 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-internals-hal/4a-internals-hal-api-loader.c2
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c146
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.h6
3 files changed, 100 insertions, 54 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.c b/src/4a-internals-hal/4a-internals-hal-api-loader.c
index ba742f1..c833521 100644
--- a/src/4a-internals-hal/4a-internals-hal-api-loader.c
+++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c
@@ -62,7 +62,7 @@ static afb_verb_t InternalHalApiStaticVerbs[] =
{
/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */
{ .verb = "ping", .callback = HalUtlPing, .info = "Ping for test"},
- { .verb = "info", .callback = InternalHalInfo, .info = "List available streams/controls for this api" },
+ { .verb = "info", .callback = InternalHalInfoVerb, .info = "List available dependencies/streams/controls for this api" },
{ .verb = "subscribe", .callback = InternalHalSubscribe, .info = "Subscribe to event(s) for values changes (streams/controls) for this api" },
{ .verb = "unsubscribe", .callback = InternalHalUnsubscribe, .info = "Unsubscribe to event(s) for values changes (streams/controls) for this api" },
{ .verb = HAL_ALL_STREAMS_VERB, .callback = HalUtlActionOnAllStream, .info = "Send a stream action on all streams" },
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 1e872bb..cef8605 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -1285,22 +1285,100 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
* Internals HAL verbs functions *
******************************************************************************/
-void InternalHalInfo(afb_req_t request)
+int GenerateInternalHalInfoJson(afb_api_t apiHandle,
+ struct HalData *currentHalData,
+ json_object *requestJ,
+ json_object **returnedJ)
{
- char *apiToCall, *returnedError = NULL, *returnedInfo = NULL;
+ int wrapRet, verboseLevel = 2;
- afb_api_t apiHandle;
- CtlConfigT *ctrlConfig;
-
- struct HalData *currentHalData;
+ char *apiToCall, *returnedError = NULL, *returnedInfo = NULL;
- json_object *requestJson,
+ json_object *mixerRequestJ = NULL,
*toReturnJ = NULL,
*requestAnswer,
*streamsArray,
*controlsArray,
*dependenciesArray;
+ if(! apiHandle || ! currentHalData || ! returnedJ)
+ return -1;
+
+ *returnedJ = NULL;
+
+ if(requestJ) {
+ wrapRet = wrap_json_unpack(requestJ,
+ "{s?:i, s?:o !}",
+ "verbose", &verboseLevel,
+ "mixer", &mixerRequestJ);
+ if(wrapRet)
+ return -2;
+ }
+
+ if(mixerRequestJ &&
+ json_object_is_type(mixerRequestJ, json_type_object) &&
+ json_object_get_object(mixerRequestJ)->count > 0) {
+ apiToCall = currentHalData->internalHalData->mixerApiName;
+ if(! apiToCall)
+ return-3;
+
+ if(InternalHalGetInfoFromMixer(apiHandle,
+ apiToCall,
+ mixerRequestJ,
+ &toReturnJ,
+ &returnedError,
+ &returnedInfo))
+ return -4;
+
+ *returnedJ = toReturnJ;
+ return 0;
+ }
+
+ requestAnswer = json_object_new_object();
+
+ if(verboseLevel >= 0) {
+ dependenciesArray = HalUtlGetJsonArrayForAllDependencies(apiHandle,
+ &currentHalData->internalHalData->probedDevicesListHead,
+ DEPENDENCY_FULL_JSON);
+ if(dependenciesArray)
+ json_object_object_add(requestAnswer, "dependencies", dependenciesArray);
+ }
+
+ if(verboseLevel >= 1) {
+ controlsArray = HalUtGetJsonArrayForAllHalMapControls(apiHandle,
+ &currentHalData->internalHalData->halMapListHead);
+ if(controlsArray)
+ json_object_object_add(requestAnswer, "controls", controlsArray);
+ }
+
+ if(verboseLevel >= 2) {
+ streamsArray = HalUtlGetJsonArrayForAllMixersData(apiHandle,
+ &currentHalData->internalHalData->streamsDataListHead);
+ if(! streamsArray)
+ streamsArray = json_object_new_array(); // Always return an array for 4a-hl-api (to prevent segfault)
+ json_object_object_add(requestAnswer, "streams", streamsArray);
+ }
+
+ if(! json_object_get_object(requestAnswer)->count) {
+ json_object_put(requestAnswer);
+ requestAnswer = NULL;
+ }
+
+ *returnedJ = requestAnswer;
+ return 0;
+}
+
+void InternalHalInfoVerb(afb_req_t request)
+{
+ int err;
+
+ afb_api_t apiHandle;
+ CtlConfigT *ctrlConfig;
+
+ struct HalData *currentHalData;
+
+ json_object *requestJ, *toReturnJ;
+
apiHandle = afb_req_get_api(request);
if(! apiHandle) {
afb_req_fail(request, "api_handle", "Can't get current internal hal api handle");
@@ -1319,55 +1397,19 @@ void InternalHalInfo(afb_req_t request)
return;
}
- requestJson = afb_req_json(request);
- if(! requestJson) {
- AFB_REQ_NOTICE(request, "Can't get request json");
- }
- else if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0) {
- apiToCall = currentHalData->internalHalData->mixerApiName;
- if(! apiToCall) {
- afb_req_fail(request, "mixer_api", "Can't get mixer api");
- return;
- }
-
- if(InternalHalGetInfoFromMixer(apiHandle, apiToCall, requestJson, &toReturnJ, &returnedError, &returnedInfo)) {
- afb_req_fail_f(request,
- "mixer_info",
- "Call to mixer info verb didn't succeed with status '%s' and info '%s'",
- returnedError ? returnedError : "not returned",
- returnedInfo ? returnedInfo : "not returned");
- return;
- }
+ requestJ = afb_req_json(request);
- afb_req_success(request, toReturnJ, "Mixer requested data");
+ err = GenerateInternalHalInfoJson(apiHandle, currentHalData, requestJ, &toReturnJ);
+ if(err) {
+ afb_req_fail_f(request,
+ "get_info_fail",
+ "Error %i happened when tried to get json info for request json '%s'",
+ err,
+ json_object_get_string(requestJ));
return;
}
- requestAnswer = json_object_new_object();
-
- dependenciesArray = HalUtlGetJsonArrayForAllDependencies(apiHandle,
- &currentHalData->internalHalData->probedDevicesListHead,
- DEPENDENCY_FULL_JSON);
- if(dependenciesArray)
- json_object_object_add(requestAnswer, "dependencies", dependenciesArray);
-
- streamsArray = HalUtlGetJsonArrayForAllMixersData(apiHandle,
- &currentHalData->internalHalData->streamsDataListHead);
- if(! streamsArray)
- streamsArray = json_object_new_array(); // Always return an array for 4a-hl-api (to prevent segfault)
- json_object_object_add(requestAnswer, "streams", streamsArray);
-
- controlsArray = HalUtGetJsonArrayForAllHalMapControls(apiHandle,
- &currentHalData->internalHalData->halMapListHead);
- if(controlsArray)
- json_object_object_add(requestAnswer, "controls", controlsArray);
-
- if(! json_object_get_object(requestAnswer)->count) {
- json_object_put(requestAnswer);
- requestAnswer = NULL;
- }
-
- afb_req_success(request, requestAnswer, "Requested data");
+ afb_req_success(request, toReturnJ, "Requested data");
}
void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscribeType subscribeUnsubscribeType)
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.h b/src/4a-internals-hal/4a-internals-hal-cb.h
index d7b998c..48e3c35 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.h
+++ b/src/4a-internals-hal/4a-internals-hal-cb.h
@@ -54,7 +54,11 @@ int InternalHalHalMixerConfig(afb_api_t apiHandle, CtlSectionT *section, json_ob
int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *halMapJ);
// Internals HAL verbs functions
-void InternalHalInfo(afb_req_t request);
+int GenerateInternalHalInfoJson(afb_api_t apiHandle,
+ struct HalData *currentHalData,
+ json_object *requestJ,
+ json_object **returnedJ);
+void InternalHalInfoVerb(afb_req_t request);
void InternalHalSubscribe(afb_req_t request);
void InternalHalUnsubscribe(afb_req_t request);