• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_DEVICE_STATE_MANAGER_H
17 #define OHOS_DM_DEVICE_STATE_MANAGER_H
18 
19 #include <string>
20 #include <memory>
21 #if defined(__LITEOS_M__)
22 #include "dm_mutex.h"
23 #else
24 #include <mutex>
25 #endif
26 #include "device_manager_service_listener.h"
27 #include "dm_adapter_manager.h"
28 #include "softbus_connector.h"
29 #include "dm_timer.h"
30 #include "hichain_connector.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 #define OFFLINE_TIMEOUT 300
35 struct StateTimerInfo {
36     std::string timerName;
37     std::string netWorkId;
38     std::string deviceId;
39 };
40 
41 class DmDeviceStateManager final : public ISoftbusStateCallback,
42                                    public std::enable_shared_from_this<DmDeviceStateManager> {
43 public:
44     DmDeviceStateManager(std::shared_ptr<SoftbusConnector> softbusConnector,
45                          std::shared_ptr<DeviceManagerServiceListener> listener,
46                          std::shared_ptr<HiChainConnector> hiChainConnector);
47     ~DmDeviceStateManager();
48     int32_t RegisterProfileListener(const std::string &pkgName, const DmDeviceInfo &info);
49     int32_t UnRegisterProfileListener(const std::string &pkgName, const DmDeviceInfo &info);
50     void PostDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info);
51     void PostDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info);
52     void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info);
53     void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info);
54     void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &info);
55     void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &info);
56     void OnProfileReady(const std::string &pkgName, const std::string &deviceId);
57     int32_t RegisterSoftbusStateCallback();
58     void RegisterOffLineTimer(const DmDeviceInfo &deviceInfo);
59     void StartOffLineTimer(const DmDeviceInfo &deviceInfo);
60     void DeleteTimeOutGroup(std::string name);
61     void RegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
62     void UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra);
63 
64 private:
65     int32_t mCumulativeQuantity_ = 0;
66     std::string profileSoName_;
67 #if !defined(__LITEOS_M__)
68     std::mutex timerMapMutex_;
69     std::mutex remoteDeviceInfosMutex_;
70 #endif
71     std::shared_ptr<SoftbusConnector> softbusConnector_;
72     std::shared_ptr<DeviceManagerServiceListener> listener_;
73     std::map<std::string, DmDeviceInfo> remoteDeviceInfos_;
74     std::map<std::string, std::string> decisionInfos_;
75     std::map<std::string, StateTimerInfo> stateTimerInfoMap_;
76     std::shared_ptr<DmTimer> timer_;
77     std::shared_ptr<HiChainConnector> hiChainConnector_;
78     std::string decisionSoName_;
79 };
80 } // namespace DistributedHardware
81 } // namespace OHOS
82 #endif // OHOS_DM_DEVICE_STATE_MANAGER_H
83