Couchbase Lite C
Couchbase Lite C API
|
Every API function that registers a listener callback returns an opaque token representing the registered callback. More...
Typedefs | |
typedef struct CBLListenerToken | CBLListenerToken |
An opaque 'cookie' representing a registered listener callback. More... | |
Functions | |
void | CBLListener_Remove (CBLListenerToken *_cbl_nullable) |
Removes a listener callback, given the token that was returned when it was added. More... | |
Scheduling notifications | |
Applications may want control over when Couchbase Lite notifications (listener callbacks) happen. They may want them called on a specific thread, or at certain times during an event loop. This behavior may vary by database, if for instance each database is associated with a separate thread. The API calls here enable this. When notifications are "buffered" for a database, calls to listeners will be deferred until the application explicitly allows them. Instead, a single callback will be issued when the first notification becomes available; this gives the app a chance to schedule a time when the notifications should be sent and callbacks called. | |
typedef void(* | CBLNotificationsReadyCallback) (void *_cbl_nullable context, CBLDatabase *db) |
Callback indicating that the database (or an object belonging to it) is ready to call one or more listeners. More... | |
void | CBLDatabase_BufferNotifications (CBLDatabase *db, CBLNotificationsReadyCallback _cbl_nullable callback, void *_cbl_nullable context) |
Switches the database to buffered-notification mode. More... | |
void | CBLDatabase_SendNotifications (CBLDatabase *db) |
Immediately issues all pending notifications for this database, by calling their listener callbacks. More... | |
Every API function that registers a listener callback returns an opaque token representing the registered callback.
To unregister any type of listener, call CBLListener_Remove.
The steps to creating a listener are:
void*
that points to your contextual information, so cast that to the actual pointer type.AddListener
function.typedef struct CBLListenerToken CBLListenerToken |
An opaque 'cookie' representing a registered listener callback.
It's returned from functions that register listeners, and used to remove a listener by calling CBLListener_Remove.
typedef void(* CBLNotificationsReadyCallback) (void *_cbl_nullable context, CBLDatabase *db) |
Callback indicating that the database (or an object belonging to it) is ready to call one or more listeners.
You should call CBLDatabase_SendNotifications at your earliest convenience, in the context (thread, dispatch queue, etc.) you want them to run.
void CBLDatabase_BufferNotifications | ( | CBLDatabase * | db, |
CBLNotificationsReadyCallback _cbl_nullable | callback, | ||
void *_cbl_nullable | context | ||
) |
Switches the database to buffered-notification mode.
Notifications for objects belonging to this database (documents, queries, replicators, and of course the database) will not be called immediately; your CBLNotificationsReadyCallback will be called instead.
db | The database whose notifications are to be buffered. |
callback | The function to be called when a notification is available. |
context | An arbitrary value that will be passed to the callback. |
void CBLDatabase_SendNotifications | ( | CBLDatabase * | db | ) |
Immediately issues all pending notifications for this database, by calling their listener callbacks.
void CBLListener_Remove | ( | CBLListenerToken * | _cbl_nullable | ) |
Removes a listener callback, given the token that was returned when it was added.