annotate plugins/perl/perl-handlers.c @ 11142:ee059fe9b362

[gaim-migrate @ 13206] Who wrote this? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 22 Jul 2005 01:49:19 +0000
parents 4315bb5f427b
children 0e9e2b923d09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 #include "perl-common.h"
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 #include "perl-handlers.h"
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 #include "debug.h"
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
5 #include "signals.h"
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 static GList *timeout_handlers = NULL;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
8 static GList *signal_handlers = NULL;
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
9 static char *perl_plugin_pref_cb;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
10 extern PerlInterpreter *my_perl;
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11
11123
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
12
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
13 /* Called to create a pointer to GaimPluginUiInfo for the GaimPluginInfo */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
14 /* It will then inturn create ui_info with the C function pointer */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
15 /* that will eventually do a call_pv to call a perl functions so users */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
16 /* can create their own frames in the prefs */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
17 GaimPluginUiInfo *gaim_perl_plugin_pref(char * frame_cb) {
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
18 GaimPluginUiInfo *ui_info;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
19
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
20 ui_info = g_new0(GaimPluginUiInfo, 1);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
21
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
22 perl_plugin_pref_cb = frame_cb;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
23
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
24 ui_info->get_plugin_pref_frame = gaim_perl_get_plugin_frame;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
25
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
26 return ui_info;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
27 }
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
28
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
29 GaimPluginPrefFrame *gaim_perl_get_plugin_frame(GaimPlugin *plugin) {
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
30 /* Sets up the Perl Stack for our call back into the script to run the */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
31 /* plugin_pref... sub */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
32 GaimPluginPrefFrame *ret_frame;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
33 dSP;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
34 int count;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
35
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
36 ENTER;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
37 SAVETMPS;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
38 /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and return */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
39 /* the frame */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
40 PUSHMARK(SP);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
41 PUTBACK;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
42
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
43 count = call_pv(perl_plugin_pref_cb, G_SCALAR | G_NOARGS);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
44
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
45 SPAGAIN;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
46
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
47 if (count != 1)
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
48 croak("call_pv: Did not return the correct number of values.\n");
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
49 /* the frame was created in a perl sub and is returned */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
50 ret_frame = (GaimPluginPrefFrame *)gaim_perl_ref_object(POPs);
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
51
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
52 /* Tidy up the Perl stack */
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
53 PUTBACK;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
54 FREETMPS;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
55 LEAVE;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
56
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
57 return ret_frame;
4315bb5f427b [gaim-migrate @ 13179]
John H. Kelm <johnkelm@gmail.com>
parents: 7386
diff changeset
58 }
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 static void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61 destroy_timeout_handler(GaimPerlTimeoutHandler *handler)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 timeout_handlers = g_list_remove(timeout_handlers, handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
65 if (handler->callback != NULL)
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
66 SvREFCNT_dec(handler->callback);
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
67
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
68 if (handler->data != NULL)
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
69 SvREFCNT_dec(handler->data);
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
70
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71 g_free(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
74 static void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
75 destroy_signal_handler(GaimPerlSignalHandler *handler)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
76 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
77 signal_handlers = g_list_remove(signal_handlers, handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
78
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
79 if (handler->callback != NULL)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
80 SvREFCNT_dec(handler->callback);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
81
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
82 if (handler->data != NULL)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
83 SvREFCNT_dec(handler->data);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
84
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
85 g_free(handler->signal);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
86 g_free(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
87 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
88
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 static int
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 perl_timeout_cb(gpointer data)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 dSP;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 ENTER;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 SAVETMPS;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97 PUSHMARK(sp);
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
98 XPUSHs((SV *)handler->data);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99 PUTBACK;
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
100 call_sv(handler->callback, G_EVAL | G_SCALAR);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 SPAGAIN;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103 PUTBACK;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 FREETMPS;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 LEAVE;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 destroy_timeout_handler(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 return 0;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
112 typedef void *DATATYPE;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
113
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
114 static void *
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
115 perl_signal_cb(va_list args, void *data)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
116 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
117 GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
118 void *ret_val = NULL;
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
119 int i;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
120 int count;
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
121 int value_count;
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
122 GaimValue *ret_value, **values;
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
123 SV **sv_args;
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
124 DATATYPE **copy_args;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
125 STRLEN na;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
126
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
127 dSP;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
128 ENTER;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
129 SAVETMPS;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
130 PUSHMARK(sp);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
131
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
132 gaim_signal_get_values(handler->instance, handler->signal,
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
133 &ret_value, &value_count, &values);
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
134
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
135 sv_args = g_new(SV *, value_count);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
136 copy_args = g_new(void **, value_count);
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
137
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
138 for (i = 0; i < value_count; i++)
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
139 {
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
140 sv_args[i] = sv_2mortal(gaim_perl_sv_from_vargs(values[i],
7386
414c701ef1ff [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 6925
diff changeset
141 (va_list*)&args, &copy_args[i]));
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
142
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
143 XPUSHs(sv_args[i]);
6566
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
144 }
f6c2a7b5afa7 [gaim-migrate @ 7088]
Christian Hammond <chipx86@chipx86.com>
parents: 6554
diff changeset
145
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
146 XPUSHs((SV *)handler->data);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
147
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
148 PUTBACK;
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
149
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
150 if (ret_value != NULL)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
151 {
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
152 count = call_sv(handler->callback, G_EVAL | G_SCALAR);
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
153
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
154 SPAGAIN;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
155
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
156 if (count != 1)
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
157 croak("Uh oh! call_sv returned %i != 1", i);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
158 else
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
159 ret_val = gaim_perl_data_from_sv(ret_value, POPs);
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
160 }
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
161 else
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
162 {
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
163 call_sv(handler->callback, G_SCALAR);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
164
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
165 SPAGAIN;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
166 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
167
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
168 if (SvTRUE(ERRSV))
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
169 {
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
170 gaim_debug_error("perl", "Perl function exited abnormally: %s\n",
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
171 SvPV(ERRSV, na));
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
172 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
173
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
174 /* See if any parameters changed. */
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
175 for (i = 0; i < value_count; i++)
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
176 {
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
177 if (gaim_value_is_outgoing(values[i]))
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
178 {
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
179 switch (gaim_value_get_type(values[i]))
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
180 {
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
181 case GAIM_TYPE_BOOLEAN:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
182 *((gboolean *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
183 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
184
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
185 case GAIM_TYPE_INT:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
186 *((int *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
187 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
188
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
189 case GAIM_TYPE_UINT:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
190 *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
191 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
192
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
193 case GAIM_TYPE_LONG:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
194 *((long *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
195 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
196
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
197 case GAIM_TYPE_ULONG:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
198 *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
199 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
200
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
201 case GAIM_TYPE_INT64:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
202 *((gint64 *)copy_args[i]) = SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
203 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
204
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
205 case GAIM_TYPE_UINT64:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
206 *((guint64 *)copy_args[i]) = SvUV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
207 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
208
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
209 case GAIM_TYPE_STRING:
6925
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
210 if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i])))
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
211 {
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
212 g_free(*((char **)copy_args[i]));
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
213 *((char **)copy_args[i]) =
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
214 g_strdup(SvPV(sv_args[i], na));
3ec6aac0ff67 [gaim-migrate @ 7472]
Christian Hammond <chipx86@chipx86.com>
parents: 6924
diff changeset
215 }
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
216 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
217
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
218 case GAIM_TYPE_POINTER:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
219 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
220 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
221
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
222 case GAIM_TYPE_BOXED:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
223 *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]);
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
224 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
225
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
226 default:
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
227 break;
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
228 }
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
229
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
230 #if 0
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
231 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i],
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
232 sv_args[i]);
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
233 #endif
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
234 }
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
235 }
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
236
6921
11d05ddf30a3 [gaim-migrate @ 7468]
Christian Hammond <chipx86@chipx86.com>
parents: 6920
diff changeset
237 PUTBACK;
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
238 FREETMPS;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
239 LEAVE;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
240
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
241 g_free(sv_args);
6920
13f78c350cd3 [gaim-migrate @ 7467]
Christian Hammond <chipx86@chipx86.com>
parents: 6919
diff changeset
242 g_free(copy_args);
6919
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
243
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
244 gaim_debug_misc("perl", "ret_val = %p\n", ret_val);
1aa771990188 [gaim-migrate @ 7466]
Christian Hammond <chipx86@chipx86.com>
parents: 6568
diff changeset
245
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
246 return ret_val;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
247 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
248
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
249 static GaimPerlSignalHandler *
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
250 find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
251 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
252 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
253 GList *l;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
254
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
255 for (l = signal_handlers; l != NULL; l = l->next)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
256 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
257 handler = (GaimPerlSignalHandler *)l->data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
258
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
259 if (handler->plugin == plugin &&
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
260 handler->instance == instance &&
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
261 !strcmp(handler->signal, signal))
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
262 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
263 return handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
264 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
265 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
266
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
267 return NULL;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
268 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
269
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 void
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
271 gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data)
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
272 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
273 GaimPerlTimeoutHandler *handler;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
274
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 if (plugin == NULL)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276 {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
277 croak("Invalid handle in adding perl timeout handler.\n");
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 return;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281 handler = g_new0(GaimPerlTimeoutHandler, 1);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
283 handler->plugin = plugin;
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
284 handler->callback = (callback != NULL && callback != &PL_sv_undef
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
285 ? newSVsv(callback) : NULL);
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
286 handler->data = (data != NULL && data != &PL_sv_undef
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
287 ? newSVsv(data) : NULL);
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289 timeout_handlers = g_list_append(timeout_handlers, handler);
6568
33486b749aa9 [gaim-migrate @ 7090]
Christian Hammond <chipx86@chipx86.com>
parents: 6567
diff changeset
290
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291 handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
292 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
293
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294 void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295 gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297 GaimPerlTimeoutHandler *handler;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
298 GList *l, *l_next;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 for (l = timeout_handlers; l != NULL; l = l_next)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 {
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302 l_next = l->next;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 handler = (GaimPerlTimeoutHandler *)l->data;
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306 if (handler->plugin == plugin)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307 destroy_timeout_handler(handler);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
308 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
310
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
311 void
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
312 gaim_perl_timeout_clear(void)
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
313 {
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
314 while (timeout_handlers != NULL)
6520
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 destroy_timeout_handler(timeout_handlers->data);
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316 }
2e2593d95121 [gaim-migrate @ 7037]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
318 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
319 gaim_perl_signal_connect(GaimPlugin *plugin, void *instance,
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
320 const char *signal, SV *callback, SV *data)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
321 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
322 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
323
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
324 handler = g_new0(GaimPerlSignalHandler, 1);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
325 handler->plugin = plugin;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
326 handler->instance = instance;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
327 handler->signal = g_strdup(signal);
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
328 handler->callback = (callback != NULL && callback != &PL_sv_undef
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
329 ? newSVsv(callback) : NULL);
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
330 handler->data = (data != NULL && data != &PL_sv_undef
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
331 ? newSVsv(data) : NULL);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
332
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
333 signal_handlers = g_list_append(signal_handlers, handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
334
6554
28b38803d0bb [gaim-migrate @ 7076]
Christian Hammond <chipx86@chipx86.com>
parents: 6549
diff changeset
335 gaim_signal_connect_vargs(instance, signal,
28b38803d0bb [gaim-migrate @ 7076]
Christian Hammond <chipx86@chipx86.com>
parents: 6549
diff changeset
336 plugin, GAIM_CALLBACK(perl_signal_cb), handler);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
337 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
338
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
339 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
340 gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance,
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
341 const char *signal)
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
342 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
343 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
344
6567
6e25e1e08ffb [gaim-migrate @ 7089]
Christian Hammond <chipx86@chipx86.com>
parents: 6566
diff changeset
345 handler = find_signal_handler(plugin, instance, signal);
6549
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
346
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
347 if (handler == NULL)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
348 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
349 croak("Invalid signal handler information in "
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
350 "disconnecting a perl signal handler.\n");
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
351 return;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
352 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
353
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
354 destroy_signal_handler(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
355 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
356
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
357 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
358 gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
359 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
360 GaimPerlSignalHandler *handler;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
361 GList *l, *l_next;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
362
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
363 for (l = signal_handlers; l != NULL; l = l_next)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
364 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
365 l_next = l->next;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
366
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
367 handler = (GaimPerlSignalHandler *)l->data;
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
368
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
369 if (handler->plugin == plugin)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
370 destroy_signal_handler(handler);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
371 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
372 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
373
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
374 void
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
375 gaim_perl_signal_clear(void)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
376 {
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
377 while (signal_handlers != NULL)
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
378 destroy_signal_handler(signal_handlers->data);
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
379 }
ed796f756237 [gaim-migrate @ 7071]
Christian Hammond <chipx86@chipx86.com>
parents: 6520
diff changeset
380