Skip to content

Commit

Permalink
Add a few default close callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorny committed Aug 29, 2011
1 parent eefd233 commit 666ecc5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/libtinynotify-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ NOTIFICATION_CLOSED_BY_CALLER
NOTIFICATION_CLOSED_BY_EXPIRATION
NOTIFICATION_CLOSED_BY_USER
NotificationCloseCallback
NOTIFICATION_FREE_ON_CLOSE
NOTIFICATION_NOOP_ON_CLOSE
notification_bind_close_callback
NotifyDispatchStatus
NOTIFY_DISPATCH_DONE
Expand Down
10 changes: 10 additions & 0 deletions lib/tinynotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ const NotifyCloseReason NOTIFICATION_CLOSED_BY_EXPIRATION = 'E';
const NotifyCloseReason NOTIFICATION_CLOSED_BY_USER = 'U';
const NotifyCloseReason NOTIFICATION_CLOSED_BY_CALLER = 'C';

static void _notification_noop_on_close(Notification n, NotifyCloseReason r, void* user_data) {
}

static void _notification_free_on_close(Notification n, NotifyCloseReason r, void* user_data) {
notification_free(n);
}

const NotificationCloseCallback NOTIFICATION_NOOP_ON_CLOSE = _notification_noop_on_close;
const NotificationCloseCallback NOTIFICATION_FREE_ON_CLOSE = _notification_free_on_close;

void notification_bind_close_callback(Notification n,
NotificationCloseCallback callback, void* user_data) {
n->close_callback = callback;
Expand Down
22 changes: 22 additions & 0 deletions lib/tinynotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,28 @@ extern const NotifyCloseReason NOTIFICATION_CLOSED_BY_CALLER;
typedef void (*NotificationCloseCallback)(Notification notification,
NotifyCloseReason close_reason, void* user_data);

/**
* NOTIFICATION_NOOP_ON_CLOSE
*
* A dummy callback function for notification_bind_close_callback(). It may be
* used if one isn't interested in the notification being closed itself but
* just wants notify_session_dispatch() to block until all notifications are
* closed.
*/
extern const NotificationCloseCallback NOTIFICATION_NOOP_ON_CLOSE;

/**
* NOTIFICATION_FREE_ON_CLOSE
*
* A callback function for notification_bind_close_callback() which frees
* #Notification as soon as it's closed.
*
* Note: when using this callback, one must not use the same #Notification
* after sending it for the first time as it will become invalid at a random
* point in time.
*/
extern const NotificationCloseCallback NOTIFICATION_FREE_ON_CLOSE;

/**
* notification_bind_close_callback
* @notification: notification to operate on
Expand Down

0 comments on commit 666ecc5

Please sign in to comment.