ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/iom_perl.h
Revision: 1.1
Committed: Thu Dec 14 15:19:31 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 /////////////////////////////////////////////////////////////////////////////
2
3 #define SvWATCHER(sv) (perl_watcher *)SvPTR (sv, IOM_CLASS "::watcher")
4
5 struct perl_watcher
6 {
7 SV *cbsv;
8 HV *self;
9
10 perl_watcher ()
11 : cbsv (0)
12 {
13 }
14
15 ~perl_watcher ()
16 {
17 SvREFCNT_dec (cbsv);
18 }
19
20 void cb (SV *cb)
21 {
22 SvREFCNT_dec (cbsv);
23 cbsv = newSVsv (cb);
24 }
25
26 void invoke (const char *type, SV *self, int arg = -1);
27 };
28
29 void
30 perl_watcher::invoke (const char *type, SV *self, int arg)
31 {
32 dSP;
33
34 ENTER;
35 SAVETMPS;
36
37 PUSHMARK (SP);
38
39 XPUSHs (sv_2mortal (self));
40
41 if (arg >= 0)
42 XPUSHs (sv_2mortal (newSViv (arg)));
43
44 PUTBACK;
45 call_sv (cbsv, G_VOID | G_EVAL | G_DISCARD);
46 SPAGAIN;
47
48 PUTBACK;
49 FREETMPS;
50 LEAVE;
51
52 if (SvTRUE (ERRSV))
53 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
54 }
55
56 #define newSVtimer(timer) new_ref ((timer)->self, IOM_CLASS "::timer")
57 #define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::timer")
58
59 struct timer : perl_watcher, time_watcher
60 {
61 tstamp interval;
62
63 timer ()
64 : time_watcher (this, &timer::execute)
65 {
66 }
67
68 void execute (time_watcher &w)
69 {
70 if (interval)
71 start (at + interval);
72
73 invoke (IOM_CLASS "::timer", newSVtimer (this));
74 }
75 };
76
77 #define newSViow(iow) new_ref ((iow)->self, IOM_CLASS "::iow")
78 #define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::iow")
79
80 struct iow : perl_watcher, io_watcher
81 {
82 iow ()
83 : io_watcher (this, &iow::execute)
84 {
85 }
86
87 void execute (io_watcher &w, short revents)
88 {
89 invoke (IOM_CLASS "::iow", newSViow (this), revents);
90 }
91 };
92
93 #define newSViw(iw) new_ref ((iw)->self, IOM_CLASS "::iw")
94 #define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::iw")
95
96 struct iw : perl_watcher, idle_watcher
97 {
98 iw ()
99 : idle_watcher (this, &iw::execute)
100 {
101 }
102
103 void execute (idle_watcher &w)
104 {
105 invoke (IOM_CLASS "::iw", newSViw (this));
106 }
107 };
108
109 #define newSVpw(pw) new_ref ((pw)->self, IOM_CLASS "::pw")
110 #define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::pw")
111
112 struct pw : perl_watcher, child_watcher
113 {
114 pw ()
115 : child_watcher (this, &pw::execute)
116 {
117 }
118
119 void execute (child_watcher &w, int status)
120 {
121 invoke (IOM_CLASS "::pw", newSVpw (this), status);
122 }
123 };
124