summaryrefslogtreecommitdiff
path: root/controller/DB.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'controller/DB.cpp')
-rw-r--r--controller/DB.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/controller/DB.cpp b/controller/DB.cpp
index bdd37c3b..bb734dc8 100644
--- a/controller/DB.cpp
+++ b/controller/DB.cpp
@@ -104,8 +104,7 @@ void DB::cleanMember(nlohmann::json &member)
member.erase("lastRequestMetaData");
}
-DB::DB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path) :
- _controller(nc),
+DB::DB(const Identity &myId,const char *path) :
_myId(myId),
_myAddress(myId.address()),
_path((path) ? path : "")
@@ -115,9 +114,7 @@ DB::DB(EmbeddedNetworkController *const nc,const Identity &myId,const char *path
_myAddressStr = tmp;
}
-DB::~DB()
-{
-}
+DB::~DB() {}
bool DB::get(const uint64_t networkId,nlohmann::json &network)
{
@@ -229,7 +226,7 @@ void DB::networks(std::vector<uint64_t> &networks)
networks.push_back(n->first);
}
-void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool push)
+void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool initialized)
{
uint64_t memberId = 0;
uint64_t networkId = 0;
@@ -313,8 +310,12 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool pu
}
}
- if (push)
- _controller->onNetworkMemberUpdate(networkId,memberId);
+ if (initialized) {
+ std::lock_guard<std::mutex> ll(_changeListeners_l);
+ for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
+ (*i)->onNetworkMemberUpdate(networkId,memberId,memberConfig);
+ }
+ }
} else if (memberId) {
if (nw) {
std::lock_guard<std::mutex> l(nw->lock);
@@ -332,20 +333,24 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool pu
}
}
- if ((push)&&((wasAuth)&&(!isAuth)&&(networkId)&&(memberId)))
- _controller->onNetworkMemberDeauthorize(networkId,memberId);
+ if ((initialized)&&((wasAuth)&&(!isAuth)&&(networkId)&&(memberId))) {
+ std::lock_guard<std::mutex> ll(_changeListeners_l);
+ for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
+ (*i)->onNetworkMemberDeauthorize(networkId,memberId);
+ }
+ }
}
-void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool push)
+void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool initialized)
{
if (networkConfig.is_object()) {
const std::string ids = networkConfig["id"];
- const uint64_t id = Utils::hexStrToU64(ids.c_str());
- if (id) {
+ const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
+ if (networkId) {
std::shared_ptr<_Network> nw;
{
std::lock_guard<std::mutex> l(_networks_l);
- std::shared_ptr<_Network> &nw2 = _networks[id];
+ std::shared_ptr<_Network> &nw2 = _networks[networkId];
if (!nw2)
nw2.reset(new _Network);
nw = nw2;
@@ -354,15 +359,19 @@ void DB::_networkChanged(nlohmann::json &old,nlohmann::json &networkConfig,bool
std::lock_guard<std::mutex> l2(nw->lock);
nw->config = networkConfig;
}
- if (push)
- _controller->onNetworkUpdate(id);
+ if (initialized) {
+ std::lock_guard<std::mutex> ll(_changeListeners_l);
+ for(auto i=_changeListeners.begin();i!=_changeListeners.end();++i) {
+ (*i)->onNetworkUpdate(networkId,networkConfig);
+ }
+ }
}
} else if (old.is_object()) {
const std::string ids = old["id"];
- const uint64_t id = Utils::hexStrToU64(ids.c_str());
- if (id) {
+ const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
+ if (networkId) {
std::lock_guard<std::mutex> l(_networks_l);
- _networks.erase(id);
+ _networks.erase(networkId);
}
}
}