1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_SHARING_SHARING_DOMAIN_RPC_CLIENT_H 17 #define OHOS_SHARING_SHARING_DOMAIN_RPC_CLIENT_H 18 19 #include <cstdint> 20 #include "common/identifier.h" 21 #include "inter_ipc_client_stub.h" 22 #include "inter_ipc_death_recipient.h" 23 #include "inter_ipc_proxy.h" 24 #include "interaction/interprocess/ipc_msg_adapter.h" 25 26 namespace OHOS { 27 namespace Sharing { 28 29 class InterIpcClient final : public IdentifierInfo, 30 public InterIpcDeathListener, 31 public std::enable_shared_from_this<InterIpcClient> { 32 public: 33 explicit InterIpcClient(); 34 ~InterIpcClient() override {}; 35 36 // rpc client 37 int32_t CreateListenerObject(); 38 void OnRemoteDied(std::string key) final; 39 void Initialize(sptr<IInterIpc> standardProxy = nullptr); 40 41 sptr<IInterIpc> GetSharingProxy(); 42 sptr<IInterIpc> GetSubProxy(std::string key, std::string className); 43 std::shared_ptr<InterIpcClient> CreateSubService(std::string key, std::string clientClassName, 44 std::string serverClassName); 45 46 void SetKey(std::string key); 47 std::shared_ptr<IpcMsgAdapter> GetMsgAdapter(); 48 int32_t Send(std::shared_ptr<BaseMsg> msg, std::shared_ptr<BaseMsg> &reply); 49 50 private: 51 void Reset(); 52 53 private: 54 std::string key_; 55 std::mutex mutex_; 56 std::shared_ptr<IpcMsgAdapter> msgAdapter_ = nullptr; 57 58 sptr<IInterIpc> domainProxy_ = nullptr; 59 sptr<InterIpcClientStub> listenerStub_ = nullptr; 60 sptr<InterIpcDeathRecipient> deathRecipient_ = nullptr; 61 }; 62 63 } // namespace Sharing 64 } // namespace OHOS 65 #endif