[Libosinfo] [libosinfo PATCH 16/31] osinfo: Introduce OsinfoLinkList
Fabiano Fidêncio
fidencio at redhat.com
Fri Nov 23 10:15:05 UTC 2018
OsinfoLinkList is an abstract type from which OsinfoDeviceLinkList will
inherit. The reason for adding this new type is that further in this
series OsinfoFeatureLinkList will be added. and it'll also inherit from
OsinfoLinkList, leading to less code duplication between DeviceLinkList
and FeatureLinkList.
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
osinfo/Makefile.am | 2 +
osinfo/libosinfo.syms | 3 ++
osinfo/osinfo.h | 1 +
osinfo/osinfo_linklist.c | 102 +++++++++++++++++++++++++++++++++++++++
osinfo/osinfo_linklist.h | 78 ++++++++++++++++++++++++++++++
5 files changed, 186 insertions(+)
create mode 100644 osinfo/osinfo_linklist.c
create mode 100644 osinfo/osinfo_linklist.h
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 8781244..0b243fc 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -95,6 +95,7 @@ libosinfo_impl_include_HEADERS = \
osinfo_platform.h \
osinfo_platformlist.h \
osinfo_link.h \
+ osinfo_linklist.h \
osinfo_list.h \
osinfo_os.h \
osinfo_oslist.h \
@@ -122,6 +123,7 @@ libosinfo_c_files = \
osinfo_entity.c \
osinfo_filter.c \
osinfo_link.c \
+ osinfo_linklist.c \
osinfo_list.c \
osinfo_device.c \
osinfo_devicelink.c \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 0c51768..b24ce16 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -546,6 +546,9 @@ LIBOSINFO_1.3.0 {
osinfo_link_get_target;
osinfo_link_get_type;
+ osinfo_linklist_get_targets;
+ osinfo_linklist_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 da4a9b5..91c2d34 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -36,6 +36,7 @@
#include <osinfo/osinfo_featurelist.h>
#include <osinfo/osinfo_filter.h>
#include <osinfo/osinfo_link.h>
+#include <osinfo/osinfo_linklist.h>
#include <osinfo/osinfo_list.h>
#include <osinfo/osinfo_device.h>
#include <osinfo/osinfo_device_driver.h>
diff --git a/osinfo/osinfo_linklist.c b/osinfo/osinfo_linklist.c
new file mode 100644
index 0000000..8154ae9
--- /dev/null
+++ b/osinfo/osinfo_linklist.c
@@ -0,0 +1,102 @@
+/*
+ * libosinfo: a list of links
+ *
+ * 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(OsinfoLinkList, osinfo_linklist, OSINFO_TYPE_LIST);
+
+#define OSINFO_LINKLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_LINKLIST, OsinfoLinkListPrivate))
+
+/**
+ * SECTION:osinfo_linklist
+ * @short_description: A list of entities links
+ * @see_also: #OsinfoList, #OsinfoLink
+ *
+ * #OsinfoLinkList is a list specialization that stores
+ * only #OsinfoLink objects.
+ */
+
+struct _OsinfoLinkListPrivate
+{
+ gboolean unused;
+};
+
+static void
+osinfo_linklist_finalize(GObject *object)
+{
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS(osinfo_linklist_parent_class)->finalize(object);
+}
+
+/* Init functions */
+static void
+osinfo_linklist_class_init(OsinfoLinkListClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS(klass);
+
+ g_klass->finalize = osinfo_linklist_finalize;
+ g_type_class_add_private(klass, sizeof(OsinfoLinkListPrivate));
+}
+
+static void
+osinfo_linklist_init(OsinfoLinkList *list)
+{
+ list->priv = OSINFO_LINKLIST_GET_PRIVATE(list);
+}
+
+
+/**
+ * osinfo_linklist_get_targets:
+ * @list: a link list
+ * @filter: (allow-none)(transfer none): an optional entity property filter
+ * @newlist: (out)(transfer full): The list of targets
+ *
+ * Get all entities matching a given filter
+ */
+void osinfo_linklist_get_targets(OsinfoLinkList *list,
+ OsinfoFilter *filter,
+ OsinfoList *newList)
+{
+ gint list_size, i;
+
+ list_size = osinfo_list_get_length(OSINFO_LIST(list));
+ for (i = 0; i < list_size; i++) {
+ OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(list), i);
+ if (!filter || osinfo_filter_matches(filter, ent)) {
+ OsinfoEntity *target = osinfo_link_get_target(OSINFO_LINK(ent));
+ osinfo_list_add(newList, target);
+ }
+ }
+}
+
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_linklist.h b/osinfo/osinfo_linklist.h
new file mode 100644
index 0000000..03d05a6
--- /dev/null
+++ b/osinfo/osinfo_linklist.h
@@ -0,0 +1,78 @@
+/*
+ * libosinfo: a list of links
+ *
+ * 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_filter.h>
+#include <osinfo/osinfo_list.h>
+
+#ifndef __OSINFO_LINKLIST_H__
+#define __OSINFO_LINKLIST_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_LINKLIST (osinfo_linklist_get_type ())
+#define OSINFO_LINKLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_LINKLIST, OsinfoLinkList))
+#define OSINFO_IS_LINKLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_LINKLIST))
+#define OSINFO_LINKLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_LINKLIST, OsinfoLinkListClass))
+#define OSINFO_IS_LINKLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_LINKLIST))
+#define OSINFO_LINKLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_LINKLIST, OsinfoLinkListClass))
+
+typedef struct _OsinfoLinkList OsinfoLinkList;
+
+typedef struct _OsinfoLinkListClass OsinfoLinkListClass;
+
+typedef struct _OsinfoLinkListPrivate OsinfoLinkListPrivate;
+
+/* object */
+struct _OsinfoLinkList
+{
+ OsinfoList parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoLinkListPrivate *priv;
+};
+
+/* class */
+struct _OsinfoLinkListClass
+{
+ /*< private >*/
+ OsinfoListClass parent_class;
+
+ /* class members */
+};
+
+GType osinfo_linklist_get_type(void);
+
+void osinfo_linklist_get_targets(OsinfoLinkList *list, OsinfoFilter *filter, OsinfoList *newList);
+
+#endif /* __OSINFO_LINKLIST_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
--
2.19.1
More information about the Libosinfo
mailing list