From 22c1e6dbe7cf74936e5ca29eadeff81312ccc506 Mon Sep 17 00:00:00 2001 From: buisson Date: Fri, 29 Apr 2005 09:35:43 +0000 Subject: Initial revision --- civyloop.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 civyloop.c (limited to 'civyloop.c') diff --git a/civyloop.c b/civyloop.c new file mode 100644 index 0000000..0414654 --- /dev/null +++ b/civyloop.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +value ivy_mainLoop(value unit) +{ + IvyMainLoop (0); + return Val_unit; +} + +void timer_cb(TimerId id, void *data, unsigned long delta) +{ + value closure = *(value*)data; + callback(closure, Val_int((int) id)); +} + +value ivy_timerRepeatafter(value nb_ticks,value delay, value closure_name) +{ + value * closure = caml_named_value(String_val(closure_name)); + TimerId id = TimerRepeatAfter(Int_val(nb_ticks), Int_val(delay), timer_cb, (void*)closure); + return Val_int(id); +} + +/* Data associated to Channel callbacks is the couple of delete and +read closures */ + +void cb_delete_channel(void *delete_read); +void cb_read_channel(Channel ch, HANDLE fd, void *closure); + + +value ivy_channelSetUp(value fd, value closure_name) +{ + Channel c; + value * closure = caml_named_value(String_val(closure_name)); + + c = IvyChannelSetUp((HANDLE)Int_val(fd), (void*)closure, cb_delete_channel, cb_read_channel); + return Val_int(c); +} + +value ivy_timerRemove(value t) +{ + TimerRemove((TimerId)Int_val(t)); + return Val_unit; +} + + +value ivy_channelClose(value ch) +{ + IvyChannelClose((Channel)Int_val(ch)); + return Val_unit; +} -- cgit v1.1