1 /*
2  * Copyright (c) 2021-2023 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 SOFTBUS_CLIENT_INFO_MANAGER_H
17 #define SOFTBUS_CLIENT_INFO_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <list>
22 #include <unordered_map>
23 #include "iremote_broker.h"
24 #include "iremote_object.h"
25 #include "iremote_proxy.h"
26 #include "session.h"
27 
28 namespace OHOS {
29 typedef std::pair<int32_t, std::pair<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>> ClientObjPair;
30 class SoftbusClientInfoManager {
31 public:
32     static SoftbusClientInfoManager &GetInstance();
33     int32_t SoftbusAddService(const std::string &pkgName, const sptr<IRemoteObject> &object,
34         const sptr<IRemoteObject::DeathRecipient> &abilityDeath, int32_t pid);
35     int32_t SoftbusRemoveService(const sptr<IRemoteObject> &object, std::string &pkgName, int32_t* pid);
36     int32_t SoftbusAddServiceInner(const std::string &pkgName, ISessionListener *listener, int32_t pid);
37     int32_t SoftbusRemoveServiceInner(const std::string &pkgName);
38     int32_t GetSoftbusInnerObject(const std::string &pkgName, ISessionListener *listener);
39     sptr<IRemoteObject> GetSoftbusClientProxy(const std::string &pkgName);
40     sptr<IRemoteObject> GetSoftbusClientProxy(const std::string &pkgName, int32_t pid);
41     void GetSoftbusClientProxyMap(std::multimap<std::string, sptr<IRemoteObject>> &softbusClientMap);
42     bool SoftbusClientIsExist(const std::string &pkgName, int32_t pid);
43 
44 private:
45     ~SoftbusClientInfoManager() = default;
46     SoftbusClientInfoManager() = default;
47     std::recursive_mutex clientObjectMapLock_;
48     std::unordered_multimap<std::string, ClientObjPair> clientObjectMap_;
49     std::map<std::string, ISessionListener> innerObjectMap_;
50     DISALLOW_COPY_AND_MOVE(SoftbusClientInfoManager);
51 };
52 } // namespace OHOS
53 #endif