ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/iom_perl.h
Revision: 1.3
Committed: Thu Dec 14 17:40:03 2006 UTC (17 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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