summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/CMakeLists.txt2
-rw-r--r--signal-composer-binding/clientApp.cpp6
-rw-r--r--signal-composer-binding/clientApp.hpp6
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp30
-rw-r--r--signal-composer-binding/signal-composer-binding.hpp7
-rw-r--r--signal-composer-binding/signal-composer.cpp59
-rw-r--r--signal-composer-binding/signal-composer.hpp12
-rw-r--r--signal-composer-binding/signal.cpp18
-rw-r--r--signal-composer-binding/source.cpp9
-rw-r--r--signal-composer-binding/source.hpp2
10 files changed, 68 insertions, 83 deletions
diff --git a/signal-composer-binding/CMakeLists.txt b/signal-composer-binding/CMakeLists.txt
index f47c9f1..2f99203 100644
--- a/signal-composer-binding/CMakeLists.txt
+++ b/signal-composer-binding/CMakeLists.txt
@@ -26,7 +26,7 @@ PROJECT_TARGET_ADD(signal-composer)
# Binder exposes a unique public entry point
SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
PREFIX "afb-"
- LABELS "BINDINGV2"
+ LABELS "BINDINGV3"
LINK_FLAGS ${BINDINGS_LINK_FLAG}
OUTPUT_NAME ${TARGET_NAME}
)
diff --git a/signal-composer-binding/clientApp.cpp b/signal-composer-binding/clientApp.cpp
index 45c43e6..7ead993 100644
--- a/signal-composer-binding/clientApp.cpp
+++ b/signal-composer-binding/clientApp.cpp
@@ -19,7 +19,7 @@
clientAppCtx::clientAppCtx(const char* uuid)
: uuid_{uuid},
- event_{nullptr,nullptr}
+ event_{nullptr}
{}
void clientAppCtx::update(Signal* sig)
@@ -79,14 +79,14 @@ void clientAppCtx::subtractSignals(std::vector<std::shared_ptr<Signal>>& sigV)
}
}
-int clientAppCtx::makeSubscription(struct afb_req request)
+int clientAppCtx::makeSubscription(AFB_ReqT request)
{
event_ = afb_event_is_valid(event_) ?
event_ : afb_daemon_make_event(uuid_.c_str());
return afb_req_subscribe(request, event_);
}
-int clientAppCtx::makeUnsubscription(struct afb_req request)
+int clientAppCtx::makeUnsubscription(AFB_ReqT request)
{
if(subscribedSignals_.empty())
{
diff --git a/signal-composer-binding/clientApp.hpp b/signal-composer-binding/clientApp.hpp
index f91b299..84746fa 100644
--- a/signal-composer-binding/clientApp.hpp
+++ b/signal-composer-binding/clientApp.hpp
@@ -23,13 +23,13 @@ class clientAppCtx: public Observer<Signal>
private:
std::string uuid_;
std::vector<std::shared_ptr<Signal>> subscribedSignals_;
- struct afb_event event_;
+ AFB_EventT event_;
public:
explicit clientAppCtx(const char* uuid);
void update(Signal* sig);
void appendSignals(std::vector<std::shared_ptr<Signal>>& sigV);
void subtractSignals(std::vector<std::shared_ptr<Signal>>& sigV);
- int makeSubscription(struct afb_req request);
- int makeUnsubscription(struct afb_req request);
+ int makeSubscription(AFB_ReqT request);
+ int makeUnsubscription(AFB_ReqT request);
};
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 7d3391b..6c60526 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -20,8 +20,8 @@
// afb-utilities
#include <wrap-json.h>
#include <filescan-utils.h>
+#include <afb/afb-binding>
-#include "signal-composer-binding.hpp"
#include "signal-composer-apidef.h"
#include "clientApp.hpp"
@@ -74,7 +74,7 @@ void onEvent(const char *event, json_object *object)
}
}
-static int one_subscribe_unsubscribe(struct afb_req request,
+static int one_subscribe_unsubscribe(AFB_ReqT request,
bool subscribe,
const std::string& event,
json_object* args,
@@ -104,7 +104,7 @@ static int one_subscribe_unsubscribe(struct afb_req request,
return err;
}
-static int subscribe_unsubscribe(struct afb_req request,
+static int subscribe_unsubscribe(AFB_ReqT request,
bool subscribe,
json_object* args,
clientAppCtx* cContext)
@@ -133,7 +133,7 @@ static int subscribe_unsubscribe(struct afb_req request,
}
/// @brief entry point for client subscription request.
-static void do_subscribe_unsubscribe(afb_req request, bool subscribe, clientAppCtx* cContext)
+static void do_subscribe_unsubscribe(AFB_ReqT request, bool subscribe, clientAppCtx* cContext)
{
int rc = 0;
json_object *oneArg = nullptr, *args = afb_req_json(request);
@@ -157,24 +157,24 @@ static void do_subscribe_unsubscribe(afb_req request, bool subscribe, clientAppC
}
/// @brief entry point for client un-subscription request.
-void subscribe(afb_req request)
+void subscribe(AFB_ReqT request)
{
- clientAppCtx *cContext = reinterpret_cast<clientAppCtx*>(afb_req_context_make(request, 0, Composer::createContext, Composer::destroyContext, nullptr));
+ clientAppCtx *cContext = reinterpret_cast<clientAppCtx*>(afb_req_context(request, 0, Composer::createContext, Composer::destroyContext, nullptr));
do_subscribe_unsubscribe(request, true, cContext);
}
/// @brief entry point for client un-subscription request.
-void unsubscribe(afb_req request)
+void unsubscribe(AFB_ReqT request)
{
- clientAppCtx *cContext = reinterpret_cast<clientAppCtx*>(afb_req_context_make(request, 0, Composer::createContext, Composer::destroyContext, nullptr));
+ clientAppCtx *cContext = reinterpret_cast<clientAppCtx*>(afb_req_context(request, 0, Composer::createContext, Composer::destroyContext, nullptr));
do_subscribe_unsubscribe(request, false, cContext);
}
/// @brief verb that loads JSON configuration (old SigComp.json file now)
-void addObjects(afb_req request)
+void addObjects(AFB_ReqT request)
{
Composer& composer = Composer::instance();
json_object *sourcesJ = nullptr,
@@ -244,7 +244,7 @@ void addObjects(afb_req request)
}
/// @brief entry point to list available signals
-void list(afb_req request)
+void list(AFB_ReqT request)
{
struct json_object *allSignalsJ = json_object_new_array();
@@ -259,7 +259,7 @@ void list(afb_req request)
}
/// @brief entry point for get requests.
-void get(struct afb_req request)
+void get(AFB_ReqT request)
{
int err = 0, i = 0;
size_t l = 0;
@@ -295,22 +295,22 @@ void get(struct afb_req request)
}
-int loadConf()
+int loadConf(AFB_ApiT api)
{
int err = 0;
std::string bindingDirPath = GetBindingDirPath();
std::string rootdir = bindingDirPath + "/etc";
- err = Composer::instance().loadConfig(rootdir);
+ err = Composer::instance().loadConfig(api, rootdir);
return err;
}
-int execConf()
+int execConf(AFB_ApiT api)
{
Composer& composer = Composer::instance();
int err = 0;
- CtlConfigExec(nullptr, composer.ctlConfig());
+ CtlConfigExec(api, composer.ctlConfig());
AFB_DEBUG("Signal Composer Control configuration Done.");
diff --git a/signal-composer-binding/signal-composer-binding.hpp b/signal-composer-binding/signal-composer-binding.hpp
deleted file mode 100644
index 8ffdd76..0000000
--- a/signal-composer-binding/signal-composer-binding.hpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-#include <afb/afb-binding>
-
-void onEvent(const char *event, struct json_object *object);
-int loadConf();
-int execConf();
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 3b631c3..324d96e 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -84,19 +84,19 @@ Composer::~Composer()
free(ctlConfig_);
}
-CtlActionT* Composer::convert2Action(const std::string& name, json_object* actionJ)
+CtlActionT* Composer::convert2Action(AFB_ApiT apihandle, const std::string& name, json_object* actionJ)
{
CtlActionT *ctlAction = new CtlActionT;
json_object_object_add(actionJ, "uid", json_object_new_string(name.c_str()));
- if(! ActionLoadOne(nullptr, ctlAction, actionJ, 0))
+ if(! ActionLoadOne(apihandle, ctlAction, actionJ, 0))
{return ctlAction;}
delete(ctlAction);
return nullptr;
}
-int Composer::loadOneSourceAPI(json_object* sourceJ)
+int Composer::loadOneSourceAPI(AFB_ApiT apihandle, json_object* sourceJ)
{
json_object *initJ = nullptr,
*getSignalsJ = nullptr,
@@ -135,11 +135,11 @@ int Composer::loadOneSourceAPI(json_object* sourceJ)
if(ctlConfig_ && ctlConfig_->requireJ)
{
const char* requireS = json_object_to_json_string(ctlConfig_->requireJ);
- if(!strcasestr(requireS, api) && !strcasestr(api, afbBindingV2.api))
+ if(!strcasestr(requireS, api) && !strcasestr(api, afbBindingV3root->apiname))
{AFB_WARNING("Caution! You don't specify the API source as required in the metadata section. This API '%s' may not be initialized", api);}
}
- initCtl = initJ ? convert2Action("init", initJ) : nullptr;
+ initCtl = initJ ? convert2Action(apihandle, "init", initJ) : nullptr;
// Define default action to take to subscibe souce's signals if none
// defined.
@@ -150,9 +150,9 @@ int Composer::loadOneSourceAPI(json_object* sourceJ)
std::string uri = "api://" + std::string(api) + "#subscribe";
json_object_object_add(getSignalsJ, "action", json_object_new_string(uri.c_str()));
}
- getSignalsCtl = convert2Action("getSignals", getSignalsJ);
+ getSignalsCtl = convert2Action(apihandle, "getSignals", getSignalsJ);
- onReceivedCtl = onReceivedJ ? convert2Action("onReceived", onReceivedJ) : nullptr;
+ onReceivedCtl = onReceivedJ ? convert2Action(apihandle, "onReceived", onReceivedJ) : nullptr;
newSourcesListV_.push_back(std::make_shared<SourceAPI>(uid, api, info, initCtl, getSignalsCtl, onReceivedCtl, retention));
return err;
@@ -173,7 +173,7 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje
{
wrap_json_pack(&sigCompJ, "{ss,ss,ss}",
"uid", "Signal-Composer-service",
- "api", afbBindingV2.api,
+ "api", afbBindingV3root->apiname,
"info", "Api on behalf the virtual signals are sent");
if(json_object_is_type(sourcesJ, json_type_array))
@@ -187,17 +187,17 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje
for (int idx = 0; idx < count; idx++)
{
json_object *sourceJ = json_object_array_get_idx(sourcesJ, idx);
- err = composer.loadOneSourceAPI(sourceJ);
+ err = composer.loadOneSourceAPI(apihandle, sourceJ);
if (err) return err;
}
}
else
{
- if (err = composer.loadOneSourceAPI(sourcesJ))
+ if ( (err = composer.loadOneSourceAPI(apihandle, sourcesJ)) )
return err;
if (sigCompJ)
{
- if (err = composer.loadOneSourceAPI(sigCompJ))
+ if ( (err = composer.loadOneSourceAPI(apihandle, sigCompJ)) )
return err;
}
}
@@ -209,7 +209,7 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje
return err;
}
-int Composer::loadOneSignal(json_object* signalJ)
+int Composer::loadOneSignal(AFB_ApiT apihandle, json_object* signalJ)
{
json_object *onReceivedJ = nullptr,
*dependsJ = nullptr,
@@ -324,7 +324,7 @@ int Composer::loadOneSignal(json_object* signalJ)
if(onReceivedCtl)
{onReceivedCtl->uid = uid;}
}
- else {onReceivedCtl = convert2Action(uid, onReceivedJ);}
+ else {onReceivedCtl = convert2Action(apihandle, uid, onReceivedJ);}
if(src != nullptr)
{src->addSignal(id, event, dependsV, retention, unit, metadataJ, frequency, onReceivedCtl, getSignalsArgs);}
@@ -348,11 +348,11 @@ int Composer::loadSignals(AFB_ApiT apihandle, CtlSectionT* section, json_object
for (int idx = 0; idx < count; idx++)
{
json_object *signalJ = json_object_array_get_idx(signalsJ, idx);
- err += composer.loadOneSignal(signalJ);
+ err += composer.loadOneSignal(apihandle, signalJ);
}
}
else
- {err = composer.loadOneSignal(signalsJ);}
+ {err = composer.loadOneSignal(apihandle, signalsJ);}
AFB_NOTICE("%ld new signals added to service", count);
}
else
@@ -421,35 +421,30 @@ void Composer::destroyContext(void* ctx)
delete(reinterpret_cast<clientAppCtx*>(ctx));
}
-int Composer::loadConfig(std::string& filepath)
+int Composer::loadConfig(AFB_ApiT api, std::string& filepath)
{
const char *dirList= getenv("CONTROL_CONFIG_PATH");
if (!dirList) dirList=CONTROL_CONFIG_PATH;
filepath.append(":");
filepath.append(dirList);
- const char *configPath = CtlConfigSearch(nullptr, filepath.c_str(), "control");
+ const char *configPath = CtlConfigSearch(api, filepath.c_str(), "control");
if (!configPath) {
- AFB_ApiError(apiHandle, "CtlPreInit: No control-* config found invalid JSON %s ", filepath.c_str());
+ AFB_ERROR_V3("CtlPreInit: No control-* config found invalid JSON %s ", filepath.c_str());
return -1;
}
// create one API per file
- ctlConfig_ = CtlLoadMetaData(nullptr, configPath);
+ ctlConfig_ = CtlLoadMetaData(api, configPath);
if (!ctlConfig_) {
- AFB_ApiError(apiHandle, "CtrlPreInit No valid control config file in:\n-- %s", configPath);
+ AFB_ERROR_V3("CtrlPreInit No valid control config file in:\n-- %s", configPath);
return -1;
}
- if (ctlConfig_->api) {
- int err = afb_daemon_rename_api(ctlConfig_->api);
- if (err) {
- AFB_ApiError(apiHandle, "Fail to rename api to:%s", ctlConfig_->api);
- return -1;
- }
- }
+ // Save the config in the api userdata field
+ afb_api_set_userdata(api, ctlConfig_);
- int err= CtlLoadSections(nullptr, ctlConfig_, ctlSections_);
+ int err= CtlLoadSections(api, ctlConfig_, ctlSections_);
return err;
}
@@ -487,14 +482,14 @@ void Composer::initSourcesAPI()
}
}
-int Composer::initSignals()
+int Composer::initSignals(AFB_ReqT request)
{
for(int i=0; i < sourcesListV_.size(); i++)
{
std::shared_ptr<SourceAPI> src = sourcesListV_[i];
src->initSignals();
}
- return execSignalsSubscription();
+ return execSignalsSubscription(request);
}
std::shared_ptr<SourceAPI> Composer::getSourceAPI(const std::string& api)
@@ -586,14 +581,14 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio
return finalResponse;
}
-int Composer::execSignalsSubscription()
+int Composer::execSignalsSubscription(AFB_ReqT request)
{
int err = 0;;
for(std::shared_ptr<SourceAPI> srcAPI: sourcesListV_)
{
if (srcAPI->api() != std::string(ctlConfig_->api))
{
- err += srcAPI->makeSubscription();
+ err += srcAPI->makeSubscription(request);
}
}
diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp
index 72cd3ee..f70e9ac 100644
--- a/signal-composer-binding/signal-composer.hpp
+++ b/signal-composer-binding/signal-composer.hpp
@@ -34,25 +34,25 @@ private:
Composer();
~Composer();
- CtlActionT* convert2Action(const std::string& name, json_object* action);
+ CtlActionT* convert2Action(AFB_ApiT apihandle, const std::string& name, json_object* action);
- int loadOneSourceAPI(json_object* sourcesJ);
+ int loadOneSourceAPI(AFB_ApiT apihandle, json_object* sourcesJ);
static int loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_object *signalsJ);
- int loadOneSignal(json_object* signalsJ);
+ int loadOneSignal(AFB_ApiT apihandle, json_object* signalsJ);
static int loadSignals(AFB_ApiT apihandle, CtlSectionT* section, json_object *signalsJ);
- int execSignalsSubscription();
+ int execSignalsSubscription(AFB_ReqT request = nullptr);
std::shared_ptr<SourceAPI> getSourceAPI(const std::string& api);
void processOptions(const std::map<std::string, int>& opts, std::shared_ptr<Signal> sig, json_object* response) const;
public:
static Composer& instance();
static void* createContext(void* ctx);
static void destroyContext(void* ctx);
- int loadConfig(std::string& filepath);
+ int loadConfig(AFB_ApiT api, std::string& filepath);
int loadSources(json_object* sourcesJ);
int loadSignals(json_object* signalsJ);
- int initSignals();
+ int initSignals(AFB_ReqT request = nullptr);
void initSourcesAPI();
CtlConfigT* ctlConfig();
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index b77ab59..98eddf1 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -229,12 +229,13 @@ void Signal::set(uint64_t timestamp, json_object*& value)
void Signal::update(Signal* sig)
{
json_object *depSigJ = json_object_new_array();
- CtlSourceT src = {
- .uid = sig->id().c_str(),
- .api = nullptr,
- .request = {nullptr, nullptr},
- .context = (void*)get_context(),
- .status = CTL_STATUS_EVT};
+ CtlSourceT source;
+ ::memset(&source, 0, sizeof(CtlSourceT));
+ source.uid = sig->id().c_str();
+ source.api = afbBindingV3root;
+ source.context = (void*)get_context();
+ source.status = CTL_STATUS_EVT ;
+
Composer& composer = Composer::instance();
for(const std::string& depSignal : dependsSigV_)
@@ -247,7 +248,7 @@ void Signal::update(Signal* sig)
}
json_object_array_add(depSigJ, sig->toJSON());
- ActionExecOne(&src, onReceived_, depSigJ);
+ ActionExecOne(&source, onReceived_, depSigJ);
}
/// @brief
@@ -323,9 +324,8 @@ void Signal::onReceivedCB(json_object *eventJ)
}
CtlSourceT source;
+ ::memset(&source, 0, sizeof(CtlSourceT));
source.uid = id_.c_str();
- source.api = nullptr; // We use binding v2, no dynamic API.
- source.request = {nullptr, nullptr};
source.context = (void*)get_context();
if (onReceived_)
ActionExecOne(&source, onReceived_, json_object_get(eventJ));
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index 939e3f6..f400731 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -48,12 +48,10 @@ void SourceAPI::init()
{
CtlSourceT source;
source.uid = init_->uid;
- source.api = nullptr; // We use binding v2, no dynamic API.
- source.request = {nullptr, nullptr};
ActionExecOne(&source, init_, json_object_new_object());
return;
}
- else if(api_ == afbBindingV2.api)
+ else if(api_ == afbBindingV3root->apiname)
{api_ = Composer::instance().ctlConfig()->api;}
}
@@ -157,15 +155,14 @@ int SourceAPI::cleanNotSubscribedSignals() {
return erased;
}
-int SourceAPI::makeSubscription()
+int SourceAPI::makeSubscription(AFB_ReqT request)
{
int err = 0;
if(getSignals_)
{
CtlSourceT source;
source.uid = api_.c_str();
- source.api = nullptr; // We use binding v2, no dynamic API.
- source.request = {nullptr, nullptr};
+ source.request = request;
json_object *argsSaveJ = getSignals_->argsJ;
for(auto& sig: signalsM_)
diff --git a/signal-composer-binding/source.hpp b/signal-composer-binding/source.hpp
index 4fef274..b4f1348 100644
--- a/signal-composer-binding/source.hpp
+++ b/signal-composer-binding/source.hpp
@@ -54,5 +54,5 @@ public:
std::vector<std::shared_ptr<Signal>> searchSignals(const std::string& name);
int cleanNotSubscribedSignals();
- int makeSubscription();
+ int makeSubscription(AFB_ReqT request = nullptr);
};