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 DevTrustChangeCallback {
34 public:
35     AccessManager(const AccessManager &) = delete;
36     AccessManager &operator = (const AccessManager &) = delete;
37     AccessManager(AccessManager &&) = delete;
38     AccessManager &operator = (AccessManager &&) = delete;
39     AccessManager() = default;
40     virtual ~AccessManager();
41     static std::shared_ptr<AccessManager> GetInstance();
42     int32_t Init();
43     int32_t UnInit();
44     bool IsDeviceOnline(const std::string &uuid);
45     virtual void OnRemoteDied() override;
46     virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override;
47     virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override;
48     virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override;
49     virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override;
50     virtual void OnDeviceTrustChange(const std::string &peerudid, const std::string &peeruuid,
51         DmAuthForm authform) override;
52     /* Send device online event which is already online */
53     void CheckTrustedDeviceOnline();
54     int32_t Dump(const std::vector<std::string> &argsStr, std::string &result);
55 
56 private:
57     int32_t RegisterDevStateCallback();
58     int32_t UnRegisterDevStateCallback();
59     int32_t InitDeviceManager();
60     int32_t UnInitDeviceManager();
61     int32_t RegDevTrustChangeCallback();
62     std::mutex accessMutex_;
63 };
64 } // namespace DistributedHardware
65 } // namespace OHOS
66 #endif
67