aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-20 16:54:14 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit78202d5bd8a8d09a55bb71b9df6d3f54b18184b8 (patch)
treeafbc89a7c104a70e7771939765309e977a5ab96a /signal-composer-binding
parentb68f95e384aa35b54e453b5e7d09dabf8d82340c (diff)
Make LUA works
- Added LUA library at link - Make app-template crash build if a checked file fails - Fix old defined variable CONTROL_LUA_PATH to a default one in the binding data directory - Add an example with unit conversion made in LUA Change-Id: I1b4712bde32a38044ad6b14ebd38b6782fd01fe9 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp12
-rw-r--r--signal-composer-binding/signal-composer.cpp21
-rw-r--r--signal-composer-binding/signal-composer.hpp1
-rw-r--r--signal-composer-binding/signal.cpp6
-rw-r--r--signal-composer-binding/signal.hpp7
-rw-r--r--signal-composer-binding/source.cpp16
-rw-r--r--signal-composer-binding/source.hpp1
7 files changed, 45 insertions, 19 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 4f12150..269eaba 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -20,14 +20,16 @@
// afb-utilities
#include <wrap-json.h>
#include <filescan-utils.h>
-// controller
-#include <ctl-lua.h>
#include "signal-composer-binding.hpp"
#include "signal-composer-apidef.h"
#include "signal-composer.hpp"
-/// @brief callback for receiving message from low binding. Treatment itself is made in SigComp class.
+/// @brief callback for receiving message from low bindings. This will callback
+/// an action defined in the configuration files depending on the event received
+///
+/// @param[in] event - event name
+/// @param[in] object - eventual data that comes with the event
void onEvent(const char *event, json_object *object)
{
AFB_DEBUG("Received event json: %s", json_object_to_json_string(object));
@@ -130,10 +132,6 @@ int loadConf()
bindingApp& bApp = bindingApp::instance();
err = bApp.loadConfig(rootdir);
- #ifdef CONTROL_SUPPORT_LUA
- err += LuaConfigLoad();
- #endif
-
return err;
}
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 151de6c..2e4f221 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -84,6 +84,15 @@ SourceAPI* bindingApp::getSourceAPI(const std::string& api)
}
return nullptr;
}
+int bindingApp::initSourcesAPI()
+{
+ int err = 0;
+ for(auto& src: sourcesListV_)
+ {
+ err += src.init();
+ }
+ return err;
+}
std::vector<std::string> bindingApp::parseURI(const std::string& uri)
{
@@ -123,7 +132,7 @@ CtlActionT* bindingApp::convert2Action(const std::string& name, json_object* act
std::string fName = std::string(function).substr(6);
wrap_json_pack(&action, "{ss,ss,so*}",
"label", name.c_str(),
- "lua", fName,
+ "lua", fName.c_str(),
"args", functionArgsJ);
}
else if(startsWith(function, "api://"))
@@ -205,13 +214,13 @@ int bindingApp::loadSourcesAPI(CtlSectionT* section, json_object *sourcesJ)
{
int err = 0;
bindingApp& bApp = instance();
- json_object *sigCompJ = nullptr;
- // add the signal composer itself as source
if(sourcesJ)
{
+ json_object *sigCompJ = nullptr;
+ // add the signal composer itself as source
wrap_json_pack(&sigCompJ, "{ss,ss}",
- "api", "signal-composer",
+ "api", afbBindingV2.api,
"info", "Api on behalf the virtual signals are sent");
json_object_array_add(sourcesJ, sigCompJ);
@@ -232,7 +241,9 @@ int bindingApp::loadSourcesAPI(CtlSectionT* section, json_object *sourcesJ)
if ((err = bApp.loadOneSourceAPI(sourcesJ))) return err;
if (sigCompJ && (err = bApp.loadOneSourceAPI(sigCompJ))) return err;
}
-}
+ }
+ else
+ {err += bindingApp::instance().initSourcesAPI();}
return err;
}
diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp
index 4050700..689f107 100644
--- a/signal-composer-binding/signal-composer.hpp
+++ b/signal-composer-binding/signal-composer.hpp
@@ -49,6 +49,7 @@ public:
int loadSignals(json_object* signalsJ);
CtlConfigT* ctlConfig();
+ int initSourcesAPI();
std::vector<std::shared_ptr<Signal>> getAllSignals();
SourceAPI* getSourceAPI(const std::string& api);
std::shared_ptr<Signal> searchSignal(const std::string& aName);
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 1679a6f..309a156 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -182,7 +182,7 @@ void Signal::attachToSourceSignals(bindingApp& bApp)
/// @brief Call update() method on observer Signal with
/// current Signal timestamp and value
-void Signal::notify()
+void Signal::notify() const
{
for (int i = 0; i < Observers_.size(); ++i)
Observers_[i]->update(timestamp_, value_);
@@ -194,7 +194,7 @@ void Signal::notify()
/// @param[in] origId - name of the origine of the recursion check
///
/// @return 0 if no infinite loop detected, -1 if not.
-int Signal::recursionCheck(const std::string& origId)
+int Signal::recursionCheck(const std::string& origId) const
{
for (const auto& obs: Observers_)
{
@@ -214,7 +214,7 @@ int Signal::recursionCheck(const std::string& origId)
/// then trigger the check against the following eventuals observers
///
/// @return 0 if no infinite loop detected, -1 if not.
-int Signal::recursionCheck()
+int Signal::recursionCheck() const
{
for (const auto& obs: Observers_)
{
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 4e078fc..c029a64 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -49,13 +49,14 @@ private:
std::vector<Signal*> Observers_;
- void notify();
+ void notify() const;
void attach(Signal *obs);
- int recursionCheck(const std::string& origId);
+ int recursionCheck(const std::string& origId) const;
public:
Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
Signal(const std::string& id, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived);
+
explicit operator bool() const;
bool operator==(const Signal& other) const;
bool operator==(const std::string& aName) const;
@@ -72,5 +73,5 @@ public:
double minimum(int seconds = 0) const;
double maximum(int seconds = 0) const;
struct SignalValue last() const;
- int recursionCheck();
+ int recursionCheck() const;
};
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index 1f5d588..2f4ab03 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -16,6 +16,7 @@
*/
#include "source.hpp"
+#include "signal-composer.hpp"
SourceAPI::SourceAPI()
{}
@@ -24,6 +25,18 @@ SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT
api_(api), info_(info), init_(init), getSignals_(getSignals)
{}
+int SourceAPI::init()
+{
+ if(init_)
+ {return ActionExecOne(init_, nullptr);}
+ else if(api_ == afbBindingV2.api)
+ {
+ api_ = bindingApp::instance().ctlConfig()->api;
+ }
+
+ return 0;
+}
+
std::string SourceAPI::api() const
{
return api_;
@@ -71,7 +84,8 @@ int SourceAPI::makeSubscription()
}
err += sig.second ? 0:ActionExecOne(getSignals_, signalJ);
if(err)
- {AFB_WARNING("Fails to subscribe to signal %s", sig.first->id().c_str());}
+ {AFB_WARNING("Fails to subscribe to signal '%s/%s'",
+ api_.c_str(), sig.first->id().c_str());}
else
{sig.second = true;}
}
diff --git a/signal-composer-binding/source.hpp b/signal-composer-binding/source.hpp
index 560a137..a995b07 100644
--- a/signal-composer-binding/source.hpp
+++ b/signal-composer-binding/source.hpp
@@ -34,6 +34,7 @@ public:
SourceAPI();
SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignal);
+ int init();
std::string api() const;
void addSignal(const std::string& id, const std::string& event, std::vector<std::string>& sources, const std::string& sClass, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);