… | |
… | |
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 |
… | |
… | |
60 | #define ARG_MAP(o) DT_MAP , (void *)static_cast<maptile *> (o) |
64 | #define ARG_MAP(o) DT_MAP , (void *)static_cast<maptile *> (o) |
61 | #define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<player *> (o) |
65 | #define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<player *> (o) |
62 | #define ARG_ARCH(o) DT_ARCH , (void *)static_cast<archetype *> (o) |
66 | #define ARG_ARCH(o) DT_ARCH , (void *)static_cast<archetype *> (o) |
63 | #define ARG_PARTY(o) DT_PARTY , (void *)static_cast<party *> (o) |
67 | #define ARG_PARTY(o) DT_PARTY , (void *)static_cast<party *> (o) |
64 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<region *> (o) |
68 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<region *> (o) |
65 | #define ARG_SOCKET(o) DT_SOCKET, (void *)static_cast<client_socket *> (o) |
69 | #define ARG_SOCKET(o) DT_SOCKET, (void *)static_cast<client *> (o) |
66 | |
70 | |
67 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
71 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
68 | |
72 | |
69 | // all these return true when the normal event processing should be skipped (if any) |
73 | // all these return true when the normal event processing should be skipped (if any) |
70 | #define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) |
74 | #define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) |
… | |
… | |
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 iw : watcher<pe_idle>, callback<void (iw &)> |
|
|
361 | { |
|
|
362 | template<class O, class M> |
|
|
363 | iw (O object, M method) |
|
|
364 | : callback<void (iw &)> (object, method) |
|
|
365 | { |
|
|
366 | alloc (); |
|
|
367 | } |
|
|
368 | |
|
|
369 | private: |
|
|
370 | void alloc (); |
|
|
371 | }; |
|
|
372 | |
|
|
373 | struct iow : watcher<pe_io>, callback<void (iow &, int)> |
|
|
374 | { |
|
|
375 | template<class O, class M> |
|
|
376 | iow (O object, M method) |
|
|
377 | : callback<void (iow &, int)> (object, method) |
|
|
378 | { |
|
|
379 | alloc (); |
|
|
380 | } |
|
|
381 | |
|
|
382 | void fd (int fd); |
|
|
383 | int poll (); |
|
|
384 | void poll (int events); |
|
|
385 | |
|
|
386 | private: |
|
|
387 | void alloc (); |
|
|
388 | }; |
|
|
389 | |
329 | #endif |
390 | #endif |
330 | |
391 | |