[gnome-software] plugins: Add a dummy plugin for self-test use



commit 5864fc7e856bc276b7e1855cb1f6b1d90b0d2eb2
Author: Richard Hughes <richard hughsie com>
Date:   Thu Mar 7 10:35:51 2013 +0000

    plugins: Add a dummy plugin for self-test use

 configure.ac                  |    1 +
 src/Makefile.am               |    3 +
 src/gs-self-test.c            |    6 ++
 src/plugins/Makefile.am       |   28 +++++++
 src/plugins/README            |   56 ++++++++++++++
 src/plugins/gs-plugin-dummy.c |  164 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 258 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3f6d7e1..c907d02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,7 @@ Makefile
 po/Makefile.in
 data/Makefile
 src/Makefile
+src/plugins/Makefile
 ])
 AC_OUTPUT
 
diff --git a/src/Makefile.am b/src/Makefile.am
index a63afb7..b9e190d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,6 @@
+SUBDIRS =                                              \
+       plugins
+
 INCLUDES =                                             \
        $(GLIB_CFLAGS)                                  \
        $(GTK_CFLAGS)                                   \
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index e984b1d..b773ee4 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -57,6 +57,12 @@ gs_plugin_loader_func (void)
        g_assert_no_error (error);
        g_assert (ret);
 
+       /* enable some that will give us predictable results */
+       ret = gs_plugin_loader_set_enabled (loader, "dummy", TRUE);
+       g_assert (ret);
+       ret = gs_plugin_loader_set_enabled (loader, "notgoingtoexist", TRUE);
+       g_assert (!ret);
+
        g_object_unref (loader);
 }
 
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
new file mode 100644
index 0000000..8233ed3
--- /dev/null
+++ b/src/plugins/Makefile.am
@@ -0,0 +1,28 @@
+## We require new-style dependency handling.
+AUTOMAKE_OPTIONS = 1.7
+
+AM_CPPFLAGS =                                          \
+       $(GLIB_CFLAGS)                                  \
+       $(GTK_CFLAGS)                                   \
+       $(SQLITE_CFLAGS)                                \
+       $(PACKAGEKIT_CFLAGS)                            \
+       -DBINDIR=\"$(bindir)\"                          \
+       -DDATADIR=\"$(datadir)\"                        \
+       -DG_LOG_DOMAIN=\"GsPlugin\"                     \
+       -DLIBDIR=\""$(libdir)"\"                        \
+       -DLOCALSTATEDIR=\""$(localstatedir)"\"          \
+       -DSBINDIR=\"$(sbindir)\"                        \
+       -DSYSCONFDIR=\""$(sysconfdir)"\"                \
+       -DTESTDATADIR=\""$(top_srcdir)/data/tests"\"    \
+       -I$(top_srcdir)/src
+
+plugindir = $(libdir)/gs-plugins
+plugin_LTLIBRARIES =                                   \
+       libgs_plugin_dummy.la
+
+libgs_plugin_dummy_la_SOURCES = gs-plugin-dummy.c
+libgs_plugin_dummy_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_dummy_la_LDFLAGS = -module -avoid-version
+libgs_plugin_dummy_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+
+-include $(top_srcdir)/git.mk
diff --git a/src/plugins/README b/src/plugins/README
new file mode 100644
index 0000000..aea4215
--- /dev/null
+++ b/src/plugins/README
@@ -0,0 +1,56 @@
+= Introduction =
+
+Plugins are modules that are loaded at runtime to provide information about
+requests and to service user actions like installing, removing and updating.
+Plugins are disabled by default, and need to be enabled manually before they
+are used.
+This allows different distributions to pick and choose how the application
+installer gathers data just by setting a single GSettings key. For instance:
+
+ SuSE has AppStream data and also uses PackageKit. The default on SuSE would be
+ to enable the 'appstream' and 'packagekit' plugins and leave the rest disabled.
+
+ Fedora doesn't have AppStream data, so it has to make do with other local data.
+ On Fedora we would enable the 'datadir-apps', 'desktop-db' and all the
+ 'hardcoded' plugins to get some sensible results. For Fedora, it probably also
+ makes sense to write a plugin that interfaces with FAS or fedora-tagger to get
+ the extra metadata for uninstalled applications.
+
+Plugins also have a priority system where the largest number gets run first.
+That means if one plugin requires some property or metadata set by another
+plugin then it *must* have a priority value that is greater to ensure the
+property is available.
+
+As we are letting the distribution pick and choose what plugins are run, we need
+a way to 'refine' the results. For instance, the 'packagekit' plugin returns
+applications with a kind GS_APP_KIND_PACKAGE which will not be returned to the
+UI for display as they are not applications.
+The 'packagekit' plugin relies on other plugins like 'appstream' or 'desktopdb'
+to add the required name, summary and icon data and to convert the GsApp to a
+GS_APP_KIND_NORMAL.
+Furthermore, the 'hardcoded-kind' plugin may override the GS_APP_KIND_NORMAL
+kind to a GS_APP_KIND_SYSTEM which means the application is core cannot be
+removed by the user. Core apps would be things like nautilus and totem.
+
+As a general rule, try to make plugins as small and self-contained as possible
+and remember to cache as much data as possible for speed. Memory is cheap, time
+less so.
+
+= Plugins =
+
+In this document, applicaton properties are specified as [id] meaning the
+property called 'id' and metadata (basically, random properites that we don't
+want to export) are specified as {sekret-property}.
+Adding and using metadata is quick as it's stored internally in a hash table,
+so don't be afraid to add extra properties where it might make sense for other
+plugins.
+
+== dummy ==
+Overview:      Provides some dummy data that is useful in self test programs.
+Methods:       Search
+               AddUpdates
+               AddInstalled
+               AddPopular
+Requires:      <nothing>
+Refines:       [id]->[name]
+               [id]->[summary]
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
new file mode 100644
index 0000000..2f3436a
--- /dev/null
+++ b/src/plugins/gs-plugin-dummy.c
@@ -0,0 +1,164 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011-2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gs-plugin.h>
+
+struct GsPluginPrivate {
+       guint                    dummy;
+};
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "dummy";
+}
+
+/**
+ * gs_plugin_initialize:
+ */
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+       /* create private area */
+       plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+       plugin->priv->dummy = 999;
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+       return 1.0f;
+}
+
+/**
+ * gs_plugin_destroy:
+ */
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       plugin->priv->dummy = 0;
+}
+
+/**
+ * gs_plugin_add_search:
+ */
+gboolean
+gs_plugin_add_search (GsPlugin *plugin, const gchar *value, GList *list, GError **error)
+{
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_updates:
+ */
+gboolean
+gs_plugin_add_updates (GsPlugin *plugin, GList **list, GError **error)
+{
+       GsApp *app;
+
+       /* add a normal application */
+       app = gs_app_new ("gnome-boxes");
+       gs_app_set_name (app, "Boxes");
+       gs_app_set_summary (app, "Do not segfault when using newer versons of libvirt.");
+       gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+       gs_plugin_add_app (list, app);
+
+       /* add an OS update */
+       app = gs_app_new ("libvirt-glib-devel;0.0.1;noarch;fedora");
+       gs_app_set_name (app, "libvirt-glib-devel");
+       gs_app_set_summary (app, "Fix several memory leaks.");
+       gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+       gs_plugin_add_app (list, app);
+
+       /* add a second OS update */
+       app = gs_app_new ("gnome-boxes-libs;0.0.1;i386;updates-testing");
+       gs_app_set_name (app, "gnome-boxes-libs");
+       gs_app_set_summary (app, "Do not segfault when using newer versons of libvirt.");
+       gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+       gs_plugin_add_app (list, app);
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_installed:
+ */
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin, GList **list, GError **error)
+{
+       GsApp *app;
+
+       app = gs_app_new ("gnome-power-manager");
+       gs_app_set_name (app, "Power Manager");
+       gs_app_set_summary (app, "Power Management Program");
+       gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+       gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+       gs_plugin_add_app (list, app);
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_add_popular:
+ */
+gboolean
+gs_plugin_add_popular (GsPlugin *plugin, GList **list, GError **error)
+{
+       GsApp *app;
+
+       app = gs_app_new ("gnome-power-manager");
+       gs_app_set_name (app, "Power Manager");
+       gs_app_set_summary (app, "Power Management Program");
+       gs_app_set_state (app, GS_APP_STATE_AVAILABLE);
+       gs_app_set_kind (app, GS_APP_KIND_NORMAL);
+       gs_plugin_add_app (list, app);
+
+       return TRUE;
+}
+
+/**
+ * gs_plugin_refine:
+ */
+gboolean
+gs_plugin_refine (GsPlugin *plugin, GList *list, GError **error)
+{
+       GsApp *app;
+       GList *l;
+
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_name (app) == NULL) {
+                       if (g_strcmp0 (gs_app_get_id (app), "gnome-boxes") == 0) {
+                               gs_app_set_name (app, "Boxes");
+                               gs_app_set_summary (app, "A simple GNOME 3 application to access remote or 
virtual systems");
+                       }
+               }
+       }
+       return TRUE;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]