• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_DISCOVERY_MANAGER_H
17 #define OHOS_DM_DISCOVERY_MANAGER_H
18 
19 #include <queue>
20 
21 #include "dm_discovery_filter.h"
22 #include "idevice_manager_service_listener.h"
23 #include "dm_timer.h"
24 #include "softbus_connector.h"
25 namespace OHOS {
26 namespace DistributedHardware {
27 typedef struct DmDiscoveryContext {
28     std::string pkgName;
29     std::string extra;
30     uint16_t subscribeId;
31     std::string filterOp;
32     std::vector<DmDeviceFilters> filters;
33 } DmDiscoveryContext;
34 
35 class DmDiscoveryManager final : public ISoftbusDiscoveryCallback,
36                                  public std::enable_shared_from_this<DmDiscoveryManager> {
37 public:
38     DmDiscoveryManager(std::shared_ptr<SoftbusConnector> softbusConnector,
39                        std::shared_ptr<IDeviceManagerServiceListener> listener);
40     ~DmDiscoveryManager();
41 
42     /**
43      * @tc.name: DmDiscoveryManager::StartDeviceDiscovery
44      * @tc.desc: Start Device Discovery of the Dm Discovery Manager
45      * @tc.type: FUNC
46      */
47     int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
48                                  const std::string &extra);
49 
50     /**
51      * @tc.name: DmDiscoveryManager::StopDeviceDiscovery
52      * @tc.desc: Stop Device Discovery of the Dm Discovery Manager
53      * @tc.type: FUNC
54      */
55     int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId);
56 
57     /**
58      * @tc.name: DmDiscoveryManager::OnDeviceFound
59      * @tc.desc: OnDevice Found of the Dm Discovery Manager
60      * @tc.type: FUNC
61      */
62     void OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info);
63 
64     /**
65      * @tc.name: DmDiscoveryManager::OnDiscoverySuccess
66      * @tc.desc: OnDiscovery Success of the Dm Discovery Manager
67      * @tc.type: FUNC
68      */
69     void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId);
70 
71     /**
72      * @tc.name: DmDiscoveryManager::OnDiscoveryFailed
73      * @tc.desc: OnDiscovery Failed of the Dm Discovery Manager
74      * @tc.type: FUNC
75      */
76     void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason);
77 
78     /**
79      * @tc.name: DmDiscoveryManager::HandleDiscoveryTimeout
80      * @tc.desc: Handle Discovery Timeout of the Dm Discovery Manager
81      * @tc.type: FUNC
82      */
83     void HandleDiscoveryTimeout(std::string name);
84 private:
85     void CfgDiscoveryTimer();
86     int32_t CheckDiscoveryQueue(const std::string &pkgName);
87 
88 private:
89     std::shared_ptr<SoftbusConnector> softbusConnector_;
90     std::shared_ptr<IDeviceManagerServiceListener> listener_;
91     std::queue<std::string> discoveryQueue_;
92     std::map<std::string, DmDiscoveryContext> discoveryContextMap_;
93     std::shared_ptr<DmTimer> timer_;
94     std::mutex locks_;
95 };
96 } // namespace DistributedHardware
97 } // namespace OHOS
98 #endif // OHOS_DM_DISCOVERY_MANAGER_H
99