Fix: ir: make duplicate event classes check smarter
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 19 Mar 2015 19:07:32 +0000 (15:07 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 Mar 2015 21:36:00 +0000 (17:36 -0400)
This patch makes bt_ctf_stream_class_add_event_class()
compare not only event classes pointers when checking
for duplicate, but also equal names and equal IDs.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/stream-class.c

index 0f823ea7aab6e209d9cc4811152ba4739a54ca37..9ef5ca790d7bbf8c8fec5ed95620b2ec5f422cef 100644 (file)
@@ -220,6 +220,50 @@ end:
        return ret;
 }
 
+static
+void event_class_exists(gpointer element, gpointer query)
+{
+       struct bt_ctf_event_class *event_class_a = element;
+       struct search_query *search_query = query;
+       struct bt_ctf_event_class *event_class_b = search_query->value;
+       int64_t id_a, id_b;
+
+       if (search_query->value == element) {
+               search_query->found = 1;
+               goto end;
+       }
+
+       /*
+        * Two event classes cannot share the same name in a given
+        * stream class.
+        */
+       if (!strcmp(bt_ctf_event_class_get_name(event_class_a),
+                       bt_ctf_event_class_get_name(event_class_b))) {
+               search_query->found = 1;
+               goto end;
+       }
+
+       /*
+        * Two event classes cannot share the same ID in a given
+        * stream class.
+        */
+       id_a = bt_ctf_event_class_get_id(event_class_a);
+       id_b = bt_ctf_event_class_get_id(event_class_b);
+
+       if (id_a < 0 || id_b < 0) {
+               /* at least one ID is not set: will be automatically set later */
+               goto end;
+       }
+
+       if (id_a == id_b) {
+               search_query->found = 1;
+               goto end;
+       }
+
+end:
+       return;
+}
+
 int bt_ctf_stream_class_add_event_class(
                struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_event_class *event_class)
@@ -234,7 +278,8 @@ int bt_ctf_stream_class_add_event_class(
 
        /* Check for duplicate event classes */
        struct search_query query = { .value = event_class, .found = 0 };
-       g_ptr_array_foreach(stream_class->event_classes, value_exists, &query);
+       g_ptr_array_foreach(stream_class->event_classes, event_class_exists,
+               &query);
        if (query.found) {
                ret = -1;
                goto end;
This page took 0.025122 seconds and 4 git commands to generate.