summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-09-02 11:43:11 +0100
committerDaniel P. Berrange <berrange@redhat.com>2010-09-02 11:43:11 +0100
commit0d01d56d81ae6eabc35500f3192078b5e232f057 (patch)
treeed5288277f2bb707aa9829a6b518deecfc88e7ff
parenteafe748ae1aa1fe46357b698f90ed5dc98d03971 (diff)
downloadlibosinfo-0d01d56d81ae6eabc35500f3192078b5e232f057.tar.gz
Introduce a new OsinfoProduct abstract class
It is neccessary to track upgrades/clones/derives relationships for platforms as well as operating systems. Introduce a common parent class for both called OsinfoProduct * data/libosinfo-dummy-data.xml: Make platform XML use the common product XML attributes/relationships * docs/reference/Libosinfo-docs.xml, docs/reference/Libosinfo-sections.txt, docs/reference/Libosinfo.types: Update for new/renamed classes * osinfo/Makefile.am, osinfo/libosinfo.syms, osinfo/osinfo.h: New OsinfoProduct class * osinfo/osinfo_product.c, osinfo/osinfo_product.h, osinfo/osinfo_productlist.h, osinfo/osinfo_productlist.c: New classes * osinfo/osinfo_os.c, osinfo/osinfo_os.h, osinfo/osinfo_platform.c, osinfo/osinfo_platform.h: Change to inherit from OsinfoProduct * osinfo/osinfo_oslist.c, osinfo/osinfo_oslist.h, osinfo/osinfo_platformlist.c, osinfo/osinfo_platformlist.h: Change to inherit from OsinfoProductList * osinfo/osinfo_db.c, osinfo/osinfo_db.h, osinfo/osinfo_loader.c: Update for new class hierarchy * osinfo/osinfo_osfilter.c, osinfo/osinfo_osfilter.h, osinfo/osinfo_osfilter.h, osinfo/osinfo_productfilter.h: Rename filter class
-rw-r--r--.gitignore5
-rw-r--r--data/libosinfo-dummy-data.xml14
-rw-r--r--docs/reference/Libosinfo-docs.xml4
-rw-r--r--docs/reference/Libosinfo-sections.txt80
-rw-r--r--docs/reference/Libosinfo.types4
-rw-r--r--osinfo/Makefile.am26
-rw-r--r--osinfo/libosinfo.syms26
-rw-r--r--osinfo/osinfo.h4
-rw-r--r--osinfo/osinfo_db.c45
-rw-r--r--osinfo/osinfo_db.h5
-rw-r--r--osinfo/osinfo_loader.c152
-rw-r--r--osinfo/osinfo_os.c89
-rw-r--r--osinfo/osinfo_os.h16
-rw-r--r--osinfo/osinfo_osfilter.c268
-rw-r--r--osinfo/osinfo_osfilter.h80
-rw-r--r--osinfo/osinfo_oslist.c2
-rw-r--r--osinfo/osinfo_oslist.h6
-rw-r--r--osinfo/osinfo_platform.c2
-rw-r--r--osinfo/osinfo_platform.h5
-rw-r--r--osinfo/osinfo_platformlist.c2
-rw-r--r--osinfo/osinfo_platformlist.h6
-rw-r--r--osinfo/osinfo_product.c164
-rw-r--r--osinfo/osinfo_product.h86
-rw-r--r--osinfo/osinfo_productfilter.c268
-rw-r--r--osinfo/osinfo_productfilter.h80
-rw-r--r--osinfo/osinfo_productlist.c166
-rw-r--r--osinfo/osinfo_productlist.h82
-rw-r--r--test/Makefile.am13
-rw-r--r--test/test-db.c16
-rw-r--r--test/test-os.c48
-rw-r--r--test/test-osfilter.c221
-rw-r--r--test/test-product.c130
-rw-r--r--test/test-productfilter.c245
33 files changed, 1494 insertions, 866 deletions
diff --git a/.gitignore b/.gitignore
index 8ea02f1..4bec76f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,10 @@ test/test-devicelist
test/test-filter
test/test-hypervisorlist
test/test-loader
-test/test-osfilter
+test/test-productfilter
test/test-oslist
+test/test-product
+test/test-platform
+test/test-platformlist
build/
gtk-doc.make
diff --git a/data/libosinfo-dummy-data.xml b/data/libosinfo-dummy-data.xml
index 1f28a49..7e31766 100644
--- a/data/libosinfo-dummy-data.xml
+++ b/data/libosinfo-dummy-data.xml
@@ -40,11 +40,10 @@
</device>
<platform id="http://qemu.org/qemu-kvm-0.11.0">
- <name>KVM</name>
+ <upgrades id="http://qemu.org/qemu-kvm-0.10.0" />
+ <short-id>kvm-0.11.0</short-id>
+ <name>KVM 0.11.0</name>
<version>0.11.0</version>
- <updates-version>0.10.0</updates-version>
- <updates-version>0.9.0</updates-version>
- <updates-version>0.8.0</updates-version>
<devices>
<device id="http://pci-ids.ucw.cz/read/PC/1002/4382" />
<device id="http://pci-ids.ucw.cz/read/PC/1274/5000" />
@@ -54,8 +53,10 @@
</platform>
<platform id="http://bits.xensource.com/oss-xen/release/3.4.1">
- <name>Xen</name>
+ <short-id>xen-3.4.1</short-id>
+ <name>Xen 3.4.1</name>
<version>3.4.1</version>
+ <vendor>XenSource</vendor>
<devices>
<device id="http://pci-ids.ucw.cz/read/PC/1002/4382" />
<device id="http://pci-ids.ucw.cz/read/PC/1274/1371/80864541" />
@@ -67,8 +68,8 @@
<upgrades id="http://fedoraproject.org/fedora-10" />
<short-id>fedora11</short-id>
<name>Fedora 11</name>
+ <version>11</version>
<vendor>Fedora Project</vendor>
- <vendor>Red Hat</vendor>
<platform id="http://qemu.org/qemu-kvm-0.11.0">
<devices>
@@ -131,6 +132,7 @@
<os id="http://software.opensuse.org/112">
<short-id>opensuse11.2</short-id>
<name>OpenSuse 11.2</name>
+ <version>11.2</version>
<vendor>OpenSuse Project</vendor>
</os>
diff --git a/docs/reference/Libosinfo-docs.xml b/docs/reference/Libosinfo-docs.xml
index 76f9451..fed358d 100644
--- a/docs/reference/Libosinfo-docs.xml
+++ b/docs/reference/Libosinfo-docs.xml
@@ -22,12 +22,14 @@
<xi:include href="xml/osinfo_devicelinklist.xml"/>
<xi:include href="xml/osinfo_entity.xml"/>
<xi:include href="xml/osinfo_filter.xml"/>
+ <xi:include href="xml/osinfo_product.xml"/>
+ <xi:include href="xml/osinfo_productfilter.xml"/>
+ <xi:include href="xml/osinfo_productlist.xml"/>
<xi:include href="xml/osinfo_platform.xml"/>
<xi:include href="xml/osinfo_platformlist.xml"/>
<xi:include href="xml/osinfo_list.xml"/>
<xi:include href="xml/osinfo_loader.xml"/>
<xi:include href="xml/osinfo_os.xml"/>
- <xi:include href="xml/osinfo_osfilter.xml"/>
<xi:include href="xml/osinfo_oslist.xml"/>
</chapter>
<chapter id="object-tree">
diff --git a/docs/reference/Libosinfo-sections.txt b/docs/reference/Libosinfo-sections.txt
index 0ad7783..bc20e77 100644
--- a/docs/reference/Libosinfo-sections.txt
+++ b/docs/reference/Libosinfo-sections.txt
@@ -15,9 +15,10 @@ osinfo_db_add_os
osinfo_db_add_platform
osinfo_db_add_device
osinfo_db_unique_values_for_property_in_os
-osinfo_db_unique_values_for_property_in_hv
+osinfo_db_unique_values_for_property_in_platform
osinfo_db_unique_values_for_property_in_dev
osinfo_db_unique_values_for_os_relationship
+osinfo_db_unique_values_for_platform_relationship
<SUBSECTION Standard>
OSINFO_DB
OSINFO_IS_DB
@@ -75,20 +76,36 @@ OSINFO_LOADER_GET_CLASS
</SECTION>
<SECTION>
+<FILE>osinfo_product</FILE>
+<TITLE>OsinfoProduct</TITLE>
+OsinfoProduct
+OsinfoProductClass
+OsinfoProductPrivate
+OsinfoProductRelationship
+osinfo_product_get_related
+osinfo_product_add_related
+<SUBSECTION Standard>
+OSINFO_PRODUCT
+OSINFO_IS_PRODUCT
+OSINFO_TYPE_PRODUCT
+osinfo_product_get_type
+OSINFO_PRODUCT_CLASS
+OSINFO_IS_PRODUCT_CLASS
+OSINFO_PRODUCT_GET_CLASS
+</SECTION>
+
+<SECTION>
<FILE>osinfo_os</FILE>
<TITLE>OsinfoOs</TITLE>
OsinfoOs
OsinfoOsClass
OsinfoOsPrivate
-OsinfoOsRelationship
osinfo_os_new
osinfo_os_get_preferred_device
osinfo_os_get_preferred_device_link
-osinfo_os_get_related
osinfo_os_get_devices
osinfo_os_get_device_links
osinfo_os_add_device
-osinfo_os_add_related_os
<SUBSECTION Standard>
OSINFO_OS
OSINFO_IS_OS
@@ -208,24 +225,45 @@ OSINFO_DEVICELINKLIST_GET_CLASS
</SECTION>
<SECTION>
-<FILE>osinfo_osfilter</FILE>
-<TITLE>OsinfoOsfilter</TITLE>
-OsinfoOsfilter
-OsinfoOsfilterClass
-OsinfoOsfilterPrivate
-osinfo_osfilter_new
-osinfo_osfilter_add_os_constraint
-osinfo_osfilter_clear_os_constraint
-osinfo_osfilter_clear_os_constraints
-osinfo_osfilter_get_os_constraint_values
+<FILE>osinfo_productfilter</FILE>
+<TITLE>OsinfoProductFilter</TITLE>
+OsinfoProductFilter
+OsinfoProductFilterClass
+OsinfoProductFilterPrivate
+osinfo_productfilter_new
+osinfo_productfilter_add_product_constraint
+osinfo_productfilter_clear_product_constraint
+osinfo_productfilter_clear_product_constraints
+osinfo_productfilter_get_product_constraint_values
+<SUBSECTION Standard>
+OSINFO_PRODUCTFILTER
+OSINFO_IS_PRODUCTFILTER
+OSINFO_TYPE_PRODUCTFILTER
+osinfo_productfilter_get_type
+OSINFO_PRODUCTFILTER_CLASS
+OSINFO_IS_PRODUCTFILTER_CLASS
+OSINFO_PRODUCTFILTER_GET_CLASS
+</SECTION>
+
+<SECTION>
+<FILE>osinfo_productlist</FILE>
+<TITLE>OsinfoProductList</TITLE>
+OsinfoProductList
+OsinfoProductListClass
+OsinfoProductListPrivate
+osinfo_productlist_new
+osinfo_productlist_new_copy
+osinfo_productlist_new_filtered
+osinfo_productlist_new_intersection
+osinfo_productlist_new_union
<SUBSECTION Standard>
-OSINFO_OSFILTER
-OSINFO_IS_OSFILTER
-OSINFO_TYPE_OSFILTER
-osinfo_osfilter_get_type
-OSINFO_OSFILTER_CLASS
-OSINFO_IS_OSFILTER_CLASS
-OSINFO_OSFILTER_GET_CLASS
+OSINFO_PRODUCTLIST
+OSINFO_IS_PRODUCTLIST
+OSINFO_TYPE_PRODUCTLIST
+osinfo_productlist_get_type
+OSINFO_PRODUCTLIST_CLASS
+OSINFO_IS_PRODUCTLIST_CLASS
+OSINFO_PRODUCTLIST_GET_CLASS
</SECTION>
<SECTION>
diff --git a/docs/reference/Libosinfo.types b/docs/reference/Libosinfo.types
index e90b674..5955684 100644
--- a/docs/reference/Libosinfo.types
+++ b/docs/reference/Libosinfo.types
@@ -7,6 +7,8 @@ osinfo_platform_get_type
osinfo_platformlist_get_type
osinfo_list_get_type
osinfo_loader_get_type
+osinfo_product_get_type
+osinfo_productfilter_get_type
+osinfo_productlist_get_type
osinfo_os_get_type
-osinfo_osfilter_get_type
osinfo_oslist_get_type
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index 4c6650e..7705d90 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -40,34 +40,38 @@ libosinfo_1_0_la_LDFLAGS = \
libosinfo_1_0_includedir = $(includedir)/libosinfo-1.0/osinfo
-libosinfo_1_0_include_HEADERS = \
- osinfo.h \
- osinfo_db.h \
+libosinfo_1_0_include_HEADERS = \
+ osinfo.h \
+ osinfo_db.h \
osinfo_loader.h \
osinfo_device.h \
osinfo_devicelink.h \
osinfo_devicelist.h \
- osinfo_devicelinklist.h \
+ osinfo_devicelinklist.h \
osinfo_entity.h \
osinfo_filter.h \
+ osinfo_product.h \
+ osinfo_productfilter.h \
+ osinfo_productlist.h \
osinfo_platform.h \
osinfo_platformlist.h \
- osinfo_list.h \
- osinfo_os.h \
- osinfo_osfilter.h \
+ osinfo_list.h \
+ osinfo_os.h \
osinfo_oslist.h
-libosinfo_1_0_la_SOURCES = \
+libosinfo_1_0_la_SOURCES = \
osinfo_entity.c \
osinfo_filter.c \
osinfo_list.c \
osinfo_device.c \
osinfo_devicelink.c \
osinfo_devicelist.c \
- osinfo_devicelinklist.c \
+ osinfo_devicelinklist.c \
+ osinfo_product.c \
+ osinfo_productfilter.c \
+ osinfo_productlist.c \
osinfo_platform.c \
- osinfo_platformlist.c \
- osinfo_osfilter.c \
+ osinfo_platformlist.c \
osinfo_oslist.c \
osinfo_os.c \
osinfo_db.c \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 1a9afc1..46a4e7a 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -12,7 +12,7 @@ LIBOSINFO_0.0.1 {
osinfo_db_add_platform;
osinfo_db_add_device;
osinfo_db_unique_values_for_property_in_os;
- osinfo_db_unique_values_for_property_in_hv;
+ osinfo_db_unique_values_for_property_in_platform;
osinfo_db_unique_values_for_property_in_dev;
osinfo_db_unique_values_for_os_relationship;
osinfo_device_get_type;
@@ -70,21 +70,29 @@ LIBOSINFO_0.0.1 {
osinfo_list_add_union;
osinfo_list_add_all;
osinfo_list_get_elements;
- osinfo_osfilter_get_type;
- osinfo_osfilter_new;
- osinfo_osfilter_add_os_constraint;
- osinfo_osfilter_clear_os_constraint;
- osinfo_osfilter_clear_os_constraints;
- osinfo_osfilter_get_os_constraint_values;
+ osinfo_productfilter_get_type;
+ osinfo_productfilter_new;
+ osinfo_productfilter_add_product_constraint;
+ osinfo_productfilter_clear_product_constraint;
+ osinfo_productfilter_clear_product_constraints;
+ osinfo_productfilter_get_product_constraint_values;
+ osinfo_product_get_type;
+ osinfo_product_new;
+ osinfo_product_get_related;
+ osinfo_product_add_related;
+ osinfo_productlist_get_type;
+ osinfo_productlist_new;
+ osinfo_productlist_new_copy;
+ osinfo_productlist_new_filtered;
+ osinfo_productlist_new_intersection;
+ osinfo_productlist_new_union;
osinfo_os_get_type;
osinfo_os_new;
osinfo_os_get_preferred_device;
osinfo_os_get_preferred_device_link;
- osinfo_os_get_related;
osinfo_os_get_devices;
osinfo_os_get_device_links;
osinfo_os_add_device;
- osinfo_os_add_related_os;
osinfo_oslist_get_type;
osinfo_oslist_new;
osinfo_oslist_new_copy;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 8d554c5..4f3a2cc 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -32,11 +32,13 @@
#include <osinfo/osinfo_devicelink.h>
#include <osinfo/osinfo_devicelist.h>
#include <osinfo/osinfo_devicelinklist.h>
+#include <osinfo/osinfo_productlist.h>
+#include <osinfo/osinfo_product.h>
+#include <osinfo/osinfo_productfilter.h>
#include <osinfo/osinfo_platformlist.h>
#include <osinfo/osinfo_platform.h>
#include <osinfo/osinfo_oslist.h>
#include <osinfo/osinfo_os.h>
-#include <osinfo/osinfo_osfilter.h>
#include <osinfo/osinfo_db.h>
#include <osinfo/osinfo_loader.h>
diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
index 8694466..94e56fc 100644
--- a/osinfo/osinfo_db.c
+++ b/osinfo/osinfo_db.c
@@ -329,18 +329,18 @@ GList *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *db, const gchar *pr
return osinfo_db_unique_values_for_property_in_entity(OSINFO_LIST(db->priv->devices), propName);
}
-struct __osinfoOsCheckRelationshipArgs {
+struct __osinfoProductCheckRelationshipArgs {
OsinfoList *list;
- OsinfoOsRelationship relshp;
+ OsinfoProductRelationship relshp;
};
-static void __osinfoAddOsIfRelationship(gpointer data, gpointer opaque)
+static void __osinfoAddProductIfRelationship(gpointer data, gpointer opaque)
{
- struct __osinfoOsCheckRelationshipArgs *args = opaque;
- OsinfoOs *os = OSINFO_OS(data);
+ struct __osinfoProductCheckRelationshipArgs *args = opaque;
+ OsinfoProduct *product = OSINFO_PRODUCT(data);
OsinfoList *newList = args->list;
- OsinfoOsList *thisList = osinfo_os_get_related(os, args->relshp);
+ OsinfoProductList *thisList = osinfo_product_get_related(product, args->relshp);
int i;
for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(thisList)) ; i++) {
@@ -354,22 +354,47 @@ static void __osinfoAddOsIfRelationship(gpointer data, gpointer opaque)
/**
* osinfo_db_unique_values_for_os_relationship
* @db: the database
- * @relshp: the operating system relationship
+ * @relshp: the product relationship
*
* Get all operating systems that are the referee
* in an operating system relationship.
*
* Returns: (transfer full): a list of operating systems
*/
-OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *db, OsinfoOsRelationship relshp)
+OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *db, OsinfoProductRelationship relshp)
{
g_return_val_if_fail(OSINFO_IS_DB(db), NULL);
OsinfoOsList *newList = osinfo_oslist_new();
- struct __osinfoOsCheckRelationshipArgs args = {OSINFO_LIST (newList), relshp};
+ struct __osinfoProductCheckRelationshipArgs args = {OSINFO_LIST (newList), relshp};
GList *entities = osinfo_list_get_elements(OSINFO_LIST(db->priv->oses));
- g_list_foreach(entities, __osinfoAddOsIfRelationship, &args);
+ g_list_foreach(entities, __osinfoAddProductIfRelationship, &args);
+ g_list_free(entities);
+
+ return newList;
+}
+
+
+/**
+ * osinfo_db_unique_values_for_platform_relationship
+ * @db: the database
+ * @relshp: the product relationship
+ *
+ * Get all platforms that are the referee
+ * in an platform relationship.
+ *
+ * Returns: (transfer full): a list of virtualization platforms
+ */
+OsinfoPlatformList *osinfo_db_unique_values_for_platform_relationship(OsinfoDb *db, OsinfoProductRelationship relshp)
+{
+ g_return_val_if_fail(OSINFO_IS_DB(db), NULL);
+
+ OsinfoPlatformList *newList = osinfo_platformlist_new();
+ struct __osinfoProductCheckRelationshipArgs args = {OSINFO_LIST (newList), relshp};
+ GList *entities = osinfo_list_get_elements(OSINFO_LIST(db->priv->platforms));
+
+ g_list_foreach(entities, __osinfoAddProductIfRelationship, &args);
g_list_free(entities);
return newList;
diff --git a/osinfo/osinfo_db.h b/osinfo/osinfo_db.h
index 1f93ac2..68fa7a7 100644
--- a/osinfo/osinfo_db.h
+++ b/osinfo/osinfo_db.h
@@ -95,7 +95,10 @@ GList *osinfo_db_unique_values_for_property_in_platform(OsinfoDb *db, const gcha
GList *osinfo_db_unique_values_for_property_in_dev(OsinfoDb *db, const gchar *propName);
// Get me all OSes that 'upgrade' another OS (or whatever relationship is specified)
-OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *db, OsinfoOsRelationship relshp);
+OsinfoOsList *osinfo_db_unique_values_for_os_relationship(OsinfoDb *db, OsinfoProductRelationship relshp);
+
+// Get me all Platforms that 'upgrade' another Platform (or whatever relationship is specified)
+OsinfoPlatformList *osinfo_db_unique_values_for_platform_relationship(OsinfoDb *db, OsinfoProductRelationship relshp);
#endif /* __OSINFO_DB_H__ */
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index de61b48..8364d4a 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -300,14 +300,90 @@ static void osinfo_loader_device_link(OsinfoLoader *loader,
}
+static void osinfo_loader_product_relshp(OsinfoLoader *loader,
+ OsinfoProduct *product,
+ OsinfoProductRelationship relshp,
+ const gchar *xpath,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr root,
+ GError **err)
+{
+ xmlNodePtr *related = NULL;
+ int nrelated = osinfo_loader_nodeset(xpath, ctxt, &related, err);
+ int i;
+ if (*err)
+ return;
+
+ for (i = 0 ; i < nrelated ; i++) {
+ gchar *id = (gchar *)xmlGetProp(related[i], BAD_CAST "id");
+ if (!id) {
+ OSINFO_ERROR(err, "Missing product upgrades id property");
+ goto cleanup;
+ }
+ OsinfoProduct *relproduct;
+ if (OSINFO_IS_PLATFORM(product))
+ relproduct = OSINFO_PRODUCT(osinfo_loader_get_platform(loader, id));
+ else
+ relproduct = OSINFO_PRODUCT(osinfo_loader_get_os(loader, id));
+ g_free(id);
+
+ osinfo_product_add_related(product, relshp, relproduct);
+ }
+
+ cleanup:
+ g_free(related);
+}
+
+
+static void osinfo_loader_product(OsinfoLoader *loader,
+ OsinfoProduct *product,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr root,
+ GError **err)
+{
+ const gchar *const keys[] = {
+ "name", "vendor", "version", "short-id", NULL
+ };
+
+ osinfo_loader_entity(loader, OSINFO_ENTITY(product), keys, ctxt, root, err);
+ if (*err)
+ return;
+
+
+ osinfo_loader_product_relshp(loader, product,
+ OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM,
+ "./derives-from",
+ ctxt,
+ root,
+ err);
+ if (*err)
+ return;
+
+ osinfo_loader_product_relshp(loader, product,
+ OSINFO_PRODUCT_RELATIONSHIP_CLONES,
+ "./clones",
+ ctxt,
+ root,
+ err);
+ if (*err)
+ return;
+
+ osinfo_loader_product_relshp(loader, product,
+ OSINFO_PRODUCT_RELATIONSHIP_UPGRADES,
+ "./upgrades",
+ ctxt,
+ root,
+ err);
+}
+
static void osinfo_loader_platform(OsinfoLoader *loader,
- xmlXPathContextPtr ctxt,
- xmlNodePtr root,
- GError **err)
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr root,
+ GError **err)
{
gchar *id = (gchar *)xmlGetProp(root, BAD_CAST "id");
const gchar *const keys[] = {
- "name", "version", NULL,
+ NULL,
};
if (!id) {
OSINFO_ERROR(err, "Missing platform id property");
@@ -321,49 +397,22 @@ static void osinfo_loader_platform(OsinfoLoader *loader,
if (*err)
return;
- osinfo_loader_device_link(loader, NULL, platform,
- "./devices/device", ctxt, root, err);
+ osinfo_loader_product(loader, OSINFO_PRODUCT(platform), ctxt, root, err);
if (*err)
return;
-}
-
-static void osinfo_loader_os_relshp(OsinfoLoader *loader,
- OsinfoOs *os,
- OsinfoOsRelationship relshp,
- const gchar *xpath,
- xmlXPathContextPtr ctxt,
- xmlNodePtr root,
- GError **err)
-{
- xmlNodePtr *related = NULL;
- int nrelated = osinfo_loader_nodeset(xpath, ctxt, &related, err);
- int i;
+ osinfo_loader_device_link(loader, NULL, platform,
+ "./devices/device", ctxt, root, err);
if (*err)
return;
-
- for (i = 0 ; i < nrelated ; i++) {
- gchar *id = (gchar *)xmlGetProp(related[i], BAD_CAST "id");
- if (!id) {
- OSINFO_ERROR(err, "Missing os upgrades id property");
- goto cleanup;
- }
- OsinfoOs *relos = osinfo_loader_get_os(loader, id);
- g_free(id);
-
- osinfo_os_add_related_os(os, relshp, relos);
- }
-
- cleanup:
- g_free(related);
}
static void osinfo_loader_os_platform(OsinfoLoader *loader,
- OsinfoOs *os,
- xmlXPathContextPtr ctxt,
- xmlNodePtr root,
- GError **err)
+ OsinfoOs *os,
+ xmlXPathContextPtr ctxt,
+ xmlNodePtr root,
+ GError **err)
{
xmlNodePtr *platforms = NULL;
int nplatforms = osinfo_loader_nodeset("./platform", ctxt, &platforms, err);
@@ -401,7 +450,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
{
gchar *id = (gchar *)xmlGetProp(root, BAD_CAST "id");
const gchar *const keys[] = {
- "name", "version", "short-id", NULL
+ NULL
};
if (!id) {
OSINFO_ERROR(err, "Missing os id property");
@@ -415,30 +464,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
if (*err)
return;
- osinfo_loader_os_relshp(loader, os,
- OSINFO_OS_RELATIONSHIP_DERIVES_FROM,
- "./derives-from",
- ctxt,
- root,
- err);
- if (*err)
- return;
-
- osinfo_loader_os_relshp(loader, os,
- OSINFO_OS_RELATIONSHIP_CLONES,
- "./clones",
- ctxt,
- root,
- err);
- if (*err)
- return;
-
- osinfo_loader_os_relshp(loader, os,
- OSINFO_OS_RELATIONSHIP_UPGRADES,
- "./upgrades",
- ctxt,
- root,
- err);
+ osinfo_loader_product(loader, OSINFO_PRODUCT(os), ctxt, root, err);
if (*err)
return;
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 034a222..097103b 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -24,7 +24,7 @@
#include <osinfo/osinfo.h>
-G_DEFINE_TYPE (OsinfoOs, osinfo_os, OSINFO_TYPE_ENTITY);
+G_DEFINE_TYPE (OsinfoOs, osinfo_os, OSINFO_TYPE_PRODUCT);
#define OSINFO_OS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_OS, OsinfoOsPrivate))
@@ -40,15 +40,6 @@ G_DEFINE_TYPE (OsinfoOs, osinfo_os, OSINFO_TYPE_ENTITY);
* and which are derived from a common ancestry.
*/
-/**
- * OsinfoOsRelationship:
- * @OSINFO_OS_RELATIONSHIP_DERIVES_FROM: a descendent (RHEL-5 derives from Fedora-6)
- * @OSINFO_OS_RELATIONSHIP_CLONES: a perfect clone (CentOS-5 clones RHEL-5)
- * @OSINFO_OS_RELATIONSHIP_UPGRADES: a new version release (RHEL-6 upgrades RHEL-4)
- *
- * Enum values used to form relationships between operating
- * systems
- */
struct _OsinfoOsPrivate
{
// OS-Platform specific information
@@ -58,19 +49,6 @@ struct _OsinfoOsPrivate
// Value: List of device_link structs
GList *deviceLinks;
-
- // Value: Array of os_link structs
- GList *osLinks;
-};
-
-struct _OsinfoOsOsLink {
- /* <os> 'verbs' <other_os>
- * fedora11 upgrades fedora10
- * centos clones rhel
- * scientificlinux derives from rhel
- */
- OsinfoOsRelationship relshp;
- OsinfoOs *otherOs;
};
struct _OsinfoOsDeviceLink {
@@ -86,13 +64,6 @@ static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED
g_object_unref(OSINFO_DEVICELINK(data));
}
-static void osinfo_os_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
-{
- struct _OsinfoOsOsLink *link = data;
- g_object_unref(link->otherOs);
- g_free(link);
-}
-
static void
osinfo_os_finalize (GObject *object)
@@ -103,9 +74,6 @@ osinfo_os_finalize (GObject *object)
g_list_free(os->priv->deviceLinks);
g_hash_table_unref(os->priv->platforms);
- g_list_foreach(os->priv->osLinks, osinfo_os_link_free, NULL);
- g_list_free(os->priv->osLinks);
-
/* Chain up to the parent class */
G_OBJECT_CLASS (osinfo_os_parent_class)->finalize (object);
}
@@ -136,7 +104,6 @@ osinfo_os_init (OsinfoOs *os)
os->priv = priv = OSINFO_OS_GET_PRIVATE(os);
os->priv->deviceLinks = NULL;
- os->priv->osLinks = NULL;
os->priv->platforms = g_hash_table_new_full(g_str_hash,
g_str_equal,
g_free,
@@ -226,37 +193,6 @@ OsinfoDeviceLink *osinfo_os_get_preferred_device_link(OsinfoOs *os, OsinfoPlatfo
/**
- * osinfo_os_get_related:
- * @os: an operating system
- * @relshp: the relationship to query
- *
- * Get a list of operating systems satisfying the the requested
- * relationship
- *
- * Returns: (transfer full): a list of related operating systems
- */
-OsinfoOsList *osinfo_os_get_related(OsinfoOs *os, OsinfoOsRelationship relshp)
-{
- g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
-
- // Create our list
- OsinfoOsList *newList = osinfo_oslist_new();
- GList *tmp = os->priv->osLinks;
-
- while (tmp) {
- struct _OsinfoOsOsLink *link = tmp->data;
-
- if (link->relshp == relshp)
- osinfo_list_add(OSINFO_LIST(newList), OSINFO_ENTITY(link->otherOs));
-
- tmp = tmp->next;
- }
-
- return newList;
-}
-
-
-/**
* osinfo_os_get_devices:
* @os: an operating system
* @platform: (allow-none)(transfer none): an optional platform to restrict to
@@ -374,29 +310,6 @@ OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoPlatform *platform, O
return link;
}
-
-
-/**
- * osinfo_os_add_related_os:
- * @os: an operating system
- * @relshp: the relationship
- * @otheros: (transfer none): the operating system to relate to
- *
- * Add an association between two operating systems
- */
-void osinfo_os_add_related_os(OsinfoOs *os, OsinfoOsRelationship relshp, OsinfoOs *otheros)
-{
- g_return_if_fail(OSINFO_IS_OS(os));
- g_return_if_fail(OSINFO_IS_OS(otheros));
-
- struct _OsinfoOsOsLink *osLink = g_new0(struct _OsinfoOsOsLink, 1);
-
- g_object_ref(otheros);
- osLink->otherOs = otheros;
- osLink->relshp = relshp;
-
- os->priv->osLinks = g_list_prepend(os->priv->osLinks, osLink);
-}
/*
* Local variables:
* indent-tabs-mode: nil
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index aea9782..515dfb9 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -23,9 +23,9 @@
*/
#include <glib-object.h>
+#include <osinfo/osinfo_product.h>
#include <osinfo/osinfo_device.h>
#include <osinfo/osinfo_devicelist.h>
-#include <osinfo/osinfo_oslist.h>
#ifndef __OSINFO_OS_H__
#define __OSINFO_OS_H__
@@ -49,7 +49,7 @@ typedef struct _OsinfoOsPrivate OsinfoOsPrivate;
/* object */
struct _OsinfoOs
{
- OsinfoEntity parent_instance;
+ OsinfoProduct parent_instance;
/* public */
@@ -60,33 +60,23 @@ struct _OsinfoOs
/* class */
struct _OsinfoOsClass
{
- OsinfoEntityClass parent_class;
+ OsinfoProductClass parent_class;
/* class members */
};
-typedef enum {
- OSINFO_OS_RELATIONSHIP_DERIVES_FROM,
- OSINFO_OS_RELATIONSHIP_UPGRADES,
- OSINFO_OS_RELATIONSHIP_CLONES,
-} OsinfoOsRelationship;
-
-
GType osinfo_os_get_type(void);
OsinfoOs *osinfo_os_new(const gchar *id);
OsinfoDevice *osinfo_os_get_preferred_device(OsinfoOs *os, OsinfoPlatform *platform, OsinfoFilter *filter);
OsinfoDeviceLink *osinfo_os_get_preferred_device_link(OsinfoOs *os, OsinfoPlatform *platform, OsinfoFilter *filter);
-OsinfoOsList *osinfo_os_get_related(OsinfoOs *os, OsinfoOsRelationship relshp);
OsinfoDeviceList *osinfo_os_get_devices(OsinfoOs *os, OsinfoPlatform *platform, OsinfoFilter *filter);
OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoPlatform *platform, OsinfoFilter *filter);
OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoPlatform *platform, OsinfoDevice *dev);
-void osinfo_os_add_related_os(OsinfoOs *os, OsinfoOsRelationship relshp, OsinfoOs *otheros);
-
#endif /* __OSINFO_OS_H__ */
/*
* Local variables:
diff --git a/osinfo/osinfo_osfilter.c b/osinfo/osinfo_osfilter.c
deleted file mode 100644
index 0115bc0..0000000
--- a/osinfo/osinfo_osfilter.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * libosinfo:
- *
- * Copyright (C) 2009-2010 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 (OsinfoOsfilter, osinfo_osfilter, OSINFO_TYPE_FILTER);
-
-#define OSINFO_OSFILTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_OSFILTER, OsinfoOsfilterPrivate))
-
-/**
- * SECTION:osinfo_osfilter
- * @short_description: an operating system filter
- * @see_also: #OsinfoFilter, #OsinfoOs
- *
- * #OsinfoOsfilter is a specialization of #OsinfoFilter that
- * can also set constraints against operating system
- * relationships. It can only be used to filter entities
- * that are #OsinfoOs objects.
- */
-
-struct _OsinfoOsfilterPrivate
-{
- // Key: relationship type
- // Value: GList of OsinfoOs *
- // Note: Only used when osfiltering OsinfoOs objects
- GHashTable *osConstraints;
-};
-
-static void osinfo_osfilter_finalize (GObject *object);
-static gboolean osinfo_osfilter_matches_default(OsinfoFilter *osfilter, OsinfoEntity *entity);
-
-static void
-osinfo_osfilter_finalize (GObject *object)
-{
- OsinfoOsfilter *osfilter = OSINFO_OSFILTER (object);
-
- g_hash_table_unref(osfilter->priv->osConstraints);
-
- /* Chain up to the parent class */
- G_OBJECT_CLASS (osinfo_osfilter_parent_class)->finalize (object);
-}
-
-/* Init functions */
-static void
-osinfo_osfilter_class_init (OsinfoOsfilterClass *klass)
-{
- GObjectClass *g_klass = G_OBJECT_CLASS(klass);
- OsinfoFilterClass *filter_klass = OSINFO_FILTER_CLASS(klass);
-
- g_klass->finalize = osinfo_osfilter_finalize;
- g_type_class_add_private (klass, sizeof (OsinfoOsfilterPrivate));
-
- filter_klass->matches = osinfo_osfilter_matches_default;
-}
-
-
-/**
- * osinfo_osfilter_new:
- *
- * Construct a new filter that matches all operating
- * systems
- *
- * Returns: (transfer full): a new filter
- */
-OsinfoOsfilter *osinfo_osfilter_new(void)
-{
- return g_object_new(OSINFO_TYPE_OSFILTER, NULL);
-}
-
-
-static void
-osinfo_osfilter_os_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
-{
- g_object_unref(value);
-}
-
-static void
-osinfo_osfilter_os_constraints_free(gpointer relshps)
-{
- g_list_foreach(relshps, osinfo_osfilter_os_constraint_free, NULL);
- g_list_free(relshps);
-}
-
-static void
-osinfo_osfilter_init (OsinfoOsfilter *osfilter)
-{
- OsinfoOsfilterPrivate *priv;
- priv = OSINFO_OSFILTER_GET_PRIVATE(osfilter);
- osfilter->priv = priv;
-
- osfilter->priv->osConstraints =
- g_hash_table_new_full(g_direct_hash,
- g_direct_equal,
- NULL,
- osinfo_osfilter_os_constraints_free);
-}
-
-
-/**
- * osinfo_osfilter_add_os_constraint:
- * @osfilter: a filter object
- * @relshp: the relationship to filter on
- * @os: (transfer none): the target os to filter on
- *
- * Adds a constraint that matches operating systems which
- * have a relationship @relshp with @os. Multiple constraints
- * can be set for the same @relshp or @os, in which case
- * all must match
- */
-gint osinfo_osfilter_add_os_constraint(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp, OsinfoOs *os)
-{
- g_return_val_if_fail(OSINFO_IS_OSFILTER(osfilter), -1);
- g_return_val_if_fail(OSINFO_IS_OS(os), -1);
-
- // First check if there exists an array of entries for this key
- // If not, create a ptrarray of strings for this key and insert into map
- gboolean found;
- gpointer origKey, foundValue;
- GList *values = NULL;
-
- found = g_hash_table_lookup_extended(osfilter->priv->osConstraints, GINT_TO_POINTER(relshp), &origKey, &foundValue);
- if (found) {
- values = foundValue;
- g_hash_table_steal(osfilter->priv->osConstraints, GINT_TO_POINTER(relshp));
- }
- g_object_ref(os);
- values = g_list_prepend(values, os);
- g_hash_table_insert(osfilter->priv->osConstraints, GINT_TO_POINTER(relshp), values);
-
- return 0;
-}
-
-/**
- * osinfo_osfilter_clear_os_constraint:
- * @osfilter: a filter object
- * @relshp: the relationship to clear
- *
- * Remove all constraints for the relationship @relshp
- */
-void osinfo_osfilter_clear_os_constraint(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp)
-{
- g_hash_table_remove(osfilter->priv->osConstraints, (gpointer) relshp);
-}
-
-
-/**
- * osinfo_osfilter_clear_os_constraints:
- * @osfilter: a filter object
- *
- * Remove all relationship constraints
- */
-void osinfo_osfilter_clear_os_constraints(OsinfoOsfilter *osfilter)
-{
- g_hash_table_remove_all(osfilter->priv->osConstraints);
-}
-
-
-/**
- * osinfo_osfilter_get_os_constraint_values:
- * @osfilter: a filter object
- * @relshp: a relationship to query
- *
- * Retrieve a list of all operating systems that are
- * the target of constraint for the relationship
- * @relshp.
- *
- * Returns: (transfer container) (element-type OsinfoOs): a list of operating systems
- */
-GList *osinfo_osfilter_get_os_constraint_values(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp)
-{
- g_return_val_if_fail(OSINFO_IS_OSFILTER(osfilter), NULL);
-
- GList *values = g_hash_table_lookup(osfilter->priv->osConstraints, GINT_TO_POINTER(relshp));
-
- return g_list_copy(values);
-}
-
-
-struct osinfo_osfilter_match_args {
- OsinfoOsfilter *osfilter;
- OsinfoEntity *entity;
- gboolean matched;
-};
-
-
-static void osinfo_osfilter_match_os_iterator(gpointer key, gpointer value, gpointer data)
-{
- struct osinfo_osfilter_match_args *args = data;
- OsinfoOs *os = OSINFO_OS(args->entity);
- OsinfoOsRelationship relshp = GPOINTER_TO_INT(key);
- GList *relOses = value;
- OsinfoOsList *oslist = osinfo_os_get_related(os, relshp);
- gboolean ret = TRUE;
-
- if (relOses && osinfo_list_get_length(OSINFO_LIST(oslist)) == 0) {
- ret = FALSE;
- goto cleanup;
- }
-
- while (relOses) {
- OsinfoOs *currOs = relOses->data;
- int i;
- gboolean found = FALSE;
- for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(oslist)) ; i++) {
- OsinfoOs *testOs = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(oslist), i));
- if (testOs == currOs) {
- found = TRUE;
- break;
- }
- }
- if (!found) {
- ret = FALSE;
- goto cleanup;
- }
-
- relOses = relOses->next;
- }
-
- cleanup:
- g_object_unref(oslist);
- args->matched = ret;
-}
-
-static gboolean osinfo_osfilter_matches_default(OsinfoFilter *filter, OsinfoEntity *entity)
-{
- g_return_val_if_fail(OSINFO_IS_OSFILTER(filter), FALSE);
- g_return_val_if_fail(OSINFO_IS_OS(entity), FALSE);
- OsinfoOsfilter *osfilter = OSINFO_OSFILTER(filter);
- struct osinfo_osfilter_match_args args = { osfilter, entity, TRUE };
-
- if (!OSINFO_FILTER_CLASS (osinfo_osfilter_parent_class)->matches(filter, entity))
- return FALSE;
-
- g_hash_table_foreach(osfilter->priv->osConstraints,
- osinfo_osfilter_match_os_iterator,
- &args);
-
- return args.matched;
-}
-
-/*
- * Local variables:
- * indent-tabs-mode: nil
- * c-indent-level: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/osinfo/osinfo_osfilter.h b/osinfo/osinfo_osfilter.h
deleted file mode 100644
index 6336e8d..0000000
--- a/osinfo/osinfo_osfilter.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * libosinfo: a mechanism to filter operating systems
- *
- * Copyright (C) 2009-2010 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>
- */
-
-#ifndef __OSINFO_OSFILTER_H__
-#define __OSINFO_OSFILTER_H__
-
-/*
- * Type macros.
- */
-#define OSINFO_TYPE_OSFILTER (osinfo_osfilter_get_type ())
-#define OSINFO_OSFILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_OSFILTER, OsinfoOsfilter))
-#define OSINFO_IS_OSFILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_OSFILTER))
-#define OSINFO_OSFILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_OSFILTER, OsinfoOsfilterClass))
-#define OSINFO_IS_OSFILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_OSFILTER))
-#define OSINFO_OSFILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_OSFILTER, OsinfoOsfilterClass))
-
-typedef struct _OsinfoOsfilter OsinfoOsfilter;
-
-typedef struct _OsinfoOsfilterClass OsinfoOsfilterClass;
-
-typedef struct _OsinfoOsfilterPrivate OsinfoOsfilterPrivate;
-
-/* object */
-struct _OsinfoOsfilter
-{
- OsinfoFilter parent_instance;
-
- /* public */
-
- /* private */
- OsinfoOsfilterPrivate *priv;
-};
-
-/* class */
-struct _OsinfoOsfilterClass
-{
- OsinfoFilterClass parent_class;
-
- /* class members */
-};
-
-GType osinfo_osfilter_get_type(void);
-
-OsinfoOsfilter *osinfo_osfilter_new(void);
-
-gint osinfo_osfilter_add_os_constraint(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp, OsinfoOs *os);
-void osinfo_osfilter_clear_os_constraint(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp);
-void osinfo_osfilter_clear_os_constraints(OsinfoOsfilter *osfilter);
-
-GList *osinfo_osfilter_get_os_constraint_values(OsinfoOsfilter *osfilter, OsinfoOsRelationship relshp);
-
-#endif /* __OSINFO_OSFILTER_H__ */
-/*
- * Local variables:
- * indent-tabs-mode: nil
- * c-indent-level: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/osinfo/osinfo_oslist.c b/osinfo/osinfo_oslist.c
index 3a52d55..b368ca3 100644
--- a/osinfo/osinfo_oslist.c
+++ b/osinfo/osinfo_oslist.c
@@ -24,7 +24,7 @@
#include <osinfo/osinfo.h>
-G_DEFINE_TYPE (OsinfoOsList, osinfo_oslist, OSINFO_TYPE_LIST);
+G_DEFINE_TYPE (OsinfoOsList, osinfo_oslist, OSINFO_TYPE_PRODUCTLIST);
#define OSINFO_OSLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_OSLIST, OsinfoOsListPrivate))
diff --git a/osinfo/osinfo_oslist.h b/osinfo/osinfo_oslist.h
index 25b7601..2ac5117 100644
--- a/osinfo/osinfo_oslist.h
+++ b/osinfo/osinfo_oslist.h
@@ -24,7 +24,7 @@
#include <glib-object.h>
#include <osinfo/osinfo_filter.h>
-#include <osinfo/osinfo_list.h>
+#include <osinfo/osinfo_productlist.h>
#ifndef __OSINFO_OSLIST_H__
#define __OSINFO_OSLIST_H__
@@ -48,7 +48,7 @@ typedef struct _OsinfoOsListPrivate OsinfoOsListPrivate;
/* object */
struct _OsinfoOsList
{
- OsinfoList parent_instance;
+ OsinfoProductList parent_instance;
/* public */
@@ -59,7 +59,7 @@ struct _OsinfoOsList
/* class */
struct _OsinfoOsListClass
{
- OsinfoListClass parent_class;
+ OsinfoProductListClass parent_class;
/* class members */
};
diff --git a/osinfo/osinfo_platform.c b/osinfo/osinfo_platform.c
index bf3ea9a..cccb72e 100644
--- a/osinfo/osinfo_platform.c
+++ b/osinfo/osinfo_platform.c
@@ -24,7 +24,7 @@
#include <osinfo/osinfo.h>
-G_DEFINE_TYPE (OsinfoPlatform, osinfo_platform, OSINFO_TYPE_ENTITY);
+G_DEFINE_TYPE (OsinfoPlatform, osinfo_platform, OSINFO_TYPE_PRODUCT);
#define OSINFO_PLATFORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_PLATFORM, OsinfoPlatformPrivate))
diff --git a/osinfo/osinfo_platform.h b/osinfo/osinfo_platform.h
index e6bc84e..908167e 100644
--- a/osinfo/osinfo_platform.h
+++ b/osinfo/osinfo_platform.h
@@ -23,6 +23,7 @@
*/
#include <glib-object.h>
+#include <osinfo/osinfo_product.h>
#include <osinfo/osinfo_device.h>
#include <osinfo/osinfo_devicelist.h>
@@ -48,7 +49,7 @@ typedef struct _OsinfoPlatformPrivate OsinfoPlatformPrivate;
/* object */
struct _OsinfoPlatform
{
- OsinfoEntity parent_instance;
+ OsinfoProduct parent_instance;
/* public */
@@ -59,7 +60,7 @@ struct _OsinfoPlatform
/* class */
struct _OsinfoPlatformClass
{
- OsinfoEntityClass parent_class;
+ OsinfoProductClass parent_class;
/* class members */
};
diff --git a/osinfo/osinfo_platformlist.c b/osinfo/osinfo_platformlist.c
index 84fd9b3..bc54e13 100644
--- a/osinfo/osinfo_platformlist.c
+++ b/osinfo/osinfo_platformlist.c
@@ -24,7 +24,7 @@
#include <osinfo/osinfo.h>
-G_DEFINE_TYPE (OsinfoPlatformList, osinfo_platformlist, OSINFO_TYPE_LIST);
+G_DEFINE_TYPE (OsinfoPlatformList, osinfo_platformlist, OSINFO_TYPE_PRODUCTLIST);
#define OSINFO_PLATFORMLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_PLATFORMLIST, OsinfoPlatformListPrivate))
diff --git a/osinfo/osinfo_platformlist.h b/osinfo/osinfo_platformlist.h
index 99a52b3..f0f602a 100644
--- a/osinfo/osinfo_platformlist.h
+++ b/osinfo/osinfo_platformlist.h
@@ -24,7 +24,7 @@
#include <glib-object.h>
#include <osinfo/osinfo_filter.h>
-#include <osinfo/osinfo_list.h>
+#include <osinfo/osinfo_productlist.h>
#ifndef __OSINFO_PLATFORMLIST_H__
#define __OSINFO_PLATFORMLIST_H__
@@ -48,7 +48,7 @@ typedef struct _OsinfoPlatformListPrivate OsinfoPlatformListPrivate;
/* object */
struct _OsinfoPlatformList
{
- OsinfoList parent_instance;
+ OsinfoProductList parent_instance;
/* public */
@@ -59,7 +59,7 @@ struct _OsinfoPlatformList
/* class */
struct _OsinfoPlatformListClass
{
- OsinfoListClass parent_class;
+ OsinfoProductListClass parent_class;
/* class members */
};
diff --git a/osinfo/osinfo_product.c b/osinfo/osinfo_product.c
new file mode 100644
index 0000000..05d3d7c
--- /dev/null
+++ b/osinfo/osinfo_product.c
@@ -0,0 +1,164 @@
+/*
+ * osinfo:
+ *
+ * Copyright (C) 2009-2010 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 PURPPRODUCTE. 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, Bproductton, MA 02111-1307 USA
+ *
+ * Authors:
+ * Arjun Roy <arroy@redhat.com>
+ * Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <osinfo/osinfo.h>
+
+G_DEFINE_ABSTRACT_TYPE (OsinfoProduct, osinfo_product, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_PRODUCT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_PRODUCT, OsinfoProductPrivate))
+
+/**
+ * SECTION:osinfo_product
+ * @short_description: An software product
+ * @see_also: #OsinfoProduct, #OsinfoPlatform
+ *
+ * #OsinfoProduct is an entity representing an software
+ * product. There are relationships amongst products
+ * to declare which are newest releases, which are clones
+ * and which are derived from a common ancestry.
+ */
+
+/**
+ * OsinfoProductRelationship:
+ * @OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM: a descendent (RHEL-5 derives from Fedora-6)
+ * @OSINFO_PRODUCT_RELATIONSHIP_CLONES: a perfect clone (CentPRODUCT-5 clones RHEL-5)
+ * @OSINFO_PRODUCT_RELATIONSHIP_UPGRADES: a new version release (RHEL-6 upgrades RHEL-4)
+ *
+ * Enum values used to form relationships between products
+ */
+struct _OsinfoProductPrivate
+{
+ // Value: Array of product_link structs
+ GList *productLinks;
+};
+
+struct _OsinfoProductProductLink {
+ /* <product> 'verbs' <other_product>
+ * fedora11 upgrades fedora10
+ * centproduct clones rhel
+ * scientificlinux derives from rhel
+ */
+ OsinfoProductRelationship relshp;
+ OsinfoProduct *otherProduct;
+};
+
+static void osinfo_product_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
+{
+ struct _OsinfoProductProductLink *link = data;
+ g_object_unref(link->otherProduct);
+ g_free(link);
+}
+
+
+static void
+osinfo_product_finalize (GObject *object)
+{
+ OsinfoProduct *product = OSINFO_PRODUCT (object);
+
+ g_list_foreach(product->priv->productLinks, osinfo_product_link_free, NULL);
+ g_list_free(product->priv->productLinks);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (osinfo_product_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_product_class_init (OsinfoProductClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+ g_klass->finalize = osinfo_product_finalize;
+ g_type_class_add_private (klass, sizeof (OsinfoProductPrivate));
+}
+
+static void
+osinfo_product_init (OsinfoProduct *product)
+{
+ OsinfoProductPrivate *priv;
+ product->priv = priv = OSINFO_PRODUCT_GET_PRIVATE(product);
+
+ product->priv->productLinks = NULL;
+}
+
+
+/**
+ * osinfo_product_get_related:
+ * @product: an product
+ * @relshp: the relationship to query
+ *
+ * Get a list of products satisfying the the requested
+ * relationship
+ *
+ * Returns: (transfer full): a list of related products
+ */
+OsinfoProductList *osinfo_product_get_related(OsinfoProduct *product, OsinfoProductRelationship relshp)
+{
+ g_return_val_if_fail(OSINFO_IS_PRODUCT(product), NULL);
+
+ // Create our list
+ OsinfoProductList *newList = osinfo_productlist_new();
+ GList *tmp = product->priv->productLinks;
+
+ while (tmp) {
+ struct _OsinfoProductProductLink *link = tmp->data;
+
+ if (link->relshp == relshp)
+ osinfo_list_add(OSINFO_LIST(newList), OSINFO_ENTITY(link->otherProduct));
+
+ tmp = tmp->next;
+ }
+
+ return newList;
+}
+
+
+/**
+ * osinfo_product_add_related:
+ * @product: a product
+ * @relshp: the relationship
+ * @otherproduct: (transfer none): the product to relate to
+ *
+ * Add an association between two products
+ */
+void osinfo_product_add_related(OsinfoProduct *product, OsinfoProductRelationship relshp, OsinfoProduct *otherproduct)
+{
+ g_return_if_fail(OSINFO_IS_PRODUCT(product));
+ g_return_if_fail(OSINFO_IS_PRODUCT(otherproduct));
+
+ struct _OsinfoProductProductLink *productLink = g_new0(struct _OsinfoProductProductLink, 1);
+
+ g_object_ref(otherproduct);
+ productLink->otherProduct = otherproduct;
+ productLink->relshp = relshp;
+
+ product->priv->productLinks = g_list_prepend(product->priv->productLinks, productLink);
+}
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_product.h b/osinfo/osinfo_product.h
new file mode 100644
index 0000000..9fec397
--- /dev/null
+++ b/osinfo/osinfo_product.h
@@ -0,0 +1,86 @@
+/*
+ * osinfo: an software product
+ *
+ * Copyright (C) 2009-2010 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 PURPPRODUCTE. 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, Bproductton, MA 02111-1307 USA
+ *
+ * Authors:
+ * Arjun Roy <arroy@redhat.com>
+ * Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_productlist.h>
+
+#ifndef __OSINFO_PRODUCT_H__
+#define __OSINFO_PRODUCT_H__
+
+/*
+ * Type macrproduct.
+ */
+#define OSINFO_TYPE_PRODUCT (osinfo_product_get_type ())
+#define OSINFO_PRODUCT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_PRODUCT, OsinfoProduct))
+#define OSINFO_IS_PRODUCT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_PRODUCT))
+#define OSINFO_PRODUCT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_PRODUCT, OsinfoProductClass))
+#define OSINFO_IS_PRODUCT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_PRODUCT))
+#define OSINFO_PRODUCT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_PRODUCT, OsinfoProductClass))
+
+typedef struct _OsinfoProduct OsinfoProduct;
+
+typedef struct _OsinfoProductClass OsinfoProductClass;
+
+typedef struct _OsinfoProductPrivate OsinfoProductPrivate;
+
+/* object */
+struct _OsinfoProduct
+{
+ OsinfoEntity parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoProductPrivate *priv;
+};
+
+/* class */
+struct _OsinfoProductClass
+{
+ OsinfoEntityClass parent_class;
+
+ /* class members */
+};
+
+typedef enum {
+ OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM,
+ OSINFO_PRODUCT_RELATIONSHIP_UPGRADES,
+ OSINFO_PRODUCT_RELATIONSHIP_CLONES,
+} OsinfoProductRelationship;
+
+
+GType osinfo_product_get_type(void);
+
+OsinfoProductList *osinfo_product_get_related(OsinfoProduct *product, OsinfoProductRelationship relshp);
+
+void osinfo_product_add_related(OsinfoProduct *product, OsinfoProductRelationship relshp, OsinfoProduct *otherproduct);
+
+#endif /* __OSINFO_PRODUCT_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_productfilter.c b/osinfo/osinfo_productfilter.c
new file mode 100644
index 0000000..f3609d4
--- /dev/null
+++ b/osinfo/osinfo_productfilter.c
@@ -0,0 +1,268 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2010 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 (OsinfoProductFilter, osinfo_productfilter, OSINFO_TYPE_FILTER);
+
+#define OSINFO_PRODUCTFILTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_PRODUCTFILTER, OsinfoProductFilterPrivate))
+
+/**
+ * SECTION:osinfo_productfilter
+ * @short_description: an operating system filter
+ * @see_also: #OsinfoFilter, #OsinfoProduct
+ *
+ * #OsinfoProductFilter is a specialization of #OsinfoFilter that
+ * can also set constraints against operating system
+ * relationships. It can only be used to filter entities
+ * that are #OsinfoProduct objects.
+ */
+
+struct _OsinfoProductFilterPrivate
+{
+ // Key: relationship type
+ // Value: GList of OsinfoProduct *
+ // Note: Only used when productfiltering OsinfoProduct objects
+ GHashTable *productConstraints;
+};
+
+static void osinfo_productfilter_finalize (GObject *object);
+static gboolean osinfo_productfilter_matches_default(OsinfoFilter *productfilter, OsinfoEntity *entity);
+
+static void
+osinfo_productfilter_finalize (GObject *object)
+{
+ OsinfoProductFilter *productfilter = OSINFO_PRODUCTFILTER (object);
+
+ g_hash_table_unref(productfilter->priv->productConstraints);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (osinfo_productfilter_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_productfilter_class_init (OsinfoProductFilterClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS(klass);
+ OsinfoFilterClass *filter_klass = OSINFO_FILTER_CLASS(klass);
+
+ g_klass->finalize = osinfo_productfilter_finalize;
+ g_type_class_add_private (klass, sizeof (OsinfoProductFilterPrivate));
+
+ filter_klass->matches = osinfo_productfilter_matches_default;
+}
+
+
+/**
+ * osinfo_productfilter_new:
+ *
+ * Construct a new filter that matches all operating
+ * systems
+ *
+ * Returns: (transfer full): a new filter
+ */
+OsinfoProductFilter *osinfo_productfilter_new(void)
+{
+ return g_object_new(OSINFO_TYPE_PRODUCTFILTER, NULL);
+}
+
+
+static void
+osinfo_productfilter_product_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
+{
+ g_object_unref(value);
+}
+
+static void
+osinfo_productfilter_product_constraints_free(gpointer relshps)
+{
+ g_list_foreach(relshps, osinfo_productfilter_product_constraint_free, NULL);
+ g_list_free(relshps);
+}
+
+static void
+osinfo_productfilter_init (OsinfoProductFilter *productfilter)
+{
+ OsinfoProductFilterPrivate *priv;
+ priv = OSINFO_PRODUCTFILTER_GET_PRIVATE(productfilter);
+ productfilter->priv = priv;
+
+ productfilter->priv->productConstraints =
+ g_hash_table_new_full(g_direct_hash,
+ g_direct_equal,
+ NULL,
+ osinfo_productfilter_product_constraints_free);
+}
+
+
+/**
+ * osinfo_productfilter_add_product_constraint:
+ * @productfilter: a filter object
+ * @relshp: the relationship to filter on
+ * @product: (transfer none): the target product to filter on
+ *
+ * Adds a constraint that matches products which
+ * have a relationship @relshp with @product. Multiple constraints
+ * can be set for the same @relshp or @product, in which case
+ * all must match
+ */
+gint osinfo_productfilter_add_product_constraint(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp, OsinfoProduct *product)
+{
+ g_return_val_if_fail(OSINFO_IS_PRODUCTFILTER(productfilter), -1);
+ g_return_val_if_fail(OSINFO_IS_PRODUCT(product), -1);
+
+ // First check if there exists an array of entries for this key
+ // If not, create a ptrarray of strings for this key and insert into map
+ gboolean found;
+ gpointer origKey, foundValue;
+ GList *values = NULL;
+
+ found = g_hash_table_lookup_extended(productfilter->priv->productConstraints, GINT_TO_POINTER(relshp), &origKey, &foundValue);
+ if (found) {
+ values = foundValue;
+ g_hash_table_steal(productfilter->priv->productConstraints, GINT_TO_POINTER(relshp));
+ }
+ g_object_ref(product);
+ values = g_list_prepend(values, product);
+ g_hash_table_insert(productfilter->priv->productConstraints, GINT_TO_POINTER(relshp), values);
+
+ return 0;
+}
+
+/**
+ * osinfo_productfilter_clear_product_constraint:
+ * @productfilter: a filter object
+ * @relshp: the relationship to clear
+ *
+ * Remove all constraints for the relationship @relshp
+ */
+void osinfo_productfilter_clear_product_constraint(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp)
+{
+ g_hash_table_remove(productfilter->priv->productConstraints, (gpointer) relshp);
+}
+
+
+/**
+ * osinfo_productfilter_clear_product_constraints:
+ * @productfilter: a filter object
+ *
+ * Remove all relationship constraints
+ */
+void osinfo_productfilter_clear_product_constraints(OsinfoProductFilter *productfilter)
+{
+ g_hash_table_remove_all(productfilter->priv->productConstraints);
+}
+
+
+/**
+ * osinfo_productfilter_get_product_constraint_values:
+ * @productfilter: a filter object
+ * @relshp: a relationship to query
+ *
+ * Retrieve a list of all operating systems that are
+ * the target of constraint for the relationship
+ * @relshp.
+ *
+ * Returns: (transfer container) (element-type OsinfoProduct): a list of operating systems
+ */
+GList *osinfo_productfilter_get_product_constraint_values(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp)
+{
+ g_return_val_if_fail(OSINFO_IS_PRODUCTFILTER(productfilter), NULL);
+
+ GList *values = g_hash_table_lookup(productfilter->priv->productConstraints, GINT_TO_POINTER(relshp));
+
+ return g_list_copy(values);
+}
+
+
+struct osinfo_productfilter_match_args {
+ OsinfoProductFilter *productfilter;
+ OsinfoEntity *entity;
+ gboolean matched;
+};
+
+
+static void osinfo_productfilter_match_product_iterator(gpointer key, gpointer value, gpointer data)
+{
+ struct osinfo_productfilter_match_args *args = data;
+ OsinfoProduct *product = OSINFO_PRODUCT(args->entity);
+ OsinfoProductRelationship relshp = GPOINTER_TO_INT(key);
+ GList *relProducts = value;
+ OsinfoProductList *productlist = osinfo_product_get_related(product, relshp);
+ gboolean ret = TRUE;
+
+ if (relProducts && osinfo_list_get_length(OSINFO_LIST(productlist)) == 0) {
+ ret = FALSE;
+ goto cleanup;
+ }
+
+ while (relProducts) {
+ OsinfoProduct *currProduct = relProducts->data;
+ int i;
+ gboolean found = FALSE;
+ for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(productlist)) ; i++) {
+ OsinfoProduct *testProduct = OSINFO_PRODUCT(osinfo_list_get_nth(OSINFO_LIST(productlist), i));
+ if (testProduct == currProduct) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found) {
+ ret = FALSE;
+ goto cleanup;
+ }
+
+ relProducts = relProducts->next;
+ }
+
+ cleanup:
+ g_object_unref(productlist);
+ args->matched = ret;
+}
+
+static gboolean osinfo_productfilter_matches_default(OsinfoFilter *filter, OsinfoEntity *entity)
+{
+ g_return_val_if_fail(OSINFO_IS_PRODUCTFILTER(filter), FALSE);
+ g_return_val_if_fail(OSINFO_IS_PRODUCT(entity), FALSE);
+ OsinfoProductFilter *productfilter = OSINFO_PRODUCTFILTER(filter);
+ struct osinfo_productfilter_match_args args = { productfilter, entity, TRUE };
+
+ if (!OSINFO_FILTER_CLASS (osinfo_productfilter_parent_class)->matches(filter, entity))
+ return FALSE;
+
+ g_hash_table_foreach(productfilter->priv->productConstraints,
+ osinfo_productfilter_match_product_iterator,
+ &args);
+
+ return args.matched;
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_productfilter.h b/osinfo/osinfo_productfilter.h
new file mode 100644
index 0000000..7067e47
--- /dev/null
+++ b/osinfo/osinfo_productfilter.h
@@ -0,0 +1,80 @@
+/*
+ * libosinfo: a mechanism to filter operating systems
+ *
+ * Copyright (C) 2009-2010 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>
+ */
+
+#ifndef __OSINFO_PRODUCTFILTER_H__
+#define __OSINFO_PRODUCTFILTER_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_PRODUCTFILTER (osinfo_productfilter_get_type ())
+#define OSINFO_PRODUCTFILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_PRODUCTFILTER, OsinfoProductFilter))
+#define OSINFO_IS_PRODUCTFILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_PRODUCTFILTER))
+#define OSINFO_PRODUCTFILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_PRODUCTFILTER, OsinfoProductFilterClass))
+#define OSINFO_IS_PRODUCTFILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_PRODUCTFILTER))
+#define OSINFO_PRODUCTFILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_PRODUCTFILTER, OsinfoProductFilterClass))
+
+typedef struct _OsinfoProductFilter OsinfoProductFilter;
+
+typedef struct _OsinfoProductFilterClass OsinfoProductFilterClass;
+
+typedef struct _OsinfoProductFilterPrivate OsinfoProductFilterPrivate;
+
+/* object */
+struct _OsinfoProductFilter
+{
+ OsinfoFilter parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoProductFilterPrivate *priv;
+};
+
+/* class */
+struct _OsinfoProductFilterClass
+{
+ OsinfoFilterClass parent_class;
+
+ /* class members */
+};
+
+GType osinfo_productfilter_get_type(void);
+
+OsinfoProductFilter *osinfo_productfilter_new(void);
+
+gint osinfo_productfilter_add_product_constraint(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp, OsinfoProduct *product);
+void osinfo_productfilter_clear_product_constraint(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp);
+void osinfo_productfilter_clear_product_constraints(OsinfoProductFilter *productfilter);
+
+GList *osinfo_productfilter_get_product_constraint_values(OsinfoProductFilter *productfilter, OsinfoProductRelationship relshp);
+
+#endif /* __OSINFO_PRODUCTFILTER_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_productlist.c b/osinfo/osinfo_productlist.c
new file mode 100644
index 0000000..7d1ce0e
--- /dev/null
+++ b/osinfo/osinfo_productlist.c
@@ -0,0 +1,166 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2010 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 (OsinfoProductList, osinfo_productlist, OSINFO_TYPE_LIST);
+
+#define OSINFO_PRODUCTLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_PRODUCTLIST, OsinfoProductListPrivate))
+
+/**
+ * SECTION:osinfo_productlist
+ * @short_description: A list of software products
+ * @see_also: #OsinfoList, #OsinfoProduct
+ *
+ * #OsinfoProductList is a list specialization that stores
+ * only #OsinfoProduct objects.
+ */
+
+struct _OsinfoProductListPrivate
+{
+ gboolean unused;
+};
+
+static void
+osinfo_productlist_finalize (GObject *object)
+{
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (osinfo_productlist_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_productlist_class_init (OsinfoProductListClass *klass)
+{
+ GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+ g_klass->finalize = osinfo_productlist_finalize;
+ g_type_class_add_private (klass, sizeof (OsinfoProductListPrivate));
+}
+
+static void
+osinfo_productlist_init (OsinfoProductList *list)
+{
+ OsinfoProductListPrivate *priv;
+ list->priv = priv = OSINFO_PRODUCTLIST_GET_PRIVATE(list);
+
+}
+
+
+/**
+ * osinfo_productlist_new:
+ *
+ * Construct a new os list that is initially empty.
+ *
+ * Returns: (transfer full): an empty os list
+ */
+OsinfoProductList *osinfo_productlist_new(void)
+{
+ return g_object_new(OSINFO_TYPE_PRODUCTLIST,
+ "element-type", OSINFO_TYPE_PRODUCT,
+ NULL);
+}
+
+
+/**
+ * osinfo_productlist_new_copy:
+ * @source: the os list to copy
+ *
+ * Construct a new os list that is filled with oss
+ * from @source
+ *
+ * Returns: (transfer full): a copy of the os list
+ */
+OsinfoProductList *osinfo_productlist_new_copy(OsinfoProductList *source)
+{
+ OsinfoProductList *newList = osinfo_productlist_new();
+ osinfo_list_add_all(OSINFO_LIST(newList),
+ OSINFO_LIST(source));
+ return newList;
+}
+
+/**
+ * osinfo_productlist_new_filtered:
+ * @source: the os list to copy
+ * @filter: the filter to apply
+ *
+ * Construct a new os list that is filled with oss
+ * from @source that match @filter
+ *
+ * Returns: (transfer full): a filtered copy of the os list
+ */
+OsinfoProductList *osinfo_productlist_new_filtered(OsinfoProductList *source, OsinfoFilter *filter)
+{
+ OsinfoProductList *newList = osinfo_productlist_new();
+ osinfo_list_add_filtered(OSINFO_LIST(newList),
+ OSINFO_LIST(source),
+ filter);
+ return newList;
+}
+
+/**
+ * osinfo_productlist_new_intersection:
+ * @sourceOne: the first os list to copy
+ * @sourceTwo: the second os list to copy
+ *
+ * Construct a new os list that is filled with only the
+ * oss that are present in both @sourceOne and @sourceTwo.
+ *
+ * Returns: (transfer full): an intersection of the two os lists
+ */
+OsinfoProductList *osinfo_productlist_new_intersection(OsinfoProductList *sourceOne, OsinfoProductList *sourceTwo)
+{
+ OsinfoProductList *newList = osinfo_productlist_new();
+ osinfo_list_add_intersection(OSINFO_LIST(newList),
+ OSINFO_LIST(sourceOne),
+ OSINFO_LIST(sourceTwo));
+ return newList;
+}
+
+/**
+ * osinfo_productlist_new_union:
+ * @sourceOne: the first os list to copy
+ * @sourceTwo: the second os list to copy
+ *
+ * Construct a new os list that is filled with all the
+ * oss that are present in either @sourceOne and @sourceTwo.
+ *
+ * Returns: (transfer full): a union of the two os lists
+ */
+OsinfoProductList *osinfo_productlist_new_union(OsinfoProductList *sourceOne, OsinfoProductList *sourceTwo)
+{
+ OsinfoProductList *newList = osinfo_productlist_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_productlist.h b/osinfo/osinfo_productlist.h
new file mode 100644
index 0000000..0a0582b
--- /dev/null
+++ b/osinfo/osinfo_productlist.h
@@ -0,0 +1,82 @@
+/*
+ * libosinfo: a list of software products
+ *
+ * Copyright (C) 2009-2010 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 <glib-object.h>
+#include <osinfo/osinfo_filter.h>
+#include <osinfo/osinfo_list.h>
+
+#ifndef __OSINFO_PRODUCTLIST_H__
+#define __OSINFO_PRODUCTLIST_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_PRODUCTLIST (osinfo_productlist_get_type ())
+#define OSINFO_PRODUCTLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_PRODUCTLIST, OsinfoProductList))
+#define OSINFO_IS_PRODUCTLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_PRODUCTLIST))
+#define OSINFO_PRODUCTLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_PRODUCTLIST, OsinfoProductListClass))
+#define OSINFO_IS_PRODUCTLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_PRODUCTLIST))
+#define OSINFO_PRODUCTLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_PRODUCTLIST, OsinfoProductListClass))
+
+typedef struct _OsinfoProductList OsinfoProductList;
+
+typedef struct _OsinfoProductListClass OsinfoProductListClass;
+
+typedef struct _OsinfoProductListPrivate OsinfoProductListPrivate;
+
+/* object */
+struct _OsinfoProductList
+{
+ OsinfoList parent_instance;
+
+ /* public */
+
+ /* private */
+ OsinfoProductListPrivate *priv;
+};
+
+/* class */
+struct _OsinfoProductListClass
+{
+ OsinfoListClass parent_class;
+
+ /* class members */
+};
+
+GType osinfo_productlist_get_type(void);
+
+OsinfoProductList *osinfo_productlist_new(void);
+OsinfoProductList *osinfo_productlist_new_copy(OsinfoProductList *source);
+OsinfoProductList *osinfo_productlist_new_filtered(OsinfoProductList *source, OsinfoFilter *filter);
+OsinfoProductList *osinfo_productlist_new_intersection(OsinfoProductList *sourceOne, OsinfoProductList *sourceTwo);
+OsinfoProductList *osinfo_productlist_new_union(OsinfoProductList *sourceOne, OsinfoProductList *sourceTwo);
+
+#endif /* __OSINFO_PRODUCTLIST_H__ */
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/test/Makefile.am b/test/Makefile.am
index 747784c..3dcd623 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,9 +5,10 @@ check_PROGRAMS = \
test-list \
test-devicelist \
test-filter \
+ test-product \
test-os \
test-oslist \
- test-osfilter \
+ test-productfilter \
test-platform \
test-platformlist \
test-db \
@@ -38,13 +39,17 @@ test_filter_LDADD = $(COMMON_LDADD)
test_filter_CFLAGS = $(COMMON_CFLAGS)
test_filter_SOURCES = test-filter.c
+test_product_LDADD = $(COMMON_LDADD)
+test_product_CFLAGS = $(COMMON_CFLAGS)
+test_product_SOURCES = test-product.c
+
test_os_LDADD = $(COMMON_LDADD)
test_os_CFLAGS = $(COMMON_CFLAGS)
test_os_SOURCES = test-os.c
-test_osfilter_LDADD = $(COMMON_LDADD)
-test_osfilter_CFLAGS = $(COMMON_CFLAGS)
-test_osfilter_SOURCES = test-osfilter.c
+test_productfilter_LDADD = $(COMMON_LDADD)
+test_productfilter_CFLAGS = $(COMMON_CFLAGS)
+test_productfilter_SOURCES = test-productfilter.c
test_platform_LDADD = $(COMMON_LDADD)
test_platform_CFLAGS = $(COMMON_CFLAGS)
diff --git a/test/test-db.c b/test/test-db.c
index 2b11544..308927d 100644
--- a/test/test-db.c
+++ b/test/test-db.c
@@ -171,7 +171,7 @@ START_TEST(test_prop_platform)
osinfo_db_add_platform(db, hv2);
osinfo_db_add_platform(db, hv3);
- GList *uniq = osinfo_db_unique_values_for_property_in_hv(db, "vendor");
+ GList *uniq = osinfo_db_unique_values_for_property_in_platform(db, "vendor");
GList *tmp = uniq;
gboolean hasAcme = FALSE;
gboolean hasFrog = FALSE;
@@ -268,12 +268,12 @@ START_TEST(test_rel_os)
osinfo_db_add_os(db, os4);
osinfo_db_add_os(db, os5);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os3);
- osinfo_os_add_related_os(os2, OSINFO_OS_RELATIONSHIP_CLONES, os4);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_UPGRADES, os5);
+ osinfo_product_add_related(OSINFO_PRODUCT(os1), OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, OSINFO_PRODUCT(os2));
+ osinfo_product_add_related(OSINFO_PRODUCT(os1), OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, OSINFO_PRODUCT(os3));
+ osinfo_product_add_related(OSINFO_PRODUCT(os2), OSINFO_PRODUCT_RELATIONSHIP_CLONES, OSINFO_PRODUCT(os4));
+ osinfo_product_add_related(OSINFO_PRODUCT(os3), OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, OSINFO_PRODUCT(os5));
- OsinfoOsList *sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_DERIVES_FROM);
+ OsinfoOsList *sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
gboolean hasOs1 = FALSE;
gboolean hasOs2 = FALSE;
gboolean hasOs3 = FALSE;
@@ -307,7 +307,7 @@ START_TEST(test_rel_os)
g_object_unref(sublist);
- sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_UPGRADES);
+ sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES);
hasOs1 = hasOs2 = hasOs3 = hasOs4 = hasOs5 = hasBad = FALSE;
for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(sublist)) ; i++) {
OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(sublist), i));
@@ -335,7 +335,7 @@ START_TEST(test_rel_os)
g_object_unref(sublist);
- sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_OS_RELATIONSHIP_CLONES);
+ sublist = osinfo_db_unique_values_for_os_relationship(db, OSINFO_PRODUCT_RELATIONSHIP_CLONES);
hasOs1 = hasOs2 = hasOs3 = hasOs4 = hasOs5 = hasBad = FALSE;
for (i = 0 ; i < osinfo_list_get_length(OSINFO_LIST(sublist)) ; i++) {
OsinfoOs *ent = OSINFO_OS(osinfo_list_get_nth(OSINFO_LIST(sublist), i));
diff --git a/test/test-os.c b/test/test-os.c
index b08f779..f2b4d3a 100644
--- a/test/test-os.c
+++ b/test/test-os.c
@@ -165,53 +165,6 @@ START_TEST(test_hv_devices_filter)
END_TEST
-START_TEST(test_relos)
-{
- OsinfoOs *os1 = osinfo_os_new("pony");
- OsinfoOs *os2 = osinfo_os_new("donkey");
- OsinfoOs *os3 = osinfo_os_new("wathog");
- OsinfoOs *os4 = osinfo_os_new("aardvark");
- OsinfoOs *os5 = osinfo_os_new("unicorn");
-
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_UPGRADES, os3);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_UPGRADES, os4);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_UPGRADES, os4);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_CLONES, os5);
-
- OsinfoOsList *os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM);
- fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 derived os");
- fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os2), "derived os is os2");
- g_object_unref(os1rel);
-
- os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_UPGRADES);
- fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 2, "Os has 2 upgraded os");
- fail_unless((osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os3) ||
- osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os4)) &&
- (osinfo_list_get_nth(OSINFO_LIST(os1rel), 1) == OSINFO_ENTITY(os3) ||
- osinfo_list_get_nth(OSINFO_LIST(os1rel), 1) == OSINFO_ENTITY(os4)),
- "upgraded oses are os3 + os4");
- g_object_unref(os1rel);
-
- os1rel = osinfo_os_get_related(os3, OSINFO_OS_RELATIONSHIP_UPGRADES);
- fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 upgraded os");
- fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os4), "upgraded os is os4");
- g_object_unref(os1rel);
-
- os1rel = osinfo_os_get_related(os1, OSINFO_OS_RELATIONSHIP_CLONES);
- fail_unless(osinfo_list_get_length(OSINFO_LIST(os1rel)) == 1, "Os has 1 upgraded os");
- fail_unless(osinfo_list_get_nth(OSINFO_LIST(os1rel), 0) == OSINFO_ENTITY(os5), "cloned os is os5");
- g_object_unref(os1rel);
-
- g_object_unref(os1);
- g_object_unref(os2);
- g_object_unref(os3);
- g_object_unref(os4);
- g_object_unref(os5);
-}
-END_TEST
-
-
START_TEST(test_device_driver)
{
OsinfoOs *os = osinfo_os_new("awesome");
@@ -323,7 +276,6 @@ os_suite(void)
tcase_add_test(tc, test_hv_devices);
tcase_add_test(tc, test_hv_devices_filter);
tcase_add_test(tc, test_hv_device_driver);
- tcase_add_test(tc, test_relos);
suite_add_tcase(s, tc);
return s;
}
diff --git a/test/test-osfilter.c b/test/test-osfilter.c
deleted file mode 100644
index ff888af..0000000
--- a/test/test-osfilter.c
+++ /dev/null
@@ -1,221 +0,0 @@
-#include <stdlib.h>
-#include <osinfo/osinfo.h>
-#include <check.h>
-
-
-
-START_TEST(test_basic)
-{
- OsinfoOsfilter *osfilter = osinfo_osfilter_new();
- OsinfoOs *os1 = osinfo_os_new("pretty");
- OsinfoOs *os2 = osinfo_os_new("ugly");
-
- fail_unless(OSINFO_IS_OSFILTER(osfilter), "Osfilter is a osfilter object");
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Osfilter matches OS");
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os1);
- GList *tmp = osinfo_osfilter_get_os_constraint_values(osfilter,
- OSINFO_OS_RELATIONSHIP_DERIVES_FROM);
- fail_unless(tmp != NULL, "Unexpected missing OS");
- fail_unless(tmp->data == os1, "Derived OS is OS 1");
- fail_unless(tmp->next == NULL, "Too many derived OS");
- g_list_free(tmp);
-
- tmp = osinfo_osfilter_get_os_constraint_values(osfilter,
- OSINFO_OS_RELATIONSHIP_CLONES);
- fail_unless(tmp == NULL, "Unexpected cloned OS");
-
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- tmp = osinfo_osfilter_get_os_constraint_values(osfilter,
- OSINFO_OS_RELATIONSHIP_DERIVES_FROM);
- fail_unless(tmp != NULL, "Unexpected missing OS");
- fail_unless(tmp->data == os2, "Derived OS is OS 1");
- fail_unless(tmp->next != NULL, "Not enough derived OS");
- fail_unless(tmp->next->data == os1, "Derived OS is OS 1");
- fail_unless(tmp->next->next == NULL, "Too many derived OS");
- g_list_free(tmp);
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_UPGRADES, os1);
- tmp = osinfo_osfilter_get_os_constraint_values(osfilter,
- OSINFO_OS_RELATIONSHIP_UPGRADES);
- fail_unless(tmp != NULL, "Unexpected missing OS");
- fail_unless(tmp->data == os1, "Derived OS is OS 1");
- fail_unless(tmp->next == NULL, "Too many derived OS");
- g_list_free(tmp);
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES, os1);
- tmp = osinfo_osfilter_get_os_constraint_values(osfilter,
- OSINFO_OS_RELATIONSHIP_CLONES);
- fail_unless(tmp != NULL, "Unexpected missing OS");
- fail_unless(tmp->data == os1, "Derived OS is OS 1");
- fail_unless(tmp->next == NULL, "Too many derived OS");
- g_list_free(tmp);
-
- g_object_unref(os2);
- g_object_unref(os1);
- g_object_unref(osfilter);
-}
-END_TEST
-
-
-START_TEST(test_osfilter_single)
-{
- OsinfoOsfilter *osfilter = osinfo_osfilter_new();
- OsinfoOs *os1 = osinfo_os_new("hot");
- OsinfoOs *os2 = osinfo_os_new("or");
- OsinfoOs *os3 = osinfo_os_new("not");
- OsinfoOs *os4 = osinfo_os_new("burger");
-
-
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os4);
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
-
- g_object_unref(os1);
- g_object_unref(os2);
- g_object_unref(os3);
- g_object_unref(os4);
- g_object_unref(osfilter);
-}
-END_TEST
-
-
-START_TEST(test_osfilter_multi)
-{
- OsinfoOsfilter *osfilter = osinfo_osfilter_new();
- OsinfoOs *os1 = osinfo_os_new("hot");
- OsinfoOs *os2 = osinfo_os_new("or");
- OsinfoOs *os3 = osinfo_os_new("not");
- OsinfoOs *os4 = osinfo_os_new("burger");
- OsinfoOs *os5 = osinfo_os_new("cat");
-
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_CLONES, os5);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_CLONES, os4);
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES, os5);
-
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5");
-
- osinfo_osfilter_clear_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_CLONES);
-
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter matches OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5");
-
- osinfo_osfilter_clear_os_constraints(osfilter);
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_UPGRADES, os5);
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os5)), "Filter does not match OS 5");
-
- g_object_unref(os1);
- g_object_unref(os2);
- g_object_unref(os3);
- g_object_unref(os4);
- g_object_unref(os5);
- g_object_unref(osfilter);
-}
-END_TEST
-
-
-START_TEST(test_osfilter_combine)
-{
- OsinfoOsfilter *osfilter = osinfo_osfilter_new();
- OsinfoOs *os1 = osinfo_os_new("hot");
- OsinfoOs *os2 = osinfo_os_new("or");
- OsinfoOs *os3 = osinfo_os_new("not");
- OsinfoOs *os4 = osinfo_os_new("burger");
-
- osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- osinfo_os_add_related_os(os3, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os4);
-
- osinfo_entity_add_param(OSINFO_ENTITY(os1), "vendor", "drevil");
- osinfo_entity_add_param(OSINFO_ENTITY(os3), "vendor", "acme");
-
- osinfo_osfilter_add_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter matches OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
-
- osinfo_filter_add_constraint(OSINFO_FILTER(osfilter), "vendor", "acme");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter does not match OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
-
- osinfo_osfilter_clear_os_constraint(osfilter, OSINFO_OS_RELATIONSHIP_DERIVES_FROM);
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os1)), "Filter does not match OS 1");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os2)), "Filter does not match OS 2");
- fail_unless(osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os3)), "Filter matches OS 3");
- fail_unless(!osinfo_filter_matches(OSINFO_FILTER(osfilter), OSINFO_ENTITY(os4)), "Filter does not match OS 4");
-
- g_object_unref(os1);
- g_object_unref(os2);
- g_object_unref(os3);
- g_object_unref(os4);
- g_object_unref(osfilter);
-}
-END_TEST
-
-
-static Suite *
-osfilter_suite(void)
-{
- Suite *s = suite_create("Osfilter");
- TCase *tc = tcase_create("Core");
- tcase_add_test(tc, test_basic);
- tcase_add_test(tc, test_osfilter_single);
- tcase_add_test(tc, test_osfilter_multi);
- tcase_add_test(tc, test_osfilter_combine);
- suite_add_tcase(s, tc);
- return s;
-}
-
-int main(void)
-{
- int number_failed;
- Suite *s = osfilter_suite ();
- SRunner *sr = srunner_create (s);
-
- g_type_init();
-
- /* Upfront so we don't confuse valgrind */
- osinfo_entity_get_type();
- osinfo_filter_get_type();
- osinfo_list_get_type();
- osinfo_oslist_get_type();
- osinfo_osfilter_get_type();
- osinfo_os_get_type();
-
- srunner_run_all (sr, CK_ENV);
- number_failed = srunner_ntests_failed (sr);
- srunner_free (sr);
-
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-/*
- * Local variables:
- * indent-tabs-mode: nil
- * c-indent-level: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/test/test-product.c b/test/test-product.c
new file mode 100644
index 0000000..31796c2
--- /dev/null
+++ b/test/test-product.c
@@ -0,0 +1,130 @@
+#include <stdlib.h>
+#include <osinfo/osinfo.h>
+#include <check.h>
+
+/* OsinfoProduct is abstract, so we need to trivially subclass it to test it */
+typedef struct _OsinfoDummy OsinfoDummy;
+typedef struct _OsinfoDummyClass OsinfoDummyClass;
+
+struct _OsinfoDummy
+{
+ OsinfoProduct parent_instance;
+};
+
+struct _OsinfoDummyClass
+{
+ OsinfoProductClass parent_class;
+};
+
+GType osinfo_dummy_get_type(void);
+
+G_DEFINE_TYPE (OsinfoDummy, osinfo_dummy, OSINFO_TYPE_PRODUCT);
+
+static void osinfo_dummy_class_init(OsinfoDummyClass *klass G_GNUC_UNUSED){}
+static void osinfo_dummy_init (OsinfoDummy *self G_GNUC_UNUSED) {}
+
+static OsinfoProduct *osinfo_dummy_new(const gchar *id) {
+ return g_object_new(osinfo_dummy_get_type(), "id", id, NULL);
+}
+
+
+START_TEST(test_basic)
+{
+ OsinfoProduct *product = osinfo_dummy_new("pony");
+
+ fail_unless(OSINFO_IS_PRODUCT(product), "Product is a product object");
+ fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(product)), "pony") == 0, "Product ID was pony");
+
+ g_object_unref(product);
+}
+END_TEST
+
+
+START_TEST(test_relproduct)
+{
+ OsinfoProduct *product1 = osinfo_dummy_new("pony");
+ OsinfoProduct *product2 = osinfo_dummy_new("donkey");
+ OsinfoProduct *product3 = osinfo_dummy_new("wathog");
+ OsinfoProduct *product4 = osinfo_dummy_new("aardvark");
+ OsinfoProduct *product5 = osinfo_dummy_new("unicorn");
+
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product3);
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product4);
+ osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product4);
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product5);
+
+ OsinfoProductList *product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
+ fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 derived product");
+ fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product2), "derived product is product2");
+ g_object_unref(product1rel);
+
+ product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES);
+ fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 2, "Product has 2 upgraded product");
+ fail_unless((osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product3) ||
+ osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4)) &&
+ (osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product3) ||
+ osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product4)),
+ "upgraded productes are product3 + product4");
+ g_object_unref(product1rel);
+
+ product1rel = osinfo_product_get_related(product3, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES);
+ fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 upgraded product");
+ fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4), "upgraded product is product4");
+ g_object_unref(product1rel);
+
+ product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_CLONES);
+ fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 upgraded product");
+ fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product5), "cloned product is product5");
+ g_object_unref(product1rel);
+
+ g_object_unref(product1);
+ g_object_unref(product2);
+ g_object_unref(product3);
+ g_object_unref(product4);
+ g_object_unref(product5);
+}
+END_TEST
+
+
+
+static Suite *
+product_suite(void)
+{
+ Suite *s = suite_create("Product");
+ TCase *tc = tcase_create("Core");
+ tcase_add_test(tc, test_basic);
+ tcase_add_test(tc, test_relproduct);
+ suite_add_tcase(s, tc);
+ return s;
+}
+
+int main(void)
+{
+ int number_failed;
+ Suite *s = product_suite ();
+ SRunner *sr = srunner_create (s);
+
+ g_type_init();
+
+ /* Upfront so we don't confuse valgrind */
+ osinfo_platform_get_type();
+ osinfo_device_get_type();
+ osinfo_product_get_type();
+ osinfo_productlist_get_type();
+ osinfo_devicelist_get_type();
+ osinfo_filter_get_type();
+
+ srunner_run_all (sr, CK_ENV);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/test/test-productfilter.c b/test/test-productfilter.c
new file mode 100644
index 0000000..dccdd75
--- /dev/null
+++ b/test/test-productfilter.c
@@ -0,0 +1,245 @@
+#include <stdlib.h>
+#include <osinfo/osinfo.h>
+#include <check.h>
+
+/* OsinfoProduct is abstract, so we need to trivially subclass it to test it */
+typedef struct _OsinfoDummy OsinfoDummy;
+typedef struct _OsinfoDummyClass OsinfoDummyClass;
+
+struct _OsinfoDummy
+{
+ OsinfoProduct parent_instance;
+};
+
+struct _OsinfoDummyClass
+{
+ OsinfoProductClass parent_class;
+};
+
+GType osinfo_dummy_get_type(void);
+
+G_DEFINE_TYPE (OsinfoDummy, osinfo_dummy, OSINFO_TYPE_PRODUCT);
+
+static void osinfo_dummy_class_init(OsinfoDummyClass *klass G_GNUC_UNUSED){}
+static void osinfo_dummy_init (OsinfoDummy *self G_GNUC_UNUSED) {}
+
+static OsinfoProduct *osinfo_dummy_new(const gchar *id) {
+ return g_object_new(osinfo_dummy_get_type(), "id", id, NULL);
+}
+
+
+START_TEST(test_basic)
+{
+ OsinfoProductFilter *productfilter = osinfo_productfilter_new();
+ OsinfoProduct *product1 = osinfo_dummy_new("pretty");
+ OsinfoProduct *product2 = osinfo_dummy_new("ugly");
+
+ fail_unless(OSINFO_IS_PRODUCTFILTER(productfilter), "ProductFilter is a productfilter object");
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "ProductFilter matches PRODUCT");
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product1);
+ GList *tmp = osinfo_productfilter_get_product_constraint_values(productfilter,
+ OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
+ fail_unless(tmp != NULL, "Unexpected missing PRODUCT");
+ fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1");
+ fail_unless(tmp->next == NULL, "Too many derived PRODUCT");
+ g_list_free(tmp);
+
+ tmp = osinfo_productfilter_get_product_constraint_values(productfilter,
+ OSINFO_PRODUCT_RELATIONSHIP_CLONES);
+ fail_unless(tmp == NULL, "Unexpected cloned PRODUCT");
+
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ tmp = osinfo_productfilter_get_product_constraint_values(productfilter,
+ OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
+ fail_unless(tmp != NULL, "Unexpected missing PRODUCT");
+ fail_unless(tmp->data == product2, "Derived PRODUCT is PRODUCT 1");
+ fail_unless(tmp->next != NULL, "Not enough derived PRODUCT");
+ fail_unless(tmp->next->data == product1, "Derived PRODUCT is PRODUCT 1");
+ fail_unless(tmp->next->next == NULL, "Too many derived PRODUCT");
+ g_list_free(tmp);
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product1);
+ tmp = osinfo_productfilter_get_product_constraint_values(productfilter,
+ OSINFO_PRODUCT_RELATIONSHIP_UPGRADES);
+ fail_unless(tmp != NULL, "Unexpected missing PRODUCT");
+ fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1");
+ fail_unless(tmp->next == NULL, "Too many derived PRODUCT");
+ g_list_free(tmp);
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product1);
+ tmp = osinfo_productfilter_get_product_constraint_values(productfilter,
+ OSINFO_PRODUCT_RELATIONSHIP_CLONES);
+ fail_unless(tmp != NULL, "Unexpected missing PRODUCT");
+ fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1");
+ fail_unless(tmp->next == NULL, "Too many derived PRODUCT");
+ g_list_free(tmp);
+
+ g_object_unref(product2);
+ g_object_unref(product1);
+ g_object_unref(productfilter);
+}
+END_TEST
+
+
+START_TEST(test_productfilter_single)
+{
+ OsinfoProductFilter *productfilter = osinfo_productfilter_new();
+ OsinfoProduct *product1 = osinfo_dummy_new("hot");
+ OsinfoProduct *product2 = osinfo_dummy_new("or");
+ OsinfoProduct *product3 = osinfo_dummy_new("not");
+ OsinfoProduct *product4 = osinfo_dummy_new("burger");
+
+
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product4);
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+
+ g_object_unref(product1);
+ g_object_unref(product2);
+ g_object_unref(product3);
+ g_object_unref(product4);
+ g_object_unref(productfilter);
+}
+END_TEST
+
+
+START_TEST(test_productfilter_multi)
+{
+ OsinfoProductFilter *productfilter = osinfo_productfilter_new();
+ OsinfoProduct *product1 = osinfo_dummy_new("hot");
+ OsinfoProduct *product2 = osinfo_dummy_new("or");
+ OsinfoProduct *product3 = osinfo_dummy_new("not");
+ OsinfoProduct *product4 = osinfo_dummy_new("burger");
+ OsinfoProduct *product5 = osinfo_dummy_new("cat");
+
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product5);
+ osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product4);
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product5);
+
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5");
+
+ osinfo_productfilter_clear_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES);
+
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter matches PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5");
+
+ osinfo_productfilter_clear_product_constraints(productfilter);
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product5);
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5");
+
+ g_object_unref(product1);
+ g_object_unref(product2);
+ g_object_unref(product3);
+ g_object_unref(product4);
+ g_object_unref(product5);
+ g_object_unref(productfilter);
+}
+END_TEST
+
+
+START_TEST(test_productfilter_combine)
+{
+ OsinfoProductFilter *productfilter = osinfo_productfilter_new();
+ OsinfoProduct *product1 = osinfo_dummy_new("hot");
+ OsinfoProduct *product2 = osinfo_dummy_new("or");
+ OsinfoProduct *product3 = osinfo_dummy_new("not");
+ OsinfoProduct *product4 = osinfo_dummy_new("burger");
+
+ osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product4);
+
+ osinfo_entity_add_param(OSINFO_ENTITY(product1), "vendor", "drevil");
+ osinfo_entity_add_param(OSINFO_ENTITY(product3), "vendor", "acme");
+
+ osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2);
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+
+ osinfo_filter_add_constraint(OSINFO_FILTER(productfilter), "vendor", "acme");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+
+ osinfo_productfilter_clear_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM);
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2");
+ fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter matches PRODUCT 3");
+ fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4");
+
+ g_object_unref(product1);
+ g_object_unref(product2);
+ g_object_unref(product3);
+ g_object_unref(product4);
+ g_object_unref(productfilter);
+}
+END_TEST
+
+
+static Suite *
+productfilter_suite(void)
+{
+ Suite *s = suite_create("ProductFilter");
+ TCase *tc = tcase_create("Core");
+ tcase_add_test(tc, test_basic);
+ tcase_add_test(tc, test_productfilter_single);
+ tcase_add_test(tc, test_productfilter_multi);
+ tcase_add_test(tc, test_productfilter_combine);
+ suite_add_tcase(s, tc);
+ return s;
+}
+
+int main(void)
+{
+ int number_failed;
+ Suite *s = productfilter_suite ();
+ SRunner *sr = srunner_create (s);
+
+ g_type_init();
+
+ /* Upfront so we don't confuse valgrind */
+ osinfo_entity_get_type();
+ osinfo_filter_get_type();
+ osinfo_list_get_type();
+ osinfo_productlist_get_type();
+ osinfo_productfilter_get_type();
+ osinfo_product_get_type();
+
+ srunner_run_all (sr, CK_ENV);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ */