17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci/** 177777dab0Sopenharmony_ci * @addtogroup PREFERENCES 187777dab0Sopenharmony_ci * @{ 197777dab0Sopenharmony_ci * 207777dab0Sopenharmony_ci * @brief Provides APIs for processing data in the form of key-value (KV) pairs. 217777dab0Sopenharmony_ci * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. 227777dab0Sopenharmony_ci * The key is of the string type, and the value can be a number, a string, a boolean value. 237777dab0Sopenharmony_ci * 247777dab0Sopenharmony_ci * @since 13 257777dab0Sopenharmony_ci */ 267777dab0Sopenharmony_ci 277777dab0Sopenharmony_ci/** 287777dab0Sopenharmony_ci * @file oh_preferences_value.h 297777dab0Sopenharmony_ci * 307777dab0Sopenharmony_ci * @brief Defines the APIs and enums related to preferences values. 317777dab0Sopenharmony_ci * 327777dab0Sopenharmony_ci * @kit ArkData 337777dab0Sopenharmony_ci * @library libohpreferences.so 347777dab0Sopenharmony_ci * @syscap SystemCapability.DistributedDataManager.Preferences.Core 357777dab0Sopenharmony_ci * 367777dab0Sopenharmony_ci * @since 13 377777dab0Sopenharmony_ci */ 387777dab0Sopenharmony_ci 397777dab0Sopenharmony_ci#ifndef OH_PREFERENCES_VALUE_H 407777dab0Sopenharmony_ci#define OH_PREFERENCES_VALUE_H 417777dab0Sopenharmony_ci 427777dab0Sopenharmony_ci#include <stdbool.h> 437777dab0Sopenharmony_ci#include <stdint.h> 447777dab0Sopenharmony_ci 457777dab0Sopenharmony_ci#ifdef __cplusplus 467777dab0Sopenharmony_ciextern "C" { 477777dab0Sopenharmony_ci#endif 487777dab0Sopenharmony_ci 497777dab0Sopenharmony_ci/** 507777dab0Sopenharmony_ci * @brief Enumerates the Preference value types. 517777dab0Sopenharmony_ci * 527777dab0Sopenharmony_ci * @since 13 537777dab0Sopenharmony_ci */ 547777dab0Sopenharmony_citypedef enum Preference_ValueType { 557777dab0Sopenharmony_ci /** 567777dab0Sopenharmony_ci * @brief Null. 577777dab0Sopenharmony_ci */ 587777dab0Sopenharmony_ci PREFERENCE_TYPE_NULL = 0, 597777dab0Sopenharmony_ci /** 607777dab0Sopenharmony_ci * @brief Int. 617777dab0Sopenharmony_ci */ 627777dab0Sopenharmony_ci PREFERENCE_TYPE_INT, 637777dab0Sopenharmony_ci /** 647777dab0Sopenharmony_ci * @brief boolean. 657777dab0Sopenharmony_ci */ 667777dab0Sopenharmony_ci PREFERENCE_TYPE_BOOL, 677777dab0Sopenharmony_ci /** 687777dab0Sopenharmony_ci * @brief String. 697777dab0Sopenharmony_ci */ 707777dab0Sopenharmony_ci PREFERENCE_TYPE_STRING, 717777dab0Sopenharmony_ci /** 727777dab0Sopenharmony_ci * @brief end butt. 737777dab0Sopenharmony_ci */ 747777dab0Sopenharmony_ci PREFERENCE_TYPE_BUTT 757777dab0Sopenharmony_ci} Preference_ValueType; 767777dab0Sopenharmony_ci 777777dab0Sopenharmony_ci/** 787777dab0Sopenharmony_ci * @brief Represents a KV pair in a Preferences instance. 797777dab0Sopenharmony_ci * 807777dab0Sopenharmony_ci * @since 13 817777dab0Sopenharmony_ci */ 827777dab0Sopenharmony_citypedef struct OH_PreferencesPair OH_PreferencesPair; 837777dab0Sopenharmony_ci 847777dab0Sopenharmony_ci/** 857777dab0Sopenharmony_ci * @brief Represents the value in a KV pair of a Preferences instance. 867777dab0Sopenharmony_ci * 877777dab0Sopenharmony_ci * @since 13 887777dab0Sopenharmony_ci */ 897777dab0Sopenharmony_citypedef struct OH_PreferencesValue OH_PreferencesValue; 907777dab0Sopenharmony_ci 917777dab0Sopenharmony_ci/** 927777dab0Sopenharmony_ci * @brief Obtains a key from an {@Link OH_PreferencesPair} instance. 937777dab0Sopenharmony_ci * 947777dab0Sopenharmony_ci * @param pairs Pointer to the target {@Link OH_PreferencesPair} instance. 957777dab0Sopenharmony_ci * @param index Represents a target index of the pairs 967777dab0Sopenharmony_ci * @return Returns preferences pointer to the key that when input parameters valid, 977777dab0Sopenharmony_ci * return nullptr otherwise while invalid args are passed in. 987777dab0Sopenharmony_ci * @see OH_PreferencesPair. 997777dab0Sopenharmony_ci * @since 13 1007777dab0Sopenharmony_ci */ 1017777dab0Sopenharmony_ciconst char *OH_PreferencesPair_GetKey(const OH_PreferencesPair *pairs, uint32_t index); 1027777dab0Sopenharmony_ci 1037777dab0Sopenharmony_ci/** 1047777dab0Sopenharmony_ci * @brief Obtains a value from an {@Link OH_PreferencesPair} instance. 1057777dab0Sopenharmony_ci * 1067777dab0Sopenharmony_ci * @param pairs Pointer to the target {@Link OH_PreferencesPair} instance. 1077777dab0Sopenharmony_ci * @param index Index of the value to obtain. 1087777dab0Sopenharmony_ci * @return Returns a pointer to the {@Link OH_PreferencesValue} obtained if the operation is successful, 1097777dab0Sopenharmony_ci * returns nullptr otherwise while invalid args are passed in. 1107777dab0Sopenharmony_ci * @see OH_PreferencesValue. 1117777dab0Sopenharmony_ci * @since 13 1127777dab0Sopenharmony_ci */ 1137777dab0Sopenharmony_ciconst OH_PreferencesValue *OH_PreferencesPair_GetPreferencesValue(const OH_PreferencesPair *pairs, uint32_t index); 1147777dab0Sopenharmony_ci 1157777dab0Sopenharmony_ci/** 1167777dab0Sopenharmony_ci * @brief Obtains the type of a preferences value. 1177777dab0Sopenharmony_ci * 1187777dab0Sopenharmony_ci * @param object Pointer to the target {@Link OH_PreferencesValue} instance. 1197777dab0Sopenharmony_ci * @return Returns the value type obtained. 1207777dab0Sopenharmony_ci * {@link PREFERENCE_TYPE_NULL} indicates invalid args are passed in. 1217777dab0Sopenharmony_ci * @see OH_PreferencesValue. 1227777dab0Sopenharmony_ci * @since 13 1237777dab0Sopenharmony_ci */ 1247777dab0Sopenharmony_ciPreference_ValueType OH_PreferencesValue_GetValueType(const OH_PreferencesValue *object); 1257777dab0Sopenharmony_ci 1267777dab0Sopenharmony_ci/** 1277777dab0Sopenharmony_ci * @brief Obtains the int value of an {@Link OH_PreferencesValue} instance. 1287777dab0Sopenharmony_ci * 1297777dab0Sopenharmony_ci * @param object Pointer to the target {@Link OH_PreferencesValue} instance. 1307777dab0Sopenharmony_ci * @param value Pointer to the value obtained. 1317777dab0Sopenharmony_ci * @return Returns the status code of the execution. 1327777dab0Sopenharmony_ci * {@link PREFERENCES_OK} indicates the operation is successful. 1337777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 1347777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. 1357777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. 1367777dab0Sopenharmony_ci * @see OH_PreferencesValue. 1377777dab0Sopenharmony_ci * @since 13 1387777dab0Sopenharmony_ci */ 1397777dab0Sopenharmony_ciint OH_PreferencesValue_GetInt(const OH_PreferencesValue *object, int *value); 1407777dab0Sopenharmony_ci 1417777dab0Sopenharmony_ci/** 1427777dab0Sopenharmony_ci * @brief Obtains the Boolean value of an {@Link OH_PreferencesValue} instance. 1437777dab0Sopenharmony_ci * 1447777dab0Sopenharmony_ci * @param object Pointer to the target {@Link OH_PreferencesValue} instance. 1457777dab0Sopenharmony_ci * @param value Pointer to the Boolean value obtained. 1467777dab0Sopenharmony_ci * @return Returns the status code of the execution. 1477777dab0Sopenharmony_ci * {@link PREFERENCES_OK} indicates the operation is successful. 1487777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 1497777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. 1507777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. 1517777dab0Sopenharmony_ci * @see OH_PreferencesValue. 1527777dab0Sopenharmony_ci * @since 13 1537777dab0Sopenharmony_ci */ 1547777dab0Sopenharmony_ciint OH_PreferencesValue_GetBool(const OH_PreferencesValue *object, bool *value); 1557777dab0Sopenharmony_ci 1567777dab0Sopenharmony_ci/** 1577777dab0Sopenharmony_ci * @brief Obtains the string value of an {@Link OH_PreferencesValue} instance. 1587777dab0Sopenharmony_ci * 1597777dab0Sopenharmony_ci * @param object Pointer to target {@Link OH_PreferencesValue} instance. 1607777dab0Sopenharmony_ci * @param value Double pointer to the value obtained in an char * array. Release {@Link OH_Preferences_FreeString} the 1617777dab0Sopenharmony_ci * memory by user when this parameter is no longer required. 1627777dab0Sopenharmony_ci * @param valueLen Pointer to the string length. 1637777dab0Sopenharmony_ci * @return Returns the status code of the execution. 1647777dab0Sopenharmony_ci * {@link PREFERENCES_OK} indicates the operation is successful. 1657777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. 1667777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. 1677777dab0Sopenharmony_ci * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. 1687777dab0Sopenharmony_ci * @see OH_PreferencesValue. 1697777dab0Sopenharmony_ci * @since 13 1707777dab0Sopenharmony_ci */ 1717777dab0Sopenharmony_ciint OH_PreferencesValue_GetString(const OH_PreferencesValue *object, char **value, uint32_t *valueLen); 1727777dab0Sopenharmony_ci#ifdef __cplusplus 1737777dab0Sopenharmony_ci}; 1747777dab0Sopenharmony_ci#endif 1757777dab0Sopenharmony_ci#endif // OH_PREFERENCES_VALUE_H