X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=lib%2Fgraph%2Fcomponent.c;h=8ffab8e0b20fe5d8fa7544f0c5ca4bfeb8c7b901;hb=3fea54f69edd1780566230255da196cb6e82df62;hp=ee8e94530063faea67dafd99772b995bf155e89a;hpb=36712f1d9ad9269638e493ca36a50979fe4da989;p=babeltrace.git diff --git a/lib/graph/component.c b/lib/graph/component.c index ee8e9453..8ffab8e0 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -40,13 +40,14 @@ #include #include #include -#include +#include #include #include #include #include #include #include +#include #include #include @@ -85,7 +86,7 @@ void bt_component_destroy(struct bt_object *obj) * bt_put(): the reference count would go from 1 to 0 again and * this function would be called again. */ - obj->ref_count.count++; + obj->ref_count++; component = container_of(obj, struct bt_component, base); BT_LOGD("Destroying component: addr=%p, name=\"%s\", graph-addr=%p", component, bt_component_get_name(component), @@ -143,10 +144,10 @@ void bt_component_destroy(struct bt_object *obj) g_free(component); } -struct bt_component *bt_component_from_private_component( +struct bt_component *bt_component_borrow_from_private( struct bt_private_component *private_component) { - return bt_get(bt_component_from_private(private_component)); + return (void *) private_component; } enum bt_component_class_type bt_component_get_class_type( @@ -185,7 +186,7 @@ struct bt_port *bt_component_add_port( struct bt_port *port = g_ptr_array_index(ports, i); port_name = bt_port_get_name(port); - assert(port_name); + BT_ASSERT(port_name); if (!strcmp(name, port_name)) { /* Port name clash, abort. */ @@ -230,17 +231,18 @@ end: BT_HIDDEN int64_t bt_component_get_input_port_count(struct bt_component *comp) { - assert(comp); + BT_ASSERT(comp); return (int64_t) comp->input_ports->len; } BT_HIDDEN int64_t bt_component_get_output_port_count(struct bt_component *comp) { - assert(comp); + BT_ASSERT(comp); return (int64_t) comp->output_ports->len; } +BT_HIDDEN enum bt_component_status bt_component_create( struct bt_component_class *component_class, const char *name, struct bt_component **user_component) @@ -249,9 +251,9 @@ enum bt_component_status bt_component_create( struct bt_component *component = NULL; enum bt_component_class_type type; - assert(user_component); - assert(component_class); - assert(name); + BT_ASSERT(user_component); + BT_ASSERT(component_class); + BT_ASSERT(name); type = bt_component_class_get_type(component_class); BT_LOGD("Creating empty component from component class: " @@ -264,7 +266,8 @@ enum bt_component_status bt_component_create( goto end; } - bt_object_init(component, bt_component_destroy); + bt_object_init_shared_with_parent(&component->base, + bt_component_destroy); component->class = bt_get(component_class); component->destroy = component_destroy_funcs[type]; component->name = g_string_new(name); @@ -275,7 +278,7 @@ enum bt_component_status bt_component_create( } component->input_ports = g_ptr_array_new_with_free_func( - bt_object_release); + (GDestroyNotify) bt_object_try_spec_release); if (!component->input_ports) { BT_LOGE_STR("Failed to allocate one GPtrArray."); status = BT_COMPONENT_STATUS_NOMEM; @@ -283,7 +286,7 @@ enum bt_component_status bt_component_create( } component->output_ports = g_ptr_array_new_with_free_func( - bt_object_release); + (GDestroyNotify) bt_object_try_spec_release); if (!component->output_ports) { BT_LOGE_STR("Failed to allocate one GPtrArray."); status = BT_COMPONENT_STATUS_NOMEM; @@ -334,7 +337,7 @@ void *bt_private_component_get_user_data( struct bt_private_component *private_component) { struct bt_component *component = - bt_component_from_private(private_component); + bt_component_borrow_from_private(private_component); return component ? component->user_data : NULL; } @@ -344,7 +347,7 @@ enum bt_component_status bt_private_component_set_user_data( void *data) { struct bt_component *component = - bt_component_from_private(private_component); + bt_component_borrow_from_private(private_component); enum bt_component_status ret = BT_COMPONENT_STATUS_OK; if (!component) { @@ -366,13 +369,13 @@ BT_HIDDEN void bt_component_set_graph(struct bt_component *component, struct bt_graph *graph) { - bt_object_set_parent(component, graph ? &graph->base : NULL); + bt_object_set_parent(&component->base, + graph ? &graph->base : NULL); } -struct bt_graph *bt_component_get_graph( - struct bt_component *component) +struct bt_graph *bt_component_borrow_graph(struct bt_component *component) { - return (struct bt_graph *) bt_object_get_parent(&component->base); + return (struct bt_graph *) bt_object_borrow_parent(&component->base); } static @@ -382,7 +385,7 @@ struct bt_port *bt_component_get_port_by_name(GPtrArray *ports, size_t i; struct bt_port *ret_port = NULL; - assert(name); + BT_ASSERT(name); for (i = 0; i < ports->len; i++) { struct bt_port *port = g_ptr_array_index(ports, i); @@ -405,7 +408,7 @@ BT_HIDDEN struct bt_port *bt_component_get_input_port_by_name(struct bt_component *comp, const char *name) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_name(comp->input_ports, name); } @@ -414,7 +417,7 @@ BT_HIDDEN struct bt_port *bt_component_get_output_port_by_name(struct bt_component *comp, const char *name) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_name(comp->output_ports, name); } @@ -440,7 +443,7 @@ BT_HIDDEN struct bt_port *bt_component_get_input_port_by_index(struct bt_component *comp, uint64_t index) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_index(comp->input_ports, index); } @@ -449,7 +452,7 @@ BT_HIDDEN struct bt_port *bt_component_get_output_port_by_index(struct bt_component *comp, uint64_t index) { - assert(comp); + BT_ASSERT(comp); return bt_component_get_port_by_index(comp->output_ports, index); } @@ -481,8 +484,8 @@ void bt_component_remove_port_by_index(struct bt_component *component, struct bt_port *port; struct bt_graph *graph; - assert(ports); - assert(index < ports->len); + BT_ASSERT(ports); + BT_ASSERT(index < ports->len); port = g_ptr_array_index(ports, index); BT_LOGD("Removing port from component: " @@ -544,7 +547,7 @@ enum bt_component_status bt_component_remove_port( ports = component->output_ports; } - assert(ports); + BT_ASSERT(ports); for (i = 0; i < ports->len; i++) { struct bt_port *cur_port = g_ptr_array_index(ports, i); @@ -574,9 +577,9 @@ enum bt_component_status bt_component_accept_port_connection( { enum bt_component_status status = BT_COMPONENT_STATUS_OK; - assert(comp); - assert(self_port); - assert(other_port); + BT_ASSERT(comp); + BT_ASSERT(self_port); + BT_ASSERT(other_port); if (comp->class->methods.accept_port_connection) { BT_LOGD("Calling user's \"accept port connection\" method: " @@ -601,9 +604,9 @@ BT_HIDDEN void bt_component_port_connected(struct bt_component *comp, struct bt_port *self_port, struct bt_port *other_port) { - assert(comp); - assert(self_port); - assert(other_port); + BT_ASSERT(comp); + BT_ASSERT(self_port); + BT_ASSERT(other_port); if (comp->class->methods.port_connected) { BT_LOGD("Calling user's \"port connected\" method: " @@ -623,8 +626,8 @@ BT_HIDDEN void bt_component_port_disconnected(struct bt_component *comp, struct bt_port *port) { - assert(comp); - assert(port); + BT_ASSERT(comp); + BT_ASSERT(port); if (comp->class->methods.port_disconnected) { BT_LOGD("Calling user's \"port disconnected\" method: " @@ -644,8 +647,8 @@ void bt_component_add_destroy_listener(struct bt_component *component, { struct bt_component_destroy_listener listener; - assert(component); - assert(func); + BT_ASSERT(component); + BT_ASSERT(func); listener.func = func; listener.data = data; g_array_append_val(component->destroy_listeners, listener); @@ -662,8 +665,8 @@ void bt_component_remove_destroy_listener(struct bt_component *component, { size_t i; - assert(component); - assert(func); + BT_ASSERT(component); + BT_ASSERT(func); for (i = 0; i < component->destroy_listeners->len; i++) { struct bt_component_destroy_listener *listener =