Added Ecore::FdHandler. Moved DEF_CONST.
authorTilman Sauerbeck <tilman@code-monkey.de>
Wed, 1 Sep 2004 20:33:15 +0000 (20:33 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 1 Sep 2004 20:33:15 +0000 (20:33 +0000)
src/ecore/Makefile.am
src/ecore/rb_ecore.c
src/ecore/rb_ecore.h
src/ecore/rb_fd_handler.c [new file with mode: 0644]
src/ecore/rb_fd_handler.h [new file with mode: 0644]
src/ecore_x/rb_cursor.c
src/ecore_x/rb_ecore_x.h

index f3c8a0869b12c6d62ce42292faea6d3e859c6c18..78a07906e74bbf9b9a6c59cd0b629d00759dd32c 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 77 2004-08-19 17:39:29Z tilman $
+## $Id: Makefile.am 109 2004-09-01 20:33:15Z tilman $
 
 AM_CFLAGS = $(ECORE_CFLAGS)
 INCLUDES = -I$(RUBYDIR)
@@ -9,7 +9,8 @@ extdir = $(RUBYSITEDIR)
 ecore_la_SOURCES = rb_ecore.c rb_ecore.h \
                    rb_idler.c rb_idler.h \
                    rb_timer.c rb_timer.h \
-                   rb_event_handler.c rb_event_handler.h
+                   rb_event_handler.c rb_event_handler.h \
+                   rb_fd_handler.c rb_fd_handler.h
 
 ecore_la_LIBADD = -L$(RUBYLIBDIR) -lruby $(ECORE_LIBS)
 ecore_la_LDFLAGS = -module -avoid-version
index 52b7e7a4915156673fe7da6d6e00ae7ef2392088..f950f7e0079f3a0e2fac96a50fb77b0b400e00da 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore.c 83 2004-08-21 19:55:35Z tilman $
+ * $Id: rb_ecore.c 109 2004-09-01 20:33:15Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -27,6 +27,7 @@
 #include "rb_timer.h"
 #include "rb_idler.h"
 #include "rb_event_handler.h"
+#include "rb_fd_handler.h"
 
 VALUE mEcore;
 
@@ -143,6 +144,7 @@ void Init_ecore (void)
        Init_Timer ();
        Init_Idler ();
        Init_EventHandler ();
+       Init_FdHandler ();
 
        /* SIGNAL_HUP */
        ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
index 5afbc03c9a9f42434aded7dadb31783a67d60544..95cbde4c7bab2bea284f9901cefa056470a0b355 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore.h 77 2004-08-19 17:39:29Z tilman $
+ * $Id: rb_ecore.h 109 2004-09-01 20:33:15Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
 \
        return rb_str_new2 (buf);
 
+#define DEF_CONST(mod, prefix, name) \
+       rb_define_const ((mod), #name, \
+                        INT2FIX (prefix##name));
+
 #ifndef __RB_ECORE_C
 VALUE mEcore;
 #endif
diff --git a/src/ecore/rb_fd_handler.c b/src/ecore/rb_fd_handler.c
new file mode 100644 (file)
index 0000000..4d7e08c
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * $Id: rb_fd_handler.c 109 2004-09-01 20: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_Fd_Handler *real;
+       VALUE callback;
+       bool deleted;
+} RbFdHandler;
+
+static int on_change (void *data, Ecore_Fd_Handler *unused)
+{
+       VALUE r;
+       RbFdHandler *fdh = data;
+
+       r = rb_funcall (fdh->callback, rb_intern ("call"), 0);
+
+       /* if the callback returns false, we return 0 and Ecore
+        * will remove the FD Handler
+        */
+       if (r == Qfalse)
+               fdh->deleted = true;
+
+       return (r != Qfalse);
+}
+
+static void c_mark (RbFdHandler *fdh)
+{
+       rb_gc_mark (fdh->callback);
+}
+
+static void c_free (RbFdHandler *fdh)
+{
+       if (fdh->real && !fdh->deleted)
+               ecore_main_fd_handler_del (fdh->real);
+
+       ecore_shutdown ();
+
+       free (fdh);
+}
+
+static VALUE c_new (VALUE klass, VALUE fd, VALUE flags)
+{
+       VALUE self;
+       RbFdHandler *fdh = NULL;
+
+       if (!rb_block_given_p ())
+               return Qnil;
+
+       Check_Type (fd, T_FIXNUM);
+       Check_Type (flags, T_FIXNUM);
+
+       self = Data_Make_Struct (klass, RbFdHandler, c_mark, c_free, fdh);
+
+       ecore_init ();
+
+       fdh->callback = rb_block_proc ();
+       fdh->real = ecore_main_fd_handler_add (FIX2INT (fd),
+                                              FIX2INT (flags), on_change,
+                                              fdh, NULL, NULL);
+
+       rb_obj_call_init (self, 0, NULL);
+
+       return self;
+}
+
+static VALUE c_delete (VALUE self)
+{
+       GET_OBJ (self, RbFdHandler, fdh);
+
+       ecore_main_fd_handler_del (fdh->real);
+       fdh->real = NULL;
+
+       return Qnil;
+}
+
+static VALUE c_fd_get (VALUE self)
+{
+       GET_OBJ (self, RbFdHandler, fdh);
+
+       return INT2FIX (ecore_main_fd_handler_fd_get (fdh->real));
+}
+
+static VALUE c_get_active (VALUE self, VALUE flags)
+{
+       int r;
+
+       GET_OBJ (self, RbFdHandler, fdh);
+
+       Check_Type (flags, T_FIXNUM);
+
+       r = ecore_main_fd_handler_active_get (fdh->real, FIX2INT (flags));
+
+       return INT2FIX (r);
+}
+
+static VALUE c_set_active (VALUE self, VALUE flags)
+{
+       GET_OBJ (self, RbFdHandler, fdh);
+
+       Check_Type (flags, T_FIXNUM);
+
+       ecore_main_fd_handler_active_set (fdh->real, FIX2INT (flags));
+
+       return Qnil;
+}
+
+void Init_FdHandler (void)
+{
+       VALUE c = rb_define_class_under (mEcore, "FdHandler", rb_cObject);
+
+       rb_define_singleton_method (c, "new", c_new, 2);
+       rb_define_method (c, "delete", c_delete, 0);
+       rb_define_method (c, "fd", c_fd_get, 0);
+       rb_define_method (c, "get_active", c_get_active, 1);
+       rb_define_method (c, "set_active", c_set_active, 1);
+
+       DEF_CONST (c, ECORE_FD_, READ);
+       DEF_CONST (c, ECORE_FD_, WRITE);
+       DEF_CONST (c, ECORE_FD_, ERROR);
+}
diff --git a/src/ecore/rb_fd_handler.h b/src/ecore/rb_fd_handler.h
new file mode 100644 (file)
index 0000000..87f09f2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $Id: rb_fd_handler.h 109 2004-09-01 20: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_FD_HANDLER_H
+#define __RB_FD_HANDLER_H
+
+void Init_FdHandler (void);
+
+#endif
index 91091515d516fe6a0495e641d66bd89825910046..0612666818ced7f212710a0d3cfbdc90f97bb774 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_cursor.c 98 2004-08-26 13:12:55Z tilman $
+ * $Id: rb_cursor.c 109 2004-09-01 20:33:15Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -24,6 +24,7 @@
 #include <Ecore_X_Cursor.h>
 
 #define __RB_CURSOR_C
+#include "../ecore/rb_ecore.h"
 #include "rb_ecore_x.h"
 #include "rb_cursor.h"
 
index a18a12d8128b442b947a7ea2a7a7731573aa1ed0..f089738c5e3f6a8b97a5510f87e5e5a60fd45e70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_x.h 98 2004-08-26 13:12:55Z tilman $
+ * $Id: rb_ecore_x.h 109 2004-09-01 20:33:15Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
 #ifndef __RB_ECORE_X_H
 #define __RB_ECORE_X_H
 
-#define DEF_CONST(mod, prefix, name) \
-       rb_define_const ((mod), #name, \
-                        INT2FIX (prefix##name));
-
 VALUE mX;
 
 #endif