1 /* 2 * Copyright (c) 2024 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_HDI_POWER_V1_2_HIBERNATE_H 17 #define OHOS_HDI_POWER_V1_2_HIBERNATE_H 18 19 #include <cstdint> 20 #include <atomic> 21 #include <mutex> 22 23 namespace OHOS { 24 namespace HDI { 25 namespace Power { 26 namespace V1_2 { 27 class Hibernate { 28 public: 29 Hibernate(const Hibernate &) = delete; 30 Hibernate(const Hibernate &&) = delete; 31 Hibernate &operator=(const Hibernate &) = delete; 32 Hibernate &operator=(const Hibernate &&) = delete; ~Hibernate()33 ~Hibernate() {}; 34 35 void Init(); 36 int32_t DoHibernate(); 37 GetInstance()38 static Hibernate &GetInstance() 39 { 40 static Hibernate instance; 41 return instance; 42 } 43 44 private: Hibernate()45 Hibernate() {}; 46 void InitSwap(); 47 bool IsSwapFileExist(); 48 int32_t MkSwap(); 49 int32_t CheckSwapFile(bool &needToCreateSwapFile); 50 int32_t CheckSwapFileSize(bool &isRightSize); 51 int32_t CreateSwapFile(); 52 int32_t RemoveSwapFile(); 53 int32_t EnableSwap(); 54 int32_t GetResumeOffset(uint64_t &resumeOffset); 55 int32_t GetResumeInfo(std::string &resumeInfo); 56 int32_t WriteOffsetAndResume(); 57 int32_t WriteOffset(); 58 int32_t WriteResume(); 59 int32_t WritePowerState(); 60 61 std::atomic_bool swapFileReady_ {false}; 62 std::mutex initMutex_; 63 }; 64 } // namespace V1_2 65 } // namespace Power 66 } // namespace HDI 67 } // namespace OHOS 68 69 #endif // OHOS_HDI_POWER_V1_2_HIBERNATE_H