[gupnp-dlna/wip/new-api: 6/46] Simplify gupnp_dlna_native_restriction_merge.



commit d1d1c0ad71f57c3978648303a14ddd9b4d10956e
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Tue Nov 27 17:42:10 2012 +0100

    Simplify gupnp_dlna_native_restriction_merge.
    
    Only the FROM_TARGET conflict resolution option was used in the code,
    so we remove other options.

 .../native/gupnp-dlna-native-profile-loader.c      |   11 +--
 .../native/sets/gupnp-dlna-native-restriction.c    |  101 +++---------------
 .../native/sets/gupnp-dlna-native-restriction.h    |   14 +--
 .../native/sets/gupnp-dlna-native-sets-private.h   |   11 --
 .../native/sets/gupnp-dlna-native-value-list.c     |   54 ---------
 tests/sets.c                                       |  114 +-------------------
 6 files changed, 20 insertions(+), 285 deletions(-)
---
diff --git a/libgupnp-dlna/profile-backends/native/gupnp-dlna-native-profile-loader.c b/libgupnp-dlna/profile-backends/native/gupnp-dlna-native-profile-loader.c
index 758c0eb..d42cb7e 100644
--- a/libgupnp-dlna/profile-backends/native/gupnp-dlna-native-profile-loader.c
+++ b/libgupnp-dlna/profile-backends/native/gupnp-dlna-native-profile-loader.c
@@ -529,14 +529,9 @@ backend_post_restriction (GUPnPDLNAProfileLoader *loader,
                 GUPnPDLNANativeRestriction *parent =
                                       (GUPnPDLNANativeRestriction *) iter->data;
 
-                if (gupnp_dlna_native_restriction_merge
-                   (restriction,
-                    parent,
-                    GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_TARGET))
-                        iter->data = NULL;
-                else
-                        g_critical ("Failed to do restriction overriding "
-                                    "merge.");
+                gupnp_dlna_native_restriction_merge (restriction,
+                                                     parent);
+                iter->data = NULL;
         }
 
         description = gupnp_dlna_native_description_new (restriction, type);
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.c b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.c
index a565b3d..13ba94b 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.c
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.c
@@ -103,109 +103,34 @@ gupnp_dlna_native_restriction_add_value_list
         return TRUE;
 }
 
-static gboolean
-check_merge_possibility (GUPnPDLNANativeRestriction *restriction,
-                         GUPnPDLNANativeRestriction *merged)
-{
-        GHashTableIter iter;
-        gpointer mrg_name_ptr;
-        gpointer mrg_value_list_ptr;
-
-        g_hash_table_iter_init (&iter, merged->entries);
-        while (g_hash_table_iter_next (&iter,
-                                       &mrg_name_ptr,
-                                       &mrg_value_list_ptr)) {
-                gpointer value_list_ptr;
-
-                if (g_hash_table_lookup_extended (restriction->entries,
-                                                  mrg_name_ptr,
-                                                  NULL,
-                                                  &value_list_ptr)) {
-                        GUPnPDLNANativeValueList *value_list =
-                                    (GUPnPDLNANativeValueList *) value_list_ptr;
-                        GUPnPDLNANativeValueList *mrg_value_list =
-                                (GUPnPDLNANativeValueList *) mrg_value_list_ptr;
-
-                        if (!gupnp_dlna_native_value_list_mergeable
-                                        (value_list,
-                                         mrg_value_list))
-                                return FALSE;
-                }
-        }
-
-        return TRUE;
-}
-
-gboolean
-gupnp_dlna_native_restriction_merge
-                        (GUPnPDLNANativeRestriction                *restriction,
-                         GUPnPDLNANativeRestriction                *merged,
-                         GUPnPDLNANativeRestrictionMergeResolution  resolution)
+void
+gupnp_dlna_native_restriction_merge (GUPnPDLNANativeRestriction *restriction,
+                                     GUPnPDLNANativeRestriction *merged)
 {
         GHashTableIter iter;
-        gpointer mrg_name_ptr;
-        gpointer mrg_value_list_ptr;
-        gboolean change_mime;
-
-        g_return_val_if_fail (restriction != NULL, FALSE);
-        g_return_val_if_fail (merged != NULL, FALSE);
-
-        switch (resolution) {
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_TARGET:
-                change_mime = (restriction->mime == NULL);
-
-                break;
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_SOURCE:
-                change_mime = (merged->mime != NULL);
+        gpointer name_ptr;
+        gpointer value_list_ptr;
 
-                break;
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE:
-                change_mime = (restriction->mime == NULL &&
-                               merged->mime != NULL);
+        g_return_if_fail (restriction != NULL);
+        g_return_if_fail (merged != NULL);
 
-                break;
-        default:
-                change_mime = FALSE;
-                g_critical ("Unknown conflict resolution: %d", resolution);
-        }
-        if (change_mime) {
-                g_free (restriction->mime);
+        if (restriction->mime == NULL) {
                 restriction->mime = merged->mime;
                 merged->mime = NULL;
         }
 
-        if (resolution == GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE &&
-            !check_merge_possibility (restriction, merged))
-                return FALSE;
-
         g_hash_table_iter_init (&iter, merged->entries);
         while (g_hash_table_iter_next (&iter,
-                                       &mrg_name_ptr,
-                                       &mrg_value_list_ptr)) {
-                gpointer value_list_ptr;
-
-                if (g_hash_table_lookup_extended (restriction->entries,
-                                                  mrg_name_ptr,
-                                                  NULL,
-                                                  &value_list_ptr)) {
-                        GUPnPDLNANativeValueList *value_list =
-                                    (GUPnPDLNANativeValueList *) value_list_ptr;
-                        GUPnPDLNANativeValueList *mrg_value_list =
-                                (GUPnPDLNANativeValueList *) mrg_value_list_ptr;
-
-                        gupnp_dlna_native_value_list_merge (value_list,
-                                                            mrg_value_list,
-                                                            resolution);
-                } else {
+                                       &name_ptr,
+                                       &value_list_ptr)) {
+                if (!g_hash_table_contains (restriction->entries, name_ptr)) {
                         g_hash_table_iter_steal (&iter);
                         g_hash_table_insert (restriction->entries,
-                                             mrg_name_ptr,
-                                             mrg_value_list_ptr);
+                                             name_ptr,
+                                             value_list_ptr);
                 }
         }
         gupnp_dlna_native_restriction_free (merged);
-
-        return TRUE;
 }
 
 gboolean
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.h b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.h
index 63bdeca..e550693 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.h
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-restriction.h
@@ -28,12 +28,6 @@
 
 G_BEGIN_DECLS
 
-typedef enum {
-        GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_TARGET,
-        GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_SOURCE,
-        GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE
-} GUPnPDLNANativeRestrictionMergeResolution;
-
 typedef struct _GUPnPDLNANativeRestriction GUPnPDLNANativeRestriction;
 
 #define GUPNP_DLNA_NATIVE_RESTRICTION(x) \
@@ -54,11 +48,9 @@ gupnp_dlna_native_restriction_add_value_list
                                         const gchar                *name,
                                         GUPnPDLNANativeValueList   *list);
 
-gboolean
-gupnp_dlna_native_restriction_merge
-                        (GUPnPDLNANativeRestriction                *restriction,
-                         GUPnPDLNANativeRestriction                *merged,
-                         GUPnPDLNANativeRestrictionMergeResolution  override);
+void
+gupnp_dlna_native_restriction_merge (GUPnPDLNANativeRestriction *restriction,
+                                     GUPnPDLNANativeRestriction *merged);
 
 gboolean
 gupnp_dlna_native_restriction_is_empty
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-sets-private.h b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-sets-private.h
index f45f9bd..fd8c4a8 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-sets-private.h
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-sets-private.h
@@ -99,23 +99,12 @@ gupnp_dlna_native_value_list_is_superset
                                          GUPnPDLNANativeInfoValue *value,
                                          gboolean                 *unsupported);
 
-void
-gupnp_dlna_native_value_list_merge
-                     (GUPnPDLNANativeValueList                  *value_list,
-                      GUPnPDLNANativeValueList                  *mrg_value_list,
-                      GUPnPDLNANativeRestrictionMergeResolution  resolution);
-
 gboolean
 gupnp_dlna_native_value_list_is_empty (GUPnPDLNANativeValueList *value_list);
 
 GList *
 gupnp_dlna_native_value_list_get_list (GUPnPDLNANativeValueList *value_list);
 
-gboolean
-gupnp_dlna_native_value_list_mergeable
-                                     (GUPnPDLNANativeValueList *value_list,
-                                      GUPnPDLNANativeValueList *mrg_value_list);
-
 gchar *
 gupnp_dlna_native_value_list_to_string (GUPnPDLNANativeValueList *value_list);
 
diff --git a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value-list.c b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value-list.c
index 617f2bb..96a7297 100644
--- a/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value-list.c
+++ b/libgupnp-dlna/profile-backends/native/sets/gupnp-dlna-native-value-list.c
@@ -201,60 +201,6 @@ gupnp_dlna_native_value_list_is_superset (GUPnPDLNANativeValueList *list,
 }
 
 gboolean
-gupnp_dlna_native_value_list_mergeable
-                                      (GUPnPDLNANativeValueList *value_list,
-                                       GUPnPDLNANativeValueList *mrg_value_list)
-{
-        if (value_list->type != mrg_value_list->type) {
-                return FALSE;
-        }
-
-        return TRUE;
-}
-
-void
-gupnp_dlna_native_value_list_merge
-                     (GUPnPDLNANativeValueList                  *value_list,
-                      GUPnPDLNANativeValueList                  *mrg_value_list,
-                      GUPnPDLNANativeRestrictionMergeResolution  resolution)
-{
-        g_return_if_fail (value_list != NULL);
-        g_return_if_fail (mrg_value_list != NULL);
-
-        switch (resolution) {
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_TARGET:
-                /* do nothing */
-                break;
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_SOURCE:
-                free_value_list (value_list);
-                value_list->values = mrg_value_list->values;
-                value_list->type = mrg_value_list->type;
-                mrg_value_list->values = NULL;
-
-                break;
-        case GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE:
-                if (!gupnp_dlna_native_value_list_mergeable (value_list,
-                                                             mrg_value_list)) {
-                        g_critical ("Tried to merge values of type '%s' into "
-                                    "values of type '%s'.",
-                                    gupnp_dlna_native_value_type_name
-                                        (mrg_value_list->type),
-                                    gupnp_dlna_native_value_type_name
-                                        (value_list->type));
-
-                        return;
-                }
-                value_list->values = g_list_concat (value_list->values,
-                                                    mrg_value_list->values);
-                mrg_value_list->values = NULL;
-
-                break;
-        default:
-                g_critical ("Unknown conflict resolution: %d", resolution);
-        }
-}
-
-gboolean
 gupnp_dlna_native_value_list_is_empty (GUPnPDLNANativeValueList *value_list)
 {
         g_return_val_if_fail (value_list != NULL, TRUE);
diff --git a/tests/sets.c b/tests/sets.c
index e63c19b..8d60fcf 100644
--- a/tests/sets.c
+++ b/tests/sets.c
@@ -247,119 +247,7 @@ restriction_adding_value_lists (void)
 static void
 restriction_merge (void)
 {
-        GUPnPDLNANativeRestriction *r1 =
-                                     gupnp_dlna_native_restriction_new (NULL);
-        GUPnPDLNANativeRestriction *r2 =
-                                     gupnp_dlna_native_restriction_new ("mime1");
-        GUPnPDLNANativeValueList *v;
-        GHashTable *e;
-        GList *l;
-
-        g_assert (gupnp_dlna_native_restriction_merge
-                         (r1,
-                          r2,
-                          GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE));
-        g_assert_cmpstr (gupnp_dlna_native_restriction_get_mime (r1),
-                         ==,
-                         "mime1");
-
-        r2 = gupnp_dlna_native_restriction_new ("mime2");
-        g_assert (gupnp_dlna_native_restriction_merge
-                         (r1,
-                          r2,
-                          GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE));
-        g_assert_cmpstr (gupnp_dlna_native_restriction_get_mime (r1),
-                         ==,
-                         "mime1");
-
-        v = gupnp_dlna_native_value_list_new
-                                       (gupnp_dlna_native_value_type_string ());
-        g_assert (gupnp_dlna_native_value_list_add_single (v, "string1"));
-        gupnp_dlna_native_restriction_add_value_list (r1, "s", v);
-
-        v = gupnp_dlna_native_value_list_new
-                                        (gupnp_dlna_native_value_type_int ());
-        g_assert (gupnp_dlna_native_value_list_add_single (v, "1"));
-        g_assert (gupnp_dlna_native_restriction_add_value_list (r1, "i", v));
-
-        r2 = gupnp_dlna_native_restriction_new ("mime2");
-        v = gupnp_dlna_native_value_list_new
-                                       (gupnp_dlna_native_value_type_string ());
-        g_assert (gupnp_dlna_native_value_list_add_single (v, "string2"));
-        g_assert (gupnp_dlna_native_restriction_add_value_list (r2, "s", v));
-
-        v = gupnp_dlna_native_value_list_new
-                                        (gupnp_dlna_native_value_type_bool ());
-        g_assert (gupnp_dlna_native_value_list_add_single (v, "true"));
-        g_assert (gupnp_dlna_native_restriction_add_value_list (r2, "b", v));
-
-        g_assert (gupnp_dlna_native_restriction_merge
-                         (r1,
-                          r2,
-                          GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE));
-
-        /* TODO: Check types and values */
-        e = gupnp_dlna_native_restriction_get_entries (r1);
-        g_assert_cmpuint (g_hash_table_size (e), ==, 3);
-        v = g_hash_table_lookup (e, "i");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 1);
-
-        v = g_hash_table_lookup (e, "s");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 2);
-
-        v = g_hash_table_lookup (e, "b");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 1);
-
-        r2 = gupnp_dlna_native_restriction_new ("mime2");
-        v = gupnp_dlna_native_value_list_new
-                                       (gupnp_dlna_native_value_type_bool ());
-        g_assert (gupnp_dlna_native_value_list_add_single (v, "true"));
-        g_assert (gupnp_dlna_native_restriction_add_value_list (r2, "s", v));
-
-        g_assert (!gupnp_dlna_native_restriction_merge
-                         (r1,
-                          r2,
-                          GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_NONE));
-        g_assert (gupnp_dlna_native_restriction_merge
-                  (r1,
-                   r2,
-                   GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_SOURCE));
-        g_assert_cmpstr (gupnp_dlna_native_restriction_get_mime (r1),
-                         ==,
-                         "mime2");
-        /* TODO: Check types and values. */
-        e = gupnp_dlna_native_restriction_get_entries (r1);
-        g_assert_cmpuint (g_hash_table_size (e), ==, 3);
-        v = g_hash_table_lookup (e, "i");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 1);
-
-        v = g_hash_table_lookup (e, "s");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 1);
-
-        v = g_hash_table_lookup (e, "b");
-        g_assert (v != NULL);
-        l = gupnp_dlna_native_value_list_get_list (v);
-        g_assert_cmpuint (g_list_length (l), ==, 1);
-
-        r2 = gupnp_dlna_native_restriction_new (NULL);
-        g_assert (gupnp_dlna_native_restriction_merge
-                  (r1,
-                   r2,
-                   GUPNP_DLNA_NATIVE_RESTRICTION_MERGE_RESOLUTION_FROM_SOURCE));
-        g_assert_cmpstr (gupnp_dlna_native_restriction_get_mime (r1),
-                         ==,
-                         "mime2");
-        gupnp_dlna_native_restriction_free (r1);
+        /* TODO: Write a test. */
 }
 
 static void



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