Browse Source

let's try saving things here

Grant Limberg 3 weeks ago
parent
commit
7662ffb64a
2 changed files with 60 additions and 8 deletions
  1. 58 0
      controller/CV2.cpp
  2. 2 8
      controller/CV2.hpp

+ 58 - 0
controller/CV2.cpp

@@ -110,6 +110,64 @@ bool CV2::isReady()
 	return (_ready == 2) && _connected;
 }
 
+void CV2::_memberChanged(nlohmann::json& old, nlohmann::json& memberConfig, bool notifyListeners)
+{
+	auto provider = opentelemetry::trace::Provider::GetTracerProvider();
+	auto tracer = provider->GetTracer("cv2");
+	auto span = tracer->StartSpan("cv2::_memberChanged");
+	auto scope = tracer->WithActiveSpan(span);
+
+	if (memberConfig.is_object()) {
+		// member config change
+		const std::string ids = memberConfig["id"];
+		const uint64_t networkId = OSUtils::jsonIntHex(memberConfig["nwid"], 0ULL);
+		const uint64_t memberId = Utils::hexStrToU64(ids.c_str());
+		if ((networkId) && (memberId)) {
+			save(memberConfig, notifyListeners);
+		}
+	}
+	else if (old.is_object()) {
+		// member delete
+		const std::string ids = old["id"];
+		const uint64_t networkId = OSUtils::jsonIntHex(old["nwid"], 0ULL);
+		const uint64_t memberId = Utils::hexStrToU64(ids.c_str());
+		if ((networkId) && (memberId)) {
+			eraseMember(networkId, memberId);
+		}
+	}
+
+	// fprintf(stderr, "CV2::_memberChanged\n");
+	DB::_memberChanged(old, memberConfig, notifyListeners);
+}
+
+void CV2::_networkChanged(nlohmann::json& old, nlohmann::json& networkConfig, bool notifyListeners)
+{
+	auto provider = opentelemetry::trace::Provider::GetTracerProvider();
+	auto tracer = provider->GetTracer("cv2");
+	auto span = tracer->StartSpan("cv2::_networkChanged");
+	auto scope = tracer->WithActiveSpan(span);
+
+	if (networkConfig.is_object()) {
+		// network config change
+		const std::string ids = networkConfig["id"];
+		const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
+		if (networkId) {
+			save(networkConfig, notifyListeners);
+		}
+	}
+	else if (old.is_object()) {
+		// network delete
+		const std::string ids = networkConfig["id"];
+		const uint64_t networkId = Utils::hexStrToU64(ids.c_str());
+		if (networkId) {
+			eraseNetwork(networkId);
+		}
+	}
+
+	// fprintf(stderr, "CV2::_networkChanged\n");
+	DB::_networkChanged(old, networkConfig, false);
+}
+
 bool CV2::save(nlohmann::json& record, bool notifyListeners)
 {
 	auto provider = opentelemetry::trace::Provider::GetTracerProvider();

+ 2 - 8
controller/CV2.hpp

@@ -59,15 +59,9 @@ class CV2 : public DB {
 			return (std::size_t)(p.first ^ p.second);
 		}
 	};
-	virtual void _memberChanged(nlohmann::json& old, nlohmann::json& memberConfig, bool notifyListeners)
-	{
-		DB::_memberChanged(old, memberConfig, notifyListeners);
-	}
+	virtual void _memberChanged(nlohmann::json& old, nlohmann::json& memberConfig, bool notifyListeners);
 
-	virtual void _networkChanged(nlohmann::json& old, nlohmann::json& networkConfig, bool notifyListeners)
-	{
-		DB::_networkChanged(old, networkConfig, notifyListeners);
-	}
+	virtual void _networkChanged(nlohmann::json& old, nlohmann::json& networkConfig, bool notifyListeners);
 
   private:
 	void initializeNetworks();