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_ABILITY_SLITE_ABILITY_SAVED_DATA_H 17 #define OHOS_ABILITY_SLITE_ABILITY_SAVED_DATA_H 18 19 #include <cstdint> 20 21 namespace OHOS { 22 namespace AbilitySlite { 23 enum class SavedResultCode : uint8_t { 24 SAVED_RESULT_OK = 0, 25 SAVED_RESULT_INVALID_PARAM, 26 SAVED_RESULT_EXCEED_UPPER_LIMIT, 27 SAVED_RESULT_ALLOC_ERROR, 28 SAVED_RESULT_NO_DATA, 29 }; 30 31 constexpr uint16_t SAVED_DATA_LIMIT = 1024; 32 33 class AbilitySavedData { 34 public: 35 AbilitySavedData(); 36 37 ~AbilitySavedData(); 38 39 SavedResultCode SetSavedData(const void *buffer, uint16_t bufferSize); 40 41 SavedResultCode SetUserSavedData(const void *buffer, uint16_t bufferSize); 42 43 SavedResultCode GetSavedData(void *buffer, uint16_t bufferSize, uint16_t *getDataSize); 44 45 SavedResultCode GetUserSavedData(void *buffer, uint16_t bufferSize, uint16_t *getDataSize); 46 47 void SetSavedResultCode(SavedResultCode code); 48 49 SavedResultCode GetSavedResultCode() const; 50 51 void Reset(); 52 53 private: 54 void *savedData = nullptr; 55 void *userSavedData = nullptr; 56 uint16_t savedDataSize = 0; 57 uint16_t userSavedDataSize = 0; 58 SavedResultCode savedResult = SavedResultCode::SAVED_RESULT_NO_DATA; 59 }; 60 } // namespace AbilitySlite 61 } // namespace OHOS 62 #endif // OHOS_ABILITY_SLITE_ABILITY_SAVED_DATA_H 63