1 /* 2 * Copyright (c) 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 OHOS_FILEMGMT_BATTERY_STATUS_LISTENER_H 17 #define OHOS_FILEMGMT_BATTERY_STATUS_LISTENER_H 18 19 #include "common_event_subscriber.h" 20 #include "data_sync_manager.h" 21 22 namespace OHOS::FileManagement::CloudSync { 23 class BatteryStatusListener : public std::enable_shared_from_this<BatteryStatusListener> { 24 public: 25 explicit BatteryStatusListener(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager); 26 ~BatteryStatusListener(); 27 void Start(); 28 void Stop(); 29 void OnStatusNormal(); 30 void OnStatusAbnormal(); 31 void OnPowerConnected(); 32 33 private: 34 std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager_; 35 std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber_ = nullptr; 36 SyncTriggerType triggerType_{SyncTriggerType::BATTERY_OK_TRIGGER}; 37 }; 38 39 class BatteryStatusSubscriber : public EventFwk::CommonEventSubscriber { 40 public: 41 BatteryStatusSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, 42 std::shared_ptr<BatteryStatusListener> listener); ~BatteryStatusSubscriber()43 ~BatteryStatusSubscriber() override {} 44 void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; 45 46 private: 47 std::shared_ptr<BatteryStatusListener> listener_; 48 }; 49 } // namespace OHOS::FileManagement::CloudSync 50 51 #endif // OHOS_FILEMGMT_BATTERY_STATUS_LISTENER_H