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

# User Rev Content
1 root 1.7 #define IOM_CLASS "urxvt"
2 root 1.2 typedef int IOM_CHAINED;
3    
4 root 1.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 root 1.1 /////////////////////////////////////////////////////////////////////////////
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 root 1.7 rxvt_warn ("%s callback evaluation error: %s", type, SvPV_nolen (ERRSV));
63 root 1.1 }
64    
65 root 1.4 #define newSVtimer(timer) iom_new_ref ((timer)->self, IOM_CLASS "::timer")
66 root 1.1 #define SvTIMER(sv) (timer *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::timer")
67    
68 root 1.5 struct timer : perl_watcher, ev::timer
69 root 1.1 {
70     timer ()
71     {
72 root 1.6 set<timer, &timer::execute> (this);
73 root 1.1 }
74    
75 root 1.5 void execute (ev::timer &w, int revents)
76 root 1.1 {
77     invoke (IOM_CLASS "::timer", newSVtimer (this));
78     }
79     };
80    
81 root 1.4 #define newSViow(iow) iom_new_ref ((iow)->self, IOM_CLASS "::iow")
82 root 1.1 #define SvIOW(sv) (iow *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::iow")
83    
84 root 1.5 struct iow : perl_watcher, ev::io
85 root 1.1 {
86     iow ()
87     {
88 root 1.6 set<iow, &iow::execute> (this);
89 root 1.1 }
90    
91 root 1.5 void execute (ev::io &w, int revents)
92 root 1.1 {
93     invoke (IOM_CLASS "::iow", newSViow (this), revents);
94     }
95     };
96    
97 root 1.4 #define newSViw(iw) iom_new_ref ((iw)->self, IOM_CLASS "::iw")
98 root 1.1 #define SvIW(sv) (iw *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::iw")
99    
100 root 1.5 struct iw : perl_watcher, ev::idle
101 root 1.1 {
102     iw ()
103     {
104 root 1.6 set<iw, &iw::execute> (this);
105 root 1.1 }
106    
107 root 1.5 void execute (ev::idle &w, int revents)
108 root 1.1 {
109     invoke (IOM_CLASS "::iw", newSViw (this));
110     }
111     };
112    
113 root 1.4 #define newSVpw(pw) iom_new_ref ((pw)->self, IOM_CLASS "::pw")
114 root 1.1 #define SvPW(sv) (pw *)(perl_watcher *)SvPTR ((sv), IOM_CLASS "::pw")
115    
116 root 1.5 struct pw : perl_watcher, ev::child
117 root 1.1 {
118     pw ()
119     {
120 root 1.6 set<pw, &pw::execute> (this);
121 root 1.1 }
122    
123 root 1.5 void execute (ev::child &w, int revents)
124 root 1.1 {
125 root 1.5 invoke (IOM_CLASS "::pw", newSVpw (this), w.rstatus);
126 root 1.1 }
127     };
128