2 * $Id: rb_idler.c 40 2004-07-25 13:14:34Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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
34 static int on_idler (void *data)
37 RbEcoreIdler *idler = data;
39 r = rb_funcall ((VALUE) idler->cb, rb_intern ("call"), 0);
41 /* if the callback returns false, we return 0 and Ecore
42 * will remove the idler
45 idler->deleted = true;
50 static void c_free (RbEcoreIdler *idler)
52 if (idler->idler && !idler->deleted)
53 ecore_idler_del (idler->idler);
60 static VALUE c_new (VALUE klass)
65 if (!rb_block_given_p ())
68 self = Data_Make_Struct (klass, RbEcoreIdler, NULL, c_free, idler);
72 idler->cb = (void *) rb_block_proc ();
73 idler->idler = ecore_idler_add (on_idler, idler);
75 rb_obj_call_init (self, 0, NULL);
80 static VALUE c_delete (VALUE self)
82 RbEcoreIdler *idler = NULL;
84 Data_Get_Struct (self, RbEcoreIdler, idler);
86 if (idler->idler && !idler->deleted) {
87 ecore_idler_del (idler->idler);
89 idler->deleted = true;
91 rb_raise (rb_eException, "Idler already deleted!");
96 void Init_Idler (void)
98 VALUE c = rb_define_class_under (mEcore, "Idler", rb_cObject);
100 rb_define_singleton_method (c, "new", c_new, 1);
101 rb_define_method (c, "delete", c_delete, 0);