From: Philippe Proulx Date: Wed, 21 Nov 2018 22:30:33 +0000 (-0500) Subject: lib: graph: add "self" and some "private" APIs X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d94d92ac6656fd252a5d7bb4f6c76935ba18e62e lib: graph: add "self" and some "private" APIs The main purpose of this patch is to create different "views" of the same graph objects. The terms are as such: Public API: You can only read properties of the object. Example: bt_graph_is_canceled(). Private API: You can create the object and set properties. Example: bt_private_graph_create(). Self API: You conceptually inherit this object. Example: bt_self_component_set_data(). This means that component user method now accepts a "self component", on which: * You can set and get user data (bt_self_component_set_data() and bt_self_component_get_data()). * You can add ports (for example, bt_self_component_source_add_output_port()). * You can borrow "self component ports", on which you can get user data (bt_self_component_port_get_data()) that you set previously with a port adding function. A notification iterator method now accepts a "self notification iterator", on which: * You can set and get user data (bt_self_notification_iterator_set_data() and bt_self_notification_iterator_get_data()). * You can borrow your "self component" (bt_self_notification_iterator_borrow_component()) or "self component output port" (bt_self_notification_iterator_borrow_port()). Also, you now use the private component class API to create component classes and set optional methods, a description, and the rest. Also in this patch: * Component class and component APIs are split into source, filter, and sink parts. This makes everything more type safe considering that: * We don't need any polymorphism like we do, for example, for field classes, for component classes and components: you always know, contextually, with which type you're dealing. * We don't need to have collections of components or component classes of different types: we can just use three collections each time. This means that the private graph API, for example, now has the three distinct bt_private_graph_add_source_component(), bt_private_graph_add_filter_component(), and bt_private_graph_add_sink_component(), each of them accepting the appropriate component class type and returning the corresponding component type. No function exists to borrow a source component's input port or a sink component's output port. * The port API is split into input and output parts, with the new `struct bt_port_in` and `struct bt_port_out` types. An interesting consequence is that, as a component class developer, there are different methods for input and output ports, so that a fitler component class, for example, can have both an "input port connected" and an "output port connected". The `flt.utils.muxer` component class is an example which takes advantage of this, not having to check the port's type in its "input port connected" method now. * Functions to go from one type to another (private to public, self to public, input port to port, and so on) are now `static inline` to avoid any performance hit. Those functions are now universally named bt_X_borrow_Y(), where `X` is the API's prefix (for example, `private_component_class`) and `Y` is the transformed type name (for example, `component_class`). * The query executor API is split into private (create, query, cancel) and public (is canceled?) parts. A user's query method accepts a "self component class" of the appropriate type. * "Private connection private notification iterator" is removed in favor of "self component input port notification iterator": you need to call bt_self_component_port_input_notification_iterator_create() with a self component input port (which you can only borrow from your own self component). Because of this, `enum bt_connection_status` is removed because it's not needed anymore. * `enum bt_component_status` is removed because it's not needed anymore. Most statuses are moved to `enum bt_self_component_status` (what a component class method returns). * `bt_output_port_notification_iterator` is renamed to `bt_port_output_notification_iterator` to be consistent with `bt_self_component_port_input_notification_iterator`. * Graph and plugin API status values are standardized. * Precondition assertion macros are used to validate preconditions in developer mode across the whole graph and plugin APIs. Consequences: * bt_plugin_get_version() returns `enum bt_property_availability` instead of `enum bt_plugin_status`. * Functions which return a count return `uint64_t` instead of `int64_t`. * Status ending with `_INVALID` are removed (not needed anymore). * Types ending with `_UNKNOWN` are removed (not needed anymore). * All "getting" functions in the graph/plugin APIs are removed in favor of "borrowing" functions. Interesting changes needed to be made to bt_connection_end() and remove_port_by_index() to support this. * bt_plugin_find_component_class() is removed. Let's not encourage this because it creates a plugin object each time, whereas the recommended approach is to create a plugin first (with bt_plugin_find() for example), and then borrow the required component classes. * Graph API: when an object's member is destroyed, internally, its pointer is set to `NULL` immediately. This makes it possible to log partial objects during destruction while keeping Valgrind's memcheck happy. * Generic logging is replaced by library logging in the graph and plugin API implementations. Signed-off-by: Philippe Proulx --- diff --git a/cli/babeltrace-cfg-cli-args-connect.c b/cli/babeltrace-cfg-cli-args-connect.c index a1c72ab2..8e941e21 100644 --- a/cli/babeltrace-cfg-cli-args-connect.c +++ b/cli/babeltrace-cfg-cli-args-connect.c @@ -562,7 +562,7 @@ static int validate_all_components_connected(struct bt_config *cfg, ret = validate_all_components_connected_in_array( cfg->cmd_data.run.sources, - bt_value_borrow_from_private(connected_components), + bt_private_value_borrow_value(connected_components), error_buf, error_buf_size); if (ret) { goto end; @@ -570,7 +570,7 @@ static int validate_all_components_connected(struct bt_config *cfg, ret = validate_all_components_connected_in_array( cfg->cmd_data.run.filters, - bt_value_borrow_from_private(connected_components), + bt_private_value_borrow_value(connected_components), error_buf, error_buf_size); if (ret) { goto end; @@ -578,7 +578,7 @@ static int validate_all_components_connected(struct bt_config *cfg, ret = validate_all_components_connected_in_array( cfg->cmd_data.run.sinks, - bt_value_borrow_from_private(connected_components), + bt_private_value_borrow_value(connected_components), error_buf, error_buf_size); if (ret) { goto end; @@ -619,7 +619,7 @@ static int validate_no_duplicate_connection(struct bt_config *cfg, connection->downstream_comp_name->str, connection->downstream_port_glob->str); - if (bt_value_map_has_entry(bt_value_borrow_from_private( + if (bt_value_map_has_entry(bt_private_value_borrow_value( flat_connection_names), flat_connection_name->str)) { snprintf(error_buf, error_buf_size, diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index b50e0a15..76eb9c00 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -243,7 +243,7 @@ int ini_handle_state(struct ini_parsing_state *state) } if (bt_value_map_has_entry( - bt_value_borrow_from_private(state->params), + bt_private_value_borrow_value(state->params), state->last_map_key)) { g_string_append_printf(state->ini_error, "Duplicate parameter key: `%s`\n", @@ -295,20 +295,20 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_integer_create_init( (int64_t) int_val)); break; } case G_TOKEN_FLOAT: /* Positive floating point number */ - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_real_create_init( state->scanner->value.v_float)); break; case G_TOKEN_STRING: /* Quoted string */ - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_string_create_init( state->scanner->value.v_string)); break; @@ -332,16 +332,16 @@ int ini_handle_state(struct ini_parsing_state *state) } else if (!strcmp(id, "true") || !strcmp(id, "TRUE") || !strcmp(id, "yes") || !strcmp(id, "YES")) { - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_bool_create_init(true)); } else if (!strcmp(id, "false") || !strcmp(id, "FALSE") || !strcmp(id, "no") || !strcmp(id, "NO")) { - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_bool_create_init(false)); } else { - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_string_create_init(id)); } break; @@ -375,14 +375,14 @@ int ini_handle_state(struct ini_parsing_state *state) goto error; } - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_integer_create_init( -((int64_t) int_val))); break; } case G_TOKEN_FLOAT: /* Negative floating point number */ - value = bt_value_borrow_from_private( + value = bt_private_value_borrow_value( bt_private_value_real_create_init( -state->scanner->value.v_float)); break; @@ -1404,7 +1404,7 @@ int add_run_cfg_comp_check_name(struct bt_config *cfg, goto end; } - if (bt_value_map_has_entry(bt_value_borrow_from_private(instance_names), + if (bt_value_map_has_entry(bt_private_value_borrow_value(instance_names), cfg_comp->instance_name->str)) { printf_err("Duplicate component instance name:\n %s\n", cfg_comp->instance_name->str); @@ -1620,8 +1620,7 @@ struct bt_config *bt_config_help_create( } cfg->cmd_data.help.cfg_component = - bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN, - NULL, NULL); + bt_config_component_create(-1, NULL, NULL); if (!cfg->cmd_data.help.cfg_component) { goto error; } @@ -1921,8 +1920,6 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[], comp_cls_name); } else { /* Fall back to plugin help */ - cfg->cmd_data.help.cfg_component->type = - BT_COMPONENT_CLASS_TYPE_UNKNOWN; g_string_assign( cfg->cmd_data.help.cfg_component->plugin_name, leftover); @@ -2520,7 +2517,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], bt_object_put_ref(cur_cfg_comp->params); status = bt_value_copy( &cur_cfg_comp->params, - bt_value_borrow_from_private(cur_base_params)); + bt_private_value_borrow_value(cur_base_params)); if (status != BT_VALUE_STATUS_OK) { print_err_oom(); goto error; @@ -2548,8 +2545,8 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], } status = bt_value_map_extend(¶ms_to_set, - bt_value_borrow_from_private(cur_cfg_comp->params), - bt_value_borrow_from_private(params)); + bt_private_value_borrow_value(cur_cfg_comp->params), + bt_private_value_borrow_value(params)); BT_OBJECT_PUT_REF_AND_RESET(params); if (status != BT_VALUE_STATUS_OK) { printf_err("Cannot extend current component parameters with --params option's argument:\n %s\n", @@ -2688,7 +2685,7 @@ struct bt_config *bt_config_run_from_args(int argc, const char *argv[], } ret = bt_config_cli_args_create_connections(cfg, - bt_value_borrow_from_private(connection_args), + bt_private_value_borrow_value(connection_args), error_buf, 256); if (ret) { printf_err("Cannot creation connections:\n%s", error_buf); @@ -2987,7 +2984,7 @@ int assign_name_to_implicit_component(struct implicit_component_args *args, } name = get_component_auto_name(prefix, - bt_value_borrow_from_private(existing_names)); + bt_private_value_borrow_value(existing_names)); if (!name) { ret = -1; @@ -3062,13 +3059,13 @@ int append_run_args_for_implicit_component( } for (i = 0; i < bt_value_array_get_size( - bt_value_borrow_from_private(impl_args->extra_params)); + bt_private_value_borrow_value(impl_args->extra_params)); i++) { struct bt_value *elem; const char *arg; elem = bt_value_array_borrow_element_by_index( - bt_value_borrow_from_private(impl_args->extra_params), + bt_private_value_borrow_value(impl_args->extra_params), i); if (!elem) { goto error; @@ -3216,7 +3213,7 @@ int convert_append_name_param(enum bt_config_component_dest dest, * component. */ name = get_component_auto_name(cur_name_prefix->str, - bt_value_borrow_from_private(all_names)); + bt_private_value_borrow_value(all_names)); append_name_opt = true; } else { /* @@ -3224,7 +3221,7 @@ int convert_append_name_param(enum bt_config_component_dest dest, * component. */ if (bt_value_map_has_entry( - bt_value_borrow_from_private(all_names), + bt_private_value_borrow_value(all_names), cur_name->str)) { printf_err("Duplicate component instance name:\n %s\n", cur_name->str); @@ -3561,7 +3558,7 @@ int fill_implicit_ctf_inputs_args(GPtrArray *implicit_ctf_inputs_args, */ BT_OBJECT_PUT_REF_AND_RESET(impl_args->extra_params); status = bt_value_copy(&impl_args->extra_params, - bt_value_borrow_from_private( + bt_private_value_borrow_value( base_implicit_ctf_input_args->extra_params)); if (status != BT_VALUE_STATUS_OK) { print_err_oom(); @@ -4181,7 +4178,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], implicit_text_args.exists = true; ret = insert_flat_params_from_array( implicit_text_args.params_arg, - bt_value_borrow_from_private(fields), "field"); + bt_private_value_borrow_value(fields), "field"); bt_object_put_ref(fields); if (ret) { goto error; @@ -4199,7 +4196,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], implicit_text_args.exists = true; ret = insert_flat_params_from_array( implicit_text_args.params_arg, - bt_value_borrow_from_private(names), "name"); + bt_private_value_borrow_value(names), "name"); bt_object_put_ref(names); if (ret) { goto error; @@ -4690,10 +4687,10 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], } for (i = 0; i < bt_value_array_get_size( - bt_value_borrow_from_private(run_args)); i++) { + bt_private_value_borrow_value(run_args)); i++) { struct bt_value *arg_value = bt_value_array_borrow_element_by_index( - bt_value_borrow_from_private(run_args), + bt_private_value_borrow_value(run_args), i); const char *arg; GString *quoted = NULL; @@ -4720,7 +4717,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], } if (i < bt_value_array_get_size( - bt_value_borrow_from_private(run_args)) - 1) { + bt_private_value_borrow_value(run_args)) - 1) { if (print_run_args) { putchar(' '); } else { @@ -4735,7 +4732,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[], } cfg = bt_config_run_from_args_array( - bt_value_borrow_from_private(run_args), retcode, + bt_private_value_borrow_value(run_args), retcode, force_omit_system_plugin_path, force_omit_home_plugin_path, initial_plugin_paths); if (!cfg) { diff --git a/cli/babeltrace.c b/cli/babeltrace.c index b9a1b335..c6daa07a 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -70,7 +70,7 @@ static const char* log_level_env_var_names[] = { /* Application's processing graph (weak) */ static struct bt_private_graph *the_graph; -static struct bt_query_executor *the_query_executor; +static struct bt_private_query_executor *the_query_executor; static bool canceled = false; GPtrArray *loaded_plugins; @@ -112,7 +112,7 @@ void signal_handler(int signum) } if (the_query_executor) { - bt_query_executor_cancel(the_query_executor); + bt_private_query_executor_cancel(the_query_executor); } canceled = true; @@ -152,7 +152,7 @@ int create_the_query_executor(void) { int ret = 0; - the_query_executor = bt_query_executor_create(); + the_query_executor = bt_private_query_executor_create(); if (!the_query_executor) { BT_LOGE_STR("Cannot create a query executor."); ret = -1; @@ -195,8 +195,8 @@ int query(struct bt_component_class *comp_cls, const char *obj, } while (true) { - status = bt_query_executor_query(the_query_executor, comp_cls, - obj, params, &result); + status = bt_private_query_executor_query(the_query_executor, + comp_cls, obj, params, &result); switch (status) { case BT_QUERY_STATUS_OK: goto ok; @@ -209,7 +209,8 @@ int query(struct bt_component_class *comp_cls, const char *obj, "time-us=%" PRIu64, sleep_time_us); if (usleep(sleep_time_us)) { - if (bt_query_executor_is_canceled(the_query_executor)) { + if (bt_query_executor_is_canceled( + bt_private_query_executor_borrow_query_executor(the_query_executor))) { BT_LOGI("Query was canceled by user: " "comp-cls-addr=%p, comp-cls-name=\"%s\", " "query-obj=\"%s\"", comp_cls, @@ -226,7 +227,6 @@ int query(struct bt_component_class *comp_cls, const char *obj, *fail_reason = "canceled by user"; goto error; case BT_QUERY_STATUS_ERROR: - case BT_QUERY_STATUS_INVALID: goto error; case BT_QUERY_STATUS_INVALID_OBJECT: *fail_reason = "invalid or unknown query object"; @@ -287,26 +287,27 @@ struct bt_plugin *find_plugin(const char *name) return bt_object_get_ref(plugin); } +typedef void *(*plugin_borrow_comp_cls_func_t)(struct bt_plugin *, + const char *); + static -struct bt_component_class *find_component_class(const char *plugin_name, +void *find_component_class_from_plugin(const char *plugin_name, const char *comp_class_name, - enum bt_component_class_type comp_class_type) + plugin_borrow_comp_cls_func_t plugin_borrow_comp_cls_func) { - struct bt_component_class *comp_class = NULL; + void *comp_class = NULL; struct bt_plugin *plugin; BT_LOGD("Finding component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", - plugin_name, comp_class_name, comp_class_type); + "comp-cls-name=\"%s\"", plugin_name, comp_class_name); plugin = find_plugin(plugin_name); - if (!plugin) { goto end; } - comp_class = bt_plugin_get_component_class_by_name_and_type(plugin, - comp_class_name, comp_class_type); + comp_class = bt_object_get_ref( + plugin_borrow_comp_cls_func(plugin, comp_class_name)); BT_OBJECT_PUT_REF_AND_RESET(plugin); end: @@ -315,13 +316,73 @@ end: BT_LOGD("Found component class: comp-cls-addr=%p", comp_class); } else { - BT_LOGD("Cannot find component class."); + BT_LOGD("Cannot find source component class."); } } return comp_class; } +static +struct bt_component_class_source *find_source_component_class( + const char *plugin_name, const char *comp_class_name) +{ + return (void *) find_component_class_from_plugin(plugin_name, + comp_class_name, + (plugin_borrow_comp_cls_func_t) + bt_plugin_borrow_source_component_class_by_name); +} + +static +struct bt_component_class_filter *find_filter_component_class( + const char *plugin_name, const char *comp_class_name) +{ + return (void *) find_component_class_from_plugin(plugin_name, + comp_class_name, + (plugin_borrow_comp_cls_func_t) + bt_plugin_borrow_filter_component_class_by_name); +} + +static +struct bt_component_class_sink *find_sink_component_class( + const char *plugin_name, const char *comp_class_name) +{ + return (void *) find_component_class_from_plugin(plugin_name, + comp_class_name, + (plugin_borrow_comp_cls_func_t) + bt_plugin_borrow_sink_component_class_by_name); +} + +static +struct bt_component_class *find_component_class(const char *plugin_name, + const char *comp_class_name, + enum bt_component_class_type comp_class_type) +{ + struct bt_component_class *comp_cls = NULL; + + switch (comp_class_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + comp_cls = bt_component_class_source_borrow_component_class( + find_source_component_class(plugin_name, + comp_class_name)); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + comp_cls = bt_component_class_filter_borrow_component_class( + find_filter_component_class(plugin_name, + comp_class_name)); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + comp_cls = bt_component_class_sink_borrow_component_class( + find_sink_component_class(plugin_name, + comp_class_name)); + break; + default: + abort(); + } + + return comp_cls; +} + static void print_indent(FILE *fp, size_t indent) { @@ -342,7 +403,6 @@ const char *component_type_str(enum bt_component_class_type type) return "sink"; case BT_COMPONENT_CLASS_TYPE_FILTER: return "filter"; - case BT_COMPONENT_CLASS_TYPE_UNKNOWN: default: return "(unknown)"; } @@ -567,7 +627,7 @@ void print_bt_config_component(struct bt_config_component *bt_config_component) fprintf(stderr, " Parameters:\n"); print_value(stderr, - bt_value_borrow_from_private(bt_config_component->params), 8); + bt_private_value_borrow_value(bt_config_component->params), 8); } static @@ -595,7 +655,7 @@ void print_cfg_run(struct bt_config *cfg) { size_t i; - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); fprintf(stderr, " Source component instances:\n"); print_bt_config_components(cfg->cmd_data.run.sources); @@ -626,19 +686,19 @@ void print_cfg_run(struct bt_config *cfg) static void print_cfg_list_plugins(struct bt_config *cfg) { - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); } static void print_cfg_help(struct bt_config *cfg) { - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); } static void print_cfg_print_ctf_metadata(struct bt_config *cfg) { - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); fprintf(stderr, " Path: %s\n", cfg->cmd_data.print_ctf_metadata.path->str); } @@ -646,7 +706,7 @@ void print_cfg_print_ctf_metadata(struct bt_config *cfg) static void print_cfg_print_lttng_live_sessions(struct bt_config *cfg) { - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); fprintf(stderr, " URL: %s\n", cfg->cmd_data.print_lttng_live_sessions.url->str); } @@ -654,7 +714,7 @@ void print_cfg_print_lttng_live_sessions(struct bt_config *cfg) static void print_cfg_query(struct bt_config *cfg) { - print_plugin_paths(bt_value_borrow_from_private(cfg->plugin_paths)); + print_plugin_paths(bt_private_value_borrow_value(cfg->plugin_paths)); fprintf(stderr, " Object: `%s`\n", cfg->cmd_data.query.object->str); fprintf(stderr, " Component class:\n"); print_bt_config_component(cfg->cmd_data.query.cfg_component); @@ -706,9 +766,9 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) for (i = 0; i < count; i++) { struct bt_plugin *plugin = - bt_plugin_set_get_plugin(plugin_set, i); + bt_plugin_set_borrow_plugin_by_index(plugin_set, i); struct bt_plugin *loaded_plugin = - find_plugin(bt_plugin_get_name(plugin)); + find_plugin(bt_plugin_get_name(plugin)); BT_ASSERT(plugin); @@ -726,8 +786,6 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) bt_plugin_get_name(plugin)); g_ptr_array_add(loaded_plugins, bt_object_get_ref(plugin)); } - - bt_object_put_ref(plugin); } } @@ -879,7 +937,8 @@ int cmd_query(struct bt_config *cfg) struct bt_value *results = NULL; const char *fail_reason = NULL; - comp_cls = find_component_class(cfg->cmd_data.query.cfg_component->plugin_name->str, + comp_cls = find_component_class( + cfg->cmd_data.query.cfg_component->plugin_name->str, cfg->cmd_data.query.cfg_component->comp_cls_name->str, cfg->cmd_data.query.cfg_component->type); if (!comp_cls) { @@ -902,7 +961,8 @@ int cmd_query(struct bt_config *cfg) } ret = query(comp_cls, cfg->cmd_data.query.object->str, - bt_value_borrow_from_private(cfg->cmd_data.query.cfg_component->params), + bt_private_value_borrow_value( + cfg->cmd_data.query.cfg_component->params), &results, &fail_reason); if (ret) { goto failed; @@ -941,12 +1001,36 @@ end: return ret; } +static +void print_component_class_help(const char *plugin_name, + struct bt_component_class *comp_cls) +{ + const char *comp_class_name = + bt_component_class_get_name(comp_cls); + const char *comp_class_description = + bt_component_class_get_description(comp_cls); + const char *comp_class_help = + bt_component_class_get_help(comp_cls); + enum bt_component_class_type type = + bt_component_class_get_type(comp_cls); + + print_plugin_comp_cls_opt(stdout, plugin_name, comp_class_name, type); + printf("\n"); + printf(" %sDescription%s: %s\n", bt_common_color_bold(), + bt_common_color_reset(), + comp_class_description ? comp_class_description : "(None)"); + + if (comp_class_help) { + printf("\n%s\n", comp_class_help); + } +} + static int cmd_help(struct bt_config *cfg) { int ret = 0; struct bt_plugin *plugin = NULL; - size_t i; + struct bt_component_class *needed_comp_cls = NULL; plugin = find_plugin(cfg->cmd_data.help.cfg_component->plugin_name->str); if (!plugin) { @@ -962,86 +1046,106 @@ int cmd_help(struct bt_config *cfg) } print_plugin_info(plugin); - printf(" %sComponent classes%s: %d\n", + printf(" %sSource component classes%s: %d\n", + bt_common_color_bold(), + bt_common_color_reset(), + (int) bt_plugin_get_source_component_class_count(plugin)); + printf(" %sFilter component classes%s: %d\n", bt_common_color_bold(), bt_common_color_reset(), - (int) bt_plugin_get_component_class_count(plugin)); + (int) bt_plugin_get_filter_component_class_count(plugin)); + printf(" %sSink component classes%s: %d\n", + bt_common_color_bold(), + bt_common_color_reset(), + (int) bt_plugin_get_sink_component_class_count(plugin)); + if (strlen(cfg->cmd_data.help.cfg_component->comp_cls_name->str) == 0) { + /* Plugin help only */ + goto end; + } - if (cfg->cmd_data.help.cfg_component->type != - BT_COMPONENT_CLASS_TYPE_UNKNOWN) { - struct bt_component_class *needed_comp_cls = - find_component_class( - cfg->cmd_data.help.cfg_component->plugin_name->str, - cfg->cmd_data.help.cfg_component->comp_cls_name->str, - cfg->cmd_data.help.cfg_component->type); + needed_comp_cls = find_component_class( + cfg->cmd_data.help.cfg_component->plugin_name->str, + cfg->cmd_data.help.cfg_component->comp_cls_name->str, + cfg->cmd_data.help.cfg_component->type); + if (!needed_comp_cls) { + BT_LOGE("Cannot find component class: plugin-name=\"%s\", " + "comp-cls-name=\"%s\", comp-cls-type=%d", + cfg->cmd_data.help.cfg_component->plugin_name->str, + cfg->cmd_data.help.cfg_component->comp_cls_name->str, + cfg->cmd_data.help.cfg_component->type); + fprintf(stderr, "\n%s%sCannot find component class %s", + bt_common_color_bold(), + bt_common_color_fg_red(), + bt_common_color_reset()); + print_plugin_comp_cls_opt(stderr, + cfg->cmd_data.help.cfg_component->plugin_name->str, + cfg->cmd_data.help.cfg_component->comp_cls_name->str, + cfg->cmd_data.help.cfg_component->type); + fprintf(stderr, "\n"); + ret = -1; + goto end; + } - if (!needed_comp_cls) { - BT_LOGE("Cannot find component class: plugin-name=\"%s\", " - "comp-cls-name=\"%s\", comp-cls-type=%d", - cfg->cmd_data.help.cfg_component->plugin_name->str, - cfg->cmd_data.help.cfg_component->comp_cls_name->str, - cfg->cmd_data.help.cfg_component->type); - fprintf(stderr, "\n%s%sCannot find component class %s", - bt_common_color_bold(), - bt_common_color_fg_red(), - bt_common_color_reset()); - print_plugin_comp_cls_opt(stderr, - cfg->cmd_data.help.cfg_component->plugin_name->str, - cfg->cmd_data.help.cfg_component->comp_cls_name->str, - cfg->cmd_data.help.cfg_component->type); - fprintf(stderr, "\n"); - ret = -1; - goto end; - } + printf("\n"); + print_component_class_help( + cfg->cmd_data.help.cfg_component->plugin_name->str, + needed_comp_cls); + +end: + bt_object_put_ref(needed_comp_cls); + bt_object_put_ref(plugin); + return ret; +} + +typedef void *(* plugin_borrow_comp_cls_by_index_func_t)(struct bt_plugin *, + uint64_t); +typedef struct bt_component_class *(* spec_comp_cls_borrow_comp_cls_func_t)( + void *); + +void cmd_list_plugins_print_component_classes(struct bt_plugin *plugin, + const char *cc_type_name, uint64_t count, + plugin_borrow_comp_cls_by_index_func_t borrow_comp_cls_by_index_func, + spec_comp_cls_borrow_comp_cls_func_t spec_comp_cls_borrow_comp_cls_func) +{ + uint64_t i; - bt_object_put_ref(needed_comp_cls); + if (count == 0) { + printf(" %s%s component classes%s: (none)\n", cc_type_name, + bt_common_color_bold(), + bt_common_color_reset()); + goto end; + } else { + printf(" %s%s component classes%s:\n", cc_type_name, + bt_common_color_bold(), + bt_common_color_reset()); } - for (i = 0; i < bt_plugin_get_component_class_count(plugin); i++) { - struct bt_component_class *comp_cls = - bt_plugin_get_component_class_by_index(plugin, i); + for (i = 0; i < count; i++) { + struct bt_component_class *comp_class = + spec_comp_cls_borrow_comp_cls_func( + borrow_comp_cls_by_index_func(plugin, i)); const char *comp_class_name = - bt_component_class_get_name(comp_cls); + bt_component_class_get_name(comp_class); const char *comp_class_description = - bt_component_class_get_description(comp_cls); - const char *comp_class_help = - bt_component_class_get_help(comp_cls); + bt_component_class_get_description(comp_class); enum bt_component_class_type type = - bt_component_class_get_type(comp_cls); - - BT_ASSERT(comp_cls); + bt_component_class_get_type(comp_class); - if (cfg->cmd_data.help.cfg_component->type != - BT_COMPONENT_CLASS_TYPE_UNKNOWN) { - if (strcmp(cfg->cmd_data.help.cfg_component->comp_cls_name->str, - comp_class_name) != 0 || - type != cfg->cmd_data.help.cfg_component->type) { - bt_object_put_ref(comp_cls); - continue; - } - } - - printf("\n"); + printf(" "); print_plugin_comp_cls_opt(stdout, - cfg->cmd_data.help.cfg_component->plugin_name->str, - comp_class_name, + bt_plugin_get_name(plugin), comp_class_name, type); - printf("\n"); - printf(" %sDescription%s: %s\n", bt_common_color_bold(), - bt_common_color_reset(), - comp_class_description ? comp_class_description : "(None)"); - if (comp_class_help) { - printf("\n%s\n", comp_class_help); + if (comp_class_description) { + printf(": %s", comp_class_description); } - bt_object_put_ref(comp_cls); + printf("\n"); } end: - bt_object_put_ref(plugin); - return ret; + return; } static @@ -1051,7 +1155,7 @@ int cmd_list_plugins(struct bt_config *cfg) int plugins_count, component_classes_count = 0, i; printf("From the following plugin paths:\n\n"); - print_value(stdout, bt_value_borrow_from_private(cfg->plugin_paths), 2); + print_value(stdout, bt_private_value_borrow_value(cfg->plugin_paths), 2); printf("\n"); plugins_count = loaded_plugins->len; if (plugins_count == 0) { @@ -1062,7 +1166,10 @@ int cmd_list_plugins(struct bt_config *cfg) for (i = 0; i < plugins_count; i++) { struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); - component_classes_count += bt_plugin_get_component_class_count(plugin); + component_classes_count += + bt_plugin_get_source_component_class_count(plugin) + + bt_plugin_get_filter_component_class_count(plugin) + + bt_plugin_get_sink_component_class_count(plugin); } printf("Found %s%d%s component classes in %s%d%s plugins.\n", @@ -1074,47 +1181,28 @@ int cmd_list_plugins(struct bt_config *cfg) bt_common_color_reset()); for (i = 0; i < plugins_count; i++) { - int j; struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); - component_classes_count = - bt_plugin_get_component_class_count(plugin); printf("\n"); print_plugin_info(plugin); - - if (component_classes_count == 0) { - printf(" %sComponent classes%s: (none)\n", - bt_common_color_bold(), - bt_common_color_reset()); - } else { - printf(" %sComponent classes%s:\n", - bt_common_color_bold(), - bt_common_color_reset()); - } - - for (j = 0; j < component_classes_count; j++) { - struct bt_component_class *comp_class = - bt_plugin_get_component_class_by_index( - plugin, j); - const char *comp_class_name = - bt_component_class_get_name(comp_class); - const char *comp_class_description = - bt_component_class_get_description(comp_class); - enum bt_component_class_type type = - bt_component_class_get_type(comp_class); - - printf(" "); - print_plugin_comp_cls_opt(stdout, - bt_plugin_get_name(plugin), comp_class_name, - type); - - if (comp_class_description) { - printf(": %s", comp_class_description); - } - - printf("\n"); - bt_object_put_ref(comp_class); - } + cmd_list_plugins_print_component_classes(plugin, "Source", + bt_plugin_get_source_component_class_count(plugin), + (plugin_borrow_comp_cls_by_index_func_t) + bt_plugin_borrow_source_component_class_by_name, + (spec_comp_cls_borrow_comp_cls_func_t) + bt_component_class_source_borrow_component_class); + cmd_list_plugins_print_component_classes(plugin, "Filter", + bt_plugin_get_filter_component_class_count(plugin), + (plugin_borrow_comp_cls_by_index_func_t) + bt_plugin_borrow_filter_component_class_by_name, + (spec_comp_cls_borrow_comp_cls_func_t) + bt_component_class_filter_borrow_component_class); + cmd_list_plugins_print_component_classes(plugin, "Sink", + bt_plugin_get_sink_component_class_count(plugin), + (plugin_borrow_comp_cls_by_index_func_t) + bt_plugin_borrow_sink_component_class_by_name, + (spec_comp_cls_borrow_comp_cls_func_t) + bt_component_class_sink_borrow_component_class); } end: @@ -1167,7 +1255,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg) goto error; } - ret = query(comp_cls, "sessions", bt_value_borrow_from_private(params), + ret = query(comp_cls, "sessions", bt_private_value_borrow_value(params), &results, &fail_reason); if (ret) { goto failed; @@ -1322,7 +1410,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg) } ret = query(comp_cls, "metadata-info", - bt_value_borrow_from_private(params), &results, &fail_reason); + bt_private_value_borrow_value(params), &results, &fail_reason); if (ret) { goto failed; } @@ -1367,7 +1455,6 @@ failed: bt_common_color_reset()); end: - destroy_the_query_executor(); bt_object_put_ref(results); bt_object_put_ref(params); bt_object_put_ref(comp_cls); @@ -1434,7 +1521,13 @@ void trace_range_destroy(gpointer data) struct cmd_run_ctx { /* Owned by this */ - GHashTable *components; + GHashTable *src_components; + + /* Owned by this */ + GHashTable *flt_components; + + /* Owned by this */ + GHashTable *sink_components; /* Owned by this */ struct bt_private_graph *graph; @@ -1499,26 +1592,33 @@ char *s_from_ns(int64_t ns) static int cmd_run_ctx_connect_upstream_port_to_downstream_component( - struct cmd_run_ctx *ctx, struct bt_component *upstream_comp, - struct bt_port *upstream_port, + struct cmd_run_ctx *ctx, + struct bt_component *upstream_comp, + struct bt_port_output *out_upstream_port, struct bt_config_connection *cfg_conn) { + typedef uint64_t (*input_port_count_func_t)(void *); + typedef struct bt_port_input *(*borrow_input_port_by_index_func_t)( + void *, uint64_t); + struct bt_port *upstream_port = + bt_port_output_borrow_port(out_upstream_port); + int ret = 0; GQuark downstreamp_comp_name_quark; - struct bt_component *downstream_comp; - int64_t downstream_port_count; + void *downstream_comp; + uint64_t downstream_port_count; uint64_t i; - int64_t (*port_count_fn)(struct bt_component *); - struct bt_port *(*port_by_index_fn)(struct bt_component *, uint64_t); + input_port_count_func_t port_count_fn; + borrow_input_port_by_index_func_t port_by_index_fn; enum bt_graph_status status = BT_GRAPH_STATUS_ERROR; bool insert_trimmer = false; struct bt_private_value *trimmer_params = NULL; char *intersection_begin = NULL; char *intersection_end = NULL; - struct bt_component *trimmer = NULL; - struct bt_component_class *trimmer_class = NULL; - struct bt_port *trimmer_input = NULL; - struct bt_port *trimmer_output = NULL; + struct bt_component_filter *trimmer = NULL; + struct bt_component_class_filter *trimmer_class = NULL; + struct bt_port_input *trimmer_input = NULL; + struct bt_port_output *trimmer_output = NULL; if (ctx->intersections && bt_component_get_class_type(upstream_comp) == @@ -1566,8 +1666,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( } } - trimmer_class = find_component_class("utils", "trimmer", - BT_COMPONENT_CLASS_TYPE_FILTER); + trimmer_class = find_filter_component_class("utils", "trimmer"); if (!trimmer_class) { goto error; } @@ -1582,8 +1681,22 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( downstreamp_comp_name_quark = g_quark_from_string( cfg_conn->downstream_comp_name->str); BT_ASSERT(downstreamp_comp_name_quark > 0); - downstream_comp = g_hash_table_lookup(ctx->components, + downstream_comp = g_hash_table_lookup(ctx->flt_components, GUINT_TO_POINTER(downstreamp_comp_name_quark)); + port_count_fn = (input_port_count_func_t) + bt_component_filter_get_input_port_count; + port_by_index_fn = (borrow_input_port_by_index_func_t) + bt_component_filter_borrow_input_port_by_index; + + if (!downstream_comp) { + downstream_comp = g_hash_table_lookup(ctx->sink_components, + GUINT_TO_POINTER(downstreamp_comp_name_quark)); + port_count_fn = (input_port_count_func_t) + bt_component_sink_get_input_port_count; + port_by_index_fn = (borrow_input_port_by_index_func_t) + bt_component_sink_borrow_input_port_by_index; + } + if (!downstream_comp) { BT_LOGE("Cannot find downstream component: comp-name=\"%s\", " "conn-arg=\"%s\"", cfg_conn->downstream_comp_name->str, @@ -1593,28 +1706,14 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( goto error; } - if (bt_component_is_filter(downstream_comp)) { - port_count_fn = bt_component_filter_get_input_port_count; - port_by_index_fn = bt_component_filter_get_input_port_by_index; - } else if (bt_component_is_sink(downstream_comp)) { - port_count_fn = bt_component_sink_get_input_port_count; - port_by_index_fn = bt_component_sink_get_input_port_by_index; - } else { - /* - * Should never happen because the connections are - * validated before we get here. - */ - BT_LOGF("Invalid connection: downstream component is a source: " - "conn-arg=\"%s\"", cfg_conn->arg->str); - abort(); - } - downstream_port_count = port_count_fn(downstream_comp); BT_ASSERT(downstream_port_count >= 0); for (i = 0; i < downstream_port_count; i++) { - struct bt_port *downstream_port = + struct bt_port_input *in_downstream_port = port_by_index_fn(downstream_comp, i); + struct bt_port *downstream_port = + bt_port_input_borrow_port(in_downstream_port); const char *upstream_port_name; const char *downstream_port_name; @@ -1622,7 +1721,6 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( /* Skip port if it's already connected. */ if (bt_port_is_connected(downstream_port)) { - bt_object_put_ref(downstream_port); BT_LOGD("Skipping downstream port: already connected: " "port-addr=%p, port-name=\"%s\"", downstream_port, @@ -1638,29 +1736,30 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( if (!bt_common_star_glob_match( cfg_conn->downstream_port_glob->str, SIZE_MAX, downstream_port_name, SIZE_MAX)) { - bt_object_put_ref(downstream_port); continue; } if (insert_trimmer) { /* - * In order to insert the trimmer between the two - * components that were being connected, we create - * a connection configuration entry which describes - * a connection from the trimmer's output to the - * original input that was being connected. + * In order to insert the trimmer between the + * two components that were being connected, we + * create a connection configuration entry which + * describes a connection from the trimmer's + * output to the original input that was being + * connected. * - * Hence, the creation of the trimmer will cause the - * graph "new port" listener to establish all downstream - * connections as its output port is connected. We will - * then establish the connection between the original - * upstream source and the trimmer. + * Hence, the creation of the trimmer will cause + * the graph "new port" listener to establish + * all downstream connections as its output port + * is connected. We will then establish the + * connection between the original upstream + * source and the trimmer. */ char *trimmer_name = NULL; enum bt_graph_status graph_status; - ret = asprintf(&trimmer_name, "%s-%s", - "stream-intersection-trimmer", + ret = asprintf(&trimmer_name, + "stream-intersection-trimmer-%s", upstream_port_name); if (ret < 0) { goto error; @@ -1668,9 +1767,9 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( ret = 0; ctx->connect_ports = false; - graph_status = bt_private_graph_add_component(ctx->graph, - trimmer_class, trimmer_name, - bt_value_borrow_from_private(trimmer_params), + graph_status = bt_private_graph_add_filter_component( + ctx->graph, trimmer_class, trimmer_name, + bt_private_value_borrow_value(trimmer_params), &trimmer); free(trimmer_name); if (graph_status != BT_GRAPH_STATUS_OK) { @@ -1679,13 +1778,13 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( BT_ASSERT(trimmer); trimmer_input = - bt_component_filter_get_input_port_by_index( + bt_component_filter_borrow_input_port_by_index( trimmer, 0); if (!trimmer_input) { goto error; } trimmer_output = - bt_component_filter_get_output_port_by_index( + bt_component_filter_borrow_output_port_by_index( trimmer, 0); if (!trimmer_output) { goto error; @@ -1695,18 +1794,18 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( * Replace the current downstream port by the trimmer's * upstream port. */ - BT_OBJECT_MOVE_REF(downstream_port, trimmer_input); + in_downstream_port = trimmer_input; + downstream_port = + bt_port_input_borrow_port(in_downstream_port); downstream_port_name = bt_port_get_name( downstream_port); - if (!downstream_port_name) { - goto error; - } + BT_ASSERT(downstream_port_name); } /* We have a winner! */ status = bt_private_graph_connect_ports(ctx->graph, - upstream_port, downstream_port, NULL); - BT_OBJECT_PUT_REF_AND_RESET(downstream_port); + out_upstream_port, in_downstream_port, NULL); + downstream_port = NULL; switch (status) { case BT_GRAPH_STATUS_OK: break; @@ -1771,7 +1870,9 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( * original downstream port. */ ret = cmd_run_ctx_connect_upstream_port_to_downstream_component( - ctx, trimmer, trimmer_output, cfg_conn); + ctx, + bt_component_filter_borrow_component(trimmer), + trimmer_output, cfg_conn); if (ret) { goto error; } @@ -1805,14 +1906,12 @@ end: BT_OBJECT_PUT_REF_AND_RESET(trimmer_params); BT_OBJECT_PUT_REF_AND_RESET(trimmer_class); BT_OBJECT_PUT_REF_AND_RESET(trimmer); - BT_OBJECT_PUT_REF_AND_RESET(trimmer_input); - BT_OBJECT_PUT_REF_AND_RESET(trimmer_output); return ret; } static int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx *ctx, - struct bt_port *upstream_port) + struct bt_port_output *upstream_port) { int ret = 0; const char *upstream_port_name; @@ -1822,9 +1921,11 @@ int cmd_run_ctx_connect_upstream_port(struct cmd_run_ctx *ctx, BT_ASSERT(ctx); BT_ASSERT(upstream_port); - upstream_port_name = bt_port_get_name(upstream_port); + upstream_port_name = bt_port_get_name( + bt_port_output_borrow_port(upstream_port)); BT_ASSERT(upstream_port_name); - upstream_comp = bt_port_get_component(upstream_port); + upstream_comp = bt_port_borrow_component( + bt_port_output_borrow_port(upstream_port)); if (!upstream_comp) { BT_LOGW("Upstream port to connect is not part of a component: " "port-addr=%p, port-name=\"%s\"", @@ -1884,17 +1985,17 @@ error: ret = -1; end: - bt_object_put_ref(upstream_comp); return ret; } static -void graph_port_added_listener(struct bt_port *port, void *data) +void graph_output_port_added_listener(struct cmd_run_ctx *ctx, + struct bt_port_output *out_port) { - struct bt_component *comp = NULL; - struct cmd_run_ctx *ctx = data; + struct bt_component *comp; + struct bt_port *port = bt_port_output_borrow_port(out_port); - comp = bt_port_get_component(port); + comp = bt_port_borrow_component(port); BT_LOGI("Port added to a graph's component: comp-addr=%p, " "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"", comp, comp ? bt_component_get_name(comp) : "", @@ -1914,66 +2015,30 @@ void graph_port_added_listener(struct bt_port *port, void *data) goto end; } - if (!bt_port_is_output(port)) { - BT_LOGI_STR("Skipping input port."); - goto end; - } - - if (cmd_run_ctx_connect_upstream_port(ctx, port)) { + if (cmd_run_ctx_connect_upstream_port(ctx, out_port)) { BT_LOGF_STR("Cannot connect upstream port."); fprintf(stderr, "Added port could not be connected: aborting\n"); abort(); } end: - bt_object_put_ref(comp); return; } static -void graph_port_removed_listener(struct bt_component *component, - struct bt_port *port, void *data) +void graph_source_output_port_added_listener( + struct bt_component_source *component, + struct bt_port_output *port, void *data) { - BT_LOGI("Port removed from a graph's component: comp-addr=%p, " - "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"", - component, bt_component_get_name(component), - port, bt_port_get_name(port)); -} - -static -void graph_ports_connected_listener(struct bt_port *upstream_port, - struct bt_port *downstream_port, void *data) -{ - struct bt_component *upstream_comp = bt_port_get_component(upstream_port); - struct bt_component *downstream_comp = bt_port_get_component(downstream_port); - - BT_ASSERT(upstream_comp); - BT_ASSERT(downstream_comp); - BT_LOGI("Graph's component ports connected: " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - upstream_comp, bt_component_get_name(upstream_comp), - upstream_port, bt_port_get_name(upstream_port), - downstream_comp, bt_component_get_name(downstream_comp), - downstream_port, bt_port_get_name(downstream_port)); - bt_object_put_ref(upstream_comp); - bt_object_put_ref(downstream_comp); + graph_output_port_added_listener(data, port); } static -void graph_ports_disconnected_listener( - struct bt_component *upstream_component, - struct bt_component *downstream_component, - struct bt_port *upstream_port, struct bt_port *downstream_port, - void *data) +void graph_filter_output_port_added_listener( + struct bt_component_filter *component, + struct bt_port_output *port, void *data) { - BT_LOGI("Graph's component ports disconnected: " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + graph_output_port_added_listener(data, port); } static @@ -1983,9 +2048,19 @@ void cmd_run_ctx_destroy(struct cmd_run_ctx *ctx) return; } - if (ctx->components) { - g_hash_table_destroy(ctx->components); - ctx->components = NULL; + if (ctx->src_components) { + g_hash_table_destroy(ctx->src_components); + ctx->src_components = NULL; + } + + if (ctx->flt_components) { + g_hash_table_destroy(ctx->flt_components); + ctx->flt_components = NULL; + } + + if (ctx->sink_components) { + g_hash_table_destroy(ctx->sink_components); + ctx->sink_components = NULL; } if (ctx->intersections) { @@ -2002,12 +2077,25 @@ static int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg) { int ret = 0; + enum bt_graph_status status; ctx->cfg = cfg; ctx->connect_ports = false; - ctx->components = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, bt_object_put_ref); - if (!ctx->components) { + ctx->src_components = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, bt_object_put_ref); + if (!ctx->src_components) { + goto error; + } + + ctx->flt_components = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, bt_object_put_ref); + if (!ctx->flt_components) { + goto error; + } + + ctx->sink_components = g_hash_table_new_full(g_direct_hash, + g_direct_equal, NULL, bt_object_put_ref); + if (!ctx->sink_components) { goto error; } @@ -2026,31 +2114,19 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg) } the_graph = ctx->graph; - ret = bt_private_graph_add_port_added_listener(ctx->graph, - graph_port_added_listener, NULL, ctx); - if (ret < 0) { + status = bt_private_graph_add_source_component_output_port_added_listener( + ctx->graph, graph_source_output_port_added_listener, NULL, ctx, + NULL); + if (status != BT_GRAPH_STATUS_OK) { BT_LOGE_STR("Cannot add \"port added\" listener to graph."); goto error; } - ret = bt_private_graph_add_port_removed_listener(ctx->graph, - graph_port_removed_listener, NULL, ctx); - if (ret < 0) { - BT_LOGE_STR("Cannot add \"port removed\" listener to graph."); - goto error; - } - - ret = bt_private_graph_add_ports_connected_listener(ctx->graph, - graph_ports_connected_listener, NULL, ctx); - if (ret < 0) { - BT_LOGE_STR("Cannot add \"ports connected\" listener to graph."); - goto error; - } - - ret = bt_private_graph_add_ports_disconnected_listener(ctx->graph, - graph_ports_disconnected_listener, NULL, ctx); - if (ret < 0) { - BT_LOGE_STR("Cannot add \"ports disconnected\" listener to graph."); + status = bt_private_graph_add_filter_component_output_port_added_listener( + ctx->graph, graph_filter_output_port_added_listener, NULL, ctx, + NULL); + if (status != BT_GRAPH_STATUS_OK) { + BT_LOGE_STR("Cannot add \"port added\" listener to graph."); goto error; } @@ -2067,7 +2143,7 @@ end: static int set_stream_intersections(struct cmd_run_ctx *ctx, struct bt_config_component *cfg_comp, - struct bt_component_class *comp_cls) + struct bt_component_class_source *src_comp_cls) { int ret = 0; uint64_t trace_idx; @@ -2088,9 +2164,11 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, struct port_id *port_id = NULL; struct trace_range *trace_range = NULL; const char *fail_reason = NULL; + struct bt_component_class *comp_cls = + bt_component_class_source_borrow_component_class(src_comp_cls); component_path_value = bt_value_map_borrow_entry_value( - bt_value_borrow_from_private(cfg_comp->params), + bt_private_value_borrow_value(cfg_comp->params), "path"); if (component_path_value && !bt_value_is_string(component_path_value)) { BT_LOGD("Cannot get path parameter: component-name=%s", @@ -2116,7 +2194,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, } ret = query(comp_cls, "trace-info", - bt_value_borrow_from_private(query_params), &query_result, + bt_private_value_borrow_value(query_params), &query_result, &fail_reason); if (ret) { BT_LOGD("Component class does not support the `trace-info` query: %s: " @@ -2306,8 +2384,8 @@ int cmd_run_ctx_create_components_from_config_components( struct cmd_run_ctx *ctx, GPtrArray *cfg_components) { size_t i; - struct bt_component_class *comp_cls = NULL; - struct bt_component *comp = NULL; + void *comp_cls = NULL; + void *comp = NULL; int ret = 0; for (i = 0; i < cfg_components->len; i++) { @@ -2315,8 +2393,26 @@ int cmd_run_ctx_create_components_from_config_components( g_ptr_array_index(cfg_components, i); GQuark quark; - comp_cls = find_component_class(cfg_comp->plugin_name->str, - cfg_comp->comp_cls_name->str, cfg_comp->type); + switch (cfg_comp->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + comp_cls = find_source_component_class( + cfg_comp->plugin_name->str, + cfg_comp->comp_cls_name->str); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + comp_cls = find_filter_component_class( + cfg_comp->plugin_name->str, + cfg_comp->comp_cls_name->str); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + comp_cls = find_sink_component_class( + cfg_comp->plugin_name->str, + cfg_comp->comp_cls_name->str); + break; + default: + abort(); + } + if (!comp_cls) { BT_LOGE("Cannot find component class: plugin-name=\"%s\", " "comp-cls-name=\"%s\", comp-cls-type=%d", @@ -2335,9 +2431,29 @@ int cmd_run_ctx_create_components_from_config_components( goto error; } - ret = bt_private_graph_add_component(ctx->graph, comp_cls, - cfg_comp->instance_name->str, - bt_value_borrow_from_private(cfg_comp->params), &comp); + switch (cfg_comp->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + ret = bt_private_graph_add_source_component(ctx->graph, + comp_cls, cfg_comp->instance_name->str, + bt_private_value_borrow_value(cfg_comp->params), + (void *) &comp); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + ret = bt_private_graph_add_filter_component(ctx->graph, + comp_cls, cfg_comp->instance_name->str, + bt_private_value_borrow_value(cfg_comp->params), + (void *) &comp); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + ret = bt_private_graph_add_sink_component(ctx->graph, + comp_cls, cfg_comp->instance_name->str, + bt_private_value_borrow_value(cfg_comp->params), + (void *) &comp); + break; + default: + abort(); + } + if (ret) { BT_LOGE("Cannot create component: plugin-name=\"%s\", " "comp-cls-name=\"%s\", comp-cls-type=%d, " @@ -2365,8 +2481,24 @@ int cmd_run_ctx_create_components_from_config_components( comp, cfg_comp->instance_name->str); quark = g_quark_from_string(cfg_comp->instance_name->str); BT_ASSERT(quark > 0); - g_hash_table_insert(ctx->components, - GUINT_TO_POINTER(quark), comp); + + switch (cfg_comp->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + g_hash_table_insert(ctx->src_components, + GUINT_TO_POINTER(quark), comp); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + g_hash_table_insert(ctx->flt_components, + GUINT_TO_POINTER(quark), comp); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + g_hash_table_insert(ctx->sink_components, + GUINT_TO_POINTER(quark), comp); + break; + default: + abort(); + } + comp = NULL; BT_OBJECT_PUT_REF_AND_RESET(comp_cls); } @@ -2420,25 +2552,27 @@ end: return ret; } +typedef uint64_t (*output_port_count_func_t)(void *); +typedef struct bt_port_output *(*borrow_output_port_by_index_func_t)( + void *, uint64_t); + static int cmd_run_ctx_connect_comp_ports(struct cmd_run_ctx *ctx, - struct bt_component *comp, - int64_t (*port_count_fn)(struct bt_component *), - struct bt_port *(*port_by_index_fn)(struct bt_component *, uint64_t)) + void *comp, output_port_count_func_t port_count_fn, + borrow_output_port_by_index_func_t port_by_index_fn) { int ret = 0; - int64_t count; + uint64_t count; uint64_t i; count = port_count_fn(comp); BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { - struct bt_port *upstream_port = port_by_index_fn(comp, i); + struct bt_port_output *upstream_port = port_by_index_fn(comp, i); BT_ASSERT(upstream_port); ret = cmd_run_ctx_connect_upstream_port(ctx, upstream_port); - bt_object_put_ref(upstream_port); if (ret) { goto end; } @@ -2456,28 +2590,27 @@ int cmd_run_ctx_connect_ports(struct cmd_run_ctx *ctx) gpointer g_name_quark, g_comp; ctx->connect_ports = true; - g_hash_table_iter_init(&iter, ctx->components); + g_hash_table_iter_init(&iter, ctx->src_components); while (g_hash_table_iter_next(&iter, &g_name_quark, &g_comp)) { - int64_t (*port_count_fn)(struct bt_component *); - struct bt_port *(*port_by_index_fn)(struct bt_component *, uint64_t); - - if (bt_component_is_source(g_comp)) { - port_count_fn = - bt_component_source_get_output_port_count; - port_by_index_fn = - bt_component_source_get_output_port_by_index; - } else if (bt_component_is_filter(g_comp)) { - port_count_fn = - bt_component_filter_get_output_port_count; - port_by_index_fn = - bt_component_filter_get_output_port_by_index; - } else { - continue; + ret = cmd_run_ctx_connect_comp_ports(ctx, g_comp, + (output_port_count_func_t) + bt_component_source_get_output_port_count, + (borrow_output_port_by_index_func_t) + bt_component_source_borrow_output_port_by_index); + if (ret) { + goto end; } + } + + g_hash_table_iter_init(&iter, ctx->flt_components); - ret = cmd_run_ctx_connect_comp_ports(ctx, - g_comp, port_count_fn, port_by_index_fn); + while (g_hash_table_iter_next(&iter, &g_name_quark, &g_comp)) { + ret = cmd_run_ctx_connect_comp_ports(ctx, g_comp, + (output_port_count_func_t) + bt_component_filter_get_output_port_count, + (borrow_output_port_by_index_func_t) + bt_component_filter_borrow_output_port_by_index); if (ret) { goto end; } @@ -2491,20 +2624,22 @@ static inline const char *bt_graph_status_str(enum bt_graph_status status) { switch (status) { - case BT_GRAPH_STATUS_CANCELED: - return "BT_GRAPH_STATUS_CANCELED"; - case BT_GRAPH_STATUS_AGAIN: - return "BT_GRAPH_STATUS_AGAIN"; - case BT_GRAPH_STATUS_END: - return "BT_GRAPH_STATUS_END"; case BT_GRAPH_STATUS_OK: return "BT_GRAPH_STATUS_OK"; - case BT_GRAPH_STATUS_INVALID: - return "BT_GRAPH_STATUS_INVALID"; - case BT_GRAPH_STATUS_NO_SINK: - return "BT_GRAPH_STATUS_NO_SINK"; + case BT_GRAPH_STATUS_END: + return "BT_GRAPH_STATUS_END"; + case BT_GRAPH_STATUS_AGAIN: + return "BT_GRAPH_STATUS_AGAIN"; + case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: + return "BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION"; + case BT_GRAPH_STATUS_CANCELED: + return "BT_GRAPH_STATUS_CANCELED"; case BT_GRAPH_STATUS_ERROR: return "BT_GRAPH_STATUS_ERROR"; + case BT_GRAPH_STATUS_NO_SINK: + return "BT_GRAPH_STATUS_NO_SINK"; + case BT_GRAPH_STATUS_NOMEM: + return "BT_GRAPH_STATUS_NOMEM"; default: return "(unknown)"; } @@ -2580,7 +2715,7 @@ int cmd_run(struct bt_config *cfg) goto error; case BT_GRAPH_STATUS_AGAIN: if (bt_graph_is_canceled( - bt_graph_borrow_from_private(ctx.graph))) { + bt_private_graph_borrow_graph(ctx.graph))) { BT_LOGI_STR("Graph was canceled by user."); goto error; } @@ -2592,14 +2727,14 @@ int cmd_run(struct bt_config *cfg) if (usleep(cfg->cmd_data.run.retry_duration_us)) { if (bt_graph_is_canceled( - bt_graph_borrow_from_private(ctx.graph))) { + bt_private_graph_borrow_graph(ctx.graph))) { BT_LOGI_STR("Graph was canceled by user."); goto error; } } } break; - case BT_COMPONENT_STATUS_END: + case BT_GRAPH_STATUS_END: goto end; default: BT_LOGE_STR("Graph failed to complete successfully"); @@ -2815,7 +2950,7 @@ int main(int argc, const char **argv) if (cfg->command_needs_plugins) { ret = load_all_plugins( - bt_value_borrow_from_private(cfg->plugin_paths)); + bt_private_value_borrow_value(cfg->plugin_paths)); if (ret) { BT_LOGE("Failed to load plugins: ret=%d", ret); retcode = 1; diff --git a/extras/gen-babeltrace-h.py b/extras/gen-babeltrace-h.py index 18310b5e..b604ea31 100644 --- a/extras/gen-babeltrace-h.py +++ b/extras/gen-babeltrace-h.py @@ -65,7 +65,7 @@ def _main(): /* * Babeltrace API * - * Copyright 2010-2017 EfficiOS Inc. + * Copyright 2010-2018 EfficiOS Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/include/Makefile.am b/include/Makefile.am index 5c0b79fc..9b8d925b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -74,8 +74,9 @@ babeltraceinclude_HEADERS = \ babeltrace/babeltrace.h \ babeltrace/logging.h \ babeltrace/object.h \ - babeltrace/types.h \ babeltrace/private-values.h \ + babeltrace/property.h \ + babeltrace/types.h \ babeltrace/values.h \ babeltrace/version.h @@ -127,13 +128,13 @@ babeltracetraceirinclude_HEADERS = \ babeltrace/trace-ir/packet.h \ babeltrace/trace-ir/private-clock-class.h \ babeltrace/trace-ir/private-event-class.h \ - babeltrace/trace-ir/private-event-header-field.h \ babeltrace/trace-ir/private-event.h \ + babeltrace/trace-ir/private-event-header-field.h \ babeltrace/trace-ir/private-field-classes.h \ babeltrace/trace-ir/private-fields.h \ babeltrace/trace-ir/private-packet-context-field.h \ - babeltrace/trace-ir/private-packet-header-field.h \ babeltrace/trace-ir/private-packet.h \ + babeltrace/trace-ir/private-packet-header-field.h \ babeltrace/trace-ir/private-stream-class.h \ babeltrace/trace-ir/private-stream.h \ babeltrace/trace-ir/private-trace.h \ @@ -151,14 +152,13 @@ babeltraceplugininclude_HEADERS = \ babeltracegraphincludedir = "$(includedir)/babeltrace/graph" babeltracegraphinclude_HEADERS = \ babeltrace/graph/component-class-filter.h \ + babeltrace/graph/component-class.h \ babeltrace/graph/component-class-sink.h \ babeltrace/graph/component-class-source.h \ - babeltrace/graph/component-class.h \ babeltrace/graph/component-filter.h \ + babeltrace/graph/component.h \ babeltrace/graph/component-sink.h \ babeltrace/graph/component-source.h \ - babeltrace/graph/component-status.h \ - babeltrace/graph/component.h \ babeltrace/graph/connection.h \ babeltrace/graph/graph.h \ babeltrace/graph/notification-event.h \ @@ -167,23 +167,34 @@ babeltracegraphinclude_HEADERS = \ babeltrace/graph/notification-packet.h \ babeltrace/graph/notification-stream.h \ babeltrace/graph/notification.h \ - babeltrace/graph/output-port-notification-iterator.h \ + babeltrace/graph/port-input.h \ + babeltrace/graph/port-output-notification-iterator.h \ + babeltrace/graph/port-output.h \ babeltrace/graph/port.h \ - babeltrace/graph/private-component-filter.h \ - babeltrace/graph/private-component-sink.h \ - babeltrace/graph/private-component-source.h \ - babeltrace/graph/private-component.h \ - babeltrace/graph/private-connection-notification-iterator.h \ - babeltrace/graph/private-connection-private-notification-iterator.h \ - babeltrace/graph/private-connection.h \ + babeltrace/graph/private-component-class-filter.h \ + babeltrace/graph/private-component-class-sink.h \ + babeltrace/graph/private-component-class-source.h \ + babeltrace/graph/private-component-class.h \ babeltrace/graph/private-graph.h \ babeltrace/graph/private-notification-event.h \ babeltrace/graph/private-notification-inactivity.h \ babeltrace/graph/private-notification-packet.h \ babeltrace/graph/private-notification-stream.h \ babeltrace/graph/private-notification.h \ - babeltrace/graph/private-port.h \ - babeltrace/graph/query-executor.h + babeltrace/graph/private-query-executor.h \ + babeltrace/graph/query-executor.h \ + babeltrace/graph/self-component-class-filter.h \ + babeltrace/graph/self-component-class-sink.h \ + babeltrace/graph/self-component-class-source.h \ + babeltrace/graph/self-component-filter.h \ + babeltrace/graph/self-component-port-input-notification-iterator.h \ + babeltrace/graph/self-component-port-input.h \ + babeltrace/graph/self-component-port-output.h \ + babeltrace/graph/self-component-port.h \ + babeltrace/graph/self-component-sink.h \ + babeltrace/graph/self-component-source.h \ + babeltrace/graph/self-component.h \ + babeltrace/graph/self-notification-iterator.h noinst_HEADERS = \ babeltrace/compat/stdlib-internal.h \ @@ -231,42 +242,43 @@ noinst_HEADERS = \ babeltrace/align-internal.h \ babeltrace/logging-internal.h \ babeltrace/endian-internal.h \ - babeltrace/trace-ir/packet-internal.h \ + babeltrace/trace-ir/attributes-internal.h \ + babeltrace/trace-ir/clock-class-internal.h \ + babeltrace/trace-ir/clock-value-internal.h \ + babeltrace/trace-ir/clock-value-set-internal.h \ babeltrace/trace-ir/event-class-internal.h \ - babeltrace/trace-ir/utils-internal.h \ - babeltrace/trace-ir/fields-internal.h \ - babeltrace/trace-ir/stream-class-internal.h \ babeltrace/trace-ir/event-internal.h \ + babeltrace/trace-ir/field-classes-internal.h \ babeltrace/trace-ir/field-path-internal.h \ + babeltrace/trace-ir/fields-internal.h \ babeltrace/trace-ir/field-wrapper-internal.h \ - babeltrace/trace-ir/trace-internal.h \ - babeltrace/trace-ir/clock-class-internal.h \ - babeltrace/trace-ir/field-classes-internal.h \ - babeltrace/trace-ir/clock-value-internal.h \ - babeltrace/trace-ir/attributes-internal.h \ - babeltrace/trace-ir/stream-internal.h \ + babeltrace/trace-ir/packet-internal.h \ babeltrace/trace-ir/resolve-field-path-internal.h \ + babeltrace/trace-ir/stream-class-internal.h \ + babeltrace/trace-ir/stream-internal.h \ + babeltrace/trace-ir/trace-internal.h \ + babeltrace/trace-ir/utils-internal.h \ babeltrace/prio-heap-internal.h \ babeltrace/lib-logging-internal.h \ babeltrace/compiler-internal.h \ babeltrace/babeltrace-internal.h \ babeltrace/assert-pre-internal.h \ + babeltrace/graph/component-class-internal.h \ + babeltrace/graph/component-class-sink-colander-internal.h \ + babeltrace/graph/component-filter-internal.h \ babeltrace/graph/component-internal.h \ - babeltrace/graph/notification-stream-internal.h \ + babeltrace/graph/component-sink-internal.h \ + babeltrace/graph/component-source-internal.h \ babeltrace/graph/connection-internal.h \ - babeltrace/graph/notification-event-internal.h \ - babeltrace/graph/query-executor-internal.h \ babeltrace/graph/graph-internal.h \ - babeltrace/graph/component-class-sink-colander-internal.h \ + babeltrace/graph/notification-event-internal.h \ babeltrace/graph/notification-inactivity-internal.h \ - babeltrace/graph/component-source-internal.h \ - babeltrace/graph/notification-packet-internal.h \ - babeltrace/graph/notification-iterator-internal.h \ babeltrace/graph/notification-internal.h \ - babeltrace/graph/component-filter-internal.h \ - babeltrace/graph/component-class-internal.h \ - babeltrace/graph/component-sink-internal.h \ + babeltrace/graph/notification-iterator-internal.h \ + babeltrace/graph/notification-packet-internal.h \ + babeltrace/graph/notification-stream-internal.h \ babeltrace/graph/port-internal.h \ + babeltrace/graph/query-executor-internal.h \ babeltrace/list-internal.h \ version.h \ version.i diff --git a/include/babeltrace/align-internal.h b/include/babeltrace/align-internal.h index 5d86ad57..d7c71bef 100644 --- a/include/babeltrace/align-internal.h +++ b/include/babeltrace/align-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_ALIGN_H /* - * BabelTrace align.h - alignment header - * * Copyright 2010 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h index 1cf3af96..d58b9860 100644 --- a/include/babeltrace/babeltrace-internal.h +++ b/include/babeltrace/babeltrace-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_INTERNAL_H /* - * babeltrace/babeltrace-internal.h - * * Copyright 2012 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index 77471a2e..bd5a69d1 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -4,7 +4,7 @@ /* * Babeltrace API * - * Copyright 2010-2017 EfficiOS Inc. + * Copyright 2010-2018 EfficiOS Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,6 @@ #include #include #include -#include #include #include #include @@ -109,22 +109,33 @@ #include #include #include -#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include #include #include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif /* BABELTRACE_BABELTRACE_H */ diff --git a/include/babeltrace/bitfield-internal.h b/include/babeltrace/bitfield-internal.h index e5d95e6f..c5d5eccd 100644 --- a/include/babeltrace/bitfield-internal.h +++ b/include/babeltrace/bitfield-internal.h @@ -2,10 +2,6 @@ #define _BABELTRACE_BITFIELD_H /* - * BabelTrace - * - * Bitfields read/write functions. - * * Copyright 2010 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/common-internal.h b/include/babeltrace/common-internal.h index c1215f5c..4c0cdc0d 100644 --- a/include/babeltrace/common-internal.h +++ b/include/babeltrace/common-internal.h @@ -1,6 +1,29 @@ #ifndef BABELTRACE_COMMON_INTERNAL_H #define BABELTRACE_COMMON_INTERNAL_H +/* + * Copyright (c) 2018 EfficiOS Inc. and Linux Foundation + * Copyright (c) 2018 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + #include #include #include diff --git a/include/babeltrace/compat/fcntl-internal.h b/include/babeltrace/compat/fcntl-internal.h index f0894e73..c5289430 100644 --- a/include/babeltrace/compat/fcntl-internal.h +++ b/include/babeltrace/compat/fcntl-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_FCNTL_H /* - * babeltrace/compat/fcntl.h - * * Copyright 2015 (c) - Jérémie Galarneau * * fcntl compatibility layer. diff --git a/include/babeltrace/compat/glib-internal.h b/include/babeltrace/compat/glib-internal.h index fd253559..e956280d 100644 --- a/include/babeltrace/compat/glib-internal.h +++ b/include/babeltrace/compat/glib-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_GLIB_H /* - * babeltrace/compat/glib.h - * * Copyright (C) 2015 Michael Jeanson * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/compat/memstream-internal.h b/include/babeltrace/compat/memstream-internal.h index 0b35330e..fa7514d0 100644 --- a/include/babeltrace/compat/memstream-internal.h +++ b/include/babeltrace/compat/memstream-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H /* - * format/ctf/memstream.h - * * Copyright 2012 (c) - Mathieu Desnoyers * * memstream compatibility layer. diff --git a/include/babeltrace/compat/mman-internal.h b/include/babeltrace/compat/mman-internal.h index fdbfd2cf..9f494526 100644 --- a/include/babeltrace/compat/mman-internal.h +++ b/include/babeltrace/compat/mman-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_MMAN_H /* - * babeltrace/compat/mman.h - * * Copyright (C) 2015-2016 Michael Jeanson * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/compat/socket-internal.h b/include/babeltrace/compat/socket-internal.h index 2d42bb68..b1fe1597 100644 --- a/include/babeltrace/compat/socket-internal.h +++ b/include/babeltrace/compat/socket-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_SOCKET_H /* - * babeltrace/compat/socket.h - * * Copyright (C) 2015-2017 Michael Jeanson * 2015 Mathieu Desnoyers * diff --git a/include/babeltrace/compat/stdlib-internal.h b/include/babeltrace/compat/stdlib-internal.h index db465edd..bd2a2c95 100644 --- a/include/babeltrace/compat/stdlib-internal.h +++ b/include/babeltrace/compat/stdlib-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_STDLIB_H /* - * babeltrace/compat/stdlib.h - * * Copyright (C) 2015 Michael Jeanson * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/compat/time-internal.h b/include/babeltrace/compat/time-internal.h index c7ce44c5..f5c09a94 100644 --- a/include/babeltrace/compat/time-internal.h +++ b/include/babeltrace/compat/time-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_INCLUDE_COMPAT_TIME_H /* - * babeltrace/compat/time.h - * * Copyright (C) 2013 JP Ikaheimonen * 2016 Michael Jeanson * diff --git a/include/babeltrace/compat/unistd-internal.h b/include/babeltrace/compat/unistd-internal.h index b06cdc86..502e87a5 100644 --- a/include/babeltrace/compat/unistd-internal.h +++ b/include/babeltrace/compat/unistd-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_UNISTD_H /* - * babeltrace/compat/unistd.h - * * (C) Copyright 2016 - Michael Jeanson * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/compat/uuid-internal.h b/include/babeltrace/compat/uuid-internal.h index 4237eb55..2c2e9295 100644 --- a/include/babeltrace/compat/uuid-internal.h +++ b/include/babeltrace/compat/uuid-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPAT_UUID_H /* - * babeltrace/compat/uuid.h - * * Copyright (C) 2011 Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/compiler-internal.h b/include/babeltrace/compiler-internal.h index 4eaa0e6e..c4c72cc4 100644 --- a/include/babeltrace/compiler-internal.h +++ b/include/babeltrace/compiler-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_COMPILER_H /* - * compiler.h - * * Copyright 2010 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/ctf-writer/attributes-internal.h b/include/babeltrace/ctf-writer/attributes-internal.h index c7d859d1..d0f19dfa 100644 --- a/include/babeltrace/ctf-writer/attributes-internal.h +++ b/include/babeltrace/ctf-writer/attributes-internal.h @@ -2,10 +2,6 @@ #define BABELTRACE_CTF_WRITER_ATTRIBUTES_H /* - * attributes.c - * - * Babeltrace - CTF writer: Attributes internal - * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * diff --git a/include/babeltrace/ctf-writer/clock-class-internal.h b/include/babeltrace/ctf-writer/clock-class-internal.h index b50eaae7..04baaa32 100644 --- a/include/babeltrace/ctf-writer/clock-class-internal.h +++ b/include/babeltrace/ctf-writer/clock-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_CLOCK_CLASS_INTERNAL_H /* - * BabelTrace - CTF writer: Clock class internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/clock-internal.h b/include/babeltrace/ctf-writer/clock-internal.h index 0a3811d6..d4c45f33 100644 --- a/include/babeltrace/ctf-writer/clock-internal.h +++ b/include/babeltrace/ctf-writer/clock-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_CLOCK_INTERNAL_H /* - * BabelTrace - CTF writer: Clock internal - * * Copyright 2017 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/ctf-writer/clock.h b/include/babeltrace/ctf-writer/clock.h index 508c6940..485f7a51 100644 --- a/include/babeltrace/ctf-writer/clock.h +++ b/include/babeltrace/ctf-writer/clock.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_CLOCK_H /* - * BabelTrace - CTF Writer: Clock - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/event-class-internal.h b/include/babeltrace/ctf-writer/event-class-internal.h index cd54739a..5da23c23 100644 --- a/include/babeltrace/ctf-writer/event-class-internal.h +++ b/include/babeltrace/ctf-writer/event-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_EVENT_CLASS_INTERNAL_H /* - * Babeltrace - CTF writer: Event class internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/event-fields.h b/include/babeltrace/ctf-writer/event-fields.h index f0f55b77..399c0e04 100644 --- a/include/babeltrace/ctf-writer/event-fields.h +++ b/include/babeltrace/ctf-writer/event-fields.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_EVENT_FIELDS_H /* - * BabelTrace - CTF Writer: Event Fields - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/event-internal.h b/include/babeltrace/ctf-writer/event-internal.h index aaac70bd..e6e15bdd 100644 --- a/include/babeltrace/ctf-writer/event-internal.h +++ b/include/babeltrace/ctf-writer/event-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_EVENT_INTERNAL_H /* - * BabelTrace - CTF Writer: Event - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/event-types.h b/include/babeltrace/ctf-writer/event-types.h index d39af8da..6e0295f6 100644 --- a/include/babeltrace/ctf-writer/event-types.h +++ b/include/babeltrace/ctf-writer/event-types.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_EVENT_TYPES_H /* - * BabelTrace - CTF Writer: Event Types - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/event.h b/include/babeltrace/ctf-writer/event.h index fb5fdb2a..bac0010b 100644 --- a/include/babeltrace/ctf-writer/event.h +++ b/include/babeltrace/ctf-writer/event.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_EVENT_H /* - * BabelTrace - CTF Writer: Event - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/field-path-internal.h b/include/babeltrace/ctf-writer/field-path-internal.h index 329ca6d5..f64cc936 100644 --- a/include/babeltrace/ctf-writer/field-path-internal.h +++ b/include/babeltrace/ctf-writer/field-path-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FIELD_PATH_INTERNAL /* - * BabelTrace - CTF writer: Field path - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/ctf-writer/field-types-internal.h b/include/babeltrace/ctf-writer/field-types-internal.h index 597bbefd..2412d518 100644 --- a/include/babeltrace/ctf-writer/field-types-internal.h +++ b/include/babeltrace/ctf-writer/field-types-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FIELD_TYPES_INTERNAL_H /* - * Babeltrace - CTF writer: Event Fields - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/field-types.h b/include/babeltrace/ctf-writer/field-types.h index 5584a293..88fcde96 100644 --- a/include/babeltrace/ctf-writer/field-types.h +++ b/include/babeltrace/ctf-writer/field-types.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FIELD_TYPES_H /* - * Babeltrace - CTF writer: Event Fields - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/fields-internal.h b/include/babeltrace/ctf-writer/fields-internal.h index 6b66f693..3fb4852c 100644 --- a/include/babeltrace/ctf-writer/fields-internal.h +++ b/include/babeltrace/ctf-writer/fields-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FIELDS_INTERNAL_H /* - * Babeltrace - CTF writer: Event Fields - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/fields.h b/include/babeltrace/ctf-writer/fields.h index eba9abd2..2ff25abd 100644 --- a/include/babeltrace/ctf-writer/fields.h +++ b/include/babeltrace/ctf-writer/fields.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FIELDS_H /* - * Babeltrace - CTF writer: Event Fields - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/functor-internal.h b/include/babeltrace/ctf-writer/functor-internal.h index e11f8b08..3e2d4e0b 100644 --- a/include/babeltrace/ctf-writer/functor-internal.h +++ b/include/babeltrace/ctf-writer/functor-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_FUNCTOR_INTERNAL_H /* - * BabelTrace - CTF Writer: Functors for use with glib data structures - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/resolve-internal.h b/include/babeltrace/ctf-writer/resolve-internal.h index b456f22d..bd8e1468 100644 --- a/include/babeltrace/ctf-writer/resolve-internal.h +++ b/include/babeltrace/ctf-writer/resolve-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_RESOLVE_INTERNAL_H /* - * Babeltrace - CTF writer: Type resolving internal - * * Copyright 2015 Jérémie Galarneau * Copyright 2016 Philippe Proulx * diff --git a/include/babeltrace/ctf-writer/stream-class-internal.h b/include/babeltrace/ctf-writer/stream-class-internal.h index f1a90e1f..dbb003f4 100644 --- a/include/babeltrace/ctf-writer/stream-class-internal.h +++ b/include/babeltrace/ctf-writer/stream-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_STREAM_CLASS_INTERNAL_H /* - * BabelTrace - CTF Writer: Stream Class - * * Copyright 2014 EfficiOS Inc. * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/stream-class.h b/include/babeltrace/ctf-writer/stream-class.h index 042b13a6..eb8da8a1 100644 --- a/include/babeltrace/ctf-writer/stream-class.h +++ b/include/babeltrace/ctf-writer/stream-class.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_STREAM_CLASS_H /* - * BabelTrace - CTF Writer: Stream Class - * * Copyright 2014 EfficiOS Inc. * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/stream-internal.h b/include/babeltrace/ctf-writer/stream-internal.h index 3da09664..9928f16f 100644 --- a/include/babeltrace/ctf-writer/stream-internal.h +++ b/include/babeltrace/ctf-writer/stream-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H /* - * BabelTrace - CTF Writer: Stream - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/stream.h b/include/babeltrace/ctf-writer/stream.h index 0a73013e..ff14adeb 100644 --- a/include/babeltrace/ctf-writer/stream.h +++ b/include/babeltrace/ctf-writer/stream.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_STREAM_H /* - * BabelTrace - CTF Writer: Stream - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/trace-internal.h b/include/babeltrace/ctf-writer/trace-internal.h index 79e3f08b..10a10f28 100644 --- a/include/babeltrace/ctf-writer/trace-internal.h +++ b/include/babeltrace/ctf-writer/trace-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_TRACE_INTERNAL_H /* - * BabelTrace - CTF Writer: Trace - * * Copyright 2014 EfficiOS Inc. * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/trace.h b/include/babeltrace/ctf-writer/trace.h index b83877a6..944af83a 100644 --- a/include/babeltrace/ctf-writer/trace.h +++ b/include/babeltrace/ctf-writer/trace.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_TRACE_H /* - * BabelTrace - CTF Writer: Stream Class - * * Copyright 2014 EfficiOS Inc. * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/utils-internal.h b/include/babeltrace/ctf-writer/utils-internal.h index 264bf335..991207a5 100644 --- a/include/babeltrace/ctf-writer/utils-internal.h +++ b/include/babeltrace/ctf-writer/utils-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_UTILS_INTERNAL_H /* - * Babeltrace - Internal CTF writer utilities - * * 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 diff --git a/include/babeltrace/ctf-writer/utils.h b/include/babeltrace/ctf-writer/utils.h index 34cf4769..f58a21b0 100644 --- a/include/babeltrace/ctf-writer/utils.h +++ b/include/babeltrace/ctf-writer/utils.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_UTILS_H /* - * BabelTrace - CTF writer: Utilities - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/validation-internal.h b/include/babeltrace/ctf-writer/validation-internal.h index 49533095..ead8c8b4 100644 --- a/include/babeltrace/ctf-writer/validation-internal.h +++ b/include/babeltrace/ctf-writer/validation-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_VALIDATION_INTERNAL_H /* - * Babeltrace - CTF writer: Validation of trace, stream class, and event class - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/ctf-writer/visitor-internal.h b/include/babeltrace/ctf-writer/visitor-internal.h index d5e02863..993b92b3 100644 --- a/include/babeltrace/ctf-writer/visitor-internal.h +++ b/include/babeltrace/ctf-writer/visitor-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_VISITOR_INTERNAL_H /* - * BabelTrace - CTF writer: Visitor internal - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/visitor.h b/include/babeltrace/ctf-writer/visitor.h index 16069118..60d0a45b 100644 --- a/include/babeltrace/ctf-writer/visitor.h +++ b/include/babeltrace/ctf-writer/visitor.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_VISITOR_H /* - * BabelTrace - CTF writer: Visitor - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/writer-internal.h b/include/babeltrace/ctf-writer/writer-internal.h index 07fed465..4c2f93bf 100644 --- a/include/babeltrace/ctf-writer/writer-internal.h +++ b/include/babeltrace/ctf-writer/writer-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_WRITER_INTERNAL_H /* - * BabelTrace - CTF Writer: Writer internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/ctf-writer/writer.h b/include/babeltrace/ctf-writer/writer.h index e12f6d47..8c82593b 100644 --- a/include/babeltrace/ctf-writer/writer.h +++ b/include/babeltrace/ctf-writer/writer.h @@ -2,8 +2,6 @@ #define BABELTRACE_CTF_WRITER_WRITER_H /* - * BabelTrace - CTF Writer: Writer - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/endian-internal.h b/include/babeltrace/endian-internal.h index db04a9ae..5c74c35d 100644 --- a/include/babeltrace/endian-internal.h +++ b/include/babeltrace/endian-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_ENDIAN_H /* - * babeltrace/endian.h - * * Copyright 2012 (c) - Mathieu Desnoyers * * endian.h compatibility layer. diff --git a/include/babeltrace/graph/component-class-filter.h b/include/babeltrace/graph/component-class-filter.h index b27eb376..beddfa10 100644 --- a/include/babeltrace/graph/component-class-filter.h +++ b/include/babeltrace/graph/component-class-filter.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_CLASS_FILTER_H /* - * Babeltrace - Component Class Interface. - * * Copyright 2016 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,28 +23,20 @@ * SOFTWARE. */ -/* For component class method type definitions */ -#include - #ifdef __cplusplus extern "C" { #endif struct bt_component_class; - -extern -struct bt_component_class *bt_component_class_filter_create(const char *name, - bt_component_class_notification_iterator_next_method method); - -extern -int bt_component_class_filter_set_notification_iterator_init_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_init_method method); - -extern -int bt_component_class_filter_set_notification_iterator_finalize_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_finalize_method method); +struct bt_component_class_filter; + +static inline +struct bt_component_class * +bt_component_class_filter_borrow_component_class( + struct bt_component_class_filter *comp_cls_filter) +{ + return (void *) comp_cls_filter; +} #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-class-internal.h b/include/babeltrace/graph/component-class-internal.h index 66d920d6..e5185739 100644 --- a/include/babeltrace/graph/component-class-internal.h +++ b/include/babeltrace/graph/component-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_CLASS_INTERNAL_H /* - * BabelTrace - Component Class Internal - * * Copyright 2015 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -30,9 +28,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -56,45 +54,57 @@ struct bt_component_class { GString *name; GString *description; GString *help; - struct { - bt_component_class_init_method init; - bt_component_class_finalize_method finalize; - bt_component_class_query_method query; - bt_component_class_accept_port_connection_method accept_port_connection; - bt_component_class_port_connected_method port_connected; - bt_component_class_port_disconnected_method port_disconnected; - } methods; + /* Array of struct bt_component_class_destroy_listener */ GArray *destroy_listeners; - bt_bool frozen; + bool frozen; struct bt_list_head node; struct bt_plugin_so_shared_lib_handle *so_handle; }; -struct bt_component_class_notification_iterator_methods { - bt_component_class_notification_iterator_init_method init; - bt_component_class_notification_iterator_finalize_method finalize; - bt_component_class_notification_iterator_next_method next; -}; - struct bt_component_class_source { struct bt_component_class parent; struct { - struct bt_component_class_notification_iterator_methods iterator; + bt_private_component_class_source_init_method init; + bt_private_component_class_source_finalize_method finalize; + bt_private_component_class_source_notification_iterator_init_method notif_iter_init; + bt_private_component_class_source_notification_iterator_finalize_method notif_iter_finalize; + bt_private_component_class_source_notification_iterator_next_method notif_iter_next; + bt_private_component_class_source_query_method query; + bt_private_component_class_source_accept_output_port_connection_method accept_output_port_connection; + bt_private_component_class_source_output_port_connected_method output_port_connected; + bt_private_component_class_source_output_port_disconnected_method output_port_disconnected; } methods; }; struct bt_component_class_sink { struct bt_component_class parent; struct { - bt_component_class_sink_consume_method consume; + bt_private_component_class_sink_init_method init; + bt_private_component_class_sink_finalize_method finalize; + bt_private_component_class_sink_query_method query; + bt_private_component_class_sink_accept_input_port_connection_method accept_input_port_connection; + bt_private_component_class_sink_input_port_connected_method input_port_connected; + bt_private_component_class_sink_input_port_disconnected_method input_port_disconnected; + bt_private_component_class_sink_consume_method consume; } methods; }; struct bt_component_class_filter { struct bt_component_class parent; struct { - struct bt_component_class_notification_iterator_methods iterator; + bt_private_component_class_filter_init_method init; + bt_private_component_class_filter_finalize_method finalize; + bt_private_component_class_filter_notification_iterator_init_method notif_iter_init; + bt_private_component_class_filter_notification_iterator_finalize_method notif_iter_finalize; + bt_private_component_class_filter_notification_iterator_next_method notif_iter_next; + bt_private_component_class_filter_query_method query; + bt_private_component_class_filter_accept_input_port_connection_method accept_input_port_connection; + bt_private_component_class_filter_accept_output_port_connection_method accept_output_port_connection; + bt_private_component_class_filter_input_port_connected_method input_port_connected; + bt_private_component_class_filter_output_port_connected_method output_port_connected; + bt_private_component_class_filter_input_port_disconnected_method input_port_disconnected; + bt_private_component_class_filter_output_port_disconnected_method output_port_disconnected; } methods; }; @@ -102,12 +112,19 @@ BT_HIDDEN void bt_component_class_add_destroy_listener(struct bt_component_class *class, bt_component_class_destroy_listener_func func, void *data); +BT_HIDDEN +void _bt_component_class_freeze(struct bt_component_class *component_class); + +#ifdef BT_DEV_MODE +# define bt_component_class_freeze _bt_component_class_freeze +#else +# define bt_component_class_freeze(_cc) +#endif + static inline const char *bt_component_class_type_string(enum bt_component_class_type type) { switch (type) { - case BT_COMPONENT_CLASS_TYPE_UNKNOWN: - return "BT_COMPONENT_CLASS_TYPE_UNKNOWN"; case BT_COMPONENT_CLASS_TYPE_SOURCE: return "BT_COMPONENT_CLASS_TYPE_SOURCE"; case BT_COMPONENT_CLASS_TYPE_SINK: diff --git a/include/babeltrace/graph/component-class-sink-colander-internal.h b/include/babeltrace/graph/component-class-sink-colander-internal.h index d1069543..0e86ff4b 100644 --- a/include/babeltrace/graph/component-class-sink-colander-internal.h +++ b/include/babeltrace/graph/component-class-sink-colander-internal.h @@ -38,7 +38,8 @@ struct bt_component_class_sink_colander_data { uint64_t *count_addr; }; -extern struct bt_component_class *bt_component_class_sink_colander_get(void); +extern struct bt_component_class_sink * +bt_component_class_sink_colander_get(void); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-class-sink.h b/include/babeltrace/graph/component-class-sink.h index 6e06e1e5..45e70139 100644 --- a/include/babeltrace/graph/component-class-sink.h +++ b/include/babeltrace/graph/component-class-sink.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_CLASS_SINK_H /* - * Babeltrace - Component Class Interface. - * * Copyright 2016 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,22 +23,20 @@ * SOFTWARE. */ -/* For component class method type definitions */ -#include - #ifdef __cplusplus extern "C" { #endif struct bt_component_class; -struct bt_private_component; - -typedef enum bt_component_status (*bt_component_class_sink_consume_method)( - struct bt_private_component *private_component); - -extern -struct bt_component_class *bt_component_class_sink_create(const char *name, - bt_component_class_sink_consume_method consume_method); +struct bt_component_class_sink; + +static inline +struct bt_component_class * +bt_component_class_sink_borrow_component_class( + struct bt_component_class_sink *comp_cls_sink) +{ + return (void *) comp_cls_sink; +} #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-class-source.h b/include/babeltrace/graph/component-class-source.h index e0c7ecce..5bf1f178 100644 --- a/include/babeltrace/graph/component-class-source.h +++ b/include/babeltrace/graph/component-class-source.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_CLASS_SOURCE_H /* - * Babeltrace - Component Class Interface. - * * Copyright 2016 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,28 +23,20 @@ * SOFTWARE. */ -/* For component class method type definitions */ -#include - #ifdef __cplusplus extern "C" { #endif struct bt_component_class; - -extern -struct bt_component_class *bt_component_class_source_create(const char *name, - bt_component_class_notification_iterator_next_method method); - -extern -int bt_component_class_source_set_notification_iterator_init_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_init_method method); - -extern -int bt_component_class_source_set_notification_iterator_finalize_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_finalize_method method); +struct bt_component_class_source; + +static inline +struct bt_component_class * +bt_component_class_source_borrow_component_class( + struct bt_component_class_source *comp_cls_source) +{ + return (void *) comp_cls_source; +} #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-class.h b/include/babeltrace/graph/component-class.h index 3b1d6965..46cb59d2 100644 --- a/include/babeltrace/graph/component-class.h +++ b/include/babeltrace/graph/component-class.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_CLASS_H /* - * Babeltrace - Component Class Interface. - * * Copyright 2016 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,162 +23,30 @@ * SOFTWARE. */ -#include - -/* For enum bt_component_status */ -#include - -/* For enum bt_notification_iterator_status */ -#include - -/* For enum bt_query_status */ -#include - /* For bt_bool */ #include -/* For bt_notification_array */ -#include - #ifdef __cplusplus extern "C" { #endif struct bt_component_class; -struct bt_component; -struct bt_private_component; -struct bt_private_port; -struct bt_port; -struct bt_value; -struct bt_private_connection_private_notification_iterator; -struct bt_query_executor; -/** - * Component class type. - */ enum bt_component_class_type { - BT_COMPONENT_CLASS_TYPE_UNKNOWN = -1, - - /** A source component is a notification generator. */ BT_COMPONENT_CLASS_TYPE_SOURCE = 0, - - /** A sink component handles incoming notifications. */ - BT_COMPONENT_CLASS_TYPE_SINK = 1, - - /** A filter component implements both Source and Sink interfaces. */ - BT_COMPONENT_CLASS_TYPE_FILTER = 2, + BT_COMPONENT_CLASS_TYPE_FILTER = 1, + BT_COMPONENT_CLASS_TYPE_SINK = 2, }; -struct bt_component_class_query_method_return { - struct bt_value *result; - enum bt_query_status status; -}; - -typedef enum bt_component_status (*bt_component_class_init_method)( - struct bt_private_component *private_component, - struct bt_value *params, void *init_method_data); - -typedef void (*bt_component_class_finalize_method)( - struct bt_private_component *private_component); - -typedef enum bt_notification_iterator_status - (*bt_component_class_notification_iterator_init_method)( - struct bt_private_connection_private_notification_iterator *notification_iterator, - struct bt_private_port *private_port); - -typedef void (*bt_component_class_notification_iterator_finalize_method)( - struct bt_private_connection_private_notification_iterator *notification_iterator); - -typedef enum bt_notification_iterator_status -(*bt_component_class_notification_iterator_next_method)( - struct bt_private_connection_private_notification_iterator *notification_iterator, - bt_notification_array notifs, uint64_t capacity, - uint64_t *count); - -typedef struct bt_component_class_query_method_return (*bt_component_class_query_method)( - struct bt_component_class *component_class, - struct bt_query_executor *query_executor, - const char *object, struct bt_value *params); - -typedef enum bt_component_status (*bt_component_class_accept_port_connection_method)( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port); - -typedef enum bt_component_status (*bt_component_class_port_connected_method)( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port); - -typedef void (*bt_component_class_port_disconnected_method)( - struct bt_private_component *private_component, - struct bt_private_port *private_port); - -extern int bt_component_class_set_init_method( - struct bt_component_class *component_class, - bt_component_class_init_method method); - -extern int bt_component_class_set_finalize_method( - struct bt_component_class *component_class, - bt_component_class_finalize_method method); - -extern int bt_component_class_set_accept_port_connection_method( - struct bt_component_class *component_class, - bt_component_class_accept_port_connection_method method); - -extern int bt_component_class_set_port_connected_method( - struct bt_component_class *component_class, - bt_component_class_port_connected_method method); - -extern int bt_component_class_set_port_disconnected_method( - struct bt_component_class *component_class, - bt_component_class_port_disconnected_method method); - -extern int bt_component_class_set_query_method( - struct bt_component_class *component_class, - bt_component_class_query_method method); - -extern int bt_component_class_set_description( - struct bt_component_class *component_class, - const char *description); - -extern int bt_component_class_set_help( - struct bt_component_class *component_class, - const char *help); - -extern int bt_component_class_freeze( - struct bt_component_class *component_class); - -/** - * Get a component class' name. - * - * @param component_class Component class of which to get the name - * @returns Name of the component class - */ extern const char *bt_component_class_get_name( struct bt_component_class *component_class); -/** - * Get a component class' description. - * - * Component classes may provide an optional description. It may, however, - * opt not to. - * - * @param component_class Component class of which to get the description - * @returns Description of the component class, or NULL. - */ extern const char *bt_component_class_get_description( struct bt_component_class *component_class); extern const char *bt_component_class_get_help( struct bt_component_class *component_class); -/** - * Get a component class' type. - * - * @param component_class Component class of which to get the type - * @returns One of #bt_component_type - */ extern enum bt_component_class_type bt_component_class_get_type( struct bt_component_class *component_class); diff --git a/include/babeltrace/graph/component-filter-internal.h b/include/babeltrace/graph/component-filter-internal.h index 08caef0e..a31a881d 100644 --- a/include/babeltrace/graph/component-filter-internal.h +++ b/include/babeltrace/graph/component-filter-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_FILTER_INTERNAL_H /* - * BabelTrace - Filter Component Internal - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -31,19 +29,10 @@ #include #include -struct bt_value; - struct bt_component_filter { struct bt_component parent; }; -/** - * Allocate a filter component. - * - * @param class Component class - * @param params A dictionary of component parameters - * @returns A filter component instance - */ BT_HIDDEN struct bt_component *bt_component_filter_create( struct bt_component_class *class); diff --git a/include/babeltrace/graph/component-filter.h b/include/babeltrace/graph/component-filter.h index 28f4f33b..ebc55387 100644 --- a/include/babeltrace/graph/component-filter.h +++ b/include/babeltrace/graph/component-filter.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_FILTER_H /* - * BabelTrace - Filter Plug-in Interface - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -33,22 +31,35 @@ extern "C" { #endif -struct bt_port; struct bt_component; +struct bt_component_filter; +struct bt_port_input; +struct bt_port_output; + +static inline +struct bt_component *bt_component_filter_borrow_component( + struct bt_component_filter *component) +{ + return (void *) component; +} + +extern uint64_t bt_component_filter_get_input_port_count( + struct bt_component_filter *component); + +extern struct bt_port_input *bt_component_filter_borrow_input_port_by_name( + struct bt_component_filter *component, const char *name); + +extern struct bt_port_input *bt_component_filter_borrow_input_port_by_index( + struct bt_component_filter *component, uint64_t index); + +extern uint64_t bt_component_filter_get_output_port_count( + struct bt_component_filter *component); + +extern struct bt_port_output *bt_component_filter_borrow_output_port_by_name( + struct bt_component_filter *component, const char *name); -extern int64_t bt_component_filter_get_input_port_count( - struct bt_component *component); -extern struct bt_port *bt_component_filter_get_input_port_by_name( - struct bt_component *component, const char *name); -extern struct bt_port *bt_component_filter_get_input_port_by_index( - struct bt_component *component, uint64_t index); - -extern int64_t bt_component_filter_get_output_port_count( - struct bt_component *component); -extern struct bt_port *bt_component_filter_get_output_port_by_name( - struct bt_component *component, const char *name); -extern struct bt_port *bt_component_filter_get_output_port_by_index( - struct bt_component *component, uint64_t index); +extern struct bt_port_output *bt_component_filter_borrow_output_port_by_index( + struct bt_component_filter *component, uint64_t index); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index 682b250e..d186425e 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_INTERNAL_H /* - * BabelTrace - Component internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -71,13 +69,6 @@ struct bt_component { bool initialized; }; -static inline -struct bt_private_component *bt_private_component_from_component( - struct bt_component *component) -{ - return (void *) component; -} - static inline struct bt_graph *bt_component_borrow_graph(struct bt_component *comp) { @@ -86,17 +77,16 @@ struct bt_graph *bt_component_borrow_graph(struct bt_component *comp) } BT_HIDDEN -enum bt_component_status bt_component_create( - struct bt_component_class *component_class, +int bt_component_create(struct bt_component_class *component_class, const char *name, struct bt_component **component); BT_HIDDEN -enum bt_component_status bt_component_accept_port_connection( +enum bt_self_component_status bt_component_accept_port_connection( struct bt_component *component, struct bt_port *self_port, struct bt_port *other_port); BT_HIDDEN -enum bt_component_status bt_component_port_connected( +enum bt_self_component_status bt_component_port_connected( struct bt_component *comp, struct bt_port *self_port, struct bt_port *other_port); @@ -109,40 +99,40 @@ void bt_component_set_graph(struct bt_component *component, struct bt_graph *graph); BT_HIDDEN -int64_t bt_component_get_input_port_count(struct bt_component *comp); +uint64_t bt_component_get_input_port_count(struct bt_component *comp); BT_HIDDEN -int64_t bt_component_get_output_port_count(struct bt_component *comp); +uint64_t bt_component_get_output_port_count(struct bt_component *comp); BT_HIDDEN -struct bt_port *bt_component_get_input_port_by_index(struct bt_component *comp, - uint64_t index); +struct bt_port_input *bt_component_borrow_input_port_by_index( + struct bt_component *comp, uint64_t index); BT_HIDDEN -struct bt_port *bt_component_get_output_port_by_index(struct bt_component *comp, - uint64_t index); +struct bt_port_output *bt_component_borrow_output_port_by_index( + struct bt_component *comp, uint64_t index); BT_HIDDEN -struct bt_port *bt_component_get_input_port_by_name(struct bt_component *comp, - const char *name); +struct bt_port_input *bt_component_borrow_input_port_by_name( + struct bt_component *comp, const char *name); BT_HIDDEN -struct bt_port *bt_component_get_output_port_by_name(struct bt_component *comp, - const char *name); +struct bt_port_output *bt_component_borrow_output_port_by_name( + struct bt_component *comp, const char *name); BT_HIDDEN -struct bt_port *bt_component_add_input_port( +struct bt_port_input *bt_component_add_input_port( struct bt_component *component, const char *name, void *user_data); BT_HIDDEN -struct bt_port *bt_component_add_output_port( +struct bt_port_output *bt_component_add_output_port( struct bt_component *component, const char *name, void *user_data); BT_HIDDEN -enum bt_component_status bt_component_remove_port( - struct bt_component *component, struct bt_port *port); +void bt_component_remove_port(struct bt_component *component, + struct bt_port *port); BT_HIDDEN void bt_component_add_destroy_listener(struct bt_component *component, @@ -153,29 +143,22 @@ void bt_component_remove_destroy_listener(struct bt_component *component, bt_component_destroy_listener_func func, void *data); static inline -const char *bt_component_status_string(enum bt_component_status status) +const char *bt_self_component_status_string( + enum bt_self_component_status status) { switch (status) { - case BT_COMPONENT_STATUS_OK: - return "BT_COMPONENT_STATUS_OK"; - case BT_COMPONENT_STATUS_END: - return "BT_COMPONENT_STATUS_END"; - case BT_COMPONENT_STATUS_AGAIN: - return "BT_COMPONENT_STATUS_AGAIN"; - case BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION: - return "BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION"; - case BT_COMPONENT_STATUS_ERROR: - return "BT_COMPONENT_STATUS_ERROR"; - case BT_COMPONENT_STATUS_UNSUPPORTED: - return "BT_COMPONENT_STATUS_UNSUPPORTED"; - case BT_COMPONENT_STATUS_INVALID: - return "BT_COMPONENT_STATUS_INVALID"; - case BT_COMPONENT_STATUS_NOMEM: - return "BT_COMPONENT_STATUS_NOMEM"; - case BT_COMPONENT_STATUS_NOT_FOUND: - return "BT_COMPONENT_STATUS_NOT_FOUND"; - case BT_COMPONENT_STATUS_GRAPH_IS_CANCELED: - return "BT_COMPONENT_STATUS_GRAPH_IS_CANCELED"; + case BT_SELF_COMPONENT_STATUS_OK: + return "BT_SELF_COMPONENT_STATUS_OK"; + case BT_SELF_COMPONENT_STATUS_END: + return "BT_SELF_COMPONENT_STATUS_END"; + case BT_SELF_COMPONENT_STATUS_AGAIN: + return "BT_SELF_COMPONENT_STATUS_AGAIN"; + case BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION: + return "BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION"; + case BT_SELF_COMPONENT_STATUS_ERROR: + return "BT_SELF_COMPONENT_STATUS_ERROR"; + case BT_SELF_COMPONENT_STATUS_NOMEM: + return "BT_SELF_COMPONENT_STATUS_NOMEM"; default: return "(unknown)"; } diff --git a/include/babeltrace/graph/component-sink-internal.h b/include/babeltrace/graph/component-sink-internal.h index 3840bd50..7b67e2fd 100644 --- a/include/babeltrace/graph/component-sink-internal.h +++ b/include/babeltrace/graph/component-sink-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_SINK_INTERNAL_H /* - * BabelTrace - Sink Component internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -33,21 +31,10 @@ #include #include -struct bt_value; - -//typedef uint32_t notification_mask_t; - struct bt_component_sink { struct bt_component parent; }; -/** - * Allocate a sink component. - * - * @param class Component class - * @param params A dictionary of component parameters - * @returns A sink component instance - */ BT_HIDDEN struct bt_component *bt_component_sink_create( struct bt_component_class *class); @@ -55,31 +42,4 @@ struct bt_component *bt_component_sink_create( BT_HIDDEN void bt_component_sink_destroy(struct bt_component *component); -static inline -enum bt_component_status bt_component_sink_consume( - struct bt_component *component) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_component_class_sink *sink_class = NULL; - - BT_ASSERT(component); - BT_ASSERT(bt_component_get_class_type(component) == - BT_COMPONENT_CLASS_TYPE_SINK); - sink_class = container_of(component->class, - struct bt_component_class_sink, parent); - BT_ASSERT(sink_class->methods.consume); - BT_LOGD("Calling user's consume method: " - "comp-addr=%p, comp-name=\"%s\"", - component, bt_component_get_name(component)); - ret = sink_class->methods.consume( - bt_private_component_from_component(component)); - BT_LOGD("User method returned: status=%s", - bt_component_status_string(ret)); - if (ret < 0) { - BT_LOGW_STR("Consume method failed."); - } - - return ret; -} - #endif /* BABELTRACE_GRAPH_COMPONENT_SINK_INTERNAL_H */ diff --git a/include/babeltrace/graph/component-sink.h b/include/babeltrace/graph/component-sink.h index a89aa424..6c33eb75 100644 --- a/include/babeltrace/graph/component-sink.h +++ b/include/babeltrace/graph/component-sink.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_SINK_H /* - * BabelTrace - Sink Component Interface - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -34,13 +32,24 @@ extern "C" { #endif struct bt_component; +struct bt_component_sink; +struct bt_port_input; + +static inline +struct bt_component *bt_component_sink_borrow_component( + struct bt_component_sink *component) +{ + return (void *) component; +} + +extern uint64_t bt_component_sink_get_input_port_count( + struct bt_component_sink *component); + +extern struct bt_port_input *bt_component_sink_borrow_input_port_by_name( + struct bt_component_sink *component, const char *name); -extern int64_t bt_component_sink_get_input_port_count( - struct bt_component *component); -extern struct bt_port *bt_component_sink_get_input_port_by_name( - struct bt_component *component, const char *name); -extern struct bt_port *bt_component_sink_get_input_port_by_index( - struct bt_component *component, uint64_t index); +extern struct bt_port_input *bt_component_sink_borrow_input_port_by_index( + struct bt_component_sink *component, uint64_t index); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-source-internal.h b/include/babeltrace/graph/component-source-internal.h index 37e6d934..08c08296 100644 --- a/include/babeltrace/graph/component-source-internal.h +++ b/include/babeltrace/graph/component-source-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_SOURCE_INTERNAL_H /* - * BabelTrace - Source Component internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -31,19 +29,10 @@ #include #include -struct bt_value; - struct bt_component_source { struct bt_component parent; }; -/** - * Allocate a source component. - * - * @param class Component class - * @param params A dictionary of component parameters - * @returns A source component instance - */ BT_HIDDEN struct bt_component *bt_component_source_create( struct bt_component_class *class); diff --git a/include/babeltrace/graph/component-source.h b/include/babeltrace/graph/component-source.h index 9f7ceccf..91af914b 100644 --- a/include/babeltrace/graph/component-source.h +++ b/include/babeltrace/graph/component-source.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_SOURCE_H /* - * BabelTrace - Source Plug-in Interface - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -34,13 +32,24 @@ extern "C" { #endif struct bt_component; +struct bt_component_source; +struct bt_port_output; + +static inline +struct bt_component *bt_component_source_borrow_component( + struct bt_component_source *component) +{ + return (void *) component; +} + +extern uint64_t bt_component_source_get_output_port_count( + struct bt_component_source *component); + +extern struct bt_port_output *bt_component_source_borrow_output_port_by_name( + struct bt_component_source *component, const char *name); -extern int64_t bt_component_source_get_output_port_count( - struct bt_component *component); -extern struct bt_port *bt_component_source_get_output_port_by_name( - struct bt_component *component, const char *name); -extern struct bt_port *bt_component_source_get_output_port_by_index( - struct bt_component *component, uint64_t index); +extern struct bt_port_output *bt_component_source_borrow_output_port_by_index( + struct bt_component_source *component, uint64_t index); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/component-status.h b/include/babeltrace/graph/component-status.h deleted file mode 100644 index fe1d59ab..00000000 --- a/include/babeltrace/graph/component-status.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef BABELTRACE_GRAPH_COMPONENT_STATUS_H -#define BABELTRACE_GRAPH_COMPONENT_STATUS_H - -/* - * BabelTrace - Babeltrace Component Interface - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Status code. Errors are always negative. - */ -enum bt_component_status { - /** No error, okay. */ - BT_COMPONENT_STATUS_OK = 0, - /** No more work to be done by this component. **/ - BT_COMPONENT_STATUS_END = 1, - /** - * Component can't process a notification at this time - * (e.g. would block), try again later. - */ - BT_COMPONENT_STATUS_AGAIN = 11, - /** Refuse port connection. */ - BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION = 111, - /** General error. */ - BT_COMPONENT_STATUS_ERROR = -1, - /** Unsupported component feature. */ - BT_COMPONENT_STATUS_UNSUPPORTED = -2, - /** Invalid arguments. */ - BT_COMPONENT_STATUS_INVALID = -22, - /** Memory allocation failure. */ - BT_COMPONENT_STATUS_NOMEM = -12, - /** Element not found. */ - BT_COMPONENT_STATUS_NOT_FOUND = -19, - BT_COMPONENT_STATUS_GRAPH_IS_CANCELED = 125, -}; - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_COMPONENT_STATUS_H */ diff --git a/include/babeltrace/graph/component.h b/include/babeltrace/graph/component.h index efcb9848..7edbc0c3 100644 --- a/include/babeltrace/graph/component.h +++ b/include/babeltrace/graph/component.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_COMPONENT_H /* - * BabelTrace - Babeltrace Component Interface - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -33,9 +31,6 @@ /* For bt_bool */ #include -/* For bt_object_get_ref */ -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/include/babeltrace/graph/connection-internal.h b/include/babeltrace/graph/connection-internal.h index 73fb1b02..98222c04 100644 --- a/include/babeltrace/graph/connection-internal.h +++ b/include/babeltrace/graph/connection-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_CONNECTION_INTERNAL_H /* - * BabelTrace - Component Connection Internal - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -30,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -60,17 +57,13 @@ struct bt_connection { GPtrArray *iterators; bool notified_upstream_port_connected; + bool notified_upstream_port_disconnected; bool notified_downstream_port_connected; + bool notified_downstream_port_disconnected; bool notified_graph_ports_connected; + bool notified_graph_ports_disconnected; }; -static inline -struct bt_private_connection *bt_private_connection_from_connection( - struct bt_connection *connection) -{ - return (void *) connection; -} - BT_HIDDEN struct bt_connection *bt_connection_create(struct bt_graph *graph, struct bt_port *upstream_port, @@ -81,7 +74,7 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph); BT_HIDDEN void bt_connection_remove_iterator(struct bt_connection *conn, - struct bt_notification_iterator_private_connection *iterator); + struct bt_self_component_port_input_notification_iterator *iterator); static inline struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn) @@ -90,56 +83,4 @@ struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn) return (void *) conn->base.parent; } -static inline -enum bt_connection_status -bt_connection_status_from_notification_iterator_status( - enum bt_notification_iterator_status iter_status) -{ - switch (iter_status) { - case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED: - return BT_CONNECTION_STATUS_ERROR; - case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - return BT_CONNECTION_STATUS_ERROR; - case BT_NOTIFICATION_ITERATOR_STATUS_END: - return BT_CONNECTION_STATUS_ERROR; - case BT_NOTIFICATION_ITERATOR_STATUS_OK: - return BT_CONNECTION_STATUS_OK; - case BT_NOTIFICATION_ITERATOR_STATUS_INVALID: - return BT_CONNECTION_STATUS_INVALID; - case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: - return BT_CONNECTION_STATUS_ERROR; - case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: - return BT_CONNECTION_STATUS_NOMEM; - case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED: - return BT_CONNECTION_STATUS_ERROR; - default: -#ifdef BT_LOGF - BT_LOGF("Unknown notification iterator status: status=%d", - iter_status); -#endif - abort(); - } -} - -static inline -const char *bt_connection_status_string(enum bt_connection_status status) -{ - switch (status) { - case BT_CONNECTION_STATUS_GRAPH_IS_CANCELED: - return "BT_CONNECTION_STATUS_GRAPH_IS_CANCELED"; - case BT_CONNECTION_STATUS_OK: - return "BT_CONNECTION_STATUS_OK"; - case BT_CONNECTION_STATUS_INVALID: - return "BT_CONNECTION_STATUS_INVALID"; - case BT_CONNECTION_STATUS_ERROR: - return "BT_CONNECTION_STATUS_ERROR"; - case BT_CONNECTION_STATUS_NOMEM: - return "BT_CONNECTION_STATUS_NOMEM"; - case BT_CONNECTION_STATUS_IS_ENDED: - return "BT_CONNECTION_STATUS_IS_ENDED"; - default: - return "(unknown)"; - } -} - #endif /* BABELTRACE_GRAPH_CONNECTION_INTERNAL_H */ diff --git a/include/babeltrace/graph/connection.h b/include/babeltrace/graph/connection.h index bf10eb5d..c49de371 100644 --- a/include/babeltrace/graph/connection.h +++ b/include/babeltrace/graph/connection.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_CONNECTION_H /* - * BabelTrace - Babeltrace Component Connection Interface - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -34,23 +32,14 @@ extern "C" { #endif -struct bt_component; +struct bt_port_input; +struct bt_port_output; struct bt_connection; -enum bt_connection_status { - BT_CONNECTION_STATUS_GRAPH_IS_CANCELED = 125, - BT_CONNECTION_STATUS_OK = 0, - BT_CONNECTION_STATUS_INVALID = -22, - BT_CONNECTION_STATUS_ERROR = -1, - BT_CONNECTION_STATUS_NOMEM = -12, - BT_CONNECTION_STATUS_IS_ENDED = 104, -}; - -/* Returns the "downstream" input port. */ -extern struct bt_port *bt_connection_get_downstream_port( +extern struct bt_port_input *bt_connection_borrow_downstream_port( struct bt_connection *connection); -/* Returns the "upstream" output port. */ -extern struct bt_port *bt_connection_get_upstream_port( + +extern struct bt_port_output *bt_connection_borrow_upstream_port( struct bt_connection *connection); extern bt_bool bt_connection_is_ended(struct bt_connection *connection); diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index 81b73676..80a661b4 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H /* - * BabelTrace - Component Graph Internal - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -29,7 +27,6 @@ #include #include -#include #include #include #include @@ -61,27 +58,37 @@ struct bt_graph { /* Queue of pointers (weak references) to sink bt_components. */ GQueue *sinks_to_consume; - bt_bool canceled; - bt_bool in_remove_listener; - bt_bool has_sink; + bool canceled; + bool in_remove_listener; + bool has_sink; /* - * If this is BT_FALSE, then the public API's consuming + * If this is false, then the public API's consuming * functions (bt_graph_consume() and bt_graph_run()) return * BT_GRAPH_STATUS_CANNOT_CONSUME. The internal "no check" * functions always work. * - * In bt_output_port_notification_iterator_create(), on success, + * In bt_port_output_notification_iterator_create(), on success, * this flag is cleared so that the iterator remains the only * consumer for the graph's lifetime. */ - bt_bool can_consume; + bool can_consume; struct { - GArray *port_added; - GArray *port_removed; - GArray *ports_connected; - GArray *ports_disconnected; + GArray *source_output_port_added; + GArray *filter_output_port_added; + GArray *filter_input_port_added; + GArray *sink_input_port_added; + GArray *source_output_port_removed; + GArray *filter_output_port_removed; + GArray *filter_input_port_removed; + GArray *sink_input_port_removed; + GArray *source_filter_ports_connected; + GArray *source_sink_ports_connected; + GArray *filter_sink_ports_connected; + GArray *source_filter_ports_disconnected; + GArray *source_sink_ports_disconnected; + GArray *filter_sink_ports_disconnected; } listeners; /* Pool of `struct bt_notification_event *` */ @@ -111,7 +118,7 @@ struct bt_graph { }; static inline -void _bt_graph_set_can_consume(struct bt_graph *graph, bt_bool can_consume) +void _bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume) { BT_ASSERT(graph); graph->can_consume = can_consume; @@ -125,7 +132,7 @@ void _bt_graph_set_can_consume(struct bt_graph *graph, bt_bool can_consume) BT_HIDDEN enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, - struct bt_component *sink); + struct bt_component_sink *sink); BT_HIDDEN void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port); @@ -177,8 +184,6 @@ const char *bt_graph_status_string(enum bt_graph_status status) return "BT_GRAPH_STATUS_END"; case BT_GRAPH_STATUS_OK: return "BT_GRAPH_STATUS_OK"; - case BT_GRAPH_STATUS_INVALID: - return "BT_GRAPH_STATUS_INVALID"; case BT_GRAPH_STATUS_NO_SINK: return "BT_GRAPH_STATUS_NO_SINK"; case BT_GRAPH_STATUS_ERROR: @@ -192,35 +197,4 @@ const char *bt_graph_status_string(enum bt_graph_status status) } } -static inline -enum bt_graph_status bt_graph_status_from_component_status( - enum bt_component_status comp_status) -{ - switch (comp_status) { - case BT_COMPONENT_STATUS_OK: - return BT_GRAPH_STATUS_OK; - case BT_COMPONENT_STATUS_END: - return BT_GRAPH_STATUS_END; - case BT_COMPONENT_STATUS_AGAIN: - return BT_GRAPH_STATUS_AGAIN; - case BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION: - return BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION; - case BT_COMPONENT_STATUS_ERROR: - return BT_GRAPH_STATUS_ERROR; - case BT_COMPONENT_STATUS_UNSUPPORTED: - return BT_GRAPH_STATUS_ERROR; - case BT_COMPONENT_STATUS_INVALID: - return BT_GRAPH_STATUS_INVALID; - case BT_COMPONENT_STATUS_NOMEM: - return BT_GRAPH_STATUS_NOMEM; - case BT_COMPONENT_STATUS_NOT_FOUND: - return BT_GRAPH_STATUS_ERROR; - default: -#ifdef BT_LOGF - BT_LOGF("Unknown component status: status=%d", comp_status); -#endif - abort(); - } -} - #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */ diff --git a/include/babeltrace/graph/graph.h b/include/babeltrace/graph/graph.h index f44bee7f..440fe58b 100644 --- a/include/babeltrace/graph/graph.h +++ b/include/babeltrace/graph/graph.h @@ -28,9 +28,6 @@ /* For bt_bool */ #include -/* For enum bt_component_status */ -#include - #ifdef __cplusplus extern "C" { #endif @@ -38,21 +35,14 @@ extern "C" { struct bt_graph; enum bt_graph_status { + BT_GRAPH_STATUS_OK = 0, + BT_GRAPH_STATUS_END = 1, + BT_GRAPH_STATUS_AGAIN = 11, BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111, - /** Canceled. */ - BT_GRAPH_STATUS_CANCELED = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED, - /** No sink can consume at the moment. */ - BT_GRAPH_STATUS_AGAIN = BT_COMPONENT_STATUS_AGAIN, - /** Downstream component does not support multiple inputs. */ - BT_GRAPH_STATUS_END = BT_COMPONENT_STATUS_END, - BT_GRAPH_STATUS_OK = BT_COMPONENT_STATUS_OK, - /** Invalid arguments. */ - BT_GRAPH_STATUS_INVALID = BT_COMPONENT_STATUS_INVALID, - /** No sink in graph. */ + BT_GRAPH_STATUS_CANCELED = 125, + BT_GRAPH_STATUS_ERROR = -1, BT_GRAPH_STATUS_NO_SINK = -6, - /** General error. */ - BT_GRAPH_STATUS_ERROR = BT_COMPONENT_STATUS_ERROR, - BT_GRAPH_STATUS_NOMEM = BT_COMPONENT_STATUS_NOMEM, + BT_GRAPH_STATUS_NOMEM = -12, }; extern bt_bool bt_graph_is_canceled(struct bt_graph *graph); diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index 2b401f20..8558f34b 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_EVENT_INTERNAL_H /* - * BabelTrace - Plug-in Event Notification internal - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/graph/notification-internal.h b/include/babeltrace/graph/notification-internal.h index 81f7d660..662ffdee 100644 --- a/include/babeltrace/graph/notification-internal.h +++ b/include/babeltrace/graph/notification-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_NOTIFICATION_INTERNAL_H /* - * BabelTrace - Plug-in Notification internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/graph/notification-iterator-internal.h b/include/babeltrace/graph/notification-iterator-internal.h index 2cfad159..28c3f8f4 100644 --- a/include/babeltrace/graph/notification-iterator-internal.h +++ b/include/babeltrace/graph/notification-iterator-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H /* - * BabelTrace - Notification Iterator Internal - * * Copyright 2015 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -31,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -40,33 +37,22 @@ struct bt_port; struct bt_graph; enum bt_notification_iterator_type { - BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION, - BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT, -}; - -enum bt_private_connection_notification_iterator_notif_type { - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_EVENT = (1U << 0), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_INACTIVITY = (1U << 1), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_BEGIN = (1U << 2), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_END = (1U << 3), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_BEGIN = (1U << 4), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END = (1U << 5), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_EVENTS = (1U << 6), - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_PACKETS = (1U << 7), + BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT, + BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT, }; -enum bt_private_connection_notification_iterator_state { +enum bt_self_component_port_input_notification_iterator_state { /* Iterator is not initialized. */ - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED, /* Iterator is active, not at the end yet, and not finalized. */ - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE, /* * Iterator is ended, not finalized yet: the "next" method * returns BT_NOTIFICATION_ITERATOR_STATUS_END. */ - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED, /* * Iterator is finalized, but not at the end yet. This means @@ -74,13 +60,13 @@ enum bt_private_connection_notification_iterator_state { * before returning the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED * status. */ - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED, /* * Iterator is finalized and ended: the "next" method always * returns BT_NOTIFICATION_ITERATOR_STATUS_CANCELED. */ - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED, }; struct bt_notification_iterator { @@ -89,7 +75,7 @@ struct bt_notification_iterator { GPtrArray *notifs; }; -struct bt_notification_iterator_private_connection { +struct bt_self_component_port_input_notification_iterator { struct bt_notification_iterator base; struct bt_component *upstream_component; /* Weak */ struct bt_port *upstream_port; /* Weak */ @@ -116,14 +102,14 @@ struct bt_notification_iterator_private_connection { */ GHashTable *stream_states; - enum bt_private_connection_notification_iterator_state state; + enum bt_self_component_port_input_notification_iterator_state state; void *user_data; }; -struct bt_notification_iterator_output_port { +struct bt_port_output_notification_iterator { struct bt_notification_iterator base; struct bt_graph *graph; /* Owned by this */ - struct bt_component *colander; /* Owned by this */ + struct bt_component_sink *colander; /* Owned by this */ /* * Only used temporarily as a bridge between a colander sink and @@ -132,28 +118,13 @@ struct bt_notification_iterator_output_port { uint64_t count; }; -static inline -struct bt_private_connection_private_notification_iterator * -bt_private_connection_private_notification_iterator_from_notification_iterator( - struct bt_notification_iterator_private_connection *iterator) -{ - return (void *) iterator; -} - -BT_HIDDEN -enum bt_connection_status bt_private_connection_notification_iterator_create( - struct bt_component *upstream_comp, - struct bt_port *upstream_port, - struct bt_connection *connection, - struct bt_notification_iterator_private_connection **iterator); - BT_HIDDEN -void bt_private_connection_notification_iterator_finalize( - struct bt_notification_iterator_private_connection *iterator); +void bt_self_component_port_input_notification_iterator_finalize( + struct bt_self_component_port_input_notification_iterator *iterator); BT_HIDDEN -void bt_private_connection_notification_iterator_set_connection( - struct bt_notification_iterator_private_connection *iterator, +void bt_self_component_port_input_notification_iterator_set_connection( + struct bt_self_component_port_input_notification_iterator *iterator, struct bt_connection *connection); static inline @@ -169,32 +140,28 @@ const char *bt_notification_iterator_status_string( return "BT_NOTIFICATION_ITERATOR_STATUS_END"; case BT_NOTIFICATION_ITERATOR_STATUS_OK: return "BT_NOTIFICATION_ITERATOR_STATUS_OK"; - case BT_NOTIFICATION_ITERATOR_STATUS_INVALID: - return "BT_NOTIFICATION_ITERATOR_STATUS_INVALID"; case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: return "BT_NOTIFICATION_ITERATOR_STATUS_ERROR"; case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: return "BT_NOTIFICATION_ITERATOR_STATUS_NOMEM"; - case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED: - return "BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED"; default: return "(unknown)"; } }; static inline -const char *bt_private_connection_notification_iterator_state_string( - enum bt_private_connection_notification_iterator_state state) +const char *bt_self_component_port_input_notification_iterator_state_string( + enum bt_self_component_port_input_notification_iterator_state state) { switch (state) { - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE: - return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE"; - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED: - return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED"; - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED: - return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED"; - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: - return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"; + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE: + return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE"; + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED: + return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED"; + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED: + return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED"; + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: + return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"; default: return "(unknown)"; } diff --git a/include/babeltrace/graph/notification-iterator.h b/include/babeltrace/graph/notification-iterator.h index dc6f8706..9389b60a 100644 --- a/include/babeltrace/graph/notification-iterator.h +++ b/include/babeltrace/graph/notification-iterator.h @@ -32,26 +32,13 @@ extern "C" { struct bt_notification; struct bt_notification_iterator; -/** - * Status code. Errors are always negative. - */ enum bt_notification_iterator_status { - /** Canceled. */ - BT_NOTIFICATION_ITERATOR_STATUS_CANCELED = 125, - /** No notifications available for now. Try again later. */ - BT_NOTIFICATION_ITERATOR_STATUS_AGAIN = 11, - /** No more notifications to be delivered. */ - BT_NOTIFICATION_ITERATOR_STATUS_END = 1, - /** No error, okay. */ BT_NOTIFICATION_ITERATOR_STATUS_OK = 0, - /** Invalid arguments. */ - BT_NOTIFICATION_ITERATOR_STATUS_INVALID = -22, - /** General error. */ + BT_NOTIFICATION_ITERATOR_STATUS_END = 1, + BT_NOTIFICATION_ITERATOR_STATUS_AGAIN = 11, + BT_NOTIFICATION_ITERATOR_STATUS_CANCELED = 125, BT_NOTIFICATION_ITERATOR_STATUS_ERROR = -1, - /** Out of memory. */ BT_NOTIFICATION_ITERATOR_STATUS_NOMEM = -12, - /** Unsupported iterator feature. */ - BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED = -2, }; #ifdef __cplusplus diff --git a/include/babeltrace/graph/notification-packet-internal.h b/include/babeltrace/graph/notification-packet-internal.h index 18f6db95..77cdf979 100644 --- a/include/babeltrace/graph/notification-packet-internal.h +++ b/include/babeltrace/graph/notification-packet-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_PACKET_INTERNAL_H /* - * BabelTrace - Packet-related Notifications - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/graph/notification-stream-internal.h b/include/babeltrace/graph/notification-stream-internal.h index 818fc431..4b4e0c7c 100644 --- a/include/babeltrace/graph/notification-stream-internal.h +++ b/include/babeltrace/graph/notification-stream-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_STREAM_INTERNAL_H /* - * BabelTrace - Stream-related Notifications - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/graph/notification-stream.h b/include/babeltrace/graph/notification-stream.h index 4283e32f..d4a97dc3 100644 --- a/include/babeltrace/graph/notification-stream.h +++ b/include/babeltrace/graph/notification-stream.h @@ -30,7 +30,7 @@ extern "C" { #endif struct bt_notification; -struct bt_private_connection_private_notification_iterator; +struct bt_self_notification_iterator; struct bt_clock_value; struct bt_stream; diff --git a/include/babeltrace/graph/notification.h b/include/babeltrace/graph/notification.h index 198485b4..ba3d2357 100644 --- a/include/babeltrace/graph/notification.h +++ b/include/babeltrace/graph/notification.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_NOTIFICATION_H /* - * BabelTrace - Plug-in Notification - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/graph/output-port-notification-iterator.h b/include/babeltrace/graph/output-port-notification-iterator.h deleted file mode 100644 index ab6c7e4f..00000000 --- a/include/babeltrace/graph/output-port-notification-iterator.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef BABELTRACE_GRAPH_OUTPUT_PORT_NOTIFICATION_ITERATOR_H -#define BABELTRACE_GRAPH_OUTPUT_PORT_NOTIFICATION_ITERATOR_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* For enum bt_notification_iterator_status */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_port; -struct bt_notification; -struct bt_notification_iterator; - -extern struct bt_notification_iterator *bt_output_port_notification_iterator_create( - struct bt_port *port, const char *colander_component_name); - -extern enum bt_notification_iterator_status -bt_output_port_notification_iterator_next( - struct bt_notification_iterator *iterator, - bt_notification_array *notifs, uint64_t *count); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_OUTPUT_PORT_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/graph/port-input.h b/include/babeltrace/graph/port-input.h new file mode 100644 index 00000000..b57e15df --- /dev/null +++ b/include/babeltrace/graph/port-input.h @@ -0,0 +1,47 @@ +#ifndef BABELTRACE_GRAPH_PORT_INPUT_H +#define BABELTRACE_GRAPH_PORT_INPUT_H + +/* + * Copyright 2017 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port; +struct bt_port_input; + +static inline +struct bt_port *bt_port_input_borrow_port(struct bt_port_input *port_input) +{ + return (void *) port_input; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PORT_INPUT_H */ diff --git a/include/babeltrace/graph/port-internal.h b/include/babeltrace/graph/port-internal.h index 57f817ee..2a681dda 100644 --- a/include/babeltrace/graph/port-internal.h +++ b/include/babeltrace/graph/port-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_PORT_INTERNAL_H /* - * BabelTrace - Babeltrace Component Port - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -37,13 +35,6 @@ struct bt_port { void *user_data; }; -static inline -struct bt_private_port *bt_private_port_from_port( - struct bt_port *port) -{ - return (void *) port; -} - BT_HIDDEN struct bt_port *bt_port_create(struct bt_component *parent_component, enum bt_port_type type, const char *name, void *user_data); @@ -60,8 +51,6 @@ const char *bt_port_type_string(enum bt_port_type port_type) return "BT_PORT_TYPE_INPUT"; case BT_PORT_TYPE_OUTPUT: return "BT_PORT_TYPE_OUTPUT"; - case BT_PORT_TYPE_UNKOWN: - return "BT_PORT_TYPE_UNKOWN"; default: return "(unknown)"; } diff --git a/include/babeltrace/graph/port-output-notification-iterator.h b/include/babeltrace/graph/port-output-notification-iterator.h new file mode 100644 index 00000000..2dd0bf22 --- /dev/null +++ b/include/babeltrace/graph/port-output-notification-iterator.h @@ -0,0 +1,67 @@ +#ifndef BABELTRACE_GRAPH_PORT_OUTPUT_NOTIFICATION_ITERATOR_H +#define BABELTRACE_GRAPH_PORT_OUTPUT_NOTIFICATION_ITERATOR_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_notification_iterator_status */ +#include + +/* For bt_notification_array */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port; +struct bt_notification; +struct bt_notification_iterator; +struct bt_port_output_notification_iterator; +struct bt_private_graph; +struct bt_port_output; + +static inline +struct bt_notification_iterator * +bt_port_output_notification_iterator_borrow_notification_iterator( + struct bt_port_output_notification_iterator *iterator) +{ + return (void *) iterator; +} + +extern struct bt_port_output_notification_iterator *bt_port_output_notification_iterator_create( + struct bt_private_graph *graph, + struct bt_port_output *output_port, + const char *colander_component_name); + +extern enum bt_notification_iterator_status +bt_port_output_notification_iterator_next( + struct bt_port_output_notification_iterator *iterator, + bt_notification_array *notifs, uint64_t *count); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PORT_OUTPUT_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/graph/port-output.h b/include/babeltrace/graph/port-output.h new file mode 100644 index 00000000..f27310d9 --- /dev/null +++ b/include/babeltrace/graph/port-output.h @@ -0,0 +1,47 @@ +#ifndef BABELTRACE_GRAPH_PORT_OUTPUT_H +#define BABELTRACE_GRAPH_PORT_OUTPUT_H + +/* + * Copyright 2017 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port; +struct bt_port_output; + +static inline +struct bt_port *bt_port_output_borrow_port(struct bt_port_output *port_output) +{ + return (void *) port_output; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PORT_OUTPUT_H */ diff --git a/include/babeltrace/graph/port.h b/include/babeltrace/graph/port.h index 63b057a4..c70ca5e0 100644 --- a/include/babeltrace/graph/port.h +++ b/include/babeltrace/graph/port.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_PORT_H /* - * BabelTrace - Babeltrace Component Connection Interface - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -38,24 +36,21 @@ extern "C" { struct bt_port; struct bt_connection; - -enum bt_port_status { - BT_PORT_STATUS_OK = 0, - BT_PORT_STATUS_ERROR = -1, - BT_PORT_STATUS_INVALID = -2, -}; +struct bt_component; enum bt_port_type { BT_PORT_TYPE_INPUT = 0, BT_PORT_TYPE_OUTPUT = 1, - BT_PORT_TYPE_UNKOWN = -1, }; extern const char *bt_port_get_name(struct bt_port *port); + extern enum bt_port_type bt_port_get_type(struct bt_port *port); -extern struct bt_connection *bt_port_get_connection(struct bt_port *port); -extern struct bt_component *bt_port_get_component(struct bt_port *port); -extern enum bt_port_status bt_port_disconnect(struct bt_port *port); + +extern struct bt_connection *bt_port_borrow_connection(struct bt_port *port); + +extern struct bt_component *bt_port_borrow_component(struct bt_port *port); + extern bt_bool bt_port_is_connected(struct bt_port *port); static inline diff --git a/include/babeltrace/graph/private-component-class-filter.h b/include/babeltrace/graph/private-component-class-filter.h new file mode 100644 index 00000000..663fad64 --- /dev/null +++ b/include/babeltrace/graph/private-component-class-filter.h @@ -0,0 +1,194 @@ +#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_FILTER_H +#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_FILTER_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_notification_array */ +#include + +/* For enum bt_self_component_status */ +#include + +/* For enum bt_query_status */ +#include + +/* For enum bt_self_notification_iterator_status */ +#include + +/* For struct bt_private_component_class_query_method_return */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_self_component_class_filter; +struct bt_component_class_filter; +struct bt_self_component_filter; +struct bt_private_component_class; +struct bt_private_component_class_filter; +struct bt_self_component_port_input; +struct bt_self_component_port_output; +struct bt_port_input; +struct bt_port_output; +struct bt_query_executor; +struct bt_value; + +typedef enum bt_self_component_status +(*bt_private_component_class_filter_init_method)( + struct bt_self_component_filter *self_component, + struct bt_value *params, void *init_method_data); + +typedef void (*bt_private_component_class_filter_finalize_method)( + struct bt_self_component_filter *self_component); + +typedef enum bt_self_notification_iterator_status +(*bt_private_component_class_filter_notification_iterator_init_method)( + struct bt_self_notification_iterator *notification_iterator, + struct bt_self_component_filter *self_component, + struct bt_self_component_port_output *port); + +typedef void +(*bt_private_component_class_filter_notification_iterator_finalize_method)( + struct bt_self_notification_iterator *notification_iterator); + +typedef enum bt_self_notification_iterator_status +(*bt_private_component_class_filter_notification_iterator_next_method)( + struct bt_self_notification_iterator *notification_iterator, + bt_notification_array notifs, uint64_t capacity, + uint64_t *count); + +typedef enum bt_query_status +(*bt_private_component_class_filter_query_method)( + struct bt_self_component_class_filter *comp_class, + struct bt_query_executor *query_executor, + const char *object, struct bt_value *params, + struct bt_value **result); + +typedef enum bt_self_component_status +(*bt_private_component_class_filter_accept_input_port_connection_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_filter_accept_output_port_connection_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_output *self_port, + struct bt_port_input *other_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_filter_input_port_connected_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_filter_output_port_connected_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_output *self_port, + struct bt_port_input *other_port); + +typedef void +(*bt_private_component_class_filter_input_port_disconnected_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_input *self_port); + +typedef void +(*bt_private_component_class_filter_output_port_disconnected_method)( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_output *self_port); + +static inline +struct bt_private_component_class * +bt_private_component_class_filter_borrow_private_component_class( + struct bt_private_component_class_filter *priv_comp_cls_filter) +{ + return (void *) priv_comp_cls_filter; +} + +static inline +struct bt_component_class_filter * +bt_private_component_class_filter_borrow_component_class_filter( + struct bt_private_component_class_filter *priv_comp_cls_filter) +{ + return (void *) priv_comp_cls_filter; +} + +extern +struct bt_private_component_class_filter * +bt_private_component_class_filter_create( + const char *name, + bt_private_component_class_filter_notification_iterator_next_method method); + +extern int bt_private_component_class_filter_set_init_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_init_method method); + +extern int bt_private_component_class_filter_set_finalize_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_finalize_method method); + +extern int bt_private_component_class_filter_set_accept_input_port_connection_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_accept_input_port_connection_method method); + +extern int bt_private_component_class_filter_set_accept_output_port_connection_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_accept_output_port_connection_method method); + +extern int bt_private_component_class_filter_set_input_port_connected_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_input_port_connected_method method); + +extern int bt_private_component_class_filter_set_output_port_connected_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_output_port_connected_method method); + +extern int bt_private_component_class_filter_set_input_port_disconnected_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_input_port_disconnected_method method); + +extern int bt_private_component_class_filter_set_output_port_disconnected_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_output_port_disconnected_method method); + +extern int bt_private_component_class_filter_set_query_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_query_method method); + +extern int bt_private_component_class_filter_set_notification_iterator_init_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_notification_iterator_init_method method); + +extern int bt_private_component_class_filter_set_notification_iterator_finalize_method( + struct bt_private_component_class_filter *comp_class, + bt_private_component_class_filter_notification_iterator_finalize_method method); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_FILTER_H */ diff --git a/include/babeltrace/graph/private-component-class-sink.h b/include/babeltrace/graph/private-component-class-sink.h new file mode 100644 index 00000000..f29701e5 --- /dev/null +++ b/include/babeltrace/graph/private-component-class-sink.h @@ -0,0 +1,139 @@ +#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SINK_H +#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SINK_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_notification_array */ +#include + +/* For enum bt_self_component_status */ +#include + +/* For enum bt_query_status */ +#include + +/* For struct bt_private_component_class_query_method_return */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_self_component_class_sink; +struct bt_component_class_sink; +struct bt_self_component_sink; +struct bt_private_component_class; +struct bt_private_component_class_sink; +struct bt_self_component_port_input; +struct bt_port_output; +struct bt_query_executor; +struct bt_value; + +typedef enum bt_self_component_status +(*bt_private_component_class_sink_init_method)( + struct bt_self_component_sink *self_component, + struct bt_value *params, void *init_method_data); + +typedef void (*bt_private_component_class_sink_finalize_method)( + struct bt_self_component_sink *self_component); + +typedef enum bt_query_status +(*bt_private_component_class_sink_query_method)( + struct bt_self_component_class_sink *comp_class, + struct bt_query_executor *query_executor, + const char *object, struct bt_value *params, + struct bt_value **result); + +typedef enum bt_self_component_status +(*bt_private_component_class_sink_accept_input_port_connection_method)( + struct bt_self_component_sink *self_component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_sink_input_port_connected_method)( + struct bt_self_component_sink *self_component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +typedef void +(*bt_private_component_class_sink_input_port_disconnected_method)( + struct bt_self_component_sink *self_component, + struct bt_self_component_port_input *self_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_sink_consume_method)( + struct bt_self_component_sink *self_component); + +static inline +struct bt_private_component_class * +bt_private_component_class_sink_borrow_private_component_class( + struct bt_private_component_class_sink *priv_comp_cls_sink) +{ + return (void *) priv_comp_cls_sink; +} + +static inline +struct bt_component_class_sink * +bt_private_component_class_sink_borrow_component_class_sink( + struct bt_private_component_class_sink *priv_comp_cls_sink) +{ + return (void *) priv_comp_cls_sink; +} + +extern +struct bt_private_component_class_sink *bt_private_component_class_sink_create( + const char *name, + bt_private_component_class_sink_consume_method method); + +extern int bt_private_component_class_sink_set_init_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_init_method method); + +extern int bt_private_component_class_sink_set_finalize_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_finalize_method method); + +extern int bt_private_component_class_sink_set_accept_input_port_connection_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_accept_input_port_connection_method method); + +extern int bt_private_component_class_sink_set_input_port_connected_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_input_port_connected_method method); + +extern int bt_private_component_class_sink_set_input_port_disconnected_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_input_port_disconnected_method method); + +extern int bt_private_component_class_sink_set_query_method( + struct bt_private_component_class_sink *comp_class, + bt_private_component_class_sink_query_method method); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SINK_H */ diff --git a/include/babeltrace/graph/private-component-class-source.h b/include/babeltrace/graph/private-component-class-source.h new file mode 100644 index 00000000..9c89c9b1 --- /dev/null +++ b/include/babeltrace/graph/private-component-class-source.h @@ -0,0 +1,163 @@ +#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SOURCE_H +#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SOURCE_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_notification_array */ +#include + +/* For enum bt_self_component_status */ +#include + +/* For enum bt_query_status */ +#include + +/* For enum bt_self_notification_iterator_status */ +#include + +/* For struct bt_private_component_class_query_method_return */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_self_component_class_source; +struct bt_component_class_source; +struct bt_self_component_source; +struct bt_private_component_class; +struct bt_private_component_class_source; +struct bt_self_component_port_output; +struct bt_port_input; +struct bt_query_executor; +struct bt_value; + +typedef enum bt_self_component_status +(*bt_private_component_class_source_init_method)( + struct bt_self_component_source *self_component, + struct bt_value *params, void *init_method_data); + +typedef void (*bt_private_component_class_source_finalize_method)( + struct bt_self_component_source *self_component); + +typedef enum bt_self_notification_iterator_status +(*bt_private_component_class_source_notification_iterator_init_method)( + struct bt_self_notification_iterator *notification_iterator, + struct bt_self_component_source *self_component, + struct bt_self_component_port_output *port); + +typedef void +(*bt_private_component_class_source_notification_iterator_finalize_method)( + struct bt_self_notification_iterator *notification_iterator); + +typedef enum bt_self_notification_iterator_status +(*bt_private_component_class_source_notification_iterator_next_method)( + struct bt_self_notification_iterator *notification_iterator, + bt_notification_array notifs, uint64_t capacity, + uint64_t *count); + +typedef enum bt_query_status +(*bt_private_component_class_source_query_method)( + struct bt_self_component_class_source *comp_class, + struct bt_query_executor *query_executor, + const char *object, struct bt_value *params, + struct bt_value **result); + +typedef enum bt_self_component_status +(*bt_private_component_class_source_accept_output_port_connection_method)( + struct bt_self_component_source *self_component, + struct bt_self_component_port_output *self_port, + struct bt_port_input *other_port); + +typedef enum bt_self_component_status +(*bt_private_component_class_source_output_port_connected_method)( + struct bt_self_component_source *self_component, + struct bt_self_component_port_output *self_port, + struct bt_port_input *other_port); + +typedef void +(*bt_private_component_class_source_output_port_disconnected_method)( + struct bt_self_component_source *self_component, + struct bt_self_component_port_output *self_port); + +static inline +struct bt_private_component_class * +bt_private_component_class_source_borrow_private_component_class( + struct bt_private_component_class_source *priv_comp_cls_source) +{ + return (void *) priv_comp_cls_source; +} + +static inline +struct bt_component_class_source * +bt_private_component_class_source_borrow_component_class_source( + struct bt_private_component_class_source *priv_comp_cls_source) +{ + return (void *) priv_comp_cls_source; +} + +extern +struct bt_private_component_class_source * +bt_private_component_class_source_create( + const char *name, + bt_private_component_class_source_notification_iterator_next_method method); + +extern int bt_private_component_class_source_set_init_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_init_method method); + +extern int bt_private_component_class_source_set_finalize_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_finalize_method method); + +extern int bt_private_component_class_source_set_accept_output_port_connection_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_accept_output_port_connection_method method); + +extern int bt_private_component_class_source_set_output_port_connected_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_output_port_connected_method method); + +extern int bt_private_component_class_source_set_output_port_disconnected_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_output_port_disconnected_method method); + +extern int bt_private_component_class_source_set_query_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_query_method method); + +extern int bt_private_component_class_source_set_notification_iterator_init_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_notification_iterator_init_method method); + +extern int bt_private_component_class_source_set_notification_iterator_finalize_method( + struct bt_private_component_class_source *comp_class, + bt_private_component_class_source_notification_iterator_finalize_method method); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_SOURCE_H */ diff --git a/include/babeltrace/graph/private-component-class.h b/include/babeltrace/graph/private-component-class.h new file mode 100644 index 00000000..a39a6b1f --- /dev/null +++ b/include/babeltrace/graph/private-component-class.h @@ -0,0 +1,56 @@ +#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_H +#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* For enum bt_query_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class; +struct bt_private_component_class; + +static inline +struct bt_component_class * +bt_private_component_class_borrow_component_class( + struct bt_private_component_class *priv_comp_cls) +{ + return (void *) priv_comp_cls; +} + +extern int bt_private_component_class_set_description( + struct bt_private_component_class *component_class, + const char *description); + +extern int bt_private_component_class_set_help( + struct bt_private_component_class *component_class, + const char *help); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_CLASS_H */ diff --git a/include/babeltrace/graph/private-component-filter.h b/include/babeltrace/graph/private-component-filter.h deleted file mode 100644 index 9b1de8cd..00000000 --- a/include/babeltrace/graph/private-component-filter.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_FILTER_H -#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_FILTER_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -/* For enum bt_component_status */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_component; -struct bt_private_component; -struct bt_private_port; - -extern struct bt_private_port * -bt_private_component_filter_get_output_port_by_name( - struct bt_private_component *private_component, - const char *name); - -extern struct bt_private_port * -bt_private_component_filter_get_output_port_by_index( - struct bt_private_component *private_component, uint64_t index); - -extern enum bt_component_status -bt_private_component_filter_add_output_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **private_port); - -extern struct bt_private_port * -bt_private_component_filter_get_input_port_by_name( - struct bt_private_component *private_component, - const char *name); - -extern struct bt_private_port * -bt_private_component_filter_get_input_port_by_index( - struct bt_private_component *private_component, uint64_t index); - -extern enum bt_component_status -bt_private_component_filter_add_input_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **private_port); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_FILTER_H */ diff --git a/include/babeltrace/graph/private-component-sink.h b/include/babeltrace/graph/private-component-sink.h deleted file mode 100644 index ba7b2907..00000000 --- a/include/babeltrace/graph/private-component-sink.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_SINK_H -#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_SINK_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -/* For enum bt_component_status */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_component; -struct bt_private_component; -struct bt_private_port; - -extern struct bt_private_port * -bt_private_component_sink_get_input_port_by_name( - struct bt_private_component *private_component, - const char *name); - -extern struct bt_private_port * -bt_private_component_sink_get_input_port_by_index( - struct bt_private_component *private_component, uint64_t index); - -extern enum bt_component_status -bt_private_component_sink_add_input_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **private_port); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_SINK_H */ diff --git a/include/babeltrace/graph/private-component-source.h b/include/babeltrace/graph/private-component-source.h deleted file mode 100644 index 0f4f41fc..00000000 --- a/include/babeltrace/graph/private-component-source.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_SOURCE_H -#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_SOURCE_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -/* For enum bt_component_status */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_component; -struct bt_private_component; -struct bt_private_port; - -extern struct bt_private_port * -bt_private_component_source_get_output_port_by_name( - struct bt_private_component *private_component, - const char *name); - -extern struct bt_private_port * -bt_private_component_source_get_output_port_by_index( - struct bt_private_component *private_component, - uint64_t index); - -extern enum bt_component_status -bt_private_component_source_add_output_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **private_port); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_SOURCE_H */ diff --git a/include/babeltrace/graph/private-component.h b/include/babeltrace/graph/private-component.h deleted file mode 100644 index f2663011..00000000 --- a/include/babeltrace/graph/private-component.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_COMPONENT_H -#define BABELTRACE_GRAPH_PRIVATE_COMPONENT_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_component; -struct bt_private_component; - -extern struct bt_component *bt_component_borrow_from_private( - struct bt_private_component *private_component); - -extern void *bt_private_component_get_user_data( - struct bt_private_component *private_component); - -extern enum bt_component_status bt_private_component_set_user_data( - struct bt_private_component *private_component, - void *user_data); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_COMPONENT_H */ diff --git a/include/babeltrace/graph/private-connection-notification-iterator.h b/include/babeltrace/graph/private-connection-notification-iterator.h deleted file mode 100644 index 46e6d137..00000000 --- a/include/babeltrace/graph/private-connection-notification-iterator.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_H -#define BABELTRACE_GRAPH_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* For enum bt_notification_iterator_status */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_component; -struct bt_notification; -struct bt_notification_iterator; - -extern struct bt_component *bt_private_connection_notification_iterator_get_component( - struct bt_notification_iterator *iterator); - -extern enum bt_notification_iterator_status -bt_private_connection_notification_iterator_next( - struct bt_notification_iterator *iterator, - bt_notification_array *notifs, uint64_t *count); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/graph/private-connection-private-notification-iterator.h b/include/babeltrace/graph/private-connection-private-notification-iterator.h deleted file mode 100644 index 339cf80c..00000000 --- a/include/babeltrace/graph/private-connection-private-notification-iterator.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_CONNECTION_PRIVATE_NOTIFICATION_ITERATOR_H -#define BABELTRACE_GRAPH_PRIVATE_CONNECTION_PRIVATE_NOTIFICATION_ITERATOR_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_connection; -struct bt_private_port; -struct bt_private_connection; -struct bt_private_connection_private_notification_iterator; - -extern struct bt_notification_iterator * -bt_private_connection_notification_iterator_borrow_from_private( - struct bt_private_connection_private_notification_iterator *private_notification_iterator); - -extern struct bt_private_component * -bt_private_connection_private_notification_iterator_get_private_component( - struct bt_private_connection_private_notification_iterator *private_notification_iterator); - -extern enum bt_notification_iterator_status -bt_private_connection_private_notification_iterator_set_user_data( - struct bt_private_connection_private_notification_iterator *private_notification_iterator, - void *user_data); - -extern void *bt_private_connection_private_notification_iterator_get_user_data( - struct bt_private_connection_private_notification_iterator *private_notification_iterator); - -extern struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph( - struct bt_private_connection_private_notification_iterator *private_notification_iterator); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_CONNECTION_PRIVATE_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/graph/private-connection.h b/include/babeltrace/graph/private-connection.h deleted file mode 100644 index c3692361..00000000 --- a/include/babeltrace/graph/private-connection.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_CONNECTION_H -#define BABELTRACE_GRAPH_PRIVATE_CONNECTION_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* For enum bt_notification_type */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_notification; -struct bt_connection; -struct bt_private_port; -struct bt_private_connection; -struct bt_notification_iterator; - -extern struct bt_connection *bt_connection_borrow_from_private( - struct bt_private_connection *private_connection); - -extern enum bt_connection_status -bt_private_connection_create_notification_iterator( - struct bt_private_connection *private_connection, - struct bt_notification_iterator **iterator); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_CONNECTION_H */ diff --git a/include/babeltrace/graph/private-graph.h b/include/babeltrace/graph/private-graph.h index 4a1fe1a0..08c31c55 100644 --- a/include/babeltrace/graph/private-graph.h +++ b/include/babeltrace/graph/private-graph.h @@ -37,94 +37,245 @@ extern "C" { struct bt_graph; struct bt_private_graph; -struct bt_port; +struct bt_port_input; +struct bt_port_output; struct bt_connection; struct bt_component; +struct bt_component_source; +struct bt_component_filter; +struct bt_component_sink; struct bt_component_class; struct bt_value; -typedef void (*bt_private_graph_port_added_listener)(struct bt_port *port, - void *data); +typedef void (*bt_private_graph_filter_component_input_port_added_listener)( + struct bt_component_filter *component, + struct bt_port_input *port, void *data); + +typedef void (*bt_private_graph_sink_component_input_port_added_listener)( + struct bt_component_sink *component, + struct bt_port_input *port, void *data); + +typedef void (*bt_private_graph_source_component_output_port_added_listener)( + struct bt_component_source *component, + struct bt_port_output *port, void *data); + +typedef void (*bt_private_graph_filter_component_output_port_added_listener)( + struct bt_component_filter *component, + struct bt_port_output *port, void *data); + +typedef void (*bt_private_graph_filter_component_input_port_removed_listener)( + struct bt_component_filter *component, + struct bt_port_input *port, void *data); + +typedef void (*bt_private_graph_sink_component_input_port_removed_listener)( + struct bt_component_sink *component, + struct bt_port_input *port, void *data); + +typedef void (*bt_private_graph_source_component_output_port_removed_listener)( + struct bt_component_source *component, + struct bt_port_output *port, void *data); + +typedef void (*bt_private_graph_filter_component_output_port_removed_listener)( + struct bt_component_filter *component, + struct bt_port_output *port, void *data); + +typedef void (*bt_private_graph_source_filter_component_ports_connected_listener)( + struct bt_component_source *source_component, + struct bt_component_filter *filter_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data); -typedef void (*bt_private_graph_port_removed_listener)( - struct bt_component *component, - struct bt_port *port, void *data); +typedef void (*bt_private_graph_source_sink_component_ports_connected_listener)( + struct bt_component_source *source_component, + struct bt_component_sink *sink_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data); -typedef void (*bt_private_graph_ports_connected_listener)( - struct bt_port *upstream_port, - struct bt_port *downstream_port, void *data); +typedef void (*bt_private_graph_filter_sink_component_ports_connected_listener)( + struct bt_component_filter *filter_component, + struct bt_component_sink *sink_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data); -typedef void (*bt_private_graph_ports_disconnected_listener)( - struct bt_component *upstream_component, - struct bt_component *downstream_component, - struct bt_port *upstream_port, struct bt_port *downstream_port, +typedef void (*bt_private_graph_source_filter_component_ports_disconnected_listener)( + struct bt_component_source *source_component, + struct bt_component_filter *filter_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, + void *data); + +typedef void (*bt_private_graph_source_sink_component_ports_disconnected_listener)( + struct bt_component_source *source_component, + struct bt_component_sink *sink_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, + void *data); + +typedef void (*bt_private_graph_filter_sink_component_ports_disconnected_listener)( + struct bt_component_filter *filter_component, + struct bt_component_sink *sink_component, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data); typedef void (* bt_private_graph_listener_removed)(void *data); -extern struct bt_graph *bt_graph_borrow_from_private( - struct bt_private_graph *priv_graph); +static inline +struct bt_graph *bt_private_graph_borrow_graph(struct bt_private_graph *graph) +{ + return (void *) graph; +} extern struct bt_private_graph *bt_private_graph_create(void); -extern enum bt_graph_status bt_private_graph_add_component( +extern enum bt_graph_status bt_private_graph_add_source_component( struct bt_private_graph *graph, - struct bt_component_class *component_class, + struct bt_component_class_source *component_class, const char *name, struct bt_value *params, - struct bt_component **component); + struct bt_component_source **component); extern enum bt_graph_status -bt_private_graph_add_component_with_init_method_data( +bt_private_graph_add_source_component_with_init_method_data( struct bt_private_graph *graph, - struct bt_component_class *component_class, + struct bt_component_class_source *component_class, const char *name, struct bt_value *params, - void *init_method_data, struct bt_component **component); + void *init_method_data, struct bt_component_source **component); + +extern enum bt_graph_status bt_private_graph_add_filter_component( + struct bt_private_graph *graph, + struct bt_component_class_filter *component_class, + const char *name, struct bt_value *params, + struct bt_component_filter **component); + +extern enum bt_graph_status +bt_private_graph_add_filter_component_with_init_method_data( + struct bt_private_graph *graph, + struct bt_component_class_filter *component_class, + const char *name, struct bt_value *params, + void *init_method_data, struct bt_component_filter **component); + +extern enum bt_graph_status bt_private_graph_add_sink_component( + struct bt_private_graph *graph, + struct bt_component_class_sink *component_class, + const char *name, struct bt_value *params, + struct bt_component_sink **component); + +extern enum bt_graph_status +bt_private_graph_add_sink_component_with_init_method_data( + struct bt_private_graph *graph, + struct bt_component_class_sink *component_class, + const char *name, struct bt_value *params, + void *init_method_data, struct bt_component_sink **component); -/** - * Creates a connection between two components using the two ports specified - * and adds the connection and components (if not already added) to the graph. - */ extern enum bt_graph_status bt_private_graph_connect_ports( struct bt_private_graph *graph, - struct bt_port *upstream, struct bt_port *downstream, + struct bt_port_output *upstream, + struct bt_port_input *downstream, struct bt_connection **connection); -/** - * Run graph to completion or until a single sink is left and "AGAIN" is received. - * - * Runs "bt_component_sink_consume()" on all sinks in round-robin until they all - * indicate that the end is reached or that an error occured. - */ extern enum bt_graph_status bt_private_graph_run( struct bt_private_graph *graph); -/** - * Runs "bt_component_sink_consume()" on the graph's sinks. Each invokation will - * invoke "bt_component_sink_consume()" on the next sink, in round-robin, until - * they all indicated that the end is reached. - */ extern enum bt_graph_status bt_private_graph_consume( struct bt_private_graph *graph); -extern int bt_private_graph_add_port_added_listener( +extern enum bt_graph_status +bt_private_graph_add_filter_component_input_port_added_listener( + struct bt_private_graph *graph, + bt_private_graph_filter_component_input_port_added_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_sink_component_input_port_added_listener( struct bt_private_graph *graph, - bt_private_graph_port_added_listener listener, - bt_private_graph_listener_removed listener_removed, void *data); + bt_private_graph_sink_component_input_port_added_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); -extern int bt_private_graph_add_port_removed_listener( +extern enum bt_graph_status +bt_private_graph_add_source_component_output_port_added_listener( struct bt_private_graph *graph, - bt_private_graph_port_removed_listener listener, - bt_private_graph_listener_removed listener_removed, void *data); + bt_private_graph_source_component_output_port_added_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); -extern int bt_private_graph_add_ports_connected_listener( +extern enum bt_graph_status +bt_private_graph_add_filter_component_output_port_added_listener( + struct bt_private_graph *graph, + bt_private_graph_filter_component_output_port_added_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_filter_component_input_port_removed_listener( + struct bt_private_graph *graph, + bt_private_graph_filter_component_input_port_removed_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_sink_component_input_port_removed_listener( + struct bt_private_graph *graph, + bt_private_graph_sink_component_input_port_removed_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_source_component_output_port_removed_listener( + struct bt_private_graph *graph, + bt_private_graph_source_component_output_port_removed_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_filter_component_output_port_removed_listener( struct bt_private_graph *graph, - bt_private_graph_ports_connected_listener listener, - bt_private_graph_listener_removed listener_removed, void *data); + bt_private_graph_filter_component_output_port_removed_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); -extern int bt_private_graph_add_ports_disconnected_listener( +extern enum bt_graph_status +bt_private_graph_add_source_filter_component_ports_connected_listener( + struct bt_private_graph *graph, + bt_private_graph_source_filter_component_ports_connected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_source_sink_component_ports_connected_listener( + struct bt_private_graph *graph, + bt_private_graph_source_sink_component_ports_connected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_filter_sink_component_ports_connected_listener( + struct bt_private_graph *graph, + bt_private_graph_filter_sink_component_ports_connected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_source_filter_component_ports_disconnected_listener( + struct bt_private_graph *graph, + bt_private_graph_source_filter_component_ports_disconnected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_source_sink_component_ports_disconnected_listener( + struct bt_private_graph *graph, + bt_private_graph_source_sink_component_ports_disconnected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); + +extern enum bt_graph_status +bt_private_graph_add_filter_sink_component_ports_disconnected_listener( struct bt_private_graph *graph, - bt_private_graph_ports_disconnected_listener listener, - bt_private_graph_listener_removed listener_removed, void *data); + bt_private_graph_filter_sink_component_ports_disconnected_listener listener, + bt_private_graph_listener_removed listener_removed, void *data, + int *listener_id); extern enum bt_graph_status bt_private_graph_cancel( struct bt_private_graph *graph); diff --git a/include/babeltrace/graph/private-notification-event.h b/include/babeltrace/graph/private-notification-event.h index 8a046198..cbede7a8 100644 --- a/include/babeltrace/graph/private-notification-event.h +++ b/include/babeltrace/graph/private-notification-event.h @@ -30,14 +30,14 @@ extern "C" { #endif struct bt_private_notification; -struct bt_private_connection_private_notification_iterator; +struct bt_self_notification_iterator; struct bt_private_event; struct bt_private_packet; struct bt_private_event_class; extern struct bt_private_notification *bt_private_notification_event_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_private_event_class *event_class, struct bt_private_packet *packet); diff --git a/include/babeltrace/graph/private-notification-inactivity.h b/include/babeltrace/graph/private-notification-inactivity.h index ca6555ff..ca8253ed 100644 --- a/include/babeltrace/graph/private-notification-inactivity.h +++ b/include/babeltrace/graph/private-notification-inactivity.h @@ -30,12 +30,12 @@ extern "C" { #endif struct bt_private_notification; -struct bt_private_connection_private_notification_iterator; +struct bt_self_notification_iterator; struct bt_clock_class; extern struct bt_private_notification *bt_private_notification_inactivity_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_clock_class *default_clock_class); extern int bt_private_notification_inactivity_set_default_clock_value( diff --git a/include/babeltrace/graph/private-notification-packet.h b/include/babeltrace/graph/private-notification-packet.h index 2e0b21f2..cd7c548a 100644 --- a/include/babeltrace/graph/private-notification-packet.h +++ b/include/babeltrace/graph/private-notification-packet.h @@ -30,17 +30,17 @@ extern "C" { #endif struct bt_private_notification; -struct bt_private_connection_private_notification_iterator; +struct bt_self_notification_iterator; struct bt_private_packet; extern struct bt_private_notification *bt_private_notification_packet_begin_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_private_packet *packet); extern struct bt_private_notification *bt_private_notification_packet_end_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_private_packet *packet); extern struct bt_private_packet * diff --git a/include/babeltrace/graph/private-notification-stream.h b/include/babeltrace/graph/private-notification-stream.h index bfdcf3c4..f5bc2d61 100644 --- a/include/babeltrace/graph/private-notification-stream.h +++ b/include/babeltrace/graph/private-notification-stream.h @@ -32,17 +32,17 @@ extern "C" { #endif struct bt_private_notification; -struct bt_private_connection_private_notification_iterator; +struct bt_self_notification_iterator; struct bt_private_stream; extern struct bt_private_notification *bt_private_notification_stream_begin_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_private_stream *stream); extern struct bt_private_notification *bt_private_notification_stream_end_create( - struct bt_private_connection_private_notification_iterator *notification_iterator, + struct bt_self_notification_iterator *notification_iterator, struct bt_private_stream *stream); extern struct bt_private_stream * diff --git a/include/babeltrace/graph/private-notification.h b/include/babeltrace/graph/private-notification.h index 60d3e316..72b3840b 100644 --- a/include/babeltrace/graph/private-notification.h +++ b/include/babeltrace/graph/private-notification.h @@ -32,8 +32,12 @@ extern "C" { struct bt_notification; struct bt_private_notification; -extern struct bt_notification *bt_notification_borrow_from_private( - struct bt_private_notification *priv_notif); +static inline +struct bt_notification *bt_private_notification_borrow_notification( + struct bt_private_notification *notification) +{ + return (void *) notification; +} #ifdef __cplusplus } diff --git a/include/babeltrace/graph/private-port.h b/include/babeltrace/graph/private-port.h deleted file mode 100644 index d7de1690..00000000 --- a/include/babeltrace/graph/private-port.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef BABELTRACE_GRAPH_PRIVATE_PORT_H -#define BABELTRACE_GRAPH_PRIVATE_PORT_H - -/* - * Copyright 2017 Philippe Proulx - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_port; -struct bt_private_port; -struct bt_private_component; -struct bt_private_connection; - -struct bt_port *bt_port_borrow_from_private( - struct bt_private_port *private_port); - -extern struct bt_private_connection *bt_private_port_get_connection( - struct bt_private_port *private_port); - -extern struct bt_private_component *bt_private_port_get_component( - struct bt_private_port *private_port); - -extern enum bt_port_status bt_private_port_remove_from_component( - struct bt_private_port *private_port); - -extern void *bt_private_port_get_user_data( - struct bt_private_port *private_port); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_PRIVATE_PORT_H */ diff --git a/include/babeltrace/graph/private-query-executor.h b/include/babeltrace/graph/private-query-executor.h new file mode 100644 index 00000000..e2cbceb3 --- /dev/null +++ b/include/babeltrace/graph/private-query-executor.h @@ -0,0 +1,63 @@ +#ifndef BABELTRACE_GRAPH_PRIVATE_QUERY_EXECUTOR_H +#define BABELTRACE_GRAPH_PRIVATE_QUERY_EXECUTOR_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* For enum bt_query_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_query_executor; +struct bt_private_query_executor; +struct bt_component_class; +struct bt_value; + +static inline +struct bt_query_executor *bt_private_query_executor_borrow_query_executor( + struct bt_private_query_executor *priv_query_executor) +{ + return (void *) priv_query_executor; +} + +extern +struct bt_private_query_executor *bt_private_query_executor_create(void); + +extern +enum bt_query_status bt_private_query_executor_query( + struct bt_private_query_executor *query_executor, + struct bt_component_class *component_class, + const char *object, struct bt_value *params, + struct bt_value **result); + +extern +enum bt_query_status bt_private_query_executor_cancel( + struct bt_private_query_executor *query_executor); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_PRIVATE_QUERY_EXECUTOR_H */ diff --git a/include/babeltrace/graph/query-executor-internal.h b/include/babeltrace/graph/query-executor-internal.h index 055f7a39..9bf247ef 100644 --- a/include/babeltrace/graph/query-executor-internal.h +++ b/include/babeltrace/graph/query-executor-internal.h @@ -28,7 +28,7 @@ struct bt_query_executor { struct bt_object base; - bt_bool canceled; + bool canceled; }; static inline const char *bt_query_status_string(enum bt_query_status status) @@ -40,10 +40,10 @@ static inline const char *bt_query_status_string(enum bt_query_status status) return "BT_QUERY_STATUS_AGAIN"; case BT_QUERY_STATUS_EXECUTOR_CANCELED: return "BT_QUERY_STATUS_EXECUTOR_CANCELED"; + case BT_QUERY_STATUS_UNSUPPORTED: + return "BT_QUERY_STATUS_UNSUPPORTED"; case BT_QUERY_STATUS_ERROR: return "BT_QUERY_STATUS_ERROR"; - case BT_QUERY_STATUS_INVALID: - return "BT_QUERY_STATUS_INVALID"; case BT_QUERY_STATUS_INVALID_OBJECT: return "BT_QUERY_STATUS_INVALID_OBJECT"; case BT_QUERY_STATUS_INVALID_PARAMS: diff --git a/include/babeltrace/graph/query-executor.h b/include/babeltrace/graph/query-executor.h index 28a8776e..3b81ec65 100644 --- a/include/babeltrace/graph/query-executor.h +++ b/include/babeltrace/graph/query-executor.h @@ -2,8 +2,6 @@ #define BABELTRACE_GRAPH_QUERY_EXECUTOR_H /* - * BabelTrace - Babeltrace Component Connection Interface - * * Copyright 2017 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,35 +30,19 @@ extern "C" { #endif -struct bt_value; struct bt_query_executor; -struct bt_component_class; enum bt_query_status { - BT_QUERY_STATUS_OK = 0, - BT_QUERY_STATUS_AGAIN = 11, - BT_QUERY_STATUS_EXECUTOR_CANCELED = 125, - BT_QUERY_STATUS_ERROR = -1, - BT_QUERY_STATUS_INVALID = -22, - BT_QUERY_STATUS_INVALID_OBJECT = -23, - BT_QUERY_STATUS_INVALID_PARAMS = -24, - BT_QUERY_STATUS_NOMEM = -12, + BT_QUERY_STATUS_OK = 0, + BT_QUERY_STATUS_AGAIN = 11, + BT_QUERY_STATUS_UNSUPPORTED = 95, + BT_QUERY_STATUS_EXECUTOR_CANCELED = 125, + BT_QUERY_STATUS_ERROR = -1, + BT_QUERY_STATUS_NOMEM = -12, + BT_QUERY_STATUS_INVALID_OBJECT = -23, + BT_QUERY_STATUS_INVALID_PARAMS = -24, }; -extern -struct bt_query_executor *bt_query_executor_create(void); - -extern -enum bt_query_status bt_query_executor_query( - struct bt_query_executor *query_executor, - struct bt_component_class *component_class, - const char *object, struct bt_value *params, - struct bt_value **result); - -extern -enum bt_query_status bt_query_executor_cancel( - struct bt_query_executor *query_executor); - extern bt_bool bt_query_executor_is_canceled(struct bt_query_executor *query_executor); diff --git a/include/babeltrace/graph/self-component-class-filter.h b/include/babeltrace/graph/self-component-class-filter.h new file mode 100644 index 00000000..d1a447cd --- /dev/null +++ b/include/babeltrace/graph/self-component-class-filter.h @@ -0,0 +1,45 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_FILTER_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_FILTER_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class_filter; +struct bt_self_component_class_filter; + +static inline +struct bt_component_class_filter * +bt_self_component_class_filter_borrow_component_class_filter( + struct bt_self_component_class_filter *self_comp_cls_filter) +{ + return (void *) self_comp_cls_filter; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_FILTER_H */ diff --git a/include/babeltrace/graph/self-component-class-sink.h b/include/babeltrace/graph/self-component-class-sink.h new file mode 100644 index 00000000..d3ab8377 --- /dev/null +++ b/include/babeltrace/graph/self-component-class-sink.h @@ -0,0 +1,45 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SINK_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SINK_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class_sink; +struct bt_self_component_class_sink; + +static inline +struct bt_component_class_sink * +bt_self_component_class_sink_borrow_component_class_sink( + struct bt_self_component_class_sink *self_comp_cls_sink) +{ + return (void *) self_comp_cls_sink; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SINK_H */ diff --git a/include/babeltrace/graph/self-component-class-source.h b/include/babeltrace/graph/self-component-class-source.h new file mode 100644 index 00000000..6cb41949 --- /dev/null +++ b/include/babeltrace/graph/self-component-class-source.h @@ -0,0 +1,45 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SOURCE_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SOURCE_H + +/* + * Copyright 2016 Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class_source; +struct bt_self_component_class_source; + +static inline +struct bt_component_class_source * +bt_self_component_class_source_borrow_component_class_source( + struct bt_self_component_class_source *self_comp_cls_source) +{ + return (void *) self_comp_cls_source; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_CLASS_SOURCE_H */ diff --git a/include/babeltrace/graph/self-component-filter.h b/include/babeltrace/graph/self-component-filter.h new file mode 100644 index 00000000..ad23cdee --- /dev/null +++ b/include/babeltrace/graph/self-component-filter.h @@ -0,0 +1,98 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_FILTER_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_FILTER_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_self_component_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_filter; +struct bt_self_component; +struct bt_self_component_filter; +struct bt_self_component_port_input; +struct bt_self_component_port_output; + +static inline +struct bt_self_component *bt_self_component_filter_borrow_self_component( + struct bt_self_component_filter *self_comp_filter) +{ + return (void *) self_comp_filter; +} + +static inline +struct bt_component_filter * +bt_self_component_filter_borrow_component_filter( + struct bt_self_component_filter *self_comp_filter) +{ + return (void *) self_comp_filter; +} + +extern struct bt_self_component *bt_self_component_borrow_from_self_component_filter( + struct bt_self_component_filter *self_component); + +extern struct bt_component_filter *bt_component_filter_borrow_from_self( + struct bt_self_component_filter *self_component); + +extern struct bt_self_component_port_output * +bt_self_component_filter_borrow_output_port_by_name( + struct bt_self_component_filter *self_component, + const char *name); + +extern struct bt_self_component_port_output * +bt_self_component_filter_borrow_output_port_by_index( + struct bt_self_component_filter *self_component, + uint64_t index); + +extern enum bt_self_component_status +bt_self_component_filter_add_output_port( + struct bt_self_component_filter *self_component, + const char *name, void *data, + struct bt_self_component_port_output **self_component_port); + +extern struct bt_self_component_port_input * +bt_self_component_filter_borrow_input_port_by_name( + struct bt_self_component_filter *self_component, + const char *name); + +extern struct bt_self_component_port_input * +bt_self_component_filter_borrow_input_port_by_index( + struct bt_self_component_filter *self_component, + uint64_t index); + +extern enum bt_self_component_status +bt_self_component_filter_add_input_port( + struct bt_self_component_filter *self_component, + const char *name, void *data, + struct bt_self_component_port_input **self_component_port); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_FILTER_H */ diff --git a/include/babeltrace/graph/self-component-port-input-notification-iterator.h b/include/babeltrace/graph/self-component-port-input-notification-iterator.h new file mode 100644 index 00000000..5bfb7104 --- /dev/null +++ b/include/babeltrace/graph/self-component-port-input-notification-iterator.h @@ -0,0 +1,68 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_notification_iterator_status */ +#include + +/* For bt_notification_array */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component; +struct bt_notification_iterator; +struct bt_self_component_port_input_notification_iterator; +struct bt_self_component_port_input; + +static inline +struct bt_notification_iterator * +bt_self_component_port_input_notification_iterator_borrow_notification_iterator( + struct bt_self_component_port_input_notification_iterator *iterator) +{ + return (void *) iterator; +} + +extern struct bt_self_component_port_input_notification_iterator * +bt_self_component_port_input_notification_iterator_create( + struct bt_self_component_port_input *input_port); + +extern struct bt_component * +bt_self_component_port_input_notification_iterator_borrow_component( + struct bt_self_component_port_input_notification_iterator *iterator); + +extern enum bt_notification_iterator_status +bt_self_component_port_input_notification_iterator_next( + struct bt_self_component_port_input_notification_iterator *iterator, + bt_notification_array *notifs, uint64_t *count); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/graph/self-component-port-input.h b/include/babeltrace/graph/self-component-port-input.h new file mode 100644 index 00000000..a133059f --- /dev/null +++ b/include/babeltrace/graph/self-component-port-input.h @@ -0,0 +1,56 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* For enum bt_self_component_port_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port_input; +struct bt_self_component_port; +struct bt_self_component_port_input; + +static inline +struct bt_self_component_port * +bt_self_component_port_input_borrow_self_component_port( + struct bt_self_component_port_input *self_component_port) +{ + return (void *) self_component_port; +} + +static inline +struct bt_port_input *bt_self_component_port_input_borrow_port_input( + struct bt_self_component_port_input *self_component_port) +{ + return (void *) self_component_port; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_PORT_INPUT_H */ diff --git a/include/babeltrace/graph/self-component-port-output.h b/include/babeltrace/graph/self-component-port-output.h new file mode 100644 index 00000000..eaf5d912 --- /dev/null +++ b/include/babeltrace/graph/self-component-port-output.h @@ -0,0 +1,56 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_PORT_OUTPUT_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_PORT_OUTPUT_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* For enum bt_self_component_port_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port_output; +struct bt_self_component_port; +struct bt_self_component_port_output; + +static inline +struct bt_self_component_port * +bt_self_component_port_output_borrow_self_component_port( + struct bt_self_component_port_output *self_component_port) +{ + return (void *) self_component_port; +} + +static inline +struct bt_port_output *bt_self_component_port_output_borrow_port_output( + struct bt_self_component_port_output *self_component_port) +{ + return (void *) self_component_port; +} + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_PORT_OUTPUT_H */ diff --git a/include/babeltrace/graph/self-component-port.h b/include/babeltrace/graph/self-component-port.h new file mode 100644 index 00000000..753cba54 --- /dev/null +++ b/include/babeltrace/graph/self-component-port.h @@ -0,0 +1,61 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_PORT_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_PORT_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_port; +struct bt_self_component_port; +struct bt_self_component; +struct bt_connection; + +enum bt_self_component_port_status { + BT_SELF_PORT_STATUS_OK = 0, + BT_SELF_PORT_STATUS_ERROR = -1, +}; + +static inline +struct bt_port *bt_self_component_port_borrow_port( + struct bt_self_component_port *self_port) +{ + return (void *) self_port; +} + +extern struct bt_self_component *bt_self_component_port_borrow_component( + struct bt_self_component_port *self_port); + +extern enum bt_self_component_port_status +bt_self_component_port_remove_from_component( + struct bt_self_component_port *self_port); + +extern void *bt_self_component_port_get_data( + struct bt_self_component_port *self_port); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_PORT_H */ diff --git a/include/babeltrace/graph/self-component-sink.h b/include/babeltrace/graph/self-component-sink.h new file mode 100644 index 00000000..b98e764b --- /dev/null +++ b/include/babeltrace/graph/self-component-sink.h @@ -0,0 +1,74 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_SINK_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_SINK_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_self_component_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_sink; +struct bt_self_component; +struct bt_self_component_sink; +struct bt_self_component_port_input; + +static inline +struct bt_self_component *bt_self_component_sink_borrow_self_component( + struct bt_self_component_sink *self_comp_sink) +{ + return (void *) self_comp_sink; +} + +static inline +struct bt_component_sink * +bt_self_component_sink_borrow_component_sink( + struct bt_self_component_sink *self_comp_sink) +{ + return (void *) self_comp_sink; +} + +extern struct bt_self_component_port_input * +bt_self_component_sink_borrow_input_port_by_name( + struct bt_self_component_sink *self_component, + const char *name); + +extern struct bt_self_component_port_input * +bt_self_component_sink_borrow_input_port_by_index( + struct bt_self_component_sink *self_component, uint64_t index); + +extern enum bt_self_component_status +bt_self_component_sink_add_input_port( + struct bt_self_component_sink *self_component, + const char *name, void *user_data, + struct bt_self_component_port_input **self_component_port); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_SINK_H */ diff --git a/include/babeltrace/graph/self-component-source.h b/include/babeltrace/graph/self-component-source.h new file mode 100644 index 00000000..61bacd19 --- /dev/null +++ b/include/babeltrace/graph/self-component-source.h @@ -0,0 +1,75 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_SOURCE_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_SOURCE_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +/* For enum bt_self_component_status */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_source; +struct bt_self_component; +struct bt_self_component_source; +struct bt_self_component_port_output; + +static inline +struct bt_self_component *bt_self_component_source_borrow_self_component( + struct bt_self_component_source *self_comp_source) +{ + return (void *) self_comp_source; +} + +static inline +struct bt_component_source * +bt_self_component_source_borrow_component_source( + struct bt_self_component_source *self_comp_source) +{ + return (void *) self_comp_source; +} + +extern struct bt_self_component_port_output * +bt_self_component_source_borrow_output_port_by_name( + struct bt_self_component_source *self_component, + const char *name); + +extern struct bt_self_component_port_output * +bt_self_component_source_borrow_output_port_by_index( + struct bt_self_component_source *self_component, + uint64_t index); + +extern enum bt_self_component_status +bt_self_component_source_add_output_port( + struct bt_self_component_source *self_component, + const char *name, void *user_data, + struct bt_self_component_port_output **self_component_port); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_SOURCE_H */ diff --git a/include/babeltrace/graph/self-component.h b/include/babeltrace/graph/self-component.h new file mode 100644 index 00000000..db2a8a8d --- /dev/null +++ b/include/babeltrace/graph/self-component.h @@ -0,0 +1,59 @@ +#ifndef BABELTRACE_GRAPH_SELF_COMPONENT_H +#define BABELTRACE_GRAPH_SELF_COMPONENT_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component; +struct bt_self_component; + +enum bt_self_component_status { + BT_SELF_COMPONENT_STATUS_OK = 0, + BT_SELF_COMPONENT_STATUS_END = 1, + BT_SELF_COMPONENT_STATUS_AGAIN = 11, + BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION = 111, + BT_SELF_COMPONENT_STATUS_ERROR = -1, + BT_SELF_COMPONENT_STATUS_NOMEM = -12, +}; + +static inline +struct bt_component *bt_self_component_borrow_component( + struct bt_self_component *self_component) +{ + return (void *) self_component; +} + +extern void *bt_self_component_get_data( + struct bt_self_component *private_component); + +extern void bt_self_component_set_data( + struct bt_self_component *private_component, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_COMPONENT_H */ diff --git a/include/babeltrace/graph/self-notification-iterator.h b/include/babeltrace/graph/self-notification-iterator.h new file mode 100644 index 00000000..aa093d27 --- /dev/null +++ b/include/babeltrace/graph/self-notification-iterator.h @@ -0,0 +1,64 @@ +#ifndef BABELTRACE_GRAPH_SELF_NOTIFICATION_ITERATOR_H +#define BABELTRACE_GRAPH_SELF_NOTIFICATION_ITERATOR_H + +/* + * Copyright 2017 Philippe Proulx + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* For BT_NOTIFICATION_ITERATOR_STATUS_* */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_self_component; +struct bt_self_notification_iterator; + +enum bt_self_notification_iterator_status { + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK = BT_NOTIFICATION_ITERATOR_STATUS_OK, + BT_SELF_NOTIFICATION_ITERATOR_STATUS_END = BT_NOTIFICATION_ITERATOR_STATUS_END, + BT_SELF_NOTIFICATION_ITERATOR_STATUS_AGAIN = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, + BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR = BT_NOTIFICATION_ITERATOR_STATUS_ERROR, + BT_SELF_NOTIFICATION_ITERATOR_STATUS_NOMEM = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM, +}; + +extern struct bt_self_component * +bt_self_notification_iterator_borrow_component( + struct bt_self_notification_iterator *notification_iterator); + +extern struct bt_self_port_output * +bt_self_notification_iterator_borrow_port( + struct bt_self_notification_iterator *notification_iterator); + +extern void bt_self_notification_iterator_set_data( + struct bt_self_notification_iterator *notification_iterator, + void *user_data); + +extern void *bt_self_notification_iterator_get_data( + struct bt_self_notification_iterator *notification_iterator); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_GRAPH_SELF_NOTIFICATION_ITERATOR_H */ diff --git a/include/babeltrace/logging.h b/include/babeltrace/logging.h index 7139a126..69efddcd 100644 --- a/include/babeltrace/logging.h +++ b/include/babeltrace/logging.h @@ -2,8 +2,6 @@ #define BABELTRACE_LOGGING_H /* - * Babeltrace - Logging - * * Copyright (c) 2017 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/mmap-align-internal.h b/include/babeltrace/mmap-align-internal.h index 0b64ab92..bef63787 100644 --- a/include/babeltrace/mmap-align-internal.h +++ b/include/babeltrace/mmap-align-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_MMAP_ALIGN_H /* - * BabelTrace mmap-align.h - mmap alignment header - * * Copyright 2010 - Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/object-internal.h b/include/babeltrace/object-internal.h index 6eed014c..ff11e907 100644 --- a/include/babeltrace/object-internal.h +++ b/include/babeltrace/object-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_OBJECT_INTERNAL_H /* - * Babeltrace - Base object - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/object.h b/include/babeltrace/object.h index c2b553a4..e72614fb 100644 --- a/include/babeltrace/object.h +++ b/include/babeltrace/object.h @@ -2,8 +2,6 @@ #define BABELTRACE_OBJECT_H /* - * BabelTrace: common reference counting - * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * Copyright (c) 2015 Jérémie Galarneau diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 786566ea..8cbc665e 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -2,13 +2,11 @@ #define BABELTRACE_PLUGIN_PLUGIN_DEV_H /* - * BabelTrace - Babeltrace Plug-in Development API - * * This is the header that you need to include for the development of * a Babeltrace plug-in. * * Copyright 2015 Jérémie Galarneau - * Copyright 2017 Philippe Proulx + * Copyright 2017-2018 Philippe Proulx * * Author: Jérémie Galarneau * @@ -36,11 +34,10 @@ /* For enum bt_plugin_status */ #include -/* For component class method type definitions */ -#include -#include -#include -#include +/* For private component class method type definitions */ +#include +#include +#include /* * _BT_HIDDEN: set the hidden attribute for internal functions @@ -71,14 +68,6 @@ typedef enum bt_plugin_status (*bt_plugin_init_func)( /* Plugin exit function type */ typedef enum bt_plugin_status (*bt_plugin_exit_func)(void); -/* - * Function to call from a plugin's initialization function to add a - * component class to a plugin object. - */ -extern enum bt_plugin_status bt_plugin_add_component_class( - struct bt_plugin *plugin, - struct bt_component_class *component_class); - /* Plugin descriptor: describes a single plugin (internal use) */ struct __bt_plugin_descriptor { /* Plugin's interface major version number */ @@ -160,33 +149,36 @@ struct __bt_plugin_component_class_descriptor { union { /* BT_COMPONENT_CLASS_TYPE_SOURCE */ struct { - bt_component_class_notification_iterator_next_method notif_iter_next; + bt_private_component_class_source_notification_iterator_next_method notif_iter_next; } source; /* BT_COMPONENT_CLASS_TYPE_FILTER */ struct { - bt_component_class_notification_iterator_next_method notif_iter_next; + bt_private_component_class_filter_notification_iterator_next_method notif_iter_next; } filter; /* BT_COMPONENT_CLASS_TYPE_SINK */ struct { - bt_component_class_sink_consume_method consume; + bt_private_component_class_sink_consume_method consume; } sink; } methods; } __attribute__((packed)); /* Type of a component class attribute (internal use) */ enum __bt_plugin_component_class_descriptor_attribute_type { - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION = 0, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP = 1, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD = 2, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD = 3, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD = 4, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD = 5, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD = 7, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD = 8, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD = 9, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD = 10, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION = 0, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP = 1, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD = 2, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD = 3, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD = 4, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD = 5, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD = 6, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD = 7, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD = 8, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD = 9, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD = 10, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD = 11, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD = 12, }; /* Component class attribute (internal use) */ @@ -212,28 +204,51 @@ struct __bt_plugin_component_class_descriptor_attribute { const char *help; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD */ - bt_component_class_init_method init_method; + bt_private_component_class_source_init_method source_init_method; + bt_private_component_class_filter_init_method filter_init_method; + bt_private_component_class_sink_init_method sink_init_method; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD */ - bt_component_class_finalize_method finalize_method; + bt_private_component_class_source_finalize_method source_finalize_method; + bt_private_component_class_filter_finalize_method filter_finalize_method; + bt_private_component_class_sink_finalize_method sink_finalize_method; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD */ - bt_component_class_query_method query_method; + bt_private_component_class_source_query_method source_query_method; + bt_private_component_class_filter_query_method filter_query_method; + bt_private_component_class_sink_query_method sink_query_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD */ + bt_private_component_class_filter_accept_input_port_connection_method filter_accept_input_port_connection_method; + bt_private_component_class_sink_accept_input_port_connection_method sink_accept_input_port_connection_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD */ + bt_private_component_class_source_accept_output_port_connection_method source_accept_output_port_connection_method; + bt_private_component_class_filter_accept_output_port_connection_method filter_accept_output_port_connection_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD */ - bt_component_class_accept_port_connection_method accept_port_connection_method; + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD */ + bt_private_component_class_filter_input_port_connected_method filter_input_port_connected_method; + bt_private_component_class_sink_input_port_connected_method sink_input_port_connected_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD */ - bt_component_class_port_connected_method port_connected_method; + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD */ + bt_private_component_class_source_output_port_connected_method source_output_port_connected_method; + bt_private_component_class_filter_output_port_connected_method filter_output_port_connected_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD */ - bt_component_class_port_disconnected_method port_disconnected_method; + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD */ + bt_private_component_class_filter_input_port_disconnected_method filter_input_port_disconnected_method; + bt_private_component_class_sink_input_port_disconnected_method sink_input_port_disconnected_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD */ + bt_private_component_class_source_output_port_disconnected_method source_output_port_disconnected_method; + bt_private_component_class_filter_output_port_disconnected_method filter_output_port_disconnected_method; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD */ - bt_component_class_notification_iterator_init_method notif_iter_init_method; + bt_private_component_class_source_notification_iterator_init_method source_notif_iter_init_method; + bt_private_component_class_filter_notification_iterator_init_method filter_notif_iter_init_method; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD */ - bt_component_class_notification_iterator_finalize_method notif_iter_finalize_method; + bt_private_component_class_source_notification_iterator_finalize_method source_notif_iter_finalize_method; + bt_private_component_class_filter_notification_iterator_finalize_method filter_notif_iter_finalize_method; } value; } __attribute__((packed)); @@ -499,7 +514,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _comp_class_id: Component class ID (C identifier). * _name: Component class name (C string). * _notif_iter_next_method: Component class's iterator next method - * (bt_component_class_notification_iterator_next_method). + * (bt_private_component_class_source_notification_iterator_next_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _notif_iter_next_method) \ static struct __bt_plugin_component_class_descriptor __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id = { \ @@ -515,11 +530,11 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ /* * Defines a filter component class descriptor with a custom ID. * - * _id: ID (any valid C identifier except `auto`). - * _comp_class_id: Component class ID (C identifier). - * _name: Component class name (C string). + * _id: ID (any valid C identifier except `auto`). + * _comp_class_id: Component class ID (C identifier). + * _name: Component class name (C string). * _notif_iter_next_method: Component class's iterator next method - * (bt_component_class_notification_iterator_next_method). + * (bt_private_component_class_filter_notification_iterator_next_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _notif_iter_next_method) \ static struct __bt_plugin_component_class_descriptor __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id = { \ @@ -539,7 +554,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _comp_class_id: Component class ID (C identifier). * _name: Component class name (C string). * _consume_method: Component class's iterator consume method - * (bt_component_class_sink_consume_method). + * (bt_private_component_class_sink_consume_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _consume_method) \ static struct __bt_plugin_component_class_descriptor __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id = { \ @@ -645,10 +660,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_source_init_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, source, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, source, _x) /* * Defines an initialization method attribute attached to a specific @@ -656,10 +671,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_filter_init_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, filter, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, filter, _x) /* * Defines an initialization method attribute attached to a specific @@ -667,43 +682,43 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_sink_init_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, sink, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines a finalize method attribute attached to a specific source + * Defines a finalization method attribute attached to a specific source * component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_finalize_method). + * _x: Finalize method (bt_private_component_class_source_finalize_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, source, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, source, _x) /* - * Defines a finalize method attribute attached to a specific filter + * Defines a finalization method attribute attached to a specific filter * component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_finalize_method). + * _x: Finalize method (bt_private_component_class_filter_finalize_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, filter, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines a finalize method attribute attached to a specific sink + * Defines a finalization method attribute attached to a specific sink * component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_finalize_method). + * _x: Finalize method (bt_private_component_class_sink_finalize_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, sink, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD, _id, _comp_class_id, sink, _x) /* * Defines a query method attribute attached to a specific source @@ -711,10 +726,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_query_method). + * _x: Finalize method (bt_private_component_class_source_query_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, source, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, source, _x) /* * Defines a query method attribute attached to a specific filter @@ -722,10 +737,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_query_method). + * _x: Finalize method (bt_private_component_class_filter_query_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, filter, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, filter, _x) /* * Defines a query method attribute attached to a specific sink @@ -733,118 +748,154 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Finalize method (bt_component_class_query_method). + * _x: Finalize method (bt_private_component_class_sink_query_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, sink, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines an accept port connection method attribute attached to a - * specific source component class descriptor. + * Defines an accept input port connection method attribute attached to + * a specific filter component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_filter_accept_input_port_connection_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(accept_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD, _id, _comp_class_id, source, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_accept_input_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines an accept port connection method attribute attached to a - * specific filter component class descriptor. + * Defines an accept input port connection method attribute attached to + * a specific sink component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_sink_accept_input_port_connection_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(accept_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_accept_input_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines an accept port connection method attribute attached to a - * specific sink component class descriptor. + * Defines an accept output port connection method attribute attached to + * a specific source component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_source_accept_output_port_connection_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(accept_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD, _id, _comp_class_id, sink, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_accept_output_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD, _id, _comp_class_id, source, _x) /* - * Defines a port connected method attribute attached to a specific - * source component class descriptor. + * Defines an accept output port connection method attribute attached to + * a specific filter component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Accept port connection method + * (bt_private_component_class_filter_accept_output_port_connection_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_accept_output_port_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an input port connected method attribute attached to a + * specific filter component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port connected method - * (bt_component_class_port_connected_method). + * (bt_private_component_class_filter_input_port_connected_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD, _id, _comp_class_id, source, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_input_port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines a port connected method attribute attached to a specific - * filter component class descriptor. + * Defines an input port connected method attribute attached to a + * specific sink component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port connected method - * (bt_component_class_port_connected_method). + * (bt_private_component_class_sink_input_port_connected_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_input_port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines a port connected method attribute attached to a specific - * sink component class descriptor. + * Defines an output port connected method attribute attached to a + * specific source component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port connected method - * (bt_component_class_port_connected_method). + * (bt_private_component_class_source_output_port_connected_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD, _id, _comp_class_id, sink, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_output_port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD, _id, _comp_class_id, source, _x) /* - * Defines a port disconnected method attribute attached to a specific - * source component class descriptor. + * Defines an output port connected method attribute attached to a + * specific filter component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Port connected method + * (bt_private_component_class_filter_output_port_connected_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_output_port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an input port disconnected method attribute attached to a + * specific filter component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port disconnected method - * (bt_component_class_port_disconnected_method). + * (bt_private_component_class_filter_input_port_disconnected_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, source, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_input_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines a port disconnected method attribute attached to a specific - * filter component class descriptor. + * Defines an input port disconnected method attribute attached to a + * specific sink component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port disconnected method - * (bt_component_class_port_disconnected_method). + * (bt_private_component_class_sink_input_port_disconnected_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_input_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines a port disconnected method attribute attached to a specific - * sink component class descriptor. + * Defines an output port disconnected method attribute attached to a + * specific source component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Port disconnected method - * (bt_component_class_port_disconnected_method). + * (bt_private_component_class_source_output_port_disconnected_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, sink, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_output_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines an output port disconnected method attribute attached to a + * specific filter component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Port disconnected method + * (bt_private_component_class_filter_output_port_disconnected_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_output_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, filter, _x) /* * Defines an iterator initialization method attribute attached to a @@ -853,10 +904,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Iterator initialization method - * (bt_component_class_notification_iterator_init_method). + * (bt_private_component_class_source_notification_iterator_init_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, source, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, source, _x) /* * Defines an iterator finalize method attribute attached to a specific @@ -865,10 +916,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Iterator finalize method - * (bt_component_class_notification_iterator_finalize_method). + * (bt_private_component_class_source_notification_iterator_finalize_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD, _id, _comp_class_id, source, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_notif_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD, _id, _comp_class_id, source, _x) /* * Defines an iterator initialization method attribute attached to a @@ -877,10 +928,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Iterator initialization method - * (bt_component_class_notification_iterator_init_method). + * (bt_private_component_class_filter_notification_iterator_init_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, filter, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, filter, _x) /* * Defines an iterator finalize method attribute attached to a specific @@ -889,10 +940,10 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). * _x: Iterator finalize method - * (bt_component_class_notification_iterator_finalize_method). + * (bt_private_component_class_filter_notification_iterator_finalize_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD, _id, _comp_class_id, filter, _x) + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_notif_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD, _id, _comp_class_id, filter, _x) /* * Defines a plugin descriptor with an automatic ID. @@ -959,7 +1010,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _notif_iter_next_method: Component class's iterator next method - * (bt_component_class_notification_iterator_next_method). + * (bt_private_component_class_source_notification_iterator_next_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _notif_iter_next_method) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_next_method) @@ -971,7 +1022,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _notif_iter_next_method: Component class's iterator next method - * (bt_component_class_notification_iterator_next_method). + * (bt_private_component_class_filter_notification_iterator_next_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _notif_iter_next_method) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_next_method) @@ -983,7 +1034,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _consume_method: Component class's consume method - * (bt_component_class_sink_consume_method). + * (bt_private_component_class_sink_consume_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS(_name, _consume_method) \ BT_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _consume_method) @@ -1054,7 +1105,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_source_init_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) @@ -1065,7 +1116,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_filter_init_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) @@ -1076,39 +1127,39 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_init_method). + * _x: Initialization method (bt_private_component_class_sink_init_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a finalize method attribute attached to a source component + * Defines a finalization method attribute attached to a source component * class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_finalize_method). + * _x: Initialization method (bt_private_component_class_source_finalize_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD(_name, _x) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a finalize method attribute attached to a filter component + * Defines a finalization method attribute attached to a filter component * class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_finalize_method). + * _x: Initialization method (bt_private_component_class_filter_finalize_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a finalize method attribute attached to a sink component class + * Defines a finalization method attribute attached to a sink component class * descriptor which is attached to the automatic plugin descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_finalize_method). + * _x: Initialization method (bt_private_component_class_sink_finalize_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(_name, _x) \ BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(auto, _name, _x) @@ -1119,7 +1170,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_query_method). + * _x: Initialization method (bt_private_component_class_source_query_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_QUERY_METHOD(_name, _x) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(auto, _name, _x) @@ -1130,7 +1181,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_query_method). + * _x: Initialization method (bt_private_component_class_filter_query_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(auto, _name, _x) @@ -1141,112 +1192,146 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * descriptor. * * _name: Component class name (C identifier). - * _x: Initialization method (bt_component_class_query_method). + * _x: Initialization method (bt_private_component_class_sink_query_method). */ #define BT_PLUGIN_SINK_COMPONENT_CLASS_QUERY_METHOD(_name, _x) \ BT_PLUGIN_SINK_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an accept port connection method attribute attached to a - * source component class descriptor which is attached to the automatic - * plugin descriptor. + * Defines an accept input port connection method attribute attached to + * a filter component class descriptor which is attached to the + * automatic plugin descriptor. * * _name: Component class name (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_filter_accept_input_port_connection_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an accept port connection method attribute attached to a - * filter component class descriptor which is attached to the automatic + * Defines an accept input port connection method attribute attached to + * a sink component class descriptor which is attached to the automatic * plugin descriptor. * * _name: Component class name (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_sink_accept_input_port_connection_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_INPUT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an accept port connection method attribute attached to a sink - * component class descriptor which is attached to the automatic plugin - * descriptor. + * Defines an accept output port connection method attribute attached to + * a source component class descriptor which is attached to the + * automatic plugin descriptor. * * _name: Component class name (C identifier). * _x: Accept port connection method - * (bt_component_class_accept_port_connection_method). + * (bt_private_component_class_source_accept_output_port_connection_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD(_name, _x) \ - BT_PLUGIN_SINK_COMPONENT_CLASS_ACCEPT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port connected method attribute attached to a source - * component class descriptor which is attached to the automatic plugin - * descriptor. + * Defines an accept output port connection method attribute attached to + * a filter component class descriptor which is attached to the + * automatic plugin descriptor. * * _name: Component class name (C identifier). - * _x: Port connected (bt_component_class_port_connected_method). + * _x: Accept port connection method + * (bt_private_component_class_filter_accept_output_port_connection_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_CONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port connected method attribute attached to a filter + * Defines an input port connected method attribute attached to a filter * component class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Port connected (bt_component_class_port_connected_method). + * _x: Port connected (bt_private_component_class_filter_input_port_connected_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_CONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port connected method attribute attached to a sink + * Defines an input port connected method attribute attached to a sink * component class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Port connected (bt_component_class_port_connected_method). + * _x: Port connected (bt_private_component_class_sink_input_port_connected_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port disconnected method attribute attached to a source + * Defines an output port connected method attribute attached to a source * component class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_port_disconnected_method). + * _x: Port connected (bt_private_component_class_source_output_port_connected_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port disconnected method attribute attached to a filter + * Defines an output port connected method attribute attached to a filter * component class descriptor which is attached to the automatic plugin * descriptor. * * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_port_disconnected_method). + * _x: Port connected (bt_private_component_class_filter_output_port_connected_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) /* - * Defines a port disconnected method attribute attached to a sink - * component class descriptor which is attached to the automatic plugin - * descriptor. + * Defines an input port disconnected method attribute attached to a + * filter component class descriptor which is attached to the automatic + * plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Port disconnected (bt_private_component_class_filter_input_port_disconnected_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an input port disconnected method attribute attached to a + * sink component class descriptor which is attached to the automatic + * plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Port disconnected (bt_private_component_class_sink_input_port_disconnected_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an output port disconnected method attribute attached to a + * source component class descriptor which is attached to the automatic + * plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Port disconnected (bt_private_component_class_source_output_port_disconnected_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an output port disconnected method attribute attached to a + * filter component class descriptor which is attached to the automatic + * plugin descriptor. * * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_port_disconnected_method). + * _x: Port disconnected (bt_private_component_class_filter_output_port_disconnected_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) /* * Defines an iterator initialization method attribute attached to a @@ -1255,7 +1340,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _x: Iterator initialization method - * (bt_component_class_notification_iterator_init_method). + * (bt_private_component_class_source_notification_iterator_init_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(_name, _x) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(auto, _name, _x) @@ -1267,7 +1352,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _x: Iterator finalize method - * (bt_component_class_notification_iterator_finalize_method). + * (bt_private_component_class_source_notification_iterator_finalize_method). */ #define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(_name, _x) \ BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(auto, _name, _x) @@ -1279,7 +1364,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _x: Iterator initialization method - * (bt_component_class_notification_iterator_init_method). + * (bt_private_component_class_filter_notification_iterator_init_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(auto, _name, _x) @@ -1291,7 +1376,7 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ * * _name: Component class name (C identifier). * _x: Iterator finalize method - * (bt_component_class_notification_iterator_finalize_method). + * (bt_private_component_class_filter_notification_iterator_finalize_method). */ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD_WITH_ID(auto, _name, _x) diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index b9579ff8..71977a74 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H /* - * BabelTrace - Plug-in Internal - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -28,9 +26,12 @@ */ #include +#include #include #include +#include #include +#include #include #include #include @@ -43,10 +44,11 @@ enum bt_plugin_type { struct bt_plugin { struct bt_object base; enum bt_plugin_type type; - bt_bool frozen; - /* Array of pointers to bt_component_class (owned by this) */ - GPtrArray *comp_classes; + /* Arrays of `struct bt_component_class *` (owned by this) */ + GPtrArray *src_comp_classes; + GPtrArray *flt_comp_classes; + GPtrArray *sink_comp_classes; /* Info (owned by this) */ struct { @@ -61,12 +63,12 @@ struct bt_plugin { unsigned int patch; GString *extra; } version; - bt_bool path_set; - bt_bool name_set; - bt_bool author_set; - bt_bool license_set; - bt_bool description_set; - bt_bool version_set; + bool path_set; + bool name_set; + bool author_set; + bool license_set; + bool description_set; + bool version_set; } info; /* Value depends on the specific plugin type */ @@ -116,16 +118,25 @@ void bt_plugin_destroy(struct bt_object *obj) BT_ASSERT(obj); plugin = container_of(obj, struct bt_plugin, base); - BT_LOGD("Destroying plugin object: addr=%p, name=\"%s\"", - plugin, plugin->info.name ? plugin->info.name->str : NULL); + BT_LIB_LOGD("Destroying plugin object: %!+l", plugin); if (plugin->destroy_spec_data) { plugin->destroy_spec_data(plugin); } - if (plugin->comp_classes) { - BT_LOGD_STR("Putting component classes."); - g_ptr_array_free(plugin->comp_classes, TRUE); + if (plugin->src_comp_classes) { + BT_LOGD_STR("Putting source component classes."); + g_ptr_array_free(plugin->src_comp_classes, TRUE); + } + + if (plugin->flt_comp_classes) { + BT_LOGD_STR("Putting filter component classes."); + g_ptr_array_free(plugin->flt_comp_classes, TRUE); + } + + if (plugin->sink_comp_classes) { + BT_LOGD_STR("Putting sink component classes."); + g_ptr_array_free(plugin->sink_comp_classes, TRUE); } if (plugin->info.name) { @@ -172,10 +183,27 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type) bt_object_init_shared(&plugin->base, bt_plugin_destroy); plugin->type = type; - /* Create empty array of component classes */ - plugin->comp_classes = - g_ptr_array_new_with_free_func((GDestroyNotify) bt_object_put_ref); - if (!plugin->comp_classes) { + /* Create empty arrays of component classes */ + plugin->src_comp_classes = + g_ptr_array_new_with_free_func( + (GDestroyNotify) bt_object_put_ref); + if (!plugin->src_comp_classes) { + BT_LOGE_STR("Failed to allocate a GPtrArray."); + goto error; + } + + plugin->flt_comp_classes = + g_ptr_array_new_with_free_func( + (GDestroyNotify) bt_object_put_ref); + if (!plugin->flt_comp_classes) { + BT_LOGE_STR("Failed to allocate a GPtrArray."); + goto error; + } + + plugin->sink_comp_classes = + g_ptr_array_new_with_free_func( + (GDestroyNotify) bt_object_put_ref); + if (!plugin->sink_comp_classes) { BT_LOGE_STR("Failed to allocate a GPtrArray."); goto error; } @@ -217,8 +245,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type) goto error; } - BT_LOGD("Created empty plugin object: type=%s, addr=%p", - bt_plugin_type_string(type), plugin); + BT_LIB_LOGD("Created empty plugin object: %!+l", plugin); goto end; error: @@ -235,8 +262,8 @@ void bt_plugin_set_path(struct bt_plugin *plugin, const char *path) BT_ASSERT(path); g_string_assign(plugin->info.path, path); plugin->info.path_set = BT_TRUE; - BT_LOGV("Set plugin's path: addr=%p, name=\"%s\", path=\"%s\"", - plugin, bt_plugin_get_name(plugin), path); + BT_LIB_LOGV("Set plugin's path: %![plugin-]+l, path=\"%s\"", + plugin, path); } static inline @@ -246,7 +273,7 @@ void bt_plugin_set_name(struct bt_plugin *plugin, const char *name) BT_ASSERT(name); g_string_assign(plugin->info.name, name); plugin->info.name_set = BT_TRUE; - BT_LOGV("Set plugin's name: addr=%p, name=\"%s\"", + BT_LIB_LOGV("Set plugin's name: %![plugin-]+l, name=\"%s\"", plugin, name); } @@ -258,8 +285,7 @@ void bt_plugin_set_description(struct bt_plugin *plugin, BT_ASSERT(description); g_string_assign(plugin->info.description, description); plugin->info.description_set = BT_TRUE; - BT_LOGV("Set plugin's description: addr=%p, name=\"%s\"", - plugin, bt_plugin_get_name(plugin)); + BT_LIB_LOGV("Set plugin's description: %![plugin-]+l", plugin); } static inline @@ -269,8 +295,8 @@ void bt_plugin_set_author(struct bt_plugin *plugin, const char *author) BT_ASSERT(author); g_string_assign(plugin->info.author, author); plugin->info.author_set = BT_TRUE; - BT_LOGV("Set plugin's author: addr=%p, name=\"%s\", author=\"%s\"", - plugin, bt_plugin_get_name(plugin), author); + BT_LIB_LOGV("Set plugin's author: %![plugin-]+l, author=\"%s\"", + plugin, author); } static inline @@ -280,8 +306,8 @@ void bt_plugin_set_license(struct bt_plugin *plugin, const char *license) BT_ASSERT(license); g_string_assign(plugin->info.license, license); plugin->info.license_set = BT_TRUE; - BT_LOGV("Set plugin's path: addr=%p, name=\"%s\", license=\"%s\"", - plugin, bt_plugin_get_name(plugin), license); + BT_LIB_LOGV("Set plugin's path: %![plugin-]+l, license=\"%s\"", + plugin, license); } static inline @@ -298,25 +324,45 @@ void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major, } plugin->info.version_set = BT_TRUE; - BT_LOGV("Set plugin's version: addr=%p, name=\"%s\", " + BT_LIB_LOGV("Set plugin's version: %![plugin-]+l, " "major=%u, minor=%u, patch=%u, extra=\"%s\"", - plugin, bt_plugin_get_name(plugin), - major, minor, patch, extra); + plugin, major, minor, patch, extra); } static inline -void bt_plugin_freeze(struct bt_plugin *plugin) +enum bt_plugin_status bt_plugin_add_component_class( + struct bt_plugin *plugin, struct bt_component_class *comp_class) { + GPtrArray *comp_classes; + BT_ASSERT(plugin); + BT_ASSERT(comp_class); + + switch (comp_class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + comp_classes = plugin->src_comp_classes; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + comp_classes = plugin->flt_comp_classes; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + comp_classes = plugin->sink_comp_classes; + break; + default: + abort(); + } - if (plugin->frozen) { - return; + /* Add new component class */ + g_ptr_array_add(comp_classes, bt_object_get_ref(comp_class)); + + /* Special case for a shared object plugin */ + if (plugin->type == BT_PLUGIN_TYPE_SO) { + bt_plugin_so_on_add_component_class(plugin, comp_class); } - BT_LOGD("Freezing plugin: addr=%p, name=\"%s\", path=\"%s\"", - plugin, bt_plugin_get_name(plugin), - bt_plugin_get_path(plugin)); - plugin->frozen = BT_TRUE; + BT_LIB_LOGD("Added component class to plugin: " + "%![plugin-]+l, %![cc-]+C", plugin, comp_class); + return BT_PLUGIN_STATUS_OK; } static @@ -372,11 +418,9 @@ void bt_plugin_set_add_plugin(struct bt_plugin_set *plugin_set, BT_ASSERT(plugin_set); BT_ASSERT(plugin); g_ptr_array_add(plugin_set->plugins, bt_object_get_ref(plugin)); - BT_LOGV("Added plugin to plugin set: " - "plugin-set-addr=%p, plugin-addr=%p, plugin-name=\"%s\", " - "plugin-path=\"%s\"", - plugin_set, plugin, bt_plugin_get_name(plugin), - bt_plugin_get_path(plugin)); + BT_LIB_LOGV("Added plugin to plugin set: " + "plugin-set-addr=%p, %![plugin-]+l", + plugin_set, plugin); } #endif /* BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H */ diff --git a/include/babeltrace/plugin/plugin-so-internal.h b/include/babeltrace/plugin/plugin-so-internal.h index 07df7422..19b422a3 100644 --- a/include/babeltrace/plugin/plugin-so-internal.h +++ b/include/babeltrace/plugin/plugin-so-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_PLUGIN_PLUGIN_SO_INTERNAL_H /* - * BabelTrace - Babeltrace Plug-in Interface - * * Copyright 2016 Jérémie Galarneau * Copyright 2017 Philippe Proulx * diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h index ae7b7c7a..667486ea 100644 --- a/include/babeltrace/plugin/plugin.h +++ b/include/babeltrace/plugin/plugin.h @@ -2,8 +2,6 @@ #define BABELTRACE_PLUGIN_PLUGIN_H /* - * BabelTrace - Babeltrace Plug-in Interface - * * Copyright 2016 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -37,6 +35,18 @@ /* For enum bt_component_class_type */ #include +/* For enum bt_component_class_source */ +#include + +/* For enum bt_component_class_filter */ +#include + +/* For enum bt_component_class_sink */ +#include + +/* For enum bt_property_availability */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -44,25 +54,18 @@ extern "C" { struct bt_plugin; struct bt_plugin_set; struct bt_component_class; +struct bt_component_class_source; +struct bt_component_class_filter; +struct bt_component_class_sink; -/** - * Status code. Errors are always negative. - */ enum bt_plugin_status { - /** No error, okay. */ BT_PLUGIN_STATUS_OK = 0, - /** General error. */ BT_PLUGIN_STATUS_ERROR = -1, - /** Memory allocation failure. */ - BT_PLUGIN_STATUS_NOMEM = -4, + BT_PLUGIN_STATUS_NOMEM = -12, }; extern struct bt_plugin *bt_plugin_find(const char *plugin_name); -extern struct bt_component_class *bt_plugin_find_component_class( - const char *plugin_name, const char *component_class_name, - enum bt_component_class_type component_class_type); - extern struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path); extern struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path, @@ -70,66 +73,58 @@ extern struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path, extern struct bt_plugin_set *bt_plugin_create_all_from_static(void); -/** - * Get the name of a plug-in. - * - * @param plugin An instance of a plug-in - * @returns Plug-in name or NULL on error - */ extern const char *bt_plugin_get_name(struct bt_plugin *plugin); -/** - * Get the name of a plug-in's author. - * - * @param plugin An instance of a plug-in - * @returns Plug-in author or NULL on error - */ extern const char *bt_plugin_get_author(struct bt_plugin *plugin); -/** - * Get the license of a plug-in. - * - * @param plugin An instance of a plug-in - * @returns Plug-in license or NULL on error - */ extern const char *bt_plugin_get_license(struct bt_plugin *plugin); -/** - * Get the decription of a plug-in. - * - * @param plugin An instance of a plug-in - * @returns Plug-in description or NULL if none is available - */ extern const char *bt_plugin_get_description(struct bt_plugin *plugin); -/** - * Get the path of a plug-in. - * - * @param plugin An instance of a plug-in - * @returns Plug-in path or NULL on error - */ extern const char *bt_plugin_get_path(struct bt_plugin *plugin); -extern enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, - unsigned int *major, unsigned int *minor, unsigned int *patch, - const char **extra); +extern enum bt_property_availability bt_plugin_get_version( + struct bt_plugin *plugin, unsigned int *major, + unsigned int *minor, unsigned int *patch, const char **extra); + +extern uint64_t bt_plugin_get_source_component_class_count( + struct bt_plugin *plugin); + +extern uint64_t bt_plugin_get_filter_component_class_count( + struct bt_plugin *plugin); -extern int64_t bt_plugin_get_component_class_count(struct bt_plugin *plugin); +extern uint64_t bt_plugin_get_sink_component_class_count( + struct bt_plugin *plugin); -extern struct bt_component_class *bt_plugin_get_component_class_by_index( +extern struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_index( struct bt_plugin *plugin, uint64_t index); -extern -struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( - struct bt_plugin *plugin, const char *name, - enum bt_component_class_type type); +extern struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_index( + struct bt_plugin *plugin, uint64_t index); + +extern struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_index( + struct bt_plugin *plugin, uint64_t index); + +extern struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_name(struct bt_plugin *plugin, + const char *name); + +extern struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_name(struct bt_plugin *plugin, + const char *name); + +extern struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_name(struct bt_plugin *plugin, + const char *name); -extern -int64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set); +extern uint64_t bt_plugin_set_get_plugin_count( + struct bt_plugin_set *plugin_set); -extern -struct bt_plugin *bt_plugin_set_get_plugin(struct bt_plugin_set *plugin_set, - uint64_t index); +extern struct bt_plugin *bt_plugin_set_borrow_plugin_by_index( + struct bt_plugin_set *plugin_set, uint64_t index); #ifdef __cplusplus } diff --git a/include/babeltrace/prio-heap-internal.h b/include/babeltrace/prio-heap-internal.h index 52de47c8..001e01d6 100644 --- a/include/babeltrace/prio-heap-internal.h +++ b/include/babeltrace/prio-heap-internal.h @@ -2,8 +2,6 @@ #define _BABELTRACE_PRIO_HEAP_H /* - * prio_heap.h - * * Static-sized priority heap containing pointers. Based on CLRS, * chapter 6. * diff --git a/include/babeltrace/private-values.h b/include/babeltrace/private-values.h index 8563e31d..b747b3d7 100644 --- a/include/babeltrace/private-values.h +++ b/include/babeltrace/private-values.h @@ -39,8 +39,12 @@ struct bt_private_value; extern struct bt_private_value *bt_private_value_null; -extern struct bt_value *bt_value_borrow_from_private( - struct bt_private_value *priv_value); +static inline +struct bt_value *bt_private_value_borrow_value( + struct bt_private_value *priv_value) +{ + return (void *) priv_value; +} extern struct bt_private_value *bt_private_value_bool_create(void); diff --git a/include/babeltrace/trace-ir/attributes-internal.h b/include/babeltrace/trace-ir/attributes-internal.h index 99d582dd..43c07c02 100644 --- a/include/babeltrace/trace-ir/attributes-internal.h +++ b/include/babeltrace/trace-ir/attributes-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_ATTRIBUTES_H /* - * attributes.c - * * Babeltrace - Trace IR: Attributes internal * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation diff --git a/include/babeltrace/trace-ir/clock-class-internal.h b/include/babeltrace/trace-ir/clock-class-internal.h index 86e0e392..a7cc7d86 100644 --- a/include/babeltrace/trace-ir/clock-class-internal.h +++ b/include/babeltrace/trace-ir/clock-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_CLOCK_CLASS_INTERNAL_H /* - * BabelTrace - Trace IR: Clock internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/event-class-internal.h b/include/babeltrace/trace-ir/event-class-internal.h index bf095da0..cb8335de 100644 --- a/include/babeltrace/trace-ir/event-class-internal.h +++ b/include/babeltrace/trace-ir/event-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_EVENT_CLASS_INTERNAL_H /* - * Babeltrace - Trace IR: Event class internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/event-internal.h b/include/babeltrace/trace-ir/event-internal.h index 11676fed..0b495672 100644 --- a/include/babeltrace/trace-ir/event-internal.h +++ b/include/babeltrace/trace-ir/event-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_EVENT_INTERNAL_H /* - * Babeltrace - Trace IR: Event internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/field-classes-internal.h b/include/babeltrace/trace-ir/field-classes-internal.h index 20bf544e..7103a86c 100644 --- a/include/babeltrace/trace-ir/field-classes-internal.h +++ b/include/babeltrace/trace-ir/field-classes-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H /* - * BabelTrace - Trace IR: Event field classes internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/field-path-internal.h b/include/babeltrace/trace-ir/field-path-internal.h index fd6ebc3c..92423d83 100644 --- a/include/babeltrace/trace-ir/field-path-internal.h +++ b/include/babeltrace/trace-ir/field-path-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_FIELD_PATH_INTERNAL /* - * BabelTrace - Trace IR: Field path - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/trace-ir/fields-internal.h b/include/babeltrace/trace-ir/fields-internal.h index c3ee0ad8..9748a300 100644 --- a/include/babeltrace/trace-ir/fields-internal.h +++ b/include/babeltrace/trace-ir/fields-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_FIELDS_INTERNAL_H /* - * Babeltrace - Trace IR: Event Fields internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/packet-internal.h b/include/babeltrace/trace-ir/packet-internal.h index ec709a35..4319abe1 100644 --- a/include/babeltrace/trace-ir/packet-internal.h +++ b/include/babeltrace/trace-ir/packet-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_PACKET_INTERNAL_H /* - * Babeltrace - Trace IR: Stream packet internal - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/trace-ir/private-clock-class.h b/include/babeltrace/trace-ir/private-clock-class.h index 72ac937d..f33cf479 100644 --- a/include/babeltrace/trace-ir/private-clock-class.h +++ b/include/babeltrace/trace-ir/private-clock-class.h @@ -41,8 +41,12 @@ extern "C" { struct bt_clock_class; struct bt_private_clock_class; -extern struct bt_clock_class *bt_clock_class_borrow_from_private( - struct bt_private_clock_class *priv_clock_class); +static inline +struct bt_clock_class *bt_private_clock_class_borrow_clock_class( + struct bt_private_clock_class *priv_clock_class) +{ + return (void *) priv_clock_class; +} extern struct bt_private_clock_class *bt_private_clock_class_create(void); diff --git a/include/babeltrace/trace-ir/private-event-class.h b/include/babeltrace/trace-ir/private-event-class.h index f81f6103..9f48ff96 100644 --- a/include/babeltrace/trace-ir/private-event-class.h +++ b/include/babeltrace/trace-ir/private-event-class.h @@ -41,8 +41,12 @@ struct bt_event_class; struct bt_private_event_class; struct bt_private_stream_class; -extern struct bt_event_class *bt_event_class_borrow_from_private( - struct bt_private_event_class *priv_event_class); +static inline +struct bt_event_class *bt_private_event_class_borrow_event_class( + struct bt_private_event_class *priv_event_class) +{ + return (void *) priv_event_class; +} extern struct bt_private_event_class *bt_private_event_class_create( struct bt_private_stream_class *stream_class); diff --git a/include/babeltrace/trace-ir/private-event.h b/include/babeltrace/trace-ir/private-event.h index d6519c36..c7781d18 100644 --- a/include/babeltrace/trace-ir/private-event.h +++ b/include/babeltrace/trace-ir/private-event.h @@ -38,8 +38,12 @@ struct bt_private_event_class; struct bt_private_field; struct bt_private_packet; -extern struct bt_event *bt_event_borrow_from_private( - struct bt_private_event *priv_event); +static inline +struct bt_event *bt_private_event_borrow_event( + struct bt_private_event *priv_event) +{ + return (void *) priv_event; +} extern struct bt_private_event_class *bt_private_event_borrow_class( struct bt_private_event *event); diff --git a/include/babeltrace/trace-ir/private-field-classes.h b/include/babeltrace/trace-ir/private-field-classes.h index 4ea7afc1..2f51a944 100644 --- a/include/babeltrace/trace-ir/private-field-classes.h +++ b/include/babeltrace/trace-ir/private-field-classes.h @@ -47,8 +47,12 @@ struct bt_private_field_path; struct bt_private_field_class_signed_enumeration_mapping_ranges; struct bt_private_field_class_unsigned_enumeration_mapping_ranges; -extern struct bt_field_class *bt_field_class_borrow_from_private( - struct bt_private_field_class *priv_field_class); +static inline +struct bt_field_class *bt_private_field_class_borrow_field_class( + struct bt_private_field_class *priv_field_class) +{ + return (void *) priv_field_class; +} extern struct bt_private_field_class * bt_private_field_class_unsigned_integer_create(void); diff --git a/include/babeltrace/trace-ir/private-fields.h b/include/babeltrace/trace-ir/private-fields.h index 09479edb..6199df01 100644 --- a/include/babeltrace/trace-ir/private-fields.h +++ b/include/babeltrace/trace-ir/private-fields.h @@ -38,8 +38,12 @@ struct bt_field; struct bt_private_field; struct bt_private_field_class; -extern struct bt_field *bt_field_borrow_from_private( - struct bt_private_field *priv_field); +static inline +struct bt_field *bt_private_field_borrow_field( + struct bt_private_field *priv_field) +{ + return (void *) priv_field; +} extern struct bt_private_field_class *bt_private_field_borrow_class( struct bt_private_field *field); diff --git a/include/babeltrace/trace-ir/private-packet.h b/include/babeltrace/trace-ir/private-packet.h index 33b7786c..9e30ce90 100644 --- a/include/babeltrace/trace-ir/private-packet.h +++ b/include/babeltrace/trace-ir/private-packet.h @@ -38,8 +38,12 @@ struct bt_private_packet_header_field; struct bt_private_packet_context_field; struct bt_private_stream; -extern struct bt_packet *bt_packet_borrow_from_private( - struct bt_private_packet *priv_packet); +static inline +struct bt_packet *bt_private_packet_borrow_packet( + struct bt_private_packet *priv_packet) +{ + return (void *) priv_packet; +} extern struct bt_private_packet *bt_private_packet_create( struct bt_private_stream *stream); diff --git a/include/babeltrace/trace-ir/private-stream-class.h b/include/babeltrace/trace-ir/private-stream-class.h index f744ebc1..ab956d45 100644 --- a/include/babeltrace/trace-ir/private-stream-class.h +++ b/include/babeltrace/trace-ir/private-stream-class.h @@ -43,8 +43,12 @@ struct bt_private_trace; struct bt_private_event_class; struct bt_private_clock_class; -extern struct bt_stream_class *bt_stream_class_borrow_from_private( - struct bt_private_stream_class *priv_stream_class); +static inline +struct bt_stream_class *bt_private_stream_class_borrow_stream_class( + struct bt_private_stream_class *priv_stream_class) +{ + return (void *) priv_stream_class; +} extern struct bt_private_stream_class *bt_private_stream_class_create( struct bt_private_trace *trace); diff --git a/include/babeltrace/trace-ir/private-stream.h b/include/babeltrace/trace-ir/private-stream.h index 39e019d3..973e3908 100644 --- a/include/babeltrace/trace-ir/private-stream.h +++ b/include/babeltrace/trace-ir/private-stream.h @@ -38,8 +38,12 @@ struct bt_stream; struct bt_private_stream; struct bt_private_stream_class; -extern struct bt_stream *bt_stream_borrow_from_private( - struct bt_private_stream *priv_stream); +static inline +struct bt_stream *bt_private_stream_borrow_stream( + struct bt_private_stream *priv_stream) +{ + return (void *) priv_stream; +} extern struct bt_private_stream *bt_private_stream_create( struct bt_private_stream_class *stream_class); diff --git a/include/babeltrace/trace-ir/private-trace.h b/include/babeltrace/trace-ir/private-trace.h index 5b429494..c771ad74 100644 --- a/include/babeltrace/trace-ir/private-trace.h +++ b/include/babeltrace/trace-ir/private-trace.h @@ -51,8 +51,12 @@ typedef void (* bt_private_trace_is_static_listener)( typedef void (* bt_private_trace_listener_removed)( struct bt_private_trace *trace, void *data); -extern struct bt_trace *bt_trace_borrow_from_private( - struct bt_private_trace *priv_trace); +static inline +struct bt_trace *bt_private_trace_borrow_trace( + struct bt_private_trace *priv_trace) +{ + return (void *) priv_trace; +} extern struct bt_private_trace *bt_private_trace_create(void); diff --git a/include/babeltrace/trace-ir/resolve-field-path-internal.h b/include/babeltrace/trace-ir/resolve-field-path-internal.h index 2ea69767..d403585f 100644 --- a/include/babeltrace/trace-ir/resolve-field-path-internal.h +++ b/include/babeltrace/trace-ir/resolve-field-path-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_RESOLVE_FIELD_PATH_INTERNAL /* - * BabelTrace - Trace IR: Field path - * * Copyright 2016 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/include/babeltrace/trace-ir/stream-class-internal.h b/include/babeltrace/trace-ir/stream-class-internal.h index 6df193eb..5c19e560 100644 --- a/include/babeltrace/trace-ir/stream-class-internal.h +++ b/include/babeltrace/trace-ir/stream-class-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_STREAM_CLASS_INTERNAL_H /* - * BabelTrace - Trace IR: Stream class internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/stream-internal.h b/include/babeltrace/trace-ir/stream-internal.h index cdb87aca..7675b7f9 100644 --- a/include/babeltrace/trace-ir/stream-internal.h +++ b/include/babeltrace/trace-ir/stream-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_STREAM_INTERNAL_H /* - * BabelTrace - CTF Writer: Stream internal - * * Copyright 2013, 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/trace-internal.h b/include/babeltrace/trace-ir/trace-internal.h index 4daac738..8e8bfa0a 100644 --- a/include/babeltrace/trace-ir/trace-internal.h +++ b/include/babeltrace/trace-ir/trace-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_TRACE_INTERNAL_H /* - * BabelTrace - Trace IR: Trace internal - * * Copyright 2014 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/include/babeltrace/trace-ir/utils-internal.h b/include/babeltrace/trace-ir/utils-internal.h index 9e859546..7ade7e0f 100644 --- a/include/babeltrace/trace-ir/utils-internal.h +++ b/include/babeltrace/trace-ir/utils-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_TRACE_IR_UTILS_INTERNAL_H /* - * Babeltrace - Internal Trace IR utilities - * * 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 diff --git a/include/babeltrace/values-internal.h b/include/babeltrace/values-internal.h index c9c728c3..4056fe2e 100644 --- a/include/babeltrace/values-internal.h +++ b/include/babeltrace/values-internal.h @@ -2,8 +2,6 @@ #define BABELTRACE_VALUES_INTERNAL_H /* - * Babeltrace - Value objects - * * Copyright (c) 2015-2017 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015-2017 Philippe Proulx * diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 5bb43335..5919b3dd 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -2,8 +2,6 @@ #define BABELTRACE_VALUES_H /* - * Babeltrace - Value objects - * * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015-2016 Philippe Proulx * diff --git a/lib/babeltrace.c b/lib/babeltrace.c index ab2b6bc8..35006c7c 100644 --- a/lib/babeltrace.c +++ b/lib/babeltrace.c @@ -1,8 +1,4 @@ /* - * babeltrace.c - * - * Babeltrace Library - * * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation * * Author: Mathieu Desnoyers diff --git a/lib/ctf-writer/attributes.c b/lib/ctf-writer/attributes.c index 828ac9d7..5b4529f0 100644 --- a/lib/ctf-writer/attributes.c +++ b/lib/ctf-writer/attributes.c @@ -81,7 +81,7 @@ void bt_ctf_attributes_destroy(struct bt_private_value *attr_obj) BT_HIDDEN int64_t bt_ctf_attributes_get_count(struct bt_private_value *attr_obj) { - return bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); + return bt_value_array_get_size(bt_private_value_borrow_value(attr_obj)); } BT_HIDDEN @@ -97,10 +97,10 @@ const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, goto end; } - if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { + if (index >= bt_value_array_get_size(bt_private_value_borrow_value(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))); + index, bt_value_array_get_size(bt_private_value_borrow_value(attr_obj))); goto end; } @@ -123,7 +123,7 @@ const char *bt_ctf_attributes_get_field_name(struct bt_private_value *attr_obj, } ret = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj)); + bt_private_value_borrow_value(attr_field_name_obj)); end: return ret; @@ -141,10 +141,10 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_value(struct bt_private_ goto end; } - if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { + if (index >= bt_value_array_get_size(bt_private_value_borrow_value(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))); + index, bt_value_array_get_size(bt_private_value_borrow_value(attr_obj))); goto end; } @@ -177,7 +177,7 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name( struct bt_private_value *value_obj = NULL; struct bt_private_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); + attr_size = bt_value_array_get_size(bt_private_value_borrow_value(attr_obj)); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -204,7 +204,7 @@ struct bt_private_value *bt_ctf_attributes_borrow_field_by_name( } field_name = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj)); + bt_private_value_borrow_value(attr_field_name_obj)); if (!strcmp(field_name, name)) { break; @@ -239,7 +239,7 @@ int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj, if (attr_field_obj) { ret = bt_private_value_array_set_element_by_index( attr_field_obj, BT_CTF_ATTR_VALUE_INDEX, - bt_value_borrow_from_private(value_obj)); + bt_private_value_borrow_value(value_obj)); attr_field_obj = NULL; goto end; } @@ -253,7 +253,7 @@ int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj, ret = bt_private_value_array_append_string_element(attr_field_obj, name); ret |= bt_private_value_array_append_element(attr_field_obj, - bt_value_borrow_from_private(value_obj)); + bt_private_value_borrow_value(value_obj)); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); @@ -261,7 +261,7 @@ int bt_ctf_attributes_set_field_value(struct bt_private_value *attr_obj, } ret = bt_private_value_array_append_element(attr_obj, - bt_value_borrow_from_private(attr_field_obj)); + bt_private_value_borrow_value(attr_field_obj)); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -319,7 +319,7 @@ int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); + count = bt_value_array_get_size(bt_private_value_borrow_value(attr_obj)); BT_ASSERT(count >= 0); /* @@ -339,7 +339,7 @@ int bt_ctf_attributes_freeze(struct bt_private_value *attr_obj) goto end; } - bt_value_freeze(bt_value_borrow_from_private(obj)); + bt_value_freeze(bt_private_value_borrow_value(obj)); } end: diff --git a/lib/ctf-writer/trace.c b/lib/ctf-writer/trace.c index 7f5f3d55..fd04695c 100644 --- a/lib/ctf-writer/trace.c +++ b/lib/ctf-writer/trace.c @@ -261,15 +261,15 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, goto end; } - if (!bt_value_is_integer(bt_value_borrow_from_private(value)) && - !bt_value_is_string(bt_value_borrow_from_private(value))) { + if (!bt_value_is_integer(bt_private_value_borrow_value(value)) && + !bt_value_is_string(bt_private_value_borrow_value(value))) { BT_LOGW("Invalid parameter: environment field's value is not an integer or string value: " "trace-addr=%p, trace-name=\"%s\", " "env-name=\"%s\", env-value-type=%s", trace, bt_ctf_trace_common_get_name(trace), name, bt_common_value_type_string( bt_value_get_type( - bt_value_borrow_from_private(value)))); + bt_private_value_borrow_value(value)))); ret = -1; goto end; } @@ -294,7 +294,7 @@ int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace, goto end; } - bt_value_freeze(bt_value_borrow_from_private(value)); + bt_value_freeze(bt_private_value_borrow_value(value)); } ret = bt_ctf_attributes_set_field_value(trace->environment, name, @@ -1760,13 +1760,13 @@ void append_env_metadata(struct bt_ctf_trace *trace, BT_ASSERT(env_field_value_obj); switch (bt_value_get_type( - bt_value_borrow_from_private(env_field_value_obj))) { + bt_private_value_borrow_value(env_field_value_obj))) { case BT_VALUE_TYPE_INTEGER: { int64_t int_value; int_value = bt_value_integer_get( - bt_value_borrow_from_private( + bt_private_value_borrow_value( env_field_value_obj)); g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", entry_name, @@ -1779,7 +1779,7 @@ void append_env_metadata(struct bt_ctf_trace *trace, char *escaped_str = NULL; str_value = bt_value_string_get( - bt_value_borrow_from_private( + bt_private_value_borrow_value( env_field_value_obj)); escaped_str = g_strescape(str_value, NULL); if (!escaped_str) { diff --git a/lib/graph/Makefile.am b/lib/graph/Makefile.am index 3dcf50dd..6be66696 100644 --- a/lib/graph/Makefile.am +++ b/lib/graph/Makefile.am @@ -4,16 +4,16 @@ noinst_LTLIBRARIES = libgraph.la # Graph library libgraph_la_SOURCES = \ - component.c \ + component-class-sink-colander.c \ component-class.c \ - graph.c \ + component-filter.c \ + component-sink.c \ + component-source.c \ + component.c \ connection.c \ - port.c \ - source.c \ - sink.c \ - filter.c \ + graph.c \ iterator.c \ - component-class-sink-colander.c \ + port.c \ query-executor.c libgraph_la_LIBADD = \ diff --git a/lib/graph/component-class-sink-colander.c b/lib/graph/component-class-sink-colander.c index f1067d41..a40f8ea0 100644 --- a/lib/graph/component-class-sink-colander.c +++ b/lib/graph/component-class-sink-colander.c @@ -25,138 +25,140 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include static -struct bt_component_class *colander_comp_cls; +struct bt_private_component_class_sink *colander_comp_cls; struct colander_data { bt_notification_array notifs; uint64_t *count_addr; - struct bt_notification_iterator *notif_iter; + struct bt_self_component_port_input_notification_iterator *notif_iter; }; static -enum bt_component_status colander_init( - struct bt_private_component *priv_comp, +enum bt_self_component_status colander_init( + struct bt_self_component_sink *self_comp, struct bt_value *params, void *init_method_data) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct colander_data *colander_data = NULL; struct bt_component_class_sink_colander_data *user_provided_data = init_method_data; if (!init_method_data) { BT_LOGW_STR("Component initialization method data is NULL."); - status = BT_COMPONENT_STATUS_INVALID; + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } colander_data = g_new0(struct colander_data, 1); if (!colander_data) { BT_LOGE_STR("Failed to allocate colander data."); - status = BT_COMPONENT_STATUS_NOMEM; + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } colander_data->notifs = user_provided_data->notifs; colander_data->count_addr = user_provided_data->count_addr; - status = bt_private_component_sink_add_input_port( - priv_comp, "in", NULL, NULL); - if (status != BT_COMPONENT_STATUS_OK) { + status = bt_self_component_sink_add_input_port(self_comp, "in", + NULL, NULL); + if (status != BT_SELF_COMPONENT_STATUS_OK) { BT_LOGE_STR("Cannot add input port."); goto end; } - (void) bt_private_component_set_user_data(priv_comp, colander_data); + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(self_comp), + colander_data); end: return status; } static -void colander_finalize(struct bt_private_component *priv_comp) +void colander_finalize(struct bt_self_component_sink *self_comp) { struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); if (!colander_data) { return; } - if (colander_data->notif_iter) { - bt_object_put_ref(colander_data->notif_iter); - } - + BT_OBJECT_PUT_REF_AND_RESET(colander_data->notif_iter); g_free(colander_data); } static -enum bt_component_status colander_port_connected(struct bt_private_component *priv_comp, - struct bt_private_port *self_priv_port, - struct bt_port *other_port) +enum bt_self_component_status colander_input_port_connected( + struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - enum bt_connection_status conn_status; - struct bt_private_connection *priv_conn = - bt_private_port_get_connection(self_priv_port); + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); - BT_ASSERT(priv_conn); BT_ASSERT(colander_data); BT_OBJECT_PUT_REF_AND_RESET(colander_data->notif_iter); - conn_status = bt_private_connection_create_notification_iterator( - priv_conn, &colander_data->notif_iter); - if (conn_status) { - BT_LOGE("Cannot create notification iterator from connection: " - "comp-addr=%p, conn-addr=%p", priv_comp, priv_conn); - status = BT_COMPONENT_STATUS_ERROR; + colander_data->notif_iter = + bt_self_component_port_input_notification_iterator_create( + self_port); + if (!colander_data->notif_iter) { + BT_LIB_LOGE("Cannot create notification iterator on " + "self component input port: %![port-]+p", + self_port); + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } end: - bt_object_put_ref(priv_conn); return status; } static -enum bt_component_status colander_consume( - struct bt_private_component *priv_comp) +enum bt_self_component_status colander_consume( + struct bt_self_component_sink *self_comp) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; enum bt_notification_iterator_status notif_iter_status; struct colander_data *colander_data = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(self_comp)); bt_notification_array notifs; BT_ASSERT(colander_data); if (!colander_data->notif_iter) { - BT_LOGW("Trying to consume without an upstream notification iterator: " - "comp-addr=%p", priv_comp); + BT_LIB_LOGW("Trying to consume without an " + "upstream notification iterator: %![comp-]+c", + self_comp); goto end; } - notif_iter_status = bt_private_connection_notification_iterator_next( - colander_data->notif_iter, ¬ifs, colander_data->count_addr); + notif_iter_status = + bt_self_component_port_input_notification_iterator_next( + colander_data->notif_iter, ¬ifs, + colander_data->count_addr); switch (notif_iter_status) { case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED: - status = BT_COMPONENT_STATUS_OK; + status = BT_SELF_COMPONENT_STATUS_OK; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - status = BT_COMPONENT_STATUS_AGAIN; + status = BT_SELF_COMPONENT_STATUS_AGAIN; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_END: - status = BT_COMPONENT_STATUS_END; + status = BT_SELF_COMPONENT_STATUS_END; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_OK: /* Move notifications to user (count already set) */ @@ -164,38 +166,38 @@ enum bt_component_status colander_consume( sizeof(*notifs) * *colander_data->count_addr); break; default: - status = BT_COMPONENT_STATUS_ERROR; + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } end: - /* Move notification to user's pointer, even if NULL. */ return status; } -struct bt_component_class *bt_component_class_sink_colander_get(void) +struct bt_component_class_sink *bt_component_class_sink_colander_get(void) { if (colander_comp_cls) { goto end; } - colander_comp_cls = bt_component_class_sink_create("colander", - colander_consume); + colander_comp_cls = bt_private_component_class_sink_create( + "colander", colander_consume); if (!colander_comp_cls) { BT_LOGE_STR("Cannot create sink colander component class."); goto end; } - (void) bt_component_class_set_init_method(colander_comp_cls, - colander_init); - (void) bt_component_class_set_finalize_method(colander_comp_cls, - colander_finalize); - (void) bt_component_class_set_port_connected_method(colander_comp_cls, - colander_port_connected); - (void) bt_component_class_freeze(colander_comp_cls); + (void) bt_private_component_class_sink_set_init_method( + colander_comp_cls, colander_init); + (void) bt_private_component_class_sink_set_finalize_method( + colander_comp_cls, colander_finalize); + (void) bt_private_component_class_sink_set_input_port_connected_method( + colander_comp_cls, colander_input_port_connected); end: - return bt_object_get_ref(colander_comp_cls); + return bt_object_get_ref( + bt_private_component_class_sink_borrow_component_class_sink( + colander_comp_cls)); } __attribute__((destructor)) static diff --git a/lib/graph/component-class.c b/lib/graph/component-class.c index 5a306fb8..36d3970f 100644 --- a/lib/graph/component-class.c +++ b/lib/graph/component-class.c @@ -1,8 +1,4 @@ /* - * component-class.c - * - * Babeltrace Plugin Component Class - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -30,14 +26,23 @@ #include #include +#include +#include +#include +#include #include #include #include #include +#include #include +#define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \ + BT_ASSERT_PRE_HOT(((struct bt_component_class *) (_cc)), \ + "Component class", ": %!+C", (_cc)) + static -void bt_component_class_destroy(struct bt_object *obj) +void destroy_component_class(struct bt_object *obj) { struct bt_component_class *class; int i; @@ -45,10 +50,7 @@ void bt_component_class_destroy(struct bt_object *obj) BT_ASSERT(obj); class = container_of(obj, struct bt_component_class, base); - BT_LOGD("Destroying component class: " - "addr=%p, name=\"%s\", type=%s", - class, bt_component_class_get_name(class), - bt_component_class_type_string(class->type)); + BT_LIB_LOGD("Destroying component class: %!+C", class); /* Call destroy listeners in reverse registration order */ for (i = class->destroy_listeners->len - 1; i >= 0; i--) { @@ -64,15 +66,22 @@ void bt_component_class_destroy(struct bt_object *obj) if (class->name) { g_string_free(class->name, TRUE); + class->name = NULL; } + if (class->description) { g_string_free(class->description, TRUE); + class->description = NULL; } + if (class->help) { g_string_free(class->help, TRUE); + class->help = NULL; } + if (class->destroy_listeners) { g_array_free(class->destroy_listeners, TRUE); + class->destroy_listeners = NULL; } g_free(class); @@ -84,7 +93,7 @@ int bt_component_class_init(struct bt_component_class *class, { int ret = 0; - bt_object_init_shared(&class->base, bt_component_class_destroy); + bt_object_init_shared(&class->base, destroy_component_class); class->type = type; class->name = g_string_new(name); if (!class->name) { @@ -121,22 +130,16 @@ end: return ret; } -struct bt_component_class *bt_component_class_source_create(const char *name, - bt_component_class_notification_iterator_next_method method) +struct bt_private_component_class_source * +bt_private_component_class_source_create( + const char *name, + bt_private_component_class_source_notification_iterator_next_method method) { struct bt_component_class_source *source_class = NULL; int ret; - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); BT_LOGD("Creating source component class: " "name=\"%s\", notif-iter-next-method-addr=%p", name, method); @@ -159,31 +162,22 @@ struct bt_component_class *bt_component_class_source_create(const char *name, goto end; } - source_class->methods.iterator.next = method; - BT_LOGD("Created source component class: " - "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p", - name, method, &source_class->parent); + source_class->methods.notif_iter_next = method; + BT_LIB_LOGD("Created source component class: %!+C", source_class); end: - return &source_class->parent; + return (void *) source_class; } -struct bt_component_class *bt_component_class_filter_create(const char *name, - bt_component_class_notification_iterator_next_method method) +struct bt_private_component_class_filter * +bt_private_component_class_filter_create(const char *name, + bt_private_component_class_filter_notification_iterator_next_method method) { struct bt_component_class_filter *filter_class = NULL; int ret; - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); BT_LOGD("Creating filter component class: " "name=\"%s\", notif-iter-next-method-addr=%p", name, method); @@ -206,31 +200,22 @@ struct bt_component_class *bt_component_class_filter_create(const char *name, goto end; } - filter_class->methods.iterator.next = method; - BT_LOGD("Created filter component class: " - "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p", - name, method, &filter_class->parent); + filter_class->methods.notif_iter_next = method; + BT_LIB_LOGD("Created filter component class: %!+C", filter_class); end: - return &filter_class->parent; + return (void *) filter_class; } -struct bt_component_class *bt_component_class_sink_create(const char *name, - bt_component_class_sink_consume_method method) +struct bt_private_component_class_sink *bt_private_component_class_sink_create( + const char *name, + bt_private_component_class_sink_consume_method method) { struct bt_component_class_sink *sink_class = NULL; int ret; - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); BT_LOGD("Creating sink component class: " "name=\"%s\", consume-method-addr=%p", name, method); @@ -254,613 +239,469 @@ struct bt_component_class *bt_component_class_sink_create(const char *name, } sink_class->methods.consume = method; - BT_LOGD("Created sink component class: " - "name=\"%s\", consume-method-addr=%p, addr=%p", - name, method, &sink_class->parent); + BT_LIB_LOGD("Created sink component class: %!+C", sink_class); end: - return &sink_class->parent; + return (void *) sink_class; } -int bt_component_class_set_init_method( - struct bt_component_class *component_class, - bt_component_class_init_method method) +int bt_private_component_class_source_set_init_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_init_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.init = method; - BT_LOGV("Set component class's initialization method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.init = method; + BT_LIB_LOGV("Set source component class's initialization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_set_query_method( - struct bt_component_class *component_class, - bt_component_class_query_method method) +int bt_private_component_class_filter_set_init_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_init_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.query = method; - BT_LOGV("Set component class's query method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.init = method; + BT_LIB_LOGV("Set filter component class's initialization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_set_accept_port_connection_method( - struct bt_component_class *component_class, - bt_component_class_accept_port_connection_method method) +int bt_private_component_class_sink_set_init_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_init_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.accept_port_connection = method; - BT_LOGV("Set component class's \"accept port connection\" method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.init = method; + BT_LIB_LOGV("Set sink component class's initialization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_set_port_connected_method( - struct bt_component_class *component_class, - bt_component_class_port_connected_method method) +int bt_private_component_class_source_set_finalize_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_finalize_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.port_connected = method; - BT_LOGV("Set component class's \"port connected\" method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.finalize = method; + BT_LIB_LOGV("Set source component class's finalization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_set_port_disconnected_method( - struct bt_component_class *component_class, - bt_component_class_port_disconnected_method method) +int bt_private_component_class_filter_set_finalize_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_finalize_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.port_disconnected = method; - BT_LOGV("Set component class's \"port disconnected\" method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.finalize = method; + BT_LIB_LOGV("Set filter component class's finalization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_set_finalize_method( - struct bt_component_class *component_class, - bt_component_class_finalize_method method) +int bt_private_component_class_sink_set_finalize_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_finalize_method method) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - component_class->methods.finalize = method; - BT_LOGV("Set component class's finalization method: " - "addr=%p, name=\"%s\", type=%s, method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - method); - -end: - return ret; + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.finalize = method; + BT_LIB_LOGV("Set sink component class's finalization method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_source_set_notification_iterator_init_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_init_method method) +int bt_private_component_class_source_set_query_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_query_method method) { - struct bt_component_class_source *source_class; - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component class is not a source component class: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - source_class = container_of(component_class, - struct bt_component_class_source, parent); - source_class->methods.iterator.init = method; - BT_LOGV("Set filter component class's notification iterator initialization method: " - "addr=%p, name=\"%s\", method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - method); - -end: - return ret; + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.query = method; + BT_LIB_LOGV("Set source component class's query method: " + "%!+C", comp_cls); + return 0; } -int bt_component_class_source_set_notification_iterator_finalize_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_finalize_method method) +int bt_private_component_class_filter_set_query_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_query_method method) { - struct bt_component_class_source *source_class; - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } - - if (component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component class is not a source component class: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.query = method; + BT_LIB_LOGV("Set filter component class's query method: " + "%!+C", comp_cls); + return 0; +} - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } +int bt_private_component_class_sink_set_query_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_query_method method) +{ + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.query = method; + BT_LIB_LOGV("Set sink component class's query method: " + "%!+C", comp_cls); + return 0; +} - source_class = container_of(component_class, - struct bt_component_class_source, parent); - source_class->methods.iterator.finalize = - method; - BT_LOGV("Set filter component class's notification iterator finalization method: " - "addr=%p, name=\"%s\", method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - method); +int bt_private_component_class_filter_set_accept_input_port_connection_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_accept_input_port_connection_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.accept_input_port_connection = method; + BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method" + ": %!+C", comp_cls); + return 0; +} -end: - return ret; +int bt_private_component_class_sink_set_accept_input_port_connection_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_accept_input_port_connection_method method) +{ + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.accept_input_port_connection = method; + BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method" + ": %!+C", comp_cls); + return 0; } -int bt_component_class_filter_set_notification_iterator_init_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_init_method method) +int bt_private_component_class_source_set_accept_output_port_connection_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_accept_output_port_connection_method method) { - struct bt_component_class_filter *filter_class; - int ret = 0; + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.accept_output_port_connection = method; + BT_LIB_LOGV("Set source component class's \"accept output port connection\" method" + ": %!+C", comp_cls); + return 0; +} - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } +int bt_private_component_class_filter_set_accept_output_port_connection_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_accept_output_port_connection_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.accept_output_port_connection = method; + BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method" + ": %!+C", comp_cls); + return 0; +} - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } +int bt_private_component_class_filter_set_input_port_connected_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_input_port_connected_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.input_port_connected = method; + BT_LIB_LOGV("Set filter component class's \"input port connected\" method" + ": %!+C", comp_cls); + return 0; +} - if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component class is not a filter component class: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } +int bt_private_component_class_sink_set_input_port_connected_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_input_port_connected_method method) +{ + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.input_port_connected = method; + BT_LIB_LOGV("Set sink component class's \"input port connected\" method" + ": %!+C", comp_cls); + return 0; +} - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } +int bt_private_component_class_source_set_output_port_connected_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_output_port_connected_method method) +{ + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.output_port_connected = method; + BT_LIB_LOGV("Set source component class's \"output port connected\" method" + ": %!+C", comp_cls); + return 0; +} - filter_class = container_of(component_class, - struct bt_component_class_filter, parent); - filter_class->methods.iterator.init = method; - BT_LOGV("Set filter component class's notification iterator initialization method: " - "addr=%p, name=\"%s\", method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - method); +int bt_private_component_class_filter_set_output_port_connected_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_output_port_connected_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.output_port_connected = method; + BT_LIB_LOGV("Set filter component class's \"output port connected\" method" + ": %!+C", comp_cls); + return 0; +} -end: - return ret; +int bt_private_component_class_filter_set_input_port_disconnected_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_input_port_disconnected_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.input_port_disconnected = method; + BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method" + ": %!+C", comp_cls); + return 0; } -int bt_component_class_filter_set_notification_iterator_finalize_method( - struct bt_component_class *component_class, - bt_component_class_notification_iterator_finalize_method method) +int bt_private_component_class_sink_set_input_port_disconnected_method( + struct bt_private_component_class_sink *priv_comp_cls, + bt_private_component_class_sink_input_port_disconnected_method method) { - struct bt_component_class_filter *filter_class; - int ret = 0; + struct bt_component_class_sink *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.input_port_disconnected = method; + BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method" + ": %!+C", comp_cls); + return 0; +} - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } +int bt_private_component_class_source_set_output_port_disconnected_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_output_port_disconnected_method method) +{ + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.output_port_disconnected = method; + BT_LIB_LOGV("Set source component class's \"output port disconnected\" method" + ": %!+C", comp_cls); + return 0; +} - if (!method) { - BT_LOGW_STR("Invalid parameter: method is NULL."); - ret = -1; - goto end; - } +int bt_private_component_class_filter_set_output_port_disconnected_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_output_port_disconnected_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.output_port_disconnected = method; + BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method" + ": %!+C", comp_cls); + return 0; +} - if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component class is not a filter component class: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } +int bt_private_component_class_source_set_notification_iterator_init_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_notification_iterator_init_method method) +{ + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.notif_iter_init = method; + BT_LIB_LOGV("Set source component class's notification iterator initialization method" + ": %!+C", comp_cls); + return 0; +} - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } +int bt_private_component_class_filter_set_notification_iterator_init_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_notification_iterator_init_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.notif_iter_init = method; + BT_LIB_LOGV("Set filter component class's notification iterator initialization method" + ": %!+C", comp_cls); + return 0; +} - filter_class = container_of(component_class, - struct bt_component_class_filter, parent); - filter_class->methods.iterator.finalize = - method; - BT_LOGV("Set filter component class's notification iterator finalization method: " - "addr=%p, name=\"%s\", method-addr=%p", - component_class, - bt_component_class_get_name(component_class), - method); +int bt_private_component_class_source_set_notification_iterator_finalize_method( + struct bt_private_component_class_source *priv_comp_cls, + bt_private_component_class_source_notification_iterator_finalize_method method) +{ + struct bt_component_class_source *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.notif_iter_finalize = method; + BT_LIB_LOGV("Set source component class's notification iterator finalization method" + ": %!+C", comp_cls); + return 0; +} -end: - return ret; +int bt_private_component_class_filter_set_notification_iterator_finalize_method( + struct bt_private_component_class_filter *priv_comp_cls, + bt_private_component_class_filter_notification_iterator_finalize_method method) +{ + struct bt_component_class_filter *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + comp_cls->methods.notif_iter_finalize = method; + BT_LIB_LOGV("Set filter component class's notification iterator finalization method" + ": %!+C", comp_cls); + return 0; } -int bt_component_class_set_description( - struct bt_component_class *component_class, +int bt_private_component_class_set_description( + struct bt_private_component_class *priv_comp_cls, const char *description) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!description) { - BT_LOGW_STR("Invalid parameter: description is NULL."); - ret = -1; - goto end; - } + struct bt_component_class *comp_cls = (void *) priv_comp_cls; - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - g_string_assign(component_class->description, description); - BT_LOGV("Set component class's description: " + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(description, "Description"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + g_string_assign(comp_cls->description, description); + BT_LIB_LOGV("Set component class's description: " "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - -end: - return ret; + comp_cls, + bt_component_class_get_name(comp_cls), + bt_component_class_type_string(comp_cls->type)); + return 0; } -int bt_component_class_set_help( - struct bt_component_class *component_class, +int bt_private_component_class_set_help( + struct bt_private_component_class *priv_comp_cls, const char *help) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (!help) { - BT_LOGW_STR("Invalid parameter: help is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - BT_LOGW("Invalid parameter: component class is frozen: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret = -1; - goto end; - } - - g_string_assign(component_class->help, help); - BT_LOGV("Set component class's help text: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - -end: - return ret; + struct bt_component_class *comp_cls = (void *) priv_comp_cls; + + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(help, "Help"); + BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); + g_string_assign(comp_cls->help, help); + BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls); + return 0; } -const char *bt_component_class_get_name( - struct bt_component_class *component_class) +const char *bt_component_class_get_name(struct bt_component_class *comp_cls) { - return component_class ? component_class->name->str : NULL; + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return comp_cls->name->str; } enum bt_component_class_type bt_component_class_get_type( - struct bt_component_class *component_class) + struct bt_component_class *comp_cls) { - return component_class ? component_class->type : - BT_COMPONENT_CLASS_TYPE_UNKNOWN; + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return comp_cls->type; } const char *bt_component_class_get_description( - struct bt_component_class *component_class) + struct bt_component_class *comp_cls) { - return component_class && component_class->description && - component_class->description->str[0] != '\0' ? - component_class->description->str : NULL; + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return comp_cls->description && + comp_cls->description->str[0] != '\0' ? + comp_cls->description->str : NULL; } const char *bt_component_class_get_help( - struct bt_component_class *component_class) + struct bt_component_class *comp_cls) { - return component_class && component_class->help && - component_class->help->str[0] != '\0' ? - component_class->help->str : NULL; + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return comp_cls->help && + comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; } BT_HIDDEN -void bt_component_class_add_destroy_listener(struct bt_component_class *class, +void bt_component_class_add_destroy_listener( + struct bt_component_class *comp_cls, bt_component_class_destroy_listener_func func, void *data) { struct bt_component_class_destroy_listener listener; - BT_ASSERT(class); + BT_ASSERT(comp_cls); BT_ASSERT(func); listener.func = func; listener.data = data; - g_array_append_val(class->destroy_listeners, listener); - BT_LOGV("Component class has no registered query method: " - "comp-class-addr=%p, comp-class-name=\"%s\", comp-class-type=%s" - "func-addr=%p, data-addr=%p", - class, - bt_component_class_get_name(class), - bt_component_class_type_string(class->type), - func, data); + g_array_append_val(comp_cls->destroy_listeners, listener); + BT_LIB_LOGV("Added destroy listener to component class: " + "%![cc-]+C, listener-func-addr=%p", comp_cls, func); } -int bt_component_class_freeze( - struct bt_component_class *component_class) +BT_HIDDEN +void _bt_component_class_freeze(struct bt_component_class *comp_cls) { - int ret = 0; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret = -1; - goto end; - } - - if (component_class->frozen) { - goto end; - } - - BT_LOGD("Freezing component class: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - component_class->frozen = BT_TRUE; - -end: - return ret; + BT_ASSERT(comp_cls); + BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); + comp_cls->frozen = true; } diff --git a/lib/graph/component-filter.c b/lib/graph/component-filter.c new file mode 100644 index 00000000..d9cb06e3 --- /dev/null +++ b/lib/graph/component-filter.c @@ -0,0 +1,192 @@ +/* + * Copyright 2016 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define BT_LOG_TAG "COMP-FILTER" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +BT_HIDDEN +void bt_component_filter_destroy(struct bt_component *component) +{ +} + +BT_HIDDEN +struct bt_component *bt_component_filter_create( + struct bt_component_class *class) +{ + struct bt_component_filter *filter = NULL; + + filter = g_new0(struct bt_component_filter, 1); + if (!filter) { + BT_LOGE_STR("Failed to allocate one filter component."); + goto end; + } + +end: + return (void *) filter; +} + +uint64_t bt_component_filter_get_output_port_count( + struct bt_component_filter *comp) +{ + return bt_component_get_output_port_count((void *) comp); +} + +struct bt_port_output *bt_component_filter_borrow_output_port_by_name( + struct bt_component_filter *comp, const char *name) +{ + return bt_component_borrow_output_port_by_name( + (void *) comp, name); +} + +struct bt_self_component_port_output * +bt_self_component_filter_borrow_output_port_by_name( + struct bt_self_component_filter *comp, const char *name) +{ + return (void *) bt_component_borrow_output_port_by_name( + (void *) comp, name); +} + +struct bt_port_output *bt_component_filter_borrow_output_port_by_index( + struct bt_component_filter *comp, uint64_t index) +{ + return bt_component_borrow_output_port_by_index( + (void *) comp, index); +} + +struct bt_self_component_port_output * +bt_self_component_filter_borrow_output_port_by_index( + struct bt_self_component_filter *comp, uint64_t index) +{ + return (void *) bt_component_borrow_output_port_by_index( + (void *) comp, index); +} + +enum bt_self_component_status bt_self_component_filter_add_output_port( + struct bt_self_component_filter *self_comp, + const char *name, void *user_data, + struct bt_self_component_port_output **self_port) +{ + struct bt_component *comp = (void *) self_comp; + int status = BT_SELF_COMPONENT_STATUS_OK; + struct bt_port *port = NULL; + + /* bt_component_add_output_port() logs details and errors */ + port = (void *) bt_component_add_output_port(comp, name, user_data); + if (!port) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (self_port) { + /* Move reference to user */ + *self_port = (void *) port; + port = NULL; + } + +end: + bt_object_put_ref(port); + return status; +} + +uint64_t bt_component_filter_get_input_port_count( + struct bt_component_filter *component) +{ + /* bt_component_get_input_port_count() logs details/errors */ + return bt_component_get_input_port_count((void *) component); +} + +struct bt_port_input *bt_component_filter_borrow_input_port_by_name( + struct bt_component_filter *component, const char *name) +{ + /* bt_component_borrow_input_port_by_name() logs details/errors */ + return bt_component_borrow_input_port_by_name( + (void *) component, name); +} + +struct bt_self_component_port_input * +bt_self_component_filter_borrow_input_port_by_name( + struct bt_self_component_filter *component, const char *name) +{ + /* bt_component_borrow_input_port_by_name() logs details/errors */ + return (void *) bt_component_borrow_input_port_by_name( + (void *) component, name); +} + +struct bt_port_input *bt_component_filter_borrow_input_port_by_index( + struct bt_component_filter *component, uint64_t index) +{ + /* bt_component_borrow_input_port_by_index() logs details/errors */ + return bt_component_borrow_input_port_by_index( + (void *) component, index); +} + +struct bt_self_component_port_input * +bt_self_component_filter_borrow_input_port_by_index( + struct bt_self_component_filter *component, uint64_t index) +{ + /* bt_component_borrow_input_port_by_index() logs details/errors */ + return (void *) bt_component_borrow_input_port_by_index( + (void *) component, index); +} + +enum bt_self_component_status bt_self_component_filter_add_input_port( + struct bt_self_component_filter *self_comp, + const char *name, void *user_data, + struct bt_self_component_port_input **self_port) +{ + int status = BT_SELF_COMPONENT_STATUS_OK; + struct bt_port *port = NULL; + struct bt_component *comp = (void *) self_comp; + + /* bt_component_add_input_port() logs details/errors */ + port = (void *) bt_component_add_input_port(comp, name, user_data); + if (!port) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (self_port) { + /* Move reference to user */ + *self_port = (void *) port; + port = NULL; + } + +end: + bt_object_put_ref(port); + return status; +} diff --git a/lib/graph/component-sink.c b/lib/graph/component-sink.c new file mode 100644 index 00000000..65403b8a --- /dev/null +++ b/lib/graph/component-sink.c @@ -0,0 +1,125 @@ +/* + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define BT_LOG_TAG "COMP-SINK" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +BT_HIDDEN +void bt_component_sink_destroy(struct bt_component *component) +{ +} + +BT_HIDDEN +struct bt_component *bt_component_sink_create(struct bt_component_class *class) +{ + struct bt_component_sink *sink = NULL; + + sink = g_new0(struct bt_component_sink, 1); + if (!sink) { + BT_LOGE_STR("Failed to allocate one sink component."); + goto end; + } + +end: + return (void *) sink; +} + +uint64_t bt_component_sink_get_input_port_count( + struct bt_component_sink *component) +{ + /* bt_component_get_input_port_count() logs details/errors */ + return bt_component_get_input_port_count((void *) component); +} + +struct bt_port_input *bt_component_sink_borrow_input_port_by_name( + struct bt_component_sink *component, const char *name) +{ + /* bt_component_borrow_input_port_by_name() logs details/errors */ + return bt_component_borrow_input_port_by_name((void *) component, name); +} + +struct bt_self_component_port_input * +bt_self_component_sink_borrow_input_port_by_name( + struct bt_self_component_sink *component, const char *name) +{ + /* bt_component_borrow_input_port_by_name() logs details/errors */ + return (void *) bt_component_borrow_input_port_by_name( + (void *) component, name); +} + +struct bt_port_input *bt_component_sink_borrow_input_port_by_index( + struct bt_component_sink *component, uint64_t index) +{ + /* bt_component_borrow_input_port_by_index() logs details/errors */ + return bt_component_borrow_input_port_by_index( + (void *) component, index); +} + +struct bt_self_component_port_input * +bt_self_component_sink_borrow_input_port_by_index( + struct bt_self_component_sink *component, uint64_t index) +{ + /* bt_component_borrow_input_port_by_index() logs details/errors */ + return (void *) bt_component_borrow_input_port_by_index( + (void *) component, index); +} + +enum bt_self_component_status bt_self_component_sink_add_input_port( + struct bt_self_component_sink *self_comp, + const char *name, void *user_data, + struct bt_self_component_port_input **self_port) +{ + int status = BT_SELF_COMPONENT_STATUS_OK; + struct bt_port *port = NULL; + struct bt_component *comp = (void *) self_comp; + + /* bt_component_add_input_port() logs details/errors */ + port = (void *) bt_component_add_input_port(comp, name, user_data); + if (!port) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (self_port) { + /* Move reference to user */ + *self_port = (void *) port; + port = NULL; + } + +end: + bt_object_put_ref(port); + return status; +} diff --git a/lib/graph/component-source.c b/lib/graph/component-source.c new file mode 100644 index 00000000..2d5039aa --- /dev/null +++ b/lib/graph/component-source.c @@ -0,0 +1,121 @@ +/* + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define BT_LOG_TAG "COMP-SOURCE" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +BT_HIDDEN +void bt_component_source_destroy(struct bt_component *component) +{ +} + +BT_HIDDEN +struct bt_component *bt_component_source_create( + struct bt_component_class *class) +{ + struct bt_component_source *source = NULL; + + source = g_new0(struct bt_component_source, 1); + if (!source) { + BT_LOGE_STR("Failed to allocate one source component."); + goto end; + } + +end: + return (void *) source; +} + +uint64_t bt_component_source_get_output_port_count( + struct bt_component_source *comp) +{ + return bt_component_get_output_port_count((void *) comp); +} + +struct bt_port_output *bt_component_source_borrow_output_port_by_name( + struct bt_component_source *comp, const char *name) +{ + return bt_component_borrow_output_port_by_name((void *) comp, name); +} + +struct bt_self_component_port_output * +bt_self_component_source_borrow_output_port_by_name( + struct bt_self_component_source *comp, const char *name) +{ + return (void *) bt_component_borrow_output_port_by_name( + (void *) comp, name); +} + +struct bt_port_output *bt_component_source_borrow_output_port_by_index( + struct bt_component_source *comp, uint64_t index) +{ + return bt_component_borrow_output_port_by_index((void *) comp, index); +} + +struct bt_self_component_port_output * +bt_self_component_source_borrow_output_port_by_index( + struct bt_self_component_source *comp, uint64_t index) +{ + return (void *) bt_component_borrow_output_port_by_index( + (void *) comp, index); +} + +enum bt_self_component_status bt_self_component_source_add_output_port( + struct bt_self_component_source *self_comp, + const char *name, void *user_data, + struct bt_self_component_port_output **self_port) +{ + struct bt_component *comp = (void *) self_comp; + int status = BT_SELF_COMPONENT_STATUS_OK; + struct bt_port *port = NULL; + + /* bt_component_add_output_port() logs details and errors */ + port = (void *) bt_component_add_output_port(comp, name, user_data); + if (!port) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (self_port) { + /* Move reference to user */ + *self_port = (void *) port; + port = NULL; + } + +end: + bt_object_put_ref(port); + return status; +} diff --git a/lib/graph/component.c b/lib/graph/component.c index 6da601c8..7bca1bfd 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -25,18 +25,17 @@ #define BT_LOG_TAG "COMP" #include -#include +#include #include #include #include #include #include #include -#include #include #include #include -#include +#include #include #include #include @@ -44,6 +43,7 @@ #include #include #include +#include #include #include @@ -63,10 +63,51 @@ void (*component_destroy_funcs[])(struct bt_component *) = { }; static -void bt_component_destroy(struct bt_object *obj) +void finalize_component(struct bt_component *comp) +{ + typedef void (*method_t)(void *); + + method_t method = NULL; + + BT_ASSERT(comp); + + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_cc = (void *) comp->class; + + method = (method_t) src_cc->methods.finalize; + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_cc = (void *) comp->class; + + method = (method_t) flt_cc->methods.finalize; + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + struct bt_component_class_sink *sink_cc = (void *) comp->class; + + method = (method_t) sink_cc->methods.finalize; + break; + } + default: + abort(); + } + + if (method) { + BT_LIB_LOGD("Calling user's finalization method: " + "%![comp-]+c", comp); + method(comp); + } +} + +static +void destroy_component(struct bt_object *obj) { struct bt_component *component = NULL; - struct bt_component_class *component_class = NULL; int i; if (!obj) { @@ -77,16 +118,16 @@ void bt_component_destroy(struct bt_object *obj) * The component's reference count is 0 if we're here. Increment * it to avoid a double-destroy (possibly infinitely recursive). * This could happen for example if the component's finalization - * function does bt_object_get_ref() (or anything that causes bt_object_get_ref() to - * be called) on itself (ref. count goes from 0 to 1), and then - * bt_object_put_ref(): the reference count would go from 1 to 0 again and - * this function would be called again. + * function does bt_object_get_ref() (or anything that causes + * bt_object_get_ref() to be called) on itself (ref. count goes + * from 0 to 1), and then bt_object_put_ref(): the reference + * count would go from 1 to 0 again and this function would be + * called again. */ 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), - obj->parent); + BT_LIB_LOGD("Destroying component: %![comp-]+c, %![graph-]+g", + component, bt_component_borrow_graph(component)); /* Call destroy listeners in reverse registration order */ BT_LOGD_STR("Calling destroy listeners."); @@ -99,17 +140,13 @@ void bt_component_destroy(struct bt_object *obj) listener->func(component, listener->data); } - component_class = component->class; - /* * User data is destroyed first, followed by the concrete * component instance. Do not finalize if the component's user * initialization method failed in the first place. */ - if (component->initialized && component->class->methods.finalize) { - BT_LOGD_STR("Calling user's finalization method."); - component->class->methods.finalize( - bt_private_component_from_component(component)); + if (component->initialized) { + finalize_component(component); } if (component->destroy) { @@ -120,81 +157,62 @@ void bt_component_destroy(struct bt_object *obj) if (component->input_ports) { BT_LOGD_STR("Destroying input ports."); g_ptr_array_free(component->input_ports, TRUE); + component->input_ports = NULL; } if (component->output_ports) { BT_LOGD_STR("Destroying output ports."); g_ptr_array_free(component->output_ports, TRUE); + component->output_ports = NULL; } if (component->destroy_listeners) { g_array_free(component->destroy_listeners, TRUE); + component->destroy_listeners = NULL; } if (component->name) { g_string_free(component->name, TRUE); + component->name = NULL; } - BT_LOGD("Putting component class."); - bt_object_put_ref(component_class); + BT_LOGD_STR("Putting component class."); + BT_OBJECT_PUT_REF_AND_RESET(component->class); g_free(component); } -struct bt_component *bt_component_borrow_from_private( - struct bt_private_component *private_component) -{ - return (void *) private_component; -} - enum bt_component_class_type bt_component_get_class_type( struct bt_component *component) { - return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN; + BT_ASSERT_PRE_NON_NULL(component, "Component"); + return component->class->type; } static -struct bt_port *bt_component_add_port( +struct bt_port *add_port( struct bt_component *component, GPtrArray *ports, enum bt_port_type port_type, const char *name, void *user_data) { - size_t i; struct bt_port *new_port = NULL; struct bt_graph *graph = NULL; - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } + BT_ASSERT_PRE_NON_NULL(component, "Component"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE(strlen(name) > 0, "Name is empty"); + graph = bt_component_borrow_graph(component); + BT_ASSERT_PRE(graph && !bt_graph_is_canceled(graph), + "Component's graph is canceled: %![comp-]+c, %![graph-]+g", + component, graph); - if (strlen(name) == 0) { - BT_LOGW_STR("Invalid parameter: name is an empty string."); - goto end; - } + // TODO: Validate that the name is not already used. - BT_LOGD("Adding port to component: comp-addr=%p, comp-name=\"%s\", " + BT_LIB_LOGD("Adding port to component: %![comp-]+c, " "port-type=%s, port-name=\"%s\"", component, - bt_component_get_name(component), bt_port_type_string(port_type), name); - /* Look for a port having the same name. */ - for (i = 0; i < ports->len; i++) { - const char *port_name; - struct bt_port *port = g_ptr_array_index(ports, i); - - port_name = bt_port_get_name(port); - BT_ASSERT(port_name); - - if (!strcmp(name, port_name)) { - /* Port name clash, abort. */ - BT_LOGW("Invalid parameter: another port with the same name already exists in the component: " - "other-port-addr=%p", port); - goto end; - } - } - new_port = bt_port_create(component, port_type, name, user_data); if (!new_port) { - BT_LOGE("Cannot create port object."); + BT_LOGE_STR("Cannot create port object."); goto end; } @@ -215,35 +233,32 @@ struct bt_port *bt_component_add_port( BT_OBJECT_PUT_REF_AND_RESET(graph); } - BT_LOGD("Created and added port to component: comp-addr=%p, comp-name=\"%s\", " - "port-type=%s, port-name=\"%s\", port-addr=%p", component, - bt_component_get_name(component), - bt_port_type_string(port_type), name, new_port); + BT_LIB_LOGD("Created and added port to component: " + "%![comp-]+c, %![port-]+p", component, new_port); end: return new_port; } BT_HIDDEN -int64_t bt_component_get_input_port_count(struct bt_component *comp) +uint64_t bt_component_get_input_port_count(struct bt_component *comp) { - BT_ASSERT(comp); - return (int64_t) comp->input_ports->len; + BT_ASSERT_PRE_NON_NULL(comp, "Component"); + return (uint64_t) comp->input_ports->len; } BT_HIDDEN -int64_t bt_component_get_output_port_count(struct bt_component *comp) +uint64_t bt_component_get_output_port_count(struct bt_component *comp) { - BT_ASSERT(comp); - return (int64_t) comp->output_ports->len; + BT_ASSERT_PRE_NON_NULL(comp, "Component"); + return (uint64_t) comp->output_ports->len; } BT_HIDDEN -enum bt_component_status bt_component_create( - struct bt_component_class *component_class, +int bt_component_create(struct bt_component_class *component_class, const char *name, struct bt_component **user_component) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_component *component = NULL; enum bt_component_class_type type; @@ -252,24 +267,23 @@ enum bt_component_status bt_component_create( BT_ASSERT(name); type = bt_component_class_get_type(component_class); - BT_LOGD("Creating empty component from component class: " - "comp-cls-addr=%p, comp-cls-type=%s, name=\"%s\"", - component_class, bt_component_class_type_string(type), name); + BT_LIB_LOGD("Creating empty component from component class: %![cc-]+C, " + "comp-name=\"%s\"", component_class, name); component = component_create_funcs[type](component_class); if (!component) { BT_LOGE_STR("Cannot create specific component object."); - status = BT_COMPONENT_STATUS_NOMEM; + ret = -1; goto end; } bt_object_init_shared_with_parent(&component->base, - bt_component_destroy); + destroy_component); component->class = bt_object_get_ref(component_class); component->destroy = component_destroy_funcs[type]; component->name = g_string_new(name); if (!component->name) { BT_LOGE_STR("Failed to allocate one GString."); - status = BT_COMPONENT_STATUS_NOMEM; + ret = -1; goto end; } @@ -277,7 +291,7 @@ enum bt_component_status bt_component_create( (GDestroyNotify) bt_object_try_spec_release); if (!component->input_ports) { BT_LOGE_STR("Failed to allocate one GPtrArray."); - status = BT_COMPONENT_STATUS_NOMEM; + ret = -1; goto end; } @@ -285,7 +299,7 @@ enum bt_component_status bt_component_create( (GDestroyNotify) bt_object_try_spec_release); if (!component->output_ports) { BT_LOGE_STR("Failed to allocate one GPtrArray."); - status = BT_COMPONENT_STATUS_NOMEM; + ret = -1; goto end; } @@ -293,72 +307,48 @@ enum bt_component_status bt_component_create( sizeof(struct bt_component_destroy_listener)); if (!component->destroy_listeners) { BT_LOGE_STR("Failed to allocate one GArray."); - status = BT_COMPONENT_STATUS_NOMEM; + ret = -1; goto end; } - BT_LOGD("Created empty component from component class: " - "comp-cls-addr=%p, comp-cls-type=%s, name=\"%s\", comp-addr=%p", - component_class, bt_component_class_type_string(type), name, - component); + BT_LIB_LOGD("Created empty component from component class: " + "%![cc-]+C, %![comp-]+c", component_class, component); BT_OBJECT_MOVE_REF(*user_component, component); end: bt_object_put_ref(component); - return status; + return ret; } const char *bt_component_get_name(struct bt_component *component) { - const char *ret = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - ret = component->name->len == 0 ? NULL : component->name->str; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(component, "Component"); + return component->name->str; } -struct bt_component_class *bt_component_get_class( +struct bt_component_class *bt_component_borrow_class( struct bt_component *component) { - return component ? bt_object_get_ref(component->class) : NULL; + BT_ASSERT_PRE_NON_NULL(component, "Component"); + return component->class; } -void *bt_private_component_get_user_data( - struct bt_private_component *private_component) +void *bt_self_component_get_data(struct bt_self_component *self_comp) { - struct bt_component *component = - bt_component_borrow_from_private(private_component); + struct bt_component *component = (void *) self_comp; - return component ? component->user_data : NULL; + BT_ASSERT_PRE_NON_NULL(component, "Component"); + return component->user_data; } -enum bt_component_status bt_private_component_set_user_data( - struct bt_private_component *private_component, +void bt_self_component_set_data(struct bt_self_component *self_comp, void *data) { - struct bt_component *component = - bt_component_borrow_from_private(private_component); - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } + struct bt_component *component = (void *) self_comp; + BT_ASSERT_PRE_NON_NULL(component, "Component"); component->user_data = data; - BT_LOGV("Set component's user data: " - "comp-addr=%p, comp-name=\"%s\", user-data-addr=%p", - component, bt_component_get_name(component), data); - -end: - return ret; + BT_LIB_LOGV("Set component's user data: %!+c", component); } BT_HIDDEN @@ -376,24 +366,19 @@ bt_bool bt_component_graph_is_canceled(struct bt_component *component) } static -struct bt_port *bt_component_get_port_by_name(GPtrArray *ports, +struct bt_port *borrow_port_by_name(GPtrArray *ports, const char *name) { - size_t i; + uint64_t i; struct bt_port *ret_port = NULL; BT_ASSERT(name); for (i = 0; i < ports->len; i++) { struct bt_port *port = g_ptr_array_index(ports, i); - const char *port_name = bt_port_get_name(port); - if (!port_name) { - continue; - } - - if (!strcmp(name, port_name)) { - ret_port = bt_object_get_ref(port); + if (!strcmp(name, port->name->str)) { + ret_port = port; break; } } @@ -402,81 +387,74 @@ struct bt_port *bt_component_get_port_by_name(GPtrArray *ports, } BT_HIDDEN -struct bt_port *bt_component_get_input_port_by_name(struct bt_component *comp, - const char *name) +struct bt_port_input *bt_component_borrow_input_port_by_name( + struct bt_component *comp, const char *name) { BT_ASSERT(comp); - - return bt_component_get_port_by_name(comp->input_ports, name); + return (void *) borrow_port_by_name(comp->input_ports, name); } BT_HIDDEN -struct bt_port *bt_component_get_output_port_by_name(struct bt_component *comp, - const char *name) +struct bt_port_output *bt_component_borrow_output_port_by_name( + struct bt_component *comp, const char *name) { - BT_ASSERT(comp); - - return bt_component_get_port_by_name(comp->output_ports, name); + BT_ASSERT_PRE_NON_NULL(comp, "Component"); + return (void *) + borrow_port_by_name(comp->output_ports, name); } static -struct bt_port *bt_component_get_port_by_index(GPtrArray *ports, uint64_t index) +struct bt_port *borrow_port_by_index(GPtrArray *ports, uint64_t index) { - struct bt_port *port = NULL; - - if (index >= ports->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "index=%" PRIu64 ", count=%u", - index, ports->len); - goto end; - } - - port = bt_object_get_ref(g_ptr_array_index(ports, index)); -end: - return port; + BT_ASSERT(index < ports->len); + return g_ptr_array_index(ports, index); } BT_HIDDEN -struct bt_port *bt_component_get_input_port_by_index(struct bt_component *comp, - uint64_t index) +struct bt_port_input *bt_component_borrow_input_port_by_index( + struct bt_component *comp, uint64_t index) { - BT_ASSERT(comp); - - return bt_component_get_port_by_index(comp->input_ports, index); + BT_ASSERT_PRE_NON_NULL(comp, "Component"); + BT_ASSERT_PRE_VALID_INDEX(index, comp->input_ports->len); + return (void *) + borrow_port_by_index(comp->input_ports, index); } BT_HIDDEN -struct bt_port *bt_component_get_output_port_by_index(struct bt_component *comp, - uint64_t index) +struct bt_port_output *bt_component_borrow_output_port_by_index( + struct bt_component *comp, uint64_t index) { - BT_ASSERT(comp); - - return bt_component_get_port_by_index(comp->output_ports, index); + BT_ASSERT_PRE_NON_NULL(comp, "Component"); + BT_ASSERT_PRE_VALID_INDEX(index, comp->output_ports->len); + return (void *) + borrow_port_by_index(comp->output_ports, index); } BT_HIDDEN -struct bt_port *bt_component_add_input_port( +struct bt_port_input *bt_component_add_input_port( struct bt_component *component, const char *name, void *user_data) { - /* bt_component_add_port() logs details */ - return bt_component_add_port(component, component->input_ports, - BT_PORT_TYPE_INPUT, name, user_data); + /* add_port() logs details */ + return (void *) + add_port(component, component->input_ports, + BT_PORT_TYPE_INPUT, name, user_data); } BT_HIDDEN -struct bt_port *bt_component_add_output_port( +struct bt_port_output *bt_component_add_output_port( struct bt_component *component, const char *name, void *user_data) { - /* bt_component_add_port() logs details */ - return bt_component_add_port(component, component->output_ports, - BT_PORT_TYPE_OUTPUT, name, user_data); + /* add_port() logs details */ + return (void *) + add_port(component, component->output_ports, + BT_PORT_TYPE_OUTPUT, name, user_data); } static -void bt_component_remove_port_by_index(struct bt_component *component, - GPtrArray *ports, size_t index) +void remove_port_by_index(struct bt_component *component, + GPtrArray *ports, uint64_t index) { struct bt_port *port; struct bt_graph *graph; @@ -484,64 +462,80 @@ void bt_component_remove_port_by_index(struct bt_component *component, BT_ASSERT(ports); BT_ASSERT(index < ports->len); port = g_ptr_array_index(ports, index); - - BT_LOGD("Removing port from component: " - "comp-addr=%p, comp-name=\"%s\", " - "port-addr=%p, port-name=\"%s\"", - component, bt_component_get_name(component), - port, bt_port_get_name(port)); + BT_LIB_LOGD("Removing port from component: %![comp-]+c, %![port-]+p", + component, port); /* Disconnect both ports of this port's connection, if any */ if (port->connection) { bt_connection_end(port->connection, true); } - /* Remove from parent's array of ports (weak refs) */ + /* + * The port's current reference count can be 0 at this point, + * which means its parent (component) keeps it alive. We are + * about to remove the port from its parent's container (with + * the g_ptr_array_remove_index() call below), which in this + * case would destroy it. This is not good because we still + * need the port for the bt_graph_notify_port_removed() call + * 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, + * 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. + */ + bt_object_get_no_null_check(&port->base); + + /* + * Remove from parent's array of ports (weak refs). This never + * destroys the port object because its reference count is at + * least 1 thanks to the bt_object_get_no_null_check() call + * above. + */ g_ptr_array_remove_index(ports, index); /* Detach port from its component parent */ - BT_OBJECT_PUT_REF_AND_RESET(port->base.parent); + bt_object_set_parent(&port->base, NULL); /* * Notify the graph's creator that a port is removed. */ - graph = bt_object_get_ref(bt_component_borrow_graph(component)); + graph = bt_component_borrow_graph(component); if (graph) { bt_graph_notify_port_removed(graph, component, port); - BT_OBJECT_PUT_REF_AND_RESET(graph); } - BT_LOGD("Removed port from component: " - "comp-addr=%p, comp-name=\"%s\", " - "port-addr=%p, port-name=\"%s\"", - component, bt_component_get_name(component), - port, bt_port_get_name(port)); + BT_LIB_LOGD("Removed port from component: %![comp-]+c, %![port-]+p", + component, port); + + /* + * Put the local reference. If this port's reference count was 0 + * when entering this function, it is 1 now, so it is destroyed + * immediately. + */ + bt_object_put_no_null_check(&port->base); } BT_HIDDEN -enum bt_component_status bt_component_remove_port( - struct bt_component *component, struct bt_port *port) +void bt_component_remove_port(struct bt_component *component, + struct bt_port *port) { - size_t i; - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + uint64_t i; GPtrArray *ports = NULL; - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (!port) { - BT_LOGW_STR("Invalid parameter: port is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } + BT_ASSERT(component); + BT_ASSERT(port); - if (bt_port_get_type(port) == BT_PORT_TYPE_INPUT) { + switch (port->type) { + case BT_PORT_TYPE_INPUT: ports = component->input_ports; - } else if (bt_port_get_type(port) == BT_PORT_TYPE_OUTPUT) { + break; + case BT_PORT_TYPE_OUTPUT: ports = component->output_ports; + break; + default: + abort(); } BT_ASSERT(ports); @@ -550,74 +544,168 @@ enum bt_component_status bt_component_remove_port( struct bt_port *cur_port = g_ptr_array_index(ports, i); if (cur_port == port) { - bt_component_remove_port_by_index(component, + remove_port_by_index(component, ports, i); goto end; } } - status = BT_COMPONENT_STATUS_NOT_FOUND; - BT_LOGW("Port to remove from component was not found: " - "comp-addr=%p, comp-name=\"%s\", " - "port-addr=%p, port-name=\"%s\"", - component, bt_component_get_name(component), - port, bt_port_get_name(port)); + BT_LIB_LOGW("Port to remove from component was not found: " + "%![comp-]+c, %![port-]+p", component, port); end: - return status; + return; } BT_HIDDEN -enum bt_component_status bt_component_accept_port_connection( +enum bt_self_component_status bt_component_accept_port_connection( struct bt_component *comp, struct bt_port *self_port, struct bt_port *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + typedef enum bt_self_component_status (*method_t)( + void *, void *, void *); + + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + method_t method = NULL; 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: " - "comp-addr=%p, comp-name=\"%s\", " - "self-port-addr=%p, self-port-name=\"%s\", " - "other-port-addr=%p, other-port-name=\"%s\"", - comp, bt_component_get_name(comp), - self_port, bt_port_get_name(self_port), - other_port, bt_port_get_name(other_port)); - status = comp->class->methods.accept_port_connection( - bt_private_component_from_component(comp), - bt_private_port_from_port(self_port), - other_port); + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_OUTPUT: + method = (method_t) src_cc->methods.accept_output_port_connection; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) flt_cc->methods.accept_input_port_connection; + break; + case BT_PORT_TYPE_OUTPUT: + method = (method_t) flt_cc->methods.accept_output_port_connection; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + struct bt_component_class_sink *sink_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) sink_cc->methods.accept_input_port_connection; + break; + default: + abort(); + } + + break; + } + default: + abort(); + } + + if (method) { + 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); BT_LOGD("User method returned: status=%s", - bt_component_status_string(status)); + bt_self_component_status_string(status)); } return status; } BT_HIDDEN -enum bt_component_status bt_component_port_connected(struct bt_component *comp, - struct bt_port *self_port, struct bt_port *other_port) +enum bt_self_component_status bt_component_port_connected( + struct bt_component *comp, struct bt_port *self_port, + struct bt_port *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + typedef enum bt_self_component_status (*method_t)( + void *, void *, void *); + + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + method_t method = NULL; 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: " - "comp-addr=%p, comp-name=\"%s\", " - "self-port-addr=%p, self-port-name=\"%s\", " - "other-port-addr=%p, other-port-name=\"%s\"", - comp, bt_component_get_name(comp), - self_port, bt_port_get_name(self_port), - other_port, bt_port_get_name(other_port)); - status = comp->class->methods.port_connected( - bt_private_component_from_component(comp), - bt_private_port_from_port(self_port), other_port); + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_OUTPUT: + method = (method_t) src_cc->methods.output_port_connected; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) flt_cc->methods.input_port_connected; + break; + case BT_PORT_TYPE_OUTPUT: + method = (method_t) flt_cc->methods.output_port_connected; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + struct bt_component_class_sink *sink_cc = (void *) comp->class; + + switch (self_port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) sink_cc->methods.input_port_connected; + break; + default: + abort(); + } + + break; + } + default: + abort(); + } + + if (method) { + 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); + BT_LOGD("User method returned: status=%s", + bt_self_component_status_string(status)); } return status; @@ -627,18 +715,67 @@ BT_HIDDEN void bt_component_port_disconnected(struct bt_component *comp, struct bt_port *port) { + typedef void (*method_t)(void *, void *); + + method_t method = NULL; + BT_ASSERT(comp); BT_ASSERT(port); - if (comp->class->methods.port_disconnected) { - BT_LOGD("Calling user's \"port disconnected\" method: " - "comp-addr=%p, comp-name=\"%s\", " - "port-addr=%p, port-name=\"%s\"", - comp, bt_component_get_name(comp), - port, bt_port_get_name(port)); - comp->class->methods.port_disconnected( - bt_private_component_from_component(comp), - bt_private_port_from_port(port)); + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_cc = (void *) comp->class; + + switch (port->type) { + case BT_PORT_TYPE_OUTPUT: + method = (method_t) src_cc->methods.output_port_disconnected; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_cc = (void *) comp->class; + + switch (port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) flt_cc->methods.input_port_disconnected; + break; + case BT_PORT_TYPE_OUTPUT: + method = (method_t) flt_cc->methods.output_port_disconnected; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + struct bt_component_class_sink *sink_cc = (void *) comp->class; + + switch (port->type) { + case BT_PORT_TYPE_INPUT: + method = (method_t) sink_cc->methods.input_port_disconnected; + break; + default: + abort(); + } + + break; + } + default: + abort(); + } + + if (method) { + BT_LIB_LOGD("Calling user's \"port disconnected\" method: " + "%![comp-]+c, %![port-]+p", comp, port); + method(comp, port); } } @@ -653,18 +790,16 @@ void bt_component_add_destroy_listener(struct bt_component *component, listener.func = func; listener.data = data; g_array_append_val(component->destroy_listeners, listener); - BT_LOGV("Added destroy listener: " - "comp-addr=%p, comp-name=\"%s\", " + BT_LIB_LOGV("Added destroy listener: %![comp-]+c, " "func-addr=%p, data-addr=%p", - component, bt_component_get_name(component), - func, data); + component, func, data); } BT_HIDDEN void bt_component_remove_destroy_listener(struct bt_component *component, bt_component_destroy_listener_func func, void *data) { - size_t i; + uint64_t i; BT_ASSERT(component); BT_ASSERT(func); @@ -677,11 +812,9 @@ void bt_component_remove_destroy_listener(struct bt_component *component, if (listener->func == func && listener->data == data) { g_array_remove_index(component->destroy_listeners, i); i--; - BT_LOGV("Removed destroy listener: " - "comp-addr=%p, comp-name=\"%s\", " + BT_LIB_LOGV("Removed destroy listener: %![comp-]+c, " "func-addr=%p, data-addr=%p", - component, bt_component_get_name(component), - func, data); + component, func, data); } } } diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 3993f070..655b36c9 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -1,8 +1,4 @@ /* - * connection.c - * - * Babeltrace Connection - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -31,25 +27,24 @@ #include #include -#include -#include #include -#include #include #include #include #include +#include #include +#include #include #include static -void bt_connection_destroy(struct bt_object *obj) +void destroy_connection(struct bt_object *obj) { struct bt_connection *connection = container_of(obj, struct bt_connection, base); - BT_LOGD("Destroying connection: addr=%p", connection); + BT_LIB_LOGD("Destroying connection: %!+x", connection); /* * Make sure that each notification iterator which was created @@ -68,6 +63,7 @@ void bt_connection_destroy(struct bt_object *obj) */ bt_connection_end(connection, false); g_ptr_array_free(connection->iterators, TRUE); + connection->iterators = NULL; /* * No bt_object_put_ref on ports as a connection only holds _weak_ @@ -77,7 +73,7 @@ void bt_connection_destroy(struct bt_object *obj) } static -void bt_connection_try_remove_from_graph(struct bt_connection *connection) +void try_remove_connection_from_graph(struct bt_connection *connection) { void *graph = (void *) bt_object_borrow_parent(&connection->base); @@ -103,48 +99,30 @@ void bt_connection_try_remove_from_graph(struct bt_connection *connection) * It is safe to remove the connection from the graph, therefore * destroying it. */ - BT_LOGD("Removing self from graph's connections: " - "graph-addr=%p, conn-addr=%p", graph, connection); + BT_LIB_LOGD("Removing self from graph's connections: " + "%![graph-]+g, %![conn-]+x", graph, connection); bt_graph_remove_connection(graph, connection); } static -void bt_connection_parent_is_owner(struct bt_object *obj) +void parent_is_owner(struct bt_object *obj) { struct bt_connection *connection = container_of(obj, struct bt_connection, base); - bt_connection_try_remove_from_graph(connection); -} - -struct bt_connection *bt_connection_borrow_from_private( - struct bt_private_connection *private_connection) -{ - return (void *) private_connection; + try_remove_connection_from_graph(connection); } BT_HIDDEN -struct bt_connection *bt_connection_create( - struct bt_graph *graph, +struct bt_connection *bt_connection_create(struct bt_graph *graph, struct bt_port *upstream_port, struct bt_port *downstream_port) { struct bt_connection *connection = NULL; - if (bt_port_get_type(upstream_port) != BT_PORT_TYPE_OUTPUT) { - BT_LOGW_STR("Invalid parameter: upstream port is not an output port."); - goto end; - } - if (bt_port_get_type(downstream_port) != BT_PORT_TYPE_INPUT) { - BT_LOGW_STR("Invalid parameter: downstream port is not an input port."); - goto end; - } - - BT_LOGD("Creating connection: " - "graph-addr=%p, upstream-port-addr=%p, uptream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - graph, upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + BT_LIB_LOGD("Creating connection: " + "%![graph-]+g, %![up-port-]+p, %![down-port-]+p", + graph, upstream_port, downstream_port); connection = g_new0(struct bt_connection, 1); if (!connection) { BT_LOGE_STR("Failed to allocate one connection."); @@ -152,9 +130,9 @@ struct bt_connection *bt_connection_create( } bt_object_init_shared_with_parent(&connection->base, - bt_connection_destroy); + destroy_connection); bt_object_set_parent_is_owner_listener_func(&connection->base, - bt_connection_parent_is_owner); + parent_is_owner); connection->iterators = g_ptr_array_new(); if (!connection->iterators) { BT_LOGE_STR("Failed to allocate a GPtrArray."); @@ -165,26 +143,20 @@ struct bt_connection *bt_connection_create( /* Weak references are taken, see comment in header. */ connection->upstream_port = upstream_port; connection->downstream_port = downstream_port; - BT_LOGD_STR("Setting upstream port's connection."); + BT_LIB_LOGD("Setting upstream port's connection: %!+p", upstream_port); bt_port_set_connection(upstream_port, connection); - BT_LOGD_STR("Setting downstream port's connection."); + BT_LIB_LOGD("Setting downstream port's connection: %!+p", + downstream_port); bt_port_set_connection(downstream_port, connection); bt_object_set_parent(&connection->base, &graph->base); - BT_LOGD("Created connection: " - "graph-addr=%p, upstream-port-addr=%p, uptream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\", " - "conn-addr=%p", - graph, upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port), - connection); + BT_LIB_LOGD("Created connection: %!+x", connection); end: return connection; } BT_HIDDEN -void bt_connection_end(struct bt_connection *conn, - bool try_remove_from_graph) +void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) { struct bt_component *downstream_comp = NULL; struct bt_component *upstream_comp = NULL; @@ -193,233 +165,117 @@ void bt_connection_end(struct bt_connection *conn, struct bt_graph *graph = bt_connection_borrow_graph(conn); size_t i; - BT_LOGD("Ending connection: conn-addr=%p, try-remove-from-graph=%d", + BT_LIB_LOGD("Ending connection: %!+x, try-remove-from-graph=%d", conn, try_remove_from_graph); + /* + * Any of the following notification callback functions could + * remove one of the connection's ports from its component. To + * make sure that at least logging in called functions works + * with existing objects, get a local reference on both ports. + */ + bt_object_get_ref(downstream_port); + bt_object_get_ref(upstream_port); + if (downstream_port) { - BT_LOGD("Disconnecting connection's downstream port: " - "port-addr=%p, port-name=\"%s\"", - downstream_port, bt_port_get_name(downstream_port)); - downstream_comp = bt_port_get_component(downstream_port); + BT_LIB_LOGD("Disconnecting connection's downstream port: %!+p", + downstream_port); + downstream_comp = bt_port_borrow_component(downstream_port); bt_port_set_connection(downstream_port, NULL); conn->downstream_port = NULL; } if (upstream_port) { - BT_LOGD("Disconnecting connection's upstream port: " - "port-addr=%p, port-name=\"%s\"", - upstream_port, bt_port_get_name(upstream_port)); - upstream_comp = bt_port_get_component(upstream_port); + BT_LIB_LOGD("Disconnecting connection's upstream port: %!+p", + upstream_port); + upstream_comp = bt_port_borrow_component(upstream_port); bt_port_set_connection(upstream_port, NULL); conn->upstream_port = NULL; } - if (downstream_comp && conn->notified_downstream_port_connected) { + if (downstream_comp && conn->notified_downstream_port_connected && + !conn->notified_downstream_port_disconnected) { /* bt_component_port_disconnected() logs details */ bt_component_port_disconnected(downstream_comp, downstream_port); + conn->notified_downstream_port_disconnected = true; } - if (upstream_comp && conn->notified_upstream_port_connected) { + if (upstream_comp && conn->notified_upstream_port_connected && + !conn->notified_upstream_port_disconnected) { /* bt_component_port_disconnected() logs details */ bt_component_port_disconnected(upstream_comp, upstream_port); + conn->notified_upstream_port_disconnected = true; } BT_ASSERT(graph); - if (conn->notified_graph_ports_connected) { + if (conn->notified_graph_ports_connected && + !conn->notified_graph_ports_disconnected) { /* bt_graph_notify_ports_disconnected() logs details */ bt_graph_notify_ports_disconnected(graph, upstream_comp, downstream_comp, upstream_port, downstream_port); + conn->notified_graph_ports_disconnected = true; } - bt_object_put_ref(downstream_comp); - bt_object_put_ref(upstream_comp); + /* + * It is safe to put the local port references now that we don't + * need them anymore. This could indeed destroy them. + */ + bt_object_put_ref(downstream_port); + bt_object_put_ref(upstream_port); /* * Because this connection is ended, finalize (cancel) each * notification iterator created from it. */ for (i = 0; i < conn->iterators->len; i++) { - struct bt_notification_iterator_private_connection *iterator = + struct bt_self_component_port_input_notification_iterator *iterator = g_ptr_array_index(conn->iterators, i); - BT_LOGD("Finalizing notification iterator created by this ended connection: " - "conn-addr=%p, iter-addr=%p", conn, iterator); - bt_private_connection_notification_iterator_finalize(iterator); + BT_LIB_LOGD("Finalizing notification iterator created by " + "this ended connection: %![iter-]+i", iterator); + bt_self_component_port_input_notification_iterator_finalize( + iterator); /* * Make sure this iterator does not try to remove itself * from this connection's iterators on destruction * because this connection won't exist anymore. */ - bt_private_connection_notification_iterator_set_connection( + bt_self_component_port_input_notification_iterator_set_connection( iterator, NULL); } g_ptr_array_set_size(conn->iterators, 0); if (try_remove_from_graph) { - bt_connection_try_remove_from_graph(conn); + try_remove_connection_from_graph(conn); } } -struct bt_port *bt_connection_get_upstream_port( +struct bt_port_output *bt_connection_borrow_upstream_port( struct bt_connection *connection) { - return connection ? bt_object_get_ref(connection->upstream_port) : NULL; + BT_ASSERT_PRE_NON_NULL(connection, "Connection"); + return (void *) connection->upstream_port; } -struct bt_port *bt_connection_get_downstream_port( +struct bt_port_input *bt_connection_borrow_downstream_port( struct bt_connection *connection) { - return connection ? bt_object_get_ref(connection->downstream_port) : NULL; -} - -enum bt_connection_status -bt_private_connection_create_notification_iterator( - struct bt_private_connection *private_connection, - struct bt_notification_iterator **user_iterator) -{ - enum bt_component_class_type upstream_comp_class_type; - struct bt_notification_iterator_private_connection *iterator = NULL; - struct bt_port *upstream_port = NULL; - struct bt_component *upstream_component = NULL; - struct bt_component_class *upstream_comp_class = NULL; - struct bt_connection *connection = NULL; - bt_component_class_notification_iterator_init_method init_method = NULL; - enum bt_connection_status status; - - if (!private_connection) { - BT_LOGW_STR("Invalid parameter: private connection is NULL."); - status = BT_CONNECTION_STATUS_INVALID; - goto end; - } - - if (!user_iterator) { - BT_LOGW_STR("Invalid parameter: notification iterator pointer is NULL."); - status = BT_CONNECTION_STATUS_INVALID; - goto end; - } - - connection = bt_connection_borrow_from_private(private_connection); - - if (bt_graph_is_canceled(bt_connection_borrow_graph(connection))) { - BT_LOGW("Cannot create notification iterator from connection: " - "connection's graph is canceled: " - "conn-addr=%p, upstream-port-addr=%p, " - "upstream-port-name=\"%s\", upstream-comp-addr=%p, " - "upstream-comp-name=\"%s\", graph-addr=%p", - connection, connection->upstream_port, - bt_port_get_name(connection->upstream_port), - upstream_component, - bt_component_get_name(upstream_component), - bt_connection_borrow_graph(connection)); - status = BT_CONNECTION_STATUS_GRAPH_IS_CANCELED; - goto end; - } - - if (bt_connection_is_ended(connection)) { - BT_LOGW("Invalid parameter: connection is ended: " - "conn-addr=%p", connection); - status = BT_CONNECTION_STATUS_IS_ENDED; - goto end; - } - - upstream_port = connection->upstream_port; - BT_ASSERT(upstream_port); - upstream_component = bt_port_get_component(upstream_port); - BT_ASSERT(upstream_component); - upstream_comp_class = upstream_component->class; - BT_LOGD("Creating notification iterator from connection: " - "conn-addr=%p, upstream-port-addr=%p, " - "upstream-port-name=\"%s\", upstream-comp-addr=%p, " - "upstream-comp-name=\"%s\"", - connection, connection->upstream_port, - bt_port_get_name(connection->upstream_port), - upstream_component, bt_component_get_name(upstream_component)); - upstream_comp_class_type = - bt_component_get_class_type(upstream_component); - BT_ASSERT(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE || - upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_FILTER); - status = bt_private_connection_notification_iterator_create(upstream_component, - upstream_port, connection, &iterator); - if (status != BT_CONNECTION_STATUS_OK) { - BT_LOGW("Cannot create notification iterator from connection."); - goto end; - } - - switch (upstream_comp_class_type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - struct bt_component_class_source *source_class = - container_of(upstream_comp_class, - struct bt_component_class_source, parent); - init_method = source_class->methods.iterator.init; - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - struct bt_component_class_filter *filter_class = - container_of(upstream_comp_class, - struct bt_component_class_filter, parent); - init_method = filter_class->methods.iterator.init; - break; - } - default: - /* Unreachable. */ - BT_LOGF("Unknown component class type: type=%d", - upstream_comp_class_type); - abort(); - } - - if (init_method) { - enum bt_notification_iterator_status iter_status; - - BT_LOGD("Calling user's initialization method: iter-addr=%p", - iterator); - iter_status = init_method( - bt_private_connection_private_notification_iterator_from_notification_iterator((void *) iterator), - bt_private_port_from_port(upstream_port)); - BT_LOGD("User method returned: status=%s", - bt_notification_iterator_status_string(iter_status)); - if (iter_status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { - BT_LOGW_STR("Initialization method failed."); - status = bt_connection_status_from_notification_iterator_status( - iter_status); - goto end; - } - } - - iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE; - g_ptr_array_add(connection->iterators, iterator); - BT_LOGD("Created notification iterator from connection: " - "conn-addr=%p, upstream-port-addr=%p, " - "upstream-port-name=\"%s\", upstream-comp-addr=%p, " - "upstream-comp-name=\"%s\", iter-addr=%p", - connection, connection->upstream_port, - bt_port_get_name(connection->upstream_port), - upstream_component, bt_component_get_name(upstream_component), - iterator); - - /* Move reference to user */ - *user_iterator = (void *) iterator; - iterator = NULL; - -end: - bt_object_put_ref(upstream_component); - bt_object_put_ref(iterator); - return status; + BT_ASSERT_PRE_NON_NULL(connection, "Connection"); + return (void *) connection->downstream_port; } BT_HIDDEN void bt_connection_remove_iterator(struct bt_connection *conn, - struct bt_notification_iterator_private_connection *iterator) + struct bt_self_component_port_input_notification_iterator *iterator) { g_ptr_array_remove(conn->iterators, iterator); - BT_LOGV("Removed notification iterator from connection: " - "conn-addr=%p, iter-addr=%p", conn, iterator); - bt_connection_try_remove_from_graph(conn); + BT_LIB_LOGV("Removed notification iterator from connection: " + "%![conn-]+x, %![iter-]+i", conn, iterator); + try_remove_connection_from_graph(conn); } bt_bool bt_connection_is_ended(struct bt_connection *connection) diff --git a/lib/graph/filter.c b/lib/graph/filter.c deleted file mode 100644 index c25160f5..00000000 --- a/lib/graph/filter.c +++ /dev/null @@ -1,376 +0,0 @@ -/* - * filter.c - * - * Babeltrace Filter Component - * - * Copyright 2016 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_TAG "COMP-FILTER" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -BT_HIDDEN -void bt_component_filter_destroy(struct bt_component *component) -{ -} - -BT_HIDDEN -struct bt_component *bt_component_filter_create( - struct bt_component_class *class) -{ - struct bt_component_filter *filter = NULL; - - filter = g_new0(struct bt_component_filter, 1); - if (!filter) { - BT_LOGE_STR("Failed to allocate one filter component."); - goto end; - } - -end: - return filter ? &filter->parent : NULL; -} - -int64_t bt_component_filter_get_input_port_count( - struct bt_component *component) -{ - int64_t ret; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = (int64_t) -1; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - ret = (int64_t) -1; - goto end; - } - - ret = (int64_t) bt_component_get_input_port_count(component); - -end: - return ret; -} - -struct bt_port *bt_component_filter_get_input_port_by_name( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_input_port_by_name() logs details/errors */ - port = bt_component_get_input_port_by_name(component, name); - -end: - return port; -} - -struct bt_port *bt_component_filter_get_input_port_by_index( - struct bt_component *component, uint64_t index) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_input_port_by_index() logs details/errors */ - port = bt_component_get_input_port_by_index(component, index); - -end: - return port; -} - -int64_t bt_component_filter_get_output_port_count( - struct bt_component *component) -{ - int64_t ret; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = (int64_t) -1; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - ret = (int64_t) -1; - goto end; - } - - /* bt_component_get_output_port_count() logs details/errors */ - ret = bt_component_get_output_port_count(component); - -end: - return ret; -} - -struct bt_port *bt_component_filter_get_output_port_by_name( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_output_port_by_name() logs details/errors */ - port = bt_component_get_output_port_by_name(component, name); - -end: - return port; -} - -struct bt_port *bt_component_filter_get_output_port_by_index( - struct bt_component *component, uint64_t index) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_output_port_by_index() logs details/errors */ - port = bt_component_get_output_port_by_index(component, index); - -end: - return port; -} - -struct bt_private_port * -bt_private_component_filter_get_input_port_by_index( - struct bt_private_component *private_component, uint64_t index) -{ - /* bt_component_filter_get_input_port_by_index() logs details/errors */ - return bt_private_port_from_port( - bt_component_filter_get_input_port_by_index( - bt_component_borrow_from_private(private_component), index)); -} - -struct bt_private_port * -bt_private_component_filter_get_input_port_by_name( - struct bt_private_component *private_component, - const char *name) -{ - /* bt_component_filter_get_input_port_by_name() logs details/errors */ - return bt_private_port_from_port( - bt_component_filter_get_input_port_by_name( - bt_component_borrow_from_private(private_component), name)); -} - -enum bt_component_status bt_private_component_filter_add_input_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **user_priv_port) -{ - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - struct bt_port *port = NULL; - struct bt_component *component = - bt_component_borrow_from_private(private_component); - struct bt_graph *graph; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - graph = bt_component_borrow_graph(component); - - if (graph && bt_graph_is_canceled(graph)) { - BT_LOGW("Cannot add input port to filter component: graph is canceled: " - "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", - component, bt_component_get_name(component), - bt_component_borrow_graph(component)); - status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; - goto end; - } - - /* bt_component_add_input_port() logs details/errors */ - port = bt_component_add_input_port(component, name, user_data); - if (!port) { - status = BT_COMPONENT_STATUS_NOMEM; - goto end; - } - - if (user_priv_port) { - /* Move reference to user */ - *user_priv_port = bt_private_port_from_port(port); - port = NULL; - } - -end: - bt_object_put_ref(port); - return status; -} - -struct bt_private_port * -bt_private_component_filter_get_output_port_by_index( - struct bt_private_component *private_component, uint64_t index) -{ - /* bt_component_filter_get_output_port_by_index() logs details/errors */ - return bt_private_port_from_port( - bt_component_filter_get_output_port_by_index( - bt_component_borrow_from_private(private_component), index)); -} - -struct bt_private_port * -bt_private_component_filter_get_output_port_by_name( - struct bt_private_component *private_component, - const char *name) -{ - /* bt_component_filter_get_output_port_by_name() logs details/errors */ - return bt_private_port_from_port( - bt_component_filter_get_output_port_by_name( - bt_component_borrow_from_private(private_component), name)); -} - -enum bt_component_status bt_private_component_filter_add_output_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **user_priv_port) -{ - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - struct bt_port *port = NULL; - struct bt_component *component = - bt_component_borrow_from_private(private_component); - struct bt_graph *graph; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - BT_LOGW("Invalid parameter: component's class is not a filter component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - graph = bt_component_borrow_graph(component); - - if (graph && bt_graph_is_canceled(graph)) { - BT_LOGW("Cannot add output port to filter component: graph is canceled: " - "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", - component, bt_component_get_name(component), - bt_component_borrow_graph(component)); - status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; - goto end; - } - - /* bt_component_add_output_port() logs details/errors */ - port = bt_component_add_output_port(component, name, user_data); - if (!port) { - status = BT_COMPONENT_STATUS_NOMEM; - goto end; - } - - if (user_priv_port) { - /* Move reference to user */ - *user_priv_port = bt_private_port_from_port(port); - port = NULL; - } - -end: - bt_object_put_ref(port); - return status; -} diff --git a/lib/graph/graph.c b/lib/graph/graph.c index 722cb2ee..1b4653de 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -41,51 +41,67 @@ #include #include #include +#include #include #include #include #include +typedef void (*port_added_func_t)(void *, void *, void *); +typedef void (*port_removed_func_t)(void *, void *, void *); +typedef void (*ports_connected_func_t)(void *, void *, void *, void *, void *); +typedef void (*ports_disconnected_func_t)(void *, void *, void *, void *, void *); +typedef enum bt_self_component_status (*comp_init_method_t)(void *, void *, void *); + struct bt_graph_listener { - void *func; bt_private_graph_listener_removed removed; void *data; }; -static -int init_listeners_array(GArray **listeners) -{ - int ret = 0; - - BT_ASSERT(listeners); - *listeners = g_array_new(FALSE, TRUE, sizeof(struct bt_graph_listener)); - if (!*listeners) { - BT_LOGE_STR("Failed to allocate one GArray."); - ret = -1; - goto end; - } +struct bt_graph_listener_port_added { + struct bt_graph_listener base; + port_added_func_t func; +}; -end: - return ret; -} +struct bt_graph_listener_port_removed { + struct bt_graph_listener base; + port_removed_func_t func; +}; -static -void call_remove_listeners(GArray *listeners) -{ - size_t i; +struct bt_graph_listener_ports_connected { + struct bt_graph_listener base; + ports_connected_func_t func; +}; - for (i = 0; i < listeners->len; i++) { - struct bt_graph_listener listener = - g_array_index(listeners, struct bt_graph_listener, i); +struct bt_graph_listener_ports_disconnected { + struct bt_graph_listener base; + ports_disconnected_func_t func; +}; - if (listener.removed) { - listener.removed(listener.data); - } - } -} +#define INIT_LISTENERS_ARRAY(_type, _listeners) \ + do { \ + _listeners = g_array_new(FALSE, TRUE, sizeof(_type)); \ + if (!(_listeners)) { \ + BT_LOGE_STR("Failed to allocate one GArray."); \ + } \ + } while (0) + +#define CALL_REMOVE_LISTENERS(_type, _listeners) \ + do { \ + size_t i; \ + \ + for (i = 0; i < (_listeners)->len; i++) { \ + _type *listener = \ + &g_array_index((_listeners), _type, i); \ + \ + if (listener->base.removed) { \ + listener->base.removed(listener->base.data); \ + } \ + } \ + } while (0) static -void bt_graph_destroy(struct bt_object *obj) +void destroy_graph(struct bt_object *obj) { struct bt_graph *graph = container_of(obj, struct bt_graph, base); @@ -116,7 +132,7 @@ void bt_graph_destroy(struct bt_object *obj) * step 4 goes from 1 to 2, and from 2 to 1 at step 6. This * ensures that this function is not called two times. */ - BT_LOGD("Destroying graph: addr=%p", graph); + BT_LIB_LOGD("Destroying graph: %!+g", graph); obj->ref_count++; /* @@ -126,43 +142,131 @@ void bt_graph_destroy(struct bt_object *obj) (void) bt_private_graph_cancel((void *) graph); /* Call all remove listeners */ - call_remove_listeners(graph->listeners.port_added); - call_remove_listeners(graph->listeners.port_removed); - call_remove_listeners(graph->listeners.ports_connected); - call_remove_listeners(graph->listeners.ports_disconnected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added, + graph->listeners.source_output_port_added); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added, + graph->listeners.filter_output_port_added); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added, + graph->listeners.filter_input_port_added); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added, + graph->listeners.sink_input_port_added); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, + graph->listeners.source_output_port_removed); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, + graph->listeners.filter_output_port_removed); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, + graph->listeners.filter_input_port_removed); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, + graph->listeners.sink_input_port_removed); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, + graph->listeners.source_filter_ports_connected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, + graph->listeners.source_sink_ports_connected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, + graph->listeners.filter_sink_ports_connected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, + graph->listeners.source_filter_ports_disconnected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, + graph->listeners.source_sink_ports_disconnected); + CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, + graph->listeners.filter_sink_ports_disconnected); if (graph->notifications) { g_ptr_array_free(graph->notifications, TRUE); + graph->notifications = NULL; } if (graph->connections) { BT_LOGD_STR("Destroying connections."); g_ptr_array_free(graph->connections, TRUE); + graph->connections = NULL; } if (graph->components) { BT_LOGD_STR("Destroying components."); g_ptr_array_free(graph->components, TRUE); + graph->components = NULL; } if (graph->sinks_to_consume) { g_queue_free(graph->sinks_to_consume); + graph->sinks_to_consume = NULL; + } + + if (graph->listeners.source_output_port_added) { + g_array_free(graph->listeners.source_output_port_added, TRUE); + graph->listeners.source_output_port_added = NULL; + } + + if (graph->listeners.filter_output_port_added) { + g_array_free(graph->listeners.filter_output_port_added, TRUE); + graph->listeners.filter_output_port_added = NULL; + } + + if (graph->listeners.filter_input_port_added) { + g_array_free(graph->listeners.filter_input_port_added, TRUE); + graph->listeners.filter_input_port_added = NULL; } - if (graph->listeners.port_added) { - g_array_free(graph->listeners.port_added, TRUE); + if (graph->listeners.sink_input_port_added) { + g_array_free(graph->listeners.sink_input_port_added, TRUE); + graph->listeners.sink_input_port_added = NULL; } - if (graph->listeners.port_removed) { - g_array_free(graph->listeners.port_removed, TRUE); + if (graph->listeners.source_output_port_removed) { + g_array_free(graph->listeners.source_output_port_removed, TRUE); + graph->listeners.source_output_port_removed = NULL; } - if (graph->listeners.ports_connected) { - g_array_free(graph->listeners.ports_connected, TRUE); + if (graph->listeners.filter_output_port_removed) { + g_array_free(graph->listeners.filter_output_port_removed, TRUE); + graph->listeners.filter_output_port_removed = NULL; } - if (graph->listeners.ports_disconnected) { - g_array_free(graph->listeners.ports_disconnected, TRUE); + if (graph->listeners.filter_input_port_removed) { + g_array_free(graph->listeners.filter_input_port_removed, TRUE); + graph->listeners.filter_input_port_removed = NULL; + } + + if (graph->listeners.sink_input_port_removed) { + g_array_free(graph->listeners.sink_input_port_removed, TRUE); + graph->listeners.sink_input_port_removed = NULL; + } + + if (graph->listeners.source_filter_ports_connected) { + g_array_free(graph->listeners.source_filter_ports_connected, + TRUE); + graph->listeners.source_filter_ports_connected = NULL; + } + + if (graph->listeners.source_sink_ports_connected) { + g_array_free(graph->listeners.source_sink_ports_connected, + TRUE); + graph->listeners.source_sink_ports_connected = NULL; + } + + if (graph->listeners.filter_sink_ports_connected) { + g_array_free(graph->listeners.filter_sink_ports_connected, + TRUE); + graph->listeners.filter_sink_ports_connected = NULL; + } + + if (graph->listeners.source_filter_ports_disconnected) { + g_array_free(graph->listeners.source_filter_ports_disconnected, + TRUE); + graph->listeners.source_filter_ports_disconnected = NULL; + } + + if (graph->listeners.source_sink_ports_disconnected) { + g_array_free(graph->listeners.source_sink_ports_disconnected, + TRUE); + graph->listeners.source_sink_ports_disconnected = NULL; + } + + if (graph->listeners.filter_sink_ports_disconnected) { + g_array_free(graph->listeners.filter_sink_ports_disconnected, + TRUE); + graph->listeners.filter_sink_ports_disconnected = NULL; } bt_object_pool_finalize(&graph->event_notif_pool); @@ -210,7 +314,7 @@ struct bt_private_graph *bt_private_graph_create(void) goto end; } - bt_object_init_shared(&graph->base, bt_graph_destroy); + bt_object_init_shared(&graph->base, destroy_graph); graph->connections = g_ptr_array_new_with_free_func( (GDestroyNotify) bt_object_try_spec_release); if (!graph->connections) { @@ -229,28 +333,116 @@ struct bt_private_graph *bt_private_graph_create(void) goto error; } - bt_graph_set_can_consume(graph, BT_TRUE); - ret = init_listeners_array(&graph->listeners.port_added); - if (ret) { - BT_LOGE_STR("Cannot create the \"port added\" listener array."); + bt_graph_set_can_consume(graph, true); + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added, + graph->listeners.source_output_port_added); + + if (!graph->listeners.source_output_port_added) { + ret = -1; goto error; } - ret = init_listeners_array(&graph->listeners.port_removed); - if (ret) { - BT_LOGE_STR("Cannot create the \"port removed\" listener array."); + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added, + graph->listeners.filter_output_port_added); + + if (!graph->listeners.filter_output_port_added) { + ret = -1; goto error; } - ret = init_listeners_array(&graph->listeners.ports_connected); - if (ret) { - BT_LOGE_STR("Cannot create the \"port connected\" listener array."); + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added, + graph->listeners.filter_input_port_added); + + if (!graph->listeners.filter_input_port_added) { + ret = -1; goto error; } - ret = init_listeners_array(&graph->listeners.ports_disconnected); - if (ret) { - BT_LOGE_STR("Cannot create the \"port disconneted\" listener array."); + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added, + graph->listeners.sink_input_port_added); + + if (!graph->listeners.sink_input_port_added) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, + graph->listeners.source_output_port_removed); + + if (!graph->listeners.source_output_port_removed) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, + graph->listeners.filter_output_port_removed); + + if (!graph->listeners.filter_output_port_removed) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, + graph->listeners.filter_input_port_removed); + + if (!graph->listeners.filter_input_port_removed) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, + graph->listeners.sink_input_port_removed); + + if (!graph->listeners.sink_input_port_removed) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected, + graph->listeners.source_filter_ports_connected); + + if (!graph->listeners.source_filter_ports_connected) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected, + graph->listeners.source_sink_ports_connected); + + if (!graph->listeners.source_sink_ports_connected) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected, + graph->listeners.filter_sink_ports_connected); + + if (!graph->listeners.filter_sink_ports_connected) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, + graph->listeners.source_filter_ports_disconnected); + + if (!graph->listeners.source_filter_ports_disconnected) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, + graph->listeners.source_sink_ports_disconnected); + + if (!graph->listeners.source_sink_ports_disconnected) { + ret = -1; + goto error; + } + + INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, + graph->listeners.filter_sink_ports_disconnected); + + if (!graph->listeners.filter_sink_ports_disconnected) { + ret = -1; goto error; } @@ -286,10 +478,11 @@ struct bt_private_graph *bt_private_graph_create(void) graph->notifications = g_ptr_array_new_with_free_func( (GDestroyNotify) notify_notification_graph_is_destroyed); - BT_LOGD("Created graph object: addr=%p", graph); + BT_LIB_LOGD("Created graph object: %!+g", graph); end: return (void *) graph; + error: BT_OBJECT_PUT_REF_AND_RESET(graph); goto end; @@ -297,149 +490,93 @@ error: enum bt_graph_status bt_private_graph_connect_ports( struct bt_private_graph *priv_graph, - struct bt_port *upstream_port, struct bt_port *downstream_port, + struct bt_port_output *upstream_port_out, + struct bt_port_input *downstream_port_in, struct bt_connection **user_connection) { struct bt_graph *graph = (void *) priv_graph; enum bt_graph_status status = BT_GRAPH_STATUS_OK; struct bt_connection *connection = NULL; - struct bt_graph *upstream_graph = NULL; - struct bt_graph *downstream_graph = NULL; + struct bt_port *upstream_port = (void *) upstream_port_out; + struct bt_port *downstream_port = (void *) downstream_port_in; struct bt_component *upstream_component = NULL; struct bt_component *downstream_component = NULL; - enum bt_component_status component_status; - bt_bool init_can_consume; + enum bt_self_component_status component_status; + bool init_can_consume; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(upstream_port, "Upstream port"); + BT_ASSERT_PRE_NON_NULL(downstream_port, "Downstream port port"); + BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); + BT_ASSERT_PRE(!bt_port_is_connected(upstream_port), + "Upstream port is already connected: %!+p", upstream_port); + BT_ASSERT_PRE(!bt_port_is_connected(downstream_port), + "Downstream port is already connected: %!+p", downstream_port); + BT_ASSERT_PRE(bt_port_borrow_component((void *) upstream_port), + "Upstream port does not belong to a component: %!+p", + upstream_port); + BT_ASSERT_PRE(bt_port_borrow_component((void *) downstream_port), + "Downstream port does not belong to a component: %!+p", + downstream_port); init_can_consume = graph->can_consume; - - if (!upstream_port) { - BT_LOGW_STR("Invalid parameter: upstream port is NULL."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - if (!downstream_port) { - BT_LOGW_STR("Invalid parameter: downstream port is NULL."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - BT_LOGD("Connecting component ports within graph: " - "graph-addr=%p, " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - graph, upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); - - if (graph->canceled) { - BT_LOGW_STR("Invalid parameter: graph is canceled."); - status = BT_GRAPH_STATUS_CANCELED; - goto end; - } - - bt_graph_set_can_consume(graph, BT_FALSE); - - /* Ensure appropriate types for upstream and downstream ports. */ - if (bt_port_get_type(upstream_port) != BT_PORT_TYPE_OUTPUT) { - BT_LOGW_STR("Invalid parameter: upstream port is not an output port."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - if (bt_port_get_type(downstream_port) != BT_PORT_TYPE_INPUT) { - BT_LOGW_STR("Invalid parameter: downstream port is not an input port."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - /* Ensure that both ports are currently unconnected. */ - if (bt_port_is_connected(upstream_port)) { - BT_LOGW_STR("Invalid parameter: upstream port is already connected."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - if (bt_port_is_connected(downstream_port)) { - BT_LOGW_STR("Invalid parameter: downstream port is already connected."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - /* - * Ensure that both ports are still attached to their creating - * component. - */ - upstream_component = bt_port_get_component(upstream_port); - if (!upstream_component) { - BT_LOGW_STR("Invalid parameter: upstream port is loose (does not belong to a component)"); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - downstream_component = bt_port_get_component(downstream_port); - if (!downstream_component) { - BT_LOGW_STR("Invalid parameter: downstream port is loose (does not belong to a component)"); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - BT_LOGD("Connecting component ports: " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "downstream-comp-addr=%p, downstream-comp-name=\"%s\"", - upstream_component, bt_component_get_name(upstream_component), - downstream_component, bt_component_get_name(downstream_component)); + BT_LIB_LOGD("Connecting component ports within graph: " + "%![graph-]+g, %![up-port-]+p, %![down-port-]+p", + graph, upstream_port, downstream_port); + bt_graph_set_can_consume(graph, false); + upstream_component = bt_port_borrow_component( + (void *) upstream_port); + downstream_component = bt_port_borrow_component( + (void *) downstream_port); /* * At this point the ports are not connected yet. Both * components need to accept an eventual connection to their * port by the other port before we continue. */ - BT_LOGD_STR("Asking upstream component to accept the connection."); + BT_LIB_LOGD("Asking upstream component to accept the connection: " + "%![comp-]+c", upstream_component); component_status = bt_component_accept_port_connection( - upstream_component, upstream_port, downstream_port); - if (component_status != BT_COMPONENT_STATUS_OK) { - if (component_status == BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION) { + upstream_component, (void *) upstream_port, + (void *) downstream_port); + if (component_status != BT_SELF_COMPONENT_STATUS_OK) { + if (component_status == BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION) { BT_LOGD_STR("Upstream component refused the connection."); } else { BT_LOGW("Cannot ask upstream component to accept the connection: " - "status=%s", bt_component_status_string(component_status)); + "status=%s", bt_self_component_status_string(component_status)); } - status = bt_graph_status_from_component_status( - component_status); + status = (int) component_status; goto end; } - BT_LOGD_STR("Asking downstream component to accept the connection."); + BT_LIB_LOGD("Asking downstream component to accept the connection: " + "%![comp-]+c", downstream_component); component_status = bt_component_accept_port_connection( - downstream_component, downstream_port, upstream_port); - if (component_status != BT_COMPONENT_STATUS_OK) { - if (component_status == BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION) { + downstream_component, (void *) downstream_port, + (void *) upstream_port); + if (component_status != BT_SELF_COMPONENT_STATUS_OK) { + if (component_status == BT_SELF_COMPONENT_STATUS_REFUSE_PORT_CONNECTION) { BT_LOGD_STR("Downstream component refused the connection."); } else { BT_LOGW("Cannot ask downstream component to accept the connection: " - "status=%s", bt_component_status_string(component_status)); + "status=%s", bt_self_component_status_string(component_status)); } - status = bt_graph_status_from_component_status( - component_status); + status = (int) component_status; goto end; } BT_LOGD_STR("Creating connection."); - connection = bt_connection_create(graph, upstream_port, - downstream_port); + connection = bt_connection_create(graph, (void *) upstream_port, + (void *) downstream_port); if (!connection) { BT_LOGW("Cannot create connection object."); status = BT_GRAPH_STATUS_NOMEM; goto end; } - BT_LOGD("Connection object created: conn-addr=%p", connection); + BT_LIB_LOGD("Connection object created: %!+x", connection); /* * Ownership of upstream_component/downstream_component and of @@ -450,46 +587,37 @@ enum bt_graph_status bt_private_graph_connect_ports( /* * Notify both components that their port is connected. */ - BT_LOGD_STR("Notifying upstream component that its port is connected."); + BT_LIB_LOGD("Notifying upstream component that its port is connected: " + "%![comp-]+c, %![port-]+p", upstream_component, upstream_port); component_status = bt_component_port_connected(upstream_component, - upstream_port, downstream_port); - if (component_status != BT_COMPONENT_STATUS_OK) { - BT_LOGW("Error while notifying upstream component that its port is connected: " - "status=%s, graph-addr=%p, " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - bt_component_status_string(component_status), graph, - upstream_component, bt_component_get_name(upstream_component), - downstream_component, bt_component_get_name(downstream_component), - upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + (void *) upstream_port, (void *) downstream_port); + if (component_status != BT_SELF_COMPONENT_STATUS_OK) { + BT_LIB_LOGW("Error while notifying upstream component that its port is connected: " + "status=%s, %![graph-]+g, %![up-comp-]+c, " + "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p", + bt_self_component_status_string(component_status), + graph, upstream_component, downstream_component, + upstream_port, downstream_port); bt_connection_end(connection, true); - status = bt_graph_status_from_component_status( - component_status); + status = (int) component_status; goto end; } connection->notified_upstream_port_connected = true; - BT_LOGD_STR("Notifying downstream component that its port is connected."); + BT_LIB_LOGD("Notifying downstream component that its port is connected: " + "%![comp-]+c, %![port-]+p", downstream_component, + downstream_port); component_status = bt_component_port_connected(downstream_component, - downstream_port, upstream_port); - if (component_status != BT_COMPONENT_STATUS_OK) { - BT_LOGW("Error while notifying downstream component that its port is connected: " - "status=%s, graph-addr=%p, " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - bt_component_status_string(component_status), graph, - upstream_component, bt_component_get_name(upstream_component), - downstream_component, bt_component_get_name(downstream_component), - upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + (void *) downstream_port, (void *) upstream_port); + if (component_status != BT_SELF_COMPONENT_STATUS_OK) { + BT_LIB_LOGW("Error while notifying downstream component that its port is connected: " + "status=%s, %![graph-]+g, %![up-comp-]+c, " + "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p", + bt_self_component_status_string(component_status), + graph, upstream_component, downstream_component, + upstream_port, downstream_port); bt_connection_end(connection, true); - status = bt_graph_status_from_component_status( - component_status); + status = (int) component_status; goto end; } @@ -501,17 +629,11 @@ enum bt_graph_status bt_private_graph_connect_ports( BT_LOGD_STR("Notifying graph's user that new component ports are connected."); bt_graph_notify_ports_connected(graph, upstream_port, downstream_port); connection->notified_graph_ports_connected = true; - BT_LOGD("Connected component ports within graph: " - "graph-addr=%p, " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - graph, - upstream_component, bt_component_get_name(upstream_component), - downstream_component, bt_component_get_name(downstream_component), - upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + BT_LIB_LOGD("Connected component ports within graph: " + "%![graph-]+g, %![up-comp-]+c, %![down-comp-]+c, " + "%![up-port-]+p, %![down-port-]+p", + graph, upstream_component, downstream_component, + upstream_port, downstream_port); if (user_connection) { /* Move reference to user */ @@ -520,36 +642,42 @@ enum bt_graph_status bt_private_graph_connect_ports( } end: - bt_object_put_ref(upstream_graph); - bt_object_put_ref(downstream_graph); - bt_object_put_ref(upstream_component); - bt_object_put_ref(downstream_component); bt_object_put_ref(connection); - if (graph) { - (void) init_can_consume; - bt_graph_set_can_consume(graph, init_can_consume); - } + (void) init_can_consume; + bt_graph_set_can_consume(graph, init_can_consume); return status; } static inline -enum bt_graph_status consume_graph_sink(struct bt_component *sink) +enum bt_graph_status consume_graph_sink(struct bt_component_sink *comp) { - enum bt_component_status comp_status; - - BT_ASSERT(sink); - comp_status = bt_component_sink_consume(sink); - BT_LOGV("Consumed from sink: addr=%p, name=\"%s\", status=%s", - sink, bt_component_get_name(sink), - bt_component_status_string(comp_status)); - BT_ASSERT_PRE(comp_status == BT_COMPONENT_STATUS_OK || - comp_status == BT_COMPONENT_STATUS_END || - comp_status == BT_COMPONENT_STATUS_AGAIN || - comp_status == BT_COMPONENT_STATUS_ERROR || - comp_status == BT_COMPONENT_STATUS_NOMEM, - "Invalid component status returned by consuming function: " - "status=%s", bt_component_status_string(comp_status)); - return (enum bt_graph_status) comp_status; + enum bt_self_component_status comp_status; + struct bt_component_class_sink *sink_class = NULL; + + BT_ASSERT(comp); + sink_class = (void *) comp->parent.class; + BT_ASSERT(sink_class->methods.consume); + BT_LIB_LOGD("Calling user's consume method: %!+c", comp); + comp_status = sink_class->methods.consume((void *) comp); + BT_LOGD("User method returned: status=%s", + bt_self_component_status_string(comp_status)); + BT_ASSERT_PRE(comp_status == BT_SELF_COMPONENT_STATUS_OK || + comp_status == BT_SELF_COMPONENT_STATUS_END || + comp_status == BT_SELF_COMPONENT_STATUS_AGAIN || + comp_status == BT_SELF_COMPONENT_STATUS_ERROR || + comp_status == BT_SELF_COMPONENT_STATUS_NOMEM, + "Invalid component status returned by consuming method: " + "status=%s", bt_self_component_status_string(comp_status)); + if (comp_status < 0) { + BT_LOGW_STR("Consume method failed."); + goto end; + } + + BT_LIB_LOGV("Consumed from sink: %![comp-]+c, status=%s", + comp, bt_self_component_status_string(comp_status)); + +end: + return (int) comp_status; } /* @@ -558,11 +686,10 @@ enum bt_graph_status consume_graph_sink(struct bt_component *sink) * still something to consume afterwards. */ static inline -enum bt_graph_status consume_sink_node(struct bt_graph *graph, - GList *node) +enum bt_graph_status consume_sink_node(struct bt_graph *graph, GList *node) { enum bt_graph_status status; - struct bt_component *sink; + struct bt_component_sink *sink; sink = node->data; status = consume_graph_sink(sink); @@ -581,23 +708,21 @@ enum bt_graph_status consume_sink_node(struct bt_graph *graph, } end: - BT_LOGV("Consumed sink node: status=%s", bt_graph_status_string(status)); + BT_LIB_LOGV("Consumed sink node: %![comp-]+c, status=%s", + sink, bt_graph_status_string(status)); return status; } BT_HIDDEN enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, - struct bt_component *sink) + struct bt_component_sink *sink) { enum bt_graph_status status; GList *sink_node; int index; - BT_LOGV("Making specific sink consume: addr=%p, " - "comp-addr=%p, comp-name=\"%s\"", - graph, sink, bt_component_get_name(sink)); - - BT_ASSERT(bt_component_borrow_graph(sink) == graph); + BT_LIB_LOGV("Making specific sink consume: %![comp-]+c", sink); + BT_ASSERT(bt_component_borrow_graph((void *) sink) == graph); if (g_queue_is_empty(graph->sinks_to_consume)) { BT_LOGV_STR("Graph's sink queue is empty: end of graph."); @@ -621,15 +746,15 @@ end: } static inline -enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph) +enum bt_graph_status consume_no_check(struct bt_graph *graph) { enum bt_graph_status status = BT_GRAPH_STATUS_OK; struct bt_component *sink; GList *current_node; - BT_LOGV("Making next sink consume: addr=%p", graph); BT_ASSERT_PRE(graph->has_sink, "Graph has no sink component: %!+g", graph); + BT_LIB_LOGV("Making next sink consume: %![graph-]+g", graph); if (unlikely(g_queue_is_empty(graph->sinks_to_consume))) { BT_LOGV_STR("Graph's sink queue is empty: end of graph."); @@ -639,8 +764,7 @@ enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph) current_node = g_queue_pop_head_link(graph->sinks_to_consume); sink = current_node->data; - BT_LOGV("Chose next sink to consume: comp-addr=%p, comp-name=\"%s\"", - sink, bt_component_get_name(sink)); + BT_LIB_LOGV("Chose next sink to consume: %!+c", sink); status = consume_sink_node(graph, current_node); end: @@ -658,50 +782,38 @@ enum bt_graph_status bt_private_graph_consume( BT_ASSERT_PRE(graph->can_consume, "Cannot consume graph in its current state: %!+g", graph); bt_graph_set_can_consume(graph, BT_FALSE); - status = bt_graph_consume_no_check(graph); + status = consume_no_check(graph); bt_graph_set_can_consume(graph, BT_TRUE); return status; } -enum bt_graph_status bt_private_graph_run( - struct bt_private_graph *priv_graph) +enum bt_graph_status bt_private_graph_run(struct bt_private_graph *priv_graph) { struct bt_graph *graph = (void *) priv_graph; enum bt_graph_status status = BT_GRAPH_STATUS_OK; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - if (graph->canceled) { - BT_LOGW("Invalid parameter: graph is canceled: " - "graph-addr=%p", graph); - status = BT_GRAPH_STATUS_CANCELED; - goto end; - } - + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); BT_ASSERT_PRE(graph->can_consume, "Cannot consume graph in its current state: %!+g", graph); bt_graph_set_can_consume(graph, BT_FALSE); - BT_LOGV("Running graph: addr=%p", graph); + BT_LIB_LOGV("Running graph: %!+g", graph); do { /* * Check if the graph is canceled at each iteration. If * the graph was canceled by another thread or by a - * signal, this is not a warning nor an error, it was - * intentional: log with a DEBUG level only. + * signal handler, this is not a warning nor an error, + * it was intentional: log with a DEBUG level only. */ if (unlikely(graph->canceled)) { - BT_LOGD("Stopping the graph: graph is canceled: " - "graph-addr=%p", graph); + BT_LIB_LOGD("Stopping the graph: graph is canceled: " + "%!+g", graph); status = BT_GRAPH_STATUS_CANCELED; goto end; } - status = bt_graph_consume_no_check(graph); + status = consume_no_check(graph); if (unlikely(status == BT_GRAPH_STATUS_AGAIN)) { /* * If AGAIN is received and there are multiple @@ -710,9 +822,9 @@ enum bt_graph_status bt_private_graph_run( * * However, in the case where a single sink is * left, the caller can decide to busy-wait and - * call bt_graph_run() continuously until the - * source is ready or it can decide to sleep for - * an arbitrary amount of time. + * call bt_private_graph_run() continuously + * until the source is ready or it can decide to + * sleep for an arbitrary amount of time. */ if (graph->sinks_to_consume->length > 1) { status = BT_GRAPH_STATUS_OK; @@ -727,191 +839,587 @@ enum bt_graph_status bt_private_graph_run( } end: - BT_LOGV("Graph ran: status=%s", bt_graph_status_string(status)); - if (graph) { - bt_graph_set_can_consume(graph, BT_TRUE); - } + BT_LIB_LOGV("Graph ran: %![graph-]+g, status=%s", graph, + bt_graph_status_string(status)); + bt_graph_set_can_consume(graph, BT_TRUE); return status; } -static -int add_listener(GArray *listeners, void *func, void *removed, void *data) +enum bt_graph_status +bt_private_graph_add_source_component_output_port_added_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_source_component_output_port_added_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) { - struct bt_graph_listener listener = { - .func = func, - .removed = removed, - .data = data, + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_port_added listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_added_func_t) func, }; + int listener_id; - g_array_append_val(listeners, listener); - return listeners->len - 1; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_output_port_added, listener); + listener_id = graph->listeners.source_output_port_added->len - 1; + BT_LIB_LOGV("Added \"source component output port added\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; } -int bt_private_graph_add_port_added_listener( +enum bt_graph_status +bt_private_graph_add_filter_component_output_port_added_listener( struct bt_private_graph *priv_graph, - bt_private_graph_port_added_listener listener, - bt_private_graph_listener_removed listener_removed, void *data) + bt_private_graph_filter_component_output_port_added_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) { struct bt_graph *graph = (void *) priv_graph; - int ret; + struct bt_graph_listener_port_added listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_added_func_t) func, + }; + int listener_id; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_output_port_added, listener); + listener_id = graph->listeners.filter_output_port_added->len - 1; + BT_LIB_LOGV("Added \"filter component output port added\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - if (graph->in_remove_listener) { - BT_LOGW("Cannot call this function during the execution of a remove listener: " - "addr=%p", graph); - ret = -1; - goto end; - } +enum bt_graph_status +bt_private_graph_add_filter_component_input_port_added_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_filter_component_input_port_added_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_port_added listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_added_func_t) func, + }; + int listener_id; - if (!listener) { - BT_LOGW_STR("Invalid parameter: listener is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_input_port_added, listener); + listener_id = graph->listeners.filter_input_port_added->len - 1; + BT_LIB_LOGV("Added \"filter component input port added\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - ret = add_listener(graph->listeners.port_added, listener, - listener_removed, data); - BT_LOGV("Added \"port added\" listener to graph: " - "graph-addr=%p, listener-addr=%p, pos=%d", - graph, listener, ret); +enum bt_graph_status +bt_private_graph_add_sink_component_input_port_added_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_sink_component_input_port_added_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_port_added listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_added_func_t) func, + }; + int listener_id; -end: - return ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.sink_input_port_added, listener); + listener_id = graph->listeners.sink_input_port_added->len - 1; + BT_LIB_LOGV("Added \"sink component input port added\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; } -int bt_private_graph_add_port_removed_listener( +enum bt_graph_status +bt_private_graph_add_source_component_output_port_removed_listener( struct bt_private_graph *priv_graph, - bt_private_graph_port_removed_listener listener, - bt_private_graph_listener_removed listener_removed, void *data) + bt_private_graph_source_component_output_port_removed_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) { struct bt_graph *graph = (void *) priv_graph; - int ret; + struct bt_graph_listener_port_removed listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_removed_func_t) func, + }; + int listener_id; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_output_port_removed, listener); + listener_id = graph->listeners.source_output_port_removed->len - 1; + BT_LIB_LOGV("Added \"source component output port removed\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - if (graph->in_remove_listener) { - BT_LOGW("Cannot call this function during the execution of a remove listener: " - "addr=%p", graph); - ret = -1; - goto end; - } +enum bt_graph_status +bt_private_graph_add_filter_component_output_port_removed_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_filter_component_output_port_removed_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_port_removed listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_removed_func_t) func, + }; + int listener_id; - if (!listener) { - BT_LOGW_STR("Invalid parameter: listener is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_output_port_removed, listener); + listener_id = graph->listeners.filter_output_port_removed->len - 1; + BT_LIB_LOGV("Added \"filter component output port removed\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - ret = add_listener(graph->listeners.port_removed, listener, - listener_removed, data); - BT_LOGV("Added \"port removed\" listener to graph: " - "graph-addr=%p, listener-addr=%p, pos=%d", - graph, listener, ret); +enum bt_graph_status +bt_private_graph_add_filter_component_input_port_removed_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_filter_component_input_port_removed_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_port_removed listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_removed_func_t) func, + }; + int listener_id; -end: - return ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_input_port_removed, listener); + listener_id = graph->listeners.filter_input_port_removed->len - 1; + BT_LIB_LOGV("Added \"filter component input port removed\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; } -int bt_private_graph_add_ports_connected_listener( +enum bt_graph_status +bt_private_graph_add_sink_component_input_port_removed_listener( struct bt_private_graph *priv_graph, - bt_private_graph_ports_connected_listener listener, - bt_private_graph_listener_removed listener_removed, void *data) + bt_private_graph_sink_component_input_port_removed_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) { struct bt_graph *graph = (void *) priv_graph; - int ret; + struct bt_graph_listener_port_removed listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (port_removed_func_t) func, + }; + int listener_id; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.sink_input_port_removed, listener); + listener_id = graph->listeners.sink_input_port_removed->len - 1; + BT_LIB_LOGV("Added \"sink component input port removed\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - if (graph->in_remove_listener) { - BT_LOGW("Cannot call this function during the execution of a remove listener: " - "addr=%p", graph); - ret = -1; - goto end; - } +enum bt_graph_status +bt_private_graph_add_source_filter_component_ports_connected_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_source_filter_component_ports_connected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_ports_connected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_connected_func_t) func, + }; + int listener_id; - if (!listener) { - BT_LOGW_STR("Invalid parameter: listener is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_filter_ports_connected, + listener); + listener_id = graph->listeners.source_filter_ports_connected->len - 1; + BT_LIB_LOGV("Added \"source to filter component ports connected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - ret = add_listener(graph->listeners.ports_connected, listener, - listener_removed, data); - BT_LOGV("Added \"port connected\" listener to graph: " - "graph-addr=%p, listener-addr=%p, pos=%d", - graph, listener, ret); +enum bt_graph_status +bt_private_graph_add_source_sink_component_ports_connected_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_source_sink_component_ports_connected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_ports_connected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_connected_func_t) func, + }; + int listener_id; -end: - return ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_sink_ports_connected, + listener); + listener_id = graph->listeners.source_sink_ports_connected->len - 1; + BT_LIB_LOGV("Added \"source to sink component ports connected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; } -int bt_private_graph_add_ports_disconnected_listener( +enum bt_graph_status +bt_private_graph_add_filter_sink_component_ports_connected_listener( struct bt_private_graph *priv_graph, - bt_private_graph_ports_disconnected_listener listener, - bt_private_graph_listener_removed listener_removed, void *data) + bt_private_graph_filter_sink_component_ports_connected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) { struct bt_graph *graph = (void *) priv_graph; - int ret; + struct bt_graph_listener_ports_connected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_connected_func_t) func, + }; + int listener_id; - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_sink_ports_connected, + listener); + listener_id = graph->listeners.filter_sink_ports_connected->len - 1; + BT_LIB_LOGV("Added \"filter to sink component ports connected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - if (graph->in_remove_listener) { - BT_LOGW("Cannot call this function during the execution of a remove listener: " - "addr=%p", graph); - ret = -1; - goto end; - } +enum bt_graph_status +bt_private_graph_add_source_filter_component_ports_disconnected_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_source_filter_component_ports_disconnected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_ports_disconnected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_disconnected_func_t) func, + }; + int listener_id; - if (!listener) { - BT_LOGW_STR("Invalid parameter: listener is NULL."); - ret = -1; - goto end; - } + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_filter_ports_disconnected, + listener); + listener_id = graph->listeners.source_filter_ports_disconnected->len - 1; + BT_LIB_LOGV("Added \"source to filter component ports disconnected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} - ret = add_listener(graph->listeners.ports_disconnected, listener, - listener_removed, data); - BT_LOGV("Added \"port disconnected\" listener to graph: " - "graph-addr=%p, listener-addr=%p, pos=%d", - graph, listener, ret); +enum bt_graph_status +bt_private_graph_add_source_sink_component_ports_disconnected_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_source_sink_component_ports_disconnected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_ports_disconnected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_disconnected_func_t) func, + }; + int listener_id; -end: - return ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.source_sink_ports_disconnected, + listener); + listener_id = graph->listeners.source_sink_ports_disconnected->len - 1; + BT_LIB_LOGV("Added \"source to sink component ports disconnected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; +} + +enum bt_graph_status +bt_private_graph_add_filter_sink_component_ports_disconnected_listener( + struct bt_private_graph *priv_graph, + bt_private_graph_filter_sink_component_ports_disconnected_listener func, + bt_private_graph_listener_removed listener_removed, void *data, + int *out_listener_id) +{ + struct bt_graph *graph = (void *) priv_graph; + struct bt_graph_listener_ports_disconnected listener = { + .base = { + .removed = listener_removed, + .data = data, + }, + .func = (ports_disconnected_func_t) func, + }; + int listener_id; + + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(func, "Listener"); + BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); + BT_ASSERT_PRE(!graph->in_remove_listener, + "Graph currently executing a \"listener removed\" listener: " + "%!+g", graph); + g_array_append_val(graph->listeners.filter_sink_ports_disconnected, + listener); + listener_id = graph->listeners.filter_sink_ports_disconnected->len - 1; + BT_LIB_LOGV("Added \"filter to sink component ports disconnected\" listener to graph: " + "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, + listener_id); + + if (listener_id) { + *out_listener_id = listener_id; + } + + return BT_GRAPH_STATUS_OK; } BT_HIDDEN void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port) { - size_t i; + uint64_t i; + GArray *listeners; + struct bt_component *comp; - BT_LOGV("Notifying graph listeners that a port was added: " - "graph-addr=%p, port-addr=%p, port-name=\"%s\"", - graph, port, bt_port_get_name(port)); + BT_ASSERT(graph); + BT_ASSERT(port); + BT_LIB_LOGV("Notifying graph listeners that a port was added: " + "%![graph-]+g, %![port-]+p", graph, port); + comp = bt_port_borrow_component(port); + BT_ASSERT(comp); + + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + switch (port->type) { + case BT_PORT_TYPE_OUTPUT: + listeners = graph->listeners.source_output_port_added; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + switch (port->type) { + case BT_PORT_TYPE_INPUT: + listeners = graph->listeners.filter_input_port_added; + break; + case BT_PORT_TYPE_OUTPUT: + listeners = graph->listeners.filter_output_port_added; + break; + default: + abort(); + } - for (i = 0; i < graph->listeners.port_added->len; i++) { - struct bt_graph_listener listener = - g_array_index(graph->listeners.port_added, - struct bt_graph_listener, i); - bt_private_graph_port_added_listener func = listener.func; + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + switch (port->type) { + case BT_PORT_TYPE_INPUT: + listeners = graph->listeners.sink_input_port_added; + break; + default: + abort(); + } - BT_ASSERT(func); - func(port, listener.data); + break; + } + default: + abort(); + } + + for (i = 0; i < listeners->len; i++) { + struct bt_graph_listener_port_added *listener = + &g_array_index(listeners, + struct bt_graph_listener_port_added, i); + + BT_ASSERT(listener->func); + listener->func(comp, port, listener->base.data); } } @@ -919,20 +1427,65 @@ BT_HIDDEN void bt_graph_notify_port_removed(struct bt_graph *graph, struct bt_component *comp, struct bt_port *port) { - size_t i; + uint64_t i; + GArray *listeners; + + BT_ASSERT(graph); + BT_ASSERT(port); + BT_LIB_LOGV("Notifying graph listeners that a port was removed: " + "%![graph-]+g, %![comp-]+c, %![port-]+p", graph, comp, port); + + switch (comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + switch (port->type) { + case BT_PORT_TYPE_OUTPUT: + listeners = graph->listeners.source_output_port_removed; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + switch (port->type) { + case BT_PORT_TYPE_INPUT: + listeners = graph->listeners.filter_input_port_removed; + break; + case BT_PORT_TYPE_OUTPUT: + listeners = graph->listeners.filter_output_port_removed; + break; + default: + abort(); + } + + break; + } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + switch (port->type) { + case BT_PORT_TYPE_INPUT: + listeners = graph->listeners.sink_input_port_removed; + break; + default: + abort(); + } - BT_LOGV("Notifying graph listeners that a port was removed: " - "graph-addr=%p, port-addr=%p, port-name=\"%s\"", - graph, port, bt_port_get_name(port)); + break; + } + default: + abort(); + } - for (i = 0; i < graph->listeners.port_removed->len; i++) { - struct bt_graph_listener listener = - g_array_index(graph->listeners.port_removed, - struct bt_graph_listener, i); - bt_private_graph_port_removed_listener func = listener.func; + for (i = 0; i < listeners->len; i++) { + struct bt_graph_listener_port_removed *listener = + &g_array_index(listeners, + struct bt_graph_listener_port_removed, i); - BT_ASSERT(func); - func(comp, port, listener.data); + BT_ASSERT(listener->func); + listener->func(comp, port, listener->base.data); } } @@ -940,23 +1493,65 @@ BT_HIDDEN void bt_graph_notify_ports_connected(struct bt_graph *graph, struct bt_port *upstream_port, struct bt_port *downstream_port) { - size_t i; + uint64_t i; + GArray *listeners; + struct bt_component *upstream_comp; + struct bt_component *downstream_comp; - BT_LOGV("Notifying graph listeners that two ports were connected: " - "graph-addr=%p, " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - graph, upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + BT_ASSERT(graph); + BT_ASSERT(upstream_port); + BT_ASSERT(downstream_port); + BT_LIB_LOGV("Notifying graph listeners that ports were connected: " + "%![graph-]+g, %![up-port-]+p, %![down-port-]+p", + graph, upstream_port, downstream_port); + upstream_comp = bt_port_borrow_component(upstream_port); + BT_ASSERT(upstream_comp); + downstream_comp = bt_port_borrow_component(downstream_port); + BT_ASSERT(downstream_comp); + + switch (upstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + switch (downstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_FILTER: + listeners = + graph->listeners.source_filter_ports_connected; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + listeners = + graph->listeners.source_sink_ports_connected; + break; + default: + abort(); + } - for (i = 0; i < graph->listeners.ports_connected->len; i++) { - struct bt_graph_listener listener = - g_array_index(graph->listeners.ports_connected, - struct bt_graph_listener, i); - bt_private_graph_ports_connected_listener func = listener.func; + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + switch (downstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SINK: + listeners = + graph->listeners.filter_sink_ports_connected; + break; + default: + abort(); + } - BT_ASSERT(func); - func(upstream_port, downstream_port, listener.data); + break; + } + default: + abort(); + } + + for (i = 0; i < listeners->len; i++) { + struct bt_graph_listener_ports_connected *listener = + &g_array_index(listeners, + struct bt_graph_listener_ports_connected, i); + + BT_ASSERT(listener->func); + listener->func(upstream_comp, downstream_comp, + upstream_port, downstream_port, listener->base.data); } } @@ -964,26 +1559,66 @@ BT_HIDDEN void bt_graph_notify_ports_disconnected(struct bt_graph *graph, struct bt_component *upstream_comp, struct bt_component *downstream_comp, - struct bt_port *upstream_port, struct bt_port *downstream_port) + struct bt_port *upstream_port, + struct bt_port *downstream_port) { - size_t i; + uint64_t i; + GArray *listeners; + + BT_ASSERT(graph); + BT_ASSERT(upstream_comp); + BT_ASSERT(downstream_comp); + BT_ASSERT(upstream_port); + BT_ASSERT(downstream_port); + BT_LIB_LOGV("Notifying graph listeners that ports were disconnected: " + "%![graph-]+g, %![up-port-]+p, %![down-port-]+p, " + "%![up-comp-]+c, %![down-comp-]+c", + graph, upstream_port, downstream_port, upstream_comp, + downstream_comp); + + switch (upstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + switch (downstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_FILTER: + listeners = + graph->listeners.source_filter_ports_disconnected; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + listeners = + graph->listeners.source_sink_ports_disconnected; + break; + default: + abort(); + } - BT_LOGV("Notifying graph listeners that two ports were disconnected: " - "graph-addr=%p, " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "downstream-port-addr=%p, downstream-port-name=\"%s\"", - graph, upstream_port, bt_port_get_name(upstream_port), - downstream_port, bt_port_get_name(downstream_port)); + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + switch (downstream_comp->class->type) { + case BT_COMPONENT_CLASS_TYPE_SINK: + listeners = + graph->listeners.filter_sink_ports_disconnected; + break; + default: + abort(); + } + + break; + } + default: + abort(); + } - for (i = 0; i < graph->listeners.ports_disconnected->len; i++) { - struct bt_graph_listener listener = - g_array_index(graph->listeners.ports_disconnected, - struct bt_graph_listener, i); - bt_private_graph_ports_disconnected_listener func = listener.func; + for (i = 0; i < listeners->len; i++) { + struct bt_graph_listener_ports_disconnected *listener = + &g_array_index(listeners, + struct bt_graph_listener_ports_disconnected, i); - BT_ASSERT(func); - func(upstream_comp, downstream_comp, upstream_port, - downstream_port, listener.data); + BT_ASSERT(listener->func); + listener->func(upstream_comp, downstream_comp, + upstream_port, downstream_port, listener->base.data); } } @@ -991,34 +1626,17 @@ enum bt_graph_status bt_private_graph_cancel( struct bt_private_graph *priv_graph) { struct bt_graph *graph = (void *) priv_graph; - enum bt_graph_status ret = BT_GRAPH_STATUS_OK; - - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - ret = BT_GRAPH_STATUS_INVALID; - goto end; - } - - graph->canceled = BT_TRUE; - BT_LOGV("Canceled graph: addr=%p", graph); -end: - return ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + graph->canceled = true; + BT_LIB_LOGV("Canceled graph: %!+i", graph); + return BT_GRAPH_STATUS_OK; } bt_bool bt_graph_is_canceled(struct bt_graph *graph) { - bt_bool canceled = BT_FALSE; - - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - goto end; - } - - canceled = graph->canceled; - -end: - return canceled; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + return graph->canceled ? BT_TRUE : BT_FALSE; } BT_HIDDEN @@ -1027,98 +1645,67 @@ void bt_graph_remove_connection(struct bt_graph *graph, { BT_ASSERT(graph); BT_ASSERT(connection); - BT_LOGV("Removing graph's connection: graph-addr=%p, conn-addr=%p", + BT_LIB_LOGV("Removing graph's connection: %![graph-]+g, %![conn-]+x", graph, connection); g_ptr_array_remove(graph->connections, connection); } -enum bt_graph_status bt_private_graph_add_component_with_init_method_data( +BT_ASSERT_PRE_FUNC +static inline +bool component_name_exists(struct bt_graph *graph, const char *name) +{ + bool exists = false; + uint64_t i; + + for (i = 0; i < graph->components->len; i++) { + struct bt_component *other_comp = graph->components->pdata[i]; + + if (strcmp(name, bt_component_get_name(other_comp)) == 0) { + BT_ASSERT_PRE_MSG("Another component with the same name already exists in the graph: " + "%![other-comp-]+c, name=\"%s\"", + other_comp, name); + exists = true; + goto end; + } + } + +end: + return exists; +} + +static +enum bt_graph_status add_component_with_init_method_data( struct bt_private_graph *priv_graph, - struct bt_component_class *component_class, + struct bt_component_class *comp_cls, + comp_init_method_t init_method, const char *name, struct bt_value *params, - void *init_method_data, - struct bt_component **user_component) + void *init_method_data, struct bt_component **user_component) { struct bt_graph *graph = (void *) priv_graph; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; - enum bt_component_status comp_status; + enum bt_self_component_status comp_status; struct bt_component *component = NULL; - enum bt_component_class_type type; - size_t i; - bt_bool init_can_consume; + int ret; + bool init_can_consume; + BT_ASSERT(comp_cls); + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); + BT_ASSERT_PRE(!component_name_exists(graph, name), + "Duplicate component name: %!+g, name=\"%s\"", graph, name); + BT_ASSERT_PRE(!params || bt_value_is_map(params), + "Parameter value is not a map value: %!+v", params); bt_object_get_ref(params); - - if (!graph) { - BT_LOGW_STR("Invalid parameter: graph is NULL."); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } init_can_consume = graph->can_consume; - - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - graph->can_consume = BT_FALSE; - type = bt_component_class_get_type(component_class); - BT_LOGD("Adding component to graph: " - "graph-addr=%p, comp-cls-addr=%p, " - "comp-cls-type=%s, name=\"%s\", params-addr=%p, " + bt_graph_set_can_consume(graph, false); + BT_LIB_LOGD("Adding component to graph: " + "%![graph-]+g, %![cc-]+C, name=\"%s\", %![params-]+v, " "init-method-data-addr=%p", - graph, component_class, bt_component_class_type_string(type), - name, params, init_method_data); + graph, comp_cls, name, params, init_method_data); - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - if (graph->canceled) { - BT_LOGW_STR("Invalid parameter: graph is canceled."); - graph_status = BT_GRAPH_STATUS_CANCELED; - goto end; - } - - if (type != BT_COMPONENT_CLASS_TYPE_SOURCE && - type != BT_COMPONENT_CLASS_TYPE_FILTER && - type != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: unknown component class type: " - "type=%d", type); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } - - for (i = 0; i < graph->components->len; i++) { - void *other_comp = graph->components->pdata[i]; - - if (strcmp(name, bt_component_get_name(other_comp)) == 0) { - BT_LOGW("Invalid parameter: another component with the same name already exists in the graph: " - "other-comp-addr=%p, name=\"%s\"", - other_comp, name); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } - } - - /* - * Parameters must be a map value, but we create a convenient - * empty one if it's NULL. - */ - if (params) { - if (!bt_value_is_map(params)) { - BT_LOGW("Invalid parameter: initialization parameters must be a map value: " - "type=%s", - bt_common_value_type_string( - bt_value_get_type(params))); - graph_status = BT_GRAPH_STATUS_INVALID; - goto end; - } - } else { - params = bt_value_borrow_from_private( + if (!params) { + params = bt_private_value_borrow_value( bt_private_value_map_create()); if (!params) { BT_LOGE_STR("Cannot create map value object."); @@ -1127,12 +1714,11 @@ enum bt_graph_status bt_private_graph_add_component_with_init_method_data( } } - comp_status = bt_component_create(component_class, name, &component); - if (comp_status != BT_COMPONENT_STATUS_OK) { - BT_LOGE("Cannot create empty component object: status=%s", - bt_component_status_string(comp_status)); - graph_status = bt_graph_status_from_component_status( - comp_status); + ret = bt_component_create(comp_cls, name, &component); + if (ret) { + BT_LOGE("Cannot create empty component object: ret=%d", + ret); + graph_status = BT_GRAPH_STATUS_NOMEM; goto end; } @@ -1144,17 +1730,14 @@ enum bt_graph_status bt_private_graph_add_component_with_init_method_data( g_ptr_array_add(graph->components, component); bt_component_set_graph(component, graph); - if (component_class->methods.init) { + if (init_method) { BT_LOGD_STR("Calling user's initialization method."); - comp_status = component_class->methods.init( - bt_private_component_from_component(component), params, - init_method_data); + comp_status = init_method(component, params, init_method_data); BT_LOGD("User method returned: status=%s", - bt_component_status_string(comp_status)); - if (comp_status != BT_COMPONENT_STATUS_OK) { + bt_self_component_status_string(comp_status)); + if (comp_status != BT_SELF_COMPONENT_STATUS_OK) { BT_LOGW_STR("Initialization method failed."); - graph_status = bt_graph_status_from_component_status( - comp_status); + graph_status = (int) comp_status; bt_component_set_graph(component, NULL); g_ptr_array_remove_fast(graph->components, component); goto end; @@ -1172,7 +1755,7 @@ enum bt_graph_status bt_private_graph_add_component_with_init_method_data( * sink queue to be consumed by bt_graph_consume(). */ if (bt_component_is_sink(component)) { - graph->has_sink = BT_TRUE; + graph->has_sink = true; g_queue_push_tail(graph->sinks_to_consume, component); } @@ -1181,13 +1764,11 @@ enum bt_graph_status bt_private_graph_add_component_with_init_method_data( * least once. */ BT_LOGD_STR("Freezing component class."); - bt_component_class_freeze(component->class); - BT_LOGD("Added component to graph: " - "graph-addr=%p, comp-cls-addr=%p, " - "comp-cls-type=%s, name=\"%s\", params-addr=%p, " - "init-method-data-addr=%p, comp-addr=%p", - graph, component_class, bt_component_class_type_string(type), - name, params, init_method_data, component); + bt_component_class_freeze(comp_cls); + BT_LIB_LOGD("Added component to graph: " + "%![graph-]+g, %![cc-]+C, name=\"%s\", %![params-]+v, " + "init-method-data-addr=%p, %![comp-]+c", + graph, comp_cls, name, params, init_method_data, component); if (user_component) { /* Move reference to user */ @@ -1198,28 +1779,86 @@ enum bt_graph_status bt_private_graph_add_component_with_init_method_data( end: bt_object_put_ref(component); bt_object_put_ref(params); - if (graph) { - graph->can_consume = init_can_consume; - } + (void) init_can_consume; + bt_graph_set_can_consume(graph, init_can_consume); return graph_status; } -enum bt_graph_status bt_private_graph_add_component( +enum bt_graph_status +bt_private_graph_add_source_component_with_init_method_data( + struct bt_private_graph *graph, + struct bt_component_class_source *comp_cls, + const char *name, struct bt_value *params, + void *init_method_data, struct bt_component_source **component) +{ + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return add_component_with_init_method_data(graph, + (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init, + name, params, init_method_data, (void *) component); +} + +enum bt_graph_status bt_private_graph_add_source_component( + struct bt_private_graph *graph, + struct bt_component_class_source *comp_cls, + const char *name, struct bt_value *params, + struct bt_component_source **component) +{ + return bt_private_graph_add_source_component_with_init_method_data( + graph, comp_cls, name, params, NULL, component); +} + +enum bt_graph_status +bt_private_graph_add_filter_component_with_init_method_data( + struct bt_private_graph *graph, + struct bt_component_class_filter *comp_cls, + const char *name, struct bt_value *params, + void *init_method_data, struct bt_component_filter **component) +{ + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return add_component_with_init_method_data(graph, + (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init, + name, params, init_method_data, (void *) component); +} + +enum bt_graph_status bt_private_graph_add_filter_component( + struct bt_private_graph *graph, + struct bt_component_class_filter *comp_cls, + const char *name, struct bt_value *params, + struct bt_component_filter **component) +{ + return bt_private_graph_add_filter_component_with_init_method_data( + graph, comp_cls, name, params, NULL, component); +} + +enum bt_graph_status +bt_private_graph_add_sink_component_with_init_method_data( struct bt_private_graph *graph, - struct bt_component_class *component_class, + struct bt_component_class_sink *comp_cls, const char *name, struct bt_value *params, - struct bt_component **component) + void *init_method_data, struct bt_component_sink **component) { - return bt_private_graph_add_component_with_init_method_data(graph, - component_class, name, params, NULL, component); + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + return add_component_with_init_method_data(graph, + (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init, + name, params, init_method_data, (void *) component); +} + +enum bt_graph_status bt_private_graph_add_sink_component( + struct bt_private_graph *graph, + struct bt_component_class_sink *comp_cls, + const char *name, struct bt_value *params, + struct bt_component_sink **component) +{ + return bt_private_graph_add_sink_component_with_init_method_data( + graph, comp_cls, name, params, NULL, component); } BT_HIDDEN int bt_graph_remove_unconnected_component(struct bt_graph *graph, struct bt_component *component) { - bt_bool init_can_consume; - int64_t count; + bool init_can_consume; + uint64_t count; uint64_t i; int ret = 0; @@ -1232,21 +1871,16 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph, count = bt_component_get_input_port_count(component); for (i = 0; i < count; i++) { - struct bt_port *port = - bt_component_get_input_port_by_index(component, i); + struct bt_port *port = (void *) + bt_component_borrow_input_port_by_index(component, i); BT_ASSERT(port); - bt_object_put_ref(port); if (bt_port_is_connected(port)) { - BT_LOGW("Cannot remove component from graph: " + BT_LIB_LOGW("Cannot remove component from graph: " "an input port is connected: " - "graph-addr=%p, comp-addr=%p, " - "comp-name=\"%s\", connected-port-addr=%p, " - "connected-port-name=\"%s\"", - graph, component, - bt_component_get_name(component), - port, bt_port_get_name(port)); + "%![graph-]+g, %![comp-]+c, %![port-]+p", + graph, component, port); goto error; } } @@ -1254,32 +1888,27 @@ int bt_graph_remove_unconnected_component(struct bt_graph *graph, count = bt_component_get_output_port_count(component); for (i = 0; i < count; i++) { - struct bt_port *port = - bt_component_get_output_port_by_index(component, i); + struct bt_port *port = (void *) + bt_component_borrow_output_port_by_index(component, i); BT_ASSERT(port); - bt_object_put_ref(port); if (bt_port_is_connected(port)) { - BT_LOGW("Cannot remove component from graph: " + BT_LIB_LOGW("Cannot remove component from graph: " "an output port is connected: " - "graph-addr=%p, comp-addr=%p, " - "comp-name=\"%s\", connected-port-addr=%p, " - "connected-port-name=\"%s\"", - graph, component, - bt_component_get_name(component), - port, bt_port_get_name(port)); + "%![graph-]+g, %![comp-]+c, %![port-]+p", + graph, component, port); goto error; } } - graph->can_consume = BT_FALSE; + bt_graph_set_can_consume(graph, false); /* Possibly remove from sinks to consume */ (void) g_queue_remove(graph->sinks_to_consume, component); if (graph->sinks_to_consume->length == 0) { - graph->has_sink = BT_FALSE; + graph->has_sink = false; } /* @@ -1294,7 +1923,8 @@ error: ret = -1; end: - graph->can_consume = init_can_consume; + (void) init_can_consume; + bt_graph_set_can_consume(graph, init_can_consume); return ret; } @@ -1315,9 +1945,3 @@ void bt_graph_add_notification(struct bt_graph *graph, */ g_ptr_array_add(graph->notifications, notif); } - -struct bt_graph *bt_graph_borrow_from_private( - struct bt_private_graph *priv_graph) -{ - return (void *) priv_graph; -} diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index ffaf7d45..ca0c49d2 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -1,8 +1,4 @@ /* - * iterator.c - * - * Babeltrace Notification Iterator - * * Copyright 2015 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -45,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -85,9 +83,9 @@ void destroy_stream_state(struct stream_state *stream_state) BT_LOGV("Destroying stream state: stream-state-addr=%p", stream_state); BT_LOGV_STR("Putting stream state's current packet."); - bt_object_put_ref(stream_state->cur_packet); + BT_OBJECT_PUT_REF_AND_RESET(stream_state->cur_packet); BT_LOGV_STR("Putting stream state's stream."); - bt_object_put_ref(stream_state->stream); + BT_OBJECT_PUT_REF_AND_RESET(stream_state->stream); g_free(stream_state); } @@ -106,9 +104,9 @@ struct stream_state *create_stream_state(struct bt_stream *stream) * We keep a reference to the stream until we know it's ended. */ stream_state->stream = bt_object_get_ref(stream); - BT_LOGV("Created stream state: stream-addr=%p, stream-name=\"%s\", " + BT_LIB_LOGV("Created stream state: %![stream-]+s, " "stream-state-addr=%p", - stream, bt_stream_get_name(stream), stream_state); + stream, stream_state); end: return stream_state; @@ -123,15 +121,16 @@ void destroy_base_notification_iterator(struct bt_object *obj) if (iterator->notifs) { g_ptr_array_free(iterator->notifs, TRUE); + iterator->notifs = NULL; } g_free(iterator); } static -void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) +void bt_self_component_port_input_notification_iterator_destroy(struct bt_object *obj) { - struct bt_notification_iterator_private_connection *iterator; + struct bt_self_component_port_input_notification_iterator *iterator; BT_ASSERT(obj); @@ -139,17 +138,18 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) * The notification iterator's reference count is 0 if we're * here. Increment it to avoid a double-destroy (possibly * infinitely recursive). This could happen for example if the - * notification iterator's finalization function does bt_object_get_ref() - * (or anything that causes bt_object_get_ref() to be called) on itself - * (ref. count goes from 0 to 1), and then bt_object_put_ref(): the - * reference count would go from 1 to 0 again and this function - * would be called again. + * notification iterator's finalization function does + * bt_object_get_ref() (or anything that causes + * bt_object_get_ref() to be called) on itself (ref. count goes + * from 0 to 1), and then bt_object_put_ref(): the reference + * count would go from 1 to 0 again and this function would be + * called again. */ obj->ref_count++; iterator = (void *) obj; - BT_LOGD("Destroying private connection notification iterator object: addr=%p", - iterator); - bt_private_connection_notification_iterator_finalize(iterator); + BT_LIB_LOGD("Destroying self component input port notification iterator object: " + "%!+i", iterator); + bt_self_component_port_input_notification_iterator_finalize(iterator); if (iterator->stream_states) { /* @@ -159,6 +159,7 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) * notification iterator object. */ g_hash_table_destroy(iterator->stream_states); + iterator->stream_states = NULL; } if (iterator->connection) { @@ -168,47 +169,49 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj) * later. */ bt_connection_remove_iterator(iterator->connection, iterator); + iterator->connection = NULL; } destroy_base_notification_iterator(obj); } BT_HIDDEN -void bt_private_connection_notification_iterator_finalize( - struct bt_notification_iterator_private_connection *iterator) +void bt_self_component_port_input_notification_iterator_finalize( + struct bt_self_component_port_input_notification_iterator *iterator) { + typedef void (*method_t)(void *); + struct bt_component_class *comp_class = NULL; - bt_component_class_notification_iterator_finalize_method - finalize_method = NULL; + method_t method = NULL; BT_ASSERT(iterator); switch (iterator->state) { - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED: + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED: /* Skip user finalization if user initialization failed */ - BT_LOGD("Not finalizing non-initialized notification iterator: " - "addr=%p", iterator); + BT_LIB_LOGD("Not finalizing non-initialized notification iterator: " + "%!+i", iterator); return; - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED: - case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED: + case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: /* Already finalized */ - BT_LOGD("Not finalizing notification iterator: already finalized: " - "addr=%p", iterator); + BT_LIB_LOGD("Not finalizing notification iterator: already finalized: " + "%!+i", iterator); return; default: break; } - BT_LOGD("Finalizing notification iterator: addr=%p", iterator); + BT_LIB_LOGD("Finalizing notification iterator: %!+i", iterator); - if (iterator->state == BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED) { - BT_LOGD("Updating notification iterator's state: " - "new-state=BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"); - iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED; + if (iterator->state == BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED) { + BT_LIB_LOGD("Updating notification iterator's state: " + "new-state=BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"); + iterator->state = BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED; } else { - BT_LOGD("Updating notification iterator's state: " - "new-state=BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED"); - iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED; + BT_LIB_LOGD("Updating notification iterator's state: " + "new-state=BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED"); + iterator->state = BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED; } BT_ASSERT(iterator->upstream_component); @@ -218,18 +221,18 @@ void bt_private_connection_notification_iterator_finalize( switch (comp_class->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: { - struct bt_component_class_source *source_class; + struct bt_component_class_source *src_comp_cls = + (void *) comp_class; - source_class = container_of(comp_class, struct bt_component_class_source, parent); - finalize_method = source_class->methods.iterator.finalize; + method = (method_t) src_comp_cls->methods.notif_iter_finalize; break; } case BT_COMPONENT_CLASS_TYPE_FILTER: { - struct bt_component_class_filter *filter_class; + struct bt_component_class_filter *flt_comp_cls = + (void *) comp_class; - filter_class = container_of(comp_class, struct bt_component_class_filter, parent); - finalize_method = filter_class->methods.iterator.finalize; + method = (method_t) flt_comp_cls->methods.notif_iter_finalize; break; } default: @@ -237,27 +240,26 @@ void bt_private_connection_notification_iterator_finalize( abort(); } - if (finalize_method) { - BT_LOGD("Calling user's finalization method: addr=%p", + if (method) { + BT_LIB_LOGD("Calling user's finalization method: %!+i", iterator); - finalize_method( - bt_private_connection_private_notification_iterator_from_notification_iterator(iterator)); + method(iterator); } iterator->upstream_component = NULL; iterator->upstream_port = NULL; - BT_LOGD("Finalized notification iterator: addr=%p", iterator); + BT_LIB_LOGD("Finalized notification iterator: %!+i", iterator); } BT_HIDDEN -void bt_private_connection_notification_iterator_set_connection( - struct bt_notification_iterator_private_connection *iterator, +void bt_self_component_port_input_notification_iterator_set_connection( + struct bt_self_component_port_input_notification_iterator *iterator, struct bt_connection *connection) { BT_ASSERT(iterator); iterator->connection = connection; - BT_LOGV("Set notification iterator's connection: " - "iter-addr=%p, conn-addr=%p", iterator, connection); + BT_LIB_LOGV("Set notification iterator's connection: " + "%![iter-]+i, %![conn-]+x", iterator, connection); } static @@ -282,45 +284,38 @@ end: return ret; } -BT_HIDDEN -enum bt_connection_status bt_private_connection_notification_iterator_create( +static +struct bt_self_component_port_input_notification_iterator * +bt_self_component_port_input_notification_iterator_create_initial( struct bt_component *upstream_comp, - struct bt_port *upstream_port, - struct bt_connection *connection, - struct bt_notification_iterator_private_connection **user_iterator) + struct bt_port *upstream_port) { - enum bt_connection_status status = BT_CONNECTION_STATUS_OK; - enum bt_component_class_type type; - struct bt_notification_iterator_private_connection *iterator = NULL; int ret; + struct bt_self_component_port_input_notification_iterator *iterator = NULL; BT_ASSERT(upstream_comp); BT_ASSERT(upstream_port); BT_ASSERT(bt_port_is_connected(upstream_port)); - BT_ASSERT(user_iterator); - BT_LOGD("Creating notification iterator on private connection: " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "conn-addr=%p", - upstream_comp, bt_component_get_name(upstream_comp), - upstream_port, bt_port_get_name(upstream_port), - connection); - type = bt_component_get_class_type(upstream_comp); - BT_ASSERT(type == BT_COMPONENT_CLASS_TYPE_SOURCE || - type == BT_COMPONENT_CLASS_TYPE_FILTER); - iterator = g_new0(struct bt_notification_iterator_private_connection, 1); + BT_LIB_LOGD("Creating initial notification iterator on self component input port: " + "%![up-comp-]+c, %![up-port-]+p", upstream_comp, upstream_port); + BT_ASSERT(bt_component_get_class_type(upstream_comp) == + BT_COMPONENT_CLASS_TYPE_SOURCE || + bt_component_get_class_type(upstream_comp) == + BT_COMPONENT_CLASS_TYPE_FILTER); + iterator = g_new0( + struct bt_self_component_port_input_notification_iterator, 1); if (!iterator) { - BT_LOGE_STR("Failed to allocate one private connection notification iterator."); - status = BT_CONNECTION_STATUS_NOMEM; + BT_LOGE_STR("Failed to allocate one self component input port " + "notification iterator."); goto end; } ret = init_notification_iterator((void *) iterator, - BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION, - bt_private_connection_notification_iterator_destroy); + BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT, + bt_self_component_port_input_notification_iterator_destroy); if (ret) { /* init_notification_iterator() logs errors */ - status = BT_CONNECTION_STATUS_NOMEM; + BT_OBJECT_PUT_REF_AND_RESET(iterator); goto end; } @@ -328,66 +323,134 @@ enum bt_connection_status bt_private_connection_notification_iterator_create( g_direct_equal, NULL, (GDestroyNotify) destroy_stream_state); if (!iterator->stream_states) { BT_LOGE_STR("Failed to allocate a GHashTable."); - status = BT_CONNECTION_STATUS_NOMEM; + BT_OBJECT_PUT_REF_AND_RESET(iterator); goto end; } iterator->upstream_component = upstream_comp; iterator->upstream_port = upstream_port; - iterator->connection = connection; + iterator->connection = iterator->upstream_port->connection; iterator->graph = bt_component_borrow_graph(upstream_comp); - iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED; - BT_LOGD("Created notification iterator: " - "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " - "upstream-port-addr=%p, upstream-port-name=\"%s\", " - "conn-addr=%p, iter-addr=%p", - upstream_comp, bt_component_get_name(upstream_comp), - upstream_port, bt_port_get_name(upstream_port), - connection, iterator); - - /* Move reference to user */ - *user_iterator = iterator; - iterator = NULL; + iterator->state = BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED; + BT_LIB_LOGD("Created initial notification iterator on self component input port: " + "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i", + upstream_port, upstream_comp, iterator); end: - bt_object_put_ref(iterator); - return status; + return iterator; } -void *bt_private_connection_private_notification_iterator_get_user_data( - struct bt_private_connection_private_notification_iterator *private_iterator) +struct bt_self_component_port_input_notification_iterator * +bt_self_component_port_input_notification_iterator_create( + struct bt_self_component_port_input *self_port) { - struct bt_notification_iterator_private_connection *iterator = (void *) - bt_private_connection_notification_iterator_borrow_from_private(private_iterator); + typedef enum bt_self_notification_iterator_status (*init_method_t)( + void *, void *, void *); + + init_method_t init_method = NULL; + struct bt_self_component_port_input_notification_iterator *iterator = + NULL; + struct bt_port *port = (void *) self_port; + struct bt_port *upstream_port; + struct bt_component *comp; + struct bt_component *upstream_comp; + struct bt_component_class *upstream_comp_cls; + + BT_ASSERT_PRE_NON_NULL(port, "Port"); + comp = bt_port_borrow_component(port); + BT_ASSERT_PRE(bt_port_is_connected(port), + "Port is not connected: %![port-]+p", port); + BT_ASSERT_PRE(comp, "Port is not part of a component: %![port-]+p", + port); + BT_ASSERT_PRE(!bt_component_graph_is_canceled(comp), + "Port's component's graph is canceled: " + "%![port-]+p, %![comp-]+c", port, comp); + BT_ASSERT(port->connection); + upstream_port = port->connection->upstream_port; + BT_ASSERT(upstream_port); + upstream_comp = bt_port_borrow_component(upstream_port); + BT_ASSERT(upstream_comp); + upstream_comp_cls = upstream_comp->class; + BT_ASSERT(upstream_comp->class->type == + BT_COMPONENT_CLASS_TYPE_SOURCE || + upstream_comp->class->type == + BT_COMPONENT_CLASS_TYPE_FILTER); + iterator = bt_self_component_port_input_notification_iterator_create_initial( + upstream_comp, upstream_port); + if (!iterator) { + BT_LOGW_STR("Cannot create self component input port " + "notification iterator."); + goto end; + } - BT_ASSERT_PRE_NON_NULL(private_iterator, "Notification iterator"); - return iterator->user_data; + switch (upstream_comp_cls->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_comp_cls = + (void *) upstream_comp_cls; + + init_method = + (init_method_t) src_comp_cls->methods.notif_iter_init; + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_comp_cls = + (void *) upstream_comp_cls; + + init_method = + (init_method_t) flt_comp_cls->methods.notif_iter_init; + break; + } + default: + /* Unreachable */ + abort(); + } + + if (init_method) { + int iter_status; + + BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator); + iter_status = init_method(iterator, upstream_comp, + upstream_port); + BT_LOGD("User method returned: status=%s", + bt_notification_iterator_status_string(iter_status)); + if (iter_status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + BT_LOGW_STR("Initialization method failed."); + goto end; + } + } + + iterator->state = BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE; + g_ptr_array_add(port->connection->iterators, iterator); + BT_LIB_LOGD("Created notification iterator on self component input port: " + "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i", + upstream_port, upstream_comp, iterator); + +end: + return iterator; } -enum bt_notification_iterator_status -bt_private_connection_private_notification_iterator_set_user_data( - struct bt_private_connection_private_notification_iterator *private_iterator, - void *data) +void *bt_self_notification_iterator_get_data( + struct bt_self_notification_iterator *self_iterator) { - struct bt_notification_iterator_private_connection *iterator = (void *) - bt_private_connection_notification_iterator_borrow_from_private(private_iterator); + struct bt_self_component_port_input_notification_iterator *iterator = + (void *) self_iterator; BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); - iterator->user_data = data; - BT_LOGV("Set notification iterator's user data: " - "iter-addr=%p, user-data-addr=%p", iterator, data); - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return iterator->user_data; } -struct bt_graph *bt_private_connection_private_notification_iterator_borrow_graph( - struct bt_private_connection_private_notification_iterator *private_iterator) +void bt_self_notification_iterator_set_data( + struct bt_self_notification_iterator *self_iterator, void *data) { - struct bt_notification_iterator_private_connection *iterator = (void *) - bt_private_connection_notification_iterator_borrow_from_private( - private_iterator); + struct bt_self_component_port_input_notification_iterator *iterator = + (void *) self_iterator; BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); - return iterator->graph; + iterator->user_data = data; + BT_LIB_LOGV("Set notification iterator's user data: " + "%!+i, user-data-addr=%p", iterator, data); } BT_ASSERT_PRE_FUNC @@ -425,7 +488,7 @@ void bt_notification_borrow_packet_stream(struct bt_notification *notif, BT_ASSERT_PRE_FUNC static inline bool validate_notification( - struct bt_notification_iterator_private_connection *iterator, + struct bt_self_component_port_input_notification_iterator *iterator, struct bt_notification *notif) { bool is_valid = true; @@ -587,7 +650,7 @@ end: BT_ASSERT_PRE_FUNC static inline bool validate_notifications( - struct bt_notification_iterator_private_connection *iterator, + struct bt_self_component_port_input_notification_iterator *iterator, uint64_t count) { bool ret = true; @@ -606,7 +669,7 @@ bool validate_notifications( BT_ASSERT_PRE_FUNC static inline bool priv_conn_notif_iter_can_end( - struct bt_notification_iterator_private_connection *iterator) + struct bt_self_component_port_input_notification_iterator *iterator) { GHashTableIter iter; gpointer stream_key, state_value; @@ -640,54 +703,46 @@ end: } enum bt_notification_iterator_status -bt_private_connection_notification_iterator_next( - struct bt_notification_iterator *user_iterator, - struct bt_notification ***user_notifs, uint64_t *user_count) +bt_self_component_port_input_notification_iterator_next( + struct bt_self_component_port_input_notification_iterator *iterator, + bt_notification_array *notifs, uint64_t *user_count) { - struct bt_notification_iterator_private_connection *iterator = - (void *) user_iterator; - struct bt_private_connection_private_notification_iterator *priv_iterator = - bt_private_connection_private_notification_iterator_from_notification_iterator(iterator); - bt_component_class_notification_iterator_next_method next_method = NULL; - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - BT_ASSERT_PRE_NON_NULL(user_iterator, "Notification iterator"); - BT_ASSERT_PRE_NON_NULL(user_notifs, "Notification array"); - BT_ASSERT_PRE_NON_NULL(user_count, "Notification count"); - BT_ASSERT_PRE(user_iterator->type == - BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION, - "Notification iterator was not created from a private connection: " - "%!+i", iterator); - BT_LIB_LOGD("Getting next private connection notification iterator's notification: %!+i", - iterator); + typedef enum bt_self_notification_iterator_status (*method_t)( + void *, bt_notification_array, uint64_t, uint64_t *); + + method_t method = NULL; + struct bt_component_class *comp_cls; + int status = BT_NOTIFICATION_ITERATOR_STATUS_OK; + + BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); + BT_ASSERT_PRE_NON_NULL(notifs, "Notification array (output)"); + BT_ASSERT_PRE_NON_NULL(user_count, "Notification count (output)"); BT_ASSERT_PRE(iterator->state == - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE, + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE, "Notification iterator's \"next\" called, but " "iterator is in the wrong state: %!+i", iterator); BT_ASSERT(iterator->upstream_component); BT_ASSERT(iterator->upstream_component->class); + BT_LIB_LOGD("Getting next self component input port " + "notification iterator's notifications: %!+i", iterator); + comp_cls = iterator->upstream_component->class; /* Pick the appropriate "next" method */ - switch (iterator->upstream_component->class->type) { + switch (comp_cls->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: { - struct bt_component_class_source *source_class = - container_of(iterator->upstream_component->class, - struct bt_component_class_source, parent); + struct bt_component_class_source *src_comp_cls = + (void *) comp_cls; - BT_ASSERT(source_class->methods.iterator.next); - next_method = source_class->methods.iterator.next; + method = (method_t) src_comp_cls->methods.notif_iter_next; break; } case BT_COMPONENT_CLASS_TYPE_FILTER: { - struct bt_component_class_filter *filter_class = - container_of(iterator->upstream_component->class, - struct bt_component_class_filter, parent); + struct bt_component_class_filter *flt_comp_cls = + (void *) comp_cls; - BT_ASSERT(filter_class->methods.iterator.next); - next_method = filter_class->methods.iterator.next; + method = (method_t) flt_comp_cls->methods.notif_iter_next; break; } default: @@ -695,13 +750,13 @@ bt_private_connection_notification_iterator_next( } /* - * Call the user's "next" method to get the next notification + * Call the user's "next" method to get the next notifications * and status. */ - BT_ASSERT(next_method); + BT_ASSERT(method); BT_LOGD_STR("Calling user's \"next\" method."); - status = next_method(priv_iterator, - (void *) user_iterator->notifs->pdata, + status = method(iterator, + (void *) iterator->base.notifs->pdata, NOTIF_BATCH_SIZE, user_count); BT_LOGD("User method returned: status=%s", bt_notification_iterator_status_string(status)); @@ -710,8 +765,8 @@ bt_private_connection_notification_iterator_next( goto end; } - if (iterator->state == BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED || - iterator->state == BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED) { + if (iterator->state == BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED || + iterator->state == BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED) { /* * The user's "next" method, somehow, cancelled its own * notification iterator. This can happen, for example, @@ -721,14 +776,13 @@ bt_private_connection_notification_iterator_next( * all its notification iterators are finalized. * * Only bt_object_put_ref() the returned notification if - * the status is - * BT_NOTIFICATION_ITERATOR_STATUS_OK because - * otherwise this field could be garbage. + * the status is BT_NOTIFICATION_ITERATOR_STATUS_OK + * because otherwise this field could be garbage. */ if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { uint64_t i; bt_notification_array notifs = - (void *) user_iterator->notifs->pdata; + (void *) iterator->base.notifs->pdata; for (i = 0; i < *user_count; i++) { bt_object_put_ref(notifs[i]); @@ -745,19 +799,17 @@ bt_private_connection_notification_iterator_next( "Notifications are invalid at this point: " "%![notif-iter-]+i, count=%" PRIu64, iterator, *user_count); - *user_notifs = (void *) user_iterator->notifs->pdata; + *notifs = (void *) iterator->base.notifs->pdata; break; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_END: BT_ASSERT_PRE(priv_conn_notif_iter_can_end(iterator), "Notification iterator cannot end at this point: " "%!+i", iterator); BT_ASSERT(iterator->state == - BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE); - iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED; - status = BT_NOTIFICATION_ITERATOR_STATUS_END; + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE); + iterator->state = BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED; BT_LOGD("Set new status: status=%s", bt_notification_iterator_status_string(status)); goto end; @@ -771,40 +823,28 @@ end: } enum bt_notification_iterator_status -bt_output_port_notification_iterator_next( - struct bt_notification_iterator *iterator, +bt_port_output_notification_iterator_next( + struct bt_port_output_notification_iterator *iterator, bt_notification_array *notifs_to_user, uint64_t *count_to_user) { enum bt_notification_iterator_status status; - struct bt_notification_iterator_output_port *out_port_iter = - (void *) iterator; enum bt_graph_status graph_status; BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); - BT_ASSERT_PRE_NON_NULL(notifs_to_user, "Notification array"); - BT_ASSERT_PRE_NON_NULL(count_to_user, "Notification count"); - BT_ASSERT_PRE(iterator->type == - BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT, - "Notification iterator was not created from an output port: " + BT_ASSERT_PRE_NON_NULL(notifs_to_user, "Notification array (output)"); + BT_ASSERT_PRE_NON_NULL(count_to_user, "Notification count (output)"); + BT_LIB_LOGD("Getting next output port notification iterator's notifications: " "%!+i", iterator); - BT_LIB_LOGD("Getting next output port notification iterator's notification: %!+i", - iterator); - graph_status = bt_graph_consume_sink_no_check( - out_port_iter->graph, out_port_iter->colander); + graph_status = bt_graph_consume_sink_no_check(iterator->graph, + iterator->colander); switch (graph_status) { case BT_GRAPH_STATUS_CANCELED: - status = BT_NOTIFICATION_ITERATOR_STATUS_CANCELED; - break; case BT_GRAPH_STATUS_AGAIN: - status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; - break; case BT_GRAPH_STATUS_END: - status = BT_NOTIFICATION_ITERATOR_STATUS_END; - break; case BT_GRAPH_STATUS_NOMEM: - status = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + status = (int) graph_status; break; case BT_GRAPH_STATUS_OK: status = BT_NOTIFICATION_ITERATOR_STATUS_OK; @@ -814,8 +854,8 @@ bt_output_port_notification_iterator_next( * to this iterator's array and sets this iterator's * notification count: move them to the user. */ - *notifs_to_user = (void *) iterator->notifs->pdata; - *count_to_user = out_port_iter->count; + *notifs_to_user = (void *) iterator->base.notifs->pdata; + *count_to_user = iterator->count; break; default: /* Other errors */ @@ -825,82 +865,86 @@ bt_output_port_notification_iterator_next( return status; } -struct bt_component *bt_private_connection_notification_iterator_get_component( - struct bt_notification_iterator *iterator) +struct bt_component *bt_self_component_port_input_notification_iterator_borrow_component( + struct bt_self_component_port_input_notification_iterator *iterator) +{ + BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); + return iterator->upstream_component; +} + +struct bt_self_component *bt_self_notification_iterator_borrow_component( + struct bt_self_notification_iterator *self_iterator) { - struct bt_notification_iterator_private_connection *iter_priv_conn; + struct bt_self_component_port_input_notification_iterator *iterator = + (void *) self_iterator; BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); - BT_ASSERT_PRE(iterator->type == - BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION, - "Notification iterator was not created from a private connection: " - "%!+i", iterator); - iter_priv_conn = (void *) iterator; - return bt_object_get_ref(iter_priv_conn->upstream_component); + return (void *) iterator->upstream_component; } -struct bt_private_component * -bt_private_connection_private_notification_iterator_get_private_component( - struct bt_private_connection_private_notification_iterator *private_iterator) +struct bt_self_port_output *bt_self_notification_iterator_borrow_port( + struct bt_self_notification_iterator *self_iterator) { - return bt_private_component_from_component( - bt_private_connection_notification_iterator_get_component( - (void *) bt_private_connection_notification_iterator_borrow_from_private(private_iterator))); + struct bt_self_component_port_input_notification_iterator *iterator = + (void *) self_iterator; + + BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); + return (void *) iterator->upstream_port; } static -void bt_output_port_notification_iterator_destroy(struct bt_object *obj) +void bt_port_output_notification_iterator_destroy(struct bt_object *obj) { - struct bt_notification_iterator_output_port *iterator = - (void *) container_of(obj, struct bt_notification_iterator, base); + struct bt_port_output_notification_iterator *iterator = (void *) obj; - BT_LOGD("Destroying output port notification iterator object: addr=%p", + BT_LIB_LOGD("Destroying output port notification iterator object: %!+i", iterator); BT_LOGD_STR("Putting graph."); - bt_object_put_ref(iterator->graph); + BT_OBJECT_PUT_REF_AND_RESET(iterator->graph); BT_LOGD_STR("Putting colander sink component."); - bt_object_put_ref(iterator->colander); + BT_OBJECT_PUT_REF_AND_RESET(iterator->colander); destroy_base_notification_iterator(obj); } -struct bt_notification_iterator *bt_output_port_notification_iterator_create( - struct bt_port *output_port, +struct bt_port_output_notification_iterator * +bt_port_output_notification_iterator_create( + struct bt_private_graph *priv_graph, + struct bt_port_output *output_port, const char *colander_component_name) { - struct bt_notification_iterator_output_port *iterator = NULL; - struct bt_component_class *colander_comp_cls = NULL; + struct bt_port_output_notification_iterator *iterator = NULL; + struct bt_component_class_sink *colander_comp_cls = NULL; struct bt_component *output_port_comp = NULL; - struct bt_component *colander_comp; - struct bt_graph *graph = NULL; + struct bt_component_sink *colander_comp; + struct bt_graph *graph = (void *) priv_graph; enum bt_graph_status graph_status; const char *colander_comp_name; - struct bt_port *colander_in_port = NULL; + struct bt_port_input *colander_in_port = NULL; struct bt_component_class_sink_colander_data colander_data; int ret; + BT_ASSERT_PRE_NON_NULL(graph, "Graph"); BT_ASSERT_PRE_NON_NULL(output_port, "Output port"); - BT_ASSERT_PRE(bt_port_get_type(output_port) == BT_PORT_TYPE_OUTPUT, - "Port is not an output port: %!+p", output_port); - output_port_comp = bt_port_get_component(output_port); + output_port_comp = bt_port_borrow_component((void *) output_port); BT_ASSERT_PRE(output_port_comp, "Output port has no component: %!+p", output_port); - graph = bt_object_get_ref(bt_component_borrow_graph(output_port_comp)); - BT_ASSERT(graph); + BT_ASSERT_PRE(bt_component_borrow_graph(output_port_comp) == + (void *) graph, + "Output port is not part of graph: %![graph-]+g, %![port-]+p", + graph, output_port); /* Create notification iterator */ - BT_LOGD("Creating notification iterator on output port: " - "comp-addr=%p, comp-name\"%s\", port-addr=%p, port-name=\"%s\"", - output_port_comp, bt_component_get_name(output_port_comp), - output_port, bt_port_get_name(output_port)); - iterator = g_new0(struct bt_notification_iterator_output_port, 1); + BT_LIB_LOGD("Creating notification iterator on output port: " + "%![port-]+p, %![comp-]+c", output_port, output_port_comp); + iterator = g_new0(struct bt_port_output_notification_iterator, 1); if (!iterator) { BT_LOGE_STR("Failed to allocate one output port notification iterator."); goto error; } ret = init_notification_iterator((void *) iterator, - BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT, - bt_output_port_notification_iterator_destroy); + BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT, + bt_port_output_notification_iterator_destroy); if (ret) { /* init_notification_iterator() logs errors */ BT_OBJECT_PUT_REF_AND_RESET(iterator); @@ -914,19 +958,18 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create( goto error; } - BT_OBJECT_MOVE_REF(iterator->graph, graph); + iterator->graph = bt_object_get_ref(graph); colander_comp_name = colander_component_name ? colander_component_name : "colander"; colander_data.notifs = (void *) iterator->base.notifs->pdata; colander_data.count_addr = &iterator->count; - - graph_status = bt_private_graph_add_component_with_init_method_data( - (void *) iterator->graph, colander_comp_cls, colander_comp_name, - NULL, &colander_data, &iterator->colander); + graph_status = + bt_private_graph_add_sink_component_with_init_method_data( + (void *) graph, colander_comp_cls, colander_comp_name, + NULL, &colander_data, &iterator->colander); if (graph_status != BT_GRAPH_STATUS_OK) { - BT_LOGW("Cannot add colander sink component to graph: " - "graph-addr=%p, name=\"%s\", graph-status=%s", - iterator->graph, colander_comp_name, + BT_LIB_LOGW("Cannot add colander sink component to graph: " + "%1[graph-]+g, status=%s", graph, bt_graph_status_string(graph_status)); goto error; } @@ -935,15 +978,15 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create( * Connect provided output port to the colander component's * input port. */ - colander_in_port = bt_component_sink_get_input_port_by_index( + colander_in_port = bt_component_sink_borrow_input_port_by_index( iterator->colander, 0); BT_ASSERT(colander_in_port); - graph_status = bt_private_graph_connect_ports((void *) iterator->graph, + graph_status = bt_private_graph_connect_ports(priv_graph, output_port, colander_in_port, NULL); if (graph_status != BT_GRAPH_STATUS_OK) { - BT_LOGW("Cannot add colander sink component to graph: " - "graph-addr=%p, name=\"%s\", graph-status=%s", - iterator->graph, colander_comp_name, + BT_LIB_LOGW("Cannot add colander sink component to graph: " + "%![graph-]+g, %![comp-]+c, status=%s", graph, + iterator->colander, bt_graph_status_string(graph_status)); goto error; } @@ -956,7 +999,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create( * sink and moved to the notification iterator's notification * member. */ - bt_graph_set_can_consume(iterator->graph, BT_FALSE); + bt_graph_set_can_consume(iterator->graph, false); goto end; error: @@ -979,23 +1022,13 @@ error: * succeeds. */ ret = bt_graph_remove_unconnected_component(iterator->graph, - colander_comp); + (void *) colander_comp); BT_ASSERT(ret == 0); } BT_OBJECT_PUT_REF_AND_RESET(iterator); end: - bt_object_put_ref(colander_in_port); bt_object_put_ref(colander_comp_cls); - bt_object_put_ref(output_port_comp); - bt_object_put_ref(graph); return (void *) iterator; } - -struct bt_notification_iterator * -bt_private_connection_notification_iterator_borrow_from_private( - struct bt_private_connection_private_notification_iterator *private_notification_iterator) -{ - return (void *) private_notification_iterator; -} diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index bd0d077b..09dece0b 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -77,31 +76,28 @@ end: } struct bt_private_notification *bt_private_notification_event_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_private_event_class *priv_event_class, struct bt_private_packet *priv_packet) { + struct bt_self_component_port_input_notification_iterator *notif_iter = + (void *) self_notif_iter; struct bt_event_class *event_class = (void *) priv_event_class; struct bt_packet *packet = (void *) priv_packet; struct bt_notification_event *notification = NULL; struct bt_event *event; - struct bt_graph *graph; BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - BT_LOGD("Creating event notification object: " - "event-class-addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64, - event_class, - bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class)); BT_ASSERT_PRE(event_class_has_trace(event_class), "Event class is not part of a trace: %!+E", event_class); + BT_LIB_LOGD("Creating event notification object: %![ec-]+E", + event_class); event = bt_event_create(event_class, packet); if (unlikely(!event)) { BT_LIB_LOGE("Cannot create event from event class: " - "%![event-class-]+E", event_class); + "%![ec-]+E", event_class); goto error; } @@ -120,10 +116,8 @@ struct bt_private_notification *bt_private_notification_event_create( * to notify the graph (pool owner) so that it removes the * notification from its notification array. */ - graph = bt_private_connection_private_notification_iterator_borrow_graph( - notif_iter); notification = (void *) bt_notification_create_from_pool( - &graph->event_notif_pool, graph); + ¬if_iter->graph->event_notif_pool, notif_iter->graph); if (unlikely(!notification)) { /* bt_notification_create_from_pool() logs errors */ goto error; @@ -133,14 +127,8 @@ struct bt_private_notification *bt_private_notification_event_create( notification->event = event; bt_packet_set_is_frozen(packet, true); bt_event_class_freeze(event_class); - BT_LOGD("Created event notification object: " - "event-addr=%p, event-class-addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64 ", " - "notif-addr=%p", - notification->event, event_class, - bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class), - notification); + BT_LIB_LOGD("Created event notification object: " + "%![notif-]+n, %![event-]+e", notification, event); goto end; error: @@ -156,11 +144,12 @@ void bt_notification_event_destroy(struct bt_notification *notif) { struct bt_notification_event *event_notif = (void *) notif; - BT_LOGD("Destroying event notification: addr=%p", notif); + BT_LIB_LOGD("Destroying event notification: %!+n", notif); if (event_notif->event) { - BT_LOGD_STR("Recycling event."); + BT_LIB_LOGD("Recycling event: %!+e", event_notif->event); bt_event_recycle(event_notif->event); + event_notif->event = NULL; } g_free(notif); @@ -179,10 +168,10 @@ void bt_notification_event_recycle(struct bt_notification *notif) return; } - BT_LOGD("Recycling event notification: addr=%p", notif); + BT_LIB_LOGD("Recycling event notification: %![notif-]+n, %![event-]+e", + notif, event_notif->event); bt_notification_reset(notif); BT_ASSERT(event_notif->event); - BT_LOGD_STR("Recycling event."); bt_event_recycle(event_notif->event); event_notif->event = NULL; graph = notif->graph; diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index 3ca527c8..2472cba1 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -40,7 +39,7 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) struct bt_notification_inactivity *notification = (struct bt_notification_inactivity *) obj; - BT_LOGD("Destroying inactivity notification: addr=%p", notification); + BT_LIB_LOGD("Destroying inactivity notification: %!+n", notification); if (notification->default_cv) { bt_clock_value_recycle(notification->default_cv); @@ -50,15 +49,19 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) } struct bt_private_notification *bt_private_notification_inactivity_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_clock_class *default_clock_class) { + struct bt_self_component_port_input_notification_iterator *notif_iter = + (void *) self_notif_iter; struct bt_notification_inactivity *notification; struct bt_notification *ret_notif = NULL; BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(default_clock_class, "Default clock class"); - BT_LOGD_STR("Creating inactivity notification object."); + BT_LIB_LOGD("Creating inactivity notification object: " + "%![iter-]+i, %![default-cc-]+K", notif_iter, + default_clock_class); notification = g_new0(struct bt_notification_inactivity, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one inactivity notification."); @@ -73,8 +76,7 @@ struct bt_private_notification *bt_private_notification_inactivity_create( goto error; } - BT_LOGD("Created inactivity notification object: addr=%p", - ret_notif); + BT_LIB_LOGD("Created inactivity notification object: %!+n", ret_notif); goto end; error: diff --git a/lib/graph/notification/notification.c b/lib/graph/notification/notification.c index e6b6af52..2b8c12d7 100644 --- a/lib/graph/notification/notification.c +++ b/lib/graph/notification/notification.c @@ -1,6 +1,4 @@ /* - * Babeltrace Plug-in Notification - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -75,9 +73,3 @@ void bt_notification_unlink_graph(struct bt_notification *notif) BT_ASSERT(notif); notif->graph = NULL; } - -struct bt_notification *bt_notification_borrow_from_private( - struct bt_private_notification *priv_notif) -{ - return (void *) priv_notif; -} diff --git a/lib/graph/notification/packet.c b/lib/graph/notification/packet.c index 64d24cbd..b15c489b 100644 --- a/lib/graph/notification/packet.c +++ b/lib/graph/notification/packet.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -66,14 +65,15 @@ end: } struct bt_private_notification *bt_private_notification_packet_begin_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_private_packet *priv_packet) { + struct bt_self_component_port_input_notification_iterator *notif_iter = + (void *) self_notif_iter; struct bt_packet *packet = (void *) priv_packet; struct bt_notification_packet_begin *notification = NULL; struct bt_stream *stream; struct bt_stream_class *stream_class; - struct bt_graph *graph; BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(packet, "Packet"); @@ -81,18 +81,11 @@ struct bt_private_notification *bt_private_notification_packet_begin_create( BT_ASSERT(stream); stream_class = bt_stream_borrow_class(stream); BT_ASSERT(stream_class); - BT_LOGD("Creating packet beginning notification object: " - "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64, - packet, stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); - graph = bt_private_connection_private_notification_iterator_borrow_graph( - notif_iter); + BT_LIB_LOGD("Creating packet beginning notification object: " + "%![packet-]+a, %![stream-]+s, %![sc-]+S", + packet, stream, stream_class); notification = (void *) bt_notification_create_from_pool( - &graph->packet_begin_notif_pool, graph); + ¬if_iter->graph->packet_begin_notif_pool, notif_iter->graph); if (!notification) { /* bt_notification_create_from_pool() logs errors */ goto end; @@ -103,14 +96,9 @@ struct bt_private_notification *bt_private_notification_packet_begin_create( bt_object_get_no_null_check_no_parent_check( ¬ification->packet->base); bt_packet_set_is_frozen(packet, true); - BT_LOGD("Created packet beginning notification object: " - "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64 ", addr=%p", - packet, stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class), notification); + BT_LIB_LOGD("Created packet beginning notification object: " + "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S", + notification, packet, stream, stream_class); goto end; end: @@ -122,8 +110,8 @@ void bt_notification_packet_begin_destroy(struct bt_notification *notif) { struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; - BT_LOGD("Destroying packet beginning notification: addr=%p", notif); - BT_LOGD_STR("Putting packet."); + BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif); + BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet); BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet); g_free(notif); } @@ -141,7 +129,7 @@ void bt_notification_packet_begin_recycle(struct bt_notification *notif) return; } - BT_LOGD("Recycling packet beginning notification: addr=%p", notif); + BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif); bt_notification_reset(notif); bt_object_put_no_null_check(&packet_begin_notif->packet->base); packet_begin_notif->packet = NULL; @@ -196,14 +184,15 @@ end: } struct bt_private_notification *bt_private_notification_packet_end_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_private_packet *priv_packet) { + struct bt_self_component_port_input_notification_iterator *notif_iter = + (void *) self_notif_iter; struct bt_packet *packet = (void *) priv_packet; struct bt_notification_packet_end *notification = NULL; struct bt_stream *stream; struct bt_stream_class *stream_class; - struct bt_graph *graph; BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(packet, "Packet"); @@ -211,18 +200,11 @@ struct bt_private_notification *bt_private_notification_packet_end_create( BT_ASSERT(stream); stream_class = bt_stream_borrow_class(stream); BT_ASSERT(stream_class); - BT_LOGD("Creating packet end notification object: " - "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64, - packet, stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); - graph = bt_private_connection_private_notification_iterator_borrow_graph( - notif_iter); + BT_LIB_LOGD("Creating packet end notification object: " + "%![packet-]+a, %![stream-]+s, %![sc-]+S", + packet, stream, stream_class); notification = (void *) bt_notification_create_from_pool( - &graph->packet_end_notif_pool, graph); + ¬if_iter->graph->packet_end_notif_pool, notif_iter->graph); if (!notification) { /* bt_notification_create_from_pool() logs errors */ goto end; @@ -233,14 +215,9 @@ struct bt_private_notification *bt_private_notification_packet_end_create( bt_object_get_no_null_check_no_parent_check( ¬ification->packet->base); bt_packet_set_is_frozen(packet, true); - BT_LOGD("Created packet end notification object: " - "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64 ", addr=%p", - packet, stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class), notification); + BT_LIB_LOGD("Created packet end notification object: " + "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S", + notification, packet, stream, stream_class); goto end; end: @@ -252,8 +229,8 @@ void bt_notification_packet_end_destroy(struct bt_notification *notif) { struct bt_notification_packet_end *packet_end_notif = (void *) notif; - BT_LOGD("Destroying packet end notification: addr=%p", notif); - BT_LOGD_STR("Putting packet."); + BT_LIB_LOGD("Destroying packet end notification: %!+n", notif); + BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet); BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); g_free(notif); } @@ -271,7 +248,7 @@ void bt_notification_packet_end_recycle(struct bt_notification *notif) return; } - BT_LOGD("Recycling packet end notification: addr=%p", notif); + BT_LIB_LOGD("Recycling packet end notification: %!+n", notif); bt_notification_reset(notif); BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); graph = notif->graph; diff --git a/lib/graph/notification/stream.c b/lib/graph/notification/stream.c index 523e8142..0e3a13d3 100644 --- a/lib/graph/notification/stream.c +++ b/lib/graph/notification/stream.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -43,37 +42,33 @@ void bt_notification_stream_end_destroy(struct bt_object *obj) struct bt_notification_stream_end *notification = (struct bt_notification_stream_end *) obj; - BT_LOGD("Destroying stream end notification: addr=%p", + BT_LIB_LOGD("Destroying stream end notification: %!+n", notification); - BT_LOGD_STR("Putting stream."); + BT_LIB_LOGD("Putting stream: %!+s", notification->stream); BT_OBJECT_PUT_REF_AND_RESET(notification->stream); if (notification->default_cv) { bt_clock_value_recycle(notification->default_cv); + notification->default_cv = NULL; } g_free(notification); } struct bt_private_notification *bt_private_notification_stream_end_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_private_stream *priv_stream) { struct bt_stream *stream = (void *) priv_stream; struct bt_notification_stream_end *notification; struct bt_stream_class *stream_class; + BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(stream, "Stream"); stream_class = bt_stream_borrow_class(stream); BT_ASSERT(stream_class); - BT_LOGD("Creating stream end notification object: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64, - stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); + BT_LIB_LOGD("Creating stream end notification object: " + "%![stream-]+s, %![sc-]+S", stream, stream_class); notification = g_new0(struct bt_notification_stream_end, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one stream end notification."); @@ -84,14 +79,9 @@ struct bt_private_notification *bt_private_notification_stream_end_create( BT_NOTIFICATION_TYPE_STREAM_END, bt_notification_stream_end_destroy, NULL); notification->stream = bt_object_get_ref(stream); - BT_LOGD("Created stream end notification object: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64 ", addr=%p", - stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class), notification); + BT_LIB_LOGD("Created stream end notification object: " + "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, + stream, stream_class); return (void *) ¬ification->parent; error: @@ -166,37 +156,33 @@ void bt_notification_stream_begin_destroy(struct bt_object *obj) struct bt_notification_stream_begin *notification = (struct bt_notification_stream_begin *) obj; - BT_LOGD("Destroying stream beginning notification: addr=%p", + BT_LIB_LOGD("Destroying stream beginning notification: %!+n", notification); - BT_LOGD_STR("Putting stream."); + BT_LIB_LOGD("Putting stream: %!+s", notification->stream); BT_OBJECT_PUT_REF_AND_RESET(notification->stream); if (notification->default_cv) { bt_clock_value_recycle(notification->default_cv); + notification->default_cv = NULL; } g_free(notification); } struct bt_private_notification *bt_private_notification_stream_begin_create( - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *self_notif_iter, struct bt_private_stream *priv_stream) { struct bt_stream *stream = (void *) priv_stream; struct bt_notification_stream_begin *notification; struct bt_stream_class *stream_class; + BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator"); BT_ASSERT_PRE_NON_NULL(stream, "Stream"); stream_class = bt_stream_borrow_class(stream); BT_ASSERT(stream_class); - BT_LOGD("Creating stream beginning notification object: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64, - stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class)); + BT_LIB_LOGD("Creating stream beginning notification object: " + "%![stream-]+s, %![sc-]+S", stream, stream_class); notification = g_new0(struct bt_notification_stream_begin, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one stream beginning notification."); @@ -207,14 +193,9 @@ struct bt_private_notification *bt_private_notification_stream_begin_create( BT_NOTIFICATION_TYPE_STREAM_BEGIN, bt_notification_stream_begin_destroy, NULL); notification->stream = bt_object_get_ref(stream); - BT_LOGD("Created stream beginning notification object: " - "stream-addr=%p, stream-name=\"%s\", " - "stream-class-addr=%p, stream-class-name=\"%s\", " - "stream-class-id=%" PRId64 ", addr=%p", - stream, bt_stream_get_name(stream), - stream_class, - bt_stream_class_get_name(stream_class), - bt_stream_class_get_id(stream_class), notification); + BT_LIB_LOGD("Created stream beginning notification object: " + "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, + stream, stream_class); return (void *) ¬ification->parent; error: return NULL; diff --git a/lib/graph/port.c b/lib/graph/port.c index 6660c66a..aa8ed98f 100644 --- a/lib/graph/port.c +++ b/lib/graph/port.c @@ -1,8 +1,4 @@ /* - * port.c - * - * Babeltrace Port - * * Copyright 2017 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -30,34 +26,33 @@ #include #include +#include +#include +#include #include #include #include #include +#include #include #include +#include static -void bt_port_destroy(struct bt_object *obj) +void destroy_port(struct bt_object *obj) { - struct bt_port *port = container_of(obj, struct bt_port, base); + struct bt_port *port = (void *) obj; - BT_LOGD("Destroying port: addr=%p, name=\"%s\", comp-addr=%p", - port, bt_port_get_name(port), obj->parent); + BT_LIB_LOGD("Destroying port: %!+p", port); if (port->name) { g_string_free(port->name, TRUE); + port->name = NULL; } g_free(port); } -struct bt_port *bt_port_borrow_from_private( - struct bt_private_port *private_port) -{ - return (void *) private_port; -} - BT_HIDDEN struct bt_port *bt_port_create(struct bt_component *parent_component, enum bt_port_type type, const char *name, void *user_data) @@ -67,25 +62,17 @@ struct bt_port *bt_port_create(struct bt_component *parent_component, BT_ASSERT(name); BT_ASSERT(parent_component); BT_ASSERT(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT); - - if (strlen(name) == 0) { - BT_LOGW_STR("Invalid parameter: name is an empty string."); - goto end; - } - + BT_ASSERT(strlen(name) > 0); port = g_new0(struct bt_port, 1); if (!port) { BT_LOGE_STR("Failed to allocate one port."); goto end; } - BT_LOGD("Creating port for component: " - "comp-addr=%p, comp-name=\"%s\", port-type=%s, " - "port-name=\"%s\"", - parent_component, bt_component_get_name(parent_component), - bt_port_type_string(type), name); - - bt_object_init_shared_with_parent(&port->base, bt_port_destroy); + BT_LIB_LOGD("Creating port for component: %![comp-]+c, port-type=%s, " + "port-name=\"%s\"", parent_component, bt_port_type_string(type), + name); + bt_object_init_shared_with_parent(&port->base, destroy_port); port->name = g_string_new(name); if (!port->name) { BT_LOGE_STR("Failed to allocate one GString."); @@ -96,11 +83,8 @@ struct bt_port *bt_port_create(struct bt_component *parent_component, port->type = type; port->user_data = user_data; bt_object_set_parent(&port->base, &parent_component->base); - BT_LOGD("Created port for component: " - "comp-addr=%p, comp-name=\"%s\", port-type=%s, " - "port-name=\"%s\", port-addr=%p", - parent_component, bt_component_get_name(parent_component), - bt_port_type_string(type), name, port); + BT_LIB_LOGD("Created port for component: " + "%![comp-]+c, %![port-]+p", parent_component, port); end: return port; @@ -108,51 +92,33 @@ end: const char *bt_port_get_name(struct bt_port *port) { - return port ? port->name->str : NULL; + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return port->name->str; } enum bt_port_type bt_port_get_type(struct bt_port *port) { - return port ? port->type : BT_PORT_TYPE_UNKOWN; -} - -struct bt_connection *bt_port_get_connection(struct bt_port *port) -{ - struct bt_connection *connection = NULL; - - if (!port) { - BT_LOGW_STR("Invalid parameter: port is NULL."); - goto end; - } - - if (!port->connection) { - /* Not an error: means disconnected */ - goto end; - } - - connection = bt_object_get_ref(port->connection); - -end: - return connection; + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return port->type; } -struct bt_component *bt_port_get_component(struct bt_port *port) +struct bt_connection *bt_port_borrow_connection(struct bt_port *port) { - return (struct bt_component *) bt_object_get_parent(&port->base); + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return port->connection; } -struct bt_private_connection *bt_private_port_get_connection( - struct bt_private_port *private_port) +struct bt_component *bt_port_borrow_component(struct bt_port *port) { - return bt_private_connection_from_connection(bt_port_get_connection( - bt_port_borrow_from_private(private_port))); + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return (struct bt_component *) bt_object_borrow_parent(&port->base); } -struct bt_private_component *bt_private_port_get_component( - struct bt_private_port *private_port) +struct bt_self_component *bt_self_component_port_borrow_component( + struct bt_self_component_port *port) { - return bt_private_component_from_component(bt_port_get_component( - bt_port_borrow_from_private(private_port))); + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return (void *) bt_object_borrow_parent((void *) port); } BT_HIDDEN @@ -165,86 +131,40 @@ void bt_port_set_connection(struct bt_port *port, * connection exists. */ port->connection = connection; - BT_LOGV("Set port's connection: " - "port-addr=%p, port-name=\"%s\", conn-addr=%p", - port, bt_port_get_name(port), connection); + BT_LIB_LOGV("Set port's connection: %![port-]+p, %![conn-]+x", port, + connection); } -enum bt_port_status bt_private_port_remove_from_component( - struct bt_private_port *private_port) +enum bt_self_component_port_status bt_self_component_port_remove_from_component( + struct bt_self_component_port *self_port) { - enum bt_port_status status = BT_PORT_STATUS_OK; - struct bt_port *port = bt_port_borrow_from_private(private_port); + struct bt_port *port = (void *) self_port; struct bt_component *comp = NULL; - enum bt_component_status comp_status; - if (!port) { - BT_LOGW_STR("Invalid parameter: private port is NULL."); - status = BT_PORT_STATUS_INVALID; - goto end; - } + BT_ASSERT_PRE_NON_NULL(port, "Port"); - comp = (void *) bt_object_get_parent(&port->base); + comp = (void *) bt_object_borrow_parent(&port->base); if (!comp) { - BT_LOGV("Port already removed from its component: " - "port-addr=%p, port-name=\"%s\", ", - port, bt_port_get_name(port)); + BT_LIB_LOGV("Port already removed from its component: %!+p", + port); goto end; } /* bt_component_remove_port() logs details */ - comp_status = bt_component_remove_port(comp, port); - BT_ASSERT(comp_status != BT_COMPONENT_STATUS_INVALID); - if (comp_status < 0) { - status = BT_PORT_STATUS_ERROR; - goto end; - } + bt_component_remove_port(comp, port); end: - bt_object_put_ref(comp); - return status; -} - -enum bt_port_status bt_port_disconnect(struct bt_port *port) -{ - enum bt_port_status status = BT_PORT_STATUS_OK; - - if (!port) { - BT_LOGW_STR("Invalid parameter: port is NULL."); - status = BT_PORT_STATUS_INVALID; - goto end; - } - - if (port->connection) { - bt_connection_end(port->connection, true); - BT_LOGV("Disconnected port: " - "port-addr=%p, port-name=\"%s\"", - port, bt_port_get_name(port)); - } - -end: - return status; + return BT_SELF_PORT_STATUS_OK; } bt_bool bt_port_is_connected(struct bt_port *port) { - int ret; - - if (!port) { - BT_LOGW_STR("Invalid parameter: port is NULL."); - ret = -1; - goto end; - } - - ret = port->connection ? 1 : 0; - -end: - return ret; + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return port->connection ? BT_TRUE : BT_FALSE; } -void *bt_private_port_get_user_data( - struct bt_private_port *private_port) +void *bt_self_component_port_get_data(struct bt_self_component_port *port) { - return private_port ? - bt_port_borrow_from_private(private_port)->user_data : NULL; + BT_ASSERT_PRE_NON_NULL(port, "Port"); + return ((struct bt_port *) port)->user_data; } diff --git a/lib/graph/query-executor.c b/lib/graph/query-executor.c index fa44b07e..2029de84 100644 --- a/lib/graph/query-executor.c +++ b/lib/graph/query-executor.c @@ -23,13 +23,17 @@ #define BT_LOG_TAG "QUERY-EXECUTOR" #include +#include #include #include #include #include #include #include +#include #include +#include +#include static void bt_query_executor_destroy(struct bt_object *obj) @@ -37,11 +41,11 @@ void bt_query_executor_destroy(struct bt_object *obj) struct bt_query_executor *query_exec = container_of(obj, struct bt_query_executor, base); - BT_LOGD("Destroying port: addr=%p", query_exec); + BT_LOGD("Destroying query executor: addr=%p", query_exec); g_free(query_exec); } -struct bt_query_executor *bt_query_executor_create(void) +struct bt_private_query_executor *bt_private_query_executor_create(void) { struct bt_query_executor *query_exec; @@ -57,149 +61,102 @@ struct bt_query_executor *bt_query_executor_create(void) BT_LOGD("Created query executor: addr=%p", query_exec); end: - return query_exec; + return (void *) query_exec; } -enum bt_query_status bt_query_executor_query( - struct bt_query_executor *query_exec, - struct bt_component_class *component_class, +enum bt_query_status bt_private_query_executor_query( + struct bt_private_query_executor *priv_query_exec, + struct bt_component_class *comp_cls, const char *object, struct bt_value *params, struct bt_value **user_result) { - struct bt_component_class_query_method_return ret = { - .result = NULL, - .status = BT_QUERY_STATUS_OK, - }; + typedef enum bt_query_status (*method_t)(void *, void *, + const void *, void *, void *); - if (!query_exec) { - BT_LOGW_STR("Invalid parameter: query executor is NULL."); - ret.status = BT_QUERY_STATUS_INVALID; - goto end; - } + struct bt_query_executor *query_exec = (void *) priv_query_exec; + enum bt_query_status status; + method_t method = NULL; - if (query_exec->canceled) { - BT_LOGW_STR("Invalid parameter: query executor is canceled."); - ret.status = BT_QUERY_STATUS_EXECUTOR_CANCELED; - goto end; + BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor"); + BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_NON_NULL(object, "Object"); + BT_ASSERT_PRE_NON_NULL(user_result, "Result (output)"); + BT_ASSERT_PRE(!query_exec->canceled, "Query executor is canceled."); + + if (!params) { + params = bt_value_null; } - if (!component_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - ret.status = BT_QUERY_STATUS_INVALID; - goto end; + switch (comp_cls->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *src_cc = (void *) comp_cls; + + method = (method_t) src_cc->methods.query; + break; } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *flt_cc = (void *) comp_cls; - if (!object) { - BT_LOGW_STR("Invalid parameter: object string is NULL."); - ret.status = BT_QUERY_STATUS_INVALID; - goto end; + method = (method_t) flt_cc->methods.query; + break; } + case BT_COMPONENT_CLASS_TYPE_SINK: + { + struct bt_component_class_sink *sink_cc = (void *) comp_cls; - if (!params) { - params = bt_value_null; + method = (method_t) sink_cc->methods.query; + break; + } + default: + abort(); } - if (!component_class->methods.query) { + if (!method) { /* Not an error: nothing to query */ - BT_LOGD("Component class has no registered query method: " - "addr=%p, name=\"%s\", type=%s", - component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type)); - ret.status = BT_QUERY_STATUS_ERROR; + BT_LIB_LOGD("Component class has no registered query method: " + "%!+C", comp_cls); + status = BT_QUERY_STATUS_UNSUPPORTED; goto end; } - BT_LOGD("Calling user's query method: " - "query-exec-addr=%p, comp-class-addr=%p, " - "comp-class-name=\"%s\", comp-class-type=%s, " - "object=\"%s\", params-addr=%p", - query_exec, component_class, - bt_component_class_get_name(component_class), - bt_component_class_type_string(component_class->type), - object, params); - ret = component_class->methods.query(component_class, query_exec, - object, params); - BT_LOGD("User method returned: status=%s, result-addr=%p", - bt_query_status_string(ret.status), ret.result); + BT_LIB_LOGD("Calling user's query method: " + "query-exec-addr=%p, %![cc-]+C, object=\"%s\", %![params-]+v", + query_exec, comp_cls, object, params); + *user_result = NULL; + status = method(comp_cls, query_exec, object, params, user_result); + BT_LIB_LOGD("User method returned: status=%s, %![res-]+v", + bt_query_status_string(status), *user_result); + BT_ASSERT_PRE(status != BT_QUERY_STATUS_EXECUTOR_CANCELED && + status != BT_QUERY_STATUS_UNSUPPORTED, + "Unexpected (illegal) returned status: status=%s", + bt_query_status_string(status)); + BT_ASSERT_PRE(status != BT_QUERY_STATUS_OK || *user_result, + "User method returned `BT_QUERY_STATUS_OK` without a result."); if (query_exec->canceled) { - BT_OBJECT_PUT_REF_AND_RESET(ret.result); - ret.status = BT_QUERY_STATUS_EXECUTOR_CANCELED; + BT_OBJECT_PUT_REF_AND_RESET(*user_result); + status = BT_QUERY_STATUS_EXECUTOR_CANCELED; goto end; - } else { - if (ret.status == BT_QUERY_STATUS_EXECUTOR_CANCELED) { - /* - * The user cannot decide that the executor is - * canceled if it's not. - */ - BT_OBJECT_PUT_REF_AND_RESET(ret.result); - ret.status = BT_QUERY_STATUS_ERROR; - goto end; - } - } - - switch (ret.status) { - case BT_QUERY_STATUS_INVALID: - /* - * This is reserved for invalid parameters passed to - * this function. - */ - BT_OBJECT_PUT_REF_AND_RESET(ret.result); - ret.status = BT_QUERY_STATUS_ERROR; - break; - case BT_QUERY_STATUS_OK: - if (!ret.result) { - ret.result = bt_value_null; - } - break; - default: - if (ret.result) { - BT_LOGW("User method did not return BT_QUERY_STATUS_OK, but result is not NULL: " - "status=%s, result-addr=%p", - bt_query_status_string(ret.status), ret.result); - BT_OBJECT_PUT_REF_AND_RESET(ret.result); - } } end: - if (user_result) { - *user_result = ret.result; - ret.result = NULL; - } - - bt_object_put_ref(ret.result); - return ret.status; + return status; } -enum bt_query_status bt_query_executor_cancel( - struct bt_query_executor *query_exec) +enum bt_query_status bt_private_query_executor_cancel( + struct bt_private_query_executor *priv_query_exec) { - enum bt_query_status ret = BT_QUERY_STATUS_OK; - - if (!query_exec) { - BT_LOGW_STR("Invalid parameter: query executor is NULL."); - ret = BT_QUERY_STATUS_INVALID; - goto end; - } + struct bt_query_executor *query_exec = (void *) priv_query_exec; + BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor"); query_exec->canceled = BT_TRUE; BT_LOGV("Canceled query executor: addr=%p", query_exec); - -end: - return ret; + return BT_QUERY_STATUS_OK; } bt_bool bt_query_executor_is_canceled(struct bt_query_executor *query_exec) { - bt_bool canceled = BT_FALSE; - - if (!query_exec) { - BT_LOGW_STR("Invalid parameter: query executor is NULL."); - goto end; - } - - canceled = query_exec->canceled; - -end: - return canceled; + BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor"); + return query_exec->canceled; } diff --git a/lib/graph/sink.c b/lib/graph/sink.c deleted file mode 100644 index dc107017..00000000 --- a/lib/graph/sink.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * sink.c - * - * Babeltrace Sink Component - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_TAG "COMP-SINK" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -BT_HIDDEN -void bt_component_sink_destroy(struct bt_component *component) -{ -} - -BT_HIDDEN -struct bt_component *bt_component_sink_create( - struct bt_component_class *class) -{ - struct bt_component_sink *sink = NULL; - - sink = g_new0(struct bt_component_sink, 1); - if (!sink) { - BT_LOGE_STR("Failed to allocate one sink component."); - goto end; - } - -end: - return sink ? &sink->parent : NULL; -} - -int64_t bt_component_sink_get_input_port_count(struct bt_component *component) -{ - int64_t ret; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = (int64_t) -1; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: component's class is not a sink component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - ret = (int64_t) -1; - goto end; - } - - /* bt_component_get_input_port_count() logs details/errors */ - ret = bt_component_get_input_port_count(component); - -end: - return ret; -} - -struct bt_port *bt_component_sink_get_input_port_by_name( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: component's class is not a sink component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_input_port_by_name() logs details/errors */ - port = bt_component_get_input_port_by_name(component, name); - -end: - return port; -} - -struct bt_port *bt_component_sink_get_input_port_by_index( - struct bt_component *component, uint64_t index) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: component's class is not a sink component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_input_port_by_index() logs details/errors */ - port = bt_component_get_input_port_by_index(component, index); - -end: - return port; -} - -struct bt_private_port * -bt_private_component_sink_get_input_port_by_index( - struct bt_private_component *private_component, uint64_t index) -{ - /* bt_component_sink_get_input_port_by_index() logs details/errors */ - return bt_private_port_from_port( - bt_component_sink_get_input_port_by_index( - bt_component_borrow_from_private(private_component), index)); -} - -struct bt_private_port * -bt_private_component_sink_get_input_port_by_name( - struct bt_private_component *private_component, - const char *name) -{ - /* bt_component_sink_get_input_port_by_name() logs details/errors */ - return bt_private_port_from_port( - bt_component_sink_get_input_port_by_name( - bt_component_borrow_from_private(private_component), name)); -} - -enum bt_component_status bt_private_component_sink_add_input_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **user_priv_port) -{ - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - struct bt_port *port = NULL; - struct bt_component *component = - bt_component_borrow_from_private(private_component); - struct bt_graph *graph; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - BT_LOGW("Invalid parameter: component's class is not a sink component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - graph = bt_component_borrow_graph(component); - - if (graph && bt_graph_is_canceled(graph)) { - BT_LOGW("Cannot add input port to sink component: graph is canceled: " - "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", - component, bt_component_get_name(component), - bt_component_borrow_graph(component)); - status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; - goto end; - } - - /* bt_component_add_input_port() logs details/errors */ - port = bt_component_add_input_port(component, name, user_data); - if (!port) { - status = BT_COMPONENT_STATUS_NOMEM; - goto end; - } - - if (user_priv_port) { - /* Move reference to user */ - *user_priv_port = bt_private_port_from_port(port); - port = NULL; - } - -end: - bt_object_put_ref(port); - return status; -} diff --git a/lib/graph/source.c b/lib/graph/source.c deleted file mode 100644 index 3510c00c..00000000 --- a/lib/graph/source.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * source.c - * - * Babeltrace Source Component - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_TAG "COMP-SOURCE" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -BT_HIDDEN -void bt_component_source_destroy(struct bt_component *component) -{ -} - -BT_HIDDEN -struct bt_component *bt_component_source_create( - struct bt_component_class *class) -{ - struct bt_component_source *source = NULL; - - source = g_new0(struct bt_component_source, 1); - if (!source) { - BT_LOGE_STR("Failed to allocate one source component."); - goto end; - } - -end: - return source ? &source->parent : NULL; -} - -int64_t bt_component_source_get_output_port_count( - struct bt_component *component) -{ - int64_t ret; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - ret = (int64_t) -1; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component's class is not a source component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - ret = (int64_t) -1; - goto end; - } - - /* bt_component_get_output_port_count() logs details/errors */ - ret = bt_component_get_output_port_count(component); - -end: - return ret; -} - -struct bt_port *bt_component_source_get_output_port_by_name( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component's class is not a source component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_output_port_by_name() logs details/errors */ - port = bt_component_get_output_port_by_name(component, name); - -end: - return port; -} - -struct bt_port *bt_component_source_get_output_port_by_index( - struct bt_component *component, uint64_t index) -{ - struct bt_port *port = NULL; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component's class is not a source component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - goto end; - } - - /* bt_component_get_output_port_by_index() logs details/errors */ - port = bt_component_get_output_port_by_index(component, index); - -end: - return port; -} - -struct bt_private_port * -bt_private_component_source_get_output_port_by_name( - struct bt_private_component *private_component, - const char *name) -{ - /* bt_component_source_get_output_port_by_name() logs details/errors */ - return bt_private_port_from_port( - bt_component_source_get_output_port_by_name( - bt_component_borrow_from_private(private_component), name)); -} - -struct bt_private_port * -bt_private_component_source_get_output_port_by_index( - struct bt_private_component *private_component, uint64_t index) -{ - /* bt_component_source_get_output_port_by_index() logs details/errors */ - return bt_private_port_from_port( - bt_component_source_get_output_port_by_index( - bt_component_borrow_from_private(private_component), index)); -} - -enum bt_component_status bt_private_component_source_add_output_port( - struct bt_private_component *private_component, - const char *name, void *user_data, - struct bt_private_port **user_priv_port) -{ - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - struct bt_port *port = NULL; - struct bt_component *component = - bt_component_borrow_from_private(private_component); - struct bt_graph *graph; - - if (!component) { - BT_LOGW_STR("Invalid parameter: component is NULL."); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - BT_LOGW("Invalid parameter: component's class is not a source component class: " - "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", - component, bt_component_get_name(component), - bt_component_class_type_string(component->class->type)); - status = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - graph = bt_component_borrow_graph(component); - - if (graph && bt_graph_is_canceled(graph)) { - BT_LOGW("Cannot add output port to source component: graph is canceled: " - "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", - component, bt_component_get_name(component), - bt_component_borrow_graph(component)); - status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; - goto end; - } - - /* bt_component_add_output_port() logs details and errors */ - port = bt_component_add_output_port(component, name, user_data); - if (!port) { - status = BT_COMPONENT_STATUS_NOMEM; - goto end; - } - - if (user_priv_port) { - /* Move reference to user */ - *user_priv_port = bt_private_port_from_port(port); - port = NULL; - } - -end: - bt_object_put_ref(port); - return status; -} diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 3eb3f186..0104a9e0 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -89,6 +89,8 @@ static char __thread lib_logging_buf[LIB_LOGGING_BUF_SIZE]; #define PRFIELD(_expr) prefix, (_expr) +#define PRFIELD_GSTRING(_expr) PRFIELD((_expr) ? (_expr)->str : NULL) + #define SET_TMP_PREFIX(_prefix2) \ do { \ strcpy(tmp_prefix, prefix); \ @@ -597,11 +599,6 @@ static inline void format_stream(char **buf_ch, bool extended, return; } - trace = (void *) bt_object_borrow_parent(&stream->base); - if (!trace) { - return; - } - BUF_APPEND(", %strace-addr=%p", PRFIELD(trace)); SET_TMP_PREFIX("trace-"); format_trace(buf_ch, false, tmp_prefix, trace); @@ -680,7 +677,7 @@ static inline void format_event(char **buf_ch, bool extended, BUF_APPEND(", %sis-frozen=%d, %sheader-field-addr=%p, " "%scommon-context-field-addr=%p, " - "%specific-scontext-field-addr=%p, " + "%sspecific-context-field-addr=%p, " "%spayload-field-addr=%p, ", PRFIELD(event->frozen), PRFIELD(event->header_field ? @@ -786,10 +783,14 @@ static inline void format_clock_value(char **buf_ch, bool extended, } BUF_APPEND(", %sis-set=%d", PRFIELD(clock_value->is_set)); - BUF_APPEND(", %sclock-class-addr=%p", - PRFIELD(clock_value->clock_class)); - SET_TMP_PREFIX("clock-class-"); - format_clock_class(buf_ch, false, tmp_prefix, clock_value->clock_class); + + if (clock_value->clock_class) { + BUF_APPEND(", %sclock-class-addr=%p", + PRFIELD(clock_value->clock_class)); + SET_TMP_PREFIX("clock-class-"); + format_clock_class(buf_ch, false, tmp_prefix, + clock_value->clock_class); + } } static inline void format_value(char **buf_ch, bool extended, @@ -872,8 +873,11 @@ static inline void format_notification(char **buf_ch, bool extended, { struct bt_notification_event *notif_event = (void *) notif; - SET_TMP_PREFIX("event-"); - format_event(buf_ch, true, tmp_prefix, notif_event->event); + if (notif_event->event) { + SET_TMP_PREFIX("event-"); + format_event(buf_ch, true, tmp_prefix, notif_event->event); + } + break; } case BT_NOTIFICATION_TYPE_STREAM_BEGIN: @@ -881,8 +885,11 @@ static inline void format_notification(char **buf_ch, bool extended, struct bt_notification_stream_begin *notif_stream = (void *) notif; - SET_TMP_PREFIX("stream-"); - format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); + if (notif_stream->stream) { + SET_TMP_PREFIX("stream-"); + format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); + } + break; } case BT_NOTIFICATION_TYPE_STREAM_END: @@ -890,8 +897,11 @@ static inline void format_notification(char **buf_ch, bool extended, struct bt_notification_stream_end *notif_stream = (void *) notif; - SET_TMP_PREFIX("stream-"); - format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); + if (notif_stream->stream) { + SET_TMP_PREFIX("stream-"); + format_stream(buf_ch, true, tmp_prefix, notif_stream->stream); + } + break; } case BT_NOTIFICATION_TYPE_PACKET_BEGIN: @@ -899,8 +909,11 @@ static inline void format_notification(char **buf_ch, bool extended, struct bt_notification_packet_begin *notif_packet = (void *) notif; - SET_TMP_PREFIX("packet-"); - format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); + if (notif_packet->packet) { + SET_TMP_PREFIX("packet-"); + format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); + } + break; } case BT_NOTIFICATION_TYPE_PACKET_END: @@ -908,8 +921,11 @@ static inline void format_notification(char **buf_ch, bool extended, struct bt_notification_packet_end *notif_packet = (void *) notif; - SET_TMP_PREFIX("packet-"); - format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); + if (notif_packet->packet) { + SET_TMP_PREFIX("packet-"); + format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); + } + break; } default: @@ -924,7 +940,7 @@ static inline void format_plugin_so_shared_lib_handle(char **buf_ch, BUF_APPEND(", %saddr=%p", PRFIELD(handle)); if (handle->path) { - BUF_APPEND(", %spath=\"%s\"", PRFIELD(handle->path->str)); + BUF_APPEND(", %spath=\"%s\"", PRFIELD_GSTRING(handle->path)); } } @@ -935,11 +951,11 @@ static inline void format_component_class(char **buf_ch, bool extended, BUF_APPEND(", %stype=%s, %sname=\"%s\"", PRFIELD(bt_component_class_type_string(comp_class->type)), - PRFIELD(comp_class->name ? comp_class->name->str : NULL)); + PRFIELD_GSTRING(comp_class->name)); if (comp_class->description) { BUF_APPEND(", %spartial-descr=\"%.32s\"", - PRFIELD(comp_class->description->str)); + PRFIELD_GSTRING(comp_class->description)); } if (!extended) { @@ -960,9 +976,14 @@ static inline void format_component(char **buf_ch, bool extended, { char tmp_prefix[64]; - BUF_APPEND(", %sname=\"%s\"", PRFIELD(component->name->str)); - SET_TMP_PREFIX("class-"); - format_component_class(buf_ch, extended, tmp_prefix, component->class); + BUF_APPEND(", %sname=\"%s\"", + PRFIELD_GSTRING(component->name)); + + if (component->class) { + SET_TMP_PREFIX("class-"); + format_component_class(buf_ch, extended, tmp_prefix, + component->class); + } if (!extended) { return; @@ -986,7 +1007,7 @@ static inline void format_port(char **buf_ch, bool extended, BUF_APPEND(", %stype=%s, %sname=\"%s\"", PRFIELD(bt_port_type_string(port->type)), - PRFIELD(port->name->str)); + PRFIELD_GSTRING(port->name)); if (!extended) { return; @@ -1059,10 +1080,10 @@ static inline void format_notification_iterator(char **buf_ch, const char *type; char tmp_prefix[64]; - if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION) { - type = "BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION"; - } else if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT) { - type = "BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT"; + if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT) { + type = "BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT"; + } else if (iterator->type == BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT) { + type = "BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT"; } else { type = "(unknown)"; } @@ -1070,41 +1091,47 @@ static inline void format_notification_iterator(char **buf_ch, BUF_APPEND(", %stype=%s", PRFIELD(type)); switch (iterator->type) { - case BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION: + case BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT: { - struct bt_notification_iterator_private_connection * - iter_priv_conn = (void *) iterator; + struct bt_self_component_port_input_notification_iterator * + port_in_iter = (void *) iterator; - if (iter_priv_conn->upstream_component) { + if (port_in_iter->upstream_component) { SET_TMP_PREFIX("upstream-comp-"); format_component(buf_ch, false, tmp_prefix, - iter_priv_conn->upstream_component); + port_in_iter->upstream_component); } - if (iter_priv_conn->upstream_port) { + if (port_in_iter->upstream_port) { SET_TMP_PREFIX("upstream-port-"); format_port(buf_ch, false, tmp_prefix, - iter_priv_conn->upstream_port); + port_in_iter->upstream_port); } - if (iter_priv_conn->connection) { + if (port_in_iter->connection) { SET_TMP_PREFIX("upstream-conn-"); format_connection(buf_ch, false, tmp_prefix, - iter_priv_conn->connection); + port_in_iter->connection); } break; } - case BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT: + case BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT: { - struct bt_notification_iterator_output_port *iter_output_port = + struct bt_port_output_notification_iterator *port_out_iter = (void *) iterator; - SET_TMP_PREFIX("graph-"); - format_graph(buf_ch, false, tmp_prefix, - iter_output_port->graph); - SET_TMP_PREFIX("colander-comp-"); - format_component(buf_ch, false, tmp_prefix, - iter_output_port->colander); + if (port_out_iter->graph) { + SET_TMP_PREFIX("graph-"); + format_graph(buf_ch, false, tmp_prefix, + port_out_iter->graph); + } + + if (port_out_iter->colander) { + SET_TMP_PREFIX("colander-comp-"); + format_component(buf_ch, false, tmp_prefix, + (void *) port_out_iter->colander); + } + break; } default: @@ -1121,12 +1148,12 @@ static inline void format_plugin(char **buf_ch, bool extended, if (plugin->info.path_set) { BUF_APPEND(", %spath=\"%s\"", - PRFIELD(plugin->info.path->str)); + PRFIELD_GSTRING(plugin->info.path)); } if (plugin->info.name_set) { BUF_APPEND(", %sname=\"%s\"", - PRFIELD(plugin->info.name->str)); + PRFIELD_GSTRING(plugin->info.name)); } if (!extended) { @@ -1135,12 +1162,12 @@ static inline void format_plugin(char **buf_ch, bool extended, if (plugin->info.author_set) { BUF_APPEND(", %sauthor=\"%s\"", - PRFIELD(plugin->info.author->str)); + PRFIELD_GSTRING(plugin->info.author)); } if (plugin->info.license_set) { BUF_APPEND(", %slicense=\"%s\"", - PRFIELD(plugin->info.license->str)); + PRFIELD_GSTRING(plugin->info.license)); } if (plugin->info.version_set) { @@ -1152,9 +1179,11 @@ static inline void format_plugin(char **buf_ch, bool extended, plugin->info.version.extra->str : ""); } - BUF_APPEND(", %sis-frozen=%d, %scomp-class-count=%u", - PRFIELD(plugin->frozen), - PRFIELD(plugin->comp_classes->len)); + BUF_APPEND(", %ssrc-comp-class-count=%u, %sflt-comp-class-count=%u, " + "%ssink-comp-class-count=%u", + PRFIELD(plugin->src_comp_classes->len), + PRFIELD(plugin->flt_comp_classes->len), + PRFIELD(plugin->sink_comp_classes->len)); if (plugin->spec_data) { struct bt_plugin_so_spec_data *spec_data = diff --git a/lib/object.c b/lib/object.c index 0f7261a9..60036544 100644 --- a/lib/object.c +++ b/lib/object.c @@ -1,8 +1,4 @@ /* - * ref.c: reference counting - * - * Babeltrace Library - * * Copyright (c) 2015 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index c0fb97b5..b875ad68 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -1,8 +1,4 @@ /* - * plugin-so.c - * - * Babeltrace Plugin (shared object) - * * Copyright 2016 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -37,6 +33,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -98,6 +98,7 @@ void fini_comp_class_list(void) bt_list_del(&comp_class->node); BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); } + BT_LOGD_STR("Released references from all component classes to shared library handles."); } @@ -278,13 +279,42 @@ enum bt_plugin_status bt_plugin_so_init( const struct __bt_plugin_component_class_descriptor *descriptor; const char *description; const char *help; - bt_component_class_init_method init_method; - bt_component_class_finalize_method finalize_method; - bt_component_class_query_method query_method; - bt_component_class_accept_port_connection_method accept_port_connection_method; - bt_component_class_port_connected_method port_connected_method; - bt_component_class_port_disconnected_method port_disconnected_method; - struct bt_component_class_notification_iterator_methods iterator_methods; + + union { + struct { + bt_private_component_class_source_init_method init; + bt_private_component_class_source_finalize_method finalize; + bt_private_component_class_source_query_method query; + bt_private_component_class_source_accept_output_port_connection_method accept_output_port_connection; + bt_private_component_class_source_output_port_connected_method output_port_connected; + bt_private_component_class_source_output_port_disconnected_method output_port_disconnected; + bt_private_component_class_source_notification_iterator_init_method notif_iter_init; + bt_private_component_class_source_notification_iterator_finalize_method notif_iter_finalize; + } source; + + struct { + bt_private_component_class_filter_init_method init; + bt_private_component_class_filter_finalize_method finalize; + bt_private_component_class_filter_query_method query; + bt_private_component_class_filter_accept_input_port_connection_method accept_input_port_connection; + bt_private_component_class_filter_accept_output_port_connection_method accept_output_port_connection; + bt_private_component_class_filter_input_port_connected_method input_port_connected; + bt_private_component_class_filter_output_port_connected_method output_port_connected; + bt_private_component_class_filter_input_port_disconnected_method input_port_disconnected; + bt_private_component_class_filter_output_port_disconnected_method output_port_disconnected; + bt_private_component_class_filter_notification_iterator_init_method notif_iter_init; + bt_private_component_class_filter_notification_iterator_finalize_method notif_iter_finalize; + } filter; + + struct { + bt_private_component_class_sink_init_method init; + bt_private_component_class_sink_finalize_method finalize; + bt_private_component_class_sink_query_method query; + bt_private_component_class_sink_accept_input_port_connection_method accept_input_port_connection; + bt_private_component_class_sink_input_port_connected_method input_port_connected; + bt_private_component_class_sink_input_port_disconnected_method input_port_disconnected; + } sink; + } methods; }; enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; @@ -409,6 +439,7 @@ enum bt_plugin_status bt_plugin_so_init( for (cur_cc_descr_attr_ptr = cc_descr_attrs_begin; cur_cc_descr_attr_ptr != cc_descr_attrs_end; cur_cc_descr_attr_ptr++) { const struct __bt_plugin_component_class_descriptor_attribute *cur_cc_descr_attr = *cur_cc_descr_attr_ptr; + enum bt_component_class_type cc_type; if (cur_cc_descr_attr == NULL) { continue; @@ -419,83 +450,220 @@ enum bt_plugin_status bt_plugin_so_init( continue; } + cc_type = cur_cc_descr_attr->comp_class_descriptor->type; + /* Find the corresponding component class descriptor entry */ for (i = 0; i < comp_class_full_descriptors->len; i++) { struct comp_class_full_descriptor *cc_full_descr = &g_array_index(comp_class_full_descriptors, struct comp_class_full_descriptor, i); - if (cur_cc_descr_attr->comp_class_descriptor == + if (cur_cc_descr_attr->comp_class_descriptor != cc_full_descr->descriptor) { - switch (cur_cc_descr_attr->type) { - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION: - cc_full_descr->description = - cur_cc_descr_attr->value.description; + continue; + } + + switch (cur_cc_descr_attr->type) { + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION: + cc_full_descr->description = + cur_cc_descr_attr->value.description; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP: + cc_full_descr->help = + cur_cc_descr_attr->value.help; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.init = + cur_cc_descr_attr->value.source_init_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP: - cc_full_descr->help = - cur_cc_descr_attr->value.help; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.init = + cur_cc_descr_attr->value.filter_init_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD: - cc_full_descr->init_method = - cur_cc_descr_attr->value.init_method; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.init = + cur_cc_descr_attr->value.sink_init_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD: - cc_full_descr->finalize_method = - cur_cc_descr_attr->value.finalize_method; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.finalize = + cur_cc_descr_attr->value.source_finalize_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD: - cc_full_descr->query_method = - cur_cc_descr_attr->value.query_method; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.finalize = + cur_cc_descr_attr->value.filter_finalize_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD: - cc_full_descr->accept_port_connection_method = - cur_cc_descr_attr->value.accept_port_connection_method; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.finalize = + cur_cc_descr_attr->value.sink_finalize_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD: - cc_full_descr->port_connected_method = - cur_cc_descr_attr->value.port_connected_method; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.query = + cur_cc_descr_attr->value.source_query_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD: - cc_full_descr->port_disconnected_method = - cur_cc_descr_attr->value.port_disconnected_method; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.query = + cur_cc_descr_attr->value.filter_query_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD: - cc_full_descr->iterator_methods.init = - cur_cc_descr_attr->value.notif_iter_init_method; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.query = + cur_cc_descr_attr->value.sink_query_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD: - cc_full_descr->iterator_methods.finalize = - cur_cc_descr_attr->value.notif_iter_finalize_method; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.accept_input_port_connection = + cur_cc_descr_attr->value.filter_accept_input_port_connection_method; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.accept_input_port_connection = + cur_cc_descr_attr->value.sink_accept_input_port_connection_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.accept_output_port_connection = + cur_cc_descr_attr->value.source_accept_output_port_connection_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.accept_output_port_connection = + cur_cc_descr_attr->value.filter_accept_output_port_connection_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.input_port_connected = + cur_cc_descr_attr->value.filter_input_port_connected_method; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.input_port_connected = + cur_cc_descr_attr->value.sink_input_port_connected_method; break; default: - /* - * WARN-level logging because - * this should not happen with - * the appropriate ABI version. - * If we're here, we know that - * for the reported version of - * the ABI, this attribute is - * unknown. - */ - BT_LOGW("Ignoring unknown component class descriptor attribute: " - "plugin-path=\"%s\", " - "plugin-name=\"%s\", " - "comp-class-name=\"%s\", " - "comp-class-type=%s, " - "attr-type-name=\"%s\", " - "attr-type-id=%d", - spec->shared_lib_handle->path ? - spec->shared_lib_handle->path->str : - NULL, - descriptor->name, - cur_cc_descr_attr->comp_class_descriptor->name, - bt_component_class_type_string( - cur_cc_descr_attr->comp_class_descriptor->type), - cur_cc_descr_attr->type_name, - cur_cc_descr_attr->type); + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.output_port_connected = + cur_cc_descr_attr->value.source_output_port_connected_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.output_port_connected = + cur_cc_descr_attr->value.filter_output_port_connected_method; break; + default: + abort(); } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.input_port_disconnected = + cur_cc_descr_attr->value.filter_input_port_disconnected_method; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.input_port_disconnected = + cur_cc_descr_attr->value.sink_input_port_disconnected_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.output_port_disconnected = + cur_cc_descr_attr->value.source_output_port_disconnected_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.output_port_disconnected = + cur_cc_descr_attr->value.filter_output_port_disconnected_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.notif_iter_init = + cur_cc_descr_attr->value.source_notif_iter_init_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.notif_iter_init = + cur_cc_descr_attr->value.filter_notif_iter_init_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.notif_iter_finalize = + cur_cc_descr_attr->value.source_notif_iter_finalize_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.notif_iter_finalize = + cur_cc_descr_attr->value.filter_notif_iter_finalize_method; + break; + default: + abort(); + } + break; + default: + /* + * WARN-level logging because this + * should not happen with the + * appropriate ABI version. If we're + * here, we know that for the reported + * version of the ABI, this attribute is + * unknown. + */ + BT_LOGW("Ignoring unknown component class descriptor attribute: " + "plugin-path=\"%s\", " + "plugin-name=\"%s\", " + "comp-class-name=\"%s\", " + "comp-class-type=%s, " + "attr-type-name=\"%s\", " + "attr-type-id=%d", + spec->shared_lib_handle->path ? + spec->shared_lib_handle->path->str : + NULL, + descriptor->name, + cur_cc_descr_attr->comp_class_descriptor->name, + bt_component_class_type_string( + cur_cc_descr_attr->comp_class_descriptor->type), + cur_cc_descr_attr->type_name, + cur_cc_descr_attr->type); + break; } } } @@ -520,7 +688,10 @@ enum bt_plugin_status bt_plugin_so_init( struct comp_class_full_descriptor *cc_full_descr = &g_array_index(comp_class_full_descriptors, struct comp_class_full_descriptor, i); - struct bt_component_class *comp_class; + struct bt_private_component_class *comp_class = NULL; + struct bt_private_component_class_source *src_comp_class = NULL; + struct bt_private_component_class_filter *flt_comp_class = NULL; + struct bt_private_component_class_sink *sink_comp_class = NULL; BT_LOGD("Creating and setting properties of plugin's component class: " "plugin-path=\"%s\", plugin-name=\"%s\", " @@ -535,19 +706,25 @@ enum bt_plugin_status bt_plugin_so_init( switch (cc_full_descr->descriptor->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: - comp_class = bt_component_class_source_create( + src_comp_class = bt_private_component_class_source_create( cc_full_descr->descriptor->name, cc_full_descr->descriptor->methods.source.notif_iter_next); + comp_class = bt_private_component_class_source_borrow_private_component_class( + src_comp_class); break; case BT_COMPONENT_CLASS_TYPE_FILTER: - comp_class = bt_component_class_filter_create( + flt_comp_class = bt_private_component_class_filter_create( cc_full_descr->descriptor->name, cc_full_descr->descriptor->methods.source.notif_iter_next); + comp_class = bt_private_component_class_filter_borrow_private_component_class( + flt_comp_class); break; case BT_COMPONENT_CLASS_TYPE_SINK: - comp_class = bt_component_class_sink_create( + sink_comp_class = bt_private_component_class_sink_create( cc_full_descr->descriptor->name, cc_full_descr->descriptor->methods.sink.consume); + comp_class = bt_private_component_class_sink_borrow_private_component_class( + sink_comp_class); break; default: /* @@ -576,8 +753,8 @@ enum bt_plugin_status bt_plugin_so_init( } if (cc_full_descr->description) { - ret = bt_component_class_set_description(comp_class, - cc_full_descr->description); + ret = bt_private_component_class_set_description( + comp_class, cc_full_descr->description); if (ret) { BT_LOGE_STR("Cannot set component class's description."); status = BT_PLUGIN_STATUS_ERROR; @@ -587,7 +764,7 @@ enum bt_plugin_status bt_plugin_so_init( } if (cc_full_descr->help) { - ret = bt_component_class_set_help(comp_class, + ret = bt_private_component_class_set_help(comp_class, cc_full_descr->help); if (ret) { BT_LOGE_STR("Cannot set component class's help string."); @@ -597,124 +774,312 @@ enum bt_plugin_status bt_plugin_so_init( } } - if (cc_full_descr->init_method) { - ret = bt_component_class_set_init_method(comp_class, - cc_full_descr->init_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's initialization method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + switch (cc_full_descr->descriptor->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + if (cc_full_descr->methods.source.init) { + ret = bt_private_component_class_source_set_init_method( + src_comp_class, + cc_full_descr->methods.source.init); + if (ret) { + BT_LOGE_STR("Cannot set source component class's initialization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - if (cc_full_descr->finalize_method) { - ret = bt_component_class_set_finalize_method(comp_class, - cc_full_descr->finalize_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's finalization method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + if (cc_full_descr->methods.source.finalize) { + ret = bt_private_component_class_source_set_finalize_method( + src_comp_class, + cc_full_descr->methods.source.finalize); + if (ret) { + BT_LOGE_STR("Cannot set source component class's finalization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - if (cc_full_descr->query_method) { - ret = bt_component_class_set_query_method( - comp_class, cc_full_descr->query_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's query method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + if (cc_full_descr->methods.source.query) { + ret = bt_private_component_class_source_set_query_method( + src_comp_class, + cc_full_descr->methods.source.query); + if (ret) { + BT_LOGE_STR("Cannot set source component class's query method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - if (cc_full_descr->accept_port_connection_method) { - ret = bt_component_class_set_accept_port_connection_method( - comp_class, cc_full_descr->accept_port_connection_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's \"accept port connection\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + if (cc_full_descr->methods.source.accept_output_port_connection) { + ret = bt_private_component_class_source_set_accept_output_port_connection_method( + src_comp_class, + cc_full_descr->methods.source.accept_output_port_connection); + if (ret) { + BT_LOGE_STR("Cannot set source component class's \"accept input output connection\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - if (cc_full_descr->port_connected_method) { - ret = bt_component_class_set_port_connected_method( - comp_class, cc_full_descr->port_connected_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's \"port connected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + if (cc_full_descr->methods.source.output_port_connected) { + ret = bt_private_component_class_source_set_output_port_connected_method( + src_comp_class, + cc_full_descr->methods.source.output_port_connected); + if (ret) { + BT_LOGE_STR("Cannot set source component class's \"output port connected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - if (cc_full_descr->port_disconnected_method) { - ret = bt_component_class_set_port_disconnected_method( - comp_class, cc_full_descr->port_disconnected_method); - if (ret) { - BT_LOGE_STR("Cannot set component class's \"port disconnected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - goto end; + if (cc_full_descr->methods.source.output_port_disconnected) { + ret = bt_private_component_class_source_set_output_port_disconnected_method( + src_comp_class, + cc_full_descr->methods.source.output_port_disconnected); + if (ret) { + BT_LOGE_STR("Cannot set source component class's \"output port disconnected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } } - } - switch (cc_full_descr->descriptor->type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - if (cc_full_descr->iterator_methods.init) { - ret = bt_component_class_source_set_notification_iterator_init_method( - comp_class, - cc_full_descr->iterator_methods.init); + if (cc_full_descr->methods.source.notif_iter_init) { + ret = bt_private_component_class_source_set_notification_iterator_init_method( + src_comp_class, + cc_full_descr->methods.source.notif_iter_init); if (ret) { - BT_LOGE_STR("Cannot set component class's notification iterator initialization method."); + BT_LOGE_STR("Cannot set source component class's notification iterator initialization method."); status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); goto end; } } - if (cc_full_descr->iterator_methods.finalize) { - ret = bt_component_class_source_set_notification_iterator_finalize_method( - comp_class, - cc_full_descr->iterator_methods.finalize); + if (cc_full_descr->methods.source.notif_iter_finalize) { + ret = bt_private_component_class_source_set_notification_iterator_finalize_method( + src_comp_class, + cc_full_descr->methods.source.notif_iter_finalize); if (ret) { BT_LOGE_STR("Cannot set source component class's notification iterator finalization method."); status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); goto end; } } + break; case BT_COMPONENT_CLASS_TYPE_FILTER: - if (cc_full_descr->iterator_methods.init) { - ret = bt_component_class_filter_set_notification_iterator_init_method( - comp_class, - cc_full_descr->iterator_methods.init); + if (cc_full_descr->methods.filter.init) { + ret = bt_private_component_class_filter_set_init_method( + flt_comp_class, + cc_full_descr->methods.filter.init); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's initialization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.finalize) { + ret = bt_private_component_class_filter_set_finalize_method( + flt_comp_class, + cc_full_descr->methods.filter.finalize); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's finalization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.query) { + ret = bt_private_component_class_filter_set_query_method( + flt_comp_class, + cc_full_descr->methods.filter.query); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's query method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.accept_input_port_connection) { + ret = bt_private_component_class_filter_set_accept_input_port_connection_method( + flt_comp_class, + cc_full_descr->methods.filter.accept_input_port_connection); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"accept input port connection\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.accept_output_port_connection) { + ret = bt_private_component_class_filter_set_accept_output_port_connection_method( + flt_comp_class, + cc_full_descr->methods.filter.accept_output_port_connection); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"accept input output connection\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.input_port_connected) { + ret = bt_private_component_class_filter_set_input_port_connected_method( + flt_comp_class, + cc_full_descr->methods.filter.input_port_connected); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.output_port_connected) { + ret = bt_private_component_class_filter_set_output_port_connected_method( + flt_comp_class, + cc_full_descr->methods.filter.output_port_connected); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.input_port_disconnected) { + ret = bt_private_component_class_filter_set_input_port_disconnected_method( + flt_comp_class, + cc_full_descr->methods.filter.input_port_disconnected); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"input port disconnected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.output_port_disconnected) { + ret = bt_private_component_class_filter_set_output_port_disconnected_method( + flt_comp_class, + cc_full_descr->methods.filter.output_port_disconnected); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's \"output port disconnected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.notif_iter_init) { + ret = bt_private_component_class_filter_set_notification_iterator_init_method( + flt_comp_class, + cc_full_descr->methods.filter.notif_iter_init); if (ret) { BT_LOGE_STR("Cannot set filter component class's notification iterator initialization method."); status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; } } - if (cc_full_descr->iterator_methods.finalize) { - ret = bt_component_class_filter_set_notification_iterator_finalize_method( - comp_class, - cc_full_descr->iterator_methods.finalize); + if (cc_full_descr->methods.filter.notif_iter_finalize) { + ret = bt_private_component_class_filter_set_notification_iterator_finalize_method( + flt_comp_class, + cc_full_descr->methods.filter.notif_iter_finalize); if (ret) { BT_LOGE_STR("Cannot set filter component class's notification iterator finalization method."); status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(comp_class); + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; } } + break; case BT_COMPONENT_CLASS_TYPE_SINK: + if (cc_full_descr->methods.sink.init) { + ret = bt_private_component_class_sink_set_init_method( + sink_comp_class, + cc_full_descr->methods.sink.init); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's initialization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.sink.finalize) { + ret = bt_private_component_class_sink_set_finalize_method( + sink_comp_class, + cc_full_descr->methods.sink.finalize); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's finalization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.sink.query) { + ret = bt_private_component_class_sink_set_query_method( + sink_comp_class, + cc_full_descr->methods.sink.query); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's query method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.sink.accept_input_port_connection) { + ret = bt_private_component_class_sink_set_accept_input_port_connection_method( + sink_comp_class, + cc_full_descr->methods.sink.accept_input_port_connection); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's \"accept input port connection\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.sink.input_port_connected) { + ret = bt_private_component_class_sink_set_input_port_connected_method( + sink_comp_class, + cc_full_descr->methods.sink.input_port_connected); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.sink.input_port_disconnected) { + ret = bt_private_component_class_sink_set_input_port_disconnected_method( + sink_comp_class, + cc_full_descr->methods.sink.input_port_disconnected); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's \"input port disconnected\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + break; default: abort(); @@ -725,11 +1090,11 @@ enum bt_plugin_status bt_plugin_so_init( * * This will call back * bt_plugin_so_on_add_component_class() so that we can - * add a mapping in the component class list when - * we know the component class is successfully added. + * add a mapping in the component class list when we + * know the component class is successfully added. */ status = bt_plugin_add_component_class(plugin, - comp_class); + (void *) comp_class); BT_OBJECT_PUT_REF_AND_RESET(comp_class); if (status < 0) { BT_LOGE("Cannot add component class to plugin."); @@ -737,14 +1102,6 @@ enum bt_plugin_status bt_plugin_so_init( } } - /* - * All the plugin's component classes should be added at this - * point. We freeze the plugin so that it's not possible to add - * component classes to this plugin object after this stage - * (plugin object becomes immutable). - */ - bt_plugin_freeze(plugin); - end: g_array_free(comp_class_full_descriptors, TRUE); return status; diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index eb935905..f70f5c31 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -1,8 +1,4 @@ /* - * plugin.c - * - * Babeltrace Plugin (generic) - * * Copyright 2016 Jérémie Galarneau * Copyright 2017 Philippe Proulx * @@ -40,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -113,44 +110,19 @@ void fini_python_plugin_provider(void) { } #endif -extern -int64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) +uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) { - int64_t count = -1; - - if (!plugin_set) { - BT_LOGW_STR("Invalid parameter: plugin set is NULL."); - goto end; - } - - count = (int64_t) plugin_set->plugins->len; - -end: - return count; + BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); + return (uint64_t) plugin_set->plugins->len; } -extern -struct bt_plugin *bt_plugin_set_get_plugin(struct bt_plugin_set *plugin_set, +struct bt_plugin *bt_plugin_set_borrow_plugin_by_index( + struct bt_plugin_set *plugin_set, uint64_t index) { - struct bt_plugin *plugin = NULL; - - if (!plugin_set) { - BT_LOGW_STR("Invalid parameter: plugin set is NULL."); - goto end; - } - - if (index >= plugin_set->plugins->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - plugin_set, index, plugin_set->plugins->len); - goto end; - } - - plugin = bt_object_get_ref(g_ptr_array_index(plugin_set->plugins, index)); - -end: - return plugin; + BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); + BT_ASSERT_PRE_VALID_INDEX(index, plugin_set->plugins->len); + return g_ptr_array_index(plugin_set->plugins, index); } struct bt_plugin_set *bt_plugin_create_all_from_static(void) @@ -163,11 +135,7 @@ struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path) { struct bt_plugin_set *plugin_set = NULL; - if (!path) { - BT_LOGW_STR("Invalid parameter: path is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(path, "Path"); BT_LOGD("Creating plugins from file: path=\"%s\"", path); /* Try shared object plugins */ @@ -214,11 +182,7 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name) int ret; size_t i, j; - if (!plugin_name) { - BT_LOGW_STR("Invalid parameter: plugin name is NULL."); - goto end; - } - + BT_ASSERT_PRE_NON_NULL(plugin_name, "Name"); BT_LOGD("Finding named plugin in standard directories and built-in plugins: " "name=\"%s\"", plugin_name); dirs = g_ptr_array_new_with_free_func((GDestroyNotify) destroy_gstring); @@ -342,9 +306,8 @@ end: } if (plugin) { - BT_LOGD("Found plugin in standard directories and built-in plugins: " - "addr=%p, name=\"%s\", path=\"%s\"", - plugin, plugin_name, bt_plugin_get_path(plugin)); + BT_LIB_LOGD("Found plugin in standard directories and built-in plugins: " + "%!+l", plugin); } else { BT_LOGD("No plugin found in standard directories and built-in plugins: " "name=\"%s\"", plugin_name); @@ -353,49 +316,10 @@ end: return plugin; } -struct bt_component_class *bt_plugin_find_component_class( - const char *plugin_name, const char *comp_cls_name, - enum bt_component_class_type comp_cls_type) -{ - struct bt_plugin *plugin = NULL; - struct bt_component_class *comp_cls = NULL; - - if (!plugin_name) { - BT_LOGW_STR("Invalid parameter: plugin name is NULL."); - goto end; - } - - if (!comp_cls_name) { - BT_LOGW_STR("Invalid parameter: component class name is NULL."); - goto end; - } - - BT_LOGD("Finding named plugin and component class in standard directories and built-in plugins: " - "plugin-name=\"%s\", comp-class-name=\"%s\"", - plugin_name, comp_cls_name); - plugin = bt_plugin_find(plugin_name); - if (!plugin) { - BT_LOGD_STR("Plugin not found."); - goto end; - } - - comp_cls = bt_plugin_get_component_class_by_name_and_type( - plugin, comp_cls_name, comp_cls_type); - if (!comp_cls) { - BT_LOGD("Component class not found in plugin: " - "plugin-addr=%p, plugin-path=\"%s\"", - plugin, bt_plugin_get_path(plugin)); - } - -end: - bt_object_put_ref(plugin); - return comp_cls; -} - static struct { pthread_mutex_t lock; struct bt_plugin_set *plugin_set; - bt_bool recurse; + bool recurse; } append_all_from_dir_info = { .lock = PTHREAD_MUTEX_INITIALIZER }; @@ -432,9 +356,9 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, struct bt_plugin *plugin = g_ptr_array_index(plugins_from_file->plugins, j); - BT_LOGD("Adding plugin to plugin set: " - "plugin-path=\"%s\", plugin-addr=%p, plugin-name=\"%s\"", - file, plugin, bt_plugin_get_name(plugin)); + BT_LIB_LOGD("Adding plugin to plugin set: " + "plugin-path=\"%s\", %![plugin-]+l", + file, plugin); bt_plugin_set_add_plugin(append_all_from_dir_info.plugin_set, plugin); } @@ -462,39 +386,22 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir( bt_bool recurse) { int nftw_flags = FTW_PHYS; - size_t path_len; enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK; - if (!path) { - BT_LOGW_STR("Invalid parameter: path is NULL."); - ret = BT_PLUGIN_STATUS_ERROR; - goto end; - } - - path_len = strlen(path); - if (path_len >= PATH_MAX) { - BT_LOGW("Invalid parameter: path length is too large: " - "path-length=%zu", path_len); - ret = BT_PLUGIN_STATUS_ERROR; - goto end; - } - + BT_ASSERT(plugin_set); + BT_ASSERT(path); + BT_ASSERT(strlen(path) < PATH_MAX); pthread_mutex_lock(&append_all_from_dir_info.lock); - append_all_from_dir_info.plugin_set = plugin_set; append_all_from_dir_info.recurse = recurse; ret = nftw(path, nftw_append_all_from_dir, APPEND_ALL_FROM_DIR_NFDOPEN_MAX, nftw_flags); - pthread_mutex_unlock(&append_all_from_dir_info.lock); - if (ret != 0) { - BT_LOGW("Cannot open directory: %s: path=\"%s\", errno=%d", - strerror(errno), path, errno); + BT_LOGW_ERRNO("Cannot open directory", ": path=\"%s\"", path); ret = BT_PLUGIN_STATUS_ERROR; } -end: return ret; } @@ -535,104 +442,47 @@ end: const char *bt_plugin_get_name(struct bt_plugin *plugin) { - const char *val = NULL; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto end; - } - - if (plugin->info.name_set) { - val = plugin->info.name->str; - } - -end: - return val; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return plugin->info.name_set ? plugin->info.name->str : NULL; } const char *bt_plugin_get_author(struct bt_plugin *plugin) { - const char *val = NULL; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto end; - } - - if (plugin->info.author_set) { - val = plugin->info.author->str; - } - -end: - return val; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return plugin->info.author_set ? plugin->info.author->str : NULL; } const char *bt_plugin_get_license(struct bt_plugin *plugin) { - const char *val = NULL; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto end; - } - - if (plugin->info.license_set) { - val = plugin->info.license->str; - } - -end: - return val; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return plugin->info.license_set ? plugin->info.license->str : NULL; } const char *bt_plugin_get_path(struct bt_plugin *plugin) { - const char *val = NULL; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto end; - } - - if (plugin->info.path_set) { - val = plugin->info.path->str; - } - -end: - return val; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return plugin->info.path_set ? plugin->info.path->str : NULL; } const char *bt_plugin_get_description(struct bt_plugin *plugin) { - const char *val = NULL; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto end; - } - - if (plugin->info.description_set) { - val = plugin->info.description->str; - } - -end: - return val; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return plugin->info.description_set ? + plugin->info.description->str : NULL; } -enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, +enum bt_property_availability bt_plugin_get_version(struct bt_plugin *plugin, unsigned int *major, unsigned int *minor, unsigned int *patch, const char **extra) { - enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; + enum bt_property_availability avail = + BT_PROPERTY_AVAILABILITY_AVAILABLE; - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - status = BT_PLUGIN_STATUS_ERROR; - goto end; - } + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); if (!plugin->info.version_set) { - BT_LOGV("Plugin's version is not set: addr=%p", plugin); - status = BT_PLUGIN_STATUS_ERROR; + BT_LIB_LOGV("Plugin's version is not set: %!+l", plugin); + avail = BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; goto end; } @@ -653,156 +503,110 @@ enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, } end: - return status; + return avail; } -int64_t bt_plugin_get_component_class_count(struct bt_plugin *plugin) +uint64_t bt_plugin_get_source_component_class_count(struct bt_plugin *plugin) { - return plugin ? plugin->comp_classes->len : (int64_t) -1; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return (uint64_t) plugin->src_comp_classes->len; } -struct bt_component_class *bt_plugin_get_component_class_by_index( - struct bt_plugin *plugin, uint64_t index) +uint64_t bt_plugin_get_filter_component_class_count(struct bt_plugin *plugin) { - struct bt_component_class *comp_class = NULL; + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return (uint64_t) plugin->flt_comp_classes->len; +} - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto error; - } +uint64_t bt_plugin_get_sink_component_class_count(struct bt_plugin *plugin) +{ + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + return (uint64_t) plugin->sink_comp_classes->len; +} - if (index >= plugin->comp_classes->len) { - BT_LOGW("Invalid parameter: index is out of bounds: " - "addr=%p, index=%" PRIu64 ", count=%u", - plugin, index, plugin->comp_classes->len); - goto error; - } +static inline +struct bt_component_class *borrow_component_class_by_index( + struct bt_plugin *plugin, GPtrArray *comp_classes, + uint64_t index) +{ + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_VALID_INDEX(index, comp_classes->len); + return g_ptr_array_index(comp_classes, index); +} - comp_class = g_ptr_array_index(plugin->comp_classes, index); - bt_object_get_ref(comp_class); - goto end; -error: - BT_OBJECT_PUT_REF_AND_RESET(comp_class); +struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_index( + struct bt_plugin *plugin, uint64_t index) +{ + return (void *) borrow_component_class_by_index(plugin, + plugin->src_comp_classes, index); +} -end: - return comp_class; +struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_index( + struct bt_plugin *plugin, uint64_t index) +{ + return (void *) borrow_component_class_by_index(plugin, + plugin->flt_comp_classes, index); +} + +struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_index( + struct bt_plugin *plugin, uint64_t index) +{ + return (void *) borrow_component_class_by_index(plugin, + plugin->sink_comp_classes, index); } -struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( - struct bt_plugin *plugin, const char *name, - enum bt_component_class_type type) +static inline +struct bt_component_class *borrow_component_class_by_name( + struct bt_plugin *plugin, GPtrArray *comp_classes, + const char *name) { struct bt_component_class *comp_class = NULL; size_t i; - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto error; - } - - if (!name) { - BT_LOGW_STR("Invalid parameter: name is NULL."); - goto error; - } + BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_NON_NULL(name, "Name"); - for (i = 0; i < plugin->comp_classes->len; i++) { + for (i = 0; i < comp_classes->len; i++) { struct bt_component_class *comp_class_candidate = - g_ptr_array_index(plugin->comp_classes, i); + g_ptr_array_index(comp_classes, i); const char *comp_class_cand_name = bt_component_class_get_name(comp_class_candidate); - enum bt_component_class_type comp_class_cand_type = - bt_component_class_get_type(comp_class_candidate); BT_ASSERT(comp_class_cand_name); - BT_ASSERT(comp_class_cand_type >= 0); - if (strcmp(name, comp_class_cand_name) == 0 && - comp_class_cand_type == type) { - comp_class = bt_object_get_ref(comp_class_candidate); + if (strcmp(name, comp_class_cand_name) == 0) { + comp_class = comp_class_candidate; break; } } - goto end; - -error: - BT_OBJECT_PUT_REF_AND_RESET(comp_class); - -end: return comp_class; } -enum bt_plugin_status bt_plugin_add_component_class( - struct bt_plugin *plugin, struct bt_component_class *comp_class) +struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_name(struct bt_plugin *plugin, + const char *name) { - enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; - struct bt_component_class *comp_class_dup = NULL; - int comp_class_index = -1; - - if (!plugin) { - BT_LOGW_STR("Invalid parameter: plugin is NULL."); - goto error; - } - - if (!comp_class) { - BT_LOGW_STR("Invalid parameter: component class is NULL."); - goto error; - } - - if (plugin->frozen) { - BT_LOGW("Invalid parameter: plugin is frozen: " - "addr=%p, name=\"%s\"", plugin, - bt_plugin_get_name(plugin)); - goto error; - } - - /* Check for duplicate */ - comp_class_dup = bt_plugin_get_component_class_by_name_and_type(plugin, - bt_component_class_get_name(comp_class), - bt_component_class_get_type(comp_class)); - if (comp_class_dup) { - BT_LOGW("Invalid parameter: a component class with this name and type already exists in the plugin: " - "plugin-addr=%p, plugin-name=\"%s\", plugin-path=\"%s\", " - "comp-class-name=\"%s\", comp-class-type=%s", - plugin, bt_plugin_get_name(plugin), - bt_plugin_get_path(plugin), - bt_component_class_get_name(comp_class), - bt_component_class_type_string( - bt_component_class_get_type(comp_class))); - goto error; - } - - /* Add new component class */ - comp_class_index = plugin->comp_classes->len; - g_ptr_array_add(plugin->comp_classes, bt_object_get_ref(comp_class)); - - /* Special case for a shared object plugin */ - if (plugin->type == BT_PLUGIN_TYPE_SO) { - bt_plugin_so_on_add_component_class(plugin, comp_class); - } - - BT_LOGD("Added component class to plugin: " - "plugin-addr=%p, plugin-name=\"%s\", plugin-path=\"%s\", " - "comp-class-addr=%p, comp-class-name=\"%s\", comp-class-type=%s", - plugin, bt_plugin_get_name(plugin), - bt_plugin_get_path(plugin), - comp_class, - bt_component_class_get_name(comp_class), - bt_component_class_type_string( - bt_component_class_get_type(comp_class))); - goto end; - -error: - /* Remove entry from plugin's component classes (if added) */ - if (comp_class_index >= 0) { - g_ptr_array_remove_index(plugin->comp_classes, - comp_class_index); - } + return (void *) borrow_component_class_by_name(plugin, + plugin->src_comp_classes, name); +} - status = BT_PLUGIN_STATUS_ERROR; +struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_name(struct bt_plugin *plugin, + const char *name) +{ + return (void *) borrow_component_class_by_name(plugin, + plugin->flt_comp_classes, name); +} -end: - bt_object_put_ref(comp_class_dup); - return status; +struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_name(struct bt_plugin *plugin, + const char *name) +{ + return (void *) borrow_component_class_by_name(plugin, + plugin->sink_comp_classes, name); } diff --git a/lib/prio_heap/prio_heap.c b/lib/prio_heap/prio_heap.c index ec5d1f97..e6e47113 100644 --- a/lib/prio_heap/prio_heap.c +++ b/lib/prio_heap/prio_heap.c @@ -1,6 +1,4 @@ /* - * prio_heap.c - * * Static-sized priority heap containing pointers. Based on CLRS, * chapter 6. * diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index d1e644f9..68c83f5f 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -1,8 +1,4 @@ /* - * attributes.c - * - * Babeltrace trace IR - Attributes - * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * @@ -81,7 +77,7 @@ void bt_attributes_destroy(struct bt_private_value *attr_obj) BT_HIDDEN int64_t bt_attributes_get_count(struct bt_private_value *attr_obj) { - return bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); + return bt_value_array_get_size(bt_private_value_borrow_value(attr_obj)); } BT_HIDDEN @@ -98,11 +94,11 @@ const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, } if (index >= bt_value_array_get_size( - bt_value_borrow_from_private(attr_obj))) { + bt_private_value_borrow_value(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, index, bt_value_array_get_size( - bt_value_borrow_from_private(attr_obj))); + bt_private_value_borrow_value(attr_obj))); goto end; } @@ -125,7 +121,7 @@ const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, } ret = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj)); + bt_private_value_borrow_value(attr_field_name_obj)); end: return ret; @@ -143,11 +139,11 @@ struct bt_private_value *bt_attributes_borrow_field_value( goto end; } - if (index >= bt_value_array_get_size(bt_value_borrow_from_private(attr_obj))) { + if (index >= bt_value_array_get_size(bt_private_value_borrow_value(attr_obj))) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, index, bt_value_array_get_size( - bt_value_borrow_from_private(attr_obj))); + bt_private_value_borrow_value(attr_obj))); goto end; } @@ -181,7 +177,7 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( struct bt_private_value *attr_field_name_obj = NULL; attr_size = bt_value_array_get_size( - bt_value_borrow_from_private(attr_obj)); + bt_private_value_borrow_value(attr_obj)); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -210,7 +206,7 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( } field_name = bt_value_string_get( - bt_value_borrow_from_private(attr_field_name_obj)); + bt_private_value_borrow_value(attr_field_name_obj)); if (!strcmp(field_name, name)) { break; @@ -245,7 +241,7 @@ int bt_attributes_set_field_value(struct bt_private_value *attr_obj, if (attr_field_obj) { ret = bt_private_value_array_set_element_by_index( attr_field_obj, BT_ATTR_VALUE_INDEX, - bt_value_borrow_from_private(value_obj)); + bt_private_value_borrow_value(value_obj)); attr_field_obj = NULL; goto end; } @@ -260,7 +256,7 @@ int bt_attributes_set_field_value(struct bt_private_value *attr_obj, ret = bt_private_value_array_append_string_element(attr_field_obj, name); ret |= bt_private_value_array_append_element(attr_field_obj, - bt_value_borrow_from_private(value_obj)); + bt_private_value_borrow_value(value_obj)); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); @@ -268,7 +264,7 @@ int bt_attributes_set_field_value(struct bt_private_value *attr_obj, } ret = bt_private_value_array_append_element(attr_obj, - bt_value_borrow_from_private(attr_field_obj)); + bt_private_value_borrow_value(attr_field_obj)); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -326,7 +322,7 @@ int bt_attributes_freeze(struct bt_private_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_get_size(bt_value_borrow_from_private(attr_obj)); + count = bt_value_array_get_size(bt_private_value_borrow_value(attr_obj)); BT_ASSERT(count >= 0); /* @@ -346,7 +342,7 @@ int bt_attributes_freeze(struct bt_private_value *attr_obj) goto end; } - bt_value_freeze(bt_value_borrow_from_private(obj)); + bt_value_freeze(bt_private_value_borrow_value(obj)); } end: diff --git a/lib/trace-ir/clock-class.c b/lib/trace-ir/clock-class.c index d77b121a..2af178da 100644 --- a/lib/trace-ir/clock-class.c +++ b/lib/trace-ir/clock-class.c @@ -344,9 +344,3 @@ int bt_clock_class_cycles_to_ns_from_origin(struct bt_clock_class *clock_class, return ret; } - -struct bt_clock_class *bt_clock_class_borrow_from_private( - struct bt_private_clock_class *priv_clock_class) -{ - return (void *) priv_clock_class; -} diff --git a/lib/trace-ir/event-class.c b/lib/trace-ir/event-class.c index 7c4ff432..8c94fbf0 100644 --- a/lib/trace-ir/event-class.c +++ b/lib/trace-ir/event-class.c @@ -414,9 +414,3 @@ void _bt_event_class_freeze(struct bt_event_class *event_class) BT_LIB_LOGD("Freezing event class: %!+E", event_class); event_class->frozen = true; } - -struct bt_event_class *bt_event_class_borrow_from_private( - struct bt_private_event_class *priv_event_class) -{ - return (void *) priv_event_class; -} diff --git a/lib/trace-ir/event.c b/lib/trace-ir/event.c index b7d4607c..b596adf1 100644 --- a/lib/trace-ir/event.c +++ b/lib/trace-ir/event.c @@ -378,9 +378,3 @@ int bt_private_event_move_header_field( event->header_field = field_wrapper; return 0; } - -struct bt_event *bt_event_borrow_from_private( - struct bt_private_event *priv_event) -{ - return (void *) priv_event; -} diff --git a/lib/trace-ir/field-classes.c b/lib/trace-ir/field-classes.c index 668bc46b..6013464c 100644 --- a/lib/trace-ir/field-classes.c +++ b/lib/trace-ir/field-classes.c @@ -1229,9 +1229,3 @@ void _bt_field_class_make_part_of_trace(struct bt_field_class *fc) break; } } - -struct bt_field_class *bt_field_class_borrow_from_private( - struct bt_private_field_class *priv_field_class) -{ - return (void *) priv_field_class; -} diff --git a/lib/trace-ir/field-path.c b/lib/trace-ir/field-path.c index 2534facf..613974e6 100644 --- a/lib/trace-ir/field-path.c +++ b/lib/trace-ir/field-path.c @@ -1,8 +1,4 @@ /* - * field-path.c - * - * Babeltrace trace IR - Field path - * * Copyright 2013, 2014 Jérémie Galarneau * Copyright 2016 Philippe Proulx * diff --git a/lib/trace-ir/fields.c b/lib/trace-ir/fields.c index eb367c7e..91e85099 100644 --- a/lib/trace-ir/fields.c +++ b/lib/trace-ir/fields.c @@ -1151,9 +1151,3 @@ bool array_field_is_set(struct bt_field *field) end: return is_set; } - -struct bt_field *bt_field_borrow_from_private( - struct bt_private_field *priv_field) -{ - return (void *) priv_field; -} diff --git a/lib/trace-ir/packet.c b/lib/trace-ir/packet.c index 3c01165f..9503f137 100644 --- a/lib/trace-ir/packet.c +++ b/lib/trace-ir/packet.c @@ -515,9 +515,3 @@ int bt_private_packet_set_packet_counter_snapshot( bt_property_uint_set(&packet->packet_counter_snapshot, value); return 0; } - -struct bt_packet *bt_packet_borrow_from_private( - struct bt_private_packet *priv_packet) -{ - return (void *) priv_packet; -} diff --git a/lib/trace-ir/stream-class.c b/lib/trace-ir/stream-class.c index f99ce1ad..1037b825 100644 --- a/lib/trace-ir/stream-class.c +++ b/lib/trace-ir/stream-class.c @@ -643,9 +643,3 @@ bt_bool bt_stream_class_default_clock_is_always_known( /* BT_CLOCK_VALUE_STATUS_UNKNOWN is not supported as of 2.0 */ return BT_TRUE; } - -struct bt_stream_class *bt_stream_class_borrow_from_private( - struct bt_private_stream_class *priv_stream_class) -{ - return (void *) priv_stream_class; -} diff --git a/lib/trace-ir/stream.c b/lib/trace-ir/stream.c index 15810b7b..5bf37b52 100644 --- a/lib/trace-ir/stream.c +++ b/lib/trace-ir/stream.c @@ -217,9 +217,3 @@ void _bt_stream_freeze(struct bt_stream *stream) BT_LIB_LOGD("Freezing stream: %!+s", stream); stream->frozen = true; } - -struct bt_stream *bt_stream_borrow_from_private( - struct bt_private_stream *priv_stream) -{ - return (void *) priv_stream; -} diff --git a/lib/trace-ir/trace.c b/lib/trace-ir/trace.c index 2c572f67..fdb07588 100644 --- a/lib/trace-ir/trace.c +++ b/lib/trace-ir/trace.c @@ -266,7 +266,7 @@ int set_environment_entry(struct bt_trace *trace, const char *name, "%![trace-]+t, entry-name=\"%s\"", trace, name); ret = bt_attributes_set_field_value(trace->environment, name, value); - bt_value_freeze(bt_value_borrow_from_private(value)); + bt_value_freeze(bt_private_value_borrow_value(value)); if (ret) { BT_LIB_LOGE("Cannot set trace's environment entry: " "%![trace-]+t, entry-name=\"%s\"", trace, name); @@ -348,7 +348,7 @@ void bt_trace_borrow_environment_entry_by_index( BT_ASSERT_PRE_NON_NULL(value, "Value"); BT_ASSERT_PRE_VALID_INDEX(index, bt_attributes_get_count(trace->environment)); - *value = bt_value_borrow_from_private( + *value = bt_private_value_borrow_value( bt_attributes_borrow_field_value(trace->environment, index)); BT_ASSERT(*value); *name = bt_attributes_get_field_name(trace->environment, index); @@ -368,7 +368,7 @@ struct bt_value *bt_trace_borrow_environment_entry_value_by_name( { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE_NON_NULL(name, "Name"); - return bt_value_borrow_from_private( + return bt_private_value_borrow_value( bt_attributes_borrow_field_value_by_name(trace->environment, name)); } diff --git a/lib/trace-ir/utils.c b/lib/trace-ir/utils.c index d59ae21b..4addffc2 100644 --- a/lib/trace-ir/utils.c +++ b/lib/trace-ir/utils.c @@ -1,8 +1,4 @@ /* - * utils.c - * - * Babeltrace trace IR - Utilities - * * Copyright 2015 Jérémie Galarneau * * Author: Jérémie Galarneau diff --git a/lib/values.c b/lib/values.c index d91b5f2e..d14bec84 100644 --- a/lib/values.c +++ b/lib/values.c @@ -1,8 +1,4 @@ /* - * Values.c: value objects - * - * Babeltrace Library - * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * @@ -1303,9 +1299,3 @@ bt_bool bt_value_compare(const struct bt_value *object_a, end: return ret; } - -struct bt_value *bt_value_borrow_from_private( - struct bt_private_value *priv_value) -{ - return (void *) priv_value; -} diff --git a/plugins/ctf/common/metadata/ctf-meta-translate.c b/plugins/ctf/common/metadata/ctf-meta-translate.c index ea2eea78..37bc36c9 100644 --- a/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -525,7 +525,7 @@ struct bt_private_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class * if (sc->default_clock_class) { ret = bt_private_stream_class_set_default_clock_class(ir_sc, - bt_clock_class_borrow_from_private(sc->default_clock_class)); + bt_private_clock_class_borrow_clock_class(sc->default_clock_class)); BT_ASSERT(ret == 0); } diff --git a/plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c b/plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c index e6ac8e59..da817a44 100644 --- a/plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c +++ b/plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c @@ -49,10 +49,10 @@ int find_mapped_clock_class(struct ctf_field_class *fc, "clock class: expected-cc-name=\"%s\", " "other-cc-name=\"%s\"", bt_clock_class_get_name( - bt_clock_class_borrow_from_private( + bt_private_clock_class_borrow_clock_class( *clock_class)), bt_clock_class_get_name( - bt_clock_class_borrow_from_private( + bt_private_clock_class_borrow_clock_class( int_fc->mapped_clock_class))); ret = -1; goto end; diff --git a/plugins/ctf/common/metadata/ctf-meta.h b/plugins/ctf/common/metadata/ctf-meta.h index 9ceef820..5f4dce53 100644 --- a/plugins/ctf/common/metadata/ctf-meta.h +++ b/plugins/ctf/common/metadata/ctf-meta.h @@ -1560,7 +1560,7 @@ struct bt_private_clock_class *ctf_trace_class_borrow_clock_class_by_name( for (i = 0; i < tc->clock_classes->len; i++) { struct bt_private_clock_class *cc = tc->clock_classes->pdata[i]; const char *cc_name = bt_clock_class_get_name( - bt_clock_class_borrow_from_private(cc)); + bt_private_clock_class_borrow_clock_class(cc)); BT_ASSERT(cc_name); if (strcmp(cc_name, name) == 0) { diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index 2a33575a..ec1f22c3 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -4676,8 +4676,8 @@ void apply_clock_class_offset(struct ctx *ctx, } freq = bt_clock_class_get_frequency( - bt_clock_class_borrow_from_private(clock)); - bt_clock_class_get_offset(bt_clock_class_borrow_from_private(clock), + bt_private_clock_class_borrow_clock_class(clock)); + bt_clock_class_get_offset(bt_private_clock_class_borrow_clock_class(clock), &cur_offset_s, &cur_offset_cycles); /* Apply offsets */ @@ -4753,7 +4753,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) } clock_class_name = bt_clock_class_get_name( - bt_clock_class_borrow_from_private(clock)); + bt_private_clock_class_borrow_clock_class(clock)); BT_ASSERT(clock_class_name); if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) { /* @@ -4775,10 +4775,10 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) * frequency (move to the part in seconds). */ freq = bt_clock_class_get_frequency( - bt_clock_class_borrow_from_private(clock)); + bt_private_clock_class_borrow_clock_class(clock)); calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq); BT_ASSERT(offset_cycles < bt_clock_class_get_frequency( - bt_clock_class_borrow_from_private(clock))); + bt_private_clock_class_borrow_clock_class(clock))); ret = bt_private_clock_class_set_offset(clock, offset_seconds, offset_cycles); BT_ASSERT(ret == 0); apply_clock_class_offset(ctx, clock); diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 3fc618b9..33808b8e 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -103,7 +103,7 @@ struct bt_notif_iter { struct stack *stack; /* Current notification iterator to create notifications (weak) */ - struct bt_private_connection_private_notification_iterator *notif_iter; + struct bt_self_notification_iterator *notif_iter; /* * Current dynamic scope field pointer. @@ -1693,12 +1693,13 @@ struct bt_private_field *borrow_next_field(struct bt_notif_iter *notit) base_fc = bt_private_field_borrow_class(base_field); BT_ASSERT(base_fc); - switch (bt_field_class_get_type(bt_field_class_borrow_from_private(base_fc))) { + switch (bt_field_class_get_type( + bt_private_field_class_borrow_field_class(base_fc))) { case BT_FIELD_CLASS_TYPE_STRUCTURE: { BT_ASSERT(index < bt_field_class_structure_get_member_count( - bt_field_class_borrow_from_private( + bt_private_field_class_borrow_field_class( bt_private_field_borrow_class( base_field)))); next_field = @@ -1709,7 +1710,7 @@ struct bt_private_field *borrow_next_field(struct bt_notif_iter *notit) case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: BT_ASSERT(index < bt_field_array_get_length( - bt_field_borrow_from_private(base_field))); + bt_private_field_borrow_field(base_field))); next_field = bt_private_field_array_borrow_element_field_by_index( base_field, index); break; @@ -1845,9 +1846,9 @@ update_def_clock: BT_ASSERT(field); BT_ASSERT(bt_private_field_borrow_class(field) == fc->ir_fc); BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(field)) == + bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || - bt_field_get_class_type(bt_field_borrow_from_private(field)) == + bt_field_get_class_type(bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); bt_private_field_unsigned_integer_set_value(field, value); stack_top(notit->stack)->index++; @@ -1890,7 +1891,7 @@ enum bt_bfcr_status bfcr_unsigned_int_char_cb(uint64_t value, string_field = stack_top(notit->stack)->base; BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(string_field)) == + bt_private_field_borrow_field(string_field)) == BT_FIELD_CLASS_TYPE_STRING); /* Append character */ @@ -1936,9 +1937,9 @@ enum bt_bfcr_status bfcr_signed_int_cb(int64_t value, BT_ASSERT(field); BT_ASSERT(bt_private_field_borrow_class(field) == fc->ir_fc); BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(field)) == + bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || - bt_field_get_class_type(bt_field_borrow_from_private(field)) == + bt_field_get_class_type(bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); bt_private_field_signed_integer_set_value(field, value); stack_top(notit->stack)->index++; @@ -1964,7 +1965,7 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value, BT_ASSERT(field); BT_ASSERT(bt_private_field_borrow_class(field) == fc->ir_fc); BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(field)) == + bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_REAL); bt_private_field_real_set_value(field, value); stack_top(notit->stack)->index++; @@ -1989,7 +1990,7 @@ enum bt_bfcr_status bfcr_string_begin_cb( BT_ASSERT(field); BT_ASSERT(bt_private_field_borrow_class(field) == fc->ir_fc); BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(field)) == + bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_STRING); ret = bt_private_field_string_clear(field); BT_ASSERT(ret == 0); @@ -2096,7 +2097,7 @@ enum bt_bfcr_status bfcr_compound_begin_cb( int ret; BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private(field)) == + bt_private_field_borrow_field(field)) == BT_FIELD_CLASS_TYPE_STRING); notit->done_filling_string = false; ret = bt_private_field_string_clear(field); @@ -2138,7 +2139,7 @@ enum bt_bfcr_status bfcr_compound_end_cb( if (array_fc->is_text) { BT_ASSERT(bt_field_get_class_type( - bt_field_borrow_from_private( + bt_private_field_borrow_field( stack_top(notit->stack)->base)) == BT_FIELD_CLASS_TYPE_STRING); bt_bfcr_set_unsigned_int_cb(notit->bfcr, @@ -2266,7 +2267,7 @@ void set_event_default_clock_value(struct bt_notif_iter *notit) struct bt_private_event *event = bt_private_notification_event_borrow_event( notit->event_notif); - struct bt_stream_class *sc = bt_stream_class_borrow_from_private( + struct bt_stream_class *sc = bt_private_stream_class_borrow_stream_class( notit->meta.sc->ir_sc); BT_ASSERT(event); @@ -2346,7 +2347,7 @@ void notify_new_packet(struct bt_notif_iter *notit, } BT_ASSERT(notit->packet); - sc = bt_stream_class_borrow_from_private(notit->meta.sc->ir_sc); + sc = bt_private_stream_class_borrow_stream_class(notit->meta.sc->ir_sc); BT_ASSERT(sc); if (bt_stream_class_packets_have_discarded_event_counter_snapshot(sc)) { @@ -2558,7 +2559,7 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notit) enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *notif_iter, struct bt_private_notification **notification) { enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK; diff --git a/plugins/ctf/common/notif-iter/notif-iter.h b/plugins/ctf/common/notif-iter/notif-iter.h index 81418628..315f54cd 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.h +++ b/plugins/ctf/common/notif-iter/notif-iter.h @@ -287,7 +287,7 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notif_iter); BT_HIDDEN enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, - struct bt_private_connection_private_notification_iterator *notif_iter, + struct bt_self_notification_iterator *notif_iter, struct bt_private_notification **notification); /** diff --git a/plugins/ctf/fs-sink/writer.c b/plugins/ctf/fs-sink/writer.c index ccd57fdd..0142ed6d 100644 --- a/plugins/ctf/fs-sink/writer.c +++ b/plugins/ctf/fs-sink/writer.c @@ -63,10 +63,10 @@ void destroy_writer_component_data(struct writer_component *writer_component) } BT_HIDDEN -void writer_component_finalize(struct bt_private_component *component) +void writer_component_finalize(struct bt_self_component *component) { struct writer_component *writer_component = (struct writer_component *) - bt_private_component_get_user_data(component); + bt_self_component_get_user_data(component); destroy_writer_component_data(writer_component); g_free(writer_component); @@ -199,7 +199,7 @@ end: BT_HIDDEN void writer_component_port_connected( - struct bt_private_component *component, + struct bt_self_component *component, struct bt_private_port *self_port, struct bt_port *other_port) { @@ -207,7 +207,7 @@ void writer_component_port_connected( struct writer_component *writer; enum bt_connection_status conn_status; - writer = bt_private_component_get_user_data(component); + writer = bt_self_component_get_user_data(component); BT_ASSERT(writer); BT_ASSERT(!writer->input_iterator); connection = bt_private_port_get_connection(self_port); @@ -222,13 +222,13 @@ void writer_component_port_connected( } BT_HIDDEN -enum bt_component_status writer_run(struct bt_private_component *component) +enum bt_component_status writer_run(struct bt_self_component *component) { enum bt_component_status ret; struct bt_notification *notification = NULL; struct bt_notification_iterator *it; struct writer_component *writer_component = - bt_private_component_get_user_data(component); + bt_self_component_get_user_data(component); enum bt_notification_iterator_status it_ret; if (unlikely(writer_component->error)) { @@ -291,7 +291,7 @@ end: BT_HIDDEN enum bt_component_status writer_component_init( - struct bt_private_component *component, struct bt_value *params, + struct bt_self_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -305,7 +305,7 @@ enum bt_component_status writer_component_init( goto end; } - ret = bt_private_component_sink_add_input_port(component, + ret = bt_self_component_sink_add_input_port(component, "in", NULL, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; @@ -338,7 +338,7 @@ enum bt_component_status writer_component_init( goto end; } - ret = bt_private_component_set_user_data(component, writer_component); + ret = bt_self_component_set_user_data(component, writer_component); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } diff --git a/plugins/ctf/fs-sink/writer.h b/plugins/ctf/fs-sink/writer.h index 04e55070..9469d398 100644 --- a/plugins/ctf/fs-sink/writer.h +++ b/plugins/ctf/fs-sink/writer.h @@ -92,19 +92,19 @@ enum bt_component_status writer_stream_end(struct writer_component *writer, BT_HIDDEN enum bt_component_status writer_component_init( - struct bt_private_component *component, struct bt_value *params, + struct bt_self_component *component, struct bt_value *params, void *init_method_data); BT_HIDDEN -enum bt_component_status writer_run(struct bt_private_component *component); +enum bt_component_status writer_run(struct bt_self_component *component); BT_HIDDEN void writer_component_port_connected( - struct bt_private_component *component, + struct bt_self_component *component, struct bt_private_port *self_port, struct bt_port *other_port); BT_HIDDEN -void writer_component_finalize(struct bt_private_component *component); +void writer_component_finalize(struct bt_self_component *component); #endif /* BABELTRACE_PLUGIN_WRITER_H */ diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index d47e18b8..2dcfc1d8 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -297,7 +297,7 @@ int convert_cycles_to_ns(struct bt_private_clock_class *clock_class, uint64_t cycles, int64_t *ns) { return bt_clock_class_cycles_to_ns_from_origin( - bt_clock_class_borrow_from_private(clock_class), cycles, ns); + bt_private_clock_class_borrow_clock_class(clock_class), cycles, ns); } static @@ -624,7 +624,7 @@ error: BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, - struct bt_private_connection_private_notification_iterator *pc_notif_iter, + struct bt_self_notification_iterator *pc_notif_iter, struct bt_notif_iter *notif_iter, struct bt_private_stream *stream, const char *path) { diff --git a/plugins/ctf/fs-src/data-stream-file.h b/plugins/ctf/fs-src/data-stream-file.h index e403656e..3a4daad8 100644 --- a/plugins/ctf/fs-src/data-stream-file.h +++ b/plugins/ctf/fs-src/data-stream-file.h @@ -91,7 +91,7 @@ struct ctf_fs_ds_file { struct ctf_fs_metadata *metadata; /* Weak */ - struct bt_private_connection_private_notification_iterator *pc_notif_iter; + struct bt_self_notification_iterator *pc_notif_iter; /* Owned by this */ struct ctf_fs_file *file; @@ -128,7 +128,7 @@ struct ctf_fs_ds_file { BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, - struct bt_private_connection_private_notification_iterator *pc_notif_iter, + struct bt_self_notification_iterator *pc_notif_iter, struct bt_notif_iter *notif_iter, struct bt_private_stream *stream, const char *path); diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 23240952..85ec796f 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -88,19 +88,19 @@ void ctf_fs_notif_iter_data_destroy( } static -enum bt_notification_iterator_status ctf_fs_iterator_next_one( +enum bt_self_notification_iterator_status ctf_fs_iterator_next_one( struct ctf_fs_notif_iter_data *notif_iter_data, struct bt_notification **notif) { - enum bt_notification_iterator_status status; + enum bt_self_notification_iterator_status status; struct bt_private_notification *priv_notif; int ret; BT_ASSERT(notif_iter_data->ds_file); status = ctf_fs_ds_file_next(notif_iter_data->ds_file, &priv_notif); - *notif = bt_notification_borrow_from_private(priv_notif); + *notif = bt_private_notification_borrow_notification(priv_notif); - if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK && + if (status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK && bt_notification_get_type(*notif) == BT_NOTIFICATION_TYPE_STREAM_BEGIN) { if (notif_iter_data->skip_stream_begin_notifs) { @@ -112,8 +112,8 @@ enum bt_notification_iterator_status ctf_fs_iterator_next_one( BT_OBJECT_PUT_REF_AND_RESET(*notif); status = ctf_fs_ds_file_next(notif_iter_data->ds_file, &priv_notif); - *notif = bt_notification_borrow_from_private(priv_notif); - BT_ASSERT(status != BT_NOTIFICATION_ITERATOR_STATUS_END); + *notif = bt_private_notification_borrow_notification(priv_notif); + BT_ASSERT(status != BT_SELF_NOTIFICATION_ITERATOR_STATUS_END); goto end; } else { /* @@ -125,7 +125,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_next_one( } } - if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK && + if (status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK && bt_notification_get_type(*notif) == BT_NOTIFICATION_TYPE_STREAM_END) { notif_iter_data->ds_file_info_index++; @@ -139,7 +139,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_next_one( * The next time ctf_fs_iterator_next() is * called for this notification iterator, * ctf_fs_ds_file_next() will return - * BT_NOTIFICATION_ITERATOR_STATUS_END(). + * BT_SELF_NOTIFICATION_ITERATOR_STATUS_END(). */ goto end; } @@ -153,12 +153,12 @@ enum bt_notification_iterator_status ctf_fs_iterator_next_one( */ ret = notif_iter_data_set_current_ds_file(notif_iter_data); if (ret) { - status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; goto end; } status = ctf_fs_ds_file_next(notif_iter_data->ds_file, &priv_notif); - *notif = bt_notification_borrow_from_private(priv_notif); + *notif = bt_private_notification_borrow_notification(priv_notif); /* * If we get a notification, we expect to get a @@ -178,14 +178,14 @@ enum bt_notification_iterator_status ctf_fs_iterator_next_one( */ BT_ASSERT(notif_iter_data->skip_stream_begin_notifs); - if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + if (status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { BT_ASSERT(bt_notification_get_type(*notif) == BT_NOTIFICATION_TYPE_STREAM_BEGIN); BT_OBJECT_PUT_REF_AND_RESET(*notif); status = ctf_fs_ds_file_next(notif_iter_data->ds_file, &priv_notif); - *notif = bt_notification_borrow_from_private(priv_notif); - BT_ASSERT(status != BT_NOTIFICATION_ITERATOR_STATUS_END); + *notif = bt_private_notification_borrow_notification(priv_notif); + BT_ASSERT(status != BT_SELF_NOTIFICATION_ITERATOR_STATUS_END); } } @@ -194,20 +194,20 @@ end: } BT_HIDDEN -enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator, +enum bt_self_notification_iterator_status ctf_fs_iterator_next( + struct bt_self_notification_iterator *iterator, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; struct ctf_fs_notif_iter_data *notif_iter_data = - bt_private_connection_private_notification_iterator_get_user_data(iterator); + bt_self_notification_iterator_get_data(iterator); uint64_t i = 0; - while (i < capacity && status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + while (i < capacity && status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { status = ctf_fs_iterator_next_one(notif_iter_data, ¬ifs[i]); - if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + if (status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { i++; } } @@ -215,72 +215,70 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( if (i > 0) { /* * Even if ctf_fs_iterator_next_one() returned something - * else than BT_NOTIFICATION_ITERATOR_STATUS_OK, we + * else than BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK, we * accumulated notification objects in the output * notification array, so we need to return - * BT_NOTIFICATION_ITERATOR_STATUS_OK so that they are + * BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK so that they are * transfered to downstream. This other status occurs * again the next time muxer_notif_iter_do_next() is * called, possibly without any accumulated * notification, in which case we'll return it. */ *count = i; - status = BT_NOTIFICATION_ITERATOR_STATUS_OK; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; } return status; } -void ctf_fs_iterator_finalize(struct bt_private_connection_private_notification_iterator *it) +void ctf_fs_iterator_finalize(struct bt_self_notification_iterator *it) { - void *notif_iter_data = - bt_private_connection_private_notification_iterator_get_user_data(it); - - ctf_fs_notif_iter_data_destroy(notif_iter_data); + ctf_fs_notif_iter_data_destroy( + bt_self_notification_iterator_get_data(it)); } -enum bt_notification_iterator_status ctf_fs_iterator_init( - struct bt_private_connection_private_notification_iterator *it, - struct bt_private_port *port) +enum bt_self_notification_iterator_status ctf_fs_iterator_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port) { struct ctf_fs_port_data *port_data; struct ctf_fs_notif_iter_data *notif_iter_data = NULL; - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + enum bt_self_notification_iterator_status ret = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; int iret; - port_data = bt_private_port_get_user_data(port); - if (!port_data) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVALID; - goto error; - } - + port_data = bt_self_component_port_get_data( + bt_self_component_port_output_borrow_self_component_port( + self_port)); + BT_ASSERT(port_data); notif_iter_data = g_new0(struct ctf_fs_notif_iter_data, 1); if (!notif_iter_data) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + ret = BT_SELF_NOTIFICATION_ITERATOR_STATUS_NOMEM; goto error; } - notif_iter_data->pc_notif_iter = it; + notif_iter_data->pc_notif_iter = self_notif_iter; notif_iter_data->notif_iter = bt_notif_iter_create( port_data->ds_file_group->ctf_fs_trace->metadata->tc, bt_common_get_page_size() * 8, ctf_fs_ds_file_medops, NULL); if (!notif_iter_data->notif_iter) { BT_LOGE_STR("Cannot create a CTF notification iterator."); - ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + ret = BT_SELF_NOTIFICATION_ITERATOR_STATUS_NOMEM; goto error; } notif_iter_data->ds_file_group = port_data->ds_file_group; iret = notif_iter_data_set_current_ds_file(notif_iter_data); if (iret) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + ret = BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; goto error; } - ret = bt_private_connection_private_notification_iterator_set_user_data(it, notif_iter_data); - if (ret != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + bt_self_notification_iterator_set_data(self_notif_iter, + notif_iter_data); + if (ret != BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { goto error; } @@ -288,7 +286,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_init( goto end; error: - (void) bt_private_connection_private_notification_iterator_set_user_data(it, NULL); + bt_self_notification_iterator_set_data(self_notif_iter, NULL); end: ctf_fs_notif_iter_data_destroy(notif_iter_data); @@ -347,11 +345,10 @@ void ctf_fs_trace_destroy_notifier(void *data) ctf_fs_trace_destroy(trace); } -void ctf_fs_finalize(struct bt_private_component *component) +void ctf_fs_finalize(struct bt_self_component_source *component) { - void *data = bt_private_component_get_user_data(component); - - ctf_fs_destroy(data); + ctf_fs_destroy(bt_self_component_get_data( + bt_self_component_source_borrow_self_component(component))); } static @@ -414,8 +411,8 @@ int create_one_port_for_trace(struct ctf_fs_component *ctf_fs, port_data->ctf_fs = ctf_fs; port_data->ds_file_group = ds_file_group; - ret = bt_private_component_source_add_output_port( - ctf_fs->priv_comp, port_name->str, port_data, NULL); + ret = bt_self_component_source_add_output_port( + ctf_fs->self_comp, port_name->str, port_data, NULL); if (ret) { goto error; } @@ -660,7 +657,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, if (props.snapshots.beginning_clock != UINT64_C(-1)) { BT_ASSERT(sc->default_clock_class); ret = bt_clock_class_cycles_to_ns_from_origin( - bt_clock_class_borrow_from_private( + bt_private_clock_class_borrow_clock_class( sc->default_clock_class), props.snapshots.beginning_clock, &begin_ns); if (ret) { @@ -1246,28 +1243,29 @@ end: } static -struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, +struct ctf_fs_component *ctf_fs_create( + struct bt_self_component_source *self_comp, struct bt_value *params) { struct ctf_fs_component *ctf_fs; struct bt_value *value = NULL; const char *path_param; - enum bt_component_status ret; ctf_fs = g_new0(struct ctf_fs_component, 1); if (!ctf_fs) { goto end; } - ret = bt_private_component_set_user_data(priv_comp, ctf_fs); - BT_ASSERT(ret == BT_COMPONENT_STATUS_OK); + bt_self_component_set_data( + bt_self_component_source_borrow_self_component(self_comp), + ctf_fs); /* * We don't need to get a new reference here because as long as * our private ctf_fs_component object exists, the containing * private component should also exist. */ - ctf_fs->priv_comp = priv_comp; + ctf_fs->self_comp = self_comp; value = bt_value_map_borrow_entry_value(params, "path"); if (value && !bt_value_is_string(value)) { goto error; @@ -1312,48 +1310,48 @@ struct ctf_fs_component *ctf_fs_create(struct bt_private_component *priv_comp, error: ctf_fs_destroy(ctf_fs); ctf_fs = NULL; - ret = bt_private_component_set_user_data(priv_comp, NULL); - BT_ASSERT(ret == BT_COMPONENT_STATUS_OK); + bt_self_component_set_data( + bt_self_component_source_borrow_self_component(self_comp), + NULL); end: return ctf_fs; } BT_HIDDEN -enum bt_component_status ctf_fs_init(struct bt_private_component *priv_comp, +enum bt_self_component_status ctf_fs_init( + struct bt_self_component_source *self_comp, struct bt_value *params, UNUSED_VAR void *init_method_data) { struct ctf_fs_component *ctf_fs; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; - ctf_fs = ctf_fs_create(priv_comp, params); + ctf_fs = ctf_fs_create(self_comp, params); if (!ctf_fs) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_COMPONENT_STATUS_ERROR; } return ret; } BT_HIDDEN -struct bt_component_class_query_method_return ctf_fs_query( - struct bt_component_class *comp_class, +enum bt_query_status ctf_fs_query( + struct bt_self_component_class_source *comp_class, struct bt_query_executor *query_exec, - const char *object, struct bt_value *params) + const char *object, struct bt_value *params, + struct bt_value **result) { - struct bt_component_class_query_method_return ret = { - .result = NULL, - .status = BT_QUERY_STATUS_OK, - }; + enum bt_query_status status = BT_QUERY_STATUS_OK; if (!strcmp(object, "metadata-info")) { - ret = metadata_info_query(comp_class, params); + status = metadata_info_query(comp_class, params, result); } else if (!strcmp(object, "trace-info")) { - ret = trace_info_query(comp_class, params); + status = trace_info_query(comp_class, params, result); } else { BT_LOGE("Unknown query object `%s`", object); - ret.status = BT_QUERY_STATUS_INVALID_OBJECT; + status = BT_QUERY_STATUS_INVALID_OBJECT; goto end; } end: - return ret; + return status; } diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h index 95711d66..d2c56686 100644 --- a/plugins/ctf/fs-src/fs.h +++ b/plugins/ctf/fs-src/fs.h @@ -70,7 +70,7 @@ struct ctf_fs_metadata { struct ctf_fs_component { /* Weak, guaranteed to exist */ - struct bt_private_component *priv_comp; + struct bt_self_component_source *self_comp; /* Array of struct ctf_fs_port_data *, owned by this */ GPtrArray *port_data; @@ -133,7 +133,7 @@ struct ctf_fs_port_data { struct ctf_fs_notif_iter_data { /* Weak */ - struct bt_private_connection_private_notification_iterator *pc_notif_iter; + struct bt_self_notification_iterator *pc_notif_iter; /* Weak, belongs to ctf_fs_trace */ struct ctf_fs_ds_file_group *ds_file_group; @@ -152,17 +152,19 @@ struct ctf_fs_notif_iter_data { }; BT_HIDDEN -enum bt_component_status ctf_fs_init(struct bt_private_component *source, +enum bt_self_component_status ctf_fs_init( + struct bt_self_component_source *source, struct bt_value *params, void *init_method_data); BT_HIDDEN -void ctf_fs_finalize(struct bt_private_component *component); +void ctf_fs_finalize(struct bt_self_component_source *component); BT_HIDDEN -struct bt_component_class_query_method_return ctf_fs_query( - struct bt_component_class *comp_class, +enum bt_query_status ctf_fs_query( + struct bt_self_component_class_source *comp_class, struct bt_query_executor *query_exec, - const char *object, struct bt_value *params); + const char *object, struct bt_value *params, + struct bt_value **result); BT_HIDDEN struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, @@ -178,15 +180,17 @@ BT_HIDDEN GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path); BT_HIDDEN -enum bt_notification_iterator_status ctf_fs_iterator_init( - struct bt_private_connection_private_notification_iterator *it, - struct bt_private_port *port); +enum bt_self_notification_iterator_status ctf_fs_iterator_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port); + BT_HIDDEN -void ctf_fs_iterator_finalize(struct bt_private_connection_private_notification_iterator *it); +void ctf_fs_iterator_finalize(struct bt_self_notification_iterator *it); BT_HIDDEN -enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator, +enum bt_self_notification_iterator_status ctf_fs_iterator_next( + struct bt_self_notification_iterator *iterator, bt_notification_array notifs, uint64_t capacity, uint64_t *count); diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index d7c9824d..ec8eccbe 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -46,15 +46,11 @@ struct range { }; BT_HIDDEN -struct bt_component_class_query_method_return metadata_info_query( - struct bt_component_class *comp_class, - struct bt_value *params) +enum bt_query_status metadata_info_query( + struct bt_self_component_class_source *comp_class, + struct bt_value *params, struct bt_value **user_result) { - struct bt_component_class_query_method_return query_ret = { - .result = NULL, - .status = BT_QUERY_STATUS_OK, - }; - + enum bt_query_status status = BT_QUERY_STATUS_OK; struct bt_private_value *result = NULL; struct bt_value *path_value = NULL; char *metadata_text = NULL; @@ -67,16 +63,15 @@ struct bt_component_class_query_method_return metadata_info_query( result = bt_private_value_map_create(); if (!result) { - query_ret.status = BT_QUERY_STATUS_NOMEM; + status = BT_QUERY_STATUS_NOMEM; goto error; } - query_ret.result = bt_value_borrow_from_private(result); BT_ASSERT(params); if (!bt_value_is_map(params)) { BT_LOGE_STR("Query parameters is not a map value object."); - query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; + status = BT_QUERY_STATUS_INVALID_PARAMS; goto error; } @@ -163,10 +158,10 @@ struct bt_component_class_query_method_return metadata_info_query( error: BT_OBJECT_PUT_REF_AND_RESET(result); - query_ret.result = NULL; + result = NULL; - if (query_ret.status >= 0) { - query_ret.status = BT_QUERY_STATUS_ERROR; + if (status >= 0) { + status = BT_QUERY_STATUS_ERROR; } end: @@ -180,7 +175,8 @@ end: fclose(metadata_fp); } - return query_ret; + *user_result = bt_private_value_borrow_value(result); + return status; } static @@ -217,7 +213,7 @@ int add_range(struct bt_private_value *info, struct range *range, } status = bt_private_value_map_insert_entry(info, range_name, - bt_value_borrow_from_private(range_map)); + bt_private_value_borrow_value(range_map)); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; @@ -330,14 +326,14 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group, } status = bt_private_value_map_insert_entry(group_info, "paths", - bt_value_borrow_from_private(file_paths)); + bt_private_value_borrow_value(file_paths)); if (status != BT_VALUE_STATUS_OK) { ret = -1; goto end; } ret = add_stream_ids(group_info, - bt_stream_borrow_from_private(group->stream)); + bt_private_stream_borrow_stream(group->stream)); if (ret) { goto end; } @@ -432,7 +428,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, trace_intersection.set = true; status = bt_private_value_array_append_element( file_groups, - bt_value_borrow_from_private(group_info)); + bt_private_value_borrow_value(group_info)); bt_object_put_ref(group_info); if (status != BT_VALUE_STATUS_OK) { goto end; @@ -454,7 +450,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name, } status = bt_private_value_map_insert_entry(trace_info, "streams", - bt_value_borrow_from_private(file_groups)); + bt_private_value_borrow_value(file_groups)); BT_OBJECT_PUT_REF_AND_RESET(file_groups); if (status != BT_VALUE_STATUS_OK) { ret = -1; @@ -468,15 +464,11 @@ end: } BT_HIDDEN -struct bt_component_class_query_method_return trace_info_query( - struct bt_component_class *comp_class, - struct bt_value *params) +enum bt_query_status trace_info_query( + struct bt_self_component_class_source *comp_class, + struct bt_value *params, struct bt_value **user_result) { - struct bt_component_class_query_method_return query_ret = { - .result = NULL, - .status = BT_QUERY_STATUS_OK, - }; - + enum bt_query_status status = BT_QUERY_STATUS_OK; struct bt_private_value *result = NULL; struct bt_value *path_value = NULL; int ret = 0; @@ -491,7 +483,7 @@ struct bt_component_class_query_method_return trace_info_query( if (!bt_value_is_map(params)) { BT_LOGE("Query parameters is not a map value object."); - query_ret.status = BT_QUERY_STATUS_INVALID_PARAMS; + status = BT_QUERY_STATUS_INVALID_PARAMS; goto error; } @@ -519,12 +511,10 @@ struct bt_component_class_query_method_return trace_info_query( result = bt_private_value_array_create(); if (!result) { - query_ret.status = BT_QUERY_STATUS_NOMEM; + status = BT_QUERY_STATUS_NOMEM; goto error; } - query_ret.result = bt_value_borrow_from_private(result); - /* Iterates over both trace paths and names simultaneously. */ for (tp_node = trace_paths, tn_node = trace_names; tp_node; tp_node = g_list_next(tp_node), @@ -548,7 +538,7 @@ struct bt_component_class_query_method_return trace_info_query( } status = bt_private_value_array_append_element(result, - bt_value_borrow_from_private(trace_info)); + bt_private_value_borrow_value(trace_info)); bt_object_put_ref(trace_info); if (status != BT_VALUE_STATUS_OK) { goto error; @@ -559,10 +549,10 @@ struct bt_component_class_query_method_return trace_info_query( error: BT_OBJECT_PUT_REF_AND_RESET(result); - query_ret.result = NULL; + result = NULL; - if (query_ret.status >= 0) { - query_ret.status = BT_QUERY_STATUS_ERROR; + if (status >= 0) { + status = BT_QUERY_STATUS_ERROR; } end: @@ -585,6 +575,7 @@ end: } g_list_free(trace_names); } - /* "path" becomes invalid with the release of path_value. */ - return query_ret; + + *user_result = bt_private_value_borrow_value(result); + return status; } diff --git a/plugins/ctf/fs-src/query.h b/plugins/ctf/fs-src/query.h index ff89fa36..baf8a338 100644 --- a/plugins/ctf/fs-src/query.h +++ b/plugins/ctf/fs-src/query.h @@ -29,13 +29,13 @@ #include BT_HIDDEN -struct bt_component_class_query_method_return metadata_info_query( - struct bt_component_class *comp_class, - struct bt_value *params); +enum bt_query_status metadata_info_query( + struct bt_self_component_class_source *comp_class, + struct bt_value *params, struct bt_value **result); BT_HIDDEN -struct bt_component_class_query_method_return trace_info_query( - struct bt_component_class *comp_class, - struct bt_value *params); +enum bt_query_status trace_info_query( + struct bt_self_component_class_source *comp_class, + struct bt_value *params, struct bt_value **result); #endif /* BABELTRACE_PLUGIN_CTF_FS_QUERY_H */ diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index f09c623b..edad6474 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -174,7 +174,7 @@ struct lttng_live_session { */ struct lttng_live_component { struct bt_object obj; - struct bt_private_component *private_component; /* weak */ + struct bt_self_component *private_component; /* weak */ struct bt_live_viewer_connection *viewer_connection; /* List of struct lttng_live_session */ @@ -209,7 +209,7 @@ enum bt_lttng_live_iterator_status { BT_LTTNG_LIVE_ITERATOR_STATUS_UNSUPPORTED = -4, }; -enum bt_component_status lttng_live_component_init(struct bt_private_component *source, +enum bt_component_status lttng_live_component_init(struct bt_self_component *source, struct bt_value *params, void *init_method_data); struct bt_component_class_query_method_return lttng_live_query( @@ -217,21 +217,21 @@ struct bt_component_class_query_method_return lttng_live_query( struct bt_query_executor *query_exec, const char *object, struct bt_value *params); -void lttng_live_component_finalize(struct bt_private_component *component); +void lttng_live_component_finalize(struct bt_self_component *component); struct bt_notification_iterator_next_method_return lttng_live_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator); + struct bt_self_notification_iterator *iterator); enum bt_component_status lttng_live_accept_port_connection( - struct bt_private_component *private_component, + struct bt_self_component *private_component, struct bt_private_port *self_private_port, struct bt_port *other_port); enum bt_notification_iterator_status lttng_live_iterator_init( - struct bt_private_connection_private_notification_iterator *it, + struct bt_self_notification_iterator *it, struct bt_private_port *port); -void lttng_live_iterator_finalize(struct bt_private_connection_private_notification_iterator *it); +void lttng_live_iterator_finalize(struct bt_self_notification_iterator *it); int lttng_live_create_viewer_session(struct lttng_live_component *lttng_live); int lttng_live_attach_session(struct lttng_live_session *session); diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 833c2ab6..99f6d51c 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -113,7 +113,7 @@ int lttng_live_add_port(struct lttng_live_component *lttng_live, if (lttng_live_is_canceled(lttng_live)) { return 0; } - status = bt_private_component_source_add_output_port( + status = bt_self_component_source_add_output_port( lttng_live->private_component, name, stream_iter, &private_port); switch (status) { @@ -163,7 +163,7 @@ int lttng_live_remove_port(struct lttng_live_component *lttng_live, if (lttng_live_is_canceled(lttng_live)) { return 0; } - status = bt_private_component_source_add_output_port(lttng_live->private_component, + status = bt_self_component_source_add_output_port(lttng_live->private_component, "no-stream", lttng_live->no_stream_iter, <tng_live->no_stream_port); switch (status) { @@ -339,10 +339,10 @@ void lttng_live_destroy_session(struct lttng_live_session *session) } BT_HIDDEN -void lttng_live_iterator_finalize(struct bt_private_connection_private_notification_iterator *it) +void lttng_live_iterator_finalize(struct bt_self_notification_iterator *it) { struct lttng_live_stream_iterator_generic *s = - bt_private_connection_private_notification_iterator_get_user_data(it); + bt_self_notification_iterator_get_user_data(it); switch (s->type) { case LIVE_STREAM_TYPE_NO_STREAM: @@ -756,7 +756,7 @@ enum bt_lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_da */ static struct bt_notification_iterator_next_method_return lttng_live_iterator_next_stream( - struct bt_private_connection_private_notification_iterator *iterator, + struct bt_self_notification_iterator *iterator, struct lttng_live_stream_iterator *stream_iter) { enum bt_lttng_live_iterator_status status; @@ -827,7 +827,7 @@ end: static struct bt_notification_iterator_next_method_return lttng_live_iterator_next_no_stream( - struct bt_private_connection_private_notification_iterator *iterator, + struct bt_self_notification_iterator *iterator, struct lttng_live_no_stream_iterator *no_stream_iter) { enum bt_lttng_live_iterator_status status; @@ -876,10 +876,10 @@ end: BT_HIDDEN struct bt_notification_iterator_next_method_return lttng_live_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator) + struct bt_self_notification_iterator *iterator) { struct lttng_live_stream_iterator_generic *s = - bt_private_connection_private_notification_iterator_get_user_data(iterator); + bt_self_notification_iterator_get_user_data(iterator); struct bt_notification_iterator_next_method_return next_return; switch (s->type) { @@ -900,7 +900,7 @@ struct bt_notification_iterator_next_method_return lttng_live_iterator_next( BT_HIDDEN enum bt_notification_iterator_status lttng_live_iterator_init( - struct bt_private_connection_private_notification_iterator *it, + struct bt_self_notification_iterator *it, struct bt_private_port *port) { enum bt_notification_iterator_status ret = @@ -916,7 +916,7 @@ enum bt_notification_iterator_status lttng_live_iterator_init( { struct lttng_live_no_stream_iterator *no_stream_iter = container_of(s, struct lttng_live_no_stream_iterator, p); - ret = bt_private_connection_private_notification_iterator_set_user_data(it, no_stream_iter); + ret = bt_self_notification_iterator_set_user_data(it, no_stream_iter); if (ret) { goto error; } @@ -926,7 +926,7 @@ enum bt_notification_iterator_status lttng_live_iterator_init( { struct lttng_live_stream_iterator *stream_iter = container_of(s, struct lttng_live_stream_iterator, p); - ret = bt_private_connection_private_notification_iterator_set_user_data(it, stream_iter); + ret = bt_self_notification_iterator_set_user_data(it, stream_iter); if (ret) { goto error; } @@ -940,7 +940,7 @@ enum bt_notification_iterator_status lttng_live_iterator_init( end: return ret; error: - if (bt_private_connection_private_notification_iterator_set_user_data(it, NULL) + if (bt_self_notification_iterator_set_user_data(it, NULL) != BT_NOTIFICATION_ITERATOR_STATUS_OK) { BT_LOGE("Error setting private data to NULL"); } @@ -1049,9 +1049,9 @@ void lttng_live_component_destroy_data(struct lttng_live_component *lttng_live) } BT_HIDDEN -void lttng_live_component_finalize(struct bt_private_component *component) +void lttng_live_component_finalize(struct bt_self_component *component) { - void *data = bt_private_component_get_user_data(component); + void *data = bt_self_component_get_user_data(component); if (!data) { return; @@ -1061,7 +1061,7 @@ void lttng_live_component_finalize(struct bt_private_component *component) static struct lttng_live_component *lttng_live_component_create(struct bt_value *params, - struct bt_private_component *private_component) + struct bt_self_component *private_component) { struct lttng_live_component *lttng_live; struct bt_value *value = NULL; @@ -1107,7 +1107,7 @@ end: BT_HIDDEN enum bt_component_status lttng_live_component_init( - struct bt_private_component *private_component, + struct bt_self_component *private_component, struct bt_value *params, void *init_method_data) { struct lttng_live_component *lttng_live; @@ -1128,7 +1128,7 @@ enum bt_component_status lttng_live_component_init( if (lttng_live_is_canceled(lttng_live)) { goto end; } - ret = bt_private_component_source_add_output_port( + ret = bt_self_component_source_add_output_port( lttng_live->private_component, "no-stream", lttng_live->no_stream_iter, <tng_live->no_stream_port); @@ -1138,7 +1138,7 @@ enum bt_component_status lttng_live_component_init( bt_object_put_ref(lttng_live->no_stream_port); /* weak */ lttng_live->no_stream_iter->port = lttng_live->no_stream_port; - ret = bt_private_component_set_user_data(private_component, lttng_live); + ret = bt_self_component_set_user_data(private_component, lttng_live); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } @@ -1146,19 +1146,19 @@ enum bt_component_status lttng_live_component_init( end: return ret; error: - (void) bt_private_component_set_user_data(private_component, NULL); + (void) bt_self_component_set_user_data(private_component, NULL); lttng_live_component_destroy_data(lttng_live); return ret; } BT_HIDDEN enum bt_component_status lttng_live_accept_port_connection( - struct bt_private_component *private_component, + struct bt_self_component *private_component, struct bt_private_port *self_private_port, struct bt_port *other_port) { struct lttng_live_component *lttng_live = - bt_private_component_get_user_data(private_component); + bt_self_component_get_user_data(private_component); struct bt_component *other_component; enum bt_component_status status = BT_COMPONENT_STATUS_OK; struct bt_port *self_port = bt_port_from_private(self_private_port); diff --git a/plugins/ctf/plugin.c b/plugins/ctf/plugin.c index ee97583f..06a715b4 100644 --- a/plugins/ctf/plugin.c +++ b/plugins/ctf/plugin.c @@ -28,8 +28,6 @@ #include #include "fs-src/fs.h" -#include "fs-sink/writer.h" -#include "lttng-live/lttng-live-internal.h" #ifndef BT_BUILT_IN_PLUGINS BT_PLUGIN_MODULE(); diff --git a/plugins/lttng-utils/plugin.c b/plugins/lttng-utils/plugin.c index d107b322..7d24bf56 100644 --- a/plugins/lttng-utils/plugin.c +++ b/plugins/lttng-utils/plugin.c @@ -54,9 +54,9 @@ void destroy_debug_info_data(struct debug_info_component *debug_info) } static -void destroy_debug_info_component(struct bt_private_component *component) +void destroy_debug_info_component(struct bt_self_component *component) { - void *data = bt_private_component_get_user_data(component); + void *data = bt_self_component_get_user_data(component); destroy_debug_info_data(data); } @@ -83,11 +83,11 @@ void unref_trace(struct debug_info_trace *di_trace) } static -void debug_info_iterator_destroy(struct bt_private_connection_private_notification_iterator *it) +void debug_info_iterator_destroy(struct bt_self_notification_iterator *it) { struct debug_info_iterator *it_data; - it_data = bt_private_connection_private_notification_iterator_get_user_data(it); + it_data = bt_self_notification_iterator_get_user_data(it); BT_ASSERT(it_data); if (it_data->input_iterator_group) { @@ -221,10 +221,10 @@ end: static struct bt_notification_iterator_next_method_return debug_info_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator) + struct bt_self_notification_iterator *iterator) { struct debug_info_iterator *debug_it = NULL; - struct bt_private_component *component = NULL; + struct bt_self_component *component = NULL; struct debug_info_component *debug_info = NULL; struct bt_notification_iterator *source_it = NULL; struct bt_notification *notification; @@ -233,12 +233,12 @@ struct bt_notification_iterator_next_method_return debug_info_iterator_next( .notification = NULL, }; - debug_it = bt_private_connection_private_notification_iterator_get_user_data(iterator); + debug_it = bt_self_notification_iterator_get_user_data(iterator); BT_ASSERT(debug_it); - component = bt_private_connection_private_notification_iterator_get_private_component(iterator); + component = bt_self_notification_iterator_get_private_component(iterator); BT_ASSERT(component); - debug_info = bt_private_component_get_user_data(component); + debug_info = bt_self_component_get_user_data(component); BT_ASSERT(debug_info); source_it = debug_it->input_iterator; @@ -267,7 +267,7 @@ end: static enum bt_notification_iterator_status debug_info_iterator_init( - struct bt_private_connection_private_notification_iterator *iterator, + struct bt_self_notification_iterator *iterator, struct bt_private_port *port) { enum bt_notification_iterator_status ret = @@ -275,8 +275,8 @@ enum bt_notification_iterator_status debug_info_iterator_init( enum bt_notification_iterator_status it_ret; enum bt_connection_status conn_status; struct bt_private_connection *connection = NULL; - struct bt_private_component *component = - bt_private_connection_private_notification_iterator_get_private_component(iterator); + struct bt_self_component *component = + bt_self_notification_iterator_get_private_component(iterator); struct debug_info_iterator *it_data = g_new0(struct debug_info_iterator, 1); struct bt_private_port *input_port; @@ -285,7 +285,7 @@ enum bt_notification_iterator_status debug_info_iterator_init( goto end; } - input_port = bt_private_component_filter_get_input_port_by_name( + input_port = bt_self_component_filter_get_input_port_by_name( component, "in"); if (!input_port) { ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; @@ -307,12 +307,12 @@ enum bt_notification_iterator_status debug_info_iterator_init( } it_data->debug_info_component = (struct debug_info_component *) - bt_private_component_get_user_data(component); + bt_self_component_get_user_data(component); it_data->err = it_data->debug_info_component->err; it_data->trace_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) unref_trace); - it_ret = bt_private_connection_private_notification_iterator_set_user_data(iterator, it_data); + it_ret = bt_self_notification_iterator_set_user_data(iterator, it_data); if (it_ret) { goto end; } @@ -397,7 +397,7 @@ end: } enum bt_component_status debug_info_component_init( - struct bt_private_component *component, struct bt_value *params, + struct bt_self_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -408,18 +408,18 @@ enum bt_component_status debug_info_component_init( goto end; } - ret = bt_private_component_set_user_data(component, debug_info); + ret = bt_self_component_set_user_data(component, debug_info); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - ret = bt_private_component_filter_add_input_port( + ret = bt_self_component_filter_add_input_port( component, "in", NULL, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } - ret = bt_private_component_filter_add_output_port( + ret = bt_self_component_filter_add_output_port( component, "out", NULL, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto end; diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 6ea9af0d..36efc583 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -1,6 +1,6 @@ /* * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation - * Copyright 2017 Philippe Proulx + * Copyright 2017 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,7 +45,7 @@ struct dmesg_component; struct dmesg_notif_iter { struct dmesg_component *dmesg_comp; - struct bt_private_connection_private_notification_iterator *pc_notif_iter; /* Weak */ + struct bt_self_notification_iterator *pc_notif_iter; /* Weak */ char *linebuf; size_t linebuf_len; FILE *fp; @@ -163,7 +163,7 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) ret = bt_private_stream_class_set_default_clock_class( dmesg_comp->stream_class, - bt_clock_class_borrow_from_private( + bt_private_clock_class_borrow_clock_class( dmesg_comp->clock_class)); if (ret) { BT_LOGE_STR("Cannot set stream class's default clock class."); @@ -351,19 +351,21 @@ void destroy_dmesg_component(struct dmesg_component *dmesg_comp) } static -enum bt_component_status create_port(struct bt_private_component *priv_comp) +enum bt_self_component_status create_port( + struct bt_self_component_source *self_comp) { - return bt_private_component_source_add_output_port(priv_comp, + return bt_self_component_source_add_output_port(self_comp, "out", NULL, NULL); } BT_HIDDEN -enum bt_component_status dmesg_init(struct bt_private_component *priv_comp, +enum bt_self_component_status dmesg_init( + struct bt_self_component_source *self_comp, struct bt_value *params, void *init_method_data) { int ret = 0; struct dmesg_component *dmesg_comp = g_new0(struct dmesg_component, 1); - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; if (!dmesg_comp) { BT_LOGE_STR("Failed to allocate one dmesg component structure."); @@ -378,7 +380,7 @@ enum bt_component_status dmesg_init(struct bt_private_component *priv_comp, ret = handle_params(dmesg_comp, params); if (ret) { - BT_LOGE("Invalid parameters: comp-addr=%p", priv_comp); + BT_LOGE("Invalid parameters: comp-addr=%p", self_comp); goto error; } @@ -386,25 +388,29 @@ enum bt_component_status dmesg_init(struct bt_private_component *priv_comp, !g_file_test(dmesg_comp->params.path->str, G_FILE_TEST_IS_REGULAR)) { BT_LOGE("Input path is not a regular file: " - "comp-addr=%p, path=\"%s\"", priv_comp, + "comp-addr=%p, path=\"%s\"", self_comp, dmesg_comp->params.path->str); goto error; } - status = create_port(priv_comp); - if (status != BT_COMPONENT_STATUS_OK) { + status = create_port(self_comp); + if (status != BT_SELF_COMPONENT_STATUS_OK) { goto error; } - (void) bt_private_component_set_user_data(priv_comp, dmesg_comp); + bt_self_component_set_data( + bt_self_component_source_borrow_self_component(self_comp), + dmesg_comp); goto end; error: destroy_dmesg_component(dmesg_comp); - (void) bt_private_component_set_user_data(priv_comp, NULL); + bt_self_component_set_data( + bt_self_component_source_borrow_self_component(self_comp), + NULL); if (status >= 0) { - status = BT_COMPONENT_STATUS_ERROR; + status = BT_SELF_COMPONENT_STATUS_ERROR; } end: @@ -412,11 +418,10 @@ end: } BT_HIDDEN -void dmesg_finalize(struct bt_private_component *priv_comp) +void dmesg_finalize(struct bt_self_component_source *self_comp) { - void *data = bt_private_component_get_user_data(priv_comp); - - destroy_dmesg_component(data); + destroy_dmesg_component(bt_self_component_get_data( + bt_self_component_source_borrow_self_component(self_comp))); } static @@ -618,29 +623,27 @@ void destroy_dmesg_notif_iter(struct dmesg_notif_iter *dmesg_notif_iter) } BT_HIDDEN -enum bt_notification_iterator_status dmesg_notif_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *priv_port) +enum bt_self_notification_iterator_status dmesg_notif_iter_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port) { - struct bt_private_component *priv_comp = NULL; struct dmesg_component *dmesg_comp; struct dmesg_notif_iter *dmesg_notif_iter = g_new0(struct dmesg_notif_iter, 1); - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; if (!dmesg_notif_iter) { BT_LOGE_STR("Failed to allocate on dmesg notification iterator structure."); goto error; } - priv_comp = bt_private_connection_private_notification_iterator_get_private_component( - priv_notif_iter); - BT_ASSERT(priv_comp); - dmesg_comp = bt_private_component_get_user_data(priv_comp); + dmesg_comp = bt_self_component_get_data( + bt_self_component_source_borrow_self_component(self_comp)); BT_ASSERT(dmesg_comp); dmesg_notif_iter->dmesg_comp = dmesg_comp; - dmesg_notif_iter->pc_notif_iter = priv_notif_iter; + dmesg_notif_iter->pc_notif_iter = self_notif_iter; if (dmesg_comp->params.read_from_stdin) { dmesg_notif_iter->fp = stdin; @@ -653,47 +656,45 @@ enum bt_notification_iterator_status dmesg_notif_iter_init( } } - (void) bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, + bt_self_notification_iterator_set_data(self_notif_iter, dmesg_notif_iter); goto end; error: destroy_dmesg_notif_iter(dmesg_notif_iter); - (void) bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, - NULL); + bt_self_notification_iterator_set_data(self_notif_iter, NULL); if (status >= 0) { - status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; } end: - bt_object_put_ref(priv_comp); return status; } BT_HIDDEN void dmesg_notif_iter_finalize( - struct bt_private_connection_private_notification_iterator *priv_notif_iter) + struct bt_self_notification_iterator *priv_notif_iter) { - destroy_dmesg_notif_iter(bt_private_connection_private_notification_iterator_get_user_data( + destroy_dmesg_notif_iter(bt_self_notification_iterator_get_data( priv_notif_iter)); } static -enum bt_notification_iterator_status dmesg_notif_iter_next_one( +enum bt_self_notification_iterator_status dmesg_notif_iter_next_one( struct dmesg_notif_iter *dmesg_notif_iter, struct bt_private_notification **notif) { ssize_t len; struct dmesg_component *dmesg_comp; - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; BT_ASSERT(dmesg_notif_iter); dmesg_comp = dmesg_notif_iter->dmesg_comp; BT_ASSERT(dmesg_comp); if (dmesg_notif_iter->state == STATE_DONE) { - status = BT_NOTIFICATION_ITERATOR_STATUS_END; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_END; goto end; } @@ -711,14 +712,14 @@ enum bt_notification_iterator_status dmesg_notif_iter_next_one( &dmesg_notif_iter->linebuf_len, dmesg_notif_iter->fp); if (len < 0) { if (errno == EINVAL) { - status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; } else if (errno == ENOMEM) { status = - BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + BT_SELF_NOTIFICATION_ITERATOR_STATUS_NOMEM; } else { if (dmesg_notif_iter->state == STATE_EMIT_STREAM_BEGINNING) { /* Stream did not even begin */ - status = BT_NOTIFICATION_ITERATOR_STATUS_END; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_END; goto end; } else { /* End current packet now */ @@ -793,7 +794,7 @@ handle_state: if (!*notif) { BT_LOGE("Cannot create notification: dmesg-comp-addr=%p", dmesg_comp); - status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; } end: @@ -801,25 +802,27 @@ end: } BT_HIDDEN -enum bt_notification_iterator_status dmesg_notif_iter_next( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, +enum bt_self_notification_iterator_status dmesg_notif_iter_next( + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { struct dmesg_notif_iter *dmesg_notif_iter = - bt_private_connection_private_notification_iterator_get_user_data( - priv_notif_iter); - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + bt_self_notification_iterator_get_data( + self_notif_iter); + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; uint64_t i = 0; - while (i < capacity && status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { - struct bt_private_notification *priv_notif; + while (i < capacity && + status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { + struct bt_private_notification *priv_notif = NULL; status = dmesg_notif_iter_next_one(dmesg_notif_iter, &priv_notif); - notifs[i] = bt_notification_borrow_from_private(priv_notif); - if (status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + notifs[i] = bt_private_notification_borrow_notification( + priv_notif); + if (status == BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK) { i++; } } @@ -828,17 +831,17 @@ enum bt_notification_iterator_status dmesg_notif_iter_next( /* * Even if dmesg_notif_iter_next_one() returned * something else than - * BT_NOTIFICATION_ITERATOR_STATUS_OK, we accumulated - * notification objects in the output notification - * array, so we need to return - * BT_NOTIFICATION_ITERATOR_STATUS_OK so that they are - * transfered to downstream. This other status occurs - * again the next time muxer_notif_iter_do_next() is - * called, possibly without any accumulated + * BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK, we + * accumulated notification objects in the output + * notification array, so we need to return + * BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK so that they + * are transfered to downstream. This other status + * occurs again the next time muxer_notif_iter_do_next() + * is called, possibly without any accumulated * notification, in which case we'll return it. */ *count = i; - status = BT_NOTIFICATION_ITERATOR_STATUS_OK; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; } return status; diff --git a/plugins/text/dmesg/dmesg.h b/plugins/text/dmesg/dmesg.h index 3e2398cf..870e87bb 100644 --- a/plugins/text/dmesg/dmesg.h +++ b/plugins/text/dmesg/dmesg.h @@ -2,7 +2,7 @@ #define BABELTRACE_PLUGIN_TEXT_DMESG_DMESG_H /* - * Copyright 2017 Philippe Proulx + * Copyright 2017 Philippe Proulx * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,24 +28,26 @@ #include BT_HIDDEN -enum bt_component_status dmesg_init(struct bt_private_component *priv_comp, +enum bt_self_component_status dmesg_init( + struct bt_self_component_source *self_comp, struct bt_value *params, void *init_method_data); BT_HIDDEN -void dmesg_finalize(struct bt_private_component *priv_comp); +void dmesg_finalize(struct bt_self_component_source *self_comp); BT_HIDDEN -enum bt_notification_iterator_status dmesg_notif_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *priv_port); +enum bt_self_notification_iterator_status dmesg_notif_iter_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port); BT_HIDDEN void dmesg_notif_iter_finalize( - struct bt_private_connection_private_notification_iterator *priv_notif_iter); + struct bt_self_notification_iterator *self_notif_iter); BT_HIDDEN -enum bt_notification_iterator_status dmesg_notif_iter_next( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, +enum bt_self_notification_iterator_status dmesg_notif_iter_next( + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count); diff --git a/plugins/text/plugin.c b/plugins/text/plugin.c index 58a7f8f7..2b09b77b 100644 --- a/plugins/text/plugin.c +++ b/plugins/text/plugin.c @@ -37,7 +37,7 @@ BT_PLUGIN_LICENSE("MIT"); BT_PLUGIN_SINK_COMPONENT_CLASS(pretty, pretty_consume); BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(pretty, pretty_init); BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(pretty, pretty_finalize); -BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD(pretty, +BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(pretty, pretty_port_connected); BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(pretty, "Pretty-print notifications (`text` format of Babeltrace 1)."); diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index 66534b58..30d7d54f 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -1,8 +1,4 @@ /* - * pretty.c - * - * Babeltrace CTF Text Output Plugin - * * Copyright 2016 Jérémie Galarneau * Copyright 2016 Mathieu Desnoyers * @@ -70,7 +66,7 @@ const char *plugin_options[] = { static void destroy_pretty_data(struct pretty_component *pretty) { - bt_object_put_ref(pretty->input_iterator); + bt_object_put_ref(pretty->iterator); if (pretty->string) { (void) g_string_free(pretty->string, TRUE); @@ -118,27 +114,32 @@ error: } BT_HIDDEN -void pretty_finalize(struct bt_private_component *component) +void pretty_finalize(struct bt_self_component_sink *comp) { - void *data = bt_private_component_get_user_data(component); - - destroy_pretty_data(data); + destroy_pretty_data( + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp))); } static -enum bt_component_status handle_notification(struct pretty_component *pretty, +enum bt_self_component_status handle_notification( + struct pretty_component *pretty, struct bt_notification *notification) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; BT_ASSERT(pretty); switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_PACKET_BEGIN: - ret = pretty_print_packet(pretty, notification); + if (pretty_print_packet(pretty, notification)) { + ret = BT_SELF_COMPONENT_STATUS_ERROR; + } break; case BT_NOTIFICATION_TYPE_EVENT: - ret = pretty_print_event(pretty, notification); + if (pretty_print_event(pretty, notification)) { + ret = BT_SELF_COMPONENT_STATUS_ERROR; + } break; case BT_NOTIFICATION_TYPE_INACTIVITY: fprintf(stderr, "Inactivity notification\n"); @@ -151,59 +152,59 @@ enum bt_component_status handle_notification(struct pretty_component *pretty, } BT_HIDDEN -enum bt_component_status pretty_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port) +enum bt_self_component_status pretty_port_connected( + struct bt_self_component_sink *comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - enum bt_connection_status conn_status; - struct bt_private_connection *connection; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct pretty_component *pretty; - pretty = bt_private_component_get_user_data(component); + pretty = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(pretty); - BT_ASSERT(!pretty->input_iterator); - connection = bt_private_port_get_connection(self_port); - BT_ASSERT(connection); - conn_status = bt_private_connection_create_notification_iterator( - connection, &pretty->input_iterator); - if (conn_status != BT_CONNECTION_STATUS_OK) { - status = BT_COMPONENT_STATUS_ERROR; + BT_ASSERT(!pretty->iterator); + pretty->iterator = bt_self_component_port_input_notification_iterator_create( + self_port); + if (!pretty->iterator) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; } - bt_object_put_ref(connection); return status; } BT_HIDDEN -enum bt_component_status pretty_consume(struct bt_private_component *component) +enum bt_self_component_status pretty_consume( + struct bt_self_component_sink *comp) { - enum bt_component_status ret; + enum bt_self_component_status ret; bt_notification_array notifs; - struct bt_notification_iterator *it; - struct pretty_component *pretty = - bt_private_component_get_user_data(component); + struct bt_self_component_port_input_notification_iterator *it; + struct pretty_component *pretty = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); enum bt_notification_iterator_status it_ret; uint64_t count = 0; uint64_t i = 0; - it = pretty->input_iterator; - it_ret = bt_private_connection_notification_iterator_next(it, ¬ifs, - &count); + it = pretty->iterator; + it_ret = bt_self_component_port_input_notification_iterator_next(it, + ¬ifs, &count); switch (it_ret) { - case BT_NOTIFICATION_ITERATOR_STATUS_END: - ret = BT_COMPONENT_STATUS_END; - BT_OBJECT_PUT_REF_AND_RESET(pretty->input_iterator); + case BT_NOTIFICATION_ITERATOR_STATUS_OK: + break; + case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: + ret = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - ret = BT_COMPONENT_STATUS_AGAIN; + ret = BT_SELF_COMPONENT_STATUS_AGAIN; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_SELF_COMPONENT_STATUS_END; + BT_OBJECT_PUT_REF_AND_RESET(pretty->iterator); goto end; - case BT_NOTIFICATION_ITERATOR_STATUS_OK: - break; default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } @@ -227,10 +228,9 @@ end: } static -enum bt_component_status add_params_to_map( - struct bt_private_value *plugin_opt_map) +int add_params_to_map(struct bt_private_value *plugin_opt_map) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; unsigned int i; for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) { @@ -243,7 +243,7 @@ enum bt_component_status add_params_to_map( case BT_VALUE_STATUS_OK: break; default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } } @@ -257,7 +257,7 @@ bt_bool check_param_exists(const char *key, struct bt_value *object, void *data) struct pretty_component *pretty = data; if (!bt_value_map_has_entry( - bt_value_borrow_from_private(pretty->plugin_opt_map), + bt_private_value_borrow_value(pretty->plugin_opt_map), key)) { fprintf(pretty->err, "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key); @@ -266,11 +266,8 @@ bt_bool check_param_exists(const char *key, struct bt_value *object, void *data) } static -enum bt_component_status apply_one_string(const char *key, - struct bt_value *params, - char **option) +void apply_one_string(const char *key, struct bt_value *params, char **option) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_value *value = NULL; const char *str; @@ -285,16 +282,13 @@ enum bt_component_status apply_one_string(const char *key, *option = g_strdup(str); end: - return ret; + return; } static -enum bt_component_status apply_one_bool(const char *key, - struct bt_value *params, - bool *option, +void apply_one_bool(const char *key, struct bt_value *params, bool *option, bool *found) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_value *value = NULL; bt_bool bool_val; @@ -309,7 +303,7 @@ enum bt_component_status apply_one_bool(const char *key, } end: - return ret; + return; } static @@ -320,9 +314,9 @@ void warn_wrong_color_param(struct pretty_component *pretty) } static -enum bt_component_status open_output_file(struct pretty_component *pretty) +int open_output_file(struct pretty_component *pretty) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; if (!pretty->options.output_path) { goto end; @@ -336,27 +330,27 @@ enum bt_component_status open_output_file(struct pretty_component *pretty) goto end; error: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; + end: return ret; } static -enum bt_component_status apply_params(struct pretty_component *pretty, - struct bt_value *params) +int apply_params(struct pretty_component *pretty, struct bt_value *params) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; enum bt_value_status status; bool value, found; char *str = NULL; pretty->plugin_opt_map = bt_private_value_map_create(); if (!pretty->plugin_opt_map) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } ret = add_params_to_map(pretty->plugin_opt_map); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret) { goto end; } /* Report unknown parameters. */ @@ -365,7 +359,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty, case BT_VALUE_STATUS_OK: break; default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } /* Known parameters. */ @@ -392,62 +386,38 @@ enum bt_component_status apply_params(struct pretty_component *pretty, } } - ret = apply_one_string("path", params, &pretty->options.output_path); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_string("path", params, &pretty->options.output_path); ret = open_output_file(pretty); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret) { goto end; } value = false; /* Default. */ - ret = apply_one_bool("no-delta", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("no-delta", params, &value, NULL); pretty->options.print_delta_field = !value; /* Reverse logic. */ value = false; /* Default. */ - ret = apply_one_bool("clock-cycles", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("clock-cycles", params, &value, NULL); pretty->options.print_timestamp_cycles = value; value = false; /* Default. */ - ret = apply_one_bool("clock-seconds", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("clock-seconds", params, &value, NULL); pretty->options.clock_seconds = value; value = false; /* Default. */ - ret = apply_one_bool("clock-date", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("clock-date", params, &value, NULL); pretty->options.clock_date = value; value = false; /* Default. */ - ret = apply_one_bool("clock-gmt", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("clock-gmt", params, &value, NULL); pretty->options.clock_gmt = value; value = false; /* Default. */ - ret = apply_one_bool("verbose", params, &value, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("verbose", params, &value, NULL); pretty->options.verbose = value; /* Names. */ - ret = apply_one_string("name-default", params, &str); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_string("name-default", params, &str); if (!str) { pretty->options.name_default = PRETTY_DEFAULT_UNSET; } else if (!strcmp(str, "show")) { @@ -455,7 +425,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty, } else if (!strcmp(str, "hide")) { pretty->options.name_default = PRETTY_DEFAULT_HIDE; } else { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } g_free(str); @@ -481,55 +451,40 @@ enum bt_component_status apply_params(struct pretty_component *pretty, pretty->options.print_scope_field_names = false; break; default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } value = false; found = false; - ret = apply_one_bool("name-payload", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("name-payload", params, &value, &found); if (found) { pretty->options.print_payload_field_names = value; } value = false; found = false; - ret = apply_one_bool("name-context", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("name-context", params, &value, &found); if (found) { pretty->options.print_context_field_names = value; } value = false; found = false; - ret = apply_one_bool("name-header", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("name-header", params, &value, &found); if (found) { pretty->options.print_header_field_names = value; } value = false; found = false; - ret = apply_one_bool("name-scope", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("name-scope", params, &value, &found); if (found) { pretty->options.print_scope_field_names = value; } /* Fields. */ - ret = apply_one_string("field-default", params, &str); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_string("field-default", params, &str); if (!str) { pretty->options.field_default = PRETTY_DEFAULT_UNSET; } else if (!strcmp(str, "show")) { @@ -537,7 +492,7 @@ enum bt_component_status apply_params(struct pretty_component *pretty, } else if (!strcmp(str, "hide")) { pretty->options.field_default = PRETTY_DEFAULT_HIDE; } else { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } g_free(str); @@ -575,86 +530,62 @@ enum bt_component_status apply_params(struct pretty_component *pretty, pretty->options.print_callsite_field = false; break; default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } value = false; found = false; - ret = apply_one_bool("field-trace", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-trace", params, &value, &found); if (found) { pretty->options.print_trace_field = value; } value = false; found = false; - ret = apply_one_bool("field-trace:hostname", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-trace:hostname", params, &value, &found); if (found) { pretty->options.print_trace_hostname_field = value; } value = false; found = false; - ret = apply_one_bool("field-trace:domain", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-trace:domain", params, &value, &found); if (found) { pretty->options.print_trace_domain_field = value; } value = false; found = false; - ret = apply_one_bool("field-trace:procname", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-trace:procname", params, &value, &found); if (found) { pretty->options.print_trace_procname_field = value; } value = false; found = false; - ret = apply_one_bool("field-trace:vpid", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-trace:vpid", params, &value, &found); if (found) { pretty->options.print_trace_vpid_field = value; } value = false; found = false; - ret = apply_one_bool("field-loglevel", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-loglevel", params, &value, &found); if (found) { pretty->options.print_loglevel_field = value; } value = false; found = false; - ret = apply_one_bool("field-emf", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-emf", params, &value, &found); if (found) { pretty->options.print_emf_field = value; } value = false; found = false; - ret = apply_one_bool("field-callsite", params, &value, &found); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } + apply_one_bool("field-callsite", params, &value, &found); if (found) { pretty->options.print_callsite_field = value; } @@ -703,22 +634,21 @@ void init_stream_packet_context_quarks(void) } BT_HIDDEN -enum bt_component_status pretty_init( - struct bt_private_component *component, +enum bt_self_component_status pretty_init( + struct bt_self_component_sink *comp, struct bt_value *params, UNUSED_VAR void *init_method_data) { - enum bt_component_status ret; + enum bt_self_component_status ret; struct pretty_component *pretty = create_pretty(); if (!pretty) { - ret = BT_COMPONENT_STATUS_NOMEM; + ret = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } - ret = bt_private_component_sink_add_input_port(component, - "in", NULL, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { + ret = bt_self_component_sink_add_input_port(comp, "in", NULL, NULL); + if (ret != BT_SELF_COMPONENT_STATUS_OK) { goto end; } @@ -731,21 +661,19 @@ enum bt_component_status pretty_init( pretty->delta_real_timestamp = -1ULL; pretty->last_real_timestamp = -1ULL; - ret = apply_params(pretty, params); - if (ret != BT_COMPONENT_STATUS_OK) { + if (apply_params(pretty, params)) { + ret = BT_SELF_COMPONENT_STATUS_ERROR; goto error; } set_use_colors(pretty); - ret = bt_private_component_set_user_data(component, pretty); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(comp), pretty); init_stream_packet_context_quarks(); end: return ret; + error: destroy_pretty_data(pretty); return ret; diff --git a/plugins/text/pretty/pretty.h b/plugins/text/pretty/pretty.h index ff573e8b..6be4ba3f 100644 --- a/plugins/text/pretty/pretty.h +++ b/plugins/text/pretty/pretty.h @@ -2,8 +2,6 @@ #define BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H /* - * BabelTrace - CTF Text Output Plug-in - * * Copyright 2016 Jérémie Galarneau * * Author: Jérémie Galarneau @@ -74,7 +72,7 @@ struct pretty_options { struct pretty_component { struct pretty_options options; - struct bt_notification_iterator *input_iterator; + struct bt_self_component_port_input_notification_iterator *iterator; FILE *out, *err; int depth; /* nesting, used for tabulation alignment. */ bool start_line; @@ -106,29 +104,30 @@ extern GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN]; BT_HIDDEN -enum bt_component_status pretty_init( - struct bt_private_component *component, +enum bt_self_component_status pretty_init( + struct bt_self_component_sink *component, struct bt_value *params, void *init_method_data); BT_HIDDEN -enum bt_component_status pretty_consume(struct bt_private_component *component); +enum bt_self_component_status pretty_consume( + struct bt_self_component_sink *component); BT_HIDDEN -enum bt_component_status pretty_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port); +enum bt_self_component_status pretty_port_connected( + struct bt_self_component_sink *component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); BT_HIDDEN -void pretty_finalize(struct bt_private_component *component); +void pretty_finalize(struct bt_self_component_sink *component); BT_HIDDEN -enum bt_component_status pretty_print_event(struct pretty_component *pretty, +int pretty_print_event(struct pretty_component *pretty, struct bt_notification *event_notif); BT_HIDDEN -enum bt_component_status pretty_print_packet(struct pretty_component *pretty, +int pretty_print_packet(struct pretty_component *pretty, struct bt_notification *packet_beginning_notif); #endif /* BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H */ diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 7e34af6d..49bb3ff2 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -1,8 +1,4 @@ /* - * print.c - * - * Babeltrace CTF Text Output Plugin Event Printing - * * Copyright 2016 Jérémie Galarneau * Copyright 2016 Mathieu Desnoyers * @@ -54,7 +50,7 @@ struct timestamp { }; static -enum bt_component_status print_field(struct pretty_component *pretty, +int print_field(struct pretty_component *pretty, struct bt_field *field, bool print_names, GQuark *filters_fields, int filter_array_len); @@ -219,11 +215,11 @@ end: } static -enum bt_component_status print_event_timestamp(struct pretty_component *pretty, +int print_event_timestamp(struct pretty_component *pretty, struct bt_event *event, bool *start_line) { bool print_names = pretty->options.print_header_field_names; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_stream *stream = NULL; struct bt_stream_class *stream_class = NULL; struct bt_trace *trace = NULL; @@ -232,18 +228,18 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty, stream = bt_event_borrow_stream(event); if (!stream) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } stream_class = bt_stream_borrow_class(stream); if (!stream_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } trace = bt_stream_class_borrow_trace(stream_class); if (!trace) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -316,11 +312,11 @@ end: } static -enum bt_component_status print_event_header(struct pretty_component *pretty, +int print_event_header(struct pretty_component *pretty, struct bt_event *event) { bool print_names = pretty->options.print_header_field_names; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_event_class *event_class = NULL; struct bt_stream_class *stream_class = NULL; struct bt_trace *trace_class = NULL; @@ -329,21 +325,21 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, event_class = bt_event_borrow_class(event); if (!event_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } stream_class = bt_event_class_borrow_stream_class(event_class); if (!stream_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } trace_class = bt_stream_class_borrow_trace(stream_class); if (!trace_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } ret = print_event_timestamp(pretty, event, &pretty->start_line); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret) { goto end; } if (pretty->options.print_trace_field) { @@ -536,10 +532,10 @@ end: } static -enum bt_component_status print_integer(struct pretty_component *pretty, +int print_integer(struct pretty_component *pretty, struct bt_field *field) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; enum bt_field_class_integer_preferred_display_base base; struct bt_field_class *int_fc; union { @@ -624,7 +620,7 @@ enum bt_component_status print_integer(struct pretty_component *pretty, break; } default: - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } end: @@ -703,10 +699,10 @@ void print_escape_string(struct pretty_component *pretty, const char *str) } static -enum bt_component_status print_enum(struct pretty_component *pretty, +int print_enum(struct pretty_component *pretty, struct bt_field *field) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field_class *enumeration_field_class = NULL; bt_field_class_enumeration_mapping_label_array label_array; uint64_t label_count; @@ -714,7 +710,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty, enumeration_field_class = bt_field_borrow_class(field); if (!enumeration_field_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -732,7 +728,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty, } if (ret) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -764,7 +760,7 @@ enum bt_component_status print_enum(struct pretty_component *pretty, skip_loop: g_string_append(pretty->string, " : container = "); ret = print_integer(pretty, field); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } g_string_append(pretty->string, " )"); @@ -792,20 +788,20 @@ int filter_field_name(struct pretty_component *pretty, const char *field_name, } static -enum bt_component_status print_struct_field(struct pretty_component *pretty, +int print_struct_field(struct pretty_component *pretty, struct bt_field *_struct, struct bt_field_class *struct_class, uint64_t i, bool print_names, uint64_t *nr_printed_fields, GQuark *filter_fields, int filter_array_len) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; const char *field_name; struct bt_field *field = NULL; struct bt_field_class *field_class = NULL;; field = bt_field_structure_borrow_member_field_by_index(_struct, i); if (!field) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -814,7 +810,7 @@ enum bt_component_status print_struct_field(struct pretty_component *pretty, if (filter_fields && !filter_field_name(pretty, field_name, filter_fields, filter_array_len)) { - ret = BT_COMPONENT_STATUS_OK; + ret = 0; goto end; } @@ -834,22 +830,22 @@ end: } static -enum bt_component_status print_struct(struct pretty_component *pretty, +int print_struct(struct pretty_component *pretty, struct bt_field *_struct, bool print_names, GQuark *filter_fields, int filter_array_len) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field_class *struct_class = NULL; uint64_t nr_fields, i, nr_printed_fields; struct_class = bt_field_borrow_class(_struct); if (!struct_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } nr_fields = bt_field_class_structure_get_member_count(struct_class); if (nr_fields < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } g_string_append(pretty->string, "{"); @@ -859,7 +855,7 @@ enum bt_component_status print_struct(struct pretty_component *pretty, ret = print_struct_field(pretty, _struct, struct_class, i, print_names, &nr_printed_fields, filter_fields, filter_array_len); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } @@ -871,7 +867,7 @@ end: } static -enum bt_component_status print_array_field(struct pretty_component *pretty, +int print_array_field(struct pretty_component *pretty, struct bt_field *array, uint64_t i, bool print_names) { struct bt_field *field = NULL; @@ -891,17 +887,17 @@ enum bt_component_status print_array_field(struct pretty_component *pretty, } static -enum bt_component_status print_array(struct pretty_component *pretty, +int print_array(struct pretty_component *pretty, struct bt_field *array, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field_class *array_class = NULL; uint64_t len; uint64_t i; array_class = bt_field_borrow_class(array); if (!array_class) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } len = bt_field_array_get_length(array); @@ -909,7 +905,7 @@ enum bt_component_status print_array(struct pretty_component *pretty, pretty->depth++; for (i = 0; i < len; i++) { ret = print_array_field(pretty, array, i, print_names); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } @@ -921,7 +917,7 @@ end: } static -enum bt_component_status print_sequence_field(struct pretty_component *pretty, +int print_sequence_field(struct pretty_component *pretty, struct bt_field *seq, uint64_t i, bool print_names) { struct bt_field *field = NULL; @@ -941,16 +937,16 @@ enum bt_component_status print_sequence_field(struct pretty_component *pretty, } static -enum bt_component_status print_sequence(struct pretty_component *pretty, +int print_sequence(struct pretty_component *pretty, struct bt_field *seq, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; uint64_t len; uint64_t i; len = bt_field_array_get_length(seq); if (len < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -959,7 +955,7 @@ enum bt_component_status print_sequence(struct pretty_component *pretty, pretty->depth++; for (i = 0; i < len; i++) { ret = print_sequence_field(pretty, seq, i, print_names); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } @@ -971,10 +967,10 @@ end: } static -enum bt_component_status print_variant(struct pretty_component *pretty, +int print_variant(struct pretty_component *pretty, struct bt_field *variant, bool print_names) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field *field = NULL; field = bt_field_variant_borrow_selected_option_field(variant); @@ -986,7 +982,7 @@ enum bt_component_status print_variant(struct pretty_component *pretty, // print_field_name_equal(pretty, tag_choice); } ret = print_field(pretty, field, print_names, NULL, 0); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } pretty->depth--; @@ -997,7 +993,7 @@ end: } static -enum bt_component_status print_field(struct pretty_component *pretty, +int print_field(struct pretty_component *pretty, struct bt_field *field, bool print_names, GQuark *filter_fields, int filter_array_len) { @@ -1020,7 +1016,7 @@ enum bt_component_status print_field(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } - return BT_COMPONENT_STATUS_OK; + return 0; } case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: @@ -1031,7 +1027,7 @@ enum bt_component_status print_field(struct pretty_component *pretty, str = bt_field_string_get_value(field); if (!str) { - return BT_COMPONENT_STATUS_ERROR; + return -1; } if (pretty->use_colors) { @@ -1041,7 +1037,7 @@ enum bt_component_status print_field(struct pretty_component *pretty, if (pretty->use_colors) { g_string_append(pretty->string, COLOR_RST); } - return BT_COMPONENT_STATUS_OK; + return 0; } case BT_FIELD_CLASS_TYPE_STRUCTURE: return print_struct(pretty, field, print_names, filter_fields, @@ -1055,21 +1051,21 @@ enum bt_component_status print_field(struct pretty_component *pretty, default: // TODO: log instead fprintf(pretty->err, "[error] Unknown type id: %d\n", (int) class_id); - return BT_COMPONENT_STATUS_ERROR; + return -1; } } static -enum bt_component_status print_stream_packet_context(struct pretty_component *pretty, +int print_stream_packet_context(struct pretty_component *pretty, struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_packet *packet = NULL; struct bt_field *main_field = NULL; packet = bt_event_borrow_packet(event); if (!packet) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } main_field = bt_packet_borrow_context_field(packet); @@ -1093,10 +1089,10 @@ end: } static -enum bt_component_status print_event_header_raw(struct pretty_component *pretty, +int print_event_header_raw(struct pretty_component *pretty, struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field *main_field = NULL; main_field = bt_event_borrow_header_field(event); @@ -1118,10 +1114,10 @@ end: } static -enum bt_component_status print_stream_event_context(struct pretty_component *pretty, +int print_stream_event_context(struct pretty_component *pretty, struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field *main_field = NULL; main_field = bt_event_borrow_common_context_field(event); @@ -1143,10 +1139,10 @@ end: } static -enum bt_component_status print_event_context(struct pretty_component *pretty, +int print_event_context(struct pretty_component *pretty, struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field *main_field = NULL; main_field = bt_event_borrow_specific_context_field(event); @@ -1168,10 +1164,10 @@ end: } static -enum bt_component_status print_event_payload(struct pretty_component *pretty, +int print_event_payload(struct pretty_component *pretty, struct bt_event *event) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_field *main_field = NULL; main_field = bt_event_borrow_payload_field(event); @@ -1210,10 +1206,10 @@ end: } BT_HIDDEN -enum bt_component_status pretty_print_event(struct pretty_component *pretty, +int pretty_print_event(struct pretty_component *pretty, struct bt_notification *event_notif) { - enum bt_component_status ret; + int ret; struct bt_event *event = bt_notification_event_borrow_event(event_notif); @@ -1221,40 +1217,40 @@ enum bt_component_status pretty_print_event(struct pretty_component *pretty, pretty->start_line = true; g_string_assign(pretty->string, ""); ret = print_event_header(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } ret = print_stream_packet_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } if (pretty->options.verbose) { ret = print_event_header_raw(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } } ret = print_stream_event_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } ret = print_event_context(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } ret = print_event_payload(pretty, event); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != 0) { goto end; } g_string_append_c(pretty->string, '\n'); if (flush_buf(pretty->out, pretty)) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; goto end; } @@ -1263,12 +1259,12 @@ end: } static -enum bt_component_status print_discarded_elements_msg( +int print_discarded_elements_msg( struct pretty_component *pretty, struct bt_packet *packet, uint64_t count, const char *elem_type) { #if 0 - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int ret = 0; struct bt_stream *stream = NULL; struct bt_stream_class *stream_class = NULL; struct bt_trace *trace = NULL; @@ -1375,7 +1371,7 @@ enum bt_component_status print_discarded_elements_msg( * with Babeltrace 1. */ if (flush_buf(stderr, pretty)) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = -1; } return ret; @@ -1384,21 +1380,21 @@ enum bt_component_status print_discarded_elements_msg( } BT_HIDDEN -enum bt_component_status pretty_print_packet(struct pretty_component *pretty, +int pretty_print_packet(struct pretty_component *pretty, struct bt_notification *packet_beginning_notif) { #if 0 struct bt_packet *packet = bt_notification_packet_begin_borrow_packet( packet_beginning_notif); uint64_t count; - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int status = 0; if (bt_packet_get_discarded_event_count(packet, &count) == BT_PACKET_PROPERTY_AVAILABILITY_AVAILABLE && count > 0) { status = print_discarded_elements_msg(pretty, packet, count, "event"); - if (status != BT_COMPONENT_STATUS_OK) { + if (status != 0) { goto end; } } @@ -1408,7 +1404,7 @@ enum bt_component_status pretty_print_packet(struct pretty_component *pretty, count > 0) { status = print_discarded_elements_msg(pretty, packet, count, "packet"); - if (status != BT_COMPONENT_STATUS_OK) { + if (status != 0) { goto end; } } diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index 04450d65..f9ce107f 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -107,35 +107,39 @@ void destroy_private_counter_data(struct counter *counter) g_free(counter); } -void counter_finalize(struct bt_private_component *component) +BT_HIDDEN +void counter_finalize(struct bt_self_component_sink *comp) { struct counter *counter; - BT_ASSERT(component); - counter = bt_private_component_get_user_data(component); + BT_ASSERT(comp); + counter = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(counter); try_print_last(counter); bt_object_put_ref(counter->notif_iter); g_free(counter); } -enum bt_component_status counter_init(struct bt_private_component *component, +BT_HIDDEN +enum bt_self_component_status counter_init( + struct bt_self_component_sink *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { - enum bt_component_status ret; + enum bt_self_component_status ret; struct counter *counter = g_new0(struct counter, 1); struct bt_value *step = NULL; struct bt_value *hide_zero = NULL; if (!counter) { - ret = BT_COMPONENT_STATUS_NOMEM; - goto end; + ret = BT_SELF_COMPONENT_STATUS_NOMEM; + goto error; } - ret = bt_private_component_sink_add_input_port(component, + ret = bt_self_component_sink_add_input_port(component, "in", NULL, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; + if (ret != BT_SELF_COMPONENT_STATUS_OK) { + goto error; } counter->last_printed_total = -1ULL; @@ -158,11 +162,9 @@ enum bt_component_status counter_init(struct bt_private_component *component, counter->hide_zero = (bool) val; } - ret = bt_private_component_set_user_data(component, counter); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(component), + counter); goto end; error: @@ -172,68 +174,61 @@ end: return ret; } -enum bt_component_status counter_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port) +BT_HIDDEN +enum bt_self_component_status counter_port_connected( + struct bt_self_component_sink *comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct counter *counter; - struct bt_notification_iterator *iterator; - struct bt_private_connection *connection; - enum bt_connection_status conn_status; + struct bt_self_component_port_input_notification_iterator *iterator; - counter = bt_private_component_get_user_data(component); + counter = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(counter); - connection = bt_private_port_get_connection(self_port); - BT_ASSERT(connection); - conn_status = bt_private_connection_create_notification_iterator( - connection, &iterator); - if (conn_status != BT_CONNECTION_STATUS_OK) { - status = BT_COMPONENT_STATUS_ERROR; + iterator = bt_self_component_port_input_notification_iterator_create( + self_port); + if (!iterator) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } BT_OBJECT_MOVE_REF(counter->notif_iter, iterator); end: - bt_object_put_ref(connection); return status; } -enum bt_component_status counter_consume(struct bt_private_component *component) +BT_HIDDEN +enum bt_self_component_status counter_consume( + struct bt_self_component_sink *comp) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; struct counter *counter; enum bt_notification_iterator_status it_ret; uint64_t notif_count; bt_notification_array notifs; - counter = bt_private_component_get_user_data(component); + counter = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(counter); if (unlikely(!counter->notif_iter)) { try_print_last(counter); - ret = BT_COMPONENT_STATUS_END; + ret = BT_SELF_COMPONENT_STATUS_END; goto end; } /* Consume notifications */ - it_ret = bt_private_connection_notification_iterator_next( + it_ret = bt_self_component_port_input_notification_iterator_next( counter->notif_iter, ¬ifs, ¬if_count); if (it_ret < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } switch (it_ret) { - case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - ret = BT_COMPONENT_STATUS_AGAIN; - goto end; - case BT_NOTIFICATION_ITERATOR_STATUS_END: - try_print_last(counter); - ret = BT_COMPONENT_STATUS_END; - goto end; case BT_NOTIFICATION_ITERATOR_STATUS_OK: { uint64_t i; @@ -267,7 +262,20 @@ enum bt_component_status counter_consume(struct bt_private_component *component) bt_object_put_ref(notif); } + + ret = BT_SELF_COMPONENT_STATUS_OK; + break; } + case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: + ret = BT_SELF_COMPONENT_STATUS_AGAIN; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + try_print_last(counter); + ret = BT_SELF_COMPONENT_STATUS_END; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: + ret = BT_SELF_COMPONENT_STATUS_NOMEM; + goto end; default: break; } diff --git a/plugins/utils/counter/counter.h b/plugins/utils/counter/counter.h index 8554df58..2c11fa33 100644 --- a/plugins/utils/counter/counter.h +++ b/plugins/utils/counter/counter.h @@ -29,7 +29,7 @@ #include struct counter { - struct bt_notification_iterator *notif_iter; + struct bt_self_component_port_input_notification_iterator *notif_iter; struct { uint64_t event; uint64_t stream_begin; @@ -45,13 +45,21 @@ struct counter { bool hide_zero; }; -enum bt_component_status counter_init(struct bt_private_component *component, +BT_HIDDEN +enum bt_self_component_status counter_init( + struct bt_self_component_sink *component, struct bt_value *params, void *init_method_data); -void counter_finalize(struct bt_private_component *component); -enum bt_component_status counter_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port); -enum bt_component_status counter_consume(struct bt_private_component *component); + +BT_HIDDEN +void counter_finalize(struct bt_self_component_sink *component); + +BT_HIDDEN +enum bt_self_component_status counter_port_connected( + struct bt_self_component_sink *component, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +BT_HIDDEN +enum bt_self_component_status counter_consume(struct bt_self_component_sink *component); #endif /* BABELTRACE_PLUGINS_UTILS_COUNTER_H */ diff --git a/plugins/utils/dummy/dummy.c b/plugins/utils/dummy/dummy.c index 31d1b70d..b3178416 100644 --- a/plugins/utils/dummy/dummy.c +++ b/plugins/utils/dummy/dummy.c @@ -30,40 +30,42 @@ void destroy_private_dummy_data(struct dummy *dummy) { bt_object_put_ref(dummy->notif_iter); g_free(dummy); + } -void dummy_finalize(struct bt_private_component *component) +BT_HIDDEN +void dummy_finalize(struct bt_self_component_sink *comp) { struct dummy *dummy; - BT_ASSERT(component); - dummy = bt_private_component_get_user_data(component); + BT_ASSERT(comp); + dummy = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(dummy); destroy_private_dummy_data(dummy); } -enum bt_component_status dummy_init(struct bt_private_component *component, +BT_HIDDEN +enum bt_self_component_status dummy_init( + struct bt_self_component_sink *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { - enum bt_component_status ret; + enum bt_self_component_status ret; struct dummy *dummy = g_new0(struct dummy, 1); if (!dummy) { - ret = BT_COMPONENT_STATUS_NOMEM; + ret = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } - ret = bt_private_component_sink_add_input_port(component, + ret = bt_self_component_sink_add_input_port(component, "in", NULL, NULL); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; - } - - ret = bt_private_component_set_user_data(component, dummy); - if (ret != BT_COMPONENT_STATUS_OK) { + if (ret != BT_SELF_COMPONENT_STATUS_OK) { goto error; } + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(component), dummy); goto end; error: @@ -73,58 +75,58 @@ end: return ret; } -enum bt_component_status dummy_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port) +BT_HIDDEN +enum bt_self_component_status dummy_port_connected( + struct bt_self_component_sink *comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct dummy *dummy; - struct bt_notification_iterator *iterator; - struct bt_private_connection *connection; - enum bt_connection_status conn_status; + struct bt_self_component_port_input_notification_iterator *iterator; - dummy = bt_private_component_get_user_data(component); + dummy = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(comp)); BT_ASSERT(dummy); - connection = bt_private_port_get_connection(self_port); - BT_ASSERT(connection); - conn_status = bt_private_connection_create_notification_iterator( - connection, &iterator); - if (conn_status != BT_CONNECTION_STATUS_OK) { - status = BT_COMPONENT_STATUS_ERROR; + iterator = bt_self_component_port_input_notification_iterator_create( + self_port); + if (!iterator) { + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } BT_OBJECT_MOVE_REF(dummy->notif_iter, iterator); end: - bt_object_put_ref(connection); return status; } -enum bt_component_status dummy_consume(struct bt_private_component *component) +BT_HIDDEN +enum bt_self_component_status dummy_consume( + struct bt_self_component_sink *component) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; bt_notification_array notifs; uint64_t count; struct dummy *dummy; enum bt_notification_iterator_status it_ret; uint64_t i; - dummy = bt_private_component_get_user_data(component); + dummy = bt_self_component_get_data( + bt_self_component_sink_borrow_self_component(component)); BT_ASSERT(dummy); if (unlikely(!dummy->notif_iter)) { - ret = BT_COMPONENT_STATUS_END; + ret = BT_SELF_COMPONENT_STATUS_END; goto end; } /* Consume one notification */ - it_ret = bt_private_connection_notification_iterator_next( + it_ret = bt_self_component_port_input_notification_iterator_next( dummy->notif_iter, ¬ifs, &count); switch (it_ret) { case BT_NOTIFICATION_ITERATOR_STATUS_OK: - ret = BT_COMPONENT_STATUS_OK; + ret = BT_SELF_COMPONENT_STATUS_OK; for (i = 0; i < count; i++) { bt_object_put_ref(notifs[i]); @@ -132,13 +134,16 @@ enum bt_component_status dummy_consume(struct bt_private_component *component) break; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - ret = BT_COMPONENT_STATUS_AGAIN; + ret = BT_SELF_COMPONENT_STATUS_AGAIN; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_END: - ret = BT_COMPONENT_STATUS_END; + ret = BT_SELF_COMPONENT_STATUS_END; goto end; case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_COMPONENT_STATUS_ERROR; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: + ret = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; default: break; diff --git a/plugins/utils/dummy/dummy.h b/plugins/utils/dummy/dummy.h index a03a0274..ffbeb5b7 100644 --- a/plugins/utils/dummy/dummy.h +++ b/plugins/utils/dummy/dummy.h @@ -25,19 +25,29 @@ #include #include +#include #include struct dummy { - struct bt_notification_iterator *notif_iter; + struct bt_self_component_port_input_notification_iterator *notif_iter; }; -enum bt_component_status dummy_init(struct bt_private_component *component, +BT_HIDDEN +enum bt_self_component_status dummy_init( + struct bt_self_component_sink *component, struct bt_value *params, void *init_method_data); -void dummy_finalize(struct bt_private_component *component); -enum bt_component_status dummy_port_connected( - struct bt_private_component *component, - struct bt_private_port *self_port, - struct bt_port *other_port); -enum bt_component_status dummy_consume(struct bt_private_component *component); + +BT_HIDDEN +void dummy_finalize(struct bt_self_component_sink *component); + +BT_HIDDEN +enum bt_self_component_status dummy_port_connected( + struct bt_self_component_sink *comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); + +BT_HIDDEN +enum bt_self_component_status dummy_consume( + struct bt_self_component_sink *component); #endif /* BABELTRACE_PLUGINS_UTILS_DUMMY_H */ diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 1cd3fd51..ac48ceae 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -44,13 +44,14 @@ struct muxer_comp { /* * Array of struct - * bt_private_connection_private_notification_iterator * + * bt_self_notification_iterator * * (weak refs) */ GPtrArray *muxer_notif_iters; /* Weak ref */ - struct bt_private_component *priv_comp; + struct bt_self_component_filter *self_comp; + unsigned int next_port_num; size_t available_input_ports; bool initializing_muxer_notif_iter; @@ -59,7 +60,7 @@ struct muxer_comp { struct muxer_upstream_notif_iter { /* Owned by this, NULL if ended */ - struct bt_notification_iterator *notif_iter; + struct bt_self_component_port_input_notification_iterator *notif_iter; /* Contains `struct bt_notification *`, owned by this */ GQueue *notifs; @@ -92,7 +93,7 @@ struct muxer_notif_iter { * muxer_upstream_notif_iters above by * muxer_notif_iter_handle_newly_connected_ports(). */ - GList *newly_connected_priv_ports; + GList *newly_connected_self_ports; /* Last time returned in a notification */ int64_t last_returned_ts_ns; @@ -140,8 +141,7 @@ void destroy_muxer_upstream_notif_iter( static struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter( struct muxer_notif_iter *muxer_notif_iter, - struct bt_notification_iterator *notif_iter, - struct bt_private_port *priv_port) + struct bt_self_component_port_input_notification_iterator *self_notif_iter) { struct muxer_upstream_notif_iter *muxer_upstream_notif_iter = g_new0(struct muxer_upstream_notif_iter, 1); @@ -151,11 +151,10 @@ struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter( goto end; } - muxer_upstream_notif_iter->notif_iter = bt_object_get_ref(notif_iter); + muxer_upstream_notif_iter->notif_iter = bt_object_get_ref(self_notif_iter); muxer_upstream_notif_iter->notifs = g_queue_new(); if (!muxer_upstream_notif_iter->notifs) { BT_LOGE_STR("Failed to allocate a GQueue."); - goto end; } @@ -164,19 +163,19 @@ struct muxer_upstream_notif_iter *muxer_notif_iter_add_upstream_notif_iter( BT_LOGD("Added muxer's upstream notification iterator wrapper: " "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p", muxer_upstream_notif_iter, muxer_notif_iter, - notif_iter); + self_notif_iter); end: return muxer_upstream_notif_iter; } static -enum bt_component_status ensure_available_input_port( - struct bt_private_component *priv_comp) +enum bt_self_component_status ensure_available_input_port( + struct bt_self_component_filter *self_comp) { - struct muxer_comp *muxer_comp = - bt_private_component_get_user_data(priv_comp); - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + struct muxer_comp *muxer_comp = bt_self_component_get_data( + bt_self_component_filter_borrow_self_component(self_comp)); + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; GString *port_name = NULL; BT_ASSERT(muxer_comp); @@ -188,18 +187,18 @@ enum bt_component_status ensure_available_input_port( port_name = g_string_new("in"); if (!port_name) { BT_LOGE_STR("Failed to allocate a GString."); - status = BT_COMPONENT_STATUS_NOMEM; + status = BT_SELF_COMPONENT_STATUS_NOMEM; goto end; } g_string_append_printf(port_name, "%u", muxer_comp->next_port_num); - status = bt_private_component_filter_add_input_port( - priv_comp, port_name->str, NULL, NULL); - if (status != BT_COMPONENT_STATUS_OK) { + status = bt_self_component_filter_add_input_port( + self_comp, port_name->str, NULL, NULL); + if (status != BT_SELF_COMPONENT_STATUS_OK) { BT_LOGE("Cannot add input port to muxer component: " "port-name=\"%s\", comp-addr=%p, status=%s", - port_name->str, priv_comp, - bt_component_status_string(status)); + port_name->str, self_comp, + bt_self_component_status_string(status)); goto end; } @@ -207,7 +206,7 @@ enum bt_component_status ensure_available_input_port( muxer_comp->next_port_num++; BT_LOGD("Added one input port to muxer component: " "port-name=\"%s\", comp-addr=%p", - port_name->str, priv_comp); + port_name->str, self_comp); end: if (port_name) { g_string_free(port_name, TRUE); @@ -217,11 +216,11 @@ end: } static -enum bt_component_status create_output_port( - struct bt_private_component *priv_comp) +enum bt_self_component_status create_output_port( + struct bt_self_component_filter *self_comp) { - return bt_private_component_filter_add_output_port( - priv_comp, "out", NULL, NULL); + return bt_self_component_filter_add_output_port( + self_comp, "out", NULL, NULL); } static @@ -288,7 +287,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) } ret = bt_value_map_extend(&real_params, - bt_value_borrow_from_private(default_params), params); + bt_private_value_borrow_value(default_params), params); if (ret) { BT_LOGE("Cannot extend default parameters map value: " "muxer-comp-addr=%p, def-params-addr=%p, " @@ -298,7 +297,7 @@ int configure_muxer_comp(struct muxer_comp *muxer_comp, struct bt_value *params) } assume_absolute_clock_classes = bt_value_map_borrow_entry_value( - bt_value_borrow_from_private(real_params), + bt_private_value_borrow_value(real_params), ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME); if (assume_absolute_clock_classes && !bt_value_is_bool(assume_absolute_clock_classes)) { @@ -327,16 +326,16 @@ end: } BT_HIDDEN -enum bt_component_status muxer_init( - struct bt_private_component *priv_comp, +enum bt_self_component_status muxer_init( + struct bt_self_component_filter *self_comp, struct bt_value *params, void *init_data) { int ret; - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; struct muxer_comp *muxer_comp = g_new0(struct muxer_comp, 1); BT_LOGD("Initializing muxer component: " - "comp-addr=%p, params-addr=%p", priv_comp, params); + "comp-addr=%p, params-addr=%p", self_comp, params); if (!muxer_comp) { BT_LOGE_STR("Failed to allocate one muxer component."); @@ -357,40 +356,42 @@ enum bt_component_status muxer_init( goto error; } - muxer_comp->priv_comp = priv_comp; - ret = bt_private_component_set_user_data(priv_comp, muxer_comp); - BT_ASSERT(ret == 0); - status = ensure_available_input_port(priv_comp); - if (status != BT_COMPONENT_STATUS_OK) { + muxer_comp->self_comp = self_comp; + bt_self_component_set_data( + bt_self_component_filter_borrow_self_component(self_comp), + muxer_comp); + status = ensure_available_input_port(self_comp); + if (status != BT_SELF_COMPONENT_STATUS_OK) { BT_LOGE("Cannot ensure that at least one muxer component's input port is available: " "muxer-comp-addr=%p, status=%s", muxer_comp, - bt_component_status_string(status)); + bt_self_component_status_string(status)); goto error; } - status = create_output_port(priv_comp); + status = create_output_port(self_comp); if (status) { BT_LOGE("Cannot create muxer component's output port: " "muxer-comp-addr=%p, status=%s", muxer_comp, - bt_component_status_string(status)); + bt_self_component_status_string(status)); goto error; } BT_LOGD("Initialized muxer component: " "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p", - priv_comp, params, muxer_comp); + self_comp, params, muxer_comp); goto end; error: destroy_muxer_comp(muxer_comp); - ret = bt_private_component_set_user_data(priv_comp, NULL); - BT_ASSERT(ret == 0); + bt_self_component_set_data( + bt_self_component_filter_borrow_self_component(self_comp), + NULL); - if (status == BT_COMPONENT_STATUS_OK) { - status = BT_COMPONENT_STATUS_ERROR; + if (status == BT_SELF_COMPONENT_STATUS_OK) { + status = BT_SELF_COMPONENT_STATUS_ERROR; } end: @@ -398,54 +399,50 @@ end: } BT_HIDDEN -void muxer_finalize(struct bt_private_component *priv_comp) +void muxer_finalize(struct bt_self_component_filter *self_comp) { - struct muxer_comp *muxer_comp = - bt_private_component_get_user_data(priv_comp); + struct muxer_comp *muxer_comp = bt_self_component_get_data( + bt_self_component_filter_borrow_self_component(self_comp)); BT_LOGD("Finalizing muxer component: comp-addr=%p", - priv_comp); + self_comp); destroy_muxer_comp(muxer_comp); } static -struct bt_notification_iterator *create_notif_iter_on_input_port( - struct bt_private_port *priv_port, int *ret) +struct bt_self_component_port_input_notification_iterator * +create_notif_iter_on_input_port( + struct bt_self_component_port_input *self_port, int *ret) { - struct bt_port *port = bt_port_borrow_from_private(priv_port); - struct bt_notification_iterator *notif_iter = NULL; - struct bt_private_connection *priv_conn = NULL; - enum bt_connection_status conn_status; + struct bt_port *port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_port)); + struct bt_self_component_port_input_notification_iterator *notif_iter = + NULL; BT_ASSERT(ret); *ret = 0; BT_ASSERT(port); BT_ASSERT(bt_port_is_connected(port)); - priv_conn = bt_private_port_get_connection(priv_port); - BT_ASSERT(priv_conn); // TODO: Advance the iterator to >= the time of the latest // returned notification by the muxer notification // iterator which creates it. - conn_status = bt_private_connection_create_notification_iterator( - priv_conn, ¬if_iter); - if (conn_status != BT_CONNECTION_STATUS_OK) { - BT_LOGE("Cannot create upstream notification iterator on input port's connection: " - "port-addr=%p, port-name=\"%s\", conn-addr=%p, " - "status=%s", - port, bt_port_get_name(port), priv_conn, - bt_connection_status_string(conn_status)); + notif_iter = bt_self_component_port_input_notification_iterator_create( + self_port); + if (!notif_iter) { + BT_LOGE("Cannot create upstream notification iterator on input port: " + "port-addr=%p, port-name=\"%s\"", + port, bt_port_get_name(port)); *ret = -1; goto end; } - BT_LOGD("Created upstream notification iterator on input port's connection: " - "port-addr=%p, port-name=\"%s\", conn-addr=%p, " - "notif-iter-addr=%p", - port, bt_port_get_name(port), priv_conn, notif_iter); + BT_LOGD("Created upstream notification iterator on input port: " + "port-addr=%p, port-name=\"%s\", notif-iter-addr=%p", + port, bt_port_get_name(port), notif_iter); end: - bt_object_put_ref(priv_conn); return notif_iter; } @@ -462,7 +459,7 @@ enum bt_notification_iterator_status muxer_upstream_notif_iter_next( "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p", muxer_upstream_notif_iter, muxer_upstream_notif_iter->notif_iter); - status = bt_private_connection_notification_iterator_next( + status = bt_self_component_port_input_notification_iterator_next( muxer_upstream_notif_iter->notif_iter, ¬ifs, &count); BT_LOGV("Upstream notification iterator's \"next\" method returned: " "status=%s", bt_notification_iterator_status_string(status)); @@ -533,18 +530,21 @@ int muxer_notif_iter_handle_newly_connected_ports( * muxer_port_connected(). */ while (true) { - GList *node = muxer_notif_iter->newly_connected_priv_ports; - struct bt_private_port *priv_port; + GList *node = muxer_notif_iter->newly_connected_self_ports; + struct bt_self_component_port_input *self_port; struct bt_port *port; - struct bt_notification_iterator *upstream_notif_iter = NULL; + struct bt_self_component_port_input_notification_iterator * + upstream_notif_iter = NULL; struct muxer_upstream_notif_iter *muxer_upstream_notif_iter; if (!node) { break; } - priv_port = node->data; - port = bt_port_borrow_from_private(priv_port); + self_port = node->data; + port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + (self_port))); BT_ASSERT(port); if (!bt_port_is_connected(port)) { @@ -557,8 +557,8 @@ int muxer_notif_iter_handle_newly_connected_ports( goto remove_node; } - upstream_notif_iter = create_notif_iter_on_input_port(priv_port, - &ret); + upstream_notif_iter = create_notif_iter_on_input_port( + self_port, &ret); if (ret) { /* create_notif_iter_on_input_port() logs errors */ BT_ASSERT(!upstream_notif_iter); @@ -567,8 +567,7 @@ int muxer_notif_iter_handle_newly_connected_ports( muxer_upstream_notif_iter = muxer_notif_iter_add_upstream_notif_iter( - muxer_notif_iter, upstream_notif_iter, - priv_port); + muxer_notif_iter, upstream_notif_iter); BT_OBJECT_PUT_REF_AND_RESET(upstream_notif_iter); if (!muxer_upstream_notif_iter) { /* @@ -580,9 +579,9 @@ int muxer_notif_iter_handle_newly_connected_ports( remove_node: bt_object_put_ref(upstream_notif_iter); - muxer_notif_iter->newly_connected_priv_ports = + muxer_notif_iter->newly_connected_self_ports = g_list_delete_link( - muxer_notif_iter->newly_connected_priv_ports, + muxer_notif_iter->newly_connected_self_ports, node); } @@ -1039,14 +1038,14 @@ enum bt_notification_iterator_status muxer_notif_iter_do_next_one( * connected new ports. If no ports were connected * during this operation, exit the loop. */ - if (!muxer_notif_iter->newly_connected_priv_ports) { + if (!muxer_notif_iter->newly_connected_self_ports) { BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: " "muxer-comp-addr=%p", muxer_comp); break; } } - BT_ASSERT(!muxer_notif_iter->newly_connected_priv_ports); + BT_ASSERT(!muxer_notif_iter->newly_connected_self_ports); /* * At this point we know that all the existing upstream @@ -1157,7 +1156,7 @@ void destroy_muxer_notif_iter(struct muxer_notif_iter *muxer_notif_iter) muxer_notif_iter->muxer_upstream_notif_iters, TRUE); } - g_list_free(muxer_notif_iter->newly_connected_priv_ports); + g_list_free(muxer_notif_iter->newly_connected_self_ports); g_free(muxer_notif_iter); } @@ -1165,7 +1164,6 @@ static int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, struct muxer_notif_iter *muxer_notif_iter) { - struct bt_component *comp; int64_t count; int64_t i; int ret = 0; @@ -1175,9 +1173,9 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, * iterator's list of newly connected ports. They will be * handled by muxer_notif_iter_handle_newly_connected_ports(). */ - comp = bt_component_borrow_from_private(muxer_comp->priv_comp); - BT_ASSERT(comp); - count = bt_component_filter_get_input_port_count(comp); + count = bt_component_filter_get_input_port_count( + bt_self_component_filter_borrow_component_filter( + muxer_comp->self_comp)); if (count < 0) { BT_LOGD("No input port to initialize for muxer component's notification iterator: " "muxer-comp-addr=%p, muxer-notif-iter-addr=%p", @@ -1186,29 +1184,29 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, } for (i = 0; i < count; i++) { - struct bt_private_port *priv_port = - bt_private_component_filter_get_input_port_by_index( - muxer_comp->priv_comp, i); + struct bt_self_component_port_input *self_port = + bt_self_component_filter_borrow_input_port_by_index( + muxer_comp->self_comp, i); struct bt_port *port; - BT_ASSERT(priv_port); - port = bt_port_borrow_from_private(priv_port); + BT_ASSERT(self_port); + port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_port)); BT_ASSERT(port); if (!bt_port_is_connected(port)) { BT_LOGD("Skipping input port: not connected: " "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"", muxer_comp, port, bt_port_get_name(port)); - bt_object_put_ref(priv_port); continue; } - bt_object_put_ref(priv_port); - muxer_notif_iter->newly_connected_priv_ports = + muxer_notif_iter->newly_connected_self_ports = g_list_append( - muxer_notif_iter->newly_connected_priv_ports, - priv_port); - if (!muxer_notif_iter->newly_connected_priv_ports) { + muxer_notif_iter->newly_connected_self_ports, + self_port); + if (!muxer_notif_iter->newly_connected_self_ports) { BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: " "port-addr=%p, port-name=\"%s\", " "muxer-notif-iter-addr=%p", port, @@ -1228,25 +1226,23 @@ end: } BT_HIDDEN -enum bt_notification_iterator_status muxer_notif_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *output_priv_port) +enum bt_self_notification_iterator_status muxer_notif_iter_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_filter *self_comp, + struct bt_self_component_port_output *port) { struct muxer_comp *muxer_comp = NULL; struct muxer_notif_iter *muxer_notif_iter = NULL; - struct bt_private_component *priv_comp = NULL; - enum bt_notification_iterator_status status = + enum bt_self_notification_iterator_status status = BT_NOTIFICATION_ITERATOR_STATUS_OK; int ret; - priv_comp = bt_private_connection_private_notification_iterator_get_private_component( - priv_notif_iter); - BT_ASSERT(priv_comp); - muxer_comp = bt_private_component_get_user_data(priv_comp); + muxer_comp = bt_self_component_get_data( + bt_self_component_filter_borrow_self_component(self_comp)); BT_ASSERT(muxer_comp); BT_LOGD("Initializing muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p", - priv_comp, muxer_comp, priv_notif_iter); + self_comp, muxer_comp, self_notif_iter); if (muxer_comp->initializing_muxer_notif_iter) { /* @@ -1256,7 +1252,7 @@ enum bt_notification_iterator_status muxer_notif_iter_init( */ BT_LOGE("Recursive initialization of muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p", - priv_comp, muxer_comp, priv_notif_iter); + self_comp, muxer_comp, self_notif_iter); goto error; } @@ -1291,18 +1287,17 @@ enum bt_notification_iterator_status muxer_notif_iter_init( BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, " "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d", - priv_comp, muxer_comp, muxer_notif_iter, - priv_notif_iter, ret); + self_comp, muxer_comp, muxer_notif_iter, + self_notif_iter, ret); goto error; } - ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, + bt_self_notification_iterator_set_data(self_notif_iter, muxer_notif_iter); - BT_ASSERT(ret == 0); BT_LOGD("Initialized muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " "notif-iter-addr=%p", - priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter); + self_comp, muxer_comp, muxer_notif_iter, self_notif_iter); goto end; error: @@ -1313,66 +1308,62 @@ error: } destroy_muxer_notif_iter(muxer_notif_iter); - ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, + bt_self_notification_iterator_set_data(self_notif_iter, NULL); - BT_ASSERT(ret == 0); status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; end: muxer_comp->initializing_muxer_notif_iter = false; - bt_object_put_ref(priv_comp); return status; } BT_HIDDEN void muxer_notif_iter_finalize( - struct bt_private_connection_private_notification_iterator *priv_notif_iter) + struct bt_self_notification_iterator *self_notif_iter) { struct muxer_notif_iter *muxer_notif_iter = - bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter); - struct bt_private_component *priv_comp = NULL; + bt_self_notification_iterator_get_data(self_notif_iter); + struct bt_self_component *self_comp = NULL; struct muxer_comp *muxer_comp = NULL; - priv_comp = bt_private_connection_private_notification_iterator_get_private_component( - priv_notif_iter); - BT_ASSERT(priv_comp); - muxer_comp = bt_private_component_get_user_data(priv_comp); + self_comp = bt_self_notification_iterator_borrow_component( + self_notif_iter); + BT_ASSERT(self_comp); + muxer_comp = bt_self_component_get_data(self_comp); BT_LOGD("Finalizing muxer component's notification iterator: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " "notif-iter-addr=%p", - priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter); + self_comp, muxer_comp, muxer_notif_iter, self_notif_iter); if (muxer_comp) { (void) g_ptr_array_remove_fast(muxer_comp->muxer_notif_iters, muxer_notif_iter); destroy_muxer_notif_iter(muxer_notif_iter); } - - bt_object_put_ref(priv_comp); } BT_HIDDEN enum bt_notification_iterator_status muxer_notif_iter_next( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { enum bt_notification_iterator_status status; struct muxer_notif_iter *muxer_notif_iter = - bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter); - struct bt_private_component *priv_comp = NULL; + bt_self_notification_iterator_get_data(self_notif_iter); + struct bt_self_component *self_comp = NULL; struct muxer_comp *muxer_comp = NULL; BT_ASSERT(muxer_notif_iter); - priv_comp = bt_private_connection_private_notification_iterator_get_private_component( - priv_notif_iter); - BT_ASSERT(priv_comp); - muxer_comp = bt_private_component_get_user_data(priv_comp); + self_comp = bt_self_notification_iterator_borrow_component( + self_notif_iter); + BT_ASSERT(self_comp); + muxer_comp = bt_self_component_get_data(self_comp); BT_ASSERT(muxer_comp); BT_LOGV("Muxer component's notification iterator's \"next\" method called: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " "notif-iter-addr=%p", - priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter); + self_comp, muxer_comp, muxer_notif_iter, self_notif_iter); status = muxer_notif_iter_do_next(muxer_comp, muxer_notif_iter, notifs, capacity, count); @@ -1380,7 +1371,7 @@ enum bt_notification_iterator_status muxer_notif_iter_next( BT_LOGE("Cannot get next notification: " "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, " "notif-iter-addr=%p, status=%s", - priv_comp, muxer_comp, muxer_notif_iter, priv_notif_iter, + self_comp, muxer_comp, muxer_notif_iter, self_notif_iter, bt_notification_iterator_status_string(status)); } else { BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: " @@ -1388,36 +1379,35 @@ enum bt_notification_iterator_status muxer_notif_iter_next( bt_notification_iterator_status_string(status)); } - bt_object_put_ref(priv_comp); return status; } BT_HIDDEN -enum bt_component_status muxer_port_connected( - struct bt_private_component *priv_comp, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +enum bt_self_component_status muxer_input_port_connected( + struct bt_self_component_filter *self_comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; - struct bt_port *self_port = - bt_port_borrow_from_private(self_private_port); + enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + struct bt_port *port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_port)); struct muxer_comp *muxer_comp = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_filter_borrow_self_component( + self_comp)); size_t i; int ret; - BT_ASSERT(self_port); + BT_ASSERT(port); BT_ASSERT(muxer_comp); BT_LOGD("Port connected: " "comp-addr=%p, muxer-comp-addr=%p, " "port-addr=%p, port-name=\"%s\", " "other-port-addr=%p, other-port-name=\"%s\"", - priv_comp, muxer_comp, self_port, bt_port_get_name(self_port), - other_port, bt_port_get_name(other_port)); - - if (bt_port_get_type(self_port) == BT_PORT_TYPE_OUTPUT) { - goto end; - } + self_comp, muxer_comp, self_port, bt_port_get_name(port), + other_port, + bt_port_get_name(bt_port_output_borrow_port(other_port))); for (i = 0; i < muxer_comp->muxer_notif_iters->len; i++) { struct muxer_notif_iter *muxer_notif_iter = @@ -1430,28 +1420,28 @@ enum bt_component_status muxer_port_connected( * muxer_notif_iter_handle_newly_connected_ports() * removes the nodes from the beginning. */ - muxer_notif_iter->newly_connected_priv_ports = + muxer_notif_iter->newly_connected_self_ports = g_list_append( - muxer_notif_iter->newly_connected_priv_ports, - self_private_port); - if (!muxer_notif_iter->newly_connected_priv_ports) { + muxer_notif_iter->newly_connected_self_ports, + self_port); + if (!muxer_notif_iter->newly_connected_self_ports) { BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: " "port-addr=%p, port-name=\"%s\", " "muxer-notif-iter-addr=%p", self_port, - bt_port_get_name(self_port), muxer_notif_iter); - status = BT_COMPONENT_STATUS_ERROR; + bt_port_get_name(port), muxer_notif_iter); + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: " "port-addr=%p, port-name=\"%s\", " "muxer-notif-iter-addr=%p", self_port, - bt_port_get_name(self_port), muxer_notif_iter); + bt_port_get_name(port), muxer_notif_iter); } /* One less available input port */ muxer_comp->available_input_ports--; - ret = ensure_available_input_port(priv_comp); + ret = ensure_available_input_port(self_comp); if (ret) { /* * Only way to report an error later since this @@ -1459,8 +1449,8 @@ enum bt_component_status muxer_port_connected( */ BT_LOGE("Cannot ensure that at least one muxer component's input port is available: " "muxer-comp-addr=%p, status=%s", - muxer_comp, bt_component_status_string(ret)); - status = BT_COMPONENT_STATUS_ERROR; + muxer_comp, bt_self_component_status_string(ret)); + status = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } @@ -1469,38 +1459,27 @@ end: } BT_HIDDEN -void muxer_port_disconnected(struct bt_private_component *priv_comp, - struct bt_private_port *priv_port) +void muxer_input_port_disconnected( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_input *self_port) { - struct bt_port *port = bt_port_borrow_from_private(priv_port); struct muxer_comp *muxer_comp = - bt_private_component_get_user_data(priv_comp); + bt_self_component_get_data( + bt_self_component_filter_borrow_self_component( + self_component)); + struct bt_port *port = + bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_port)); BT_ASSERT(port); BT_ASSERT(muxer_comp); - BT_LOGD("Port disconnected: " - "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, " - "port-name=\"%s\"", priv_comp, muxer_comp, - port, bt_port_get_name(port)); - /* - * There's nothing special to do when a port is disconnected - * because this component deals with upstream notification - * iterators which were already created thanks to connected - * ports. The fact that the port is disconnected does not cancel - * the upstream notification iterators created using its - * connection: they still exist, even if the connection is dead. - * The only way to remove an upstream notification iterator is - * for its "next" operation to return - * BT_NOTIFICATION_ITERATOR_STATUS_END. - */ - if (bt_port_get_type(port) == BT_PORT_TYPE_INPUT) { - /* One more available input port */ - muxer_comp->available_input_ports++; - BT_LOGD("Leaving disconnected input port available for future connections: " - "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, " - "port-name=\"%s\", avail-input-port-count=%zu", - priv_comp, muxer_comp, port, bt_port_get_name(port), - muxer_comp->available_input_ports); - } + /* One more available input port */ + muxer_comp->available_input_ports++; + BT_LOGD("Leaving disconnected input port available for future connections: " + "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, " + "port-name=\"%s\", avail-input-port-count=%zu", + self_component, muxer_comp, port, bt_port_get_name(port), + muxer_comp->available_input_ports); } diff --git a/plugins/utils/muxer/muxer.h b/plugins/utils/muxer/muxer.h index a55642dc..9949cbcb 100644 --- a/plugins/utils/muxer/muxer.h +++ b/plugins/utils/muxer/muxer.h @@ -25,41 +25,42 @@ */ #include +#include #include BT_HIDDEN -enum bt_component_status muxer_init( - struct bt_private_component *priv_comp, +enum bt_self_component_status muxer_init( + struct bt_self_component_filter *self_comp, struct bt_value *params, void *init_data); BT_HIDDEN -void muxer_finalize( - struct bt_private_component *priv_comp); +void muxer_finalize(struct bt_self_component_filter *self_comp); BT_HIDDEN -enum bt_notification_iterator_status muxer_notif_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *priv_port); +enum bt_self_notification_iterator_status muxer_notif_iter_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_filter *self_comp, + struct bt_self_component_port_output *self_port); BT_HIDDEN void muxer_notif_iter_finalize( - struct bt_private_connection_private_notification_iterator *priv_notif_iter); + struct bt_self_notification_iterator *self_notif_iter); BT_HIDDEN -enum bt_notification_iterator_status muxer_notif_iter_next( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, +enum bt_self_notification_iterator_status muxer_notif_iter_next( + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count); BT_HIDDEN -enum bt_component_status muxer_port_connected( - struct bt_private_component *priv_comp, - struct bt_private_port *self_private_port, - struct bt_port *other_port); +enum bt_self_component_status muxer_input_port_connected( + struct bt_self_component_filter *comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port); BT_HIDDEN -void muxer_port_disconnected( - struct bt_private_component *priv_comp, - struct bt_private_port *priv_port); +void muxer_input_port_disconnected( + struct bt_self_component_filter *self_component, + struct bt_self_component_port_input *self_port); #endif /* BABELTRACE_PLUGINS_UTILS_MUXER_H */ diff --git a/plugins/utils/plugin.c b/plugins/utils/plugin.c index 6a87a5f6..9c1d79dc 100644 --- a/plugins/utils/plugin.c +++ b/plugins/utils/plugin.c @@ -23,8 +23,6 @@ #include #include "dummy/dummy.h" #include "counter/counter.h" -#include "trimmer/trimmer.h" -#include "trimmer/iterator.h" #include "muxer/muxer.h" #ifndef BT_BUILT_IN_PLUGINS @@ -40,7 +38,7 @@ BT_PLUGIN_LICENSE("MIT"); BT_PLUGIN_SINK_COMPONENT_CLASS(dummy, dummy_consume); BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(dummy, dummy_init); BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(dummy, dummy_finalize); -BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD(dummy, +BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(dummy, dummy_port_connected); BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(dummy, "Consume notifications and discard them."); @@ -49,7 +47,7 @@ BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(dummy, BT_PLUGIN_SINK_COMPONENT_CLASS(counter, counter_consume); BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(counter, counter_init); BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(counter, counter_finalize); -BT_PLUGIN_SINK_COMPONENT_CLASS_PORT_CONNECTED_METHOD(counter, +BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(counter, counter_port_connected); BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(counter, "Count notifications and print the results."); @@ -73,10 +71,10 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(muxer, "Sort notifications from multiple input ports to a single output port by time."); BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(muxer, muxer_init); BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD(muxer, muxer_finalize); -BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_DISCONNECTED_METHOD(muxer, - muxer_port_disconnected); -BT_PLUGIN_FILTER_COMPONENT_CLASS_PORT_CONNECTED_METHOD(muxer, - muxer_port_connected); +BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(muxer, + muxer_input_port_disconnected); +BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(muxer, + muxer_input_port_connected); BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(muxer, muxer_notif_iter_init); BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(muxer, diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index f157de81..f4ee3ead 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -49,11 +49,11 @@ gboolean close_packets(gpointer key, gpointer value, gpointer user_data) } BT_HIDDEN -void trimmer_iterator_finalize(struct bt_private_connection_private_notification_iterator *it) +void trimmer_iterator_finalize(struct bt_self_notification_iterator *it) { struct trimmer_iterator *trim_it; - trim_it = bt_private_connection_private_notification_iterator_get_user_data(it); + trim_it = bt_self_notification_iterator_get_user_data(it); BT_ASSERT(trim_it); bt_object_put_ref(trim_it->input_iterator); @@ -65,7 +65,7 @@ void trimmer_iterator_finalize(struct bt_private_connection_private_notification BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_init( - struct bt_private_connection_private_notification_iterator *iterator, + struct bt_self_notification_iterator *iterator, struct bt_private_port *port) { enum bt_notification_iterator_status ret = @@ -74,8 +74,8 @@ enum bt_notification_iterator_status trimmer_iterator_init( enum bt_connection_status conn_status; struct bt_private_port *input_port = NULL; struct bt_private_connection *connection = NULL; - struct bt_private_component *component = - bt_private_connection_private_notification_iterator_get_private_component(iterator); + struct bt_self_component *component = + bt_self_notification_iterator_get_private_component(iterator); struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1); if (!it_data) { @@ -84,7 +84,7 @@ enum bt_notification_iterator_status trimmer_iterator_init( } /* Create a new iterator on the upstream component. */ - input_port = bt_private_component_filter_get_input_port_by_name( + input_port = bt_self_component_filter_get_input_port_by_name( component, "in"); BT_ASSERT(input_port); connection = bt_private_port_get_connection(input_port); @@ -101,7 +101,7 @@ enum bt_notification_iterator_status trimmer_iterator_init( it_data->packet_map = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); - it_ret = bt_private_connection_private_notification_iterator_set_user_data(iterator, + it_ret = bt_self_notification_iterator_set_user_data(iterator, it_data); if (it_ret) { goto end; @@ -557,10 +557,10 @@ enum bt_notification_iterator_status evaluate_notification( BT_HIDDEN struct bt_notification_iterator_next_method_return trimmer_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator) + struct bt_self_notification_iterator *iterator) { struct trimmer_iterator *trim_it = NULL; - struct bt_private_component *component = NULL; + struct bt_self_component *component = NULL; struct trimmer *trimmer = NULL; struct bt_notification_iterator *source_it = NULL; struct bt_notification_iterator_next_method_return ret = { @@ -569,13 +569,13 @@ struct bt_notification_iterator_next_method_return trimmer_iterator_next( }; bool notification_in_range = false; - trim_it = bt_private_connection_private_notification_iterator_get_user_data(iterator); + trim_it = bt_self_notification_iterator_get_user_data(iterator); BT_ASSERT(trim_it); - component = bt_private_connection_private_notification_iterator_get_private_component( + component = bt_self_notification_iterator_get_private_component( iterator); BT_ASSERT(component); - trimmer = bt_private_component_get_user_data(component); + trimmer = bt_self_component_get_user_data(component); BT_ASSERT(trimmer); source_it = trim_it->input_iterator; diff --git a/plugins/utils/trimmer/iterator.h b/plugins/utils/trimmer/iterator.h index 65a74f44..0d35e7e5 100644 --- a/plugins/utils/trimmer/iterator.h +++ b/plugins/utils/trimmer/iterator.h @@ -41,14 +41,14 @@ struct trimmer_iterator { BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_init( - struct bt_private_connection_private_notification_iterator *iterator, + struct bt_self_notification_iterator *iterator, struct bt_private_port *port); BT_HIDDEN -void trimmer_iterator_finalize(struct bt_private_connection_private_notification_iterator *it); +void trimmer_iterator_finalize(struct bt_self_notification_iterator *it); BT_HIDDEN struct bt_notification_iterator_next_method_return trimmer_iterator_next( - struct bt_private_connection_private_notification_iterator *iterator); + struct bt_self_notification_iterator *iterator); #endif /* BABELTRACE_PLUGIN_TRIMMER_ITERATOR_H */ diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index 0aa74758..ba4053f9 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -48,9 +48,9 @@ struct trimmer *create_trimmer_data(void) return g_new0(struct trimmer, 1); } -void finalize_trimmer(struct bt_private_component *component) +void finalize_trimmer(struct bt_self_component *component) { - void *data = bt_private_component_get_user_data(component); + void *data = bt_self_component_get_user_data(component); destroy_trimmer_data(data); } @@ -345,7 +345,7 @@ end: } enum bt_component_status trimmer_component_init( - struct bt_private_component *component, struct bt_value *params, + struct bt_self_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -357,19 +357,19 @@ enum bt_component_status trimmer_component_init( } /* Create input and output ports */ - ret = bt_private_component_filter_add_input_port( + ret = bt_self_component_filter_add_input_port( component, "in", NULL, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - ret = bt_private_component_filter_add_output_port( + ret = bt_self_component_filter_add_output_port( component, "out", NULL, NULL); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - ret = bt_private_component_set_user_data(component, trimmer); + ret = bt_self_component_set_user_data(component, trimmer); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } diff --git a/plugins/utils/trimmer/trimmer.h b/plugins/utils/trimmer/trimmer.h index 1f151cb9..6e0f609e 100644 --- a/plugins/utils/trimmer/trimmer.h +++ b/plugins/utils/trimmer/trimmer.h @@ -50,9 +50,9 @@ struct trimmer { }; enum bt_component_status trimmer_component_init( - struct bt_private_component *component, + struct bt_self_component *component, struct bt_value *params, void *init_method_data); -void finalize_trimmer(struct bt_private_component *component); +void finalize_trimmer(struct bt_self_component *component); #endif /* BABELTRACE_PLUGINS_UTILS_TRIMMER_H */ diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index 92ee2ca2..d58b8ea8 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -23,50 +23,57 @@ #include #include -static enum bt_component_status sink_consume( - struct bt_private_component *private_component) +static enum bt_self_component_status sink_consume( + struct bt_self_component_sink *self_comp) { - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } -static enum bt_notification_iterator_status dummy_iterator_init_method( - struct bt_private_connection_private_notification_iterator *private_iterator, - struct bt_private_port *private_port) +static enum bt_self_notification_iterator_status src_dummy_iterator_init_method( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port) { - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; +} + +static enum bt_self_notification_iterator_status flt_dummy_iterator_init_method( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_filter *self_comp, + struct bt_self_component_port_output *self_port) +{ + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; } static void dummy_iterator_finalize_method( - struct bt_private_connection_private_notification_iterator *private_iterator) + struct bt_self_notification_iterator *self_notif_iter) { } -static enum bt_notification_iterator_status dummy_iterator_next_method( - struct bt_private_connection_private_notification_iterator *private_iterator, +static enum bt_self_notification_iterator_status dummy_iterator_next_method( + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { - return BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; } -static struct bt_component_class_query_method_return query_method( - struct bt_component_class *component_class, +static enum bt_query_status flt_query_method( + struct bt_self_component_class_filter *component_class, struct bt_query_executor *query_exec, - const char *object, struct bt_value *params) + const char *object, struct bt_value *params, + struct bt_value **result) { - struct bt_private_value *results = bt_private_value_array_create(); - struct bt_component_class_query_method_return ret = { - .status = BT_QUERY_STATUS_OK, - .result = bt_value_borrow_from_private(results), - }; + struct bt_private_value *res = bt_private_value_array_create(); + *result = bt_private_value_borrow_value(res); int iret; - BT_ASSERT(ret.result); - iret = bt_private_value_array_append_string_element(results, object); + BT_ASSERT(*result); + iret = bt_private_value_array_append_string_element(res, object); BT_ASSERT(iret == 0); - iret = bt_private_value_array_append_element(results, params); + iret = bt_private_value_array_append_element(res, params); BT_ASSERT(iret == 0); - return ret; + return BT_QUERY_STATUS_OK; } BT_PLUGIN_MODULE(); @@ -79,7 +86,7 @@ BT_PLUGIN_VERSION(1, 2, 3, "yes"); BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_iterator_next_method); BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(source, "A source."); BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(source, - dummy_iterator_init_method); + src_dummy_iterator_init_method); BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(source, dummy_iterator_finalize_method); @@ -95,7 +102,7 @@ BT_PLUGIN_SINK_COMPONENT_CLASS_HELP(sink, BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_iterator_next_method); BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(filter, "A filter."); BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(filter, - dummy_iterator_init_method); + flt_dummy_iterator_init_method); BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(filter, dummy_iterator_finalize_method); -BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD(filter, query_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS_QUERY_METHOD(filter, flt_query_method); diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 828b11a4..e90ad648 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -55,7 +55,6 @@ static bool debug = false; static enum test current_test; static GArray *test_events; static struct bt_private_graph *graph; -static struct bt_private_connection_private_notification_iterator *cur_notif_iter; static struct bt_private_stream_class *src_stream_class; static struct bt_private_event_class *src_event_class; static struct bt_private_stream *src_stream1; @@ -97,7 +96,7 @@ struct src_iter_user_data { }; struct sink_user_data { - struct bt_notification_iterator *notif_iter; + void *notif_iter; }; /* @@ -263,25 +262,25 @@ void init_static_data(void) BT_ASSERT(src_event_class); src_stream1 = bt_private_stream_create(src_stream_class); BT_ASSERT(src_stream1); - pub_src_stream1 = bt_stream_borrow_from_private(src_stream1); + pub_src_stream1 = bt_private_stream_borrow_stream(src_stream1); src_stream2 = bt_private_stream_create(src_stream_class); BT_ASSERT(src_stream2); - pub_src_stream2 = bt_stream_borrow_from_private(src_stream2); + pub_src_stream2 = bt_private_stream_borrow_stream(src_stream2); src_stream1_packet1 = bt_private_packet_create(src_stream1); BT_ASSERT(src_stream1_packet1); - pub_src_stream1_packet1 = bt_packet_borrow_from_private( + pub_src_stream1_packet1 = bt_private_packet_borrow_packet( src_stream1_packet1); src_stream1_packet2 = bt_private_packet_create(src_stream1); BT_ASSERT(src_stream1_packet2); - pub_src_stream1_packet2 = bt_packet_borrow_from_private( + pub_src_stream1_packet2 = bt_private_packet_borrow_packet( src_stream1_packet2); src_stream2_packet1 = bt_private_packet_create(src_stream2); BT_ASSERT(src_stream2_packet1); - pub_src_stream2_packet1 = bt_packet_borrow_from_private( + pub_src_stream2_packet1 = bt_private_packet_borrow_packet( src_stream2_packet1); src_stream2_packet2 = bt_private_packet_create(src_stream2); BT_ASSERT(src_stream2_packet2); - pub_src_stream2_packet2 = bt_packet_borrow_from_private( + pub_src_stream2_packet2 = bt_private_packet_borrow_packet( src_stream2_packet2); if (debug) { @@ -314,12 +313,11 @@ void fini_static_data(void) } static -void src_iter_finalize( - struct bt_private_connection_private_notification_iterator *private_notification_iterator) +void src_iter_finalize(struct bt_self_notification_iterator *self_notif_iter) { struct src_iter_user_data *user_data = - bt_private_connection_private_notification_iterator_get_user_data( - private_notification_iterator); + bt_self_notification_iterator_get_data( + self_notif_iter); if (user_data) { g_free(user_data); @@ -327,18 +325,16 @@ void src_iter_finalize( } static -enum bt_notification_iterator_status src_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *private_port) +enum bt_self_notification_iterator_status src_iter_init( + struct bt_self_notification_iterator *self_notif_iter, + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_port) { struct src_iter_user_data *user_data = g_new0(struct src_iter_user_data, 1); - int ret; BT_ASSERT(user_data); - ret = bt_private_connection_private_notification_iterator_set_user_data( - priv_notif_iter, user_data); - BT_ASSERT(ret == 0); + bt_self_notification_iterator_set_data(self_notif_iter, user_data); switch (current_test) { case TEST_NO_AUTO_NOTIFS: @@ -349,75 +345,76 @@ enum bt_notification_iterator_status src_iter_init( abort(); } - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; } static -void src_iter_next_seq_one(struct src_iter_user_data *user_data, +void src_iter_next_seq_one(struct bt_self_notification_iterator* notif_iter, + struct src_iter_user_data *user_data, struct bt_notification **notif) { struct bt_private_packet *event_packet = NULL; switch (user_data->seq[user_data->at]) { case SEQ_STREAM1_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_stream_begin_create( - cur_notif_iter, src_stream1)); + notif_iter, src_stream1)); break; case SEQ_STREAM2_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_stream_begin_create( - cur_notif_iter, src_stream2)); + notif_iter, src_stream2)); break; case SEQ_STREAM1_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_stream_end_create( - cur_notif_iter, src_stream1)); + notif_iter, src_stream1)); break; case SEQ_STREAM2_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_stream_end_create( - cur_notif_iter, src_stream2)); + notif_iter, src_stream2)); break; case SEQ_STREAM1_PACKET1_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_begin_create( - cur_notif_iter, src_stream1_packet1)); + notif_iter, src_stream1_packet1)); break; case SEQ_STREAM1_PACKET2_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_begin_create( - cur_notif_iter, src_stream1_packet2)); + notif_iter, src_stream1_packet2)); break; case SEQ_STREAM2_PACKET1_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_begin_create( - cur_notif_iter, src_stream2_packet1)); + notif_iter, src_stream2_packet1)); break; case SEQ_STREAM2_PACKET2_BEGIN: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_begin_create( - cur_notif_iter, src_stream2_packet2)); + notif_iter, src_stream2_packet2)); break; case SEQ_STREAM1_PACKET1_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_end_create( - cur_notif_iter, src_stream1_packet1)); + notif_iter, src_stream1_packet1)); break; case SEQ_STREAM1_PACKET2_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_end_create( - cur_notif_iter, src_stream1_packet2)); + notif_iter, src_stream1_packet2)); break; case SEQ_STREAM2_PACKET1_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_end_create( - cur_notif_iter, src_stream2_packet1)); + notif_iter, src_stream2_packet1)); break; case SEQ_STREAM2_PACKET2_END: - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_packet_end_create( - cur_notif_iter, src_stream2_packet2)); + notif_iter, src_stream2_packet2)); break; case SEQ_EVENT_STREAM1_PACKET1: event_packet = src_stream1_packet1; @@ -436,9 +433,9 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data, } if (event_packet) { - *notif = bt_notification_borrow_from_private( + *notif = bt_private_notification_borrow_notification( bt_private_notification_event_create( - cur_notif_iter, src_event_class, event_packet)); + notif_iter, src_event_class, event_packet)); } BT_ASSERT(*notif); @@ -446,24 +443,25 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data, } static -enum bt_notification_iterator_status src_iter_next_seq( +enum bt_self_notification_iterator_status src_iter_next_seq( + struct bt_self_notification_iterator *notif_iter, struct src_iter_user_data *user_data, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { - enum bt_notification_iterator_status status = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; uint64_t i = 0; BT_ASSERT(user_data->seq); if (user_data->seq[user_data->at] == SEQ_END) { - status = BT_NOTIFICATION_ITERATOR_STATUS_END; + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_END; goto end; } while (i < capacity && user_data->seq[user_data->at] != SEQ_END) { - src_iter_next_seq_one(user_data, ¬ifs[i]); + src_iter_next_seq_one(notif_iter, user_data, ¬ifs[i]); i++; } @@ -475,34 +473,34 @@ end: } static -enum bt_notification_iterator_status src_iter_next( - struct bt_private_connection_private_notification_iterator *priv_iterator, +enum bt_self_notification_iterator_status src_iter_next( + struct bt_self_notification_iterator *self_notif_iter, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { struct src_iter_user_data *user_data = - bt_private_connection_private_notification_iterator_get_user_data(priv_iterator); + bt_self_notification_iterator_get_data(self_notif_iter); BT_ASSERT(user_data); - cur_notif_iter = priv_iterator; - return src_iter_next_seq(user_data, notifs, capacity, count); + return src_iter_next_seq(self_notif_iter, user_data, notifs, + capacity, count); } static -enum bt_component_status src_init( - struct bt_private_component *private_component, +enum bt_self_component_status src_init( + struct bt_self_component_source *self_comp, struct bt_value *params, void *init_method_data) { int ret; - ret = bt_private_component_source_add_output_port( - private_component, "out", NULL, NULL); + ret = bt_self_component_source_add_output_port( + self_comp, "out", NULL, NULL); BT_ASSERT(ret == 0); - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -void src_finalize(struct bt_private_component *private_component) +void src_finalize(struct bt_self_component_source *self_comp) { } @@ -562,8 +560,7 @@ void append_test_events_from_notification(struct bt_notification *notification) static enum bt_notification_iterator_status common_consume( - struct bt_notification_iterator *notif_iter, - bool is_output_port_notif_iter) + void *notif_iter, bool is_output_port_notif_iter) { enum bt_notification_iterator_status ret; bt_notification_array notifications = NULL; @@ -574,10 +571,10 @@ enum bt_notification_iterator_status common_consume( BT_ASSERT(notif_iter); if (is_output_port_notif_iter) { - ret = bt_output_port_notification_iterator_next(notif_iter, + ret = bt_port_output_notification_iterator_next(notif_iter, ¬ifications, &count); } else { - ret = bt_private_connection_notification_iterator_next( + ret = bt_self_component_port_input_notification_iterator_next( notif_iter, ¬ifications, &count); } @@ -609,25 +606,27 @@ end: } static -enum bt_component_status sink_consume( - struct bt_private_component *priv_component) +enum bt_self_component_status sink_consume( + struct bt_self_component_sink *self_comp) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; struct sink_user_data *user_data = - bt_private_component_get_user_data(priv_component); + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component( + self_comp)); enum bt_notification_iterator_status it_ret; BT_ASSERT(user_data && user_data->notif_iter); it_ret = common_consume(user_data->notif_iter, false); if (it_ret < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_COMPONENT_STATUS_ERROR; goto end; } switch (it_ret) { case BT_NOTIFICATION_ITERATOR_STATUS_END: - ret = BT_COMPONENT_STATUS_END; + ret = BT_SELF_COMPONENT_STATUS_END; BT_OBJECT_PUT_REF_AND_RESET(user_data->notif_iter); goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: @@ -641,49 +640,48 @@ end: } static -enum bt_component_status sink_port_connected( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +enum bt_self_component_status sink_port_connected( + struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_port, + struct bt_port_output *other_port) { - struct bt_private_connection *priv_conn = - bt_private_port_get_connection(self_private_port); - struct sink_user_data *user_data = bt_private_component_get_user_data( - private_component); - enum bt_connection_status conn_status; + struct sink_user_data *user_data = + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component( + self_comp)); BT_ASSERT(user_data); - BT_ASSERT(priv_conn); - conn_status = bt_private_connection_create_notification_iterator( - priv_conn, &user_data->notif_iter); - BT_ASSERT(conn_status == 0); - bt_object_put_ref(priv_conn); - return BT_COMPONENT_STATUS_OK; + user_data->notif_iter = + bt_self_component_port_input_notification_iterator_create( + self_port); + return BT_SELF_COMPONENT_STATUS_OK; } static -enum bt_component_status sink_init( - struct bt_private_component *private_component, +enum bt_self_component_status sink_init( + struct bt_self_component_sink *self_comp, struct bt_value *params, void *init_method_data) { struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); int ret; BT_ASSERT(user_data); - ret = bt_private_component_set_user_data(private_component, + bt_self_component_set_data( + bt_self_component_sink_borrow_self_component(self_comp), user_data); + ret = bt_self_component_sink_add_input_port( + self_comp, "in", NULL, NULL); BT_ASSERT(ret == 0); - ret = bt_private_component_sink_add_input_port( - private_component, "in", NULL, NULL); - BT_ASSERT(ret == 0); - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -void sink_finalize(struct bt_private_component *private_component) +void sink_finalize(struct bt_self_component_sink *self_comp) { - struct sink_user_data *user_data = bt_private_component_get_user_data( - private_component); + struct sink_user_data *user_data = + bt_self_component_get_data( + bt_self_component_sink_borrow_self_component( + self_comp)); if (user_data) { bt_object_put_ref(user_data->notif_iter); @@ -692,51 +690,55 @@ void sink_finalize(struct bt_private_component *private_component) } static -void create_source_sink(struct bt_private_graph *graph, struct bt_component **source, - struct bt_component **sink) +void create_source_sink(struct bt_private_graph *graph, + struct bt_component_source **source, + struct bt_component_sink **sink) { - struct bt_component_class *src_comp_class; - struct bt_component_class *sink_comp_class; + struct bt_private_component_class_source *src_comp_class; + struct bt_private_component_class_sink *sink_comp_class; int ret; /* Create source component */ if (source) { - src_comp_class = bt_component_class_source_create("src", + src_comp_class = bt_private_component_class_source_create("src", src_iter_next); BT_ASSERT(src_comp_class); - ret = bt_component_class_set_init_method(src_comp_class, - src_init); + ret = bt_private_component_class_source_set_init_method( + src_comp_class, src_init); BT_ASSERT(ret == 0); - ret = bt_component_class_set_finalize_method(src_comp_class, - src_finalize); + ret = bt_private_component_class_source_set_finalize_method( + src_comp_class, src_finalize); BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_notification_iterator_init_method( + ret = bt_private_component_class_source_set_notification_iterator_init_method( src_comp_class, src_iter_init); BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_notification_iterator_finalize_method( + ret = bt_private_component_class_source_set_notification_iterator_finalize_method( src_comp_class, src_iter_finalize); BT_ASSERT(ret == 0); - ret = bt_private_graph_add_component(graph, src_comp_class, "source", - NULL, source); + ret = bt_private_graph_add_source_component(graph, + bt_private_component_class_source_borrow_component_class_source( + src_comp_class), "source", NULL, source); BT_ASSERT(ret == 0); bt_object_put_ref(src_comp_class); } /* Create sink component */ if (sink) { - sink_comp_class = bt_component_class_sink_create("sink", + sink_comp_class = bt_private_component_class_sink_create("sink", sink_consume); BT_ASSERT(sink_comp_class); - ret = bt_component_class_set_init_method(sink_comp_class, - sink_init); + ret = bt_private_component_class_sink_set_init_method( + sink_comp_class, sink_init); BT_ASSERT(ret == 0); - ret = bt_component_class_set_finalize_method(sink_comp_class, - sink_finalize); - ret = bt_component_class_set_port_connected_method( + ret = bt_private_component_class_sink_set_finalize_method( + sink_comp_class, sink_finalize); + ret = bt_private_component_class_sink_set_input_port_connected_method( sink_comp_class, sink_port_connected); BT_ASSERT(ret == 0); - ret = bt_private_graph_add_component(graph, sink_comp_class, "sink", - NULL, sink); + ret = bt_private_graph_add_sink_component(graph, + bt_private_component_class_sink_borrow_component_class_sink( + sink_comp_class), + "sink", NULL, sink); BT_ASSERT(ret == 0); bt_object_put_ref(sink_comp_class); } @@ -746,10 +748,10 @@ static void do_std_test(enum test test, const char *name, const struct test_event *expected_test_events) { - struct bt_component *src_comp; - struct bt_component *sink_comp; - struct bt_port *upstream_port; - struct bt_port *downstream_port; + struct bt_component_source *src_comp; + struct bt_component_sink *sink_comp; + struct bt_port_output *upstream_port; + struct bt_port_input *downstream_port; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; clear_test_events(); @@ -761,14 +763,14 @@ void do_std_test(enum test test, const char *name, create_source_sink(graph, &src_comp, &sink_comp); /* Connect source to sink */ - upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out"); + upstream_port = bt_component_source_borrow_output_port_by_name( + src_comp, "out"); BT_ASSERT(upstream_port); - downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); + downstream_port = bt_component_sink_borrow_input_port_by_name( + sink_comp, "in"); BT_ASSERT(downstream_port); graph_status = bt_private_graph_connect_ports(graph, upstream_port, downstream_port, NULL); - bt_object_put_ref(upstream_port); - bt_object_put_ref(downstream_port); /* Run the graph until the end */ while (graph_status == BT_GRAPH_STATUS_OK || @@ -776,7 +778,8 @@ void do_std_test(enum test test, const char *name, graph_status = bt_private_graph_run(graph); } - ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); + ok(graph_status == BT_GRAPH_STATUS_END, + "graph finishes without any error"); /* Compare the resulting test events */ if (expected_test_events) { @@ -840,11 +843,11 @@ void test_output_port_notification_iterator(void) { .type = TEST_EV_TYPE_END, }, { .type = TEST_EV_TYPE_SENTINEL, }, }; - struct bt_component *src_comp; - struct bt_notification_iterator *notif_iter; + struct bt_component_source *src_comp; + struct bt_port_output_notification_iterator *notif_iter; enum bt_notification_iterator_status iter_status = BT_NOTIFICATION_ITERATOR_STATUS_OK; - struct bt_port *upstream_port; + struct bt_port_output *upstream_port; clear_test_events(); current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; @@ -855,11 +858,11 @@ void test_output_port_notification_iterator(void) create_source_sink(graph, &src_comp, NULL); /* Create notification iterator on source's output port */ - upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out"); - notif_iter = bt_output_port_notification_iterator_create(upstream_port, - NULL); + upstream_port = bt_component_source_borrow_output_port_by_name( + src_comp, "out"); + notif_iter = bt_port_output_notification_iterator_create(graph, + upstream_port, NULL); ok(notif_iter, "bt_private_output_port_notification_iterator_create() succeeds"); - bt_object_put_ref(upstream_port); /* Consume the notification iterator */ while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index 629982aa..796cb582 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -49,7 +49,7 @@ void test_bool(void) struct bt_value *obj; priv_obj = bt_private_value_bool_create(); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_bool(obj), "bt_private_value_bool_create() returns a boolean value object"); @@ -67,7 +67,7 @@ void test_bool(void) value = BT_FALSE; priv_obj = bt_private_value_bool_create_init(BT_TRUE); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_bool(obj), "bt_private_value_bool_create_init() returns a boolean value object"); value = bt_value_bool_get(obj); @@ -85,7 +85,7 @@ void test_integer(void) struct bt_value *obj; priv_obj = bt_private_value_integer_create(); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_integer(obj), "bt_private_value_integer_create() returns an integer value object"); @@ -101,7 +101,7 @@ void test_integer(void) pass("putting an existing integer value object does not cause a crash") priv_obj = bt_private_value_integer_create_init(321456987); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_integer(obj), "bt_private_value_integer_create_init() returns an integer value object"); value = bt_value_integer_get(obj); @@ -119,7 +119,7 @@ void test_real(void) struct bt_value *obj; priv_obj = bt_private_value_real_create(); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_real(obj), "bt_private_value_real_create() returns a real number value object"); @@ -136,7 +136,7 @@ void test_real(void) pass("putting an existing real number value object does not cause a crash") priv_obj = bt_private_value_real_create_init(33.1649758); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_real(obj), "bt_private_value_real_create_init() returns a real number value object"); value = bt_value_real_get(obj); @@ -154,7 +154,7 @@ void test_string(void) struct bt_value *obj; priv_obj = bt_private_value_string_create(); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_string(obj), "bt_private_value_string_create() returns a string value object"); @@ -171,7 +171,7 @@ void test_string(void) pass("putting an existing string value object does not cause a crash") priv_obj = bt_private_value_string_create_init("initial value"); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ok(obj && bt_value_is_string(obj), "bt_private_value_string_create_init() returns a string value object"); value = bt_value_string_get(obj); @@ -195,22 +195,22 @@ void test_array(void) struct bt_value *array_obj; priv_array_obj = bt_private_value_array_create(); - array_obj = bt_value_borrow_from_private(priv_array_obj); + array_obj = bt_private_value_borrow_value(priv_array_obj); ok(array_obj && bt_value_is_array(array_obj), "bt_private_value_array_create() returns an array value object"); ok(bt_value_array_is_empty(array_obj), "initial array value object size is 0"); priv_obj = bt_private_value_integer_create_init(345); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret = bt_private_value_array_append_element(priv_array_obj, obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); priv_obj = bt_private_value_real_create_init(-17.45); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret |= bt_private_value_array_append_element(priv_array_obj, obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); priv_obj = bt_private_value_bool_create_init(BT_TRUE); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret |= bt_private_value_array_append_element(priv_array_obj, obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); ret |= bt_private_value_array_append_element(priv_array_obj, @@ -242,7 +242,7 @@ void test_array(void) "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)"); priv_obj = bt_private_value_integer_create_init(1001); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); BT_ASSERT(obj); ok(!bt_private_value_array_set_element_by_index(priv_array_obj, 2, obj), "bt_value_array_set_element_by_index() succeeds"); @@ -503,22 +503,22 @@ void test_map(void) struct map_foreach_checklist checklist; priv_map_obj = bt_private_value_map_create(); - map_obj = bt_value_borrow_from_private(priv_map_obj); + map_obj = bt_private_value_borrow_value(priv_map_obj); ok(map_obj && bt_value_is_map(map_obj), "bt_private_value_map_create() returns a map value object"); ok(bt_value_map_get_size(map_obj) == 0, "initial map value object size is 0"); priv_obj = bt_private_value_integer_create_init(19457); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret = bt_private_value_map_insert_entry(priv_map_obj, "int", obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); priv_obj = bt_private_value_real_create_init(5.444); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret |= bt_private_value_map_insert_entry(priv_map_obj, "real", obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); priv_obj = bt_private_value_bool_create(); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret |= bt_private_value_map_insert_entry(priv_map_obj, "bt_bool", obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); ret |= bt_private_value_map_insert_entry(priv_map_obj, "null", @@ -528,7 +528,7 @@ void test_map(void) "inserting an element into a map value object increment its size"); priv_obj = bt_private_value_bool_create_init(BT_TRUE); - obj = bt_value_borrow_from_private(priv_obj); + obj = bt_private_value_borrow_value(priv_obj); ret = bt_private_value_map_insert_entry(priv_map_obj, "bt_bool", obj); BT_OBJECT_PUT_REF_AND_RESET(priv_obj); ok(!ret, "bt_private_value_map_insert_entry() accepts an existing key"); @@ -652,13 +652,13 @@ void test_compare_bool(void) BT_ASSERT(bool1 && bool2 && bool3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(bool1)), + bt_private_value_borrow_value(bool1)), "cannot compare null value object and bt_bool value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(bool1), - bt_value_borrow_from_private(bool2)), + ok(!bt_value_compare(bt_private_value_borrow_value(bool1), + bt_private_value_borrow_value(bool2)), "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)"); - ok(bt_value_compare(bt_value_borrow_from_private(bool1), - bt_value_borrow_from_private(bool3)), + ok(bt_value_compare(bt_private_value_borrow_value(bool1), + bt_private_value_borrow_value(bool3)), "boolean value objects are equivalent (BT_FALSE and BT_FALSE)"); BT_OBJECT_PUT_REF_AND_RESET(bool1); @@ -678,13 +678,13 @@ void test_compare_integer(void) BT_ASSERT(int1 && int2 && int3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(int1)), + bt_private_value_borrow_value(int1)), "cannot compare null value object and integer value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(int1), - bt_value_borrow_from_private(int2)), + ok(!bt_value_compare(bt_private_value_borrow_value(int1), + bt_private_value_borrow_value(int2)), "integer value objects are not equivalent (10 and -23)"); - ok(bt_value_compare(bt_value_borrow_from_private(int1), - bt_value_borrow_from_private(int3)), + ok(bt_value_compare(bt_private_value_borrow_value(int1), + bt_private_value_borrow_value(int3)), "integer value objects are equivalent (10 and 10)"); BT_OBJECT_PUT_REF_AND_RESET(int1); @@ -705,13 +705,13 @@ void test_compare_real(void) BT_ASSERT(real1 && real2 && real3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(real1)), + bt_private_value_borrow_value(real1)), "cannot compare null value object and real number value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(real1), - bt_value_borrow_from_private(real2)), + ok(!bt_value_compare(bt_private_value_borrow_value(real1), + bt_private_value_borrow_value(real2)), "real number value objects are not equivalent (17.38 and -14.23)"); - ok(bt_value_compare(bt_value_borrow_from_private(real1), - bt_value_borrow_from_private(real3)), + ok(bt_value_compare(bt_private_value_borrow_value(real1), + bt_private_value_borrow_value(real3)), "real number value objects are equivalent (17.38 and 17.38)"); BT_OBJECT_PUT_REF_AND_RESET(real1); @@ -732,13 +732,13 @@ void test_compare_string(void) BT_ASSERT(string1 && string2 && string3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(string1)), + bt_private_value_borrow_value(string1)), "cannot compare null value object and string value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(string1), - bt_value_borrow_from_private(string2)), + ok(!bt_value_compare(bt_private_value_borrow_value(string1), + bt_private_value_borrow_value(string2)), "string value objects are not equivalent (\"hello\" and \"bt_value\")"); - ok(bt_value_compare(bt_value_borrow_from_private(string1), - bt_value_borrow_from_private(string3)), + ok(bt_value_compare(bt_private_value_borrow_value(string1), + bt_private_value_borrow_value(string3)), "string value objects are equivalent (\"hello\" and \"hello\")"); BT_OBJECT_PUT_REF_AND_RESET(string1); @@ -756,8 +756,8 @@ void test_compare_array(void) BT_ASSERT(array1 && array2 && array3); - ok(bt_value_compare(bt_value_borrow_from_private(array1), - bt_value_borrow_from_private(array2)), + ok(bt_value_compare(bt_private_value_borrow_value(array1), + bt_private_value_borrow_value(array2)), "empty array value objects are equivalent"); status = bt_private_value_array_append_integer_element(array1, 23); @@ -779,20 +779,20 @@ void test_compare_array(void) status = bt_private_value_array_append_bool_element(array3, BT_FALSE); BT_ASSERT(status == BT_VALUE_STATUS_OK); BT_ASSERT(bt_value_array_get_size( - bt_value_borrow_from_private(array1)) == 3); + bt_private_value_borrow_value(array1)) == 3); BT_ASSERT(bt_value_array_get_size( - bt_value_borrow_from_private(array2)) == 3); + bt_private_value_borrow_value(array2)) == 3); BT_ASSERT(bt_value_array_get_size( - bt_value_borrow_from_private(array3)) == 3); + bt_private_value_borrow_value(array3)) == 3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(array1)), + bt_private_value_borrow_value(array1)), "cannot compare null value object and array value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(array1), - bt_value_borrow_from_private(array2)), + ok(!bt_value_compare(bt_private_value_borrow_value(array1), + bt_private_value_borrow_value(array2)), "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])"); - ok(bt_value_compare(bt_value_borrow_from_private(array1), - bt_value_borrow_from_private(array3)), + ok(bt_value_compare(bt_private_value_borrow_value(array1), + bt_private_value_borrow_value(array3)), "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])"); BT_OBJECT_PUT_REF_AND_RESET(array1); @@ -810,8 +810,8 @@ void test_compare_map(void) BT_ASSERT(map1 && map2 && map3); - ok(bt_value_compare(bt_value_borrow_from_private(map1), - bt_value_borrow_from_private(map2)), + ok(bt_value_compare(bt_private_value_borrow_value(map1), + bt_private_value_borrow_value(map2)), "empty map value objects are equivalent"); @@ -837,20 +837,20 @@ void test_compare_map(void) status = bt_private_value_map_insert_real_entry(map3, "two", 14.2); BT_ASSERT(status == BT_VALUE_STATUS_OK); BT_ASSERT(bt_value_map_get_size( - bt_value_borrow_from_private(map1)) == 3); + bt_private_value_borrow_value(map1)) == 3); BT_ASSERT(bt_value_map_get_size( - bt_value_borrow_from_private(map2)) == 3); + bt_private_value_borrow_value(map2)) == 3); BT_ASSERT(bt_value_map_get_size( - bt_value_borrow_from_private(map3)) == 3); + bt_private_value_borrow_value(map3)) == 3); ok(!bt_value_compare(bt_value_null, - bt_value_borrow_from_private(map1)), + bt_private_value_borrow_value(map1)), "cannot compare null value object and map value object"); - ok(!bt_value_compare(bt_value_borrow_from_private(map1), - bt_value_borrow_from_private(map2)), + ok(!bt_value_compare(bt_private_value_borrow_value(map1), + bt_private_value_borrow_value(map2)), "map value objects are not equivalent"); - ok(bt_value_compare(bt_value_borrow_from_private(map1), - bt_value_borrow_from_private(map3)), + ok(bt_value_compare(bt_private_value_borrow_value(map1), + bt_private_value_borrow_value(map3)), "map value objects are equivalent"); BT_OBJECT_PUT_REF_AND_RESET(map1); @@ -901,26 +901,26 @@ void test_copy(void) array_obj && map_obj); status = bt_private_value_array_append_element(array_obj, - bt_value_borrow_from_private(bool_obj)); + bt_private_value_borrow_value(bool_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_private_value_array_append_element(array_obj, - bt_value_borrow_from_private(integer_obj)); + bt_private_value_borrow_value(integer_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_private_value_array_append_element(array_obj, - bt_value_borrow_from_private(real_obj)); + bt_private_value_borrow_value(real_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_private_value_array_append_element(array_obj, bt_value_null); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_private_value_map_insert_entry(map_obj, "array", - bt_value_borrow_from_private(array_obj)); + bt_private_value_borrow_value(array_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_private_value_map_insert_entry(map_obj, "string", - bt_value_borrow_from_private(string_obj)); + bt_private_value_borrow_value(string_obj)); BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_value_copy(&map_copy_obj, - bt_value_borrow_from_private(map_obj)); + bt_private_value_borrow_value(map_obj)); ok(status == BT_VALUE_STATUS_OK && map_copy_obj, "bt_value_copy() succeeds"); @@ -948,11 +948,11 @@ void test_copy(void) "bt_value_copy() returns a different pointer (real)"); null_copy_obj = bt_private_value_array_borrow_element_by_index( array_copy_obj, 3); - ok(bt_value_borrow_from_private(null_copy_obj) == bt_value_null, + ok(bt_private_value_borrow_value(null_copy_obj) == bt_value_null, "bt_value_copy() returns the same pointer (null)"); - ok(bt_value_compare(bt_value_borrow_from_private(map_obj), - bt_value_borrow_from_private(map_copy_obj)), + ok(bt_value_compare(bt_private_value_borrow_value(map_obj), + bt_private_value_borrow_value(map_copy_obj)), "source and destination value objects have the same content"); BT_OBJECT_PUT_REF_AND_RESET(map_copy_obj); @@ -1013,27 +1013,27 @@ void test_extend(void) BT_ASSERT(status == BT_VALUE_STATUS_OK); status = bt_value_map_extend( &extended_map, - bt_value_borrow_from_private(base_map), - bt_value_borrow_from_private(extension_map)); + bt_private_value_borrow_value(base_map), + bt_private_value_borrow_value(extension_map)); ok(status == BT_VALUE_STATUS_OK && extended_map, "bt_value_map_extend() succeeds"); ok(bt_value_map_get_size( - bt_value_borrow_from_private(extended_map)) == 5, + bt_private_value_borrow_value(extended_map)) == 5, "bt_value_map_extend() returns a map object with the correct size"); - ok(compare_map_elements(bt_value_borrow_from_private(base_map), - bt_value_borrow_from_private(extended_map), "file"), + ok(compare_map_elements(bt_private_value_borrow_value(base_map), + bt_private_value_borrow_value(extended_map), "file"), "bt_value_map_extend() picks the appropriate element (file)"); - ok(compare_map_elements(bt_value_borrow_from_private(extension_map), - bt_value_borrow_from_private(extended_map), "edit"), + ok(compare_map_elements(bt_private_value_borrow_value(extension_map), + bt_private_value_borrow_value(extended_map), "edit"), "bt_value_map_extend() picks the appropriate element (edit)"); - ok(compare_map_elements(bt_value_borrow_from_private(base_map), - bt_value_borrow_from_private(extended_map), "selection"), + ok(compare_map_elements(bt_private_value_borrow_value(base_map), + bt_private_value_borrow_value(extended_map), "selection"), "bt_value_map_extend() picks the appropriate element (selection)"); - ok(compare_map_elements(bt_value_borrow_from_private(extension_map), - bt_value_borrow_from_private(extended_map), "find"), + ok(compare_map_elements(bt_private_value_borrow_value(extension_map), + bt_private_value_borrow_value(extended_map), "find"), "bt_value_map_extend() picks the appropriate element (find)"); - ok(compare_map_elements(bt_value_borrow_from_private(extension_map), - bt_value_borrow_from_private(extended_map), "project"), + ok(compare_map_elements(bt_private_value_borrow_value(extension_map), + bt_private_value_borrow_value(extended_map), "project"), "bt_value_map_extend() picks the appropriate element (project)"); BT_OBJECT_PUT_REF_AND_RESET(array); diff --git a/tests/lib/test_graph_topo.c b/tests/lib/test_graph_topo.c index b57d644f..25845292 100644 --- a/tests/lib/test_graph_topo.c +++ b/tests/lib/test_graph_topo.c @@ -17,26 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include -#include #include #include "tap/tap.h" @@ -44,13 +29,18 @@ #define NR_TESTS 99 enum event_type { - COMP_ACCEPT_PORT_CONNECTION, - COMP_PORT_CONNECTED, - COMP_PORT_DISCONNECTED, - GRAPH_PORT_ADDED, - GRAPH_PORT_REMOVED, - GRAPH_PORTS_CONNECTED, - GRAPH_PORTS_DISCONNECTED, + SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, + SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, + SRC_COMP_OUTPUT_PORT_CONNECTED, + SINK_COMP_INPUT_PORT_CONNECTED, + SRC_COMP_OUTPUT_PORT_DISCONNECTED, + SINK_COMP_INPUT_PORT_DISCONNECTED, + GRAPH_SRC_OUTPUT_PORT_ADDED, + GRAPH_SINK_INPUT_PORT_ADDED, + GRAPH_SRC_OUTPUT_PORT_REMOVED, + GRAPH_SINK_INPUT_PORT_REMOVED, + GRAPH_SRC_SINK_PORTS_CONNECTED, + GRAPH_SRC_SINK_PORTS_DISCONNECTED, }; enum test { @@ -71,49 +61,75 @@ struct event { struct bt_component *comp; struct bt_port *self_port; struct bt_port *other_port; - } comp_accept_port_connection; + } src_comp_accept_output_port_connection; + + struct { + struct bt_component *comp; + struct bt_port *self_port; + struct bt_port *other_port; + } sink_comp_accept_input_port_connection; + + struct { + struct bt_component *comp; + struct bt_port *self_port; + struct bt_port *other_port; + } src_comp_output_port_connected; struct { struct bt_component *comp; struct bt_port *self_port; struct bt_port *other_port; - } comp_port_connected; + } sink_comp_input_port_connected; + + struct { + struct bt_component *comp; + struct bt_port *self_port; + } src_comp_output_port_disconnected; + + struct { + struct bt_component *comp; + struct bt_port *self_port; + } sink_comp_input_port_disconnected; struct { struct bt_component *comp; struct bt_port *port; - } comp_port_disconnected; + } graph_src_output_port_added; struct { struct bt_component *comp; struct bt_port *port; - } graph_port_added; + } graph_sink_input_port_added; struct { struct bt_component *comp; struct bt_port *port; - } graph_port_removed; + } graph_src_output_port_removed; + + struct { + struct bt_component *comp; + struct bt_port *port; + } graph_sink_input_port_removed; struct { struct bt_component *upstream_comp; struct bt_component *downstream_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - struct bt_connection *conn; - } graph_ports_connected; + } graph_src_sink_ports_connected; struct { struct bt_component *upstream_comp; struct bt_component *downstream_comp; struct bt_port *upstream_port; struct bt_port *downstream_port; - } graph_ports_disconnected; + } graph_src_sink_ports_disconnected; } data; }; static GArray *events; -static struct bt_component_class *src_comp_class; -static struct bt_component_class *sink_comp_class; +static struct bt_private_component_class_source *src_comp_class; +static struct bt_private_component_class_sink *sink_comp_class; static enum test current_test; static @@ -136,115 +152,175 @@ bool compare_events(struct event *ev_a, struct event *ev_b) } switch (ev_a->type) { - case COMP_ACCEPT_PORT_CONNECTION: - if (ev_a->data.comp_accept_port_connection.comp != - ev_b->data.comp_accept_port_connection.comp) { + case SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION: + if (ev_a->data.src_comp_accept_output_port_connection.comp != + ev_b->data.src_comp_accept_output_port_connection.comp) { return false; } - if (ev_a->data.comp_accept_port_connection.self_port != - ev_b->data.comp_accept_port_connection.self_port) { + if (ev_a->data.src_comp_accept_output_port_connection.self_port != + ev_b->data.src_comp_accept_output_port_connection.self_port) { return false; } - if (ev_a->data.comp_accept_port_connection.other_port != - ev_b->data.comp_accept_port_connection.other_port) { + if (ev_a->data.src_comp_accept_output_port_connection.other_port != + ev_b->data.src_comp_accept_output_port_connection.other_port) { return false; } break; - case COMP_PORT_CONNECTED: - if (ev_a->data.comp_port_connected.comp != - ev_b->data.comp_port_connected.comp) { + case SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION: + if (ev_a->data.sink_comp_accept_input_port_connection.comp != + ev_b->data.sink_comp_accept_input_port_connection.comp) { return false; } - if (ev_a->data.comp_port_connected.self_port != - ev_b->data.comp_port_connected.self_port) { + if (ev_a->data.sink_comp_accept_input_port_connection.self_port != + ev_b->data.sink_comp_accept_input_port_connection.self_port) { return false; } - if (ev_a->data.comp_port_connected.other_port != - ev_b->data.comp_port_connected.other_port) { + if (ev_a->data.sink_comp_accept_input_port_connection.other_port != + ev_b->data.sink_comp_accept_input_port_connection.other_port) { return false; } break; - case COMP_PORT_DISCONNECTED: - if (ev_a->data.comp_port_disconnected.comp != - ev_b->data.comp_port_disconnected.comp) { + case SRC_COMP_OUTPUT_PORT_CONNECTED: + if (ev_a->data.src_comp_output_port_connected.comp != + ev_b->data.src_comp_output_port_connected.comp) { + return false; + } + + if (ev_a->data.src_comp_output_port_connected.self_port != + ev_b->data.src_comp_output_port_connected.self_port) { return false; } - if (ev_a->data.comp_port_disconnected.port != - ev_b->data.comp_port_disconnected.port) { + if (ev_a->data.src_comp_output_port_connected.other_port != + ev_b->data.src_comp_output_port_connected.other_port) { return false; } break; - case GRAPH_PORT_ADDED: - if (ev_a->data.graph_port_added.comp != - ev_b->data.graph_port_added.comp) { + case SINK_COMP_INPUT_PORT_CONNECTED: + if (ev_a->data.sink_comp_input_port_connected.comp != + ev_b->data.sink_comp_input_port_connected.comp) { return false; } - if (ev_a->data.graph_port_added.port != - ev_b->data.graph_port_added.port) { + if (ev_a->data.sink_comp_input_port_connected.self_port != + ev_b->data.sink_comp_input_port_connected.self_port) { + return false; + } + + if (ev_a->data.sink_comp_input_port_connected.other_port != + ev_b->data.sink_comp_input_port_connected.other_port) { return false; } break; - case GRAPH_PORT_REMOVED: - if (ev_a->data.graph_port_removed.comp != - ev_b->data.graph_port_removed.comp) { + case SRC_COMP_OUTPUT_PORT_DISCONNECTED: + if (ev_a->data.src_comp_output_port_disconnected.comp != + ev_b->data.src_comp_output_port_disconnected.comp) { return false; } - if (ev_a->data.graph_port_removed.port != - ev_b->data.graph_port_removed.port) { + if (ev_a->data.src_comp_output_port_disconnected.self_port != + ev_b->data.src_comp_output_port_disconnected.self_port) { return false; } break; - case GRAPH_PORTS_CONNECTED: - if (ev_a->data.graph_ports_connected.upstream_comp != - ev_b->data.graph_ports_connected.upstream_comp) { + case SINK_COMP_INPUT_PORT_DISCONNECTED: + if (ev_a->data.sink_comp_input_port_disconnected.comp != + ev_b->data.sink_comp_input_port_disconnected.comp) { return false; } - if (ev_a->data.graph_ports_connected.downstream_comp != - ev_b->data.graph_ports_connected.downstream_comp) { + if (ev_a->data.sink_comp_input_port_disconnected.self_port != + ev_b->data.sink_comp_input_port_disconnected.self_port) { + return false; + } + break; + case GRAPH_SRC_OUTPUT_PORT_ADDED: + if (ev_a->data.graph_src_output_port_added.comp != + ev_b->data.graph_src_output_port_added.comp) { return false; } - if (ev_a->data.graph_ports_connected.upstream_port != - ev_b->data.graph_ports_connected.upstream_port) { + if (ev_a->data.graph_src_output_port_added.port != + ev_b->data.graph_src_output_port_added.port) { + return false; + } + break; + case GRAPH_SINK_INPUT_PORT_ADDED: + if (ev_a->data.graph_sink_input_port_added.comp != + ev_b->data.graph_sink_input_port_added.comp) { + return false; + } + + if (ev_a->data.graph_sink_input_port_added.port != + ev_b->data.graph_sink_input_port_added.port) { + return false; + } + break; + case GRAPH_SRC_OUTPUT_PORT_REMOVED: + if (ev_a->data.graph_src_output_port_removed.comp != + ev_b->data.graph_src_output_port_removed.comp) { + return false; + } + + if (ev_a->data.graph_src_output_port_removed.port != + ev_b->data.graph_src_output_port_removed.port) { + return false; + } + break; + case GRAPH_SINK_INPUT_PORT_REMOVED: + if (ev_a->data.graph_sink_input_port_removed.comp != + ev_b->data.graph_sink_input_port_removed.comp) { + return false; + } + + if (ev_a->data.graph_sink_input_port_removed.port != + ev_b->data.graph_sink_input_port_removed.port) { + return false; + } + break; + case GRAPH_SRC_SINK_PORTS_CONNECTED: + if (ev_a->data.graph_src_sink_ports_connected.upstream_comp != + ev_b->data.graph_src_sink_ports_connected.upstream_comp) { + return false; + } + + if (ev_a->data.graph_src_sink_ports_connected.downstream_comp != + ev_b->data.graph_src_sink_ports_connected.downstream_comp) { return false; } - if (ev_a->data.graph_ports_connected.downstream_port != - ev_b->data.graph_ports_connected.downstream_port) { + if (ev_a->data.graph_src_sink_ports_connected.upstream_port != + ev_b->data.graph_src_sink_ports_connected.upstream_port) { return false; } - if (ev_a->data.graph_ports_connected.conn != - ev_b->data.graph_ports_connected.conn) { + if (ev_a->data.graph_src_sink_ports_connected.downstream_port != + ev_b->data.graph_src_sink_ports_connected.downstream_port) { return false; } break; - case GRAPH_PORTS_DISCONNECTED: - if (ev_a->data.graph_ports_disconnected.upstream_comp != - ev_b->data.graph_ports_disconnected.upstream_comp) { + case GRAPH_SRC_SINK_PORTS_DISCONNECTED: + if (ev_a->data.graph_src_sink_ports_disconnected.upstream_comp != + ev_b->data.graph_src_sink_ports_disconnected.upstream_comp) { return false; } - if (ev_a->data.graph_ports_disconnected.downstream_comp != - ev_b->data.graph_ports_disconnected.downstream_comp) { + if (ev_a->data.graph_src_sink_ports_disconnected.downstream_comp != + ev_b->data.graph_src_sink_ports_disconnected.downstream_comp) { return false; } - if (ev_a->data.graph_ports_disconnected.upstream_port != - ev_b->data.graph_ports_disconnected.upstream_port) { + if (ev_a->data.graph_src_sink_ports_disconnected.upstream_port != + ev_b->data.graph_src_sink_ports_disconnected.upstream_port) { return false; } - if (ev_a->data.graph_ports_disconnected.downstream_port != - ev_b->data.graph_ports_disconnected.downstream_port) { + if (ev_a->data.graph_src_sink_ports_disconnected.downstream_port != + ev_b->data.graph_src_sink_ports_disconnected.downstream_port) { return false; } break; @@ -288,47 +364,77 @@ size_t event_pos(struct event *event) } static -enum bt_notification_iterator_status src_iter_next( - struct bt_private_connection_private_notification_iterator *priv_iterator, +enum bt_self_notification_iterator_status src_iter_next( + struct bt_self_notification_iterator *self_iterator, bt_notification_array notifs, uint64_t capacity, uint64_t *count) { - return BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; } static -enum bt_component_status accept_port_connection( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +enum bt_self_component_status src_accept_output_port_connection( + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_comp_port, + struct bt_port_input *other_port) { struct event event = { - .type = COMP_ACCEPT_PORT_CONNECTION, - .data.comp_accept_port_connection = { - .comp = bt_component_borrow_from_private(private_component), - .self_port = bt_port_borrow_from_private(self_private_port), - .other_port = other_port, + .type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, + .data.src_comp_accept_output_port_connection = { + .comp = bt_self_component_borrow_component( + bt_self_component_source_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_output_borrow_self_component_port( + self_comp_port)), + .other_port = bt_port_input_borrow_port(other_port), }, }; append_event(&event); - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -enum bt_component_status src_port_connected( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +enum bt_self_component_status sink_accept_input_port_connection( + struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_comp_port, + struct bt_port_output *other_port) { - int ret; + struct event event = { + .type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, + .data.sink_comp_accept_input_port_connection = { + .comp = bt_self_component_borrow_component( + bt_self_component_sink_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_comp_port)), + .other_port = bt_port_output_borrow_port(other_port), + }, + }; + append_event(&event); + return BT_SELF_COMPONENT_STATUS_OK; +} + +static +enum bt_self_component_status src_output_port_connected( + struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_comp_port, + struct bt_port_input *other_port) +{ + int ret; struct event event = { - .type = COMP_PORT_CONNECTED, - .data.comp_port_connected = { - .comp = bt_component_borrow_from_private(private_component), - .self_port = bt_port_borrow_from_private(self_private_port), - .other_port = other_port, + .type = SRC_COMP_OUTPUT_PORT_CONNECTED, + .data.src_comp_output_port_connected = { + .comp = bt_self_component_borrow_component( + bt_self_component_source_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_output_borrow_self_component_port( + self_comp_port)), + .other_port = bt_port_input_borrow_port(other_port), }, }; @@ -336,29 +442,61 @@ enum bt_component_status src_port_connected( switch (current_test) { case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED: - ret = bt_private_component_source_add_output_port( - private_component, "hello", NULL, NULL); + ret = bt_self_component_source_add_output_port( + self_comp, "hello", NULL, NULL); BT_ASSERT(ret == 0); break; case TEST_SRC_PORT_CONNECTED_ERROR: - return BT_COMPONENT_STATUS_ERROR; + return BT_SELF_COMPONENT_STATUS_ERROR; default: break; } - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -void src_port_disconnected(struct bt_private_component *private_component, - struct bt_private_port *private_port) +enum bt_self_component_status sink_input_port_connected( + struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_comp_port, + struct bt_port_output *other_port) +{ + struct event event = { + .type = SINK_COMP_INPUT_PORT_CONNECTED, + .data.sink_comp_input_port_connected = { + .comp = bt_self_component_borrow_component( + bt_self_component_sink_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_comp_port)), + .other_port = bt_port_output_borrow_port(other_port), + }, + }; + + append_event(&event); + + if (current_test == TEST_SINK_PORT_CONNECTED_ERROR) { + return BT_SELF_COMPONENT_STATUS_ERROR; + } else { + return BT_SELF_COMPONENT_STATUS_OK; + } +} + +static +void src_output_port_disconnected(struct bt_self_component_source *self_comp, + struct bt_self_component_port_output *self_comp_port) { int ret; struct event event = { - .type = COMP_PORT_DISCONNECTED, - .data.comp_port_disconnected = { - .comp = bt_component_borrow_from_private(private_component), - .port = bt_port_borrow_from_private(private_port), + .type = SRC_COMP_OUTPUT_PORT_DISCONNECTED, + .data.src_comp_output_port_disconnected = { + .comp = bt_self_component_borrow_component( + bt_self_component_source_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_output_borrow_self_component_port( + self_comp_port)), }, }; @@ -366,7 +504,9 @@ void src_port_disconnected(struct bt_private_component *private_component, switch (current_test) { case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: - ret = bt_private_port_remove_from_component(private_port); + ret = bt_self_component_port_remove_from_component( + bt_self_component_port_output_borrow_self_component_port( + self_comp_port)); BT_ASSERT(ret == 0); default: break; @@ -374,74 +514,99 @@ void src_port_disconnected(struct bt_private_component *private_component, } static -enum bt_component_status src_init(struct bt_private_component *priv_comp, +void sink_input_port_disconnected(struct bt_self_component_sink *self_comp, + struct bt_self_component_port_input *self_comp_port) +{ + struct event event = { + .type = SINK_COMP_INPUT_PORT_DISCONNECTED, + .data.sink_comp_input_port_disconnected = { + .comp = bt_self_component_borrow_component( + bt_self_component_sink_borrow_self_component( + self_comp)), + .self_port = bt_self_component_port_borrow_port( + bt_self_component_port_input_borrow_self_component_port( + self_comp_port)), + }, + }; + + append_event(&event); +} + +static +enum bt_self_component_status src_init( + struct bt_self_component_source *self_comp, struct bt_value *params, void *init_method_data) { int ret; - ret = bt_private_component_source_add_output_port( - priv_comp, "out", NULL, NULL); + ret = bt_self_component_source_add_output_port( + self_comp, "out", NULL, NULL); BT_ASSERT(ret == 0); - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -enum bt_component_status sink_consume( - struct bt_private_component *priv_component) +enum bt_self_component_status sink_init( + struct bt_self_component_sink *self_comp, + struct bt_value *params, void *init_method_data) { - struct bt_private_port *def_port; + int ret; + + ret = bt_self_component_sink_add_input_port(self_comp, + "in", NULL, NULL); + BT_ASSERT(ret == 0); + return BT_SELF_COMPONENT_STATUS_OK; +} + +static +enum bt_self_component_status sink_consume( + struct bt_self_component_sink *self_comp) +{ + struct bt_self_component_port_input *def_port; int ret; switch (current_test) { case TEST_SINK_REMOVES_PORT_IN_CONSUME: case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: - def_port = bt_private_component_sink_get_input_port_by_name( - priv_component, "in"); + def_port = bt_self_component_sink_borrow_input_port_by_name( + self_comp, "in"); BT_ASSERT(def_port); - ret = bt_private_port_remove_from_component(def_port); + ret = bt_self_component_port_remove_from_component( + bt_self_component_port_input_borrow_self_component_port( + def_port)); BT_ASSERT(ret == 0); - bt_object_put_ref(def_port); break; default: break; } - return BT_COMPONENT_STATUS_OK; + return BT_SELF_COMPONENT_STATUS_OK; } static -enum bt_component_status sink_port_connected( - struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +void graph_src_output_port_added(struct bt_component_source *comp, + struct bt_port_output *port, void *data) { struct event event = { - .type = COMP_PORT_CONNECTED, - .data.comp_port_connected = { - .comp = bt_component_borrow_from_private(private_component), - .self_port = bt_port_borrow_from_private(self_private_port), - .other_port = other_port, + .type = GRAPH_SRC_OUTPUT_PORT_ADDED, + .data.graph_src_output_port_added = { + .comp = bt_component_source_borrow_component(comp), + .port = bt_port_output_borrow_port(port), }, }; append_event(&event); - - if (current_test == TEST_SINK_PORT_CONNECTED_ERROR) { - return BT_COMPONENT_STATUS_ERROR; - } else { - return BT_COMPONENT_STATUS_OK; - } } static -void sink_port_disconnected(struct bt_private_component *private_component, - struct bt_private_port *private_port) +void graph_sink_input_port_added(struct bt_component_sink *comp, + struct bt_port_input *port, void *data) { struct event event = { - .type = COMP_PORT_DISCONNECTED, - .data.comp_port_disconnected = { - .comp = bt_component_borrow_from_private(private_component), - .port = bt_port_borrow_from_private(private_port), + .type = GRAPH_SINK_INPUT_PORT_ADDED, + .data.graph_sink_input_port_added = { + .comp = bt_component_sink_borrow_component(comp), + .port = bt_port_input_borrow_port(port), }, }; @@ -449,31 +614,14 @@ void sink_port_disconnected(struct bt_private_component *private_component, } static -enum bt_component_status sink_init(struct bt_private_component *priv_comp, - struct bt_value *params, void *init_method_data) -{ - int ret; - - ret = bt_private_component_sink_add_input_port(priv_comp, - "in", NULL, NULL); - BT_ASSERT(ret == 0); - return BT_COMPONENT_STATUS_OK; -} - -static -void graph_port_added(struct bt_port *port, - void *data) +void graph_src_output_port_removed(struct bt_component_source *comp, + struct bt_port_output *port, void *data) { - struct bt_component *comp = bt_port_get_component(port); - - BT_ASSERT(comp); - bt_object_put_ref(comp); - struct event event = { - .type = GRAPH_PORT_ADDED, - .data.graph_port_added = { - .comp = comp, - .port = port, + .type = GRAPH_SRC_OUTPUT_PORT_REMOVED, + .data.graph_src_output_port_removed = { + .comp = bt_component_source_borrow_component(comp), + .port = bt_port_output_borrow_port(port), }, }; @@ -481,14 +629,14 @@ void graph_port_added(struct bt_port *port, } static -void graph_port_removed(struct bt_component *component, - struct bt_port *port, void *data) +void graph_sink_input_port_removed(struct bt_component_sink *comp, + struct bt_port_input *port, void *data) { struct event event = { - .type = GRAPH_PORT_REMOVED, - .data.graph_port_removed = { - .comp = component, - .port = port, + .type = GRAPH_SINK_INPUT_PORT_REMOVED, + .data.graph_sink_input_port_removed = { + .comp = bt_component_sink_borrow_component(comp), + .port = bt_port_input_borrow_port(port), }, }; @@ -496,30 +644,22 @@ void graph_port_removed(struct bt_component *component, } static -void graph_ports_connected(struct bt_port *upstream_port, - struct bt_port *downstream_port, void *data) +void graph_src_sink_ports_connected(struct bt_component_source *upstream_comp, + struct bt_component_sink *downstream_comp, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data) { - struct bt_component *upstream_comp = - bt_port_get_component(upstream_port); - struct bt_component *downstream_comp = - bt_port_get_component(downstream_port); - struct bt_connection *conn = bt_port_get_connection(upstream_port); - - BT_ASSERT(upstream_comp); - BT_ASSERT(downstream_comp); - BT_ASSERT(conn); - bt_object_put_ref(upstream_comp); - bt_object_put_ref(downstream_comp); - bt_object_put_ref(conn); - struct event event = { - .type = GRAPH_PORTS_CONNECTED, - .data.graph_ports_connected = { - .upstream_comp = upstream_comp, - .downstream_comp = downstream_comp, - .upstream_port = upstream_port, - .downstream_port = downstream_port, - .conn = conn, + .type = GRAPH_SRC_SINK_PORTS_CONNECTED, + .data.graph_src_sink_ports_connected = { + .upstream_comp = + bt_component_source_borrow_component(upstream_comp), + .downstream_comp = + bt_component_sink_borrow_component(downstream_comp), + .upstream_port = + bt_port_output_borrow_port(upstream_port), + .downstream_port = + bt_port_input_borrow_port(downstream_port), }, }; @@ -527,19 +667,22 @@ void graph_ports_connected(struct bt_port *upstream_port, } static -void graph_ports_disconnected( - struct bt_component *upstream_comp, - struct bt_component *downstream_comp, - struct bt_port *upstream_port, struct bt_port *downstream_port, - void *data) +void graph_src_sink_ports_disconnected(struct bt_component_source *upstream_comp, + struct bt_component_sink *downstream_comp, + struct bt_port_output *upstream_port, + struct bt_port_input *downstream_port, void *data) { struct event event = { - .type = GRAPH_PORTS_DISCONNECTED, - .data.graph_ports_disconnected = { - .upstream_comp = upstream_comp, - .downstream_comp = downstream_comp, - .upstream_port = upstream_port, - .downstream_port = downstream_port, + .type = GRAPH_SRC_SINK_PORTS_DISCONNECTED, + .data.graph_src_sink_ports_disconnected = { + .upstream_comp = + bt_component_source_borrow_component(upstream_comp), + .downstream_comp = + bt_component_sink_borrow_component(downstream_comp), + .upstream_port = + bt_port_output_borrow_port(upstream_port), + .downstream_port = + bt_port_input_borrow_port(downstream_port), }, }; @@ -551,34 +694,36 @@ void init_test(void) { int ret; - src_comp_class = bt_component_class_source_create("src", src_iter_next); + src_comp_class = bt_private_component_class_source_create( + "src", src_iter_next); BT_ASSERT(src_comp_class); - ret = bt_component_class_set_init_method(src_comp_class, src_init); + ret = bt_private_component_class_source_set_init_method( + src_comp_class, src_init); BT_ASSERT(ret == 0); - ret = bt_component_class_set_accept_port_connection_method( - src_comp_class, accept_port_connection); + ret = bt_private_component_class_source_set_accept_output_port_connection_method( + src_comp_class, src_accept_output_port_connection); BT_ASSERT(ret == 0); - ret = bt_component_class_set_port_connected_method(src_comp_class, - src_port_connected); + ret = bt_private_component_class_source_set_output_port_connected_method( + src_comp_class, src_output_port_connected); BT_ASSERT(ret == 0); - ret = bt_component_class_set_port_disconnected_method( - src_comp_class, src_port_disconnected); + ret = bt_private_component_class_source_set_output_port_disconnected_method( + src_comp_class, src_output_port_disconnected); BT_ASSERT(ret == 0); - sink_comp_class = bt_component_class_sink_create("sink", sink_consume); + sink_comp_class = bt_private_component_class_sink_create("sink", + sink_consume); BT_ASSERT(sink_comp_class); - ret = bt_component_class_set_init_method(sink_comp_class, sink_init); + ret = bt_private_component_class_sink_set_init_method(sink_comp_class, + sink_init); BT_ASSERT(ret == 0); - ret = bt_component_class_set_accept_port_connection_method( - sink_comp_class, accept_port_connection); + ret = bt_private_component_class_sink_set_accept_input_port_connection_method( + sink_comp_class, sink_accept_input_port_connection); BT_ASSERT(ret == 0); - ret = bt_component_class_set_port_connected_method(sink_comp_class, - sink_port_connected); + ret = bt_private_component_class_sink_set_input_port_connected_method( + sink_comp_class, sink_input_port_connected); BT_ASSERT(ret == 0); - ret = bt_component_class_set_port_disconnected_method(sink_comp_class, - sink_port_disconnected); + ret = bt_private_component_class_sink_set_input_port_disconnected_method( + sink_comp_class, sink_input_port_disconnected); BT_ASSERT(ret == 0); - bt_component_class_freeze(src_comp_class); - bt_component_class_freeze(sink_comp_class); events = g_array_new(FALSE, TRUE, sizeof(struct event)); BT_ASSERT(events); } @@ -592,25 +737,29 @@ void fini_test(void) } static -struct bt_component *create_src(struct bt_private_graph *graph) +struct bt_component_source *create_src(struct bt_private_graph *graph) { - struct bt_component *comp; + struct bt_component_source *comp; int ret; - ret = bt_private_graph_add_component(graph, src_comp_class, "src-comp", NULL, - &comp); + ret = bt_private_graph_add_source_component(graph, + bt_private_component_class_source_borrow_component_class_source( + src_comp_class), + "src-comp", NULL, &comp); BT_ASSERT(ret == 0); return comp; } static -struct bt_component *create_sink(struct bt_private_graph *graph) +struct bt_component_sink *create_sink(struct bt_private_graph *graph) { - struct bt_component *comp; + struct bt_component_sink *comp; int ret; - ret = bt_private_graph_add_component(graph, sink_comp_class, "sink-comp", - NULL, &comp); + ret = bt_private_graph_add_sink_component(graph, + bt_private_component_class_sink_borrow_component_class_sink( + sink_comp_class), + "sink-comp", NULL, &comp); BT_ASSERT(ret == 0); return comp; } @@ -622,17 +771,23 @@ struct bt_private_graph *create_graph(void) int ret; BT_ASSERT(graph); - ret = bt_private_graph_add_port_added_listener(graph, graph_port_added, NULL, - NULL); + ret = bt_private_graph_add_source_component_output_port_added_listener( + graph, graph_src_output_port_added, NULL, NULL, NULL); + BT_ASSERT(ret >= 0); + ret = bt_private_graph_add_sink_component_input_port_added_listener( + graph, graph_sink_input_port_added, NULL, NULL, NULL); BT_ASSERT(ret >= 0); - ret = bt_private_graph_add_port_removed_listener(graph, graph_port_removed, - NULL, NULL); + ret = bt_private_graph_add_source_component_output_port_removed_listener( + graph, graph_src_output_port_removed, NULL, NULL, NULL); BT_ASSERT(ret >= 0); - ret = bt_private_graph_add_ports_connected_listener(graph, - graph_ports_connected, NULL, NULL); + ret = bt_private_graph_add_sink_component_input_port_removed_listener( + graph, graph_sink_input_port_removed, NULL, NULL, NULL); BT_ASSERT(ret >= 0); - ret = bt_private_graph_add_ports_disconnected_listener(graph, - graph_ports_disconnected, NULL, NULL); + ret = bt_private_graph_add_source_sink_component_ports_connected_listener( + graph, graph_src_sink_ports_connected, NULL, NULL, NULL); + BT_ASSERT(ret >= 0); + ret = bt_private_graph_add_source_sink_component_ports_disconnected_listener( + graph, graph_src_sink_ports_disconnected, NULL, NULL, NULL); BT_ASSERT(ret >= 0); return graph; } @@ -646,22 +801,25 @@ void prepare_test(enum test test, const char *name) } static -void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port(void) +void test_sink_removes_port_in_consume_then_src_removes_disconnected_port(void) { int ret; - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; - struct bt_connection *conn; + struct bt_port_output *src_def_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsink_def_port; struct event event; enum bt_graph_status status; size_t src_accept_port_connection_pos; size_t sink_accept_port_connection_pos; size_t src_port_connected_pos; size_t sink_port_connected_pos; - size_t graph_ports_connected; + size_t graph_ports_connected_pos; size_t src_port_disconnected_pos; size_t sink_port_disconnected_pos; size_t graph_ports_disconnected_pos; @@ -674,76 +832,78 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, NULL); BT_ASSERT(status == 0); - BT_ASSERT(conn); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 7 events so far */ ok(events->len == 7, "we have the expected number of events (before consume)"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); sink_accept_port_connection_pos = event_pos(&event); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); /* Sink's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = sink; - event.data.comp_port_connected.self_port = sink_def_port; - event.data.comp_port_connected.other_port = src_def_port; + event.type = SINK_COMP_INPUT_PORT_CONNECTED; + event.data.sink_comp_input_port_connected.comp = gsink; + event.data.sink_comp_input_port_connected.self_port = gsink_def_port; + event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); /* Graph's ports connected */ - event.type = GRAPH_PORTS_CONNECTED; - event.data.graph_ports_connected.upstream_comp = src; - event.data.graph_ports_connected.downstream_comp = sink; - event.data.graph_ports_connected.upstream_port = src_def_port; - event.data.graph_ports_connected.downstream_port = sink_def_port; - event.data.graph_ports_connected.conn = conn; + event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; + event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_connected.downstream_comp = gsink; + event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; ok(has_event(&event), "got the expected graph's ports connected event"); - graph_ports_connected = event_pos(&event); + graph_ports_connected_pos = event_pos(&event); /* Order of events */ - ok(src_port_connected_pos < graph_ports_connected, + ok(src_port_connected_pos < graph_ports_connected_pos, "event order is good (1)"); - ok(sink_port_connected_pos < graph_ports_connected, + ok(sink_port_connected_pos < graph_ports_connected_pos, "event order is good (2)"); ok(src_accept_port_connection_pos < src_port_connected_pos, "event order is good (3)"); @@ -759,39 +919,39 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port ok(events->len == 5, "we have the expected number of events (after consume)"); /* Source's port disconnected */ - event.type = COMP_PORT_DISCONNECTED; - event.data.comp_port_disconnected.comp = src; - event.data.comp_port_disconnected.port = src_def_port; + event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; + event.data.src_comp_output_port_disconnected.comp = gsrc; + event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; ok(has_event(&event), "got the expected source's port disconnected event"); src_port_disconnected_pos = event_pos(&event); /* Sink's port disconnected */ - event.type = COMP_PORT_DISCONNECTED; - event.data.comp_port_disconnected.comp = sink; - event.data.comp_port_disconnected.port = sink_def_port; + event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; + event.data.sink_comp_input_port_disconnected.comp = gsink; + event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; ok(has_event(&event), "got the expected sink's port disconnected event"); sink_port_disconnected_pos = event_pos(&event); /* Graph's ports disconnected */ - event.type = GRAPH_PORTS_DISCONNECTED; - event.data.graph_ports_disconnected.upstream_comp = src; - event.data.graph_ports_disconnected.downstream_comp = sink; - event.data.graph_ports_disconnected.upstream_port = src_def_port; - event.data.graph_ports_disconnected.downstream_port = sink_def_port; + event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; + event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; + event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; ok(has_event(&event), "got the expected graph's ports disconnected event"); graph_ports_disconnected_pos = event_pos(&event); /* Graph's port removed (sink) */ - event.type = GRAPH_PORT_REMOVED; - event.data.graph_port_removed.comp = sink; - event.data.graph_port_removed.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_REMOVED; + event.data.graph_sink_input_port_removed.comp = gsink; + event.data.graph_sink_input_port_removed.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port removed event (for sink)"); graph_port_removed_sink_pos = event_pos(&event); /* Graph's port removed (source) */ - event.type = GRAPH_PORT_REMOVED; - event.data.graph_port_removed.comp = src; - event.data.graph_port_removed.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_REMOVED; + event.data.graph_src_output_port_removed.comp = gsrc; + event.data.graph_src_output_port_removed.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port removed event (for source)"); graph_port_removed_src_pos = event_pos(&event); @@ -818,21 +978,21 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port bt_object_put_ref(graph); bt_object_put_ref(sink); bt_object_put_ref(src); - bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); } static -void test_sink_removes_port_in_port_connected(void) +void test_sink_removes_port_in_consume(void) { int ret; - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; - struct bt_connection *conn; + struct bt_port_output *src_def_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsink_def_port; struct event event; enum bt_graph_status status; size_t src_accept_port_connection_pos; @@ -851,68 +1011,71 @@ void test_sink_removes_port_in_port_connected(void) BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, NULL); BT_ASSERT(status == 0); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 7 events so far */ ok(events->len == 7, "we have the expected number of events (before consume)"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); sink_accept_port_connection_pos = event_pos(&event); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); /* Sink's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = sink; - event.data.comp_port_connected.self_port = sink_def_port; - event.data.comp_port_connected.other_port = src_def_port; + event.type = SINK_COMP_INPUT_PORT_CONNECTED; + event.data.sink_comp_input_port_connected.comp = gsink; + event.data.sink_comp_input_port_connected.self_port = gsink_def_port; + event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); /* Graph's ports connected */ - event.type = GRAPH_PORTS_CONNECTED; - event.data.graph_ports_connected.upstream_comp = src; - event.data.graph_ports_connected.downstream_comp = sink; - event.data.graph_ports_connected.upstream_port = src_def_port; - event.data.graph_ports_connected.downstream_port = sink_def_port; - event.data.graph_ports_connected.conn = conn; + event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; + event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_connected.downstream_comp = gsink; + event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; ok(has_event(&event), "got the expected graph's ports connected event"); graph_ports_connected_pos = event_pos(&event); @@ -935,32 +1098,32 @@ void test_sink_removes_port_in_port_connected(void) ok(events->len == 4, "we have the expected number of events (after consume)"); /* Source's port disconnected */ - event.type = COMP_PORT_DISCONNECTED; - event.data.comp_port_disconnected.comp = src; - event.data.comp_port_disconnected.port = src_def_port; + event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; + event.data.src_comp_output_port_disconnected.comp = gsrc; + event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; ok(has_event(&event), "got the expected source's port disconnected event"); src_port_disconnected_pos = event_pos(&event); /* Sink's port disconnected */ - event.type = COMP_PORT_DISCONNECTED; - event.data.comp_port_disconnected.comp = sink; - event.data.comp_port_disconnected.port = sink_def_port; + event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; + event.data.sink_comp_input_port_disconnected.comp = gsink; + event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; ok(has_event(&event), "got the expected sink's port disconnected event"); sink_port_disconnected_pos = event_pos(&event); /* Graph's ports disconnected */ - event.type = GRAPH_PORTS_DISCONNECTED; - event.data.graph_ports_disconnected.upstream_comp = src; - event.data.graph_ports_disconnected.downstream_comp = sink; - event.data.graph_ports_disconnected.upstream_port = src_def_port; - event.data.graph_ports_disconnected.downstream_port = sink_def_port; + event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; + event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; + event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; ok(has_event(&event), "got the expected graph's ports disconnected event"); graph_ports_disconnected_pos = event_pos(&event); /* Graph's port removed (sink) */ - event.type = GRAPH_PORT_REMOVED; - event.data.graph_port_removed.comp = sink; - event.data.graph_port_removed.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_REMOVED; + event.data.graph_sink_input_port_removed.comp = gsink; + event.data.graph_sink_input_port_removed.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port removed event (for sink)"); graph_port_removed_sink_pos = event_pos(&event); @@ -976,24 +1139,25 @@ void test_sink_removes_port_in_port_connected(void) ok(graph_ports_disconnected_pos < graph_port_removed_sink_pos, "event order is good (11)"); - bt_object_put_ref(graph); bt_object_put_ref(sink); bt_object_put_ref(src); - bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); + bt_object_put_ref(graph); } static void test_src_adds_port_in_port_connected(void) { - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; - struct bt_port *src_hello_port; - struct bt_connection *conn; + struct bt_port_output *src_def_port; + struct bt_port_output *src_hello_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsrc_hello_port; + struct bt_port *gsink_def_port; struct event event; enum bt_graph_status status; size_t src_accept_port_connection_pos; @@ -1009,79 +1173,83 @@ void test_src_adds_port_in_port_connected(void) BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, NULL); BT_ASSERT(status == 0); - src_hello_port = bt_component_source_get_output_port_by_name(src, + src_hello_port = bt_component_source_borrow_output_port_by_name(src, "hello"); BT_ASSERT(src_hello_port); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsrc_hello_port = bt_port_output_borrow_port(src_hello_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 8 events */ ok(events->len == 8, "we have the expected number of events"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); sink_accept_port_connection_pos = event_pos(&event); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); /* Graph's port added (source) */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_hello_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_hello_port; ok(has_event(&event), "got the expected graph's port added event (for source)"); graph_port_added_src_pos = event_pos(&event); /* Sink's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = sink; - event.data.comp_port_connected.self_port = sink_def_port; - event.data.comp_port_connected.other_port = src_def_port; + event.type = SINK_COMP_INPUT_PORT_CONNECTED; + event.data.sink_comp_input_port_connected.comp = gsink; + event.data.sink_comp_input_port_connected.self_port = gsink_def_port; + event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); /* Graph's ports connected */ - event.type = GRAPH_PORTS_CONNECTED; - event.data.graph_ports_connected.upstream_comp = src; - event.data.graph_ports_connected.downstream_comp = sink; - event.data.graph_ports_connected.upstream_port = src_def_port; - event.data.graph_ports_connected.downstream_port = sink_def_port; - event.data.graph_ports_connected.conn = conn; - ok(has_event(&event), "got the expected graph's port connected event (for source)"); + event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; + event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_connected.downstream_comp = gsink; + event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; + ok(has_event(&event), "got the expected graph's ports connected event"); graph_ports_connected_pos = event_pos(&event); /* Order of events */ @@ -1098,24 +1266,23 @@ void test_src_adds_port_in_port_connected(void) ok(graph_port_added_src_pos < graph_ports_connected_pos, "event order is good (6)"); - bt_object_put_ref(graph); - bt_object_put_ref(sink); bt_object_put_ref(src); - bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); - bt_object_put_ref(src_hello_port); + bt_object_put_ref(sink); + bt_object_put_ref(graph); } static void test_simple(void) { - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; - struct bt_connection *conn; + struct bt_port_output *src_def_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsink_def_port; struct event event; enum bt_graph_status status; size_t src_accept_port_connection_pos; @@ -1129,68 +1296,71 @@ void test_simple(void) BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, NULL); BT_ASSERT(status == 0); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 7 events */ ok(events->len == 7, "we have the expected number of events"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); sink_accept_port_connection_pos = event_pos(&event); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); /* Sink's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = sink; - event.data.comp_port_connected.self_port = sink_def_port; - event.data.comp_port_connected.other_port = src_def_port; + event.type = SINK_COMP_INPUT_PORT_CONNECTED; + event.data.sink_comp_input_port_connected.comp = gsink; + event.data.sink_comp_input_port_connected.self_port = gsink_def_port; + event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); - /* Graph's port connected */ - event.type = GRAPH_PORTS_CONNECTED; - event.data.graph_ports_connected.upstream_comp = src; - event.data.graph_ports_connected.downstream_comp = sink; - event.data.graph_ports_connected.upstream_port = src_def_port; - event.data.graph_ports_connected.downstream_port = sink_def_port; - event.data.graph_ports_connected.conn = conn; + /* Graph's ports connected */ + event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; + event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; + event.data.graph_src_sink_ports_connected.downstream_comp = gsink; + event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; + event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; ok(has_event(&event), "got the expected graph's ports connected event"); graph_ports_connected_pos = event_pos(&event); @@ -1204,22 +1374,23 @@ void test_simple(void) ok(sink_accept_port_connection_pos < sink_port_connected_pos, "event order is good (4)"); - bt_object_put_ref(graph); bt_object_put_ref(sink); + bt_object_put_ref(graph); bt_object_put_ref(src); - bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); } static void test_src_port_connected_error(void) { - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; + struct bt_port_output *src_def_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsink_def_port; struct bt_connection *conn = NULL; struct event event; enum bt_graph_status status; @@ -1231,51 +1402,55 @@ void test_src_port_connected_error(void) BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, &conn); ok(status != BT_GRAPH_STATUS_OK, "bt_private_graph_connect_ports() returns an error"); - ok(!conn, "returned connection is NULL"); + ok(!conn, "returned connection is still NULL"); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 5 events */ ok(events->len == 5, "we have the expected number of events"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); @@ -1287,18 +1462,20 @@ void test_src_port_connected_error(void) bt_object_put_ref(sink); bt_object_put_ref(src); bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); } static void test_sink_port_connected_error(void) { - struct bt_component *src; - struct bt_component *sink; + struct bt_component_source *src; + struct bt_component_sink *sink; + struct bt_component *gsrc; + struct bt_component *gsink; struct bt_private_graph *graph; - struct bt_port *src_def_port; - struct bt_port *sink_def_port; + struct bt_port_output *src_def_port; + struct bt_port_input *sink_def_port; + struct bt_port *gsrc_def_port; + struct bt_port *gsink_def_port; struct bt_connection *conn = NULL; struct event event; enum bt_graph_status status; @@ -1313,67 +1490,71 @@ void test_sink_port_connected_error(void) BT_ASSERT(graph); src = create_src(graph); sink = create_sink(graph); - src_def_port = bt_component_source_get_output_port_by_name(src, "out"); + src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in"); + sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); BT_ASSERT(sink_def_port); - status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port, - &conn); + status = bt_private_graph_connect_ports(graph, src_def_port, + sink_def_port, &conn); ok(status != BT_GRAPH_STATUS_OK, "bt_private_graph_connect_ports() returns an error"); - ok(!conn, "returned connection is NULL"); + ok(!conn, "returned connection is still NULL"); + gsrc = bt_component_source_borrow_component(src); + gsink = bt_component_sink_borrow_component(sink); + gsrc_def_port = bt_port_output_borrow_port(src_def_port); + gsink_def_port = bt_port_input_borrow_port(sink_def_port); /* We're supposed to have 5 events */ ok(events->len == 7, "we have the expected number of events"); /* Source's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = src; - event.data.graph_port_added.port = src_def_port; + event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; + event.data.graph_src_output_port_added.comp = gsrc; + event.data.graph_src_output_port_added.port = gsrc_def_port; ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); /* Sink's port added */ - event.type = GRAPH_PORT_ADDED; - event.data.graph_port_added.comp = sink; - event.data.graph_port_added.port = sink_def_port; + event.type = GRAPH_SINK_INPUT_PORT_ADDED; + event.data.graph_sink_input_port_added.comp = gsink; + event.data.graph_sink_input_port_added.port = gsink_def_port; ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); /* Source's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = src; - event.data.comp_accept_port_connection.self_port = src_def_port; - event.data.comp_accept_port_connection.other_port = sink_def_port; + event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; + event.data.src_comp_accept_output_port_connection.comp = gsrc; + event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; + event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's accept port connection event"); src_accept_port_connection_pos = event_pos(&event); /* Sink's accept port connection */ - event.type = COMP_ACCEPT_PORT_CONNECTION; - event.data.comp_accept_port_connection.comp = sink; - event.data.comp_accept_port_connection.self_port = sink_def_port; - event.data.comp_accept_port_connection.other_port = src_def_port; + event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; + event.data.sink_comp_accept_input_port_connection.comp = gsink; + event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; + event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's accept port connection event"); sink_accept_port_connection_pos = event_pos(&event); /* Source's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = src; - event.data.comp_port_connected.self_port = src_def_port; - event.data.comp_port_connected.other_port = sink_def_port; + event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; + event.data.src_comp_output_port_connected.comp = gsrc; + event.data.src_comp_output_port_connected.self_port = gsrc_def_port; + event.data.src_comp_output_port_connected.other_port = gsink_def_port; ok(has_event(&event), "got the expected source's port connected event"); src_port_connected_pos = event_pos(&event); /* Sink's port connected */ - event.type = COMP_PORT_CONNECTED; - event.data.comp_port_connected.comp = sink; - event.data.comp_port_connected.self_port = sink_def_port; - event.data.comp_port_connected.other_port = src_def_port; + event.type = SINK_COMP_INPUT_PORT_CONNECTED; + event.data.sink_comp_input_port_connected.comp = gsink; + event.data.sink_comp_input_port_connected.self_port = gsink_def_port; + event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); /* Source's port disconnected */ - event.type = COMP_PORT_DISCONNECTED; - event.data.comp_port_disconnected.comp = src; - event.data.comp_port_disconnected.port = src_def_port; + event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; + event.data.src_comp_output_port_disconnected.comp = gsrc; + event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; ok(has_event(&event), "got the expected source's port disconnected event"); src_port_disconnected_pos = event_pos(&event); @@ -1385,12 +1566,10 @@ void test_sink_port_connected_error(void) ok(sink_port_connected_pos < src_port_disconnected_pos, "event order is good (3)"); + bt_object_put_ref(conn); bt_object_put_ref(graph); bt_object_put_ref(sink); bt_object_put_ref(src); - bt_object_put_ref(conn); - bt_object_put_ref(src_def_port); - bt_object_put_ref(sink_def_port); } static @@ -1413,8 +1592,8 @@ int main(int argc, char **argv) test_src_port_connected_error(); test_sink_port_connected_error(); test_src_adds_port_in_port_connected(); - test_sink_removes_port_in_port_connected(); - test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port(); + test_sink_removes_port_in_consume(); + test_sink_removes_port_in_consume_then_src_removes_disconnected_port(); fini_test(); return exit_status(); } diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index eb4fd2ae..bd59512b 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -15,14 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include @@ -31,7 +24,7 @@ #include "tap/tap.h" #include "common.h" -#define NR_TESTS 58 +#define NR_TESTS 35 #define NON_EXISTING_PATH "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so" /* Those symbols are written to by some test plugins */ @@ -69,43 +62,6 @@ static char *get_test_plugin_path(const char *plugin_dir, return ret; } -static void test_invalid(const char *plugin_dir) -{ - struct bt_plugin_set *plugin_set; - - diag("invalid plugin test below"); - - plugin_set = bt_plugin_create_all_from_file(NON_EXISTING_PATH); - ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a non-existing file"); - - plugin_set = bt_plugin_create_all_from_file(plugin_dir); - ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a directory"); - - ok(!bt_plugin_create_all_from_file(NULL), - "bt_plugin_create_all_from_file() handles NULL correctly"); - ok(!bt_plugin_create_all_from_dir(NULL, BT_FALSE), - "bt_plugin_create_all_from_dir() handles NULL correctly"); - ok(!bt_plugin_get_name(NULL), - "bt_plugin_get_name() handles NULL correctly"); - ok(!bt_plugin_get_description(NULL), - "bt_plugin_get_description() handles NULL correctly"); - ok(bt_plugin_get_version(NULL, NULL, NULL, NULL, NULL) != - BT_PLUGIN_STATUS_OK, - "bt_plugin_get_version() handles NULL correctly"); - ok(!bt_plugin_get_author(NULL), - "bt_plugin_get_author() handles NULL correctly"); - ok(!bt_plugin_get_license(NULL), - "bt_plugin_get_license() handles NULL correctly"); - ok(!bt_plugin_get_path(NULL), - "bt_plugin_get_path() handles NULL correctly"); - ok(bt_plugin_get_component_class_count(NULL) < 0, - "bt_plugin_get_component_class_count() handles NULL correctly"); - ok(!bt_plugin_get_component_class_by_index(NULL, 0), - "bt_plugin_get_component_class_by_index() handles NULL correctly"); - ok(!bt_plugin_get_component_class_by_name_and_type(NULL, NULL, 0), - "bt_plugin_get_component_class_by_name_and_type() handles NULL correctly"); -} - static void test_minimal(const char *plugin_dir) { struct bt_plugin_set *plugin_set; @@ -123,14 +79,14 @@ static void test_minimal(const char *plugin_dir) "plugin's initialization function is called during bt_plugin_create_all_from_file()"); ok(bt_plugin_set_get_plugin_count(plugin_set) == 1, "bt_plugin_create_all_from_file() returns the expected number of plugins"); - plugin = bt_plugin_set_get_plugin(plugin_set, 0); + plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0); ok(strcmp(bt_plugin_get_name(plugin), "test_minimal") == 0, "bt_plugin_get_name() returns the expected name"); ok(strcmp(bt_plugin_get_description(plugin), "Minimal Babeltrace plugin with no component classes") == 0, "bt_plugin_get_description() returns the expected description"); - ok(bt_plugin_get_version(plugin, NULL, NULL, NULL, NULL) != - BT_PLUGIN_STATUS_OK, + ok(bt_plugin_get_version(plugin, NULL, NULL, NULL, NULL) == + BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE, "bt_plugin_get_version() fails when there's no version"); ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0, "bt_plugin_get_author() returns the expected author"); @@ -138,9 +94,12 @@ static void test_minimal(const char *plugin_dir) "bt_plugin_get_license() returns the expected license"); ok(strcmp(bt_plugin_get_path(plugin), minimal_path) == 0, "bt_plugin_get_path() returns the expected path"); - ok(bt_plugin_get_component_class_count(plugin) == 0, - "bt_plugin_get_component_class_count() returns the expected value"); - bt_object_put_ref(plugin); + ok(bt_plugin_get_source_component_class_count(plugin) == 0, + "bt_plugin_get_source_component_class_count() returns the expected value"); + ok(bt_plugin_get_filter_component_class_count(plugin) == 0, + "bt_plugin_get_filter_component_class_count() returns the expected value"); + ok(bt_plugin_get_sink_component_class_count(plugin) == 0, + "bt_plugin_get_sink_component_class_count() returns the expected value"); bt_object_put_ref(plugin_set); ok(check_env_var("BT_TEST_PLUGIN_EXIT_CALLED") == 1, "plugin's exit function is called when the plugin is destroyed"); @@ -152,10 +111,10 @@ static void test_sfs(const char *plugin_dir) { struct bt_plugin_set *plugin_set; struct bt_plugin *plugin; - struct bt_component_class *sink_comp_class; - struct bt_component_class *source_comp_class; - struct bt_component_class *filter_comp_class; - struct bt_component *sink_component; + struct bt_component_class_sink *sink_comp_class; + struct bt_component_class_source *source_comp_class; + struct bt_component_class_filter *filter_comp_class; + struct bt_component_sink *sink_component; char *sfs_path = get_test_plugin_path(plugin_dir, "sfs"); unsigned int major, minor, patch; const char *extra; @@ -166,7 +125,8 @@ static void test_sfs(const char *plugin_dir) struct bt_private_graph *graph; const char *object_str; enum bt_graph_status graph_ret; - struct bt_query_executor *query_exec = bt_query_executor_create(); + struct bt_private_query_executor *query_exec = + bt_private_query_executor_create(); int ret; BT_ASSERT(query_exec); @@ -175,9 +135,9 @@ static void test_sfs(const char *plugin_dir) plugin_set = bt_plugin_create_all_from_file(sfs_path); BT_ASSERT(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1); - plugin = bt_plugin_set_get_plugin(plugin_set, 0); + plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0); ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) == - BT_PLUGIN_STATUS_OK, + BT_PROPERTY_AVAILABILITY_AVAILABLE, "bt_plugin_get_version() succeeds when there's a version"); ok(major == 1, "bt_plugin_get_version() returns the expected major version"); @@ -187,47 +147,41 @@ static void test_sfs(const char *plugin_dir) "bt_plugin_get_version() returns the expected patch version"); ok(strcmp(extra, "yes") == 0, "bt_plugin_get_version() returns the expected extra version"); - ok(bt_plugin_get_component_class_count(plugin) == 3, - "bt_plugin_get_component_class_count() returns the expected value"); - - source_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "source", BT_COMPONENT_CLASS_TYPE_SOURCE); + ok(bt_plugin_get_source_component_class_count(plugin) == 1, + "bt_plugin_get_source_component_class_count() returns the expected value"); + ok(bt_plugin_get_filter_component_class_count(plugin) == 1, + "bt_plugin_get_filter_component_class_count() returns the expected value"); + ok(bt_plugin_get_sink_component_class_count(plugin) == 1, + "bt_plugin_get_sink_component_class_count() returns the expected value"); + + source_comp_class = bt_plugin_borrow_source_component_class_by_name( + plugin, "source"); ok(source_comp_class, - "bt_plugin_get_component_class_by_name_and_type() finds a source component class"); + "bt_plugin_borrow_source_component_class_by_name() finds a source component class"); - sink_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "sink", BT_COMPONENT_CLASS_TYPE_SINK); + sink_comp_class = bt_plugin_borrow_sink_component_class_by_name( + plugin, "sink"); ok(sink_comp_class, - "bt_plugin_get_component_class_by_name_and_type() finds a sink component class"); - ok(strcmp(bt_component_class_get_help(sink_comp_class), + "bt_plugin_borrow_sink_component_class_by_name() finds a sink component class"); + ok(strcmp(bt_component_class_get_help( + bt_component_class_sink_borrow_component_class(sink_comp_class)), "Bacon ipsum dolor amet strip steak cupim pastrami venison shoulder.\n" "Prosciutto beef ribs flank meatloaf pancetta brisket kielbasa drumstick\n" "venison tenderloin cow tail. Beef short loin shoulder meatball, sirloin\n" "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n") == 0, "bt_component_class_get_help() returns the expected help text"); - filter_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "filter", BT_COMPONENT_CLASS_TYPE_FILTER); + filter_comp_class = bt_plugin_borrow_filter_component_class_by_name( + plugin, "filter"); ok(filter_comp_class, - "bt_plugin_get_component_class_by_name_and_type() finds a filter component class"); - ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter", - BT_COMPONENT_CLASS_TYPE_SOURCE), - "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type"); + "bt_plugin_borrow_filter_component_class_by_name() finds a filter component class"); params = bt_private_value_integer_create_init(23); BT_ASSERT(params); - ret = bt_query_executor_query(NULL, filter_comp_class, "object", - bt_value_borrow_from_private(params), &results); - ok (ret, "bt_query_executor_query() handles NULL (query executor)"); - ret = bt_query_executor_query(query_exec, NULL, "object", - bt_value_borrow_from_private(params), &results); - ok (ret, "bt_query_executor_query() handles NULL (component class)"); - ret = bt_query_executor_query(query_exec, filter_comp_class, NULL, - bt_value_borrow_from_private(params), &results); - ok (ret, "bt_query_executor_query() handles NULL (object)"); - ret = bt_query_executor_query(query_exec, filter_comp_class, - "get-something", bt_value_borrow_from_private(params), + ret = bt_private_query_executor_query(query_exec, + bt_component_class_filter_borrow_component_class(filter_comp_class), + "get-something", bt_private_value_borrow_value(params), &results); - ok(ret == 0 && results, "bt_query_executor_query() succeeds"); + ok(ret == 0 && results, "bt_private_query_executor_query() succeeds"); BT_ASSERT(bt_value_is_array(results) && bt_value_array_get_size(results) == 2); object = bt_value_array_borrow_element_by_index(results, 0); BT_ASSERT(object && bt_value_is_string(object)); @@ -235,41 +189,23 @@ static void test_sfs(const char *plugin_dir) ok(strcmp(object_str, "get-something") == 0, "bt_component_class_query() receives the expected object name"); res_params = bt_value_array_borrow_element_by_index(results, 1); - ok(res_params == bt_value_borrow_from_private(params), + ok(res_params == bt_private_value_borrow_value(params), "bt_component_class_query() receives the expected parameters"); - diag("> putting the plugin object here"); - BT_OBJECT_PUT_REF_AND_RESET(plugin); - graph = bt_private_graph_create(); - BT_ASSERT(graph); - graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink", - NULL, &sink_component); - ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component, - "bt_private_graph_add_component() still works after the plugin object is destroyed"); - BT_OBJECT_PUT_REF_AND_RESET(sink_component); - BT_OBJECT_PUT_REF_AND_RESET(source_comp_class); - bt_object_put_ref(graph); + bt_object_get_ref(sink_comp_class); + diag("> putting the plugin set object here"); + BT_OBJECT_PUT_REF_AND_RESET(plugin_set); graph = bt_private_graph_create(); BT_ASSERT(graph); - graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink", + graph_ret = bt_private_graph_add_sink_component(graph, sink_comp_class, "the-sink", NULL, &sink_component); ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component, - "bt_private_graph_add_component() still works after the source component class object is destroyed"); + "bt_private_graph_add_sink_component() still works after the plugin object is destroyed"); BT_OBJECT_PUT_REF_AND_RESET(sink_component); - BT_OBJECT_PUT_REF_AND_RESET(filter_comp_class); bt_object_put_ref(graph); - graph = bt_private_graph_create(); - BT_ASSERT(graph); - graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink", - NULL, &sink_component); - ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component, - "bt_private_graph_add_component() still works after the filter component class object is destroyed"); - BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); - BT_OBJECT_PUT_REF_AND_RESET(sink_component); free(sfs_path); - bt_object_put_ref(graph); - bt_object_put_ref(plugin_set); + bt_object_put_ref(sink_comp_class); bt_object_put_ref(results); bt_object_put_ref(params); bt_object_put_ref(query_exec); @@ -300,12 +236,8 @@ static void test_find(const char *plugin_dir) { int ret; struct bt_plugin *plugin; - struct bt_component_class *comp_cls_sink; - struct bt_component_class *comp_cls_source; char *plugin_path; - ok(!bt_plugin_find(NULL), - "bt_plugin_find() handles NULL"); ok(!bt_plugin_find(NON_EXISTING_PATH), "bt_plugin_find() returns NULL with an unknown plugin name"); ret = asprintf(&plugin_path, "%s" G_SEARCHPATH_SEPARATOR_S @@ -323,27 +255,6 @@ static void test_find(const char *plugin_dir) ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0, "bt_plugin_find() finds the correct plugin for a given name"); BT_OBJECT_PUT_REF_AND_RESET(plugin); - comp_cls_sink = bt_plugin_find_component_class(NULL, "sink", - BT_COMPONENT_CLASS_TYPE_SINK); - ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (plugin name)"); - comp_cls_sink = bt_plugin_find_component_class("test_sfs", NULL, - BT_COMPONENT_CLASS_TYPE_SINK); - ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (component class name)"); - comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink2", - BT_COMPONENT_CLASS_TYPE_SINK); - ok(!comp_cls_sink, "bt_plugin_find_component_class() fails with an unknown component class name"); - comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink", - BT_COMPONENT_CLASS_TYPE_SINK); - ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with valid parameters"); - ok(strcmp(bt_component_class_get_name(comp_cls_sink), "sink") == 0, - "bt_plugin_find_component_class() returns the appropriate component class (sink)"); - comp_cls_source = bt_plugin_find_component_class("test_sfs", "source", - BT_COMPONENT_CLASS_TYPE_SOURCE); - ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with another component class name (same plugin)"); - ok(strcmp(bt_component_class_get_name(comp_cls_source), "source") == 0, - "bt_plugin_find_component_class() returns the appropriate component class (source)"); - BT_OBJECT_PUT_REF_AND_RESET(comp_cls_sink); - BT_OBJECT_PUT_REF_AND_RESET(comp_cls_source); free(plugin_path); } @@ -360,7 +271,6 @@ int main(int argc, char **argv) plugin_dir = argv[1]; plan_tests(NR_TESTS); - test_invalid(plugin_dir); test_minimal(plugin_dir); test_sfs(plugin_dir); test_create_all_from_dir(plugin_dir);