2 * heavily based on code from Gedit, which is based on code from Ephiphany
4 * Copyright (C) 2003 Marco Pesenti Gritti
5 * Copyright (C) 2003, 2004 Christian Persch
6 * Copyright (C) 2005 - Paolo Maggi
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
26 #include "rb-module.h"
31 typedef struct _RBModuleClass RBModuleClass
;
35 GTypeModuleClass parent_class
;
40 GTypeModule parent_instance
;
49 typedef GType (*RBModuleRegisterFunc
) (GTypeModule
*);
51 static void rb_module_init (RBModule
*action
);
52 static void rb_module_class_init (RBModuleClass
*class);
54 static GObjectClass
*parent_class
= NULL
;
56 G_DEFINE_TYPE (RBModule
, rb_module
, G_TYPE_TYPE_MODULE
)
59 rb_module_load (GTypeModule
*gmodule
)
61 RBModule
*module
= RB_MODULE (gmodule
);
62 RBModuleRegisterFunc register_func
;
64 rb_debug ("Loading %s", module
->path
);
66 module
->library
= g_module_open (module
->path
, 0);
68 if (module
->library
== NULL
) {
69 g_warning (g_module_error());
74 /* extract symbols from the lib */
75 if (!g_module_symbol (module
->library
, "register_rb_plugin", (void *)®ister_func
)) {
76 g_warning (g_module_error ());
77 g_module_close (module
->library
);
81 g_assert (register_func
);
83 module
->type
= register_func (gmodule
);
84 if (module
->type
== 0) {
85 g_warning ("Invalid rb plugin contained by module %s", module
->path
);
93 rb_module_unload (GTypeModule
*gmodule
)
95 RBModule
*module
= RB_MODULE (gmodule
);
97 rb_debug ("Unloading %s", module
->path
);
99 g_module_close (module
->library
);
101 module
->library
= NULL
;
106 rb_module_get_path (RBModule
*module
)
108 g_return_val_if_fail (RB_IS_MODULE (module
), NULL
);
114 rb_module_new_object (RBModule
*module
)
117 rb_debug ("Creating object of type %s", g_type_name (module
->type
));
119 if (module
->type
== 0) {
123 obj
= g_object_new (module
->type
,
124 "name", module
->name
,
130 rb_module_init (RBModule
*module
)
132 rb_debug ("RBModule %p initialising", module
);
136 rb_module_finalize (GObject
*object
)
138 RBModule
*module
= RB_MODULE (object
);
140 rb_debug ("GeditModule %p finalising", module
);
142 g_free (module
->path
);
144 G_OBJECT_CLASS (parent_class
)->finalize (object
);
148 rb_module_class_init (RBModuleClass
*class)
150 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
151 GTypeModuleClass
*module_class
= G_TYPE_MODULE_CLASS (class);
153 parent_class
= (GObjectClass
*) g_type_class_peek_parent (class);
155 object_class
->finalize
= rb_module_finalize
;
157 module_class
->load
= rb_module_load
;
158 module_class
->unload
= rb_module_unload
;
162 rb_module_new (const gchar
*path
, const char *module
)
166 if (path
== NULL
|| path
[0] == '\0') {
170 result
= g_object_new (RB_TYPE_MODULE
, NULL
);
172 g_type_module_set_name (G_TYPE_MODULE (result
), path
);
173 result
->path
= g_strdup (path
);
174 result
->name
= g_strdup (module
);