summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer-binding.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-12 00:29:28 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commitd663f702c0e4fa562783504a483dce8f362d628e (patch)
treefdb656d0467a935aa6790dd9e05d3e373606a3e1 /signal-composer-binding/signal-composer-binding.cpp
parent75cfbf3d0206f12422091e6479c508c69445bf4a (diff)
Progression on config parsing.
Change-Id: Idd8d8987ccabef381f6d79c1d508930a2d4bae3c Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer-binding.cpp')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp64
1 files changed, 37 insertions, 27 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 2ca1dec..90401f2 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -13,27 +13,27 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+*/
-#include <ctl-config.h>
+#include <string.h>
+// 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 "wrap-json.h"
#include "signal-composer.hpp"
-SignalComposer SigComp;
-static CtlConfigT *ctlConfig=NULL;
-
/// @brief callback for receiving message from low binding. Treatment itself is made in SigComp class.
void onEvent(const char *event, json_object *object)
{
- SigComp.treatMessage(object);
}
/// @brief entry point for client subscription request. Treatment itself is made in SigComp class.
void subscribe(afb_req request)
{
- if(SigComp.subscribe(request))
+ if(true)
afb_req_success(request, NULL, NULL);
else
afb_req_fail(request, "error", NULL);
@@ -42,7 +42,7 @@ void subscribe(afb_req request)
/// @brief entry point for client un-subscription request. Treatment itself is made in SigComp class.
void unsubscribe(afb_req request)
{
- if(SigComp.unsubscribe(request))
+ if(true)
afb_req_success(request, NULL, NULL);
else
afb_req_fail(request, "error when unsubscribe", NULL);
@@ -55,7 +55,7 @@ void loadConf(afb_req request)
const char* confd;
wrap_json_unpack(args, "{s:s}", "path", &confd);
- int ret = SigComp.parseConfigAndSubscribe(confd);
+ int ret = 0;
if( ret == 0)
afb_req_success(request, NULL, NULL);
else
@@ -66,39 +66,49 @@ void loadConf(afb_req request)
void get(afb_req request)
{
json_object *jobj;
- if(SigComp.get(request, &jobj))
+ if(true)
{
afb_req_success(request, jobj, NULL);
- } else {
+ }
+ else
+ {
afb_req_fail(request, "error", NULL);
}
}
-/// @brief entry point for systemD timers. Treatment itself is made in SigComp class.
-/// @param[in] source: systemD timer, t: time of tick, data: interval (ms).
-int ticked(sd_event_source *source, uint64_t t, void* data)
-{
- SigComp.tick(source, t, data);
- return 0;
-}
-
int loadConf()
{
- int errcount=0;
+ int ret = 0;
+ const char* rootdir = strncat(GetBindingDirPath(), "/etc",
+ sizeof(GetBindingDirPath()) - strlen(GetBindingDirPath()) -1);
- ctlConfig = CtlConfigLoad();
+ bindingApp& bApp = bindingApp::instance();
+ bApp.loadConfig(rootdir);
#ifdef CONTROL_SUPPORT_LUA
- errcount += LuaLibInit();
+ ret += LuaConfigLoad();
#endif
- return errcount;
+ return ret;
}
int execConf()
{
- int err = CtlConfigExec();
+ bindingApp& bApp = bindingApp::instance();
+ int ret = CtlConfigExec(bApp.ctlConfig());
+ std::vector<std::shared_ptr<Signal>> allSignals = bApp.getAllSignals();
+ ssize_t sigCount = allSignals.size();
+
+ for(auto& sig: allSignals)
+ {
+ if( (ret = sig->recursionCheck()) )
+ {
+ AFB_ERROR("There is an infinite recursion loop in your signals definition. Root coming from signal: %s", sig->id().c_str());
+ return ret;
+ }
+ }
+
+ AFB_DEBUG("Signal Composer Control configuration Done.\n signals=%d", (int)sigCount);
- AFB_DEBUG ("Signal Composer Control configuration Done errcount=%d", errcount);
- return errcount;
+ return ret;
}