PebbleOS
Loading...
Searching...
No Matches
Functions
Notification storage

Flash storage for received notifications. More...

Functions

void notification_storage_init (void)
 Initialize storage, discarding all stored notifications.
 
void notification_storage_lock (void)
 Lock the storage mutex (recursive).
 
void notification_storage_unlock (void)
 Unlock the storage mutex.
 
void notification_storage_store (TimelineItem *notification)
 Store a notification.
 
bool notification_storage_notification_exists (const Uuid *id)
 Check whether a notification is stored, including one marked deleted.
 
size_t notification_storage_get_len (const Uuid *uuid)
 Get the serialized size of a stored notification.
 
bool notification_storage_get (const Uuid *id, TimelineItem *item_out)
 Read a notification from storage.
 
void notification_storage_set_status (const Uuid *id, uint8_t status)
 Set the status of a stored notification.
 
bool notification_storage_get_status (const Uuid *id, uint8_t *status)
 Get the status of a stored notification.
 
void notification_storage_remove (const Uuid *id)
 Remove a notification by marking it deleted.
 
bool notification_storage_find_ancs_notification_id (uint32_t ancs_uid, Uuid *uuid_out)
 Find the most recent notification with an ANCS UID.
 
bool notification_storage_find_ancs_notification_by_timestamp (TimelineItem *notification, CommonTimelineItemHeader *header_out)
 Find a stored notification identical to a given one.
 
void notification_storage_iterate (bool(*iter_callback)(void *data, SerializedTimelineItemHeader *header_id), void *data)
 Iterate over the headers of all notifications not marked deleted.
 
void notification_storage_iterate_strings_after (time_t item_cutoff, AttributeList *attr_list, size_t buffer_size, bool(*iter_callback)(void *data, const CommonTimelineItemHeader *header, const TimelineItem *item), void *data)
 Iterate over all notifications, reading selected string attributes of recent ones.
 
void notification_storage_rewrite (void(*iter_callback)(TimelineItem *notification, SerializedTimelineItemHeader *header, void *data), void *data)
 Rewrite all notifications through a callback.
 
void notification_storage_reset_and_init (void)
 Discard all notifications and reset the storage state.
 

Detailed Description

Flash storage for received notifications.

Notifications are appended to a single file as a SerializedTimelineItemHeader followed by the serialized attributes and actions. Removing a notification only marks it deleted; deleted entries are dropped when the file is compacted, and the oldest notifications are deleted when the file is full. The file is wiped at boot.

Every function takes the storage mutex, which is recursive; use notification_storage_lock() to group several calls.

Function Documentation

◆ notification_storage_find_ancs_notification_by_timestamp()

bool notification_storage_find_ancs_notification_by_timestamp ( TimelineItem *  notification,
CommonTimelineItemHeader *  header_out 
)

Find a stored notification identical to a given one.

Matches the timestamp, layout and serialized attributes and actions.

Parameters
notificationNotification to match.
[out]header_outHeader of the matching notification.
Returns
true if a match was found.

◆ notification_storage_find_ancs_notification_id()

bool notification_storage_find_ancs_notification_id ( uint32_t  ancs_uid,
Uuid *  uuid_out 
)

Find the most recent notification with an ANCS UID.

iOS can reuse ANCS UIDs after a reconnection, so the newest match wins.

Parameters
ancs_uidANCS UID to look for.
[out]uuid_outId of the matching notification.
Returns
true if found.

◆ notification_storage_get()

bool notification_storage_get ( const Uuid *  id,
TimelineItem *  item_out 
)

Read a notification from storage.

Parameters
idNotification id.
[out]item_outNotification. Its allocated_buffer comes from the calling task's heap and must be freed with timeline_item_free_allocated_buffer().
Returns
true on success, false if not found or unreadable.

◆ notification_storage_get_len()

size_t notification_storage_get_len ( const Uuid *  uuid)

Get the serialized size of a stored notification.

Parameters
uuidNotification id.
Returns
Size of the header and payload in bytes, 0 if not found.

◆ notification_storage_get_status()

bool notification_storage_get_status ( const Uuid *  id,
uint8_t *  status 
)

Get the status of a stored notification.

Parameters
idNotification id.
[out]statusStatus, a combination of TimelineItemStatus flags.
Returns
true if found and not marked deleted.

◆ notification_storage_init()

void notification_storage_init ( void  )

Initialize storage, discarding all stored notifications.

◆ notification_storage_iterate()

void notification_storage_iterate ( bool(*)(void *data, SerializedTimelineItemHeader *header_id)  iter_callback,
void *  data 
)

Iterate over the headers of all notifications not marked deleted.

Do not call other notification storage functions from iter_callback; doing so corrupts storage.

Parameters
iter_callbackCalled with data and each header; return false to stop.
dataContext for iter_callback.

◆ notification_storage_iterate_strings_after()

void notification_storage_iterate_strings_after ( time_t  item_cutoff,
AttributeList *  attr_list,
size_t  buffer_size,
bool(*)(void *data, const CommonTimelineItemHeader *header, const TimelineItem *item)  iter_callback,
void *  data 
)

Iterate over all notifications, reading selected string attributes of recent ones.

For notifications with a timestamp at or after item_cutoff, the string attributes listed in attr_list are read into their cstring buffers (buffer_size bytes each, empty when absent) without deserializing or allocating the payload, and the callback gets an item carrying the header and that list. Older notifications get a NULL item. Corrupt and deleted entries are skipped. Callback arguments are only valid during the callback.

Do not call other notification storage functions from iter_callback.

Parameters
item_cutoffOldest timestamp for which strings are read.
attr_listString attributes to read; each cstring points to a buffer of buffer_size.
buffer_sizeSize of each string buffer in bytes, including the terminator.
iter_callbackCalled with data, the header and the item or NULL; return false to stop.
dataContext for iter_callback.

◆ notification_storage_lock()

void notification_storage_lock ( void  )

Lock the storage mutex (recursive).

◆ notification_storage_notification_exists()

bool notification_storage_notification_exists ( const Uuid *  id)

Check whether a notification is stored, including one marked deleted.

Parameters
idNotification id.
Returns
true if found.

◆ notification_storage_remove()

void notification_storage_remove ( const Uuid *  id)

Remove a notification by marking it deleted.

Parameters
idNotification id.

◆ notification_storage_reset_and_init()

void notification_storage_reset_and_init ( void  )

Discard all notifications and reset the storage state.

◆ notification_storage_rewrite()

void notification_storage_rewrite ( void(*)(TimelineItem *notification, SerializedTimelineItemHeader *header, void *data)  iter_callback,
void *  data 
)

Rewrite all notifications through a callback.

Each notification not marked deleted is deserialized, passed to iter_callback, and written to a new file along with its header, so changes made by the callback are persisted. Deleted entries are dropped.

Parameters
iter_callbackCalled with each notification, its header and data.
dataContext for iter_callback.

◆ notification_storage_set_status()

void notification_storage_set_status ( const Uuid *  id,
uint8_t  status 
)

Set the status of a stored notification.

Parameters
idNotification id.
statusNew status, a combination of TimelineItemStatus flags.

◆ notification_storage_store()

void notification_storage_store ( TimelineItem *  notification)

Store a notification.

Storage is compacted, deleting the oldest notifications if needed, when the file is full. On a write error all notifications are discarded.

Parameters
notificationNotification to store; it is serialized, the caller keeps ownership.

◆ notification_storage_unlock()

void notification_storage_unlock ( void  )

Unlock the storage mutex.