From a17272283c803e13258e5dc6b19533c672ceee18 Mon Sep 17 00:00:00 2001 From: hattenberger Date: Wed, 27 Mar 2013 13:17:19 +0000 Subject: some fixes in ivy-ocaml tag 1.2 --- trunk/civyloop.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 trunk/civyloop.c (limited to 'trunk/civyloop.c') diff --git a/trunk/civyloop.c b/trunk/civyloop.c new file mode 100644 index 0000000..083b104 --- /dev/null +++ b/trunk/civyloop.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +value ivy_mainLoop(value unit) +{ +#if IVYMINOR_VERSION == 8 + IvyMainLoop (NULL,NULL); +#else + IvyMainLoop (); +#endif + return Val_unit; +} + +void timer_cb(TimerId id, void *data, unsigned long delta) +{ + value closure = *(value*)data; + callback(closure, Val_long(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 */ + +extern void cb_delete_channel(void *delete_read); +extern void cb_read_channel(Channel ch, IVY_HANDLE fd, void *closure); +extern void cb_write_channel(Channel ch, IVY_HANDLE fd, void *closure); + + +value ivy_channelSetUp(value fd, value closure_name) +{ + Channel c; + value * closure = caml_named_value(String_val(closure_name)); + +#if IVYMINOR_VERSION == 8 + c = IvyChannelAdd((IVY_HANDLE)Int_val(fd), (void*)closure, cb_delete_channel, cb_read_channel); +#else + c = IvyChannelAdd((IVY_HANDLE)Int_val(fd), (void*)closure, cb_delete_channel, cb_read_channel, cb_write_channel); +#endif + return Val_int(c); +} + +value ivy_timerRemove(value t) +{ + TimerRemove((TimerId)Long_val(t)); + return Val_unit; +} + + +value ivy_channelClose(value ch) +{ + IvyChannelRemove((Channel)Long_val(ch)); + return Val_unit; +} -- cgit v1.1