summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-07 09:28:21 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 11:29:21 +0200
commit041a50e3b11d545672d01e9d8985717a3dc90543 (patch)
treec971b63b75f26a6ae54b448c7c8b3b4d27bbd9f7
parent6a6ff77ec19edf8f41aeb69d88e4bdf32b351ce3 (diff)
Add an 'info' verb to 'hal-manager'
Add an 'info' verb to 'hal-manager' that allows to get information about all json hal. The verbose level can be specified. If it is not, it will be set to the lowest by default. BUG-AGL: SPEC-2890 Change-Id: I113a733b32e1b758f94586006df6ab0130cf097a Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-hal-manager/4a-hal-manager-cb.c87
-rw-r--r--src/4a-hal-manager/4a-hal-manager-cb.h1
-rw-r--r--src/4a-hal-manager/4a-hal-manager.c1
3 files changed, 89 insertions, 0 deletions
diff --git a/src/4a-hal-manager/4a-hal-manager-cb.c b/src/4a-hal-manager/4a-hal-manager-cb.c
index 771ff50..67f46a9 100644
--- a/src/4a-hal-manager/4a-hal-manager-cb.c
+++ b/src/4a-hal-manager/4a-hal-manager-cb.c
@@ -26,6 +26,8 @@
#include "4a-hal-utilities-data.h"
+#include "../4a-internals-hal/4a-internals-hal-cb.h"
+
#include "4a-hal-manager-cb.h"
/*******************************************************************************
@@ -127,6 +129,91 @@ void HalMgrLoaded(afb_req_t request)
afb_req_success(request, requestAnswer, "Requested data");
}
+void HalMgrInfo(afb_req_t request)
+{
+ int err, wrapRet = 0;
+
+ afb_api_t apiHandle;
+ struct HalMgrData *halMgrData;
+ struct HalData *currentHalData;
+
+ json_object *requestJson, *toReturnJ, *returnedInfoJ, *transferredJson = NULL;
+
+ apiHandle = afb_req_get_api(request);
+ if(! apiHandle) {
+ afb_req_fail(request, "api_handle", "Can't get hal manager api handle");
+ return;
+ }
+
+ halMgrData = (struct HalMgrData *) afb_api_get_userdata(apiHandle);
+ if(! halMgrData) {
+ afb_req_fail(request, "hal_manager_data", "Can't get hal manager data");
+ return;
+ }
+
+ if(cds_list_empty(&halMgrData->halDataListHead)) {
+ afb_req_success(request, NULL, "No Hal Api loaded");
+ return;
+ }
+
+ requestJson = afb_req_json(request);
+ if(! requestJson) {
+ AFB_REQ_NOTICE(request, "Can't get request json, will use default verbose");
+ wrapRet = wrap_json_pack(&transferredJson, "{s:i}", "verbose", 0);
+ if(wrapRet) {
+ afb_req_fail(request, "json_request", "Didn't succeed to generate default json request");
+ return;
+ }
+ }
+ else {
+ AFB_REQ_DEBUG(request,
+ "Received request json ('%s') will be transferred to each hal 'info' verb",
+ json_object_get_string(requestJson));
+ transferredJson = requestJson;
+ }
+
+ toReturnJ = json_object_new_array();
+ if(! toReturnJ) {
+ afb_req_fail(request,
+ "response_json_array",
+ "Didn't succeed to allocate response json array");
+ if(! requestJson)
+ json_object_put(transferredJson);
+ return;
+ }
+
+ cds_list_for_each_entry(currentHalData, &halMgrData->halDataListHead, node) {
+ if(! currentHalData->internalHalData) {
+ AFB_REQ_INFO(request,
+ "'%s' hal is an external hal, will not be able to get info about it",
+ currentHalData->apiName);
+ continue;
+ }
+
+ err = GenerateInternalHalInfoJson(apiHandle,
+ currentHalData,
+ transferredJson,
+ &returnedInfoJ);
+ if(err){
+ AFB_REQ_INFO(request,
+ "Error %i happened when tried to generate hal '%s' information json",
+ err,
+ currentHalData->apiName);
+ json_object_put(toReturnJ);
+ if(! requestJson)
+ json_object_put(transferredJson);
+ return;
+ }
+
+ json_object_array_add(toReturnJ, returnedInfoJ);
+ }
+
+ if(! requestJson)
+ json_object_put(transferredJson);
+
+ afb_req_success(request, toReturnJ, "Requested data");
+}
+
void HalMgrLoad(afb_req_t request)
{
char *apiName, *uid, *info = NULL, *author = NULL, *version = NULL, *date = NULL;
diff --git a/src/4a-hal-manager/4a-hal-manager-cb.h b/src/4a-hal-manager/4a-hal-manager-cb.h
index eaf42a5..d35f83e 100644
--- a/src/4a-hal-manager/4a-hal-manager-cb.h
+++ b/src/4a-hal-manager/4a-hal-manager-cb.h
@@ -27,6 +27,7 @@ void HalMgrDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_obje
// Exported verbs callbacks
void HalMgrLoaded(afb_req_t request);
+void HalMgrInfo(afb_req_t request);
void HalMgrLoad(afb_req_t request);
void HalMgrUnload(afb_req_t request);
void HalMgrSubscribeEvent(afb_req_t request);
diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c
index c587e8a..e21b948 100644
--- a/src/4a-hal-manager/4a-hal-manager.c
+++ b/src/4a-hal-manager/4a-hal-manager.c
@@ -41,6 +41,7 @@ afb_verb_t HalManagerApiStaticVerbs[] =
/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */
{ .verb = "ping", .callback = HalUtlPing, .info = "Ping for test"},
{ .verb = "loaded", .callback = HalMgrLoaded, .info = "Show loaded HAL"},
+ { .verb = "info", .callback = HalMgrInfo, .info = "List available dependencies/controls/streams for all hals"},
{ .verb = "load", .callback = HalMgrLoad, .info = "Load an external HAL to HAL Manager"},
{ .verb = "unload", .callback = HalMgrUnload, .info = "Unload an external HAL to HAL Manager"},
{ .verb = "subscribe", .callback = HalMgrSubscribeEvent, .info = "Subscribe to an event"},