summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/source.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-11-02 15:58:45 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit6ee4db6878464642ddf9f0909748841a45b58a88 (patch)
tree4c3588d216e903174f1281b757e98816d7323afa /signal-composer-binding/source.cpp
parented2c3d0267e3c5e1392635dacad2752de935d6b4 (diff)
Migrate to ctl-utilities library
New version of controller as a library. Loading additionnals files from each sections. Change-Id: I4f5e78d0baf9650cb8d1cc1da26f8e1fd73b792c Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/source.cpp')
-rw-r--r--signal-composer-binding/source.cpp51
1 files changed, 21 insertions, 30 deletions
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index 4511fa7..3e8153a 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -28,14 +28,19 @@ SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT
signalsDefault_({onReceived, retention})
{}
-int SourceAPI::init()
+void SourceAPI::init()
{
if(init_)
- {return ActionExecOne(init_, nullptr);}
+ {
+ CtlSourceT source;
+ source.uid = init_->uid;
+ source.api = nullptr; // We use binding v2, no dynamic API.
+ source.request = {nullptr, nullptr};
+ ActionExecOne(&source, init_, nullptr);
+ return;
+ }
else if(api_ == afbBindingV2.api)
{api_ = Composer::instance().ctlConfig()->api;}
-
- return 0;
}
std::string SourceAPI::api() const
@@ -52,20 +57,6 @@ void SourceAPI::addSignal(const std::string& id, const std::string& event, std::
{
std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, retention, frequency, onReceived, getSignalsArgs);
- if(onReceived)
- {
- struct signalCBT* ctx = onReceived->source.context ?
- (struct signalCBT*)onReceived->source.context :
- (struct signalCBT*)calloc (1, sizeof(struct signalCBT));
- if(!ctx->searchNsetSignalValue)
- {ctx->searchNsetSignalValue = searchNsetSignalValueHandle;}
- if(!ctx->setSignalValue)
- {ctx->setSignalValue = setSignalValueHandle;}
-
- ctx->aSignal = (void*)sig.get();
- onReceived->source.context = (void*)ctx;
- }
-
signalsMap_[id] = sig;
}
@@ -104,29 +95,29 @@ std::vector<std::shared_ptr<Signal>> SourceAPI::searchSignals(const std::string&
return signals;
}
-int SourceAPI::makeSubscription()
+void SourceAPI::makeSubscription()
{
- 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};
+
for(auto& sig: signalsMap_)
{
json_object* signalJ = sig.second->toJSON();
if(!signalJ)
{
AFB_ERROR("Error building JSON query object to subscribe to for signal %s", sig.second->id().c_str());
- err = -1;
break;
}
- err += ActionExecOne(getSignals_, signalJ);
- if(err)
- {AFB_WARNING("Fails to subscribe to signal '%s/%s'",
- api_.c_str(), sig.second->id().c_str());}
- else
- {sig.second->subscribed_ = true;}
+ source.uid = sig.second->id().c_str();
+ source.context = (void*)sig.second->get_context();
+ ActionExecOne(&source, getSignals_, signalJ);
+ // Considerate signal subscribed no matter what
+ sig.second->subscribed_ = true;
}
- err += ActionExecOne(getSignals_, nullptr);
+ ActionExecOne(&source, getSignals_, nullptr);
}
-
- return err;
}