aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-21 18:17:45 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit58f2d68238464f8fb3451b3c8245e62914b4bb14 (patch)
tree4c3f62ed0c43b88fdf1069f093da5a36b2187844
parentb9dd9b46d25f106694528722d63fdc1611d31afd (diff)
Batch low-can subscription
Change-Id: Ic1561e34d01be2b15618536fe6ef01066c184520 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--plugins/low-can.cpp77
-rw-r--r--signal-composer-binding/source.cpp1
2 files changed, 42 insertions, 36 deletions
diff --git a/plugins/low-can.cpp b/plugins/low-can.cpp
index 7fc5020..c1fbd60 100644
--- a/plugins/low-can.cpp
+++ b/plugins/low-can.cpp
@@ -47,6 +47,7 @@ typedef struct {
typedef struct {
struct pluginCBT* pluginHandle;
+ json_object *subscriptionBatch;
allDoorsCtxT allDoorsCtx;
} lowCANCtxT;
@@ -58,14 +59,12 @@ void setDoor(doorT* aDoor, const char* eventName, int eventStatus)
}
// Call at initialisation time
-CTLP_ONLOAD(plugin, bAppHandle)
+CTLP_ONLOAD(plugin, composerHandle)
{
lowCANCtxT *pluginCtx= (lowCANCtxT*)calloc (1, sizeof(lowCANCtxT));
- allDoorsCtxT allDoorsCtx = allDoorsCtxT();
- ::memset(&allDoorsCtx, 0, sizeof(allDoorsCtxT));
- pluginCtx->allDoorsCtx = allDoorsCtx;
- pluginCtx->pluginHandle = (struct pluginCBT*)bAppHandle;
+ pluginCtx->pluginHandle = (struct pluginCBT*)composerHandle;
+ pluginCtx->subscriptionBatch = json_object_new_array();
AFB_NOTICE ("Low-can plugin: label='%s' version='%s' info='%s'",
plugin->label,
@@ -76,46 +75,52 @@ CTLP_ONLOAD(plugin, bAppHandle)
}
CTLP_CAPI (subscribeToLow, source, argsJ, eventJ, context) {
+ lowCANCtxT *pluginCtx = (lowCANCtxT*)source->context;
json_object* dependsArrayJ = nullptr, *subscribeArgsJ = nullptr, *subscribeFilterJ = nullptr, *responseJ = nullptr, *filterJ = nullptr;
const char *id = nullptr, *event = nullptr, *unit = nullptr;
double frequency = 0;
int err = 0;
- err = wrap_json_unpack(eventJ, "{ss,s?s,s?o,s?s,s?F,s?o !}",
- "id", &id,
- "event", &event,
- "depends", &dependsArrayJ,
- "unit", &unit,
- "frequency", &frequency,
- "getSignalsArgs", &filterJ);
- if(err)
+ if(eventJ)
{
- AFB_ERROR("Problem to unpack JSON object eventJ: %s",
- json_object_to_json_string(eventJ));
- return err;
+ err = wrap_json_unpack(eventJ, "{ss,s?s,s?o,s?s,s?F,s?o !}",
+ "id", &id,
+ "event", &event,
+ "depends", &dependsArrayJ,
+ "unit", &unit,
+ "frequency", &frequency,
+ "getSignalsArgs", &filterJ);
+ if(err)
+ {
+ AFB_ERROR("Problem to unpack JSON object eventJ: %s",
+ json_object_to_json_string(eventJ));
+ return err;
+ }
+
+ if(frequency > 0 && !filterJ)
+ {wrap_json_pack(&subscribeFilterJ, "{sf}", "frequency", frequency);}
+ else
+ {subscribeFilterJ = filterJ;}
+
+ std::string eventStr = std::string(event);
+ std::string lowEvent = eventStr.substr(eventStr.find("/")+1);
+ err = wrap_json_pack(&subscribeArgsJ, "{ss, so*}",
+ "event", lowEvent.c_str(),
+ "filter", subscribeFilterJ);
+ if(err)
+ {
+ AFB_ERROR("Error building subscription query object");
+ return err;
+ }
+
+ json_object_array_add(pluginCtx->subscriptionBatch, subscribeArgsJ);
}
-
- if(frequency > 0 && !filterJ)
- {wrap_json_pack(&subscribeFilterJ, "{sf}", "frequency", frequency);}
else
- {subscribeFilterJ = filterJ;}
-
- std::string eventStr = std::string(event);
- std::string lowEvent = eventStr.substr(eventStr.find("/")+1);
- err = wrap_json_pack(&subscribeArgsJ, "{ss, so*}",
- "event", lowEvent.c_str(),
- "filter", subscribeFilterJ);
- if(err)
- {
- AFB_ERROR("Error building subscription query object");
- return err;
- }
- AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(subscribeArgsJ, JSON_C_TO_STRING_PRETTY));
- err = afb_service_call_sync("low-can", "subscribe", subscribeArgsJ, &responseJ);
- if(err)
{
- AFB_ERROR("Subscribe to 'low-can/%s' %s", lowEvent.c_str(), json_object_to_json_string(responseJ));
- return err;
+ AFB_DEBUG("Calling subscribe with %s", json_object_to_json_string_ext(pluginCtx->subscriptionBatch, JSON_C_TO_STRING_PRETTY));
+ err = afb_service_call_sync("low-can", "subscribe", pluginCtx->subscriptionBatch, &responseJ);
+ if(err)
+ {AFB_ERROR("Subscribe to '%s' responseJ:%s", json_object_to_json_string_ext(pluginCtx->subscriptionBatch, JSON_C_TO_STRING_PRETTY), json_object_to_json_string(responseJ));}
}
return err;
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index 6c991f0..d777515 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -91,6 +91,7 @@ int SourceAPI::makeSubscription()
else
{sig.second = true;}
}
+ err += ActionExecOne(getSignals_, nullptr);
}
return err;