• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_ADVERTISE_MANAGER_H
17 #define OHOS_ADVERTISE_MANAGER_H
18 
19 #include "dm_timer.h"
20 #include "softbus_listener.h"
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 class AdvertiseManager : public std::enable_shared_from_this<AdvertiseManager> {
25 public:
26     AdvertiseManager(std::shared_ptr<SoftbusListener> softbusListener);
27     ~AdvertiseManager();
28 
29     int32_t StartAdvertising(const std::string &pkgName, const std::map<std::string, std::string> &advertiseParam);
30     int32_t StopAdvertising(const std::string &pkgName, int32_t publishId);
31     void ClearPulishIdCache(const std::string &pkgName);
32 
33 private:
34     void HandleAutoStopAdvertise(const std::string &timerName, const std::string &pkgName, int32_t publishId);
35     void ConfigAdvParam(const std::map<std::string, std::string> &advertiseParam, DmPublishInfo *dmPubInfo,
36                         const std::string &pkgName);
37     int32_t GenInnerPublishId(const std::string &pkgName, int32_t publishId);
38     int32_t GetAndRemoveInnerPublishId(const std::string &pkgName, int32_t publishId);
39 
40 private:
41     std::shared_ptr<DmTimer> timer_;
42     std::shared_ptr<SoftbusListener> softbusListener_;
43 
44     std::mutex pubMapLock_;
45     // Caller publishId to inner publishId. The key is the caller pkgName, the value is
46     // a list of externals publishId to inner publishId.
47     std::map<std::string, std::map<int32_t, int32_t>> pkgName2PubIdMap_;
48     std::set<int32_t> publishIdSet_;
49 };
50 } // namespace DistributedHardware
51 } // namespace OHOS
52 #endif // OHOS_ADVERTISE_MANAGER_H
53