• 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 DEVICE_PROFILE_ADAPTER_H
17 #define DEVICE_PROFILE_ADAPTER_H
18 
19 #include <functional>
20 #include <memory>
21 #include <vector>
22 
23 #include "iprofile_event_callback.h"
24 #include "nocopyable.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace Msdp {
29 namespace DeviceStatus {
30 class DeviceProfileAdapter final {
31     DECLARE_DELAYED_SINGLETON(DeviceProfileAdapter);
32     class ProfileEventCallbackImpl final : public DeviceProfile::IProfileEventCallback {
33     public:
34         void OnSyncCompleted(const DeviceProfile::SyncResult &syncResults) override;
35         void OnProfileChanged(const DeviceProfile::ProfileChangeNotification &changeNotification) override;
36     };
37 public:
38     using ProfileEventCallback = std::shared_ptr<DeviceProfile::IProfileEventCallback>;
39     using DPCallback = std::function<void(const std::string &, bool)>;
40     DISALLOW_COPY_AND_MOVE(DeviceProfileAdapter);
41 
42     int32_t UpdateCrossingSwitchState(bool state);
43     int32_t UpdateCrossingSwitchState(bool state, const std::vector<std::string> &deviceIds);
44     bool GetCrossingSwitchState(const std::string &deviceId);
45     int32_t RegisterCrossingStateListener(const std::string &deviceId, DPCallback callback);
46     int32_t UnregisterCrossingStateListener(const std::string &deviceId);
47 
48 private:
49     int32_t RegisterProfileListener(const std::string &deviceId);
50     void OnProfileChanged(const std::string &deviceId);
51     std::map<std::string, DeviceProfileAdapter::ProfileEventCallback> profileEventCallbacks_;
52     std::mutex adapterLock_;
53     std::map<std::string, DeviceProfileAdapter::DPCallback> callbacks_;
54     const std::string characteristicsName_ = "currentStatus";
55 };
56 
57 #define DP_ADAPTER OHOS::DelayedSingleton<DeviceProfileAdapter>::GetInstance()
58 } // namespace DeviceStatus
59 } // namespace Msdp
60 } // namespace OHOS
61 
62 #endif // DEVICE_PROFILE_ADAPTER_H