gnome-scan r635 - in trunk: . lib modules



Author: phsadleder
Date: Mon Nov 17 14:51:36 2008
New Revision: 635
URL: http://svn.gnome.org/viewvc/gnome-scan?rev=635&view=rev

Log:
Port module loading to vala.


Added:
   trunk/lib/gnome-scan-module-helper.h
   trunk/lib/gnome-scan-module.vala
Removed:
   trunk/lib/gnome-scan-module.c
   trunk/lib/gnome-scan-module.h
Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/lib/Makefile.am
   trunk/modules/gsane-backend.c
   trunk/modules/gsane-scanner.c
   trunk/modules/gsfile-backend.c
   trunk/modules/gsfile-scanner.c

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Mon Nov 17 14:51:36 2008
@@ -16,10 +16,12 @@
 	gnome-scan-common.vala	\
 	gnome-scan-option.vala	\
 	gnome-scan-option-widget.vala \
+	gnome-scan-module.vala \
 	$(NULL)
 
 lib SONAME@_la_VALAPKGADD = \
 	--pkg=glib-2.0	\
+	--pkg=gmodule-2.0 \ 
 	--pkg=gtk+-2.0	\
 	--pkg=gconf-2.0 \
 	--vapidir=$(top_srcdir) --pkg=config \
@@ -54,8 +56,6 @@
 	gnome-scan-dialog.c          \
 	gnome-scan-module-manager.h          \
 	gnome-scan-module-manager.c          \
-	gnome-scan-module.h          \
-	gnome-scan-module.c          \
 	gnome-scan-param-specs.c          \
 	gnome-scan-param-specs.h          \
 	gnome-scan-init.c          \

Added: trunk/lib/gnome-scan-module-helper.h
==============================================================================
--- (empty file)
+++ trunk/lib/gnome-scan-module-helper.h	Mon Nov 17 14:51:36 2008
@@ -0,0 +1,109 @@
+/* Gnome Scan - Scan as easy as you print
+ * Copyright  2007  Ãtienne Bersac <bersace03 laposte net>
+ *
+ * Gnome Scan 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.
+ * 
+ * gnome-scan 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 gnome-scan.  If not, write to:
+ *
+ *	the Free Software Foundation, Inc.
+ *	51 Franklin Street, Fifth Floor
+ *	Boston, MA 02110-1301, USA
+ */
+
+#include <glib-object.h>
+#include <gmodule.h>
+
+G_BEGIN_DECLS
+
+/**
+ * GS_DEFINE_MODULE_TYPE:
+ * @TN: Capitalized type name
+ * @t_n: Type function prefix
+ * @T_P: Parent GType macro
+ *
+ * Convenient macro used to declare a dynamicly registered type.
+ *
+ * For example:
+ * <programlisting>
+GS_DEFINE_MODULE_TYPE (FooBar, foo_bar, G_TYPE_OBJECT)
+ * </programlisting>
+ *
+ * expands to:
+ *
+ * <programlisting>
+static void     foo_bar_init       (FooBar      *self);	
+static void     foo_bar_class_init (FooBarClass *klass);	
+
+static GType foo_bar_type = 0;	
+GType	
+foo_bar_get_type () 
+{ return foo_bar_type; } 
+
+void 
+foo_bar_register_type (GTypeModule *module)	
+{	
+  if (!foo_bar_type)
+    {	
+      static const GTypeInfo type_info =	
+      {	
+        sizeof (FooBarClass),						
+        (GBaseInitFunc) NULL,					
+        (GBaseFinalizeFunc) NULL,				
+        (GClassInitFunc) foo_bar_class_init, 		
+        NULL,
+        NULL,
+        sizeof (FooBar),							
+        0,
+        (GInstanceInitFunc) foo_bar_init			
+      }; 
+
+      foo_bar_type =	
+        g_type_module_register_type (module, G_TYPE_OBJECT,	
+                                     g_intern_static_string ("FooBar"), &type_info, 0);	
+    } 
+}
+ * </programlisting>
+ *
+ * See: G_DEFINE_TYPE
+ **/
+#define GS_DEFINE_MODULE_TYPE(TN, t_n, T_P)			static void     t_n##_init       (TN      *self);	\
+static void     t_n##_class_init (TN##Class *klass);	\
+\
+static GType t_n##_type = 0;	\
+GType	\
+t_n##_get_type () \
+{ return t_n##_type; } \
+\
+void \
+t_n##_register_type (GTypeModule *module)	\
+{	\
+  if (!t_n##_type)\
+    {	\
+      static const GTypeInfo type_info =	\
+      {	\
+        sizeof (TN##Class),						\
+        (GBaseInitFunc) NULL,					\
+        (GBaseFinalizeFunc) NULL,				\
+        (GClassInitFunc) t_n##_class_init, 		\
+        NULL,           /* class_finalize */	\
+        NULL,           /* class_data     */	\
+        sizeof (TN),							\
+        0,              /* n_preallocs    */	\
+        (GInstanceInitFunc) t_n##_init			\
+      }; \
+\
+      t_n##_type =	\
+        g_type_module_register_type (module, T_P,	\
+                                     g_intern_static_string (#TN), &type_info, 0);	\
+    } \
+}
+

Added: trunk/lib/gnome-scan-module.vala
==============================================================================
--- (empty file)
+++ trunk/lib/gnome-scan-module.vala	Mon Nov 17 14:51:36 2008
@@ -0,0 +1,70 @@
+using GLib;
+
+namespace Gnome {
+	namespace Scan {
+		
+		/**
+		 * SECTION: gnome-scan-module
+		 * @short_description: Module loading and initialization
+		 *
+		 * A module represent the library opened with #GModule where are
+		 * stored a list of #GObjects.
+		 **/
+		public class Module : TypeModule {
+
+			[Description(nick="Filename", blurb="Library filename for use with GModule")]
+			public string filename { get; construct set; }
+
+			private GLib.Module library;
+			private InitFunc init;
+			private	FinalizeFunc finalize;
+
+			public delegate void InitFunc (Module module);
+			public delegate void FinalizeFunc ();
+
+			public override bool load () {
+				library = GLib.Module.open (filename, ModuleFlags.BIND_MASK);
+				if (library == null) {
+					warning (GLib.Module.error());
+					return false;
+				}
+				
+				void * init_function;
+				void * finalize_function;
+				
+				if (!library.symbol ("gnome_scan_module_init", out init_function) ||
+					!library.symbol ("gnome_scan_module_finalize", out finalize_function))
+				{
+					warning ("%s does not contain a valid %s", filename, ( this.get_type().name() ));
+					return false;
+				}
+				
+				init = (InitFunc) init_function;
+				finalize = (FinalizeFunc) finalize_function;
+				
+				init (this);	
+				
+				return true;
+			}
+			
+			public override void unload () {
+				finalize ();
+			}
+			
+
+			/**
+			 * gnome_scan_module_new:
+			 * @filename: The path to shared object
+			 * 
+			 * Open and initialize a new module. This function should be used only
+			 * by #GnomeScanModuleManager.
+			 * 
+			 * Returns: a new #GnomeScanModule
+			 **/
+			public Module (string filename) {
+				this.filename = filename;
+			}
+			
+		}
+	}
+}
\ No newline at end of file

Modified: trunk/modules/gsane-backend.c
==============================================================================
--- trunk/modules/gsane-backend.c	(original)
+++ trunk/modules/gsane-backend.c	Mon Nov 17 14:51:36 2008
@@ -21,6 +21,7 @@
 
 #include <sane/sane.h>
 #include <gnome-scan-module.h>
+#include <gnome-scan-module-helper.h>
 #include "gsane-backend.h"
 #include "gsane-scanner.h"
 

Modified: trunk/modules/gsane-scanner.c
==============================================================================
--- trunk/modules/gsane-scanner.c	(original)
+++ trunk/modules/gsane-scanner.c	Mon Nov 17 14:51:36 2008
@@ -23,6 +23,7 @@
 #include <gegl.h>
 #include <string.h>
 #include <gnome-scan-module.h>
+#include <gnome-scan-module-helper.h>
 #include <gnome-scan-param-specs.h>
 #include "gsane-common.h"
 #include "gsane-scanner.h"

Modified: trunk/modules/gsfile-backend.c
==============================================================================
--- trunk/modules/gsfile-backend.c	(original)
+++ trunk/modules/gsfile-backend.c	Mon Nov 17 14:51:36 2008
@@ -21,6 +21,7 @@
  */
 
 #include <gnome-scan-module.h>
+#include <gnome-scan-module-helper.h>
 #include "gsfile-backend.h"
 #include "gsfile-scanner.h"
 

Modified: trunk/modules/gsfile-scanner.c
==============================================================================
--- trunk/modules/gsfile-scanner.c	(original)
+++ trunk/modules/gsfile-scanner.c	Mon Nov 17 14:51:36 2008
@@ -25,6 +25,7 @@
 
 #include <glib/gi18n.h>
 #include <gnome-scan-module.h>
+#include <gnome-scan-module-helper.h>
 #include <gnome-scan-param-specs.h>
 #include "gsfile-pspec.h"
 #include "gsfile-scanner.h"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]