1 /*
2  * Copyright (c) 2022-2024 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_DM_IPC_SERVER_LISTENER_MGR_H
17 #define OHOS_DM_IPC_SERVER_LISTENER_MGR_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 
24 #include "ipc_skeleton.h"
25 #include "dm_single_instance.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 typedef struct CommonSvcId {
30     uint32_t handle;
31     uint32_t token;
32     uint32_t cookie;
33     uint32_t cbId;
34 } CommonSvcId;
35 
36 class IpcServerListenermgr {
37     DM_DECLARE_SINGLE_INSTANCE(IpcServerListenermgr);
38 
39 public:
40     /**
41      * @tc.name: IpcServerListener::RegisterListener
42      * @tc.desc: Register Listener of the Ipc Server Listener
43      * @tc.type: FUNC
44      */
45     int32_t RegisterListener(std::string &pkgName, const CommonSvcId *svcId);
46 
47     /**
48      * @tc.name: IpcServerListener::GetListenerByPkgName
49      * @tc.desc: Get Listener By package Name of the Ipc Server Listener
50      * @tc.type: FUNC
51      */
52     int32_t GetListenerByPkgName(std::string &pkgName, CommonSvcId *svcId);
53 
54     /**
55      * @tc.name: IpcServerListener::UnregisterListener
56      * @tc.desc: Unregister Listener of the Ipc Server Listener
57      * @tc.type: FUNC
58      */
59     int32_t UnregisterListener(std::string &pkgName);
60 
61     /**
62      * @tc.name: IpcServerListener::GetAllListeners
63      * @tc.desc: Get All Listeners of the Ipc Server Listener
64      * @tc.type: FUNC
65      */
66     const std::map<std::string, CommonSvcId> &GetAllListeners();
67 
68 private:
69     std::map<std::string, CommonSvcId> dmListenerMap_;
70     std::mutex lock_;
71 };
72 } // namespace DistributedHardware
73 } // namespace OHOS
74 #endif // OHOS_DM_IPC_SERVER_LISTENER_MGR_H
75