aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-cb.c77
-rw-r--r--README.md6
2 files changed, 38 insertions, 45 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");
diff --git a/README.md b/README.md
index 67eb682..6bb00af 100644
--- a/README.md
+++ b/README.md
@@ -173,15 +173,15 @@ Connect to your 4a binder using afb-client-demo
afb-client-demo ws://localhost:1234/api?token=
```
-### List the loaded hal
+### List the ready hal
-In the connected client, try to list the loaded hal:
+In the connected client, try to list the ready hal:
```4a-hal-manager loaded```
And now with more information:
-```4a-hal-manager loaded { "verbose" : 1 }```
+```4a-hal-manager loaded { "verbose" : true }```
### Play with an 'internal' hal (described in a json configuration file)