1
#include "gego_global_notify.h"
3
static GegoGlobalNotify * _gego_global_notify_instance = NULL;
5
#define GEGO_GLOBAL_NOTIFY_GET_PRIVATE(o)\
6
G_TYPE_INSTANCE_GET_PRIVATE (o, GEGO_TYPE_GLOBEL_NOTIFY, GegoGlobalNotifyPrivate)
9
* section: gego_global_notify
10
* @title: GegoGlobalNotify
11
* @short_description: subscriber based application wide notifications.
13
* The #GegoGlobalNotify tries to solve a probrem that occurs in many peaces of
14
* software: How to notify many parts, or components, of changes, or how to
15
* send information from one part of a program to many other parts the same
21
* @short_description: aoeu
25
////////////////////////////////////////////////////////////////////////////////
27
struct GegoGlobalNotifyPrivate {
28
/* <--- private ---> */
29
GHashTable * hash_table; /* GHashTable<gchar *><GLinkedList<GegoGlobalNotifyCallbackItem*>*>* */
33
struct GegoCallbackItem {
34
/* <--- private ---> */
35
guint subscription_id;
37
gpointer subscriber_data;
41
G_DEFINE_TYPE_WITH_PRIVATE (GegoGlobalNotify, gego_global_notify, G_TYPE_OBJECT);
44
gego_global_notify_new (void) {
45
GegoGlobalNotify * self = g_object_new (GEGO_TYPE_GLOBEL_NOTIFY, NULL, NULL);
52
gego_global_notify_constructor (GType gtype,
54
GObjectConstructParam * properties) {
55
static GObject * self = NULL;
59
self = G_OBJECT_CLASS (gego_global_notify_parent_class
60
)->constructor (gtype, n_properties, properties);
61
g_object_add_weak_pointer (G_OBJECT (self), (gpointer) &self);
62
return G_OBJECT (self);
65
return g_object_ref (G_OBJECT (self));
69
gego_global_notify_class_init (GegoGlobalNotifyClass * klass) {
70
GObjectClass * object_class = G_OBJECT_CLASS (klass);
72
object_class->constructor = gego_global_notify_constructor;
79
gego_global_notify_init (GegoGlobalNotify * self) {
81
GegoGlobalNotifyPrivate * priv = GEGO_GLOBAL_NOTIFY_GET_PRIVATE (self);
83
/* Note that the hash table should contain linked lists of
84
* GegoGlobalNotifyCallbackItems.
86
* GHashTable<gchar *><GLinkedList<GegoGlobalNotifyCallbackItem *> *>*
88
priv->hash_table = g_hash_table_new (g_str_hash, g_str_equal);
92
////////////////////////////////////////////////////////////////////////////////
95
* gego_global_notify_initalize:
96
* @short_description: Should be run at the start of the program.
98
* @err: (allow-none): NULL'ed errer to be passed to function.
101
gego_global_notify_initalize (GError * err) {
102
if (_gego_global_notify_instance != NULL) {
103
err = g_error_new (GEGO_GLOBAL_NOTIFY_ERROR,
104
GEGO_GLOBAL_NOTIFY_ERROR_ALREADY_INITALIZED,
105
"The Global Notify system is already initialized.");
108
_gego_global_notify_instance = gego_global_notify_new ();
112
* gego_global_notify_unsubscribe:
113
* @short_description: Sholud only be run when the program quits.
115
* Calling callbacks after this point is an undefined behaviour.
117
* @err: (allow-none):NULL'ed errer to be passed to function.
120
gego_global_notify_uninitalize (GError * err) {
121
g_object_unref (_gego_global_notify_instance);
125
* gego_global_notify_add_notification:
127
* Add a notifications to the system.
129
* @name The name of the notification to be added.
130
* @err: (allow-none):NULL'ed errer to be passed to function.
132
* return: GUI for that callbacks. negative value on fail.
135
gego_global_notify_add_notification (gchar * name, GError * err) {
140
* gego_global_notify_remove_notification:
141
* @short_description: removes a notification from the system.
144
* @name: The name of the notification to be removed from the system.
145
* @notification_id: The notification ID that was given when the notification
146
* was added to the system.
147
* @err: (allow-none):A NULL'ed error to be passed to the...
150
gego_global_notify_remove_notification (gchar * name,
151
gint notification_id,
157
* gego_global_notify_subscribe:
158
* @short_description: hook up a callback to a signal name.
160
* @name: The name of the callback to attash to.
161
* @callback: the callback to hookup to the signal.
164
* This function is used to hook up a callback to a globla signal. It is
165
* is recomended to save the retuned value for when a callback should be
166
* unsubscribed to, using the gego_global_notify_unsubscribe() function.
168
* Here is an example of a callback.
169
* \[<!-- language="C" -->
173
* returns: the subscription id of the signal.
176
gego_global_notify_subscribe (gchar * name, GCallback callback, gpointer subscriber_data, GError * err);
179
* gego_global_notify_unsubscribe:
180
* @short_description: removes a callback from a
183
gego_global_notify_unsubscribe (gchar * name, gint subscription_id, GError * err);
186
gego_global_notify_call (gchar * name, gpointer caller_data, GError * err);
189
* gego_global_notify_is_initialized:
190
* @short_description: Check if Global Notify is initialized.
192
* return: #TRUE if Global Notify is initialized, otherwise #FALSE
195
gego_global_notify_is_initialized (void);
198
* gego_global_notify_error_quark: (skip)
201
gego_global_notify_error_quark (void) {
202
return g_quark_from_static_string ("gego-global-notify-error-quark");