Commit 05250dc8a68ca704386e997ad1da3227d1b87a05
1 parent
3a7c0254
Exists in
master
and in
4 other branches
Refactoring plugin engine.
Showing
3 changed files
with
77 additions
and
3 deletions
Show diff stats
configure.ac
| ... | ... | @@ -86,7 +86,7 @@ dnl INSTALL_PACKAGES="windows-lib ${INSTALL_PACKAGES}" |
| 86 | 86 | *) |
| 87 | 87 | app_cv_osname="linux" |
| 88 | 88 | |
| 89 | - CFLAGS="$CFLAGS -pthread" | |
| 89 | + CFLAGS="$CFLAGS -pthread -DLIBDIR=\$(libdir)" | |
| 90 | 90 | LDFLAGS="$LDFLAGS -pthread" |
| 91 | 91 | |
| 92 | 92 | dnl INSTALL_PACKAGES="linux-lib ${INSTALL_PACKAGES}" | ... | ... |
src/include/pw3270/application.h
| ... | ... | @@ -69,8 +69,7 @@ |
| 69 | 69 | void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type); |
| 70 | 70 | PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app); |
| 71 | 71 | |
| 72 | -// gboolean pw3270_settings_set_int(const gchar *key, gint value); | |
| 73 | - | |
| 72 | + void pw3270_application_plugin_foreach(GApplication *app, GFunc func, gpointer user_data); | |
| 74 | 73 | |
| 75 | 74 | // Tools |
| 76 | 75 | GtkBuilder * pw3270_application_get_builder(const gchar *name); | ... | ... |
src/objects/application/application.c
| ... | ... | @@ -54,6 +54,8 @@ |
| 54 | 54 | |
| 55 | 55 | GSettings * settings; |
| 56 | 56 | |
| 57 | + GSList * plugins; ///< @brief Handlers of the loaded plugins. | |
| 58 | + | |
| 57 | 59 | PW3270_UI_STYLE ui_style; |
| 58 | 60 | |
| 59 | 61 | }; |
| ... | ... | @@ -176,12 +178,78 @@ |
| 176 | 178 | g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT); |
| 177 | 179 | } |
| 178 | 180 | |
| 181 | + // Get plugins. | |
| 182 | + { | |
| 183 | +#ifdef _WIN32 | |
| 184 | + UINT errorMode; | |
| 185 | + lib3270_autoptr(char) path = lib3270_build_data_filename("plugins",NULL); | |
| 186 | +#else | |
| 187 | + const gchar * path = G_STRINGIFY(LIBDIR) G_DIR_SEPARATOR_S G_STRINGIFY(PRODUCT_NAME) "-plugins"; | |
| 188 | +#endif // _WIN32 | |
| 189 | + | |
| 190 | + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { | |
| 191 | + | |
| 192 | + g_message("Loading plugins from %s",path); | |
| 193 | + | |
| 194 | + GError * err = NULL; | |
| 195 | + GDir * dir = g_dir_open(path,0,&err); | |
| 196 | + | |
| 197 | + if(dir) { | |
| 198 | + | |
| 199 | + const gchar *name; | |
| 200 | + while((name = g_dir_read_name(dir)) != NULL) { | |
| 201 | + | |
| 202 | + g_autofree gchar *filename = g_build_filename(path,name,NULL); | |
| 203 | + | |
| 204 | + if(g_str_has_suffix(filename,G_MODULE_SUFFIX)) { | |
| 205 | + | |
| 206 | + g_message("Loading %s",filename); | |
| 207 | + | |
| 208 | + GModule *handle = g_module_open(filename,G_MODULE_BIND_LOCAL); | |
| 209 | + | |
| 210 | + if(handle) { | |
| 211 | + | |
| 212 | + app->plugins = g_slist_append(app->plugins,handle); | |
| 213 | + | |
| 214 | + } else { | |
| 215 | + | |
| 216 | + g_warning("Can't load %s: %s",filename,g_module_error()); | |
| 217 | + | |
| 218 | + } | |
| 219 | + | |
| 220 | + } | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + } | |
| 225 | + | |
| 226 | + g_dir_close(dir); | |
| 227 | + } | |
| 228 | + | |
| 229 | + if(err) { | |
| 230 | + | |
| 231 | + g_warning("Can't load plugins from %s: %s",path,err->message); | |
| 232 | + g_error_free(err); | |
| 233 | + | |
| 234 | + } | |
| 235 | + | |
| 236 | + | |
| 237 | + } | |
| 238 | + | |
| 239 | + } | |
| 240 | + | |
| 179 | 241 | } |
| 180 | 242 | |
| 243 | + | |
| 181 | 244 | static void finalize(GObject *object) { |
| 182 | 245 | |
| 183 | 246 | pw3270Application * application = PW3270_APPLICATION(object); |
| 184 | 247 | |
| 248 | + if(application->plugins) { | |
| 249 | + g_slist_free_full(application->plugins,(GDestroyNotify) g_module_close); | |
| 250 | + application->plugins = NULL; | |
| 251 | + } | |
| 252 | + | |
| 185 | 253 | if(application->settings) { |
| 186 | 254 | g_object_unref(application->settings); |
| 187 | 255 | application->settings = NULL; |
| ... | ... | @@ -320,3 +388,10 @@ |
| 320 | 388 | return PW3270_APPLICATION(app)->settings; |
| 321 | 389 | |
| 322 | 390 | } |
| 391 | + | |
| 392 | + void pw3270_application_plugin_foreach(GApplication *app, GFunc func, gpointer user_data) { | |
| 393 | + | |
| 394 | + g_return_if_fail(PW3270_IS_APPLICATION(app)); | |
| 395 | + g_slist_foreach(PW3270_APPLICATION(app)->plugins, func, user_data); | |
| 396 | + | |
| 397 | + } | ... | ... |