lib: do not allow port to be removed when message iterators are active
[babeltrace.git] / lib / graph / component.c
index 7bca1bfd7ef542fcc50aea65094c2c48fece7cbb..841931270163110277f19d370c4cf727d35fdd95 100644 (file)
@@ -1,8 +1,7 @@
 /*
+ * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
 #define BT_LOG_TAG "COMP"
 #include <babeltrace/lib-logging-internal.h>
 
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/graph/self-component.h>
-#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-const.h>
+#include <babeltrace/graph/component-source-const.h>
+#include <babeltrace/graph/component-filter-const.h>
+#include <babeltrace/graph/component-sink-const.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/graph/component-source-internal.h>
 #include <babeltrace/graph/component-sink-internal.h>
 #include <babeltrace/graph/connection-internal.h>
 #include <babeltrace/graph/graph-internal.h>
-#include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/message-iterator-internal.h>
 #include <babeltrace/graph/port-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler-internal.h>
-#include <babeltrace/object.h>
 #include <babeltrace/types.h>
-#include <babeltrace/values.h>
-#include <babeltrace/values-internal.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/assert-pre-internal.h>
+#include <babeltrace/value.h>
+#include <babeltrace/value-internal.h>
 #include <stdint.h>
 #include <inttypes.h>
 
 static
 struct bt_component * (* const component_create_funcs[])(
-               struct bt_component_class *) = {
+               const struct bt_component_class *) = {
        [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create,
        [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create,
        [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_create,
@@ -182,7 +183,7 @@ void destroy_component(struct bt_object *obj)
 }
 
 enum bt_component_class_type bt_component_get_class_type(
-               struct bt_component *component)
+               const struct bt_component *component)
 {
        BT_ASSERT_PRE_NON_NULL(component, "Component");
        return component->class->type;
@@ -227,7 +228,8 @@ struct bt_port *add_port(
        /*
         * Notify the graph's creator that a new port was added.
         */
-       graph = bt_object_get_ref(bt_component_borrow_graph(component));
+       bt_object_get_ref(bt_component_borrow_graph(component));
+       graph = bt_component_borrow_graph(component);
        if (graph) {
                bt_graph_notify_port_added(graph, new_port);
                BT_OBJECT_PUT_REF_AND_RESET(graph);
@@ -241,14 +243,14 @@ end:
 }
 
 BT_HIDDEN
-uint64_t bt_component_get_input_port_count(struct bt_component *comp)
+uint64_t bt_component_get_input_port_count(const struct bt_component *comp)
 {
        BT_ASSERT_PRE_NON_NULL(comp, "Component");
        return (uint64_t) comp->input_ports->len;
 }
 
 BT_HIDDEN
-uint64_t bt_component_get_output_port_count(struct bt_component *comp)
+uint64_t bt_component_get_output_port_count(const struct bt_component *comp)
 {
        BT_ASSERT_PRE_NON_NULL(comp, "Component");
        return (uint64_t) comp->output_ports->len;
@@ -265,7 +267,6 @@ int bt_component_create(struct bt_component_class *component_class,
        BT_ASSERT(user_component);
        BT_ASSERT(component_class);
        BT_ASSERT(name);
-
        type = bt_component_class_get_type(component_class);
        BT_LIB_LOGD("Creating empty component from component class: %![cc-]+C, "
                "comp-name=\"%s\"", component_class, name);
@@ -276,9 +277,9 @@ int bt_component_create(struct bt_component_class *component_class,
                goto end;
        }
 
-       bt_object_init_shared_with_parent(&component->base,
-               destroy_component);
-       component->class = bt_object_get_ref(component_class);
+       bt_object_init_shared_with_parent(&component->base, destroy_component);
+       component->class = component_class;
+       bt_object_get_no_null_check(component->class);
        component->destroy = component_destroy_funcs[type];
        component->name = g_string_new(name);
        if (!component->name) {
@@ -320,20 +321,20 @@ end:
        return ret;
 }
 
-const char *bt_component_get_name(struct bt_component *component)
+const char *bt_component_get_name(const struct bt_component *component)
 {
        BT_ASSERT_PRE_NON_NULL(component, "Component");
        return component->name->str;
 }
 
 struct bt_component_class *bt_component_borrow_class(
-               struct bt_component *component)
+               const struct bt_component *component)
 {
        BT_ASSERT_PRE_NON_NULL(component, "Component");
        return component->class;
 }
 
-void *bt_self_component_get_data(struct bt_self_component *self_comp)
+void *bt_self_component_get_data(const struct bt_self_component *self_comp)
 {
        struct bt_component *component = (void *) self_comp;
 
@@ -359,7 +360,7 @@ void bt_component_set_graph(struct bt_component *component,
                graph ? &graph->base : NULL);
 }
 
-bt_bool bt_component_graph_is_canceled(struct bt_component *component)
+bt_bool bt_component_graph_is_canceled(const struct bt_component *component)
 {
        return bt_graph_is_canceled(
                (void *) bt_object_borrow_parent(&component->base));
@@ -480,10 +481,10 @@ void remove_port_by_index(struct bt_component *component,
         * below (in which its component is `NULL` as expected because
         * of the bt_object_set_parent() call below).
         *
-        * To avoid a destroyed port during the notification callback,
+        * To avoid a destroyed port during the message callback,
         * get a reference now, and put it (destroying the port if its
         * reference count is 0 at this point) after notifying the
-        * private graph's user.
+        * graph's user.
         */
        bt_object_get_no_null_check(&port->base);
 
@@ -544,8 +545,7 @@ void bt_component_remove_port(struct bt_component *component,
                struct bt_port *cur_port = g_ptr_array_index(ports, i);
 
                if (cur_port == port) {
-                       remove_port_by_index(component,
-                               ports, i);
+                       remove_port_by_index(component, ports, i);
                        goto end;
                }
        }
@@ -563,7 +563,7 @@ enum bt_self_component_status bt_component_accept_port_connection(
                struct bt_port *other_port)
 {
        typedef enum bt_self_component_status (*method_t)(
-               void *, void *, void *);
+               void *, void *, const void *);
 
        enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        method_t method = NULL;
@@ -626,7 +626,7 @@ enum bt_self_component_status bt_component_accept_port_connection(
                BT_LIB_LOGD("Calling user's \"accept port connection\" method: "
                        "%![comp-]+c, %![self-port-]+p, %![other-port-]+p",
                        comp, self_port, other_port);
-               status = method(comp, self_port, other_port);
+               status = method(comp, self_port, (void *) other_port);
                BT_LOGD("User method returned: status=%s",
                        bt_self_component_status_string(status));
        }
@@ -640,7 +640,7 @@ enum bt_self_component_status bt_component_port_connected(
                struct bt_port *other_port)
 {
        typedef enum bt_self_component_status (*method_t)(
-               void *, void *, void *);
+               void *, void *, const void *);
 
        enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
        method_t method = NULL;
@@ -703,7 +703,7 @@ enum bt_self_component_status bt_component_port_connected(
                BT_LIB_LOGD("Calling user's \"port connected\" method: "
                        "%![comp-]+c, %![self-port-]+p, %![other-port-]+p",
                        comp, self_port, other_port);
-               status = method(comp, self_port, other_port);
+               status = method(comp, self_port, (void *) other_port);
                BT_LOGD("User method returned: status=%s",
                        bt_self_component_status_string(status));
        }
@@ -818,3 +818,13 @@ void bt_component_remove_destroy_listener(struct bt_component *component,
                }
        }
 }
+
+void bt_component_get_ref(const struct bt_component *component)
+{
+       bt_object_get_ref(component);
+}
+
+void bt_component_put_ref(const struct bt_component *component)
+{
+       bt_object_put_ref(component);
+}
This page took 0.025954 seconds and 4 git commands to generate.