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 168f8c9567c8fd6ad4ece0a012b2e9f66d7f81f8..bba9cf308a371d88906773151c6935f6b6f13b2b 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 4dddcb45cccfda9318dfef81577d976001eff588..b485b1a4ed374fe57f38d99908f333381de47ec6 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 44195ac6f564c3e635a8d3eab71f0e1d378b353b..d2d477e7bdf4c057ec7b351974bced1a8e878568 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 ce5ded9cffee889bbe6952d028c13171247b3075..0bc55d2215c7608c20b647ace8a03129c7c9806c 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 cc4db5308d5447e97857f4202ac064cb09ac5c17..7647bf1e145098044164ca65be38bbe00e62b764 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 0a8e9304041149f0c8abb62fc799d1abe69b9780..b78a42eac052d09aada5bee6571a08fd74674785 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 748da1c824852c5731e764bbe74e1cdd5d5993a9..1640af93aca28321956cd8b795f3e1861329fd90 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 27d02a0178188bf04e588b58046c12fed4ae9f42..fec06a9eb8dc860d3bb3b49e926dc9f85075c74d 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 93d0f7878bd5190dfcbf4cba21a1cc959369e528..047907d0c33280addbd9350465290926c03df3d0 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 28dbc5a5fdfcb834f934aa586cb783d97ac4d707..8273dc1125fa781085e175146bb53c9a055b39a3 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 a77e3dbbba0891a8f8c06d08d4e21a3c3cb98eaa..fb3de2d94253b676372ac21fd932a916b9ae7236 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 d1b55df74d7923ce86f2fc4f292da7ab7dfd1e2a..1f873c82df6b2f143c5a8c3a84514d277cfea109 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)