From b4b317a9dfcfa790f3caa28042ba028f92c8bd16 Mon Sep 17 00:00:00 2001 From: wanghang Date: Mon, 14 Feb 2022 06:20:48 +0000 Subject: [PATCH] =?UTF-8?q?DM=E5=90=8C=E8=BF=9B=E7=A8=8B=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanghang Change-Id: I678d90ec6cab6b2d00a3fc628d3c1d7ddfc07cdf --- .../include/ipc/standard/ipc_client_manager.h | 3 +- .../ipc/standard/ipc_client_server_proxy.h | 3 +- .../include/ipc/standard/ipc_client_stub.h | 1 - .../include/ipc/standard/ipc_remote_broker.h | 2 -- .../src/ipc/standard/ipc_client_manager.cpp | 3 +- .../ipc/standard/ipc_client_server_proxy.cpp | 2 ++ .../src/ipc/standard/ipc_client_stub.cpp | 6 ---- .../ipc/standard/ipc_server_client_proxy.h | 2 +- .../include/ipc/standard/ipc_server_stub.h | 9 ++++-- .../ipc/standard/ipc_server_client_proxy.cpp | 2 ++ .../src/ipc/standard/ipc_server_listener.cpp | 10 +++--- .../src/ipc/standard/ipc_server_stub.cpp | 32 ++++++++++++------- 12 files changed, 43 insertions(+), 32 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h index 168f8c956..bba9cf308 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h @@ -26,6 +26,7 @@ #include "ipc_def.h" #include "ipc_remote_broker.h" #include "iremote_object.h" +#include "ipc_client_server_proxy.h" namespace OHOS { namespace DistributedHardware { @@ -52,7 +53,7 @@ private: private: std::mutex lock_; std::map> dmListener_; - sptr dmInterface_ { nullptr }; + sptr dmInterface_ { nullptr }; sptr dmRecipient_ { nullptr }; }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h index 4dddcb45c..b485b1a4e 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_server_proxy.h @@ -30,8 +30,7 @@ class IpcClientServerProxy : public IRemoteProxy { public: explicit IpcClientServerProxy(const sptr &impl) : IRemoteProxy(impl) {}; ~IpcClientServerProxy() {}; - int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; - + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); private: static inline BrokerDelegator delegator_; }; diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h index 44195ac6f..d2d477e7b 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_stub.h @@ -32,7 +32,6 @@ public: IpcClientStub() {}; ~IpcClientStub() {}; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h index ce5ded9cf..0bc55d221 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_remote_broker.h @@ -30,8 +30,6 @@ public: virtual ~IpcRemoteBroker() { } - virtual int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) = 0; - public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager"); }; diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index cc4db5308..7647bf1e1 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -25,6 +25,7 @@ #include "iservice_registry.h" #include "system_ability_definition.h" + namespace OHOS { namespace DistributedHardware { void DmDeathRecipient::OnRemoteDied(const wptr &remote) @@ -60,7 +61,7 @@ int32_t IpcClientManager::ClientInit() if (!object->AddDeathRecipient(dmRecipient_)) { LOGE("InitDeviceManagerService: AddDeathRecipient Failed"); } - dmInterface_ = iface_cast(object); + dmInterface_ = iface_cast(object); LOGI("DeviceManager::InitDeviceManagerService completed"); return DM_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp index 0a8e93040..b78a42eac 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp @@ -24,6 +24,7 @@ namespace OHOS { namespace DistributedHardware { int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { + LOGI("ipc client server proxy send cmd"); sptr remote = Remote(); if (remote == nullptr) { LOGE("remote service null"); @@ -34,6 +35,7 @@ int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr r MessageParcel reply; MessageOption option; if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) { + LOGE("Set Request fialed"); return DM_IPC_SEND_REQUEST_FAILED; } if (remote->SendRequest(cmdCode, data, reply, option) != DM_OK) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp index 748da1c82..1640af93a 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp @@ -32,11 +32,5 @@ int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa LOGW("unsupport code: %d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - -int32_t IpcClientStub::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - LOGE("error"); - return DM_OK; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h index 27d02a017..fec06a9eb 100644 --- a/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_client_proxy.h @@ -25,7 +25,7 @@ class IpcServerClientProxy : public IRemoteProxy { public: explicit IpcServerClientProxy(const sptr &impl) : IRemoteProxy(impl) {}; ~IpcServerClientProxy() {}; - int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; + int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); private: static inline BrokerDelegator delegator_; diff --git a/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h index 93d0f7878..047907d0c 100644 --- a/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h +++ b/services/devicemanagerservice/include/ipc/standard/ipc_server_stub.h @@ -24,6 +24,7 @@ #include "hichain_connector.h" #include "ipc_remote_broker.h" +#include "ipc_server_client_proxy.h" #include "iremote_stub.h" #include "nlohmann/json.hpp" #include "single_instance.h" @@ -49,12 +50,13 @@ public: void OnStart() override; void OnStop() override; int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) override; int32_t RegisterDeviceManagerListener(std::string &pkgName, sptr listener); int32_t UnRegisterDeviceManagerListener(std::string &pkgName); ServiceRunningState QueryServiceState() const; - const std::map> &GetDmListener(); - const sptr GetDmListener(std::string pkgName) const; + std::map> &GetDmListener(); + sptr GetDmListener(std::string pkgName); + std::map> &GetDmListenerProxy(); + sptr GetDmListenerProxy(std::string pkgName); private: IpcServerStub(); @@ -67,6 +69,7 @@ private: std::mutex listenerLock_; std::map> appRecipient_; std::map> dmListener_; + std::map> dmListenerProxy_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp index 28dbc5a5f..8273dc112 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp @@ -25,6 +25,7 @@ namespace OHOS { namespace DistributedHardware { int32_t IpcServerClientProxy::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { + LOGI("ipc server client proxy send"); sptr remote = Remote(); if (remote == nullptr) { LOGE("remote service null"); @@ -34,6 +35,7 @@ int32_t IpcServerClientProxy::SendCmd(int32_t cmdCode, std::shared_ptr r MessageParcel reply; MessageOption option; if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) { + LOGE("Set Request fialed"); return DM_IPC_FAILED; } if (remote->SendRequest(cmdCode, data, reply, option) != DM_OK) { diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp index a77e3dbbb..fb3de2d94 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_listener.cpp @@ -18,13 +18,15 @@ #include "dm_constants.h" #include "dm_log.h" #include "ipc_server_stub.h" +#include "ipc_server_client_proxy.h" namespace OHOS { namespace DistributedHardware { int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { + LOGI("Ipc Server Listener SendRequest"); std::string pkgName = req->GetPkgName(); - sptr listener = IpcServerStub::GetInstance().GetDmListener(pkgName); + sptr listener = IpcServerStub::GetInstance().GetDmListenerProxy(pkgName); if (listener == nullptr) { LOGI("cannot get listener for package:%s.", pkgName.c_str()); return DM_POINT_NULL; @@ -34,13 +36,13 @@ int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr int32_t IpcServerListener::SendAll(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) { - std::map> listeners = IpcServerStub::GetInstance().GetDmListener(); + LOGI("Ipc Server Listener SendAll"); + std::map> listeners = IpcServerStub::GetInstance().GetDmListenerProxy(); for (auto iter : listeners) { auto pkgName = iter.first; auto remote = iter.second; req->SetPkgName(pkgName); - sptr listener = iface_cast(remote); - listener->SendCmd(cmdCode, req, rsp); + remote->SendCmd(cmdCode, req, rsp); } return DM_OK; } diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index d1b55df74..1f873c82d 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -90,12 +90,6 @@ int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa return ret; } -int32_t IpcServerStub::SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - LOGI("SendCmd cmdCode: %d", cmdCode); - return DM_OK; -} - ServiceRunningState IpcServerStub::QueryServiceState() const { return state_; @@ -118,7 +112,9 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(std::string &pkgName, sptr< if (!listener->AddDeathRecipient(appRecipient)) { LOGE("RegisterDeviceManagerListener: AddDeathRecipient Failed"); } + dmListener_[pkgName] = listener; + dmListenerProxy_[pkgName] = iface_cast(listener); appRecipient_[pkgName] = appRecipient; return DM_OK; } @@ -140,6 +136,7 @@ int32_t IpcServerStub::UnRegisterDeviceManagerListener(std::string &pkgName) if (recipientIter == appRecipient_.end()) { LOGI("UnRegisterDeviceManagerListener: appRecipient not exists"); dmListener_.erase(pkgName); + dmListenerProxy_.erase(pkgName); return DM_OK; } auto listener = listenerIter->second; @@ -147,23 +144,36 @@ int32_t IpcServerStub::UnRegisterDeviceManagerListener(std::string &pkgName) listener->RemoveDeathRecipient(appRecipient); appRecipient_.erase(pkgName); dmListener_.erase(pkgName); + dmListenerProxy_.erase(pkgName); return DM_OK; } -const std::map> &IpcServerStub::GetDmListener() +std::map> &IpcServerStub::GetDmListener() { return dmListener_; } -const sptr IpcServerStub::GetDmListener(std::string pkgName) const +sptr IpcServerStub::GetDmListener(std::string pkgName) { auto iter = dmListener_.find(pkgName); if (iter == dmListener_.end()) { return nullptr; } - auto remote = iter->second; - sptr dmListener = iface_cast(remote); - return dmListener; + return dmListener_[pkgName]; +} + +std::map> &IpcServerStub::GetDmListenerProxy() +{ + return dmListenerProxy_; +} + +sptr IpcServerStub::GetDmListenerProxy(std::string pkgName) +{ + auto iter = dmListenerProxy_.find(pkgName); + if (iter == dmListenerProxy_.end()) { + return nullptr; + } + return dmListenerProxy_[pkgName]; } void AppDeathRecipient::OnRemoteDied(const wptr &remote) -- Gitee