ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/iom_perl.h
Revision: 1.7
Committed: Fri Jan 7 21:17:07 2011 UTC (13 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rxvt-unicode-rel-9_29, rxvt-unicode-rel-9_26, rxvt-unicode-rel-9_25, rxvt-unicode-rel-9_22, rxvt-unicode-rel-9_20, rxvt-unicode-rel-9_21, rel-9_14, rel-9_11, rel-9_12, rxvt-unicode-rel-9_19, rxvt-unicode-rel-9_18, rxvt-unicode-rel-9_17, rxvt-unicode-rel-9_16, rxvt-unicode-rel-9_15, rxvt-unicode-rel-9_30, HEAD
Changes since 1.6: +2 -1 lines
Log Message:
minor warn cleanup

File Contents

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