summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp3
-rw-r--r--signal-composer-binding/signal-composer.cpp64
-rw-r--r--signal-composer-binding/signal-composer.hpp2
-rw-r--r--signal-composer-binding/signal.cpp3
4 files changed, 25 insertions, 47 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 7cdda91..0d9c8e3 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -279,9 +279,6 @@ int execConf()
int err = 0;
CtlConfigExec(nullptr, composer.ctlConfig());
- composer.initSourcesAPI();
- composer.initSignals();
-
AFB_DEBUG("Signal Composer Control configuration Done.");
return err;
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 3b11a70..ce4fe47 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -37,6 +37,22 @@ extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, struct s
sig->set(timestamp, value);
}
+bool startsWith(const std::string& str, const std::string& pattern)
+{
+ size_t sep;
+ if( (sep = str.find(pattern)) != std::string::npos && !sep)
+ {return true;}
+ return false;
+}
+
+void extractString(void* closure, json_object* object)
+{
+ std::vector<std::string> *files = (std::vector<std::string>*) closure;
+ const char *oneFile = json_object_get_string(object);
+
+ files->push_back(oneFile);
+}
+
// aSignal member value will be initialized in sourceAPI->addSignal()
static struct signalCBT pluginHandle = {
.searchNsetSignalValue = searchNsetSignalValueHandle,
@@ -47,7 +63,7 @@ static struct signalCBT pluginHandle = {
CtlSectionT Composer::ctlSections_[] = {
[0]={.key="plugins" , .uid="plugins", .info=nullptr,
- .loadCB=pluginsLoad,
+ .loadCB=PluginConfig,
.handle=&pluginHandle,
.actions=nullptr},
[1]={.key="sources" , .uid="sources", .info=nullptr,
@@ -89,25 +105,13 @@ CtlActionT* Composer::convert2Action(const std::string& name, json_object* actio
CtlActionT *ctlAction = new CtlActionT;
json_object_object_add(actionJ, "uid", json_object_new_string(name.c_str()));
+
if(! ActionLoadOne(nullptr, ctlAction, actionJ, 0))
{return ctlAction;}
-
delete(ctlAction);
return nullptr;
}
-/// @brief Load controller plugins
-///
-/// @param[in] section - Control Section structure
-/// @param[in] pluginsJ - JSON object containing all plugins definition made in
-/// JSON configuration file.
-///
-/// @return 0 if OK, other if not.
-int Composer::pluginsLoad(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ)
-{
- return PluginConfig(nullptr, section, pluginsJ);
-}
-
int Composer::loadOneSourceAPI(json_object* sourceJ)
{
json_object *initJ = nullptr,
@@ -158,7 +162,9 @@ int Composer::loadOneSourceAPI(json_object* sourceJ)
if(!getSignalsJ)
{
getSignalsJ = json_object_new_object();
- std::string function = "api://" + std::string(api) + "/subscribe";
+ std::string uri = "api://" + std::string(api);
+ std::string function = "subscribe";
+ json_object_object_add(getSignalsJ, "uri", json_object_new_string(uri.c_str()));
json_object_object_add(getSignalsJ, "function", json_object_new_string(function.c_str()));
}
getSignalsCtl = convert2Action("getSignals", getSignalsJ);
@@ -259,11 +265,6 @@ int Composer::loadOneSignal(json_object* signalJ)
}
std::string api = eventStr.substr(0, sep);
src = getSourceAPI(api);
- if(!src)
- {
- AFB_ERROR("This signal'source isn't registered. Check your configuration.");
- return -1;
- }
}
else
{
@@ -362,6 +363,8 @@ int Composer::loadSignals(AFB_ApiT apihandle, CtlSectionT* section, json_object
{err = composer.loadOneSignal(signalsJ);}
AFB_NOTICE("%ld new signals added to service", count);
}
+ else
+ {Composer::instance().initSignals();}
return err;
}
@@ -452,27 +455,6 @@ void Composer::destroyContext(void* ctx)
delete(reinterpret_cast<clientAppCtx*>(ctx));
}
-std::vector<std::string> Composer::parseURI(const std::string& uri)
-{
- std::vector<std::string> uriV;
- std::string delimiters = "/";
-
- std::string::size_type start = 0;
- auto pos = uri.find_first_of(delimiters, start);
- while(pos != std::string::npos)
- {
- if(pos != start) // ignore empty tokens
- uriV.emplace_back(uri, start, pos - start);
- start = pos + 1;
- pos = uri.find_first_of(delimiters, start);
- }
-
- if(start < uri.length()) // ignore trailing delimiter
- uriV.emplace_back(uri, start, uri.length() - start); // add what's left of the string
-
- return uriV;
-}
-
int Composer::loadConfig(std::string& filepath)
{
const char *dirList= getenv("CONTROL_CONFIG_PATH");
diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp
index db45189..7139a72 100644
--- a/signal-composer-binding/signal-composer.hpp
+++ b/signal-composer-binding/signal-composer.hpp
@@ -35,7 +35,6 @@ private:
~Composer();
CtlActionT* convert2Action(const std::string& name, json_object* action);
- static int pluginsLoad(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ);
int loadOneSourceAPI(json_object* sourcesJ);
static int loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_object *signalsJ);
@@ -50,7 +49,6 @@ public:
static Composer& instance();
static void* createContext(void* ctx);
static void destroyContext(void* ctx);
- static std::vector<std::string> parseURI(const std::string& uri);
int loadConfig(std::string& filepath);
int loadSources(json_object* sourcesJ);
int loadSignals(json_object* signalsJ);
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 577d94c..63bc0a8 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -189,7 +189,8 @@ struct signalCBT* Signal::get_context()
signalCtx_.aSignal = (void*)this;
- signalCtx_.pluginCtx = onReceived_ && onReceived_->type == CTL_TYPE_CB ?
+ signalCtx_.pluginCtx = onReceived_ && onReceived_->type == CTL_TYPE_CB
+ && onReceived_->exec.cb.plugin ?
onReceived_->exec.cb.plugin->context:
nullptr;
}