let's try saving things here

This commit is contained in:
Grant Limberg 2025-07-16 11:55:12 -07:00
parent 9375c48e33
commit 7662ffb64a
2 changed files with 60 additions and 8 deletions

View file

@ -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();

View file

@ -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();