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 FOUNDATION_AAFWK_SERVICES_ABILITYMGR_INCLUDE_TASK_DATA_PERSISTENCE_MGR_H 17 #define FOUNDATION_AAFWK_SERVICES_ABILITYMGR_INCLUDE_TASK_DATA_PERSISTENCE_MGR_H 18 19 #include <memory> 20 #include <unordered_map> 21 22 #include "singleton.h" 23 #include "ability_event_handler.h" 24 #include "mission_data_storage.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 const std::string THREAD_NAME = "TaskDataStorage"; 29 const std::string SAVE_MISSION_INFO = "SaveMissionInfo"; 30 const std::string DELETE_MISSION_INFO = "DeleteMissionInfo"; 31 const std::string SAVE_MISSION_SNAPSHOT = "SaveMissionSnapshot"; 32 const std::string GET_MISSION_SNAPSHOT = "GetMissionSnapshot"; 33 34 class TaskDataPersistenceMgr : public std::enable_shared_from_this<TaskDataPersistenceMgr> { 35 DECLARE_DELAYED_SINGLETON(TaskDataPersistenceMgr) 36 public: 37 /** 38 * @brief initialization of task data persistence manager. 39 * @param user id Indicates the missionInfo object of user to operate. 40 * @return Returns true if init successfully, returns false otherwise. 41 */ 42 bool Init(int userId); 43 44 /** 45 * @brief Boot query persistent storage. 46 * @return Returns true if this function is successfully called; returns false otherwise. 47 */ 48 bool LoadAllMissionInfo(std::list<InnerMissionInfo> &missionInfoList); 49 50 /** 51 * @brief Save the mission data. 52 * @param missionInfo Indicates the missionInfo object to be save. 53 * @return Returns true if the data is successfully saved; returns false otherwise. 54 */ 55 bool SaveMissionInfo(const InnerMissionInfo &missionInfo); 56 57 /** 58 * @brief Delete the mission data corresponding to the mission Id. 59 * @param missionId Indicates this mission id. 60 * @return Returns true if the data is successfully deleted; returns false otherwise. 61 */ 62 bool DeleteMissionInfo(int missionId); 63 64 /** 65 * @brief Remove user directory. 66 * @param userId Indicates this user id. 67 * @return Returns true if the directory is successfully removed; returns false otherwise. 68 */ 69 bool RemoveUserDir(int32_t userId); 70 71 /** 72 * @brief save mission snapshot 73 * @param missionId id of mission 74 * @param snapshot result of snapshot 75 * @return return true if update mission snapshot success, else false 76 */ 77 bool SaveMissionSnapshot(int missionId, const MissionSnapshot& snapshot); 78 79 /** 80 * @brief Get the mission snapshot object 81 * @param missionId id of mission 82 * @param missionSnapshot 83 * @return return true if update mission snapshot success, else false 84 */ 85 bool GetMissionSnapshot(int missionId, MissionSnapshot& missionSnapshot); 86 87 private: 88 std::unordered_map<int, std::shared_ptr<MissionDataStorage>> missionDataStorageMgr_; 89 std::shared_ptr<MissionDataStorage> currentMissionDataStorage_; 90 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 91 std::shared_ptr<AppExecFwk::EventHandler> handler_; 92 int32_t currentUserId_ = -1; 93 std::mutex mutex_; 94 }; 95 } // namespace AAFwk 96 } // namespace OHOS 97 #endif // FOUNDATION_AAFWK_SERVICES_ABILITYMGR_INCLUDE_TASK_DATA_PERSISTENCE_MGR_H