projects
/
ruby-ecore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Documentation arrived.
[ruby-ecore.git]
/
src
/
ecore
/
rb_timer.c
diff --git
a/src/ecore/rb_timer.c
b/src/ecore/rb_timer.c
index 543a5415f6dcc2c3ad2a423dce81ec361b8d04b1..55b4a393bb74a86b3ef1954f4a22c6d5de5fedc2 100644
(file)
--- a/
src/ecore/rb_timer.c
+++ b/
src/ecore/rb_timer.c
@@
-1,5
+1,5
@@
/*
/*
- * $Id: rb_timer.c
40 2004-07-25 13:14:34
Z tilman $
+ * $Id: rb_timer.c
60 2004-08-10 14:12:36
Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
@@
-19,24
+19,24
@@
*/
#include <ruby.h>
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
#include <Ecore.h>
-#include <stdbool.h>
#include "rb_ecore.h"
typedef struct {
#include "rb_ecore.h"
typedef struct {
- Ecore_Timer *
timer
;
-
void *cb
;
+ Ecore_Timer *
real
;
+
VALUE callback
;
bool deleted;
bool deleted;
-} Rb
Ecore
Timer;
+} RbTimer;
static int on_timer (void *data)
{
VALUE r;
static int on_timer (void *data)
{
VALUE r;
- Rb
Ecore
Timer *timer = data;
+ RbTimer *timer = data;
- r = rb_funcall (
(VALUE) timer->cb
, rb_intern ("call"), 0);
+ r = rb_funcall (
timer->callback
, rb_intern ("call"), 0);
/* if the callback returns false, we return 0 and Ecore
* will remove the timer
/* if the callback returns false, we return 0 and Ecore
* will remove the timer
@@
-47,46
+47,63
@@
static int on_timer (void *data)
return (r != Qfalse);
}
return (r != Qfalse);
}
-static void c_free (RbEcoreTimer *timer)
+static void c_mark (RbTimer *timer)
+{
+ rb_gc_mark (timer->callback);
+}
+
+static void c_free (RbTimer *timer)
{
{
- if (timer->
timer
&& !timer->deleted)
- ecore_timer_del (timer->
timer
);
+ if (timer->
real
&& !timer->deleted)
+ ecore_timer_del (timer->
real
);
ecore_shutdown ();
free (timer);
}
ecore_shutdown ();
free (timer);
}
+/*
+ * call-seq:
+ * Ecore::Timer.new(interval) { block } => timer
+ *
+ * Creates an Ecore::Timer object with the specified interval.
+ * When the timeout is hit, the block is called.
+ * If the block returns false, the timer is deleted.
+ */
static VALUE c_new (VALUE klass, VALUE interval)
{
VALUE self;
static VALUE c_new (VALUE klass, VALUE interval)
{
VALUE self;
- Rb
EcoreTimer *timer
;
+ Rb
Timer *timer = NULL
;
if (!rb_block_given_p ())
return Qnil;
if (!rb_block_given_p ())
return Qnil;
- self = Data_Make_Struct (klass, Rb
EcoreTimer, NULL
, c_free, timer);
+ self = Data_Make_Struct (klass, Rb
Timer, c_mark
, c_free, timer);
ecore_init ();
ecore_init ();
- timer->c
b = (void *)
rb_block_proc ();
- timer->
timer
= ecore_timer_add (NUM2DBL (interval),
-
on_timer, timer);
+ timer->c
allback =
rb_block_proc ();
+ timer->
real
= ecore_timer_add (NUM2DBL (interval),
+ on_timer, timer);
rb_obj_call_init (self, 0, NULL);
return self;
}
rb_obj_call_init (self, 0, NULL);
return self;
}
+/*
+ * call-seq:
+ * timer.delete => nil
+ *
+ * Deletes <i>timer</i>.
+ */
static VALUE c_delete (VALUE self)
{
static VALUE c_delete (VALUE self)
{
- RbEcoreTimer *timer = NULL;
-
- Data_Get_Struct (self, RbEcoreTimer, timer);
+ GET_OBJ (self, RbTimer, timer);
- if (timer->
timer
&& !timer->deleted) {
- ecore_timer_del (timer->
timer
);
- timer->
timer
= NULL;
+ if (timer->
real
&& !timer->deleted) {
+ ecore_timer_del (timer->
real
);
+ timer->
real
= NULL;
timer->deleted = true;
} else
rb_raise (rb_eException, "Timer already deleted!");
timer->deleted = true;
} else
rb_raise (rb_eException, "Timer already deleted!");