[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [libosinfo 3/6] Add ResourcesList class



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

Add special list class to hold Resources instances.
---
 docs/reference/Libosinfo-sections.txt |   21 ++++
 osinfo/Makefile.am                    |    4 +-
 osinfo/libosinfo.syms                 |    6 +
 osinfo/osinfo.h                       |    1 +
 osinfo/osinfo_resourceslist.c         |  172 +++++++++++++++++++++++++++++++++
 osinfo/osinfo_resourceslist.h         |   96 ++++++++++++++++++
 6 files changed, 299 insertions(+), 1 deletions(-)
 create mode 100644 osinfo/osinfo_resourceslist.c
 create mode 100644 osinfo/osinfo_resourceslist.h

diff --git a/docs/reference/Libosinfo-sections.txt b/docs/reference/Libosinfo-sections.txt
index 521019f..81dfb2a 100644
--- a/docs/reference/Libosinfo-sections.txt
+++ b/docs/reference/Libosinfo-sections.txt
@@ -465,6 +465,27 @@ OSINFO_RESOURCES_GET_CLASS
 </SECTION>
 
 <SECTION>
+<FILE>osinfo_resourceslist</FILE>
+<TITLE>OsinfoResourcesList</TITLE>
+OsinfoResourcesList
+OsinfResourcesListoClass
+OsinfResourcesListoPrivate
+osinfo_resourceslist_new
+osinfo_resourceslist_new_copy
+osinfo_resourceslist_new_filtered
+osinfo_resourceslist_new_intersection
+osinfo_resourceslist_new_union
+<SUBSECTION Standard>
+OSINFO_RESOURCESLIST
+OSINFO_IS_RESOURCESLIST
+OSINFO_TYPE_RESOURCESLIST
+osinfo_resourceslist_get_type
+OSINFO_RESOURCESLIST_CLASS
+OSINFO_IS_RESOURCESLIST_CLASS
+OSINFO_RESOURCESLIST_GET_CLASS
+</SECTION>
+
+<SECTION>
 <FILE>osinfo_devicelink</FILE>
 <TITLE>OsinfoDeviceLink</TITLE>
 OsinfoDeviceLink
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 0b59284..5b0e25b 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -64,7 +64,8 @@ libosinfo_1_0_include_HEADERS = \
   osinfo_deploymentlist.h	\
   osinfo_media.h		\
   osinfo_medialist.h		\
-  osinfo_resources.h
+  osinfo_resources.h		\
+  osinfo_resourceslist.h
 
 libosinfo_1_0_la_SOURCES =	\
   osinfo_entity.c		\
@@ -87,6 +88,7 @@ libosinfo_1_0_la_SOURCES =	\
   osinfo_media.c		\
   osinfo_medialist.c		\
   osinfo_resources.c		\
+  osinfo_resourceslist.c	\
   osinfo_db.c			\
   osinfo_loader.c
 
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 872f139..30df286 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -164,6 +164,12 @@ LIBOSINFO_0.0.1 {
 	osinfo_resources_get_n_cpus;
 	osinfo_resources_get_ram;
 	osinfo_resources_get_storage;
+	osinfo_resourceslist_get_type;
+	osinfo_resourceslist_new;
+	osinfo_resourceslist_new_copy;
+	osinfo_resourceslist_new_filtered;
+	osinfo_resourceslist_new_intersection;
+	osinfo_resourceslist_new_union;
 
     local:
         *;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index dc33605..0013dd1 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -45,6 +45,7 @@
 #include <osinfo/osinfo_media.h>
 #include <osinfo/osinfo_medialist.h>
 #include <osinfo/osinfo_resources.h>
+#include <osinfo/osinfo_resourceslist.h>
 #include <osinfo/osinfo_db.h>
 #include <osinfo/osinfo_loader.h>
 
diff --git a/osinfo/osinfo_resourceslist.c b/osinfo/osinfo_resourceslist.c
new file mode 100644
index 0000000..34d369c
--- /dev/null
+++ b/osinfo/osinfo_resourceslist.c
@@ -0,0 +1,172 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2011 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
+ *
+ * Authors:
+ *   Arjun Roy <arroy redhat com>
+ *   Daniel P. Berrange <berrange redhat com>
+ */
+
+#include <osinfo/osinfo.h>
+
+G_DEFINE_TYPE (OsinfoResourcesList, osinfo_resourceslist, OSINFO_TYPE_LIST);
+
+#define OSINFO_RESOURCESLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+                                               OSINFO_TYPE_RESOURCESLIST,          \
+                                               OsinfoResourcesListPrivate))
+
+/**
+ * SECTION:osinfo_resourceslist
+ * @short_description: A list of installation resources
+ * @see_also: #OsinfoList, #OsinfoResources
+ *
+ * #OsinfoResourcesList is a list specialization that stores
+ * only #OsinfoResources objects.
+ */
+
+struct _OsinfoResourcesListPrivate
+{
+    gboolean unused;
+};
+
+static void
+osinfo_resourceslist_finalize (GObject *object)
+{
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_resourceslist_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_resourceslist_class_init (OsinfoResourcesListClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+    g_klass->finalize = osinfo_resourceslist_finalize;
+    g_type_class_add_private (klass, sizeof (OsinfoResourcesListPrivate));
+}
+
+static void
+osinfo_resourceslist_init (OsinfoResourcesList *list)
+{
+    OsinfoResourcesListPrivate *priv;
+    list->priv = priv = OSINFO_RESOURCESLIST_GET_PRIVATE(list);
+
+}
+
+/**
+ * osinfo_resourceslist_new:
+ *
+ * Construct a new resources list that is initially empty.
+ *
+ * Returns: (transfer full): an empty resources list
+ */
+OsinfoResourcesList *osinfo_resourceslist_new(void)
+{
+    return g_object_new(OSINFO_TYPE_RESOURCESLIST,
+                        "element-type", OSINFO_TYPE_RESOURCES,
+                        NULL);
+}
+
+/**
+ * osinfo_resourceslist_new_copy:
+ * @source: the resources list to copy
+ *
+ * Construct a new resources list that is filled with resources instances
+ * from @source
+ *
+ * Returns: (transfer full): a copy of the resources list
+ */
+OsinfoResourcesList *osinfo_resourceslist_new_copy(OsinfoResourcesList *source)
+{
+    OsinfoResourcesList *newList = osinfo_resourceslist_new();
+    osinfo_list_add_all(OSINFO_LIST(newList),
+                        OSINFO_LIST(source));
+    return newList;
+}
+
+/**
+ * osinfo_resourceslist_new_filtered:
+ * @source: the resources list to copy
+ * @filter: the filter to apply
+ *
+ * Construct a new resources list that is filled with resources instances
+ * from @source that match @filter
+ *
+ * Returns: (transfer full): a filtered copy of the resources list
+ */
+OsinfoResourcesList *osinfo_resourceslist_new_filtered
+                                (OsinfoResourcesList *source,
+                                 OsinfoFilter *filter)
+{
+    OsinfoResourcesList *newList = osinfo_resourceslist_new();
+    osinfo_list_add_filtered(OSINFO_LIST(newList),
+                             OSINFO_LIST(source),
+                             filter);
+    return newList;
+}
+
+/**
+ * osinfo_resourceslist_new_intersection:
+ * @sourceOne: the first resources list to copy
+ * @sourceTwo: the second resources list to copy
+ *
+ * Construct a new resources list that is filled with only the
+ * resources instances that are present in both @sourceOne and @sourceTwo.
+ *
+ * Returns: (transfer full): an intersection of the two resources lists
+ */
+OsinfoResourcesList *osinfo_resourceslist_new_intersection
+                                (OsinfoResourcesList *sourceOne,
+                                 OsinfoResourcesList *sourceTwo)
+{
+    OsinfoResourcesList *newList = osinfo_resourceslist_new();
+    osinfo_list_add_intersection(OSINFO_LIST(newList),
+                                 OSINFO_LIST(sourceOne),
+                                 OSINFO_LIST(sourceTwo));
+    return newList;
+}
+
+/**
+ * osinfo_resourceslist_new_union:
+ * @sourceOne: the first resources list to copy
+ * @sourceTwo: the second resources list to copy
+ *
+ * Construct a new resources list that is filled with all the
+ * resources instances that are present in either @sourceOne and @sourceTwo.
+ *
+ * Returns: (transfer full): a union of the two resources lists
+ */
+OsinfoResourcesList *osinfo_resourceslist_new_union
+                                (OsinfoResourcesList *sourceOne,
+                                 OsinfoResourcesList *sourceTwo)
+{
+    OsinfoResourcesList *newList = osinfo_resourceslist_new();
+    osinfo_list_add_union(OSINFO_LIST(newList),
+                          OSINFO_LIST(sourceOne),
+                          OSINFO_LIST(sourceTwo));
+    return newList;
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_resourceslist.h b/osinfo/osinfo_resourceslist.h
new file mode 100644
index 0000000..e9c6c0e
--- /dev/null
+++ b/osinfo/osinfo_resourceslist.h
@@ -0,0 +1,96 @@
+/*
+ * libosinfo: a list of minimum/recommended resources
+ *
+ * Copyright (C) 2009-2011 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
+ *
+ * Authors:
+ *   Zeeshan Ali <zeenix redhat com>
+ *   Arjun Roy <arroy redhat com>
+ *   Daniel P. Berrange <berrange redhat com>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_list.h>
+
+#ifndef __OSINFO_RESOURCESLIST_H__
+#define __OSINFO_RESOURCESLIST_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_RESOURCESLIST                  (osinfo_resourceslist_get_type ())
+#define OSINFO_RESOURCESLIST(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                    OSINFO_TYPE_RESOURCESLIST,         \
+                                                    OsinfoResourcesList))
+#define OSINFO_IS_RESOURCESLIST(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+                                                    OSINFO_TYPE_RESOURCESLIST))
+#define OSINFO_RESOURCESLIST_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass),  \
+                                                    OSINFO_TYPE_RESOURCESLIST,         \
+                                                    OsinfoResourcesListClass))
+#define OSINFO_IS_RESOURCESLIST_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass),  \
+                                                    OSINFO_TYPE_RESOURCESLIST))
+#define OSINFO_RESOURCESLIST_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj),  \
+                                                    OSINFO_TYPE_RESOURCESLIST,         \
+                                                    OsinfoResourcesListClass))
+
+typedef struct _OsinfoResourcesList        OsinfoResourcesList;
+
+typedef struct _OsinfoResourcesListClass   OsinfoResourcesListClass;
+
+typedef struct _OsinfoResourcesListPrivate OsinfoResourcesListPrivate;
+
+/* object */
+struct _OsinfoResourcesList
+{
+    OsinfoList parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoResourcesListPrivate *priv;
+};
+
+/* class */
+struct _OsinfoResourcesListClass
+{
+    OsinfoListClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_resourceslist_get_type(void);
+
+OsinfoResourcesList *osinfo_resourceslist_new(void);
+OsinfoResourcesList *osinfo_resourceslist_new_copy(OsinfoResourcesList *source);
+OsinfoResourcesList *osinfo_resourceslist_new_filtered
+                                (OsinfoResourcesList *source,
+                                 OsinfoFilter *filter);
+OsinfoResourcesList *osinfo_resourceslist_new_intersection
+                                (OsinfoResourcesList *sourceOne,
+                                 OsinfoResourcesList *sourceTwo);
+OsinfoResourcesList *osinfo_resourceslist_new_union
+                                (OsinfoResourcesList *sourceOne,
+                                 OsinfoResourcesList *sourceTwo);
+
+#endif /* __OSINFO_RESOURCESLIST_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
1.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]