[Libosinfo] [libosinfo PATCH 06/31] osinfo: Introduce OsinfoLink
Fabiano Fidêncio
fidencio at redhat.com
Fri Nov 23 10:14:55 UTC 2018
OsinfoLink is a generic type from which OsinfoDeviceLink will inherit.
The reason for adding this new type is that futher in this series we'll
add OsinfoFeatureLink, which will also inherit from OsinfoLink, and we
can avoid some code duplication between the DeviceLink and FeatureLink
types.
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
osinfo/Makefile.am | 2 +
osinfo/libosinfo.syms | 3 +
osinfo/osinfo.h | 1 +
osinfo/osinfo_link.c | 166 ++++++++++++++++++++++++++++++++++++++++++
osinfo/osinfo_link.h | 79 ++++++++++++++++++++
po/POTFILES.in | 1 +
6 files changed, 252 insertions(+)
create mode 100644 osinfo/osinfo_link.c
create mode 100644 osinfo/osinfo_link.h
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 318c61d..000ca90 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -93,6 +93,7 @@ libosinfo_impl_include_HEADERS = \
osinfo_productlist.h \
osinfo_platform.h \
osinfo_platformlist.h \
+ osinfo_link.h \
osinfo_list.h \
osinfo_os.h \
osinfo_oslist.h \
@@ -119,6 +120,7 @@ libosinfo_c_files = \
osinfo_datamaplist.c \
osinfo_entity.c \
osinfo_filter.c \
+ osinfo_link.c \
osinfo_list.c \
osinfo_device.c \
osinfo_devicelink.c \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index f49cd93..cb1079b 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -540,6 +540,9 @@ LIBOSINFO_1.3.0 {
osinfo_featurelist_get_type;
osinfo_featurelist_new;
+ osinfo_link_get_target;
+ osinfo_link_get_type;
+
osinfo_os_add_maximum_resources;
osinfo_os_get_all_device_links;
osinfo_os_get_maximum_resources;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index d90f72b..9840d73 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -34,6 +34,7 @@
#include <osinfo/osinfo_feature.h>
#include <osinfo/osinfo_featurelist.h>
#include <osinfo/osinfo_filter.h>
+#include <osinfo/osinfo_link.h>
#include <osinfo/osinfo_list.h>
#include <osinfo/osinfo_device.h>
#include <osinfo/osinfo_device_driver.h>
diff --git a/osinfo/osinfo_link.c b/osinfo/osinfo_link.c
new file mode 100644
index 0000000..8ff5823
--- /dev/null
+++ b/osinfo/osinfo_link.c
@@ -0,0 +1,166 @@
+/*
+ * libosinfo: A reference to an entity
+ *
+ * Copyright (C) 2018 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Fabiano Fidêncio <fidencio at redhat.com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include <glib/gi18n-lib.h>
+
+G_DEFINE_ABSTRACT_TYPE(OsinfoLink, osinfo_link, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_LINK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_LINK, OsinfoLinkPrivate))
+
+/**
+ * SECTION:osinfo_link
+ * @short_description: An entity link
+ * @see_also: #OsinfoOs, #OsinfoPlatform
+ *
+ * #OsinfoLink is an entity representing some kind of link. Links can
+ * be associated with operating systems and platforms.
+ */
+
+struct _OsinfoLinkPrivate
+{
+ OsinfoEntity *target;
+};
+
+enum {
+ PROP_0,
+
+ PROP_TARGET
+};
+
+static void
+osinfo_link_set_property(GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ OsinfoLink *link = OSINFO_LINK(object);
+
+ switch (property_id)
+ {
+ case PROP_TARGET:
+ if (link->priv->target)
+ g_object_unref(link->priv->target);
+ link->priv->target = g_value_get_object(value);
+ if (link->priv->target)
+ g_object_ref(link->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_link_get_property(GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ OsinfoLink *link = OSINFO_LINK(object);
+
+ switch (property_id)
+ {
+ case PROP_TARGET:
+ g_value_set_object(value, link->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_link_finalize(GObject *object)
+{
+ OsinfoLink *link = OSINFO_LINK(object);
+
+ if (link->priv->target)
+ g_object_unref(link->priv->target);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(osinfo_link_parent_class)->finalize(object);
+}
+
+/* Init functions */
+static void
+osinfo_link_class_init(OsinfoLinkClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS(klass);
+ GParamSpec *pspec;
+
+ g_klass->set_property = osinfo_link_set_property;
+ g_klass->get_property = osinfo_link_get_property;
+
+ /**
+ * OsinfoLink:target:
+ *
+ * The entity target of the link.
+ */
+ pspec = g_param_spec_object("target",
+ "Target",
+ _("Entity target"),
+ OSINFO_TYPE_ENTITY,
+ 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_link_finalize;
+ g_type_class_add_private(klass, sizeof(OsinfoLinkPrivate));
+}
+
+static void
+osinfo_link_init(OsinfoLink *link)
+{
+ link->priv = OSINFO_LINK_GET_PRIVATE(link);
+}
+
+/**
+ * osinfo_link_get_target:
+ * @link: the entity link
+ *
+ * Retrieve the #OsinfoEntity that the link points to.
+ *
+ * Returns: (transfer none): the target of the entity link
+ */
+OsinfoEntity *osinfo_link_get_target(OsinfoLink *link)
+{
+ return link->priv->target;
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_link.h b/osinfo/osinfo_link.h
new file mode 100644
index 0000000..1e6dce4
--- /dev/null
+++ b/osinfo/osinfo_link.h
@@ -0,0 +1,79 @@
+/*
+ * libosinfo: A reference to an entity
+ *
+ * Copyright (C) 2018 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Fabiano Fidêncio <fidencio at redhat.com>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_entity.h>
+
+#ifndef __OSINFO_LINK_H__
+#define __OSINFO_LINK_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_LINK (osinfo_link_get_type ())
+#define OSINFO_LINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_LINK, OsinfoLink))
+#define OSINFO_IS_LINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_LINK))
+#define OSINFO_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_LINK, OsinfoLinkClass))
+#define OSINFO_IS_LINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_LINK))
+#define OSINFO_LINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_LINK, OsinfoLinkClass))
+
+typedef struct _OsinfoLink OsinfoLink;
+
+typedef struct _OsinfoLinkClass OsinfoLinkClass;
+
+typedef struct _OsinfoLinkPrivate OsinfoLinkPrivate;
+
+#define OSINFO_LINK_PROP_SUPPORTED "supported"
+
+/* object */
+struct _OsinfoLink
+{
+ OsinfoEntity parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoLinkPrivate *priv;
+};
+
+/* class */
+struct _OsinfoLinkClass
+{
+ /*< private >*/
+ OsinfoEntityClass parent_class;
+
+ /* class members */
+};
+
+GType osinfo_link_get_type(void);
+
+OsinfoEntity *osinfo_link_get_target(OsinfoLink *link);
+
+#endif /* __OSINFO_LINK_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a5d4559..4fcb0c6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ osinfo/osinfo_entity.c
osinfo/osinfo_feature.c
osinfo/osinfo_install_config_param.c
osinfo/osinfo_install_script.c
+osinfo/osinfo_link.c
osinfo/osinfo_list.c
osinfo/osinfo_loader.c
osinfo/osinfo_media.c
--
2.19.1
More information about the Libosinfo
mailing list