forked from nemomobile/mce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mce-modules.c
230 lines (185 loc) · 4.83 KB
/
mce-modules.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
* @file mce-modules.c
* Module handling for MCE
* <p>
* Copyright © 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
* <p>
* @author David Weinehall <[email protected]>
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce 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 mce. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glib.h>
#include <gmodule.h>
#include <stdio.h> /* fprintf(), stdout */
#include <string.h> /* strcmp() */
#include "mce.h" /* module_info_struct */
#include "mce-modules.h"
#include "mce-log.h" /* mce_log(), LL_* */
#include "mce-conf.h" /* mce_conf_get_string(),
* mce_conf_get_string_list()
*/
/** List of all loaded modules */
static GSList *modules = NULL;
/**
* Dump information about mce modules to stdout
*/
void mce_modules_dump_info(void)
{
GModule *module;
gint i;
for (i = 0; (module = g_slist_nth_data(modules, i)) != NULL; i++) {
const gchar *modulename = g_module_name(module);
module_info_struct *modinfo;
gchar *tmp = NULL;
gpointer mip;
fprintf(stdout,
_("\n"
"Module: %s\n"),
modulename);
if (g_module_symbol(module,
"module_info",
&mip) == FALSE) {
fprintf(stdout,
" %-32s\n",
"module lacks information");
continue;
}
modinfo = (module_info_struct *)mip;
fprintf(stdout,
" %-32s %s\n",
_("name:"),
modinfo->name ? modinfo->name : _("<undefined>"));
if (modinfo->depends != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->depends));
fprintf(stdout,
" %-32s %s\n",
_("depends:"),
tmp ? tmp : "");
g_free(tmp);
tmp = NULL;
if (modinfo->recommends != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->recommends));
fprintf(stdout,
" %-32s %s\n",
_("recommends:"),
tmp ? tmp : "");
g_free(tmp);
tmp = NULL;
if (modinfo->provides != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->provides));
fprintf(stdout,
" %-32s %s\n",
_("provides:"),
tmp ? tmp : "");
g_free(tmp);
tmp = NULL;
if (modinfo->enhances != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->enhances));
fprintf(stdout,
" %-32s %s\n",
_("enhances:"),
tmp ? tmp : "");
g_free(tmp);
tmp = NULL;
if (modinfo->conflicts != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->conflicts));
fprintf(stdout,
" %-32s %s\n",
_("conflicts:"),
tmp ? tmp : "");
g_free(tmp);
tmp = NULL;
if (modinfo->replaces != NULL)
tmp = g_strjoinv(",", (gchar **)(modinfo->replaces));
fprintf(stdout,
" %-32s %s\n",
_("replaces:"),
tmp ? tmp : "");
g_free(tmp);
fprintf(stdout,
" %-32s %d\n",
_("priority:"),
modinfo->priority);
}
}
/** Construct path for named mce plugin
*
* @param directory Location of the plugin
* @module_name Name of the plugin
*
* @return Path to shared object
*/
static gchar * mce_modules_build_path(const gchar *directory,
const gchar *module_name)
{
return g_strdup_printf("%s/%s.so", directory, module_name);
}
/**
* Init function for the mce-modules component
*
* @return TRUE on success, FALSE on failure
*/
gboolean mce_modules_init(void)
{
gchar **modlist = NULL;
gsize length;
gchar *path = NULL;
/* Get the module path */
path = mce_conf_get_string(MCE_CONF_MODULES_GROUP,
MCE_CONF_MODULES_PATH,
DEFAULT_MCE_MODULE_PATH);
/* Get the list modules to load */
modlist = mce_conf_get_string_list(MCE_CONF_MODULES_GROUP,
MCE_CONF_MODULES_MODULES,
&length);
if (modlist != NULL) {
gint i;
for (i = 0; modlist[i]; i++) {
GModule *module;
gchar *tmp = mce_modules_build_path(path, modlist[i]);
mce_log(LL_INFO,
"Loading module: %s from %s",
modlist[i], path);
if ((module = g_module_open(tmp, 0)) != NULL) {
/* XXX: check dependencies, conflicts, et al */
modules = g_slist_prepend(modules, module);
} else {
const char *err = g_module_error();
mce_log(LL_ERR, "%s", err ?: "unknown error");
mce_log(LL_ERR,
"Failed to load module: %s; skipping",
modlist[i]);
}
g_free(tmp);
}
g_strfreev(modlist);
}
g_free(path);
return TRUE;
}
/**
* Exit function for the mce-modules component
*/
void mce_modules_exit(void)
{
GModule *module;
gint i;
if (modules != NULL) {
for (i = 0; (module = g_slist_nth_data(modules, i)) != NULL; i++) {
g_module_close(module);
}
g_slist_free(modules);
modules = NULL;
}
return;
}