summaryrefslogtreecommitdiffstats
path: root/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-21 16:04:25 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:53:53 +0200
commit16277b3b7960eab843ffd00a961d3d2d21ecd425 (patch)
treee25b167efc8b2a09e6dbcfa987f5e71bcfe36847 /4a-hal/4a-hal-manager/4a-hal-manager-cb.c
parent51dff31e2c0183458a4ed53c06b02625529cc3e4 (diff)
Improve hal list response from hal-manager
Improve 'loaded' verb response from hal-manager by only sending back the hal with the 'READY' status. Also add two boolean options to this verb call : - 'verbose' option to get all information of the hal. - 'all' option to get all hal and not just the 'READY' ones. Change-Id: I23d3d8ab75b429b2938249d10adbb67073eff259 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-manager/4a-hal-manager-cb.c')
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-cb.c77
1 files changed, 35 insertions, 42 deletions
diff --git a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
index 680863e..d4d1495 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
+++ b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
@@ -60,8 +60,7 @@ void HalMgrPing(AFB_ReqT request)
void HalMgrLoaded(AFB_ReqT request)
{
- int requestJsonErr = 0, requestOptionValue;
- uint64_t cpt, numberOfLoadedApi;
+ int requestJsonErr = 0, allHal = 0, verbose = 0;
char cardIdString[10];
@@ -83,8 +82,9 @@ void HalMgrLoaded(AFB_ReqT request)
return;
}
- numberOfLoadedApi = HalUtlGetNumberOfHalInList(&HalMgrGlobalData->first);
- if(! numberOfLoadedApi) {
+ currentHalData = HalMgrGlobalData->first;
+
+ if(! currentHalData) {
AFB_ReqSuccess(request, NULL, "No Hal Api loaded");
return;
}
@@ -95,48 +95,41 @@ void HalMgrLoaded(AFB_ReqT request)
return;
}
- currentHalData = HalMgrGlobalData->first;
-
requestJson = AFB_ReqJson(request);
- if(! requestJson) {
+ if(! requestJson)
AFB_ReqNotice(request, "%s: Can't get request json", __func__);
- }
- else {
- // Get request option
- requestJsonErr = wrap_json_unpack(requestJson, "{s:i}", "verbose", &requestOptionValue);
- }
-
- // Case if request key is 'verbose' and value is bigger than 0
- if(! requestJsonErr && requestOptionValue > 0) {
- for(cpt = 0; cpt < numberOfLoadedApi; cpt++) {
- if(currentHalData->sndCardId >= 0)
- snprintf(cardIdString, 6, "hw:%i", currentHalData->sndCardId);
- else
- snprintf(cardIdString, 10, "not-found");
-
- wrap_json_pack(&apiObject,
- "{s:s s:i s:s s:i s:s s:s s:s s:s s:s}",
- "api", currentHalData->apiName,
- "status", (int) currentHalData->status,
- "sndcard", currentHalData->sndCardPath,
- "internal", (int) currentHalData->internal,
- "info", currentHalData->info ? currentHalData->info : "",
- "author", currentHalData->author ? currentHalData->author : "",
- "version", currentHalData->version ? currentHalData->version : "",
- "date", currentHalData->date ? currentHalData->date : "",
- "snd-dev-id", cardIdString);
- json_object_array_add(requestAnswer, apiObject);
-
- currentHalData = currentHalData->next;
+ else
+ requestJsonErr = wrap_json_unpack(requestJson, "{s?:b s?:b}", "all", &allHal, "verbose", &verbose);
+
+ while(currentHalData) {
+ if(allHal || currentHalData->status == HAL_STATUS_READY) {
+ // Case if request key is 'verbose' and value is bigger than 0
+ if(! requestJsonErr && verbose) {
+ if(currentHalData->sndCardId >= 0)
+ snprintf(cardIdString, 6, "hw:%i", currentHalData->sndCardId);
+ else
+ snprintf(cardIdString, 10, "not-found");
+
+ wrap_json_pack(&apiObject,
+ "{s:s s:i s:s s:i s:s s:s s:s s:s s:s}",
+ "api", currentHalData->apiName,
+ "status", (int) currentHalData->status,
+ "sndcard", currentHalData->sndCardPath,
+ "internal", (int) currentHalData->internal,
+ "info", currentHalData->info ? currentHalData->info : "",
+ "author", currentHalData->author ? currentHalData->author : "",
+ "version", currentHalData->version ? currentHalData->version : "",
+ "date", currentHalData->date ? currentHalData->date : "",
+ "snd-dev-id", cardIdString);
+ json_object_array_add(requestAnswer, apiObject);
+ }
+ // Case if request is empty or not handled
+ else {
+ json_object_array_add(requestAnswer, json_object_new_string(currentHalData->apiName));
+ }
}
- }
- // Case if request is empty or not handled
- else {
- for(cpt = 0; cpt < numberOfLoadedApi; cpt++) {
- json_object_array_add(requestAnswer, json_object_new_string(currentHalData->apiName));
- currentHalData = currentHalData->next;
- }
+ currentHalData = currentHalData->next;
}
AFB_ReqSuccess(request, requestAnswer, "Requested data");