summaryrefslogtreecommitdiffstats
path: root/4a-hal/4a-hal-manager
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-21 17:07:36 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-28 15:38:58 +0100
commit756f8d02b445631df44243d528165fb1fe414487 (patch)
tree1ef835068d6cf24f33eeb0a0a136865a23a1884e /4a-hal/4a-hal-manager
parent524ad81cd52d52555d0e6cbaf865f6bb6cfecb25 (diff)
Move from controller functions to afb functions
Move from controller 'afb-definitions.h' functions to application framework 'afb/afb-binding.h' functions. Change-Id: I4cd62af881ef8ac949b082ede9dfcc4736d1e12c Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-manager')
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-cb.c106
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-cb.h16
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager-events.h2
-rw-r--r--4a-hal/4a-hal-manager/4a-hal-manager.c33
4 files changed, 74 insertions, 83 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 ba01394..81f2c10 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
+++ b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c
@@ -22,6 +22,8 @@
#include <wrap-json.h>
+#include <afb/afb-binding.h>
+
#include "4a-hal-utilities-data.h"
#include "4a-hal-manager-cb.h"
@@ -32,9 +34,9 @@
******************************************************************************/
// TBD JAI : to implement
-void HalMgrDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_object *eventJ)
+void HalMgrDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_object *eventJ)
{
- AFB_ApiWarning(apiHandle, "Not implemented yet");
+ AFB_API_WARNING(apiHandle, "Not implemented yet");
// Use "4a-hal-manager-events.h" to handle events
}
@@ -42,58 +44,55 @@ void HalMgrDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_objec
* HAL Manager verbs functions *
******************************************************************************/
-void HalMgrPing(AFB_ReqT request)
+void HalMgrPing(afb_req_t request)
{
static int count = 0;
count++;
- AFB_ReqNotice(request, "ping count = %d", count);
- AFB_ReqSuccess(request, json_object_new_int(count), NULL);
+ AFB_REQ_NOTICE(request, "ping count = %d", count);
+ afb_req_success(request, json_object_new_int(count), NULL);
return;
}
-void HalMgrLoaded(AFB_ReqT request)
+void HalMgrLoaded(afb_req_t request)
{
int requestJsonErr = 0, allHal = 0, verbose = 0;
char cardIdString[32];
- AFB_ApiT apiHandle;
+ afb_api_t apiHandle;
struct HalMgrData *HalMgrGlobalData;
struct SpecificHalData *currentHalData;
json_object *requestJson, *requestAnswer, *apiObject;
- apiHandle = (AFB_ApiT ) AFB_ReqGetApi(request);
- if(! apiHandle) {
- AFB_ReqFail(request, "api_handle", "Can't get hal manager api handle");
+ if(! (apiHandle = afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get hal manager api handle");
return;
}
- HalMgrGlobalData = (struct HalMgrData *) AFB_ApiGetUserData(apiHandle);
- if(! HalMgrGlobalData) {
- AFB_ReqFail(request, "hal_manager_data", "Can't get hal manager data");
+ if(! (HalMgrGlobalData = (struct HalMgrData *) afb_api_get_userdata(apiHandle))) {
+ afb_req_fail(request, "hal_manager_data", "Can't get hal manager data");
return;
}
currentHalData = HalMgrGlobalData->first;
if(! currentHalData) {
- AFB_ReqSuccess(request, NULL, "No Hal Api loaded");
+ afb_req_success(request, NULL, "No Hal Api loaded");
return;
}
requestAnswer = json_object_new_array();
if(! requestAnswer) {
- AFB_ReqFail(request, "json_answer", "Can't generate json answer");
+ afb_req_fail(request, "json_answer", "Can't generate json answer");
return;
}
- requestJson = AFB_ReqJson(request);
- if(! requestJson)
- AFB_ReqNotice(request, "Can't get request json");
+ if(! (requestJson = afb_req_json(request)))
+ AFB_REQ_NOTICE(request, "Can't get request json");
else
requestJsonErr = wrap_json_unpack(requestJson, "{s?:b s?:b}", "all", &allHal, "verbose", &verbose);
@@ -128,41 +127,38 @@ void HalMgrLoaded(AFB_ReqT request)
currentHalData = currentHalData->next;
}
- AFB_ReqSuccess(request, requestAnswer, "Requested data");
+ afb_req_success(request, requestAnswer, "Requested data");
}
-void HalMgrLoad(AFB_ReqT request)
+void HalMgrLoad(afb_req_t request)
{
int cardId = -1;
char *apiName, *sndCardPath, *info = NULL, *author = NULL, *version = NULL, *date = NULL;
- AFB_ApiT apiHandle;
+ afb_api_t apiHandle;
struct HalMgrData *HalMgrGlobalData;
struct SpecificHalData *addedHal;
json_object *requestJson, *apiReceviedMetadata;
- apiHandle = (AFB_ApiT) AFB_ReqGetApi(request);
- if(! apiHandle) {
- AFB_ReqFail(request, "api_handle", "Can't get hal manager api handle");
+ if(! (apiHandle = afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get hal manager api handle");
return;
}
- HalMgrGlobalData = (struct HalMgrData *) AFB_ApiGetUserData(apiHandle);
- if(! HalMgrGlobalData) {
- AFB_ReqFail(request, "hal_manager_data", "Can't get hal manager data");
+ if(! (HalMgrGlobalData = (struct HalMgrData *) afb_api_get_userdata(apiHandle))) {
+ afb_req_fail(request, "hal_manager_data", "Can't get hal manager data");
return;
}
- requestJson = AFB_ReqJson(request);
- if(! requestJson) {
- AFB_ReqFail(request, "request_json", "Can't get request json");
+ if(! (requestJson = afb_req_json(request))) {
+ afb_req_fail(request, "request_json", "Can't get request json");
return;
}
if(! json_object_object_get_ex(requestJson, "metadata", &apiReceviedMetadata)) {
- AFB_ReqFail(request, "api_metadata", "Can't get json metadata section to register external hal");
+ afb_req_fail(request, "api_metadata", "Can't get json metadata section to register external hal");
return;
}
@@ -175,7 +171,7 @@ void HalMgrLoad(AFB_ReqT request)
"version", &version,
"date", &date,
"snd-dev-id", &cardId)) {
- AFB_ReqFail(request, "api_metadata", "Can't metadata of api to register");
+ afb_req_fail(request, "api_metadata", "Can't metadata of api to register");
return;
}
@@ -204,75 +200,71 @@ void HalMgrLoad(AFB_ReqT request)
// TBD JAI: add subscription to this api status events, if subscription fails, remove hal from list
- AFB_ReqSuccess(request, NULL, "Api successfully registered");
+ afb_req_success(request, NULL, "Api successfully registered");
}
-void HalMgrUnload(AFB_ReqT request)
+void HalMgrUnload(afb_req_t request)
{
char *apiName;
- AFB_ApiT apiHandle;
+ afb_api_t apiHandle;
struct HalMgrData *HalMgrGlobalData;
struct SpecificHalData *HalToRemove;
json_object *requestJson;
- apiHandle = (AFB_ApiT) AFB_ReqGetApi(request);
- if(! apiHandle) {
- AFB_ReqFail(request, "api_handle", "Can't get hal manager api handle");
+ if(! (apiHandle = afb_req_get_api(request))) {
+ afb_req_fail(request, "api_handle", "Can't get hal manager api handle");
return;
}
- HalMgrGlobalData = (struct HalMgrData *) AFB_ApiGetUserData(apiHandle);
- if(! HalMgrGlobalData) {
- AFB_ReqFail(request, "hal_manager_data", "Can't get hal manager data");
+ if(! (HalMgrGlobalData = (struct HalMgrData *) afb_api_get_userdata(apiHandle))) {
+ afb_req_fail(request, "hal_manager_data", "Can't get hal manager data");
return;
}
- requestJson = AFB_ReqJson(request);
- if(! requestJson) {
- AFB_ReqFail(request, "request_json", "Can't get request json");
+ if(! (requestJson = afb_req_json(request))) {
+ afb_req_fail(request, "request_json", "Can't get request json");
return;
}
if(wrap_json_unpack(requestJson, "{s:s}", "api", &apiName)) {
- AFB_ReqFail(request, "requested_api", "Can't get api to remove");
+ afb_req_fail(request, "requested_api", "Can't get api to remove");
return;
}
- HalToRemove = HalUtlSearchHalDataByApiName(&HalMgrGlobalData->first, apiName);
- if(! HalToRemove) {
- AFB_ReqFail(request, "requested_api", "Can't find api to remove");
+ if(! (HalToRemove = HalUtlSearchHalDataByApiName(&HalMgrGlobalData->first, apiName))) {
+ afb_req_fail(request, "requested_api", "Can't find api to remove");
return;
}
if(HalToRemove->internal) {
- AFB_ReqFail(request, "requested_api", "Can't remove an internal controller api");
+ afb_req_fail(request, "requested_api", "Can't remove an internal controller api");
return;
}
if(HalUtlRemoveSelectedHalFromList(&HalMgrGlobalData->first, HalToRemove)) {
- AFB_ReqFail(request, "unregister_error", "Didn't succeed to remove specified api");
+ afb_req_fail(request, "unregister_error", "Didn't succeed to remove specified api");
return;
}
// TBD JAI: remove subscription to this api status events
- AFB_ReqSuccess(request, NULL, "Api successfully unregistered");
+ afb_req_success(request, NULL, "Api successfully unregistered");
}
// TBD JAI : to implement
-void HalMgrSubscribeEvent(AFB_ReqT request)
+void HalMgrSubscribeEvent(afb_req_t request)
{
- AFB_ReqWarning(request, "Not implemented yet");
+ AFB_REQ_WARNING(request, "Not implemented yet");
- AFB_ReqSuccess(request, json_object_new_boolean(0), NULL);
+ afb_req_success(request, json_object_new_boolean(0), NULL);
}
// TBD JAI : to implement
-void HalMgrUnsubscribeEvent(AFB_ReqT request)
+void HalMgrUnsubscribeEvent(afb_req_t request)
{
- AFB_ReqWarning(request, "Not implemented yet");
+ AFB_REQ_WARNING(request, "Not implemented yet");
- AFB_ReqSuccess(request, json_object_new_boolean(0), NULL);
+ afb_req_success(request, json_object_new_boolean(0), NULL);
}
diff --git a/4a-hal/4a-hal-manager/4a-hal-manager-cb.h b/4a-hal/4a-hal-manager/4a-hal-manager-cb.h
index dbed634..e0e144f 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager-cb.h
+++ b/4a-hal/4a-hal-manager/4a-hal-manager-cb.h
@@ -20,17 +20,17 @@
#include <stdio.h>
-#include <afb-definitions.h>
+#include <afb/afb-binding.h>
// Event handler
-void HalMgrDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_object *eventJ);
+void HalMgrDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_object *eventJ);
// Exported verbs callbacks
-void HalMgrPing(AFB_ReqT request);
-void HalMgrLoaded(AFB_ReqT request);
-void HalMgrLoad(AFB_ReqT request);
-void HalMgrUnload(AFB_ReqT request);
-void HalMgrSubscribeEvent(AFB_ReqT request);
-void HalMgrUnsubscribeEvent(AFB_ReqT request);
+void HalMgrPing(afb_req_t request);
+void HalMgrLoaded(afb_req_t request);
+void HalMgrLoad(afb_req_t request);
+void HalMgrUnload(afb_req_t request);
+void HalMgrSubscribeEvent(afb_req_t request);
+void HalMgrUnsubscribeEvent(afb_req_t request);
#endif /* _HALMGR_CB_INCLUDE_ */ \ No newline at end of file
diff --git a/4a-hal/4a-hal-manager/4a-hal-manager-events.h b/4a-hal/4a-hal-manager/4a-hal-manager-events.h
index 30034cf..bf0d9ff 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager-events.h
+++ b/4a-hal/4a-hal-manager/4a-hal-manager-events.h
@@ -20,7 +20,7 @@
#include <stdio.h>
-#include <afb-definitions.h>
+#include <afb/afb-binding.h>
// TBD JAI: declare events handlers functions
diff --git a/4a-hal/4a-hal-manager/4a-hal-manager.c b/4a-hal/4a-hal-manager/4a-hal-manager.c
index c510d17..75177e7 100644
--- a/4a-hal/4a-hal-manager/4a-hal-manager.c
+++ b/4a-hal/4a-hal-manager/4a-hal-manager.c
@@ -20,7 +20,7 @@
#include <stdio.h>
#include <string.h>
-#include <afb-definitions.h>
+#include <afb/afb-binding.h>
#include "4a-hal-utilities-data.h"
#include "4a-hal-utilities-verbs-loader.h"
@@ -31,7 +31,7 @@
#include "4a-hal-manager-cb.h"
// Default api to print log when apihandle not available
-AFB_ApiT AFB_default;
+afb_api_t AFB_default;
// Local (static) Hal manager data structure
static struct HalMgrData localHalMgrGlobalData;
@@ -41,7 +41,7 @@ static struct HalMgrData localHalMgrGlobalData;
******************************************************************************/
// Hal manager exported verbs
-AFB_ApiVerbs HalManagerApiStaticVerbs[] =
+afb_verb_t HalManagerApiStaticVerbs[] =
{
/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */
{ .verb = "ping", .callback = HalMgrPing, .info = "Ping test"},
@@ -67,7 +67,7 @@ struct SpecificHalData **HalMngGetFirstHalData(void)
* Dynamic API functions for hal manager *
******************************************************************************/
-static int HalMgrInitApi(AFB_ApiT apiHandle)
+static int HalMgrInitApi(afb_api_t apiHandle)
{
struct SpecificHalData *currentCtlHalData;
struct HalMgrData *HalMgrGlobalData;
@@ -79,8 +79,7 @@ static int HalMgrInitApi(AFB_ApiT apiHandle)
AFB_default = apiHandle;
// Retrieve section config from api handle
- HalMgrGlobalData = (struct HalMgrData *) AFB_ApiGetUserData(apiHandle);
- if(! HalMgrGlobalData)
+ if(! (HalMgrGlobalData = (struct HalMgrData *) afb_api_get_userdata(apiHandle)))
return -2;
if(HalUtlInitializeHalMgrData(apiHandle, HalMgrGlobalData, HAL_MANAGER_API_NAME, HAL_MANAGER_API_INFO))
@@ -91,7 +90,7 @@ static int HalMgrInitApi(AFB_ApiT apiHandle)
while(currentCtlHalData) {
if(! currentCtlHalData->apiName)
return -4;
- else if(AFB_RequireApi(apiHandle, currentCtlHalData->apiName, 1))
+ else if(afb_api_require_api(apiHandle, currentCtlHalData->apiName, 1))
return -5;
currentCtlHalData = currentCtlHalData->next;
@@ -100,7 +99,7 @@ static int HalMgrInitApi(AFB_ApiT apiHandle)
return 0;
}
-static int HalMgrLoadApi(void *cbdata, AFB_ApiT apiHandle)
+static int HalMgrLoadApi(void *cbdata, afb_api_t apiHandle)
{
struct HalMgrData *HalMgrGlobalData;
@@ -110,39 +109,39 @@ static int HalMgrLoadApi(void *cbdata, AFB_ApiT apiHandle)
HalMgrGlobalData = (struct HalMgrData *) cbdata;
// Save closure as api's data context
- AFB_ApiSetUserData(apiHandle, HalMgrGlobalData);
+ afb_api_set_userdata(apiHandle, HalMgrGlobalData);
// Add static controls verbs
if(HalUtlLoadVerbs(apiHandle, HalManagerApiStaticVerbs)) {
- AFB_ApiError(apiHandle, "Load section : fail to register static verbs");
+ AFB_API_ERROR(apiHandle, "Load section : fail to register static verbs");
return 1;
}
// Declare an event manager for Hal Manager
- AFB_ApiOnEvent(apiHandle, HalMgrDispatchApiEvent);
+ afb_api_on_event(apiHandle, HalMgrDispatchApiEvent);
// Init Api function (does not receive user closure ???)
- AFB_ApiOnInit(apiHandle, HalMgrInitApi);
+ afb_api_on_init(apiHandle, HalMgrInitApi);
- AFB_ApiSeal(apiHandle);
+ afb_api_seal(apiHandle);
return 0;
}
-int HalMgrCreateApi(AFB_ApiT apiHandle, struct HalMgrData *HalMgrGlobalData)
+int HalMgrCreateApi(afb_api_t apiHandle, struct HalMgrData *HalMgrGlobalData)
{
if(! apiHandle || ! HalMgrGlobalData)
return -1;
// Create one API
- return AFB_NewApi(apiHandle, HAL_MANAGER_API_NAME, HAL_MANAGER_API_INFO, 1, HalMgrLoadApi, HalMgrGlobalData) ? 0 : -1;
+ return afb_api_new_api(apiHandle, HAL_MANAGER_API_NAME, HAL_MANAGER_API_INFO, 1, HalMgrLoadApi, HalMgrGlobalData) ? 0 : -1;
}
/*******************************************************************************
* Startup function *
******************************************************************************/
-int afbBindingEntry(AFB_ApiT apiHandle)
+int afbBindingEntry(afb_api_t apiHandle)
{
int status = 0, rc;
@@ -152,7 +151,7 @@ int afbBindingEntry(AFB_ApiT apiHandle)
// Hugely hack to make all V2 AFB_DEBUG to work in fileutils
AFB_default = apiHandle;
- AFB_ApiNotice(apiHandle, "Binding start");
+ AFB_API_NOTICE(apiHandle, "Binding start");
// Load Hal-Manager using Api v3
rc = HalMgrCreateApi(apiHandle, &localHalMgrGlobalData);