diff --git a/services/param/watcher/proxy/watcher_manager.cpp b/services/param/watcher/proxy/watcher_manager.cpp index fd5c0e9d82f5860d502a73bd5c5e06a8f5fb0635..9b782d54de709f50f8e469bd4f0d56fdf9faf60f 100644 --- a/services/param/watcher/proxy/watcher_manager.cpp +++ b/services/param/watcher/proxy/watcher_manager.cpp @@ -97,7 +97,7 @@ int32_t WatcherManager::AddWatcher(const std::string &keyPrefix, uint32_t remote SendMessage(group, MSG_ADD_WATCHER); } } - SendLocalChange(keyPrefix, remoteWatcher); + SendLocalChange(keyPrefix, remoteWatcherId); WATCHER_LOGI("Add watcher %s remoteWatcherId: %u groupId %u success", keyPrefix.c_str(), remoteWatcherId, group->GetGroupId()); return 0; @@ -127,9 +127,7 @@ int32_t WatcherManager::RefreshWatcher(const std::string &keyPrefix, uint32_t re WATCHER_LOGV("Refresh watcher %s remoteWatcherId: %u", keyPrefix.c_str(), remoteWatcherId); auto group = GetWatcherGroup(keyPrefix); WATCHER_CHECK(group != nullptr, return 0, "Can not find group %s", keyPrefix.c_str()); - auto remoteWatcher = GetRemoteWatcher(remoteWatcherId); - WATCHER_CHECK(remoteWatcher != nullptr, return 0, "Can not find watcher %s %d", keyPrefix.c_str(), remoteWatcherId); - SendLocalChange(keyPrefix, remoteWatcher); + SendLocalChange(keyPrefix, remoteWatcherId); return 0; } @@ -201,15 +199,16 @@ void WatcherManager::ProcessWatcherMessage(const ParamMessage *msg) } } -void WatcherManager::SendLocalChange(const std::string &keyPrefix, RemoteWatcherPtr &remoteWatcher) +void WatcherManager::SendLocalChange(const std::string &keyPrefix, uint32_t remoteWatcherId) { struct Context { char *buffer; - RemoteWatcherPtr remoteWatcher; + uint32_t remoteWatcherId; std::string keyPrefix; + WatcherManager *watcherManagerPtr; }; std::vector buffer(PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX); - struct Context context = {buffer.data(), remoteWatcher, keyPrefix}; + struct Context context = {buffer.data(), remoteWatcherId, keyPrefix, this}; // walk watcher SystemTraversalParameter("", [](ParamHandle handle, void *cookie) { struct Context *context = (struct Context *)(cookie); @@ -219,7 +218,8 @@ void WatcherManager::SendLocalChange(const std::string &keyPrefix, RemoteWatcher } uint32_t size = PARAM_CONST_VALUE_LEN_MAX; SystemGetParameterValue(handle, context->buffer + PARAM_NAME_LEN_MAX, &size); - context->remoteWatcher->ProcessParameterChange( + auto remoteWatcher = context->watcherManagerPtr->GetRemoteWatcher(context->remoteWatcherId); + remoteWatcher->ProcessParameterChange( context->keyPrefix, context->buffer, context->buffer + PARAM_NAME_LEN_MAX); }, reinterpret_cast(&context)); } diff --git a/services/param/watcher/proxy/watcher_manager.h b/services/param/watcher/proxy/watcher_manager.h index 521893a44471c79e7e1f27698693b7819528137e..2b7d7cb641e430a6e3782f5ceca652d684cc24e7 100644 --- a/services/param/watcher/proxy/watcher_manager.h +++ b/services/param/watcher/proxy/watcher_manager.h @@ -90,7 +90,7 @@ private: void RunLoop(); void StartLoop(); void StopLoop(); - void SendLocalChange(const std::string &keyPrefix, RemoteWatcherPtr &remoteWatcher); + void SendLocalChange(const std::string &keyPrefix, uint32_t remoteWatcherId); int SendMessage(WatcherGroupPtr group, int type); int GetServerFd(bool retry); int GetRemoteWatcherId(uint32_t &remoteWatcherId);