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 OHOS_ABILITY_RUNTIME_TASK_DATA_PERSISTENCE_MGR_H 17 #define OHOS_ABILITY_RUNTIME_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 constexpr const char* THREAD_NAME = "TaskDataStorage"; 29 constexpr const char* SAVE_MISSION_INFO = "SaveMissionInfo"; 30 constexpr const char* DELETE_MISSION_INFO = "DeleteMissionInfo"; 31 constexpr const char* SAVE_MISSION_SNAPSHOT = "SaveMissionSnapshot"; 32 constexpr const char* 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 #ifdef SUPPORT_GRAPHICS 80 /** 81 * @brief Get the Snapshot object 82 * @param missionId Indicates this mission id. 83 * @return Returns PixelMap of snapshot. 84 */ 85 std::shared_ptr<Media::PixelMap> GetSnapshot(int missionId) const; 86 #endif 87 88 /** 89 * @brief Get the mission snapshot object 90 * @param missionId id of mission 91 * @param missionSnapshot output snapshot of mission. 92 * @param isLowResolution low resolution. 93 * @return return true if update mission snapshot success, else false 94 */ 95 bool GetMissionSnapshot(int missionId, MissionSnapshot& missionSnapshot, bool isLowResolution); 96 97 private: 98 std::unordered_map<int, std::shared_ptr<MissionDataStorage>> missionDataStorageMgr_; 99 std::shared_ptr<MissionDataStorage> currentMissionDataStorage_; 100 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 101 std::shared_ptr<AppExecFwk::EventHandler> handler_; 102 int32_t currentUserId_ = -1; 103 std::mutex mutex_; 104 }; 105 } // namespace AAFwk 106 } // namespace OHOS 107 #endif // OHOS_ABILITY_RUNTIME_TASK_DATA_PERSISTENCE_MGR_H 108