• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_H
17 #define OHOS_SHARING_DOMAIN_RPC_CLIENT_H
18 
19 #include <cstdint>
20 #include "domain_def.h"
21 #include "domain_rpc_death_recipient.h"
22 #include "common/identifier.h"
23 #include "domain_rpc_service_stub.h"
24 #include "domain_rpc_service_proxy.h"
25 
26 namespace OHOS {
27 namespace Sharing {
28 
29 class DomainRpcClient final : public IDomainPeer,
30                               public IdentifierInfo,
31                               public DomainRpcDeathListener,
32                               public IDomainStubListener,
33                               public std::enable_shared_from_this<DomainRpcClient> {
34 public:
35     explicit DomainRpcClient();
~DomainRpcClient()36     ~DomainRpcClient() override {};
37 
38     //rpc client
39     void Initialize();
40     void OnRemoteDied(std::string deviceId) final;
41     void OnDomainRequest(std::shared_ptr<BaseDomainMsg> msg) final;
42     int32_t CreateListenerObject();
43 
44     void SetDomainProxy(sptr<IDomainRpcService> peerProxy);
45     sptr<IDomainRpcService> GetSubProxy(int32_t type = 0);
46     sptr<IDomainRpcService> GetDomainProxy(std::string deviceId);
47 
48     //peer client
49     void SetPeerListener(std::weak_ptr<IDomainPeerListener> listener) final;
50     int32_t SendDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> BaseMsg) final;
51 
52 private:
53     void Reset();
54 
55 private:
56     std::mutex mutex_;
57     sptr<IDomainRpcService> domainProxy_ = nullptr;
58     sptr<DomainRpcServiceStub> listenerStub_ = nullptr;
59     sptr<DomainRpcDeathRecipient> deathRecipient_ = nullptr;
60 };
61 
62 } // namespace Sharing
63 } // namespace OHOS
64 #endif
65