/*
- * $Id: rb_timer.c 50 2004-08-01 10:18:39Z tilman $
+ * $Id: rb_timer.c 279 2005-03-13 14:32:25Z tilman $
*
- * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
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;
ecore_init ();
timer->callback = rb_block_proc ();
+ timer->deleted = false;
timer->real = ecore_timer_add (NUM2DBL (interval),
on_timer, timer);
return self;
}
+/*
+ * call-seq:
+ * timer.delete => nil
+ *
+ * Deletes <i>timer</i>.
+ */
static VALUE c_delete (VALUE self)
{
GET_OBJ (self, RbTimer, timer);
return Qnil;
}
+static VALUE c_deleted_get (VALUE self)
+{
+ GET_OBJ (self, RbTimer, timer);
+
+ return timer->deleted ? Qtrue : Qfalse;
+}
+
+static VALUE c_interval_set (VALUE self, VALUE interval)
+{
+ GET_OBJ (self, RbTimer, timer);
+
+ ecore_timer_interval_set (timer->real, NUM2DBL (interval));
+
+ return Qnil;
+}
+
void Init_Timer (void)
{
VALUE c = rb_define_class_under (mEcore, "Timer", rb_cObject);
rb_define_singleton_method (c, "new", c_new, 1);
rb_define_method (c, "delete", c_delete, 0);
+ rb_define_method (c, "deleted?", c_deleted_get, 0);
+ rb_define_method (c, "interval=", c_interval_set, 1);
}