• 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_SERVICE_H
17 #define OHOS_SHARING_DOMAIN_RPC_SERVICE_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 #include "domain_def.h"
22 #include "domain_rpc_service_stub.h"
23 #include "system_ability.h"
24 #include "system_ability_definition.h"
25 
26 namespace OHOS {
27 namespace Sharing {
28 
29 class DomainRpcService final : public SystemAbility,
30                                public DomainRpcServiceStub,
31                                public IDomainPeer,
32                                public std::enable_shared_from_this<DomainRpcService> {
33     DECLARE_SYSTEM_ABILITY(DomainRpcService);
34 
35 public:
36     using Ptr = std::shared_ptr<DomainRpcService>;
37     explicit DomainRpcService(int32_t systemAbilityId, bool runOnCreate = true);
38     ~DomainRpcService() override;
39 
40     void DelPeerProxy(std::string remoteId);
41     void CreateDeathListener(std::string deviceId) final;
42     void SetPeerListener(std::weak_ptr<IDomainPeerListener> listener) final;
43 
44     int32_t SendDomainRequest(std::string remoteId, std::shared_ptr<BaseDomainMsg> msg) final;
45     int32_t DoRpcCommand(std::shared_ptr<BaseDomainMsg> msg, std::shared_ptr<BaseDomainMsg> replyMsg) final;
46 
47     sptr<IRemoteObject> GetSubSystemAbility(int32_t subtype) final;
48 
49 protected:
50     void OnDump() final;
51     void OnStop() final;
52     void OnStart() final;
53 
54 private:
55     std::mutex mutex_;
56     Ptr shared_from_this_ = nullptr;
57     std::unordered_map<std::string, sptr<IRemoteObject>> DomainRpcStubs_;
58 };
59 
60 } // namespace Sharing
61 } // namespace OHOS
62 #endif
63