X-Git-Url: http://git.code-monkey.de/?p=ruby-ecore.git;a=blobdiff_plain;f=src%2Fecore%2Frb_timer.c;h=939a88d9df91c8a64a0f8e5790ad10b107255d31;hp=a021106f2cc5d7bcfe917cfac8e2619280e27425;hb=d907bd016f15dc5be72d12ee1742047eafc2abae;hpb=f601b2dd76332041b11da615b01f068690ad0453 diff --git a/src/ecore/rb_timer.c b/src/ecore/rb_timer.c index a021106..939a88d 100644 --- a/src/ecore/rb_timer.c +++ b/src/ecore/rb_timer.c @@ -1,7 +1,7 @@ /* - * $Id: rb_timer.c 67 2004-08-12 20:08:13Z tilman $ + * $Id: rb_timer.c 351 2006-02-10 15:25:40Z 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 @@ -62,6 +62,15 @@ static void c_free (RbTimer *timer) free (timer); } +static VALUE c_alloc (VALUE klass) +{ + RbTimer *timer = NULL; + + ecore_init (); + + return Data_Make_Struct (klass, RbTimer, c_mark, c_free, timer); +} + /* * call-seq: * Ecore::Timer.new(interval) { block } => timer @@ -70,25 +79,18 @@ static void c_free (RbTimer *timer) * 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) +static VALUE c_init (VALUE self, VALUE interval) { - VALUE self; - RbTimer *timer = NULL; + GET_OBJ (self, RbTimer, timer); if (!rb_block_given_p ()) - return Qnil; - - self = Data_Make_Struct (klass, RbTimer, c_mark, c_free, timer); - - ecore_init (); + rb_raise (rb_eStandardError, "block missing"); timer->callback = rb_block_proc (); timer->deleted = false; timer->real = ecore_timer_add (NUM2DBL (interval), on_timer, timer); - rb_obj_call_init (self, 0, NULL); - return self; } @@ -112,10 +114,29 @@ static VALUE c_delete (VALUE self) 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_alloc_func (c, c_alloc); + rb_define_method (c, "initialize", c_init, 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); }