summaryrefslogtreecommitdiffstats
path: root/4a-hal
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-05-27 22:10:50 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:51:00 +0200
commitb1734993fee173ca854dc4396c85c0766d01bbb8 (patch)
treebf1dc709d9a1f4117ac33605d372314e437fbe71 /4a-hal
parentee559d1b2aab833e1767e9f97b9b9cf97644bd03 (diff)
Implementation of functions for external hal
Implementation of functions that allows to handle register/unregister external hal. Change-Id: Idf7ad2ab7dd811195a9c86d3fc194086746e99ef Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal')
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-cb.c122
1 files changed, 116 insertions, 6 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 6373dcb..deea87e 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
+++ b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
@@ -139,20 +139,130 @@ void HalMgrLoaded(afb_request *request)
afb_request_success(request, requestAnswer, "Requested data");
}
-// TODO JAI : to implement
void HalMgrLoad(afb_request *request)
{
- AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__);
+ char *apiName, *sndCard, *info = NULL, *author = NULL, *version = NULL, *date = NULL;
- afb_request_success(request, json_object_new_boolean(false), NULL);
+ afb_dynapi *apiHandle;
+ struct HalMgrData *HalMgrGlobalData;
+ struct SpecificHalData *addedHal;
+
+ struct json_object *requestJson, *apiReceviedMetadata;
+
+ apiHandle = (afb_dynapi *) afb_request_get_dynapi(request);
+ if(! apiHandle) {
+ afb_request_fail(request, "api_handle", "Can't get hal manager api handle");
+ return;
+ }
+
+ HalMgrGlobalData = (struct HalMgrData *) afb_dynapi_get_userdata(apiHandle);
+ if(! HalMgrGlobalData) {
+ afb_request_fail(request, "hal_manager_data", "Can't get hal manager data");
+ return;
+ }
+
+ requestJson = afb_request_json(request);
+ if(! requestJson) {
+ afb_request_fail(request, "request_json", "Can't get request json");
+ return;
+ }
+
+ if(! json_object_object_get_ex(requestJson, "metadata", &apiReceviedMetadata)) {
+ afb_request_fail(request, "api_metadata", "Can't get api to register metadata");
+ return;
+ }
+
+ if(wrap_json_unpack(apiReceviedMetadata,
+ "{s:s s:s s?:s s?:s s?:s s?:s}",
+ "api", &apiName,
+ "uid", &sndCard,
+ "info", &info,
+ "author", &author,
+ "version", &version,
+ "date", &date)) {
+ afb_request_fail(request, "api_metadata", "Can't metadata of api to register");
+ return;
+ }
+
+ // TODO JAI: try connect to the api to test if it really exists
+
+ addedHal = HalUtlAddHalApiToHalList(HalMgrGlobalData);
+
+ addedHal->internal = false;
+ addedHal->status = HAL_STATUS_UNAVAILABLE;
+
+ addedHal->apiName = strdup(apiName);
+ addedHal->sndCard = strdup(sndCard);
+
+ if(info)
+ addedHal->info = strdup(info);
+
+ if(author)
+ addedHal->author = strdup(author);
+
+ if(version)
+ addedHal->version = strdup(version);
+
+ if(date)
+ addedHal->date = strdup(date);
+
+ // TODO JAI: add subscription to this api status events
+
+ afb_request_success(request, NULL, "Api successfully registered");
}
-// TODO JAI : to implement
void HalMgrUnload(afb_request *request)
{
- AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__);
+ char *apiName;
- afb_request_success(request, json_object_new_boolean(false), NULL);
+ afb_dynapi *apiHandle;
+ struct HalMgrData *HalMgrGlobalData;
+ struct SpecificHalData *HalToRemove;
+
+ struct json_object *requestJson;
+
+ apiHandle = (afb_dynapi *) afb_request_get_dynapi(request);
+ if(! apiHandle) {
+ afb_request_fail(request, "api_handle", "Can't get hal manager api handle");
+ return;
+ }
+
+ HalMgrGlobalData = (struct HalMgrData *) afb_dynapi_get_userdata(apiHandle);
+ if(! HalMgrGlobalData) {
+ afb_request_fail(request, "hal_manager_data", "Can't get hal manager data");
+ return;
+ }
+
+ requestJson = afb_request_json(request);
+ if(! requestJson) {
+ afb_request_fail(request, "request_json", "Can't get request json");
+ return;
+ }
+
+ if(wrap_json_unpack(requestJson, "{s:s}", "api", &apiName)) {
+ afb_request_fail(request, "requested_api", "Can't get api to remove");
+ return;
+ }
+
+ HalToRemove = HalUtlSearchHalDataByApiName(HalMgrGlobalData, apiName);
+ if(! HalToRemove) {
+ afb_request_fail(request, "requested_api", "Can't find api to remove");
+ return;
+ }
+
+ if(HalToRemove->internal) {
+ afb_request_fail(request, "requested_api", "Can't remove an internal controller api");
+ return;
+ }
+
+ if(HalUtlRemoveSelectedHalFromList(HalMgrGlobalData, HalToRemove)) {
+ afb_request_fail(request, "unregister_error", "Didn't succeed to remove specified api");
+ return;
+ }
+
+ // TODO JAI: remove subscription to this api status events
+
+ afb_request_success(request, NULL, "Api successfully unregistered");
}
// TODO JAI : to implement