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 DATA_ASSET_H 17 #define DATA_ASSET_H 18 /** 19 * @addtogroup RDB 20 * @{ 21 * 22 * @brief The relational database (RDB) store manages data based on relational models. 23 * With the underlying SQLite database, the RDB store provides a complete mechanism for managing local databases. 24 * To satisfy different needs in complicated scenarios, the RDB store offers a series of APIs for performing operations 25 * such as adding, deleting, modifying, and querying data, and supports direct execution of SQL statements. 26 * 27 * @since 11 28 */ 29 30 /** 31 * @file data_asset.h 32 * 33 * @brief Provides the data type of asset. 34 * @library libnative_rdb_ndk.z.so 35 * @syscap SystemCapability.DistributedDataManager.RelationalStore.Core 36 * @since 11 37 */ 38 #include <cstddef> 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 /** 43 * @brief Describes the status of asset. 44 * 45 * @since 11 46 */ 47 typedef enum Data_AssetStatus { 48 /** 49 * @brief Means the status of asset is null. 50 */ 51 ASSET_NULL = 0, 52 53 /** 54 * @brief Means the status of asset is normal. 55 */ 56 ASSET_NORMAL, 57 58 /** 59 * @brief Means the asset needs to be inserted. 60 */ 61 ASSET_INSERT, 62 63 /** 64 * @brief Means the asset needs to be updated. 65 */ 66 ASSET_UPDATE, 67 68 /** 69 * @brief Means the asset needs to be deleted. 70 */ 71 ASSET_DELETE, 72 73 /** 74 * @brief Means the status of asset is abnormal. 75 */ 76 ASSET_ABNORMAL, 77 78 /** 79 * @brief Means the status of asset is downloading. 80 */ 81 ASSET_DOWNLOADING 82 } Data_AssetStatus; 83 84 /** 85 * @brief Define the Data_Asset structure type. 86 * 87 * Provides information of an asset. 88 * 89 * @since 11 90 */ 91 typedef struct Data_Asset Data_Asset; 92 93 /** 94 * @brief Set the name of the Data_Asset. 95 * 96 * @param asset Represents a pointer to an {@link Data_Asset} instance. 97 * @param name Indicates the name to set. 98 * @return Returns a specific error code. 99 * {@link RDB_OK} - success. 100 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 101 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 102 * @see Data_Asset 103 * @since 11 104 */ 105 int OH_Data_Asset_SetName(Data_Asset *asset, const char *name); 106 107 /** 108 * @brief Set the uri of the Data_Asset. 109 * 110 * @param asset Represents a pointer to an {@link Data_Asset} instance. 111 * @param uri Indicates the uri to set. 112 * @return Returns a specific error code. 113 * {@link RDB_OK} - success. 114 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 115 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 116 * @see Data_Asset 117 * @since 11 118 */ 119 int OH_Data_Asset_SetUri(Data_Asset *asset, const char *uri); 120 121 /** 122 * @brief Set the path of the Data_Asset. 123 * 124 * @param asset Represents a pointer to an {@link Data_Asset} instance. 125 * @param path Indicates the path to set. 126 * @return Returns a specific error code. 127 * {@link RDB_OK} - success. 128 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 129 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 130 * @see Data_Asset 131 * @since 11 132 */ 133 int OH_Data_Asset_SetPath(Data_Asset *asset, const char *path); 134 135 /** 136 * @brief Set the create time of the Data_Asset. 137 * 138 * @param asset Represents a pointer to an {@link Data_Asset} instance. 139 * @param createTime Indicates the create time to set. 140 * @return Returns a specific error code. 141 * {@link RDB_OK} - success. 142 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 143 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 144 * @see Data_Asset 145 * @since 11 146 */ 147 int OH_Data_Asset_SetCreateTime(Data_Asset *asset, int64_t createTime); 148 149 /** 150 * @brief Set the modify time of the Data_Asset. 151 * 152 * @param asset Represents a pointer to an {@link Data_Asset} instance. 153 * @param modifyTime Indicates the create time to set. 154 * @return Returns a specific error code. 155 * {@link RDB_OK} - success. 156 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 157 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 158 * @see Data_Asset 159 * @since 11 160 */ 161 int OH_Data_Asset_SetModifyTime(Data_Asset *asset, int64_t modifyTime); 162 163 /** 164 * @brief Set the size of the Data_Asset. 165 * 166 * @param asset Represents a pointer to an {@link Data_Asset} instance. 167 * @param size Indicates the size to set. 168 * @return Returns a specific error code. 169 * {@link RDB_OK} - success. 170 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 171 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 172 * @see Data_Asset 173 * @since 11 174 */ 175 int OH_Data_Asset_SetSize(Data_Asset *asset, size_t size); 176 177 /** 178 * @brief Set the status of the Data_Asset. 179 * 180 * @param asset Represents a pointer to an {@link Data_Asset} instance. 181 * @param status Indicates the status to set. Specific status can be referenced {@link Data_AssetStatus}. 182 * @return Returns a specific error code. 183 * {@link RDB_OK} - success. 184 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 185 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 186 * @see Data_Asset, Data_AssetStatus 187 * @since 11 188 */ 189 int OH_Data_Asset_SetStatus(Data_Asset *asset, Data_AssetStatus status); 190 191 /** 192 * @brief Obtains the name of the asset. 193 * 194 * @param asset Represents a pointer to an {@link Data_Asset} instance. 195 * @param name This parameter is the output parameter, 196 * and the name of the asset as a char * is written to this variable. 197 * @param length Indicates the length of the name. 198 * @return Returns a specific error code. 199 * {@link RDB_ERR} - Indicates that the function execution exception. 200 * {@link RDB_OK} - success. 201 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 202 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 203 * @see Data_Asset 204 * @since 11 205 */ 206 int OH_Data_Asset_GetName(Data_Asset *asset, char *name, size_t *length); 207 208 /** 209 * @brief Obtains the uri of the asset. 210 * 211 * @param asset Represents a pointer to an {@link Data_Asset} instance. 212 * @param uri This parameter is the output parameter, 213 * and the uri of the asset as a char * is written to this variable. 214 * @param length Indicates the length of the uri. 215 * @return Returns a specific error code. 216 * {@link RDB_ERR} - Indicates that the function execution exception. 217 * {@link RDB_OK} - success. 218 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 219 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 220 * @see Data_Asset 221 * @since 11 222 */ 223 int OH_Data_Asset_GetUri(Data_Asset *asset, char *uri, size_t *length); 224 225 /** 226 * @brief Obtains the path of the asset. 227 * 228 * @param asset Represents a pointer to an {@link Data_Asset} instance. 229 * @param path This parameter is the output parameter, 230 * and the path of the asset as a char * is written to this variable. 231 * @param length Indicates the length of the path. 232 * @return Returns a specific error code. 233 * {@link RDB_ERR} - Indicates that the function execution exception. 234 * {@link RDB_OK} - success. 235 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 236 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 237 * @see Data_Asset 238 * @since 11 239 */ 240 int OH_Data_Asset_GetPath(Data_Asset *asset, char *path, size_t *length); 241 242 /** 243 * @brief Obtains the create time of the asset. 244 * 245 * @param asset Represents a pointer to an {@link Data_Asset} instance. 246 * @param createTime This parameter is the output parameter, 247 * and the create time of the asset as a int64_t is written to this variable. 248 * @return Returns a specific error code. 249 * {@link RDB_ERR} - Indicates that the function execution exception. 250 * {@link RDB_OK} - success. 251 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 252 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 253 * @see Data_Asset 254 * @since 11 255 */ 256 int OH_Data_Asset_GetCreateTime(Data_Asset *asset, int64_t *createTime); 257 258 /** 259 * @brief Obtains the modify time of the asset. 260 * 261 * @param asset Represents a pointer to an {@link Data_Asset} instance. 262 * @param modifyTime This parameter is the output parameter, 263 * and the create time of the asset as a int64_t is written to this variable. 264 * @return Returns a specific error code. 265 * {@link RDB_ERR} - Indicates that the function execution exception. 266 * {@link RDB_OK} - success. 267 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 268 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 269 * @see Data_Asset 270 * @since 11 271 */ 272 int OH_Data_Asset_GetModifyTime(Data_Asset *asset, int64_t *modifyTime); 273 274 /** 275 * @brief Obtains the size of the asset. 276 * 277 * @param asset Represents a pointer to an {@link Data_Asset} instance. 278 * @param size This parameter is the output parameter, 279 * and the size of the asset as a size_t is written to this variable. 280 * @return Returns a specific error code. 281 * {@link RDB_ERR} - Indicates that the function execution exception. 282 * {@link RDB_OK} - success. 283 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 284 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 285 * @see Data_Asset 286 * @since 11 287 */ 288 int OH_Data_Asset_GetSize(Data_Asset *asset, size_t *size); 289 290 /** 291 * @brief Obtains the status of the asset. 292 * 293 * @param asset Represents a pointer to an {@link Data_Asset} instance. 294 * @param status This parameter is the output parameter, 295 * and the size of the status as a {@link Data_AssetStatus} is written to this variable. 296 * @return Returns a specific error code. 297 * {@link RDB_OK} - success. 298 * {@link RDB_E_INVALID_ARGS} - The error code for common invalid args. 299 * Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 300 * @see Data_Asset Data_AssetStatus. 301 * @since 11 302 */ 303 int OH_Data_Asset_GetStatus(Data_Asset *asset, Data_AssetStatus *status); 304 305 /** 306 * @brief Creates an {@link Data_Asset} instance. 307 * 308 * @return If the creation is successful, a pointer to the instance of the @link Data_Asset} structure is returned, 309 * otherwise NULL is returned. 310 * @see Data_Asset. 311 * @since 11 312 */ 313 Data_Asset *OH_Data_Asset_CreateOne(void); 314 315 /** 316 * @brief Destroy the {@link Data_Asset} object and reclaim the memory occupied by the object. 317 * 318 * @param asset Represents a pointer to an {@link Data_Asset} instance. 319 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 320 * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 321 * @see Data_Asset, OH_Rdb_ErrCode. 322 * @since 11 323 */ 324 int OH_Data_Asset_DestroyOne(Data_Asset *asset); 325 326 /** 327 * @brief Creates {@link Data_Asset} instances of given number. 328 * 329 * @param count Represents the count of {@link Data_Asset} to create. 330 * @return If the creation is successful, a pointer to the instance of the {@link Data_Asset} structure is returned. 331 * If the creation is unsuccessful, nullptr is returned. 332 * @see Data_Asset. 333 * @since 11 334 */ 335 Data_Asset **OH_Data_Asset_CreateMultiple(uint32_t count); 336 337 /** 338 * @brief Destroy the {@link Data_Asset} objects and reclaim the memory occupied by the objects. 339 * 340 * @param assets Represents a pointer to an {@link Data_Asset} instance. 341 * @param count Represents the count of {@link Data_Asset} to destroy. 342 * @return Returns the status code of the execution. Successful execution returns RDB_OK, 343 * while failure returns a specific error code. Specific error codes can be referenced {@link OH_Rdb_ErrCode}. 344 * @see Data_Asset, OH_Rdb_ErrCode. 345 * @since 11 346 */ 347 int OH_Data_Asset_DestroyMultiple(Data_Asset **assets, uint32_t count); 348 #ifdef __cplusplus 349 }; 350 #endif 351 #endif // DATA_ASSET_H 352