summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-11 13:36:17 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:49 +0100
commit1b4bbe3b4f048754fe90e93546126f1d161d8037 (patch)
tree539e372998e876e7f90fd9ef4ee0e3ff81189112 /signal-composer-binding
parent9a4ba373acf7b7feac6d980506bcdad20b96bdb6 (diff)
Avoid create duplicate source entries.
Change-Id: If50a439634382fa6d1c856b5c3fb29db4eb93a31 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer.cpp12
-rw-r--r--signal-composer-binding/source.cpp22
-rw-r--r--signal-composer-binding/source.hpp6
3 files changed, 34 insertions, 6 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 4a0346c..0fb3f3d 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -300,6 +300,16 @@ int Composer::loadOneSourceAPI(json_object* sourceJ)
return err;
}
+ // Checking duplicate entry and ignore if so
+ for(auto& src: sourcesListV_)
+ {
+ if(*src == uid)
+ {
+ json_object_put(sourceJ);
+ return 0;
+ }
+ }
+
if(ctlConfig_ && ctlConfig_->requireJ)
{
const char* requireS = json_object_to_json_string(ctlConfig_->requireJ);
@@ -322,7 +332,7 @@ int Composer::loadOneSourceAPI(json_object* sourceJ)
onReceivedCtl = onReceivedJ ? convert2Action("onReceived", onReceivedJ) : nullptr;
- sourcesListV_.push_back(std::make_shared<SourceAPI>(api, info, initCtl, getSignalsCtl, onReceivedCtl, retention));
+ sourcesListV_.push_back(std::make_shared<SourceAPI>(uid, api, info, initCtl, getSignalsCtl, onReceivedCtl, retention));
return err;
}
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index f616e51..f34b88f 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -21,13 +21,27 @@
SourceAPI::SourceAPI()
{}
-SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignals, CtlActionT* onReceived, int retention):api_(api),
- info_(info),
- init_(init),
- getSignals_(getSignals),
+SourceAPI::SourceAPI(const std::string& uid, const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignals, CtlActionT* onReceived, int retention):
+ uid_{uid},
+ api_{api},
+ info_{info},
+ init_{init},
+ getSignals_{getSignals},
signalsDefault_({onReceived, retention})
{}
+bool SourceAPI::operator ==(const SourceAPI& other) const
+{
+ if(uid_ == other.uid_) {return true;}
+ return false;
+}
+
+bool SourceAPI::operator ==(const std::string& other) const
+{
+ if(uid_ == other) {return true;}
+ return false;
+}
+
void SourceAPI::init()
{
if(init_)
diff --git a/signal-composer-binding/source.hpp b/signal-composer-binding/source.hpp
index 3d44922..8dd18e5 100644
--- a/signal-composer-binding/source.hpp
+++ b/signal-composer-binding/source.hpp
@@ -26,6 +26,7 @@ struct signalsDefault {
class SourceAPI {
private:
+ std::string uid_;
std::string api_;
std::string info_;
CtlActionT* init_;
@@ -38,7 +39,10 @@ private:
public:
SourceAPI();
- SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignal, CtlActionT* onReceived, int retention);
+ SourceAPI(const std::string& uid_, const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignal, CtlActionT* onReceived, int retention);
+
+ bool operator==(const SourceAPI& other) const;
+ bool operator==(const std::string& aName) const;
void init();
std::string api() const;