bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/libgego
1
by Gustav Hartvigsson
* Initial code. |
1 |
#include "gego_global_notify.h" |
2 |
||
3 |
static GegoGlobalNotify * _gego_global_notify_instance = NULL; |
|
4 |
||
10
by Gustav Hartvigsson
* Made it compile again |
5 |
|
1
by Gustav Hartvigsson
* Initial code. |
6 |
#define GEGO_GLOBAL_NOTIFY_GET_PRIVATE(o)\
|
7 |
G_TYPE_INSTANCE_GET_PRIVATE (o, GEGO_TYPE_GLOBEL_NOTIFY, GegoGlobalNotifyPrivate)
|
|
8 |
||
9 |
/**
|
|
10 |
* section: gego_global_notify
|
|
11 |
* @title: GegoGlobalNotify
|
|
12 |
* @short_description: subscriber based application wide notifications.
|
|
13 |
*
|
|
14 |
* The #GegoGlobalNotify tries to solve a probrem that occurs in many peaces of
|
|
15 |
* software: How to notify many parts, or components, of changes, or how to
|
|
16 |
* send information from one part of a program to many other parts the same
|
|
17 |
* program
|
|
18 |
**/
|
|
19 |
||
20 |
/**
|
|
21 |
* GegoGlobalNotify:
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
22 |
* @short_description:
|
23 |
*
|
|
1
by Gustav Hartvigsson
* Initial code. |
24 |
*/
|
25 |
||
26 |
||
27 |
////////////////////////////////////////////////////////////////////////////////
|
|
28 |
||
5
by Gustav Hartvigsson
* Annotate everything! |
29 |
/**
|
30 |
* GegoGlobalNotifyPrivate: (skip)
|
|
31 |
*
|
|
32 |
* @hash_table:
|
|
10
by Gustav Hartvigsson
* Made it compile again |
33 |
* GHashTable<gchar *><GLinkedList<GegoCallbackItem*>*>*
|
5
by Gustav Hartvigsson
* Annotate everything! |
34 |
*/
|
10
by Gustav Hartvigsson
* Made it compile again |
35 |
struct
|
36 |
_GegoGlobalNotifyPrivate { |
|
5
by Gustav Hartvigsson
* Annotate everything! |
37 |
/* < private > */ |
38 |
GHashTable * hash_table; |
|
1
by Gustav Hartvigsson
* Initial code. |
39 |
};
|
40 |
||
5
by Gustav Hartvigsson
* Annotate everything! |
41 |
|
42 |
/**
|
|
43 |
* GegoCallbackItem: (skip)
|
|
44 |
*
|
|
45 |
* @subscription_id: The id of the subscriber.
|
|
46 |
* @key_id: The key id of the callback.
|
|
47 |
* @subscriber_data: The data provided by the subscriber_data.
|
|
48 |
* @callback: The callback to be run.
|
|
49 |
*/
|
|
10
by Gustav Hartvigsson
* Made it compile again |
50 |
struct
|
51 |
_GegoCallbackItem { |
|
5
by Gustav Hartvigsson
* Annotate everything! |
52 |
/* < private > */ |
1
by Gustav Hartvigsson
* Initial code. |
53 |
guint subscription_id; |
54 |
GQuark key_id; |
|
55 |
gpointer subscriber_data; |
|
56 |
GCallback callback; |
|
57 |
};
|
|
58 |
||
16
by Gustav Hartvigsson
* Moved GegoWebApplication out of the way |
59 |
G_DEFINE_TYPE_WITH_PRIVATE (GegoGlobalNotify, gego_global_notify, G_TYPE_OBJECT) |
1
by Gustav Hartvigsson
* Initial code. |
60 |
|
5
by Gustav Hartvigsson
* Annotate everything! |
61 |
/**
|
62 |
* gego_global_notify_new: (skip)
|
|
63 |
*
|
|
64 |
* @void: (skip)
|
|
65 |
*/
|
|
1
by Gustav Hartvigsson
* Initial code. |
66 |
GegoGlobalNotify * |
67 |
gego_global_notify_new (void) { |
|
68 |
GegoGlobalNotify * self = g_object_new (GEGO_TYPE_GLOBEL_NOTIFY, NULL, NULL); |
|
69 |
|
|
70 |
return self; |
|
71 |
}
|
|
72 |
||
73 |
||
5
by Gustav Hartvigsson
* Annotate everything! |
74 |
/**
|
75 |
* gego_global_notify_constructor: (skip)
|
|
76 |
* gtype: (skip)
|
|
77 |
* n_properties: (skip)
|
|
78 |
* properties: (skip)
|
|
79 |
*/
|
|
1
by Gustav Hartvigsson
* Initial code. |
80 |
static GObject * |
81 |
gego_global_notify_constructor (GType gtype, |
|
82 |
guint n_properties, |
|
83 |
GObjectConstructParam * properties) { |
|
84 |
static GObject * self = NULL; |
|
85 |
|
|
86 |
|
|
87 |
if (self == NULL) { |
|
88 |
self = G_OBJECT_CLASS (gego_global_notify_parent_class |
|
89 |
)->constructor (gtype, n_properties, properties); |
|
90 |
g_object_add_weak_pointer (G_OBJECT (self), (gpointer) &self); |
|
91 |
return G_OBJECT (self); |
|
92 |
} |
|
93 |
|
|
94 |
return g_object_ref (G_OBJECT (self)); |
|
95 |
}
|
|
96 |
||
5
by Gustav Hartvigsson
* Annotate everything! |
97 |
/**
|
98 |
* gego_global_notify_class_init: (skip)
|
|
99 |
*
|
|
100 |
* klass: (skip)
|
|
101 |
*/
|
|
1
by Gustav Hartvigsson
* Initial code. |
102 |
static void |
103 |
gego_global_notify_class_init (GegoGlobalNotifyClass * klass) { |
|
104 |
GObjectClass * object_class = G_OBJECT_CLASS (klass); |
|
105 |
|
|
106 |
object_class->constructor = gego_global_notify_constructor; |
|
107 |
|
|
108 |
}
|
|
109 |
||
110 |
||
5
by Gustav Hartvigsson
* Annotate everything! |
111 |
/**
|
112 |
* gego_global_notify_init: (skip)
|
|
113 |
*
|
|
114 |
* @self: (skip)
|
|
115 |
*/
|
|
1
by Gustav Hartvigsson
* Initial code. |
116 |
static void |
117 |
gego_global_notify_init (GegoGlobalNotify * self) { |
|
118 |
|
|
119 |
GegoGlobalNotifyPrivate * priv = GEGO_GLOBAL_NOTIFY_GET_PRIVATE (self); |
|
120 |
|
|
121 |
/* Note that the hash table should contain linked lists of |
|
122 |
* GegoGlobalNotifyCallbackItems.
|
|
123 |
* In template speak:
|
|
124 |
* GHashTable<gchar *><GLinkedList<GegoGlobalNotifyCallbackItem *> *>*
|
|
125 |
*/
|
|
126 |
priv->hash_table = g_hash_table_new (g_str_hash, g_str_equal); |
|
127 |
|
|
128 |
}
|
|
129 |
||
130 |
////////////////////////////////////////////////////////////////////////////////
|
|
131 |
||
132 |
/**
|
|
133 |
* gego_global_notify_initalize:
|
|
134 |
* @short_description: Should be run at the start of the program.
|
|
135 |
*
|
|
136 |
* @err: (allow-none): NULL'ed errer to be passed to function.
|
|
137 |
*/
|
|
138 |
gboolean
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
139 |
gego_global_notify_initalize (GError ** err) { |
1
by Gustav Hartvigsson
* Initial code. |
140 |
if (_gego_global_notify_instance != NULL) { |
4
by Gustav Hartvigsson
* Changed err to the correct type |
141 |
g_set_error (err, GEGO_GLOBAL_NOTIFY_ERROR, |
1
by Gustav Hartvigsson
* Initial code. |
142 |
GEGO_GLOBAL_NOTIFY_ERROR_ALREADY_INITALIZED, |
143 |
"The Global Notify system is already initialized."); |
|
16
by Gustav Hartvigsson
* Moved GegoWebApplication out of the way |
144 |
return FALSE; |
1
by Gustav Hartvigsson
* Initial code. |
145 |
} |
146 |
_gego_global_notify_instance = gego_global_notify_new (); |
|
16
by Gustav Hartvigsson
* Moved GegoWebApplication out of the way |
147 |
return TRUE; |
1
by Gustav Hartvigsson
* Initial code. |
148 |
}
|
149 |
||
150 |
/**
|
|
151 |
* gego_global_notify_unsubscribe:
|
|
152 |
* @short_description: Sholud only be run when the program quits.
|
|
153 |
*
|
|
154 |
* Calling callbacks after this point is an undefined behaviour.
|
|
155 |
*
|
|
156 |
* @err: (allow-none):NULL'ed errer to be passed to function.
|
|
157 |
*/
|
|
158 |
gboolean
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
159 |
gego_global_notify_uninitalize (GError ** err) { |
160 |
gego_global_notify_return_not_initialized(err); |
|
1
by Gustav Hartvigsson
* Initial code. |
161 |
g_object_unref (_gego_global_notify_instance); |
162 |
}
|
|
163 |
||
164 |
/**
|
|
165 |
* gego_global_notify_add_notification:
|
|
166 |
*
|
|
167 |
* Add a notifications to the system.
|
|
168 |
*
|
|
169 |
* @name The name of the notification to be added.
|
|
170 |
* @err: (allow-none):NULL'ed errer to be passed to function.
|
|
171 |
*
|
|
172 |
* return: GUI for that callbacks. negative value on fail.
|
|
173 |
*/
|
|
174 |
gint
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
175 |
gego_global_notify_add_notification (gchar * name, GError ** err) { |
176 |
gego_global_notify_return_not_initialized(err); |
|
177 |
//TODO |
|
1
by Gustav Hartvigsson
* Initial code. |
178 |
return 0; |
179 |
}
|
|
180 |
||
181 |
/**
|
|
182 |
* gego_global_notify_remove_notification:
|
|
183 |
* @short_description: removes a notification from the system.
|
|
184 |
*
|
|
185 |
*
|
|
186 |
* @name: The name of the notification to be removed from the system.
|
|
187 |
* @notification_id: The notification ID that was given when the notification
|
|
188 |
* was added to the system.
|
|
189 |
* @err: (allow-none):A NULL'ed error to be passed to the...
|
|
190 |
*/
|
|
191 |
void
|
|
192 |
gego_global_notify_remove_notification (gchar * name, |
|
193 |
gint notification_id, |
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
194 |
GError ** err) { |
195 |
gego_global_notify_return_not_initialized(err); |
|
196 |
//TODO |
|
1
by Gustav Hartvigsson
* Initial code. |
197 |
}
|
198 |
||
199 |
/**
|
|
200 |
* gego_global_notify_subscribe:
|
|
201 |
* @short_description: hook up a callback to a signal name.
|
|
202 |
*
|
|
203 |
* @name: The name of the callback to attash to.
|
|
204 |
* @callback: the callback to hookup to the signal.
|
|
205 |
*
|
|
206 |
*
|
|
207 |
* This function is used to hook up a callback to a globla signal. It is
|
|
208 |
* is recomended to save the retuned value for when a callback should be
|
|
209 |
* unsubscribed to, using the gego_global_notify_unsubscribe() function.
|
|
210 |
*
|
|
211 |
* Here is an example of a callback.
|
|
212 |
* \[<!-- language="C" -->
|
|
213 |
*
|
|
214 |
* \]
|
|
215 |
*
|
|
216 |
* returns: the subscription id of the signal.
|
|
217 |
*/
|
|
218 |
gint
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
219 |
gego_global_notify_subscribe (gchar * name, |
220 |
GCallback callback, |
|
221 |
gpointer subscriber_data, |
|
222 |
GError ** err) { |
|
223 |
gego_global_notify_return_not_initialized(err); |
|
224 |
// TODO |
|
225 |
}
|
|
1
by Gustav Hartvigsson
* Initial code. |
226 |
|
227 |
/**
|
|
228 |
* gego_global_notify_unsubscribe:
|
|
5
by Gustav Hartvigsson
* Annotate everything! |
229 |
* @short_description: removes a callback from a notify.
|
230 |
*
|
|
231 |
* @name: The name of the notify to unsubscribed to.
|
|
232 |
* @subscription_id: The Subscription ID that was got when the subscription was.
|
|
233 |
* made.
|
|
234 |
* @err: (out)(allow-none): Error to be filled with an error if such has occured.
|
|
1
by Gustav Hartvigsson
* Initial code. |
235 |
*/
|
236 |
void
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
237 |
gego_global_notify_unsubscribe (gchar * name, |
238 |
gint subscription_id, |
|
239 |
GError ** err) { |
|
240 |
gego_global_notify_return_not_initialized(err); |
|
241 |
// TODO |
|
242 |
}
|
|
1
by Gustav Hartvigsson
* Initial code. |
243 |
|
5
by Gustav Hartvigsson
* Annotate everything! |
244 |
/**
|
245 |
* gego_global_notify_call:
|
|
246 |
* @short_description: Calls all subscribers to a notify.
|
|
247 |
*
|
|
248 |
* @name: The name of the notify to call.
|
|
249 |
* @caller_data: The data to be passed to the callback.
|
|
250 |
* @err: (out)(allow-none): Error to be filled with an error if such has occured.
|
|
251 |
*/
|
|
1
by Gustav Hartvigsson
* Initial code. |
252 |
gint
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
253 |
gego_global_notify_call (gchar * name, |
254 |
gpointer caller_data, |
|
255 |
GError ** err) { |
|
256 |
gego_global_notify_return_not_initialized(err); |
|
257 |
// TODO |
|
258 |
}
|
|
1
by Gustav Hartvigsson
* Initial code. |
259 |
|
260 |
/**
|
|
261 |
* gego_global_notify_is_initialized:
|
|
262 |
* @short_description: Check if Global Notify is initialized.
|
|
263 |
*
|
|
264 |
* return: #TRUE if Global Notify is initialized, otherwise #FALSE
|
|
265 |
*/
|
|
266 |
gboolean
|
|
7
by Gustav Hartvigsson
* Fixed build... sort of |
267 |
gego_global_notify_is_initialized (void) { |
4
by Gustav Hartvigsson
* Changed err to the correct type |
268 |
if (_gego_global_notify_instance == 0) { |
269 |
return TRUE; |
|
270 |
} else { |
|
271 |
return FALSE; |
|
272 |
} |
|
273 |
}
|
|
1
by Gustav Hartvigsson
* Initial code. |
274 |
|
275 |
/**
|
|
22
by Gustav Hartvigsson
* Moved remaining Docs into the C file |
276 |
* gego_global_notify_return_not_initialized:
|
277 |
* @short_description: convinience macro; returns with an error if Global Notify
|
|
278 |
* is not initialized.
|
|
279 |
*
|
|
280 |
* @err: (type GError) An #GError to be passed to the macro.
|
|
281 |
*/
|
|
282 |
||
283 |
||
284 |
||
285 |
/**
|
|
1
by Gustav Hartvigsson
* Initial code. |
286 |
* gego_global_notify_error_quark: (skip)
|
287 |
*/
|
|
288 |
GQuark
|
|
7
by Gustav Hartvigsson
* Fixed build... sort of |
289 |
gego_global_notify_error_quark (void) { |
1
by Gustav Hartvigsson
* Initial code. |
290 |
return g_quark_from_static_string ("gego-global-notify-error-quark"); |
291 |
}
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
292 |
|
293 |
/**
|
|
22
by Gustav Hartvigsson
* Moved remaining Docs into the C file |
294 |
* GEGO_GLOBAL_NOTIFY_ERROR:
|
295 |
* @short_description: A convinience wrapper around #gego_global_notify_error_quark()
|
|
296 |
*/
|
|
297 |
||
23
by Gustav Hartvigsson
* Something got lost in translation :P |
298 |
/**
|
299 |
* GegoGlobalNotifyErrorName:
|
|
300 |
* @short_description: Get the name of the error.
|
|
301 |
*/
|
|
22
by Gustav Hartvigsson
* Moved remaining Docs into the C file |
302 |
|
303 |
/**
|
|
4
by Gustav Hartvigsson
* Changed err to the correct type |
304 |
* gego_global_notify_error_get_name:
|
305 |
* @short_description: Get the string name of the #GegoGlobalNotifyError.
|
|
306 |
*
|
|
307 |
* @k: The error to get the name of.
|
|
308 |
*
|
|
309 |
* Anagalius to GegoGlobalNotifyErrorName[k], but included for binding
|
|
310 |
* purposus.
|
|
311 |
*
|
|
312 |
* return: The string containing the name of the error. Or NULL on fail.
|
|
313 |
*/
|
|
314 |
gchar * |
|
315 |
gego_global_notify_error_get_name (GegoGlobalNotifyError k) { |
|
316 |
if (k > GEGO_GLOBAL_NOTIFY_ERROR_LAST) { |
|
317 |
return NULL; |
|
318 |
} |
|
319 |
return GegoGlobalNotifyErrorName[k]; |
|
320 |
}
|