2 * $Id: rb_idle_enterer.c 154 2004-12-09 18:49:18Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 Ecore_Idle_Enterer *real;
34 static int on_idle_enter (void *data)
37 RbIdleEnterer *idle_enterer = data;
39 r = rb_funcall (idle_enterer->callback, rb_intern ("call"), 0);
41 /* if the callback returns false, we return 0 and Ecore
42 * will remove the idle enterer
45 idle_enterer->deleted = true;
50 static void c_mark (RbIdleEnterer *idle_enterer)
52 rb_gc_mark (idle_enterer->callback);
55 static void c_free (RbIdleEnterer *idle_enterer)
57 if (idle_enterer->real && !idle_enterer->deleted)
58 ecore_idle_enterer_del (idle_enterer->real);
67 * Ecore::IdleEnterer.new { block } => idle_enterer
69 * Creates an Ecore::IdleEnterer object.
70 * When Ecore enters the idle state, the specified block will be called.
71 * If the block returns false, the IdleEnterer is deleted.
73 static VALUE c_new (VALUE klass)
76 RbIdleEnterer *idle_enterer;
78 if (!rb_block_given_p ())
81 self = Data_Make_Struct (klass, RbIdleEnterer, c_mark, c_free,
86 idle_enterer->callback = rb_block_proc ();
87 idle_enterer->deleted = false;
88 idle_enterer->real = ecore_idle_enterer_add (on_idle_enter,
91 rb_obj_call_init (self, 0, NULL);
98 * idle_enterer.delete => nil
100 * Deletes <i>idle_enterer</i>.
102 static VALUE c_delete (VALUE self)
104 GET_OBJ (self, RbIdleEnterer, idle_enterer);
106 if (idle_enterer->real && !idle_enterer->deleted) {
107 ecore_idle_enterer_del (idle_enterer->real);
108 idle_enterer->real = NULL;
109 idle_enterer->deleted = true;
111 rb_raise (rb_eException, "IdleEnterer already deleted!");
116 void Init_IdleEnterer (void)
118 VALUE c = rb_define_class_under (mEcore, "IdleEnterer", rb_cObject);
120 rb_define_singleton_method (c, "new", c_new, 0);
121 rb_define_method (c, "delete", c_delete, 0);