1 /*
2  * Copyright (c) 2021-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_DISTRIBUTED_HARDWARE_ACCESS_MANAGER_H
17 #define OHOS_DISTRIBUTED_HARDWARE_ACCESS_MANAGER_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <memory>
22 #include <mutex>
23 #include <vector>
24 
25 #include "device_manager_callback.h"
26 #include "dm_device_info.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 class AccessManager : public std::enable_shared_from_this<AccessManager>,
31     public DmInitCallback,
32     public DeviceStateCallback {
33 public:
34     AccessManager(const AccessManager &) = delete;
35     AccessManager &operator = (const AccessManager &) = delete;
36     AccessManager(AccessManager &&) = delete;
37     AccessManager &operator = (AccessManager &&) = delete;
38     AccessManager() = default;
39     virtual ~AccessManager();
40     static std::shared_ptr<AccessManager> GetInstance();
41     int32_t Init();
42     int32_t UnInit();
43     bool IsDeviceOnline(const std::string &uuid);
44     virtual void OnRemoteDied() override;
45     virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override;
46     virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override;
47     virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override;
48     virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override;
49     /* Send device online event which is already online */
50     void CheckTrustedDeviceOnline();
51     int32_t Dump(const std::vector<std::string> &argsStr, std::string &result);
52 
53 private:
54     int32_t RegisterDevStateCallback();
55     int32_t UnRegisterDevStateCallback();
56     int32_t InitDeviceManager();
57     int32_t UnInitDeviceManager();
58     std::mutex accessMutex_;
59 };
60 } // namespace DistributedHardware
61 } // namespace OHOS
62 #endif
63