Mercurial > pidgin.yaz
comparison plugins/perl/perl-handlers.c @ 6520:2e2593d95121
[gaim-migrate @ 7037]
Added timeout handler support to perl. It may not work. Probably should,
but who knows.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 20 Aug 2003 10:25:58 +0000 |
parents | |
children | ed796f756237 |
comparison
equal
deleted
inserted
replaced
6519:7f0fffa1077b | 6520:2e2593d95121 |
---|---|
1 #include "perl-common.h" | |
2 #include "perl-handlers.h" | |
3 | |
4 #include "debug.h" | |
5 | |
6 static GList *timeout_handlers = NULL; | |
7 | |
8 extern PerlInterpreter *my_perl; | |
9 | |
10 static void | |
11 destroy_timeout_handler(GaimPerlTimeoutHandler *handler) | |
12 { | |
13 timeout_handlers = g_list_remove(timeout_handlers, handler); | |
14 | |
15 g_free(handler->name); | |
16 g_free(handler); | |
17 } | |
18 | |
19 static int | |
20 perl_timeout_cb(gpointer data) | |
21 { | |
22 void *atmp[2] = { NULL, NULL }; | |
23 GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data; | |
24 | |
25 dSP; | |
26 ENTER; | |
27 SAVETMPS; | |
28 PUSHMARK(sp); | |
29 XPUSHs((SV *)handler->args); | |
30 PUTBACK; | |
31 call_pv(handler->name, G_EVAL | G_SCALAR); | |
32 SPAGAIN; | |
33 | |
34 atmp[0] = handler->args; | |
35 | |
36 PUTBACK; | |
37 FREETMPS; | |
38 LEAVE; | |
39 | |
40 destroy_timeout_handler(handler); | |
41 | |
42 return 0; | |
43 } | |
44 | |
45 void | |
46 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, const char *func, | |
47 void *args) | |
48 { | |
49 GaimPerlTimeoutHandler *handler; | |
50 | |
51 if (plugin == NULL) | |
52 { | |
53 gaim_debug(GAIM_DEBUG_ERROR, "perl", | |
54 "Invalid handle in adding perl timeout handler.\n"); | |
55 return; | |
56 } | |
57 | |
58 handler = g_new0(GaimPerlTimeoutHandler, 1); | |
59 | |
60 handler->plugin = plugin; | |
61 handler->name = g_strdup(func); | |
62 handler->args = args; | |
63 | |
64 timeout_handlers = g_list_append(timeout_handlers, handler); | |
65 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); | |
66 } | |
67 | |
68 void | |
69 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin) | |
70 { | |
71 GaimPerlTimeoutHandler *handler; | |
72 GList *l, *l_next; | |
73 | |
74 for (l = timeout_handlers; l != NULL; l = l_next) | |
75 { | |
76 l_next = l->next; | |
77 | |
78 handler = (GaimPerlTimeoutHandler *)l->data; | |
79 | |
80 if (handler->plugin == plugin) | |
81 destroy_timeout_handler(handler); | |
82 } | |
83 } | |
84 | |
85 void | |
86 gaim_perl_timeout_clear(void) | |
87 { | |
88 while (timeout_handlers) | |
89 destroy_timeout_handler(timeout_handlers->data); | |
90 } | |
91 |