comparison plugins/perl/perl-handlers.c @ 6568:33486b749aa9

[gaim-migrate @ 7090] Add the same spiffiness to timeouts. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 22 Aug 2003 04:17:10 +0000
parents 6e25e1e08ffb
children 1aa771990188
comparison
equal deleted inserted replaced
6567:6e25e1e08ffb 6568:33486b749aa9
12 static void 12 static void
13 destroy_timeout_handler(GaimPerlTimeoutHandler *handler) 13 destroy_timeout_handler(GaimPerlTimeoutHandler *handler)
14 { 14 {
15 timeout_handlers = g_list_remove(timeout_handlers, handler); 15 timeout_handlers = g_list_remove(timeout_handlers, handler);
16 16
17 g_free(handler->name); 17 if (handler->callback != NULL)
18 SvREFCNT_dec(handler->callback);
19
20 if (handler->data != NULL)
21 SvREFCNT_dec(handler->data);
22
18 g_free(handler); 23 g_free(handler);
19 } 24 }
20 25
21 static void 26 static void
22 destroy_signal_handler(GaimPerlSignalHandler *handler) 27 destroy_signal_handler(GaimPerlSignalHandler *handler)
23 { 28 {
24 signal_handlers = g_list_remove(signal_handlers, handler); 29 signal_handlers = g_list_remove(signal_handlers, handler);
25
26 if (handler->instance != NULL)
27 SvREFCNT_dec(handler->instance);
28 30
29 if (handler->callback != NULL) 31 if (handler->callback != NULL)
30 SvREFCNT_dec(handler->callback); 32 SvREFCNT_dec(handler->callback);
31 33
32 if (handler->data != NULL) 34 if (handler->data != NULL)
43 45
44 dSP; 46 dSP;
45 ENTER; 47 ENTER;
46 SAVETMPS; 48 SAVETMPS;
47 PUSHMARK(sp); 49 PUSHMARK(sp);
48 XPUSHs((SV *)handler->args); 50 XPUSHs((SV *)handler->data);
49 PUTBACK; 51 PUTBACK;
50 call_pv(handler->name, G_EVAL | G_SCALAR); 52 call_sv(handler->callback, G_EVAL | G_SCALAR);
51 SPAGAIN; 53 SPAGAIN;
52 54
53 PUTBACK; 55 PUTBACK;
54 FREETMPS; 56 FREETMPS;
55 LEAVE; 57 LEAVE;
131 133
132 return NULL; 134 return NULL;
133 } 135 }
134 136
135 void 137 void
136 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, const char *func, 138 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data)
137 void *args)
138 { 139 {
139 GaimPerlTimeoutHandler *handler; 140 GaimPerlTimeoutHandler *handler;
140 141
141 if (plugin == NULL) 142 if (plugin == NULL)
142 { 143 {
144 return; 145 return;
145 } 146 }
146 147
147 handler = g_new0(GaimPerlTimeoutHandler, 1); 148 handler = g_new0(GaimPerlTimeoutHandler, 1);
148 149
149 handler->plugin = plugin; 150 handler->plugin = plugin;
150 handler->name = g_strdup(func); 151 handler->callback = (callback != NULL && callback != &PL_sv_undef
151 handler->args = args; 152 ? newSVsv(callback) : NULL);
153 handler->data = (data != NULL && data != &PL_sv_undef
154 ? newSVsv(data) : NULL);
152 155
153 timeout_handlers = g_list_append(timeout_handlers, handler); 156 timeout_handlers = g_list_append(timeout_handlers, handler);
157
154 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); 158 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler);
155 } 159 }
156 160
157 void 161 void
158 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin) 162 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin)