Notification API. More...
#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "notify.h"
#include "logging2.h"
#include "memory.h"
#include "notify_type.h"
#include "observer.h"
#include "queue.h"
Go to the source code of this file.
Data Structures | |
struct | Notify |
Notification API. More... | |
Functions | |
struct Notify * | notify_new (void) |
Create a new notifications handler. | |
void | notify_free (struct Notify **ptr) |
Free a notification handler. | |
void | notify_set_parent (struct Notify *notify, struct Notify *parent) |
Set the parent notification handler. | |
static bool | send (struct Notify *source, struct Notify *current, enum NotifyType event_type, int event_subtype, void *event_data) |
Send out a notification message. | |
bool | notify_send (struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data) |
Send out a notification message. | |
bool | notify_observer_add (struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data) |
Add an observer to an object. | |
bool | notify_observer_remove (struct Notify *notify, const observer_t callback, const void *global_data) |
Remove an observer from an object. | |
void | notify_observer_remove_all (struct Notify *notify) |
Remove all the observers from an object. | |
Variables | |
static const char * | NotifyTypeNames [] |
Lookup table for NotifyType Must be the same size and order as NotifyType. | |
Notification API.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file notify.c.
struct Notify * notify_new | ( | void | ) |
Create a new notifications handler.
ptr | New notification handler |
Definition at line 62 of file notify.c.
void notify_free | ( | struct Notify ** | ptr | ) |
Free a notification handler.
ptr | Notification handler to free |
Definition at line 75 of file notify.c.
Set the parent notification handler.
notify | Notification handler to alter |
parent | Parent notification handler |
Notifications are passed up the tree of handlers.
Definition at line 95 of file notify.c.
|
static |
Send out a notification message.
source | Source of the event, e.g. Account |
current | Current handler, e.g. NeoMutt |
event_type | Type of event, e.g. NT_ACCOUNT |
event_subtype | Subtype, e.g. NT_ACCOUNT_ADD |
event_data | Private data associated with the event type |
true | Successfully sent |
Notifications are sent to all observers of the object, then propagated up the handler tree. For example a "new email" notification would be sent to the Mailbox that owns it, the Account (owning the Mailbox) and finally the NeoMutt object.
notify_observer_remove()
, then we garbage-collect any dead list entries after we've finished. Definition at line 120 of file notify.c.
bool notify_send | ( | struct Notify * | notify, |
enum NotifyType | event_type, | ||
int | event_subtype, | ||
void * | event_data | ||
) |
Send out a notification message.
notify | Notification handler |
event_type | Type of event, e.g. NT_ACCOUNT |
event_subtype | Subtype, e.g. NT_ACCOUNT_ADD |
event_data | Private data associated with the event |
true | Successfully sent |
See send() for more details.
Definition at line 173 of file notify.c.
bool notify_observer_add | ( | struct Notify * | notify, |
enum NotifyType | type, | ||
observer_t | callback, | ||
void * | global_data | ||
) |
Add an observer to an object.
notify | Notification handler |
type | Notification type to observe, e.g. NT_WINDOW |
callback | Function to call on a matching event, see observer_t |
global_data | Private data associated with the observer |
true | Successful |
New observers are added to the front of the list, giving them higher priority than existing observers.
Definition at line 191 of file notify.c.
bool notify_observer_remove | ( | struct Notify * | notify, |
const observer_t | callback, | ||
const void * | global_data | ||
) |
Remove an observer from an object.
notify | Notification handler |
callback | Function to call on a matching event, see observer_t |
global_data | Private data to match specific callback |
true | Successful |
send()
is present higher up the call stack, removing multiple entries from the list will cause it to crash. Definition at line 230 of file notify.c.
void notify_observer_remove_all | ( | struct Notify * | notify | ) |
|
static |
Lookup table for NotifyType Must be the same size and order as NotifyType.