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_DOMAIN_RPC_SERVICE_STUB_H 17 #define OHOS_SHARING_DOMAIN_RPC_SERVICE_STUB_H 18 19 #include <unordered_map> 20 #include <vector> 21 #include "domain_rpc_death_recipient.h" 22 #include "i_domain_rpc_service.h" 23 24 namespace OHOS { 25 namespace Sharing { 26 27 class IDomainStubListener { 28 public: 29 virtual ~IDomainStubListener() = default; 30 virtual void OnDomainRequest(std::shared_ptr<BaseDomainMsg> msg) = 0; 31 }; 32 33 class DomainRpcServiceStub : public IRemoteStub<IDomainRpcService>, 34 public NoCopyable { 35 public: 36 virtual ~DomainRpcServiceStub(); 37 38 sptr<IRemoteObject> GetSubSystemAbility(int32_t type) override; 39 void SetStubListener(std::weak_ptr<IDomainStubListener> listener); 40 int32_t SetListenerObject(const sptr<IRemoteObject> &object) override; 41 int32_t DoRpcCommand(std::shared_ptr<BaseDomainMsg> msg, std::shared_ptr<BaseDomainMsg> replyMsg) override; 42 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 43 44 protected: 45 virtual void CreateDeathListener(std::string deviceId); 46 int32_t DoRpcCommand(MessageParcel &data, MessageParcel &reply); 47 int32_t GetSystemAbility(MessageParcel &data, MessageParcel &reply); 48 int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply); 49 50 protected: 51 std::mutex mutex_; 52 std::weak_ptr<IDomainStubListener> stubListener_; 53 std::unordered_map<std::string, sptr<IDomainRpcService>> peerProxys_; 54 std::unordered_map<std::string, sptr<DomainRpcDeathRecipient>> deathRecipients_; 55 }; 56 57 } // namespace Sharing 58 } // namespace OHOS 59 #endif 60