From abcda323591c93df201d7ace5688741c3425fb2a Mon Sep 17 00:00:00 2001 From: renjiecui Date: Thu, 2 Nov 2023 19:44:30 +0800 Subject: [PATCH] add Signed-off-by: renjiecui --- .../relational_store/include/oh_cursor.h | 13 ++ .../include/relational_store.h | 137 ++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/distributeddatamgr/relational_store/include/oh_cursor.h b/distributeddatamgr/relational_store/include/oh_cursor.h index 02e9549b3..daabd912c 100644 --- a/distributeddatamgr/relational_store/include/oh_cursor.h +++ b/distributeddatamgr/relational_store/include/oh_cursor.h @@ -285,6 +285,19 @@ typedef struct OH_Cursor { * @since 11 */ int (*getAssets)(OH_Cursor *cursor, int32_t columnIndex, Data_Asset **value, uint32_t *length); + + /** + * @brief Function pointer. Obtains the count of the {@Data_Asset} in the given column. + * + * @param cursor Represents a pointer to an {@link OH_Cursor} instance. + * @param columnIndex Indicates the zero-based column index. + * @param count Indicates the count of the assets int the column. + * @return Returns the status code of the execution. + * @see OH_Cursor. + * @since 11 + */ + int (*getAssetsCount)(OH_Cursor *cursor, int32_t columnIndex, uint32_t *count); + } OH_Cursor; #ifdef __cplusplus diff --git a/distributeddatamgr/relational_store/include/relational_store.h b/distributeddatamgr/relational_store/include/relational_store.h index f32c252d8..f770901eb 100644 --- a/distributeddatamgr/relational_store/include/relational_store.h +++ b/distributeddatamgr/relational_store/include/relational_store.h @@ -556,6 +556,90 @@ typedef enum Rdb_SubscribeType { RDB_SUBSCRIBE_TYPE_CLOUD_DETAILS, } Rdb_SubscribeType; +/** + * @brief The callback function of cloud data change event. + * + * @param context Represents the context of data observer. + * @param values Indicates the cloud accounts that changed. + * @param count The count of changed cloud accounts. + * @see OH_VObject. + * @since 11 + */ +typedef void (*Rdb_BriefObserver)(void *context, const char *values[], uint32_t count); + +/** + * @brief The callback function of cloud data change details event. + * + * @param context Represents the context of data observer. + * @param changeInfo Indicates the {@link Rdb_ChangeInfo} of changed tables. + * @param count The count of changed tables. + * @see Rdb_ChangeInfo. + * @since 11 + */ +typedef void (*Rdb_DetailsObserver)(void *context, const Rdb_ChangeInfo **changeInfo, uint32_t count); + +/** + * @brief Indicates the callback functions. + * + * @since 11 + */ +typedef union Rdb_SubscribeCallback { + /** + * The callback function of cloud data change details event. + */ + Rdb_DetailsObserver detailsObserver; + + /** + * The callback function of cloud data change event. + */ + Rdb_BriefObserver briefObserver; +} Rdb_SubscribeCallback; + +/** + * @brief Indicates the observer of data. + * + * @since 11 + */ +typedef struct Rdb_DataObserver { + /** + * The context of data observer. + */ + void *context; + + /** + * The callback of data observer. + */ + Rdb_SubscribeCallback callback; +} Rdb_DataObserver; + +/** + * @brief Registers an observer for the database. + * When data in the distributed database changes, the callback will be invoked. + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param type Indicates the subscription type, which is defined in {@link Rdb_SubscribeType}. + * @param observer The {@link Rdb_DataObserver} of change events in the database. + * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. + * @see OH_Rdb_Store. + * @see Rdb_DataObserver. + * @since 11 + */ +int OH_Rdb_Subscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer); + +/** + * @brief Remove specified observer of specified type from the database. + * + * @param store Represents a pointer to an {@link OH_Rdb_Store} instance. + * @param type Indicates the subscription type, which is defined in {@link Rdb_SubscribeType}. + * @param observer The {@link Rdb_DataObserver} of change events in the database. + * If this is nullptr, remove all observers of the type. + * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. + * @see OH_Rdb_Store. + * @see Rdb_DataObserver. + * @since 11 + */ +int OH_Rdb_Unsubscribe(OH_Rdb_Store *store, Rdb_SubscribeType type, const Rdb_DataObserver *observer); + /** * @brief Indicates the database synchronization mode. * @@ -737,6 +821,15 @@ typedef struct Rdb_ProgressDetails { */ Rdb_TableDetails *OH_Rdb_GetTableDetails(Rdb_ProgressDetails *progress, int32_t version); +/** + * @brief The callback function of progress. + * + * @param progressDetails The details of the sync progress. + * @see Rdb_ProgressDetails. + * @since 11 + */ +typedef void (*Rdb_ProgressCallback)(void *context, Rdb_ProgressDetails *progressDetails); + /** * @brief The callback function of sync. * @@ -746,6 +839,23 @@ Rdb_TableDetails *OH_Rdb_GetTableDetails(Rdb_ProgressDetails *progress, int32_t */ typedef void (*Rdb_SyncCallback)(Rdb_ProgressDetails *progressDetails); +/** + * @brief The observer of progress. + * + * @since 11 + */ +typedef struct Rdb_ProgressObserver { + /** + * The context of progress observer. + */ + void *context; + + /** + * The callback function of progress observer. + */ + Rdb_ProgressCallback callback; +} Rdb_ProgressObserver; + /** * @brief Sync data to cloud. * @@ -761,6 +871,33 @@ typedef void (*Rdb_SyncCallback)(Rdb_ProgressDetails *progressDetails); */ int OH_Rdb_CloudSync(OH_Rdb_Store *store, Rdb_SyncMode mode, const char *tables[], uint32_t count, Rdb_SyncCallback *callback); + +/** + * @brief Subscribes to the automatic synchronization progress of an RDB store. + * A callback will be invoked when there is a notification of the automatic synchronization progress. + * + * @param store Indicates the pointer to the target {@Link OH_Rdb_Store} instance. + * @param observer The {@link Rdb_ProgressObserver} for the automatic synchornizaiton progress. + * Indicates the callback invoked to return the automatic synchronization progress. + * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. + * @see OH_Rdb_Store. + * @see Rdb_ProgressObserver. + * @since 11 + */ +int OH_Rdb_SubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer); + +/** + * @brief Unsubscribes from the automatic synchronziation progress of an RDB store. + * + * @param store Indicates the pointer to the target {@Link OH_Rdb_Store} instance. + * @param observer Indicates the {@link Rdb_ProgressObserver} callback for the automatic synchornizaiton progress. + * If it is a null pointer, all callbacks for the automatic synchornizaiton progress will be unregistered. + * @return Returns the status code of the execution. See {@link OH_Rdb_ErrCode}. + * @see OH_Rdb_Store. + * @see Rdb_ProgressObserver. + * @since 11 + */ +int OH_Rdb_UnsubscribeAutoSyncProgress(OH_Rdb_Store *store, const Rdb_ProgressObserver *observer); #ifdef __cplusplus }; #endif -- Gitee