From 872cda7e94e4d07caab3883ec8915019f2bdf711 Mon Sep 17 00:00:00 2001 From: chengjinsong2 Date: Tue, 9 May 2023 17:58:39 +0800 Subject: [PATCH] =?UTF-8?q?fixed=209409da4=20from=20https://gitee.com/chne?= =?UTF-8?q?g-jinsong/startup=5Finit=5Flite/pulls/1940=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?param=5Fwatcher=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chengjinsong2 --- services/param/watcher/proxy/watcher_manager.cpp | 16 ++++++++-------- services/param/watcher/proxy/watcher_manager.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/param/watcher/proxy/watcher_manager.cpp b/services/param/watcher/proxy/watcher_manager.cpp index fd5c0e9d8..9b782d54d 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 521893a44..2b7d7cb64 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); -- Gitee