diff --git a/distributeddatamgr/preferences/BUILD.gn b/distributeddatamgr/preferences/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..77c03331c6a4d6c259edececb9b44af3e89556a3 --- /dev/null +++ b/distributeddatamgr/preferences/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +import("//foundation/distributeddatamgr/preferences/preferences.gni") + +ohos_ndk_headers("preferences_ndk_header") { + dest_dir = "$ndk_headers_out_dir/database/preferences/" + sources = [ + "./include/oh_preferences.h", + "./include/oh_preferences_err_code.h", + "./include/oh_preferences_option.h", + "./include/oh_preferences_value.h", + ] +} + +ohos_ndk_library("libohpreferences") { + output_name = "ohpreferences" + output_extension = "so" + system_capability = "SystemCapability.DistributedDataManager.Preferences.Core" + ndk_description_file = "./libpreferences.ndk.json" + min_compact_version = "13" + system_capability_headers = [ + "database/preferences/oh_preferences.h", + "database/preferences/oh_preferences_err_code.h", + "database/preferences/oh_preferences_value.h", + "database/preferences/oh_preferences_option.h", + ] +} diff --git a/distributeddatamgr/preferences/include/oh_preferences.h b/distributeddatamgr/preferences/include/oh_preferences.h new file mode 100644 index 0000000000000000000000000000000000000000..c3a56fd957325706b955d94fa3568c5d8a7d1824 --- /dev/null +++ b/distributeddatamgr/preferences/include/oh_preferences.h @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup PREFERENCES + * @{ + * + * @brief Provides APIs for processing data in the form of key-value (KV) pairs. + * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. + * The key is of the string type, and the value can be a number, a string, a boolean value. + * + * @since 13 + */ + +/** + * @file oh_preferences.h + * + * @brief Defines the APIS and enums of Preference. + * + * @kit ArkData + * @library libohpreferences.so + * @syscap SystemCapability.DistributedDataManager.Preferences.Core + * + * @since 13 + */ + +#ifndef OH_PREFERENCES_H +#define OH_PREFERENCES_H + +#include +#include + +#include "oh_preferences_value.h" +#include "oh_preferences_option.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Represents a Preferences instance. + * + * @since 13 + */ +typedef struct OH_Preferences OH_Preferences; + +/** + * @brief Call to return the change in KV pairs. + * + * @param context Pointer to the context of data observer. + * @param pairs Pointer to the KV pairs to be observed. + * @param count Number of KV pairs to be observed. + * @see OH_PreferencesPair. + * @since 13 + */ +typedef void (*OH_PreferencesDataObserver)(void *context, const OH_PreferencesPair *pairs, uint32_t count); + +/** + * @brief Opens a Preferences object. + * + * @param option Pointer to an {@Link OH_PreferencesOption} instance. + * @param errCode Pointer to the status code of the execution. For details, See {@link OH_Preferences_ErrCode}. + * @return Returns an pointer to the Preferences object in {@Link OH_Preferences} if the operation is successful, + * returns nullptr otherwise. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_NOT_SUPPORTED} indicates the capability is not supported. + * {@link PREFERENCES_ERROR_DELETE_FILE} indicates delete file failed. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences OH_PreferencesOption. + * @since 13 + */ +OH_Preferences *OH_Preferences_Open(OH_PreferencesOption *option, int *errCode); + +/** + * @brief Closes a Preferences object. + * + * @param preference Pointer to the {@Link OH_Preferences} instance to close. + * @param option Pointer to an {@Link OH_PreferencesOption} instance. + * @return Returns the status code of the execution. For details, see {@Link OH_Preferences_ErrCode}. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_Close(OH_Preferences *preference); + +/** + * @brief Obtains the integer value in a Preferences object based on the given key. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key of the value to obtain. + * @param value Pointer to the value obtained. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * {@link PREFERENCES_ERROR_KEY_NOT_FOUND} indicates the key does not exist. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_GetInt(OH_Preferences *preference, const char *key, int *value); + +/** + * @brief Obtains the Boolean value in a Preferences object based on the given key. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key of the value to obtain. + * @param value Pointer to the Boolean value obtained. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * {@link PREFERENCES_ERROR_KEY_NOT_FOUND} indicates the key does not exist. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_GetBool(OH_Preferences *preference, const char *key, bool *value); + +/** + * @brief Obtains the string value in a Preferences object based on the given key. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key of the value to obtain. + * @param value Double pointer to the value obtained in an char * array. Release {@Link OH_Preferences_FreeString} the + * memory by user when this parameter is no longer required. + * @param valueLen Pointer to the length of the string obtained. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * {@link PREFERENCES_ERROR_KEY_NOT_FOUND} indicates the key does not exist. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_GetString(OH_Preferences *preference, const char *key, char **value, uint32_t *valueLen); + +/** + * @brief Free a string got by Preferences object. + * + * @param string Point to string need to free. + * @see OH_Preferences. + * @since 13 + */ +void OH_Preferences_FreeString(char *string); + +/** + * @brief Sets an integer in a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key to set. + * @param value Value to set. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_SetInt(OH_Preferences *preference, const char *key, int value); + +/** + * @brief Sets a Boolean value in a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key to set. + * @param value Boolean value to set. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_SetBool(OH_Preferences *preference, const char *key, bool value); + +/** + * @brief Sets a string in a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key to set. + * @param value Point to string to set. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_SetString(OH_Preferences *preference, const char *key, const char *value); + +/** + * @brief Deletes a KV pair from a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param key Pointer to the key of the data to delete. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences. + * @since 13 + */ +int OH_Preferences_Delete(OH_Preferences *preference, const char *key); + +/** + * @brief Registers a data observer for a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param context Pointer to the context of the data observer. + * @param observer the {@Link OH_PreferencesDataObserver} to register. + * @param keys Pointer to the keys to observe. + * @param keyCount Number of keys to observe. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * {@link PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT} indicates get dataObsMgrClient error. + * @see OH_Preferences OH_PreferencesDataObserver. + * @since 13 + */ +int OH_Preferences_RegisterDataObserver(OH_Preferences *preference, void *context, + OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount); + +/** + * @brief Unregisters a data observer for a Preferences object. + * + * @param preference Pointer to the target {@Link OH_Preferences} instance. + * @param context Pointer to the context of the data observer. + * @param observer the {@Link OH_PreferencesDataObserver} to unregister. + * @param keys Pointer to the keys observed. If this parameter is null, this API unregisters the listening for all keys. + * @param keyCount Number of the keys. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_Preferences OH_PreferencesDataObserver. + * @since 13 + */ +int OH_Preferences_UnregisterDataObserver(OH_Preferences *preference, void *context, + OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount); + +#ifdef __cplusplus +}; +#endif + +/** @} */ +#endif // OH_PREFERENCES_H \ No newline at end of file diff --git a/distributeddatamgr/preferences/include/oh_preferences_err_code.h b/distributeddatamgr/preferences/include/oh_preferences_err_code.h new file mode 100644 index 0000000000000000000000000000000000000000..5b77219b9d9647f416e18126d8014747b23ddf24 --- /dev/null +++ b/distributeddatamgr/preferences/include/oh_preferences_err_code.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup PREFERENCES + * @{ + * + * @brief Provides APIs for processing data in the form of key-value (KV) pairs. + * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. + * The key is of the string type, and the value can be a number, a string, a boolean value. + * + * @since 13 + */ + +/** + * @file preferences_err_code.h + * + * @brief Defines the status codes used in the Preferences module. + * + * @kit ArkData + * @library libohpreferences.so + * @syscap SystemCapability.DistributedDataManager.Preferences.Core + * + * @since 13 + */ + + +#ifndef OH_PREFERENCES_ERR_CODE_H +#define OH_PREFERENCES_ERR_CODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the status codes. + * + * @since 13 + */ +typedef enum OH_Preferences_ErrCode { + /** @error Operation successful. */ + PREFERENCES_OK = 0, + /* @error Invalid args. */ + PREFERENCES_ERROR_INVALID_PARAM = 401, + /* @error Capability not supported. */ + PREFERENCES_ERROR_NOT_SUPPORTED = 801, + /* @error Base error code. */ + PREFERENCES_ERROR_BASE = 15500000, + /* @error Failed to delete a file. */ + PREFERENCES_ERROR_DELETE_FILE = 15500010, + /* @error Storage error. */ + PREFERENCES_ERROR_STORAGE = 15500011, + /* @error Failed to malloc memory. */ + PREFERENCES_ERROR_MALLOC = 15500012, + /* @error Key not found error. */ + PREFERENCES_ERROR_KEY_NOT_FOUND = 15500013, + /* @error Failed to get DataObsMgrClient. */ + PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT = 15500019, +} OH_Preferences_ErrCode; + +#ifdef __cplusplus +}; +#endif + +#endif // OH_PREFERENCES_ERR_CODE_H diff --git a/distributeddatamgr/preferences/include/oh_preferences_option.h b/distributeddatamgr/preferences/include/oh_preferences_option.h new file mode 100644 index 0000000000000000000000000000000000000000..a8a25af9f55287456e3595803981a3c727390acf --- /dev/null +++ b/distributeddatamgr/preferences/include/oh_preferences_option.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup PREFERENCES + * @{ + * + * @brief Provides APIs for processing data in the form of key-value (KV) pairs. + * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. + * The key is of the string type, and the value can be a number, a string, a boolean value. + * + * @since 13 + */ + +/** + * @file oh_preferences_option.h + * + * @brief Defines the APIs and enums related to preferences option. + * + * @kit ArkData + * @library libohpreferences.so + * @syscap SystemCapability.DistributedDataManager.Preferences.Core + * + * @since 13 + */ + +#ifndef OH_PREFERENCES_OPTION_H +#define OH_PREFERENCES_OPTION_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Represents an OH_PreferencesOption instance. + * + * @since 13 + */ +typedef struct OH_PreferencesOption OH_PreferencesOption; + +/** + * @brief Creates an {@Link OH_PreferencesOption} instance. + * + * @return Returns a pointer to the {@Link OH_PreferencesOption} instance created if the operation is successful; + * returns nullptr otherwise while malloc memory failed. + * @see OH_PreferencesOption. + * @since 13 + */ +OH_PreferencesOption *OH_PreferencesOption_Create(void); + +/** + * @brief Sets the file path in an {@Link OH_PreferencesOption} instance. + * + * @param option Pointer to the target {@Link OH_PreferencesOption} instance. + * @param fileName Pointer to the file name to set. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} success. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * @see OH_PreferencesOption. + * @since 13 + */ +int OH_PreferencesOption_SetFileName(OH_PreferencesOption *option, const char *fileName); + +/** + * @brief Sets the bundle name in an {@Link OH_PreferencesOption} instance. + * + * @param option Pointer to the target {@Link OH_PreferencesOption} instance. + * @param bundleName Pointer to the bundle name to set. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} success. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * @see OH_PreferencesOption. + * @since 13 + */ +int OH_PreferencesOption_SetBundleName(OH_PreferencesOption *option, const char *bundleName); + +/** + * @brief Sets the data group ID in an {@Link OH_PreferencesOption} instance. + * + * @param option Represents a pointer to an {@link OH_PreferencesOption} instance. + * @param dataGroupId Represents preferences data group id param. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} success. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * @see OH_PreferencesOption. + * @since 13 + */ +int OH_PreferencesOption_SetDataGroupId(OH_PreferencesOption *option, const char *dataGroupId); + +/** + * @brief Destroys an {@Link OH_PreferencesOption} instance. + * + * @param option Pointer to the {@Link OH_PreferencesOption} instance to destroy. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * @see OH_PreferencesOption. + * @since 13 + */ +int OH_PreferencesOption_Destroy(OH_PreferencesOption *option); +#ifdef __cplusplus +}; +#endif +#endif // OH_PREFERENCES_OPTION_H \ No newline at end of file diff --git a/distributeddatamgr/preferences/include/oh_preferences_value.h b/distributeddatamgr/preferences/include/oh_preferences_value.h new file mode 100644 index 0000000000000000000000000000000000000000..945e28fc62980fe1de55cd342a2f1eb33e3d2bb7 --- /dev/null +++ b/distributeddatamgr/preferences/include/oh_preferences_value.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup PREFERENCES + * @{ + * + * @brief Provides APIs for processing data in the form of key-value (KV) pairs. + * You can use the APIs provided by the Preferences module to query, modify, and persist KV pairs. + * The key is of the string type, and the value can be a number, a string, a boolean value. + * + * @since 13 + */ + +/** + * @file oh_preferences_value.h + * + * @brief Defines the APIs and enums related to preferences values. + * + * @kit ArkData + * @library libohpreferences.so + * @syscap SystemCapability.DistributedDataManager.Preferences.Core + * + * @since 13 + */ + +#ifndef OH_PREFERENCES_VALUE_H +#define OH_PREFERENCES_VALUE_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the Preference value types. + * + * @since 13 + */ +typedef enum Preference_ValueType { + /** + * @brief Null. + */ + PREFERENCE_TYPE_NULL = 0, + /** + * @brief Int. + */ + PREFERENCE_TYPE_INT, + /** + * @brief boolean. + */ + PREFERENCE_TYPE_BOOL, + /** + * @brief String. + */ + PREFERENCE_TYPE_STRING, + /** + * @brief end butt. + */ + PREFERENCE_TYPE_BUTT +} Preference_ValueType; + +/** + * @brief Represents a KV pair in a Preferences instance. + * + * @since 13 + */ +typedef struct OH_PreferencesPair OH_PreferencesPair; + +/** + * @brief Represents the value in a KV pair of a Preferences instance. + * + * @since 13 + */ +typedef struct OH_PreferencesValue OH_PreferencesValue; + +/** + * @brief Obtains a key from an {@Link OH_PreferencesPair} instance. + * + * @param pairs Pointer to the target {@Link OH_PreferencesPair} instance. + * @param index Represents a target index of the pairs + * @return Returns preferences pointer to the key that when input parameters valid, + * return nullptr otherwise while invalid args are passed in. + * @see OH_PreferencesPair. + * @since 13 + */ +const char *OH_PreferencesPair_GetKey(const OH_PreferencesPair *pairs, uint32_t index); + +/** + * @brief Obtains a value from an {@Link OH_PreferencesPair} instance. + * + * @param pairs Pointer to the target {@Link OH_PreferencesPair} instance. + * @param index Index of the value to obtain. + * @return Returns a pointer to the {@Link OH_PreferencesValue} obtained if the operation is successful, + * returns nullptr otherwise while invalid args are passed in. + * @see OH_PreferencesValue. + * @since 13 + */ +const OH_PreferencesValue *OH_PreferencesPair_GetPreferencesValue(const OH_PreferencesPair *pairs, uint32_t index); + +/** + * @brief Obtains the type of a preferences value. + * + * @param object Pointer to the target {@Link OH_PreferencesValue} instance. + * @return Returns the value type obtained. + * {@link PREFERENCE_TYPE_NULL} indicates invalid args are passed in. + * @see OH_PreferencesValue. + * @since 13 + */ +Preference_ValueType OH_PreferencesValue_GetValueType(const OH_PreferencesValue *object); + +/** + * @brief Obtains the int value of an {@Link OH_PreferencesValue} instance. + * + * @param object Pointer to the target {@Link OH_PreferencesValue} instance. + * @param value Pointer to the value obtained. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_PreferencesValue. + * @since 13 + */ +int OH_PreferencesValue_GetInt(const OH_PreferencesValue *object, int *value); + +/** + * @brief Obtains the Boolean value of an {@Link OH_PreferencesValue} instance. + * + * @param object Pointer to the target {@Link OH_PreferencesValue} instance. + * @param value Pointer to the Boolean value obtained. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_PreferencesValue. + * @since 13 + */ +int OH_PreferencesValue_GetBool(const OH_PreferencesValue *object, bool *value); + +/** + * @brief Obtains the string value of an {@Link OH_PreferencesValue} instance. + * + * @param object Pointer to target {@Link OH_PreferencesValue} instance. + * @param value Double pointer to the value obtained in an char * array. Release {@Link OH_Preferences_FreeString} the + * memory by user when this parameter is no longer required. + * @param valueLen Pointer to the string length. + * @return Returns the status code of the execution. + * {@link PREFERENCES_OK} indicates the operation is successful. + * {@link PREFERENCES_ERROR_INVALID_PARAM} indicates invalid args are passed in. + * {@link PREFERENCES_ERROR_STORAGE} indicates an storage error. + * {@link PREFERENCES_ERROR_MALLOC} indicates an malloc memory error. + * @see OH_PreferencesValue. + * @since 13 + */ +int OH_PreferencesValue_GetString(const OH_PreferencesValue *object, char **value, uint32_t *valueLen); +#ifdef __cplusplus +}; +#endif +#endif // OH_PREFERENCES_VALUE_H \ No newline at end of file diff --git a/distributeddatamgr/preferences/libpreferences.ndk.json b/distributeddatamgr/preferences/libpreferences.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..9c41566f528e86b05404777fa5528a6c277090af --- /dev/null +++ b/distributeddatamgr/preferences/libpreferences.ndk.json @@ -0,0 +1,94 @@ +[ + { + "first_introduced": "13", + "name": "OH_Preferences_Open" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_Close" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_GetInt" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_GetBool" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_GetString" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_FreeString" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_SetInt" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_SetBool" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_SetString" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_Delete" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_RegisterDataObserver" + }, + { + "first_introduced": "13", + "name": "OH_Preferences_UnregisterDataObserver" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesOption_Create" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesOption_SetFileName" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesOption_SetBundleName" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesOption_SetDataGroupId" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesOption_Destroy" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesPair_GetKey" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesPair_GetPreferencesValue" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesValue_GetValueType" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesValue_GetInt" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesValue_GetBool" + }, + { + "first_introduced": "13", + "name": "OH_PreferencesValue_GetString" + } +] \ No newline at end of file