… | |
… | |
9 | using namespace std; |
9 | using namespace std; |
10 | |
10 | |
11 | #include <EXTERN.h> |
11 | #include <EXTERN.h> |
12 | #include <perl.h> |
12 | #include <perl.h> |
13 | #include <XSUB.h> |
13 | #include <XSUB.h> |
|
|
14 | |
|
|
15 | #include <EventAPI.h> |
|
|
16 | |
|
|
17 | #include "callback.h" |
14 | |
18 | |
15 | // optimisations/workaround for functions requiring my_perl in scope (anti-bloat) |
19 | // optimisations/workaround for functions requiring my_perl in scope (anti-bloat) |
16 | #undef localtime |
20 | #undef localtime |
17 | #undef srand48 |
21 | #undef srand48 |
18 | #undef drand48 |
22 | #undef drand48 |
… | |
… | |
324 | void get (sint64 &i) { i = get_sint64 (); } |
328 | void get (sint64 &i) { i = get_sint64 (); } |
325 | }; |
329 | }; |
326 | |
330 | |
327 | char *fgets (char *s, int n, object_thawer &thawer); |
331 | char *fgets (char *s, int n, object_thawer &thawer); |
328 | |
332 | |
|
|
333 | struct watcher_base |
|
|
334 | { |
|
|
335 | static struct EventAPI *GEventAPI; |
|
|
336 | }; |
|
|
337 | |
|
|
338 | template<class base> |
|
|
339 | struct watcher : watcher_base |
|
|
340 | { |
|
|
341 | base *pe; |
|
|
342 | |
|
|
343 | void start (bool repeat = false) { GEventAPI->start ((pe_watcher *)pe, repeat); } |
|
|
344 | void stop (bool cancel_events = false) { GEventAPI->stop ((pe_watcher *)pe, cancel_events); } |
|
|
345 | void now () { GEventAPI->now ((pe_watcher *)pe); } |
|
|
346 | void suspend () { GEventAPI->suspend ((pe_watcher *)pe); } |
|
|
347 | void resume () { GEventAPI->resume ((pe_watcher *)pe); } |
|
|
348 | |
|
|
349 | void prio (int new_prio) { ((pe_watcher *)pe)->prio = new_prio; } |
|
|
350 | |
|
|
351 | ~watcher () |
|
|
352 | { |
|
|
353 | cancel (); |
|
|
354 | } |
|
|
355 | |
|
|
356 | private: |
|
|
357 | void cancel () { GEventAPI->cancel ((pe_watcher *)pe); } // private |
|
|
358 | }; |
|
|
359 | |
|
|
360 | struct iow : watcher<pe_io>, callback<void (iow &, int)> |
|
|
361 | { |
|
|
362 | template<class O, class M> |
|
|
363 | iow (O object, M method) |
|
|
364 | : callback<void (iow &, int)> (object, method) |
|
|
365 | { |
|
|
366 | alloc (); |
|
|
367 | } |
|
|
368 | |
|
|
369 | iow &fd (int fd); |
|
|
370 | int poll (); |
|
|
371 | iow &poll (int events); |
|
|
372 | |
|
|
373 | private: |
|
|
374 | void alloc (); |
|
|
375 | }; |
|
|
376 | |
329 | #endif |
377 | #endif |
330 | |
378 | |