Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-module.c
Go to the documentation of this file.
1 /*
2  * ev-module.c
3  * This file is part of Evince
4  *
5  * Copyright (C) 2005 - Paolo Maggi
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 /* This is a modified version of ephy-module.c from Epiphany source code.
24  * Here the original copyright assignment:
25  *
26  * Copyright (C) 2003 Marco Pesenti Gritti
27  * Copyright (C) 2003, 2004 Christian Persch
28  *
29  */
30 
31 /*
32  * Modified by the gedit Team, 2005. See the AUTHORS file for a
33  * list of people on the gedit Team.
34  * See the ChangeLog files for a list of changes.
35  *
36  * $Id: gedit-module.c 5367 2006-12-17 14:29:49Z pborelli $
37  */
38 
39 /* Modified by evince team */
40 
41 #include "config.h"
42 
43 #include "ev-module.h"
44 
45 #include <gmodule.h>
46 
48 
50  GTypeModuleClass parent_class;
51 };
52 
53 struct _EvModule {
54  GTypeModule parent_instance;
55 
56  GModule *library;
57  gboolean resident;
58 
59  gchar *path;
60  GType type;
61 };
62 
63 typedef GType (*EvModuleRegisterFunc) (GTypeModule *);
64 
65 static void ev_module_init (EvModule *action);
66 static void ev_module_class_init (EvModuleClass *class);
67 
68 #define ev_module_get_type _ev_module_get_type
69 G_DEFINE_TYPE (EvModule, ev_module, G_TYPE_TYPE_MODULE)
70 
71 static gboolean
72 ev_module_load (GTypeModule *gmodule)
73 {
74  EvModule *module = EV_MODULE (gmodule);
75  EvModuleRegisterFunc register_func;
76 
77  module->library = g_module_open (module->path, 0);
78 
79  if (!module->library) {
80  g_warning ("%s", g_module_error ());
81 
82  return FALSE;
83  }
84 
85  /* extract symbols from the lib */
86  if (!g_module_symbol (module->library, "register_evince_backend",
87  (void *) &register_func)) {
88  g_warning ("%s", g_module_error ());
89  g_module_close (module->library);
90 
91  return FALSE;
92  }
93 
94  /* symbol can still be NULL even though g_module_symbol
95  * returned TRUE */
96  if (!register_func) {
97  g_warning ("Symbol 'register_evince_backend' should not be NULL");
98  g_module_close (module->library);
99 
100  return FALSE;
101  }
102 
103  module->type = register_func (gmodule);
104 
105  if (module->type == 0) {
106  g_warning ("Invalid evince backend contained by module %s", module->path);
107 
108  return FALSE;
109  }
110 
111  if (module->resident)
112  g_module_make_resident (module->library);
113 
114  return TRUE;
115 }
116 
117 static void
118 ev_module_unload (GTypeModule *gmodule)
119 {
120  EvModule *module = EV_MODULE (gmodule);
121 
122  g_module_close (module->library);
123  module->library = NULL;
124 }
125 
126 const gchar *
128 {
129  g_return_val_if_fail (EV_IS_MODULE (module), NULL);
130 
131  return module->path;
132 }
133 
134 GObject *
136 {
137  g_return_val_if_fail (EV_IS_MODULE (module), NULL);
138 
139  if (module->type == 0)
140  return NULL;
141 
142  return g_object_new (module->type, NULL);
143 }
144 
145 GType
147 {
148  g_return_val_if_fail (EV_IS_MODULE (module), 0);
149 
150  return module->type;
151 }
152 
153 static void
155 {
156 }
157 
158 static void
159 ev_module_finalize (GObject *object)
160 {
161  EvModule *module = EV_MODULE (object);
162 
163  g_free (module->path);
164 
165  G_OBJECT_CLASS (ev_module_parent_class)->finalize (object);
166 }
167 
168 static void
170 {
171  GObjectClass *object_class = G_OBJECT_CLASS (class);
172  GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
173 
174  object_class->finalize = ev_module_finalize;
175 
176  module_class->load = ev_module_load;
177  module_class->unload = ev_module_unload;
178 }
179 
180 EvModule *
181 _ev_module_new (const gchar *path,
182  gboolean resident)
183 {
184  EvModule *result;
185 
186  g_return_val_if_fail (path != NULL && path[0] != '\0', NULL);
187 
188  result = g_object_new (EV_TYPE_MODULE, NULL);
189 
190  g_type_module_set_name (G_TYPE_MODULE (result), path);
191  result->path = g_strdup (path);
192  result->resident = resident;
193 
194  return result;
195 }