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 TIMER_CJSON_HELPER_H 17 #define TIMER_CJSON_HELPER_H 18 19 #include <fstream> 20 21 #include <cJSON.h> 22 #include "timer_manager_interface.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 27 constexpr const char *HOLD_ON_REBOOT = "hold_on_reboot"; 28 constexpr const char *DROP_ON_REBOOT = "drop_on_reboot"; 29 30 class CjsonHelper { 31 public: 32 std::string QueryWant(std::string tableName, uint64_t timerId); 33 cJSON* QueryTable(std::string tableName, cJSON** db); 34 std::vector<std::tuple<std::string, std::string, int64_t>> QueryAutoReboot(); 35 bool Insert(std::string tableName, std::shared_ptr<TimerEntry> timerInfo); 36 bool UpdateTrigger(std::string tableName, int64_t timerId, int64_t triggerTime); 37 bool UpdateTriggerGroup(std::string tableName, std::vector<std::pair<uint64_t, uint64_t>> timerVec); 38 bool UpdateState(std::string tableName, int64_t timerId); 39 bool Delete(std::string tableName, int64_t timerId); 40 bool ClearInvaildDataInHoldOnReboot(); 41 void Clear(std::string tableName); 42 bool StrToI64(std::string str, int64_t& value); 43 bool IsNumber(cJSON* item); 44 bool IsString(cJSON* item); 45 static CjsonHelper &GetInstance(); 46 bool LoadAndParseJsonFile(const std::string& tableName, cJSON* &db, cJSON* &table); 47 48 private: 49 CjsonHelper(); 50 void SaveJson(cJSON* data); 51 static std::mutex mutex_; 52 }; 53 } // namespace MiscServices 54 } // namespace OHOS 55 #endif //TIMER_CJSON_HELPER_H 56