• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device 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_MINI_DM_IPC_CLIENT_MANAGER_H
17 #define OHOS_MINI_DM_IPC_CLIENT_MANAGER_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 
24 #include "ipc_client.h"
25 #include "ipc_def.h"
26 #include "ipc_remote_broker.h"
27 #include "iremote_object.h"
28 #include "system_ability_status_change_stub.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DmDeathRecipient : public IRemoteObject::DeathRecipient {
33 public:
34     /**
35      * @tc.name: DmDeathRecipient::OnRemoteDied
36      * @tc.desc: ipc client initialization
37      * @tc.type: FUNC
38      */
39     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
40     DmDeathRecipient() = default;
41     ~DmDeathRecipient() override = default;
42 };
43 
44 class IpcClientManagerMini : public IpcClient {
45     friend class DmDeathRecipient;
46     DECLARE_IPC_INTERFACE(IpcClientManagerMini);
47 public:
48     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
49     public:
50         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
51         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
InitPkgName(const std::string & pkgName)52         void InitPkgName(const std::string &pkgName)
53         {
54             pkgName_ = pkgName;
55         }
56     private:
57         std::string pkgName_ = "";
58     };
59 
60 public:
61     /**
62      * @tc.name: IpcClientManager::Init
63      * @tc.desc: ipc client Manager initialization
64      * @tc.type: FUNC
65      */
66     virtual int32_t Init(const std::string &pkgName) override;
67     /**
68      * @tc.name: IpcClientManager::UnInit
69      * @tc.desc: ipc client Manager Uninitialization
70      * @tc.type: FUNC
71      */
72     virtual int32_t UnInit(const std::string &pkgName) override;
73     /**
74      * @tc.name: IpcClientManager::SendRequest
75      * @tc.desc: ipc client Manager Send Request
76      * @tc.type: FUNC
77      */
78     virtual int32_t SendRequest(int32_t cmdCode, std::shared_ptr<IpcReq> req, std::shared_ptr<IpcRsp> rsp) override;
79 
80     virtual int32_t OnDmServiceDied() override;
81 private:
82     int32_t ClientInit();
83     void SubscribeDMSAChangeListener(const std::string &pkgName);
84 private:
85     std::mutex lock_;
86     sptr<IpcRemoteBroker> dmInterface_ { nullptr };
87     sptr<DmDeathRecipient> dmRecipient_ { nullptr };
88     std::atomic<bool> isSubscribeDMSAChangeListener = false;
89     sptr<SystemAbilityListener> saListenerCallback = nullptr;
90 };
91 } // namespace DistributedHardware
92 } // namespace OHOS
93 #endif // OHOS_MINI_DM_IPC_CLIENT_MANAGER_H
94