1 /* 2 * Copyright (c) 2022 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 #include "define_multimodal.h" 28 29 namespace OHOS { 30 namespace MMI { 31 class DeviceProfileAdapter final { 32 DECLARE_DELAYED_SINGLETON(DeviceProfileAdapter); 33 class ProfileEventCallbackImpl : public DeviceProfile::IProfileEventCallback { 34 public: 35 void OnSyncCompleted(const DeviceProfile::SyncResult &syncResults) override; 36 void OnProfileChanged(const DeviceProfile::ProfileChangeNotification &changeNotification) override; 37 }; 38 public: 39 using ProfileEventCallback = std::shared_ptr<DeviceProfile::IProfileEventCallback>; 40 using DPCallback = std::function<void(const std::string &, bool)>; 41 DISALLOW_COPY_AND_MOVE(DeviceProfileAdapter); 42 43 int32_t UpdateCrossingSwitchState(bool state); 44 int32_t UpdateCrossingSwitchState(bool state, const std::vector<std::string> &deviceIds); 45 bool GetCrossingSwitchState(const std::string &deviceId); 46 int32_t RegisterCrossingStateListener(const std::string &deviceId, DPCallback callback); 47 int32_t UnregisterCrossingStateListener(const std::string &deviceId); 48 49 private: 50 int32_t RegisterProfileListener(const std::string &deviceId); 51 void OnProfileChanged(const std::string &deviceId); 52 std::map<std::string, DeviceProfileAdapter::ProfileEventCallback> profileEventCallbacks_; 53 std::mutex adapterLock_; 54 std::map<std::string, DeviceProfileAdapter::DPCallback> callbacks_; 55 }; 56 57 #define DProfileAdapter ::OHOS::DelayedSingleton<DeviceProfileAdapter>::GetInstance() 58 } // namespace MMI 59 } // namespace OHOS 60 61 #endif // DEVICE_PROFILE_ADAPTER_H