Added Ecore::IdleEnterer.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Dec 2004 18:33:15 +0000 (18:33 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Dec 2004 18:33:15 +0000 (18:33 +0000)
src/ecore/Makefile.am
src/ecore/rb_ecore.c
src/ecore/rb_idle_enterer.c [new file with mode: 0644]
src/ecore/rb_idle_enterer.h [new file with mode: 0644]

index 6d481def67e801970b1834ef4d70fe5a660b9af3..2f745845e4cfd207f8da266ac7b955464192aed2 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 146 2004-11-27 15:38:52Z tilman $
+## $Id: Makefile.am 152 2004-12-09 18:33:15Z tilman $
 
 AM_CFLAGS = $(ECORE_CFLAGS)
 INCLUDES = -I$(RUBYDIR)
@@ -8,6 +8,7 @@ extdir = $(RUBYSITEDIR)
 
 ecore_la_SOURCES = rb_ecore.c rb_ecore.h \
                    rb_idler.c rb_idler.h \
+                   rb_idle_enterer.c rb_idle_enterer.h \
                    rb_timer.c rb_timer.h \
                    rb_animator.c rb_animator.h \
                    rb_event_handler.c rb_event_handler.h \
index 342d0230f997d50efc972625140f5c445fe6feef..9ff2ea37445608e96cd1f131934a035298ae302a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore.c 147 2004-11-27 15:42:34Z tilman $
+ * $Id: rb_ecore.c 152 2004-12-09 18:33:15Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -151,6 +151,7 @@ void Init_ecore (void)
        Init_Timer ();
        Init_Animator ();
        Init_Idler ();
+       Init_IdleEnterer ();
        Init_EventHandler ();
        Init_FdHandler ();
 
diff --git a/src/ecore/rb_idle_enterer.c b/src/ecore/rb_idle_enterer.c
new file mode 100644 (file)
index 0000000..03e6716
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * $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);
+}
diff --git a/src/ecore/rb_idle_enterer.h b/src/ecore/rb_idle_enterer.h
new file mode 100644 (file)
index 0000000..f4e7bac
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $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