Implement GPluginSource
GPluginSource will be used by the manager to help modularize the refresh method
and eventually implement static plugins.
Testing Done:
Ran the unit tests
Reviewed at https://reviews.imfreedom.org/r/1778/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/gplugin-source.c Sat Sep 17 21:54:09 2022 -0500
@@ -0,0 +1,68 @@
+ * Copyright (C) 2011-2022 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 this library; if not, see <https://www.gnu.org/licenses/>. +#include "gplugin-source.h" + * An interface that the manager will call during refresh to query plugins. +G_DEFINE_INTERFACE(GPluginSource, gplugin_source, G_TYPE_OBJECT) +/****************************************************************************** + * GInterface implementation + *****************************************************************************/ +gplugin_source_default_init(G_GNUC_UNUSED GPluginSourceInterface *iface) { +/****************************************************************************** + *****************************************************************************/ + * @source: The instance. + * This method is called when [method@GPlugin.Manager.refresh] is running. The + * source should scan its available sources for plugins. For the filesystem + * source, this is paths that have been registered with the manager. + * The implementation should return TRUE if it found a new unqueried plugin, + * which will tell the manager to continue scanning. + * Returns: %TRUE if an unqueried plugin was found, %FALSE otherwise. +gplugin_source_scan(GPluginSource *source) { + GPluginSourceInterface *iface = NULL; + g_return_val_if_fail(GPLUGIN_IS_SOURCE(source), FALSE); + iface = GPLUGIN_SOURCE_GET_IFACE(source); + if(iface && iface->scan) { + return iface->scan(source); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/gplugin-source.h Sat Sep 17 21:54:09 2022 -0500
@@ -0,0 +1,45 @@
+ * Copyright (C) 2011-2022 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 this library; if not, see <https://www.gnu.org/licenses/>. +#ifndef GPLUGIN_SOURCE_H +#define GPLUGIN_SOURCE_H +#include <glib-object.h> +#define GPLUGIN_TYPE_SOURCE (gplugin_source_get_type()) +G_DECLARE_INTERFACE(GPluginSource, gplugin_source, GPLUGIN, SOURCE, +struct _GPluginSourceInterface { + gboolean (*scan)(GPluginSource *source); +gboolean gplugin_source_scan(GPluginSource *source); +#endif /* GPLUGIN_SOURCE_H */ --- a/gplugin/meson.build Sat Sep 17 21:53:11 2022 -0500
+++ b/gplugin/meson.build Sat Sep 17 21:54:09 2022 -0500
@@ -35,10 +35,12 @@
GPLUGIN_PRIVATE_HEADERS = [
GPLUGIN_PRIVATE_SOURCES = [
GPLUGIN_PRIVATE_BUILT_HEADERS = [
--- a/gplugin/tests/meson.build Sat Sep 17 21:53:11 2022 -0500
+++ b/gplugin/tests/meson.build Sat Sep 17 21:54:09 2022 -0500
@@ -71,6 +71,10 @@
dependencies : [gplugin_dep, GLIB, GOBJECT])
+e = executable('test-source', 'test-source.c', + dependencies : [gplugin_dep, GLIB, GOBJECT]) e = executable('test-version-compare', 'test-version-compare.c',
dependencies : [gplugin_dep, GLIB, GOBJECT])
test('Version Compare', e)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/test-source.c Sat Sep 17 21:54:09 2022 -0500
@@ -0,0 +1,101 @@
+ * Copyright (C) 2011-2020 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 this library; if not, see <https://www.gnu.org/licenses/>. +#include "gplugin-source.h" +/****************************************************************************** + * TestSource Implementation + *****************************************************************************/ +G_DECLARE_FINAL_TYPE(TestGPluginSource, test_gplugin_source, TEST_GPLUGIN, +struct _TestGPluginSource { +test_gplugin_source_scan(GPluginSource *source) { + TestGPluginSource *test_source = TEST_GPLUGIN_SOURCE(source); + return test_source->scan_result; +test_gplugin_source_iface_init(GPluginSourceInterface *iface) { + iface->scan = test_gplugin_source_scan; +G_DEFINE_TYPE_WITH_CODE(TestGPluginSource, test_gplugin_source, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(GPLUGIN_TYPE_SOURCE, test_gplugin_source_iface_init)) +test_gplugin_source_init(G_GNUC_UNUSED TestGPluginSource *source) { +test_gplugin_source_class_init(G_GNUC_UNUSED TestGPluginSourceClass *klass) { +test_gplugin_source_new(gboolean scan_result) { + TestGPluginSource *source = g_object_new(test_gplugin_source_get_type(), NULL); + source->scan_result = scan_result; + return GPLUGIN_SOURCE(source); +/****************************************************************************** + *****************************************************************************/ +test_gplugin_source_scan_false(void) { + GPluginSource *source = test_gplugin_source_new(FALSE); + g_assert_false(gplugin_source_scan(source)); + g_clear_object(&source); +test_gplugin_source_scan_true(void) { + GPluginSource *source = test_gplugin_source_new(TRUE); + g_assert_true(gplugin_source_scan(source)); + g_clear_object(&source); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) + g_test_init(&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); + g_test_add_func("/source/scan/false", test_gplugin_source_scan_false); + g_test_add_func("/source/scan/true", test_gplugin_source_scan_true); --- a/po/POTFILES Sat Sep 17 21:53:11 2022 -0500
+++ b/po/POTFILES Sat Sep 17 21:54:09 2022 -0500
@@ -16,6 +16,7 @@
gplugin/gplugin-plugin-info.c
gplugin/gplugin-private.c
+gplugin/gplugin-source.c gplugin/gplugin-version.c