[Workman-devel] [PATCH] WorkmanObject: add plugin property

Josh Poimboeuf jpoimboe at redhat.com
Tue Apr 2 20:23:25 UTC 2013


Add a plugin property to WorkmanObject.  Every object will be "owned" by
the plugin that created it.  The object will then be able to call the
plugin to refresh or set a property.
---
 workman/workman-object-private.h |  2 ++
 workman/workman-object.c         | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/workman/workman-object-private.h b/workman/workman-object-private.h
index 4ecec84..b751e40 100644
--- a/workman/workman-object-private.h
+++ b/workman/workman-object-private.h
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
 void workman_object_set_state(WorkmanObject *object,
                               WorkmanState state);
 
+WorkmanPlugin *workman_object_get_plugin(WorkmanObject *object);
+
 G_END_DECLS
 
 #endif /* __WORKMAN_OBJECT_PRIVATE_H__ */
diff --git a/workman/workman-object.c b/workman/workman-object.c
index e613fe4..b8ad679 100644
--- a/workman/workman-object.c
+++ b/workman/workman-object.c
@@ -23,6 +23,7 @@
 #include <config.h>
 
 #include "workman.h"
+#include "workman-object-private.h"
 
 G_DEFINE_ABSTRACT_TYPE(WorkmanObject, workman_object, G_TYPE_OBJECT);
 
@@ -33,6 +34,7 @@ struct _WorkmanObjectPrivate {
     gchar *name;
     WorkmanState state;
     GList *attributes;
+    WorkmanPlugin *plugin;
 };
 
 
@@ -41,6 +43,7 @@ enum {
     PROP_NAME,
     PROP_STATE,
     PROP_ATTRIBUTES,
+    PROP_PLUGIN,
 };
 
 
@@ -63,6 +66,9 @@ workman_object_get_property(GObject *object,
         case PROP_ATTRIBUTES:
             g_value_set_boxed(value, self->priv->attributes);
             break;
+        case PROP_PLUGIN:
+            g_value_set_object(value, self->priv->plugin);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
             break;
@@ -89,6 +95,10 @@ workman_object_set_property(GObject *object,
             g_boxed_free(WORKMAN_TYPE_ATTRIBUTE_LIST, self->priv->attributes);
             self->priv->attributes = g_value_dup_boxed(value);
             break;
+        case PROP_PLUGIN:
+            g_object_unref(self->priv->plugin);
+            self->priv->plugin = g_value_dup_object(value);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
             break;
@@ -104,6 +114,9 @@ workman_object_dispose(GObject *object)
     g_boxed_free(WORKMAN_TYPE_ATTRIBUTE_LIST, self->priv->attributes);
     self->priv->attributes = NULL;
 
+    g_object_unref(self->priv->plugin);
+    self->priv->plugin = NULL;
+
     G_OBJECT_CLASS(workman_object_parent_class)->dispose(object);
 }
 
@@ -163,9 +176,19 @@ workman_object_class_init(WorkmanObjectClass *klass)
                                G_PARAM_READWRITE |
                                G_PARAM_CONSTRUCT_ONLY |
                                G_PARAM_STATIC_STRINGS);
-
     g_object_class_install_property(g_klass, PROP_ATTRIBUTES, pspec);
 
+
+    pspec = g_param_spec_object("plugin",
+                                "Plugin",
+                                "The object's WorkmanPlugin",
+                                WORKMAN_TYPE_PLUGIN,
+                                G_PARAM_READWRITE |
+                                G_PARAM_CONSTRUCT_ONLY |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_PLUGIN, pspec);
+
+
     g_type_class_add_private(klass, sizeof(WorkmanObjectPrivate));
 }
 
@@ -263,6 +286,16 @@ void workman_object_set_state(WorkmanObject *self,
 }
 
 
+WorkmanPlugin *
+workman_object_get_plugin(WorkmanObject *self)
+{
+    if (self->priv->plugin)
+        g_object_ref(self->priv->plugin);
+
+    return self->priv->plugin;
+}
+
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
-- 
1.7.11.7




More information about the Workman-devel mailing list