--- /dev/null
+/*
+ * $Id: rb_idle_enterer.c 152 2004-12-09 18:33:15Z tilman $
+ *
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <ruby.h>
+#include <stdbool.h>
+
+#include <Ecore.h>
+
+#include "rb_ecore.h"
+
+typedef struct {
+ Ecore_Idle_Enterer *real;
+ VALUE callback;
+ bool deleted;
+} RbIdleEnterer;
+
+static int on_idle_enter (void *data)
+{
+ VALUE r;
+ RbIdleEnterer *idle_enterer = data;
+
+ r = rb_funcall (idle_enterer->callback, rb_intern ("call"), 0);
+
+ /* if the callback returns false, we return 0 and Ecore
+ * will remove the idle enterer
+ */
+ if (r == Qfalse)
+ idle_enterer->deleted = true;
+
+ return (r != Qfalse);
+}
+
+static void c_mark (RbIdleEnterer *idle_enterer)
+{
+ rb_gc_mark (idle_enterer->callback);
+}
+
+static void c_free (RbIdleEnterer *idle_enterer)
+{
+ if (idle_enterer->real && !idle_enterer->deleted)
+ ecore_idle_enterer_del (idle_enterer->real);
+
+ ecore_shutdown ();
+
+ free (idle_enterer);
+}
+
+/*
+ * call-seq:
+ * Ecore::IdleEnterer.new { block } => idle_enterer
+ *
+ * Creates an Ecore::IdleEnterer object.
+ * When Ecore enters the idle state, the specified block will be called.
+ * If the block returns false, the IdleEnterer is deleted.
+ */
+static VALUE c_new (VALUE klass)
+{
+ VALUE self;
+ RbIdleEnterer *idle_enterer;
+
+ if (!rb_block_given_p ())
+ return Qnil;
+
+ self = Data_Make_Struct (klass, RbIdleEnterer, c_mark, c_free,
+ idle_enterer);
+
+ ecore_init ();
+
+ idle_enterer->callback = rb_block_proc ();
+ idle_enterer->deleted = false;
+ idle_enterer->real = ecore_idle_enterer_add (on_idle_enter,
+ idle_enterer);
+
+ rb_obj_call_init (self, 0, NULL);
+
+ return self;
+}
+
+/*
+ * call-seq:
+ * idle_enterer.delete => nil
+ *
+ * Deletes <i>idle_enterer</i>.
+ */
+static VALUE c_delete (VALUE self)
+{
+ GET_OBJ (self, RbIdleEnterer, idle_enterer);
+
+ if (idle_enterer->real && !idle_enterer->deleted) {
+ ecore_idle_enterer_del (idle_enterer->real);
+ idle_enterer->real = NULL;
+ idle_enterer->deleted = true;
+ } else
+ rb_raise (rb_eException, "IdleEnterer already deleted!");
+
+ return Qnil;
+}
+
+void Init_IdleEnterer (void)
+{
+ VALUE c = rb_define_class_under (mEcore, "IdleEnterer", rb_cObject);
+
+ rb_define_singleton_method (c, "new", c_new, 1);
+ rb_define_method (c, "delete", c_delete, 0);
+}
--- /dev/null
+/*
+ * $Id: rb_idle_enterer.h 152 2004-12-09 18:33:15Z tilman $
+ *
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __RB_IDLER_ENTERER_H
+#define __RB_IDLER_ENTERER_H
+
+void Init_IdleEnterer (void);
+
+#endif