[Kazehakase-cvs] kazehakase-svn [2914] * src/kz-embed-module.c: A new file for embed module.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Tue Mar 20 15:35:23 JST 2007


Revision: 2914
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=2914
Author:   ikezoe
Date:     2007-03-20 15:35:23 +0900 (Tue, 20 Mar 2007)

Log Message:
-----------
* src/kz-embed-module.c: A new file for embed module.
* src/Makefile.am: Add kz-embed-module.c.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/src/Makefile.am

Added Paths:
-----------
    kazehakase/trunk/src/kz-embed-module.c

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2007-03-20 05:49:01 UTC (rev 2913)
+++ kazehakase/trunk/ChangeLog	2007-03-20 06:35:23 UTC (rev 2914)
@@ -1,5 +1,10 @@
 2007-03-20  Hiroyuki Ikezoe  <poinc****@ikezo*****>
 
+	* src/kz-embed-module.c: A new file for embed module.
+	* src/Makefile.am: Add kz-embed-module.c.
+
+2007-03-20  Hiroyuki Ikezoe  <poinc****@ikezo*****>
+
 	* configure.in: Define embeddir.
 
 2007-03-20  Hiroyuki Ikezoe  <poinc****@ikezo*****>

Modified: kazehakase/trunk/src/Makefile.am
===================================================================
--- kazehakase/trunk/src/Makefile.am	2007-03-20 05:49:01 UTC (rev 2913)
+++ kazehakase/trunk/src/Makefile.am	2007-03-20 06:35:23 UTC (rev 2914)
@@ -15,6 +15,7 @@
 	-DKZ_SYSCONFDIR=\""$(sysconfdir)/$(PACKAGE)"\" \
 	-DKZ_DATADIR=\""$(datadir)/$(PACKAGE)"\" \
 	-DKZ_SEARCH_MODULEDIR=\""$(searchdir)"\" \
+	-DKZ_EMBED_MODULEDIR=\""$(embeddir)"\" \
 	-DGTK_DISABLE_DEPRECATED=1 \
 	-DGDK_DISABLE_DEPRECATED=1 \
 	-DG_LOG_DOMAIN=\"Kazehakase\" \
@@ -109,6 +110,7 @@
 libkazehakase_la_SOURCES = \
 	kz-app.c \
 	kz-embed.c \
+	kz-embed-module.c \
 	kz-embed-event.c \
 	kz-gesture.c \
 	kz-tab-label.c \

Added: kazehakase/trunk/src/kz-embed-module.c
===================================================================
--- kazehakase/trunk/src/kz-embed-module.c	2007-03-20 05:49:01 UTC (rev 2913)
+++ kazehakase/trunk/src/kz-embed-module.c	2007-03-20 06:35:23 UTC (rev 2914)
@@ -0,0 +1,180 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  Copyright (C) 2007 Hiroyuki Ikezoe
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib/gi18n.h>
+#include <gmodule.h>
+
+#include "kazehakase.h"
+#include "glib-utils.h"
+#include "kz-embed.h"
+
+typedef struct _KzEmbedModule KzEmbedModule;
+typedef struct _KzEmbedModuleClass KzEmbedModuleClass;
+
+struct _KzEmbedModule
+{
+	GTypeModule  object;
+	GModule *library;
+
+	void             (*init)     (GTypeModule *module);
+	void             (*exit)     (void);
+	GtkWidget       *(*create)   (const gchar *url);
+	gchar *path;
+};
+
+struct _KzEmbedModuleClass
+{
+	GTypeModuleClass parent_class;
+};
+
+GType kz_embed_module_get_type (void) G_GNUC_CONST;
+
+G_DEFINE_TYPE (KzEmbedModule, kz_embed_module, G_TYPE_TYPE_MODULE)
+
+#define KZ_TYPE_EMBED_MODULE      (kz_embed_module_get_type ())
+#define KZ_EMBED_MODULE(module)   (G_TYPE_CHECK_INSTANCE_CAST ((module), KZ_TYPE_EMBED_MODULE, KzEmbedModule))
+
+static GSList *loaded_embed;
+
+static gboolean
+kz_embed_module_load (GTypeModule *module)
+{
+	KzEmbedModule *s_module = KZ_EMBED_MODULE(module); 
+	gpointer initp, exitp, createp;
+
+	s_module->library = g_module_open(s_module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+	if (!s_module->library)
+	{
+		g_warning(g_module_error());
+		return FALSE;
+	}
+
+	/* exsact symbols from the lib */
+	if (!g_module_symbol(s_module->library, "kz_embed_module_init", &initp) ||
+	    !g_module_symbol(s_module->library, "kz_embed_module_exit", &exitp) ||
+	    !g_module_symbol(s_module->library, "kz_embed_module_create", &createp))
+	{
+		g_warning(g_module_error());
+		g_module_close(s_module->library);
+
+		return FALSE;
+	}
+
+	s_module->init   = initp;
+	s_module->exit   = exitp;
+	s_module->create = createp;
+
+	s_module->init(module);
+
+	return TRUE;
+}
+ 
+static void
+kz_embed_module_unload (GTypeModule *module)
+{
+	KzEmbedModule *s_module = KZ_EMBED_MODULE(module);
+
+	s_module->exit();
+
+	g_module_close(s_module->library);
+	s_module->library = NULL;
+
+	s_module->init   = NULL;
+	s_module->exit   = NULL;
+	s_module->create = NULL;
+}
+
+static void
+kz_embed_module_finalize (GObject *object)
+{
+	KzEmbedModule *module = KZ_EMBED_MODULE(object);
+
+	g_free(module->path);
+
+	G_OBJECT_CLASS(kz_embed_module_parent_class)->finalize(object);
+}
+static void
+kz_embed_module_class_init (KzEmbedModuleClass *klass)
+{
+	GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS(klass);
+	GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+	module_class->load   = kz_embed_module_load;
+	module_class->unload = kz_embed_module_unload;
+
+	gobject_class->finalize = kz_embed_module_finalize;
+} 
+
+static void
+kz_embed_module_init (KzEmbedModule *module)
+{
+}
+
+static GtkWidget *
+kz_embed_module_create (KzEmbedModule *module, const gchar *url)
+{
+	GtkWidget *embed = NULL;
+	if (g_type_module_use(G_TYPE_MODULE(module)))
+	{
+		embed = module->create(url);
+		g_type_module_unuse(G_TYPE_MODULE(module));
+		return embed;
+	}
+	return NULL;
+}
+ 
+GtkWidget *
+kz_embed_new (const gchar *name, const gchar *url)
+{
+	GSList *l;
+	gchar *module_path;
+	KzEmbedModule *module;
+	GtkWidget *embed = NULL;
+
+	for (l = loaded_embed; l; l = l->next)
+	{
+		module = l->data;
+
+		if (strcmp(G_TYPE_MODULE (module)->name, name) == 0)
+			return kz_embed_module_create(module, url);
+	}
+
+	if (g_module_supported())
+	{
+		module_path = g_module_build_path(KZ_EMBED_MODULEDIR, name);
+
+		if (module_path)
+		{
+			module = g_object_new(KZ_TYPE_EMBED_MODULE, NULL);
+
+			g_type_module_set_name(G_TYPE_MODULE(module), name);
+			module->path = g_strdup(module_path);
+
+			loaded_embed = g_slist_prepend(loaded_embed,
+					module);
+
+			embed = kz_embed_module_create(module, url);
+			g_free(module_path);
+		}
+	}
+ 
+	return embed;
+}
+





More information about the Kazehakase-cvs mailing list
Back to archive index