[Workman-devel] [PATCH] Add WorkmanPlugin abstract class

Josh Poimboeuf jpoimboe at redhat.com
Mon Mar 25 22:38:15 UTC 2013


This will be the superclass of WorkmanPluginCgroup,
WorkmanPluginLibvirt, WorkmanPluginSystemd, etc.

Note that some of the subclass methods are optional, since only some of
the subclasses will need to implement them.
---
 workman/Makefile.am      |   2 +
 workman/workman-plugin.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++
 workman/workman-plugin.h | 147 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 306 insertions(+)
 create mode 100644 workman/workman-plugin.c
 create mode 100644 workman/workman-plugin.h

diff --git a/workman/Makefile.am b/workman/Makefile.am
index 4ef03f3..2548e7e 100644
--- a/workman/Makefile.am
+++ b/workman/Makefile.am
@@ -25,6 +25,7 @@ HEADERS_PRIVATE = \
 			workman-partition-private.h \
 			workman-consumer-private.h \
 			workman-manager-linux.h \
+			workman-plugin.h \
                         $(NULL)
 CFILES = \
 			workman-main.c \
@@ -36,6 +37,7 @@ CFILES = \
 			workman-manager.c \
 			workman-manager-linux.c \
 			workman-lists.c \
+			workman-plugin.c \
                         $(NULL)
 libworkman_1_0_la_SOURCES = \
 			$(libworkman_1_0_la_HEADERS) \
diff --git a/workman/workman-plugin.c b/workman/workman-plugin.c
new file mode 100644
index 0000000..144c872
--- /dev/null
+++ b/workman/workman-plugin.c
@@ -0,0 +1,157 @@
+/*
+ * workman-plugin.c: workload manager
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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.1 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Josh Poimboeuf <jpoimboe at redhat.com>
+ */
+
+#include <config.h>
+
+#include "workman.h"
+#include "workman-plugin.h"
+
+G_DEFINE_ABSTRACT_TYPE(WorkmanPlugin, workman_plugin, G_TYPE_OBJECT);
+
+#define WORKMAN_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WORKMAN_TYPE_PLUGIN, WorkmanPluginPrivate))
+
+
+struct _WorkmanPluginPrivate {
+    gboolean unused;
+};
+
+
+static void
+workman_plugin_class_init(WorkmanPluginClass *klass)
+{
+    g_type_class_add_private(klass, sizeof (WorkmanPluginPrivate));
+}
+
+
+static void
+workman_plugin_init(WorkmanPlugin *self)
+{
+    self->priv = WORKMAN_PLUGIN_GET_PRIVATE(self);
+}
+
+
+WorkmanPartition *
+workman_plugin_add_object(WorkmanPlugin *self,
+                          WorkmanState state,
+                          const gchar *name,
+                          WorkmanObject *parent,
+                          GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    if (!klass->add_object)
+        return NULL;
+
+    return klass->add_object(self, state, name, parent, error);
+}
+
+
+gboolean
+workman_plugin_remove_object(WorkmanPlugin *self,
+                             WorkmanState state,
+                             WorkmanObject *object,
+                             GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    if (!klass->remove_object)
+        return FALSE;
+
+    return klass->remove_object(self, state, object, error);
+}
+
+
+GList *
+workman_plugin_get_objects(WorkmanPlugin *self,
+                           GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    return klass->get_objects(self, error);
+}
+
+
+GList *
+workman_plugin_get_object_attributes(WorkmanPlugin *self,
+                                     WorkmanState state,
+                                     WorkmanObject *object,
+                                     GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    return klass->get_object_attributes(self, state, object, error);
+}
+
+
+gboolean
+workman_plugin_update_attribute(WorkmanPlugin *self,
+                                WorkmanAttribute *attribute,
+                                GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    if (!klass->update_attribute)
+        return FALSE;
+
+    return klass->update_attribute(self, attribute, error);
+}
+
+
+gboolean
+workman_plugin_set_object_parent(WorkmanPlugin *self,
+                                 WorkmanState state,
+                                 WorkmanObject *object,
+                                 WorkmanObject *parent,
+                                 GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    if (!klass->set_object_parent)
+        return FALSE;
+
+    return klass->set_object_parent(self, state, object, parent, error);
+}
+
+
+GList *
+workman_plugin_get_object_processes(WorkmanPlugin *self,
+                                    WorkmanObject *object,
+                                    GError **error)
+{
+    WorkmanPluginClass *klass = WORKMAN_PLUGIN_GET_CLASS(self);
+
+    if (!klass->get_object_processes)
+        return NULL;
+
+    return klass->get_object_processes(self, object, error);
+}
+
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ *
+ * vim: set expandtab shiftwidth=4 tabstop=4 :
+ */
diff --git a/workman/workman-plugin.h b/workman/workman-plugin.h
new file mode 100644
index 0000000..8e28534
--- /dev/null
+++ b/workman/workman-plugin.h
@@ -0,0 +1,147 @@
+/*
+ * workman-plugin.h: workload manager
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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.1 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Josh Poimboeuf <jpoimboe at redhat.com>
+ */
+
+#if !defined(__WORKMAN_H__) && !defined(WORKMAN_BUILD)
+# error "Only <workman/workman.h> can be included directly."
+#endif
+
+#ifndef __WORKMAN_PLUGIN_H__
+# define __WORKMAN_PLUGIN_H__
+
+# include <glib-object.h>
+
+G_BEGIN_DECLS
+
+# define WORKMAN_TYPE_PLUGIN            (workman_plugin_get_type ())
+# define WORKMAN_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), WORKMAN_TYPE_PLUGIN, WorkmanPlugin))
+# define WORKMAN_IS_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WORKMAN_TYPE_PLUGIN))
+# define WORKMAN_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), WORKMAN_TYPE_PLUGIN, WorkmanPluginClass))
+# define WORKMAN_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WORKMAN_TYPE_PLUGIN))
+# define WORKMAN_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), WORKMAN_TYPE_PLUGIN, WorkmanPluginClass))
+
+typedef struct _WorkmanPlugin        WorkmanPlugin;
+typedef struct _WorkmanPluginClass   WorkmanPluginClass;
+typedef struct _WorkmanPluginPrivate WorkmanPluginPrivate;
+
+struct _WorkmanPlugin
+{
+    GObject parent_instance;
+
+    /* public */
+
+    /* private */
+    WorkmanPluginPrivate *priv;
+};
+
+/* class */
+struct _WorkmanPluginClass
+{
+    /*< private >*/
+    GObjectClass parent_class;
+
+    /* public */
+    WorkmanPartition *(*add_object)(WorkmanPlugin *plugin,
+                                    WorkmanState state,
+                                    const gchar *name,
+                                    WorkmanObject *parent,
+                                    GError **error);
+
+    gboolean (*remove_object)(WorkmanPlugin *plugin,
+                              WorkmanState state,
+                              WorkmanObject *object,
+                              GError **error);
+
+    GList *(*get_objects)(WorkmanPlugin *plugin,
+                          GError **error);
+
+    GList *(*get_object_attributes)(WorkmanPlugin *plugin,
+                                    WorkmanState state,
+                                    WorkmanObject *object,
+                                    GError **error);
+
+    gboolean (*update_attribute)(WorkmanPlugin *plugin,
+                                 WorkmanAttribute *attribute,
+                                 GError **error);
+
+    gboolean (*set_object_parent)(WorkmanPlugin *plugin,
+                                  WorkmanState state,
+                                  WorkmanObject *object,
+                                  WorkmanObject *parent,
+                                  GError **error);
+
+    GList *(*get_object_processes)(WorkmanPlugin *plugin,
+                                   WorkmanObject *object,
+                                   GError **error);
+
+    /* Remove from padding when adding new virtual functions */
+    gpointer padding[20];
+};
+
+GType workman_plugin_get_type(void);
+
+WorkmanPartition *workman_plugin_add_object(WorkmanPlugin *plugin,
+                                            WorkmanState state,
+                                            const gchar *name,
+                                            WorkmanObject *parent,
+                                            GError **error);
+
+gboolean workman_plugin_remove_object(WorkmanPlugin *plugin,
+                                      WorkmanState state,
+                                      WorkmanObject *object,
+                                      GError **error);
+
+GList *workman_plugin_get_objects(WorkmanPlugin *plugin,
+                                  GError **error);
+
+GList *workman_plugin_get_object_attributes(WorkmanPlugin *plugin,
+                                            WorkmanState state,
+                                            WorkmanObject *object,
+                                            GError **error);
+
+gboolean workman_plugin_update_attribute(WorkmanPlugin *plugin,
+                                         WorkmanAttribute *attribute,
+                                         GError **error);
+
+gboolean workman_plugin_set_object_parent(WorkmanPlugin *plugin,
+                                          WorkmanState state,
+                                          WorkmanObject *object,
+                                          WorkmanObject *parent,
+                                          GError **error);
+
+GList *workman_plugin_get_object_processes(WorkmanPlugin *plugin,
+                                           WorkmanObject *object,
+                                           GError **error);
+
+
+G_END_DECLS
+
+#endif /* __WORKMAN_PLUGIN_H__ */
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ *
+ * vim: set expandtab shiftwidth=4 tabstop=4 :
+ */
-- 
1.7.11.7




More information about the Workman-devel mailing list