1 /* 2 * Copyright (c) 2021 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 BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_SCREEN_STATUS_MANAGER_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_SCREEN_STATUS_MANAGER_H 18 19 #include <mutex> 20 21 #include "distributed_kv_data_manager.h" 22 #include "event_handler.h" 23 #include "event_runner.h" 24 #include "singleton.h" 25 26 #include "distributed_device_callback.h" 27 #include "distributed_flow_control.h" 28 29 namespace OHOS { 30 namespace Notification { 31 class DistributedScreenStatusManager : private DistributedFlowControl, 32 public DelayedSingleton<DistributedScreenStatusManager> { 33 public: 34 ErrCode CheckRemoteDevicesIsUsing(bool &isUsing); 35 ErrCode SetLocalScreenStatus(bool screenOn); 36 37 private: 38 void OnDeviceConnected(const std::string &deviceId); 39 void OnDeviceDisconnected(const std::string &deviceId); 40 41 void GetKvDataManager(void); 42 bool CheckKvDataManager(void); 43 void GetKvStore(void); 44 bool CheckKvStore(void); 45 46 std::string GenerateDistributedKey(const std::string &deviceId); 47 48 private: 49 std::recursive_mutex mutex_; 50 std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ = nullptr; 51 std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr; 52 std::unique_ptr<DistributedKv::DistributedKvDataManager> kvDataManager_ = nullptr; 53 std::shared_ptr<DistributedKv::SingleKvStore> kvStore_ = nullptr; 54 std::shared_ptr<DistributedDeviceCallback> deviceCb_ = nullptr; 55 56 bool localScreenOn_ = false; 57 58 DECLARE_DELAYED_SINGLETON(DistributedScreenStatusManager); 59 DISALLOW_COPY_AND_MOVE(DistributedScreenStatusManager); 60 }; 61 } // namespace Notification 62 } // namespace OHOS 63 64 #endif /* BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_SCREEN_STATUS_MANAGER_H */ 65