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 /** 17 * @addtogroup PREFERENCES 18 * @{ 19 * 20 * @brief Provides APIs for processing data in the form of key-value (KV) pairs. 21 * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. 22 * The key is of the string type, and the value can be a number, a string, a boolean value. 23 * 24 * @since 13 25 */ 26 27 /** 28 * @file oh_preferences_option.h 29 * 30 * @brief Defines the APIs and enums related to preferences option. 31 * 32 * @kit ArkData 33 * @library libohpreferences.so 34 * @syscap SystemCapability.DistributedDataManager.Preferences.Core 35 * 36 * @since 13 37 */ 38 39 #ifndef OH_PREFERENCES_OPTION_H 40 #define OH_PREFERENCES_OPTION_H 41 42 #include <stdint.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @brief Represents an OH_PreferencesOption instance. 50 * 51 * @since 13 52 */ 53 typedef struct OH_PreferencesOption OH_PreferencesOption; 54 55 /** 56 * @brief Enumerates the preferences storage types. 57 * 58 * @since 18 59 */ 60 typedef enum Preferences_StorageType { 61 /** XML storage*/ 62 PREFERENCES_STORAGE_XML = 0, 63 /** GSKV storage */ 64 PREFERENCES_STORAGE_GSKV 65 } Preferences_StorageType; 66 67 /** 68 * @brief Creates an {@Link OH_PreferencesOption} instance. 69 * 70 * @return Returns a pointer to the {@Link OH_PreferencesOption} instance created if the operation is successful; 71 * returns nullptr otherwise while malloc memory failed. 72 * @see OH_PreferencesOption. 73 * @since 13 74 */ 75 OH_PreferencesOption *OH_PreferencesOption_Create(void); 76 77 /** 78 * @brief Sets the file path in an {@Link OH_PreferencesOption} instance. 79 * 80 * @param option Pointer to the target {@Link OH_PreferencesOption} instance. 81 * @param fileName Pointer to the file name to set. 82 * @return Returns the status code of the execution. 83 * {@link PREFERENCES_OK} success. 84 * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 85 * @see OH_PreferencesOption. 86 * @since 13 87 */ 88 int OH_PreferencesOption_SetFileName(OH_PreferencesOption *option, const char *fileName); 89 90 /** 91 * @brief Sets the bundle name in an {@Link OH_PreferencesOption} instance. 92 * 93 * @param option Pointer to the target {@Link OH_PreferencesOption} instance. 94 * @param bundleName Pointer to the bundle name to set. 95 * @return Returns the status code of the execution. 96 * {@link PREFERENCES_OK} success. 97 * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 98 * @see OH_PreferencesOption. 99 * @since 13 100 */ 101 int OH_PreferencesOption_SetBundleName(OH_PreferencesOption *option, const char *bundleName); 102 103 /** 104 * @brief Sets the data group ID in an {@Link OH_PreferencesOption} instance. 105 * 106 * @param option Represents a pointer to an {@link OH_PreferencesOption} instance. 107 * @param dataGroupId Represents preferences data group id param. 108 * @return Returns the status code of the execution. 109 * {@link PREFERENCES_OK} success. 110 * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 111 * @see OH_PreferencesOption. 112 * @since 13 113 */ 114 int OH_PreferencesOption_SetDataGroupId(OH_PreferencesOption *option, const char *dataGroupId); 115 116 /** 117 * @brief Sets the storage type in an {@Link OH_PreferencesOption} instance. 118 * 119 * @param option Represents a pointer to an {@link OH_PreferencesOption} instance. 120 * @param type Represents preferences storage type. 121 * @return Returns the status code of the execution. 122 * {@link PREFERENCES_OK} success. 123 * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 124 * @see OH_PreferencesOption. 125 * @since 16 126 */ 127 int OH_PreferencesOption_SetStorageType(OH_PreferencesOption *option, Preferences_StorageType type); 128 129 /** 130 * @brief Destroys an {@Link OH_PreferencesOption} instance. 131 * 132 * @param option Pointer to the {@Link OH_PreferencesOption} instance to destroy. 133 * @return Returns the status code of the execution. 134 * {@link PREFERENCES_OK} indicates the operation is successful. 135 * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 136 * @see OH_PreferencesOption. 137 * @since 13 138 */ 139 int OH_PreferencesOption_Destroy(OH_PreferencesOption *option); 140 #ifdef __cplusplus 141 }; 142 #endif 143 /** @} */ 144 #endif // OH_PREFERENCES_OPTION_H