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 <functional>
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     std::pair<int32_t, std::string> GetEnabledStatus(const std::string &networkId);
33     void OnReady();
34     void PutEnabledStatus(const std::string &enabledStatus);
35     void 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     static constexpr const uint32_t FIRST_VERSION = 4;
41 
42     #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
43     class SubscribeDPChangeListener : public DistributedDeviceProfile::ProfileChangeListenerStub {
44     public:
45         SubscribeDPChangeListener();
46         ~SubscribeDPChangeListener();
47         int32_t OnTrustDeviceProfileAdd(const DistributedDeviceProfile::TrustDeviceProfile &profile) override;
48         int32_t OnTrustDeviceProfileDelete(const DistributedDeviceProfile::TrustDeviceProfile &profile) override;
49         int32_t OnTrustDeviceProfileUpdate(const DistributedDeviceProfile::TrustDeviceProfile &oldProfile,
50             const DistributedDeviceProfile::TrustDeviceProfile &newProfile) override;
51         int32_t OnDeviceProfileAdd(const DistributedDeviceProfile::DeviceProfile &profile) override;
52         int32_t OnDeviceProfileDelete(const DistributedDeviceProfile::DeviceProfile &profile) override;
53         int32_t OnDeviceProfileUpdate(const DistributedDeviceProfile::DeviceProfile &oldProfile,
54             const DistributedDeviceProfile::DeviceProfile &newProfile) override;
55         int32_t OnServiceProfileAdd(const DistributedDeviceProfile::ServiceProfile &profile) override;
56         int32_t OnServiceProfileDelete(const DistributedDeviceProfile::ServiceProfile &profile) override;
57         int32_t OnServiceProfileUpdate(const DistributedDeviceProfile::ServiceProfile &oldProfile,
58             const DistributedDeviceProfile::ServiceProfile &newProfile) override;
59         int32_t OnCharacteristicProfileAdd(const DistributedDeviceProfile::CharacteristicProfile &profile) override;
60         int32_t OnCharacteristicProfileDelete(const DistributedDeviceProfile::CharacteristicProfile &profile) override;
61         int32_t OnCharacteristicProfileUpdate(const DistributedDeviceProfile::CharacteristicProfile &oldProfile,
62             const DistributedDeviceProfile::CharacteristicProfile &newProfile) override;
63     };
64     #endif
65 
66 private:
67     DevProfile();
68     ~DevProfile() = default;
69     void Notify(bool isEnable);
70     std::mutex callbackMutex_;
71     Observer observer_ = nullptr;
72     #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
73     std::map<std::string, DistributedDeviceProfile::SubscribeInfo> subscribeInfoCache_;
74     #endif // PB_DEVICE_INFO_MANAGER_ENABLE
75 
76 };
77 } // namespace MiscServices
78 } // namespace OHOS
79 #endif // PASTE_BOARD_DEV_PROFILE_H
80