• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2023 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 PASTE_BOARD_DEV_PROFILE_H
17 #define PASTE_BOARD_DEV_PROFILE_H
18 
19 #include "api/visibility.h"
20 #include "common/concurrent_map.h"
21 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
22 #include "distributed_device_profile_client.h"
23 #include "profile_change_listener_stub.h"
24 #endif // PB_DEVICE_INFO_MANAGER_ENABLE
25 
26 namespace OHOS {
27 namespace MiscServices {
28 class API_EXPORT DevProfile {
29 public:
30     using Observer = std::function<void(bool isEnable)>;
31     static DevProfile &GetInstance();
32     int32_t GetEnabledStatus(const std::string &networkId, std::string &enabledStatus);
33     void OnReady();
34     void PutEnabledStatus(const std::string &enabledStatus);
35     bool GetRemoteDeviceVersion(const std::string &networkId, uint32_t &deviceVersion);
36     void SubscribeProfileEvent(const std::string &networkId);
37     void UnSubscribeProfileEvent(const std::string &networkId);
38     void UnsubscribeAllProfileEvents();
39     void Watch(Observer observer);
40     void UpdateEnabledStatus(const std::string &udid, const std::string &res);
41     void EraseEnabledStatus(const std::string &udid);
42     static constexpr const uint32_t FIRST_VERSION = 4;
43 
44 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
45     class SubscribeDPChangeListener : public DistributedDeviceProfile::ProfileChangeListenerStub {
46     public:
47         SubscribeDPChangeListener();
48         ~SubscribeDPChangeListener();
49         int32_t OnTrustDeviceProfileAdd(const DistributedDeviceProfile::TrustDeviceProfile &profile) override;
50         int32_t OnTrustDeviceProfileDelete(const DistributedDeviceProfile::TrustDeviceProfile &profile) override;
51         int32_t OnTrustDeviceProfileUpdate(const DistributedDeviceProfile::TrustDeviceProfile &oldProfile,
52             const DistributedDeviceProfile::TrustDeviceProfile &newProfile) override;
53         int32_t OnDeviceProfileAdd(const DistributedDeviceProfile::DeviceProfile &profile) override;
54         int32_t OnDeviceProfileDelete(const DistributedDeviceProfile::DeviceProfile &profile) override;
55         int32_t OnDeviceProfileUpdate(const DistributedDeviceProfile::DeviceProfile &oldProfile,
56             const DistributedDeviceProfile::DeviceProfile &newProfile) override;
57         int32_t OnServiceProfileAdd(const DistributedDeviceProfile::ServiceProfile &profile) override;
58         int32_t OnServiceProfileDelete(const DistributedDeviceProfile::ServiceProfile &profile) override;
59         int32_t OnServiceProfileUpdate(const DistributedDeviceProfile::ServiceProfile &oldProfile,
60             const DistributedDeviceProfile::ServiceProfile &newProfile) override;
61         int32_t OnCharacteristicProfileAdd(const DistributedDeviceProfile::CharacteristicProfile &profile) override;
62         int32_t OnCharacteristicProfileDelete(const DistributedDeviceProfile::CharacteristicProfile &profile) override;
63         int32_t OnCharacteristicProfileUpdate(const DistributedDeviceProfile::CharacteristicProfile &oldProfile,
64             const DistributedDeviceProfile::CharacteristicProfile &newProfile) override;
65     };
66 #endif
67 
68 private:
69     DevProfile();
70     ~DevProfile() = default;
71     void Notify(bool isEnable);
72     std::mutex callbackMutex_;
73     Observer observer_ = nullptr;
74 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
75     std::map<std::string, DistributedDeviceProfile::SubscribeInfo> subscribeInfoCache_;
76     ConcurrentMap<std::string, std::string> enabledStatusCache_;
77 #endif // PB_DEVICE_INFO_MANAGER_ENABLE
78 };
79 } // namespace MiscServices
80 } // namespace OHOS
81 #endif // PASTE_BOARD_DEV_PROFILE_H
82