[Libosinfo] [libosinfo PATCH 08/31] devicelink: Inherit from OsinfoLink

Fabiano Fidêncio fidencio at redhat.com
Fri Nov 23 10:14:57 UTC 2018


Let's take advantage of the generic OsinfoLink type and inherit from it.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/osinfo_devicelink.c | 82 ++------------------------------------
 osinfo/osinfo_devicelink.h |  6 +--
 2 files changed, 6 insertions(+), 82 deletions(-)

diff --git a/osinfo/osinfo_devicelink.c b/osinfo/osinfo_devicelink.c
index 41ebd56..3b9909b 100644
--- a/osinfo/osinfo_devicelink.c
+++ b/osinfo/osinfo_devicelink.c
@@ -27,7 +27,7 @@
 #include <osinfo/osinfo.h>
 #include <glib/gi18n-lib.h>
 
-G_DEFINE_TYPE(OsinfoDeviceLink, osinfo_devicelink, OSINFO_TYPE_ENTITY);
+G_DEFINE_TYPE(OsinfoDeviceLink, osinfo_devicelink, OSINFO_TYPE_LINK);
 
 #define OSINFO_DEVICELINK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_DEVICELINK, OsinfoDeviceLinkPrivate))
 
@@ -43,68 +43,13 @@ G_DEFINE_TYPE(OsinfoDeviceLink, osinfo_devicelink, OSINFO_TYPE_ENTITY);
 
 struct _OsinfoDeviceLinkPrivate
 {
-    OsinfoDevice *target;
+    gboolean unused;
 };
 
-enum {
-    PROP_0,
-
-    PROP_TARGET
-};
-
-static void
-osinfo_devicelink_set_property(GObject *object,
-                               guint property_id,
-                               const GValue *value,
-                               GParamSpec *pspec)
-{
-    OsinfoDeviceLink *devlink = OSINFO_DEVICELINK(object);
-
-    switch (property_id)
-        {
-        case PROP_TARGET:
-            if (devlink->priv->target)
-                g_object_unref(devlink->priv->target);
-            devlink->priv->target = g_value_get_object(value);
-            if (devlink->priv->target)
-                g_object_ref(devlink->priv->target);
-            break;
-        default:
-            /* We don't have any other property... */
-            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
-            break;
-        }
-}
-
-static void
-osinfo_devicelink_get_property(GObject *object,
-                               guint property_id,
-                               GValue *value,
-                               GParamSpec *pspec)
-{
-    OsinfoDeviceLink *devlink = OSINFO_DEVICELINK(object);
-
-    switch (property_id)
-        {
-        case PROP_TARGET:
-            g_value_set_object(value, devlink->priv->target);
-            break;
-        default:
-            /* We don't have any other property... */
-            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
-            break;
-        }
-}
-
 
 static void
 osinfo_devicelink_finalize(GObject *object)
 {
-    OsinfoDeviceLink *devlink = OSINFO_DEVICELINK(object);
-
-    if (devlink->priv->target)
-        g_object_unref(devlink->priv->target);
-
     /* Chain up to the parent class */
     G_OBJECT_CLASS(osinfo_devicelink_parent_class)->finalize(object);
 }
@@ -114,27 +59,6 @@ static void
 osinfo_devicelink_class_init(OsinfoDeviceLinkClass *klass)
 {
     GObjectClass *g_klass = G_OBJECT_CLASS(klass);
-    GParamSpec *pspec;
-
-    g_klass->set_property = osinfo_devicelink_set_property;
-    g_klass->get_property = osinfo_devicelink_get_property;
-
-    /**
-     * OsinfoDeviceLink:target:
-     *
-     * The target of the device link.
-     */
-    pspec = g_param_spec_object("target",
-                                "Target",
-                                _("Target device"),
-                                OSINFO_TYPE_DEVICE,
-                                G_PARAM_CONSTRUCT_ONLY |
-                                G_PARAM_READWRITE |
-                                G_PARAM_STATIC_STRINGS);
-    g_object_class_install_property(g_klass,
-                                    PROP_TARGET,
-                                    pspec);
-
 
     g_klass->finalize = osinfo_devicelink_finalize;
     g_type_class_add_private(klass, sizeof(OsinfoDeviceLinkPrivate));
@@ -174,7 +98,7 @@ OsinfoDeviceLink *osinfo_devicelink_new(OsinfoDevice *target)
  */
 OsinfoDevice *osinfo_devicelink_get_target(OsinfoDeviceLink *devlink)
 {
-    return devlink->priv->target;
+    return OSINFO_DEVICE(osinfo_link_get_target(OSINFO_LINK(devlink)));
 }
 
 const gchar *osinfo_devicelink_get_driver(OsinfoDeviceLink *devlink)
diff --git a/osinfo/osinfo_devicelink.h b/osinfo/osinfo_devicelink.h
index 9fe44e1..f2fad4d 100644
--- a/osinfo/osinfo_devicelink.h
+++ b/osinfo/osinfo_devicelink.h
@@ -23,7 +23,7 @@
  */
 
 #include <glib-object.h>
-#include <osinfo/osinfo_entity.h>
+#include <osinfo/osinfo_link.h>
 
 #ifndef __OSINFO_DEVICELINK_H__
 #define __OSINFO_DEVICELINK_H__
@@ -50,7 +50,7 @@ typedef struct _OsinfoDeviceLinkPrivate OsinfoDeviceLinkPrivate;
 /* object */
 struct _OsinfoDeviceLink
 {
-    OsinfoEntity parent_instance;
+    OsinfoLink parent_instance;
 
     /* public */
 
@@ -62,7 +62,7 @@ struct _OsinfoDeviceLink
 struct _OsinfoDeviceLinkClass
 {
     /*< private >*/
-    OsinfoEntityClass parent_class;
+    OsinfoLinkClass parent_class;
 
     /* class members */
 };
-- 
2.19.1




More information about the Libosinfo mailing list