From 7f9e33046ee9b069f29ffceffae56ff1edf007b0 Mon Sep 17 00:00:00 2001 From: hongll Date: Thu, 24 Jul 2025 17:57:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E9=80=80=E5=87=BA=E9=87=8D=E5=90=AF=E5=90=8E=EF=BC=8C=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E8=8E=B7=E5=8F=96=E4=BB=A3=E7=90=86=E6=97=A0?= =?UTF-8?q?=E6=95=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: h60047265 --- samgr_client/source/remote_register_rpc.c | 12 ++++++++--- samgr_endpoint/source/default_client.h | 1 + samgr_endpoint/source/default_client_rpc.c | 23 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/samgr_client/source/remote_register_rpc.c b/samgr_client/source/remote_register_rpc.c index 4eb1462..55f44ff 100644 --- a/samgr_client/source/remote_register_rpc.c +++ b/samgr_client/source/remote_register_rpc.c @@ -79,7 +79,10 @@ IUnknown *SAMGR_FindServiceApi(const char *service, const char *feature) SaName key = {service, feature}; int index = VECTOR_FindByKey(&g_remoteRegister.clients, &key); if (index != INVALID_INDEX) { - return VECTOR_At(&g_remoteRegister.clients, index); + IUnknown *proxy = VECTOR_At(&g_remoteRegister.clients, index); + if (SAMGR_IsProxyValid(proxy)) { + return proxy; + } } IUnknown *proxy = SAMGR_CreateIProxy(service, feature); if (proxy == NULL) { @@ -88,9 +91,12 @@ IUnknown *SAMGR_FindServiceApi(const char *service, const char *feature) MUTEX_Lock(g_remoteRegister.mtx); index = VECTOR_FindByKey(&g_remoteRegister.clients, &key); if (index != INVALID_INDEX) { + IUnknown *oldProxy = VECTOR_Swap(&g_remoteRegister.clients, index, proxy); MUTEX_Unlock(g_remoteRegister.mtx); - proxy->Release(proxy); - return VECTOR_At(&g_remoteRegister.clients, index); + if (oldProxy != NULL) { + oldProxy->Release(oldProxy); + } + return proxy; } VECTOR_Add(&g_remoteRegister.clients, proxy); MUTEX_Unlock(g_remoteRegister.mtx); diff --git a/samgr_endpoint/source/default_client.h b/samgr_endpoint/source/default_client.h index d1cfdb9..25b4066 100644 --- a/samgr_endpoint/source/default_client.h +++ b/samgr_endpoint/source/default_client.h @@ -28,6 +28,7 @@ struct SaName { const char *feature; }; +BOOL SAMGR_IsProxyValid(IUnknown *proxy); IUnknown *SAMGR_CreateIProxy(const char *service, const char *feature); IUnknown *SAMGR_CreateIRemoteProxy(const char *deviceId, const char *service, const char *feature); SaName *SAMGR_GetSAName(const IUnknown *proxy); diff --git a/samgr_endpoint/source/default_client_rpc.c b/samgr_endpoint/source/default_client_rpc.c index 3017c9b..d90324b 100644 --- a/samgr_endpoint/source/default_client_rpc.c +++ b/samgr_endpoint/source/default_client_rpc.c @@ -24,6 +24,29 @@ static SvcIdentity QueryRemoteIdentity(const char *deviceId, const char *service static const IClientEntry DEFAULT_ENTRY = {CLIENT_IPROXY_BEGIN, .Invoke = ProxyInvoke, IPROXY_END}; static MutexId g_mutex = NULL; +BOOL SAMGR_IsProxyValid(IUnknown *proxy) +{ + if (proxy != NULL) { + IDefaultClient *client = GET_OBJECT(proxy, IDefaultClient, entry.iUnknown); + if (client == NULL) { + return false; + } + IClientHeader *header = &client->header; + if (header == NULL) { + return false; + } + if (header->deadId == INVALID_INDEX && + header->target.handle == INVALID_INDEX && + header->target.token == INVALID_INDEX && + header->target.cookie == INVALID_INDEX) { + return false; + } else { + return true; + } + } + return false; +} + IUnknown *SAMGR_CreateIProxy(const char *service, const char *feature) { SvcIdentity identity = QueryIdentity(service, feature); -- Gitee