Mercurial > pidgin
comparison src/event.c @ 5205:fefad67de2c7
[gaim-migrate @ 5573]
I had a damn good commit message, but it was eaten. Let's try it again.
Announcing, Gaim Plugin API version 2.0, or GPAPIV2.0 for short.
There are lots'a cool thingies here.
Okay now, this isn't as cool as the previous message, but:
1) There's now a single entry function for all plugin types. It returns a
detailed information structure on the plugin. This removes a lot of the
ugliness from old plugins. Oh yeah, libicq wasn't converted to this, so
if you use it, well, you shouldn't have used it anyway, but now you
can't! bwahahaha. Use AIM/ICQ.
2) There are now 3 types of plugins: Standard, Loader, and Protocol
plugins.
Standard plugins are, well, standard, compiled plugins.
Loader plugins load other plugins. For example, the perl support is now
a loader plugin. It loads perl scripts. In the future, we'll have
Ruby and Python loader plugins.
Protocol plugins are, well, protocol plugins... yeah...
3) Plugins have unique IDs, so they can be referred to or automatically
updated from a plugin database in the future. Neat, huh?
4) Plugins will have dependency support in the future, and can be hidden,
so if you have, say, a logging core plugin, it won't have to show up,
but then you load the GTK+ logging plugin and it'll auto-load the core
plugin. Core/UI split plugins!
5) There will eventually be custom plugin signals and RPC of some sort, for
the core/ui split plugins.
So, okay, back up .gaimrc.
I'd like to thank my parents for their support, javabsp for helping convert
a bunch of protocol plugins, and Etan for helping convert a bunch of
standard plugins.
Have fun. If you have any problems, please let me know, but you probably
won't have anything major happen. You will have to convert your plugins,
though, and I'm not guaranteeing that all perl scripts will still work.
I'll end up changing the perl script API eventually, so I know they won't
down the road. Don't worry, though. It'll be mass cool.
faceprint wants me to just commit the damn code already. So, here we go!!!
..
..
I need a massage. From a young, cute girl. Are there any young, cute girls
in the audience? IM me plz k thx.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Fri, 25 Apr 2003 06:47:33 +0000 |
| parents | |
| children | 0241d6b6702d |
comparison
equal
deleted
inserted
replaced
| 5204:44de70702205 | 5205:fefad67de2c7 |
|---|---|
| 1 /** | |
| 2 * @file event.c Event API | |
| 3 * @ingroup core | |
| 4 * | |
| 5 * gaim | |
| 6 * | |
| 7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License as published by | |
| 11 * the Free Software Foundation; either version 2 of the License, or | |
| 12 * (at your option) any later version. | |
| 13 * | |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 */ | |
| 23 #include "event.h" | |
| 24 | |
| 25 #include <sys/time.h> | |
| 26 #include <stdarg.h> | |
| 27 #include <stdio.h> | |
| 28 #include <string.h> | |
| 29 | |
| 30 /* | |
| 31 * XXX - This is for debug_printf! Move out when debug_printf moved to debug.h | |
| 32 * -- ChipX86 | |
| 33 */ | |
| 34 #include "gaim.h" | |
| 35 | |
| 36 /** | |
| 37 * A signal callback. | |
| 38 */ | |
| 39 typedef struct | |
| 40 { | |
| 41 void *handle; /**< The plugin module handle. */ | |
| 42 GaimEvent event; /**< The event type. */ | |
| 43 void *function; /**< The function to call. */ | |
| 44 void *data; /**< The data to pass to the function. */ | |
| 45 | |
| 46 } GaimSignalCallback; | |
| 47 | |
| 48 /** | |
| 49 * A broadcast function. | |
| 50 */ | |
| 51 typedef struct | |
| 52 { | |
| 53 GaimSignalBroadcastFunc func; | |
| 54 void *data; | |
| 55 | |
| 56 } GaimSignalBroadcaster; | |
| 57 | |
| 58 static GList *callbacks = NULL; | |
| 59 static GList *broadcasters = NULL; | |
| 60 | |
| 61 void | |
| 62 gaim_signal_connect(void *handle, GaimEvent event, | |
| 63 void *func, void *data) | |
| 64 { | |
| 65 GaimSignalCallback *call; | |
| 66 | |
| 67 g_return_if_fail(func != NULL); | |
| 68 | |
| 69 call = g_new0(GaimSignalCallback, 1); | |
| 70 call->handle = handle; | |
| 71 call->event = event; | |
| 72 call->function = func; | |
| 73 call->data = data; | |
| 74 | |
| 75 callbacks = g_list_append(callbacks, call); | |
| 76 | |
| 77 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
| 78 } | |
| 79 | |
| 80 void | |
| 81 gaim_signal_disconnect(void *handle, GaimEvent event, void *func) | |
| 82 { | |
| 83 GList *c, *next_c; | |
| 84 GaimSignalCallback *g = NULL; | |
| 85 | |
| 86 g_return_if_fail(func != NULL); | |
| 87 | |
| 88 for (c = callbacks; c != NULL; c = next_c) { | |
| 89 next_c = c->next; | |
| 90 | |
| 91 g = (GaimSignalCallback *)c->data; | |
| 92 | |
| 93 if (handle == g->handle && func == g->function) { | |
| 94 callbacks = g_list_remove(callbacks, c->data); | |
| 95 g_free(g); | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 void | |
| 101 gaim_signals_disconnect_by_handle(void *handle) | |
| 102 { | |
| 103 GList *c, *c_next; | |
| 104 GaimSignalCallback *g; | |
| 105 | |
| 106 g_return_if_fail(handle != NULL); | |
| 107 | |
| 108 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
| 109 | |
| 110 for (c = callbacks; c != NULL; c = c_next) { | |
| 111 c_next = c->next; | |
| 112 g = (GaimSignalCallback *)c->data; | |
| 113 | |
| 114 if (g->handle == handle) { | |
| 115 callbacks = g_list_remove(callbacks, (gpointer)g); | |
| 116 | |
| 117 debug_printf("Removing callback, %d remain\n", | |
| 118 g_list_length(callbacks)); | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void | |
| 124 gaim_signals_register_broadcast_func(GaimSignalBroadcastFunc func, | |
| 125 void *data) | |
| 126 { | |
| 127 GaimSignalBroadcaster *broadcaster; | |
| 128 | |
| 129 g_return_if_fail(func != NULL); | |
| 130 | |
| 131 broadcaster = g_new0(GaimSignalBroadcaster, 1); | |
| 132 | |
| 133 broadcaster->func = func; | |
| 134 broadcaster->data = data; | |
| 135 | |
| 136 broadcasters = g_list_append(broadcasters, broadcaster); | |
| 137 } | |
| 138 | |
| 139 void | |
| 140 gaim_signals_unregister_broadcast_func(GaimSignalBroadcastFunc func) | |
| 141 { | |
| 142 GList *l; | |
| 143 GaimSignalBroadcaster *broadcaster; | |
| 144 | |
| 145 g_return_if_fail(func != NULL); | |
| 146 | |
| 147 for (l = broadcasters; l != NULL; l = l->next) { | |
| 148 broadcaster = l->data; | |
| 149 | |
| 150 if (broadcaster->func == func) { | |
| 151 broadcasters = g_list_remove(broadcasters, broadcaster); | |
| 152 | |
| 153 g_free(broadcaster); | |
| 154 | |
| 155 break; | |
| 156 } | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 int | |
| 161 gaim_event_broadcast(GaimEvent event, ...) | |
| 162 { | |
| 163 GList *c; | |
| 164 GList *l; | |
| 165 GaimSignalCallback *g; | |
| 166 GaimSignalBroadcaster *broadcaster; | |
| 167 va_list arrg; | |
| 168 void *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL; | |
| 169 | |
| 170 for (c = callbacks; c != NULL; c = c->next) { | |
| 171 void (*cbfunc)(void *, ...); | |
| 172 | |
| 173 g = (GaimSignalCallback *)c->data; | |
| 174 | |
| 175 if (g->event == event && g->function != NULL) { | |
| 176 time_t time; | |
| 177 int id; | |
| 178 cbfunc = g->function; | |
| 179 | |
| 180 va_start(arrg, event); | |
| 181 | |
| 182 switch (event) { | |
| 183 /* no args */ | |
| 184 case event_blist_update: | |
| 185 case event_quit: | |
| 186 cbfunc(g->data); | |
| 187 break; | |
| 188 | |
| 189 /* one arg */ | |
| 190 case event_signon: | |
| 191 case event_signoff: | |
| 192 case event_new_conversation: | |
| 193 case event_del_conversation: | |
| 194 case event_error: | |
| 195 case event_connecting: | |
| 196 arg1 = va_arg(arrg, void *); | |
| 197 cbfunc(arg1, g->data); | |
| 198 break; | |
| 199 | |
| 200 /* two args */ | |
| 201 case event_buddy_signon: | |
| 202 case event_buddy_signoff: | |
| 203 case event_buddy_away: | |
| 204 case event_buddy_back: | |
| 205 case event_buddy_idle: | |
| 206 case event_buddy_unidle: | |
| 207 case event_set_info: | |
| 208 case event_draw_menu: | |
| 209 case event_got_typing: | |
| 210 arg1 = va_arg(arrg, void *); | |
| 211 arg2 = va_arg(arrg, void *); | |
| 212 cbfunc(arg1, arg2, g->data); | |
| 213 break; | |
| 214 | |
| 215 case event_chat_leave: | |
| 216 arg1 = va_arg(arrg, void*); | |
| 217 id = va_arg(arrg, int); | |
| 218 cbfunc(arg1, id, g->data); | |
| 219 break; | |
| 220 | |
| 221 /* three args */ | |
| 222 case event_im_send: | |
| 223 case event_im_displayed_sent: | |
| 224 case event_away: | |
| 225 arg1 = va_arg(arrg, void *); | |
| 226 arg2 = va_arg(arrg, void *); | |
| 227 arg3 = va_arg(arrg, void *); | |
| 228 cbfunc(arg1, arg2, arg3, g->data); | |
| 229 break; | |
| 230 | |
| 231 case event_chat_buddy_join: | |
| 232 case event_chat_buddy_leave: | |
| 233 case event_chat_send: | |
| 234 case event_chat_join: | |
| 235 arg1 = va_arg(arrg, void*); | |
| 236 id = va_arg(arrg, int); | |
| 237 arg3 = va_arg(arrg, void*); | |
| 238 cbfunc(arg1, id, arg3, g->data); | |
| 239 break; | |
| 240 | |
| 241 case event_warned: | |
| 242 arg1 = va_arg(arrg, void*); | |
| 243 arg2 = va_arg(arrg, void*); | |
| 244 id = va_arg(arrg, int); | |
| 245 cbfunc(arg1, arg2, id, g->data); | |
| 246 break; | |
| 247 | |
| 248 /* four args */ | |
| 249 case event_im_recv: | |
| 250 case event_chat_invited: | |
| 251 arg1 = va_arg(arrg, void *); | |
| 252 arg2 = va_arg(arrg, void *); | |
| 253 arg3 = va_arg(arrg, void *); | |
| 254 arg4 = va_arg(arrg, void *); | |
| 255 cbfunc(arg1, arg2, arg3, arg4, g->data); | |
| 256 break; | |
| 257 | |
| 258 case event_chat_recv: | |
| 259 case event_chat_send_invite: | |
| 260 arg1 = va_arg(arrg, void *); | |
| 261 id = va_arg(arrg, int); | |
| 262 | |
| 263 arg3 = va_arg(arrg, void *); | |
| 264 arg4 = va_arg(arrg, void *); | |
| 265 cbfunc(arg1, id, arg3, arg4, g->data); | |
| 266 break; | |
| 267 | |
| 268 /* five args */ | |
| 269 case event_im_displayed_rcvd: | |
| 270 arg1 = va_arg(arrg, void *); | |
| 271 arg2 = va_arg(arrg, void *); | |
| 272 arg3 = va_arg(arrg, void *); | |
| 273 arg4 = va_arg(arrg, void *); | |
| 274 time = va_arg(arrg, time_t); | |
| 275 cbfunc(arg1, arg2, arg3, arg4, time, g->data); | |
| 276 break; | |
| 277 | |
| 278 default: | |
| 279 debug_printf("unknown event %d\n", event); | |
| 280 break; | |
| 281 } | |
| 282 | |
| 283 va_end(arrg); | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 for (l = broadcasters; l != NULL; l = l->next) { | |
| 288 broadcaster = l->data; | |
| 289 | |
| 290 va_start(arrg, event); | |
| 291 broadcaster->func(event, broadcaster->data, arrg); | |
| 292 } | |
| 293 | |
| 294 return 0; | |
| 295 } | |
| 296 | |
| 297 const char * | |
| 298 gaim_event_get_name(GaimEvent event) | |
| 299 { | |
| 300 static char buf[128]; | |
| 301 | |
| 302 switch (event) { | |
| 303 case event_signon: | |
| 304 snprintf(buf, sizeof(buf), "event_signon"); | |
| 305 break; | |
| 306 case event_signoff: | |
| 307 snprintf(buf, sizeof(buf), "event_signoff"); | |
| 308 break; | |
| 309 case event_away: | |
| 310 snprintf(buf, sizeof(buf), "event_away"); | |
| 311 break; | |
| 312 case event_back: | |
| 313 snprintf(buf, sizeof(buf), "event_back"); | |
| 314 break; | |
| 315 case event_im_recv: | |
| 316 snprintf(buf, sizeof(buf), "event_im_recv"); | |
| 317 break; | |
| 318 case event_im_send: | |
| 319 snprintf(buf, sizeof(buf), "event_im_send"); | |
| 320 break; | |
| 321 case event_buddy_signon: | |
| 322 snprintf(buf, sizeof(buf), "event_buddy_signon"); | |
| 323 break; | |
| 324 case event_buddy_signoff: | |
| 325 snprintf(buf, sizeof(buf), "event_buddy_signoff"); | |
| 326 break; | |
| 327 case event_buddy_away: | |
| 328 snprintf(buf, sizeof(buf), "event_buddy_away"); | |
| 329 break; | |
| 330 case event_buddy_back: | |
| 331 snprintf(buf, sizeof(buf), "event_buddy_back"); | |
| 332 break; | |
| 333 case event_buddy_idle: | |
| 334 snprintf(buf, sizeof(buf), "event_buddy_idle"); | |
| 335 break; | |
| 336 case event_buddy_unidle: | |
| 337 snprintf(buf, sizeof(buf), "event_buddy_unidle"); | |
| 338 break; | |
| 339 case event_blist_update: | |
| 340 snprintf(buf, sizeof(buf), "event_blist_update"); | |
| 341 break; | |
| 342 case event_chat_invited: | |
| 343 snprintf(buf, sizeof(buf), "event_chat_invited"); | |
| 344 break; | |
| 345 case event_chat_join: | |
| 346 snprintf(buf, sizeof(buf), "event_chat_join"); | |
| 347 break; | |
| 348 case event_chat_leave: | |
| 349 snprintf(buf, sizeof(buf), "event_chat_leave"); | |
| 350 break; | |
| 351 case event_chat_buddy_join: | |
| 352 snprintf(buf, sizeof(buf), "event_chat_buddy_join"); | |
| 353 break; | |
| 354 case event_chat_buddy_leave: | |
| 355 snprintf(buf, sizeof(buf), "event_chat_buddy_leave"); | |
| 356 break; | |
| 357 case event_chat_recv: | |
| 358 snprintf(buf, sizeof(buf), "event_chat_recv"); | |
| 359 break; | |
| 360 case event_chat_send: | |
| 361 snprintf(buf, sizeof(buf), "event_chat_send"); | |
| 362 break; | |
| 363 case event_warned: | |
| 364 snprintf(buf, sizeof(buf), "event_warned"); | |
| 365 break; | |
| 366 case event_error: | |
| 367 snprintf(buf, sizeof(buf), "event_error"); | |
| 368 break; | |
| 369 case event_quit: | |
| 370 snprintf(buf, sizeof(buf), "event_quit"); | |
| 371 break; | |
| 372 case event_new_conversation: | |
| 373 snprintf(buf, sizeof(buf), "event_new_conversation"); | |
| 374 break; | |
| 375 case event_set_info: | |
| 376 snprintf(buf, sizeof(buf), "event_set_info"); | |
| 377 break; | |
| 378 case event_draw_menu: | |
| 379 snprintf(buf, sizeof(buf), "event_draw_menu"); | |
| 380 break; | |
| 381 case event_im_displayed_sent: | |
| 382 snprintf(buf, sizeof(buf), "event_im_displayed_sent"); | |
| 383 break; | |
| 384 case event_im_displayed_rcvd: | |
| 385 snprintf(buf, sizeof(buf), "event_im_displayed_rcvd"); | |
| 386 break; | |
| 387 case event_chat_send_invite: | |
| 388 snprintf(buf, sizeof(buf), "event_chat_send_invite"); | |
| 389 break; | |
| 390 case event_got_typing: | |
| 391 snprintf(buf, sizeof(buf), "event_got_typing"); | |
| 392 break; | |
| 393 case event_del_conversation: | |
| 394 snprintf(buf, sizeof(buf), "event_del_conversation"); | |
| 395 break; | |
| 396 case event_connecting: | |
| 397 snprintf(buf, sizeof(buf), "event_connecting"); | |
| 398 break; | |
| 399 default: | |
| 400 snprintf(buf, sizeof(buf), "event_unknown"); | |
| 401 break; | |
| 402 } | |
| 403 | |
| 404 return buf; | |
| 405 } | |
| 406 | |
| 407 GList * | |
| 408 gaim_get_callbacks(void) | |
| 409 { | |
| 410 return callbacks; | |
| 411 } | |
| 412 |
