From 890882eff34b4cba6f08a25f8ca56866c20b3fbe Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 28 Mar 2017 14:14:42 -0400 Subject: [PATCH] Visibility: split graph API into public and private interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The goal here is to avoid that a component or a graph user calls methods that do not logically apply to itself, but should according to the API's intention. For example, a component should not be able to remove the ports of another component, and a graph user should not be able to create a notification iterator directly. Therefore the existing bt_component, bt_port, bt_connection, and bt_notification_iterator objects are considered "public": any user can call their API. The user-defined methods (callbacks) now accept private versions of those objects: * bt_private_component * bt_private_port * bt_private_connection * bt_private_notification_iterator This ensures that only the user which is called back with those private objects can call specific, private methods, which start with the `bt_private_` prefix. For example, any user can get a sink component's input port by name with bt_component_sink_get_input_port(). This function accepts a bt_component object parameter and returns a bt_port object. However, only the called back user can get its private version of the port with the equivalent bt_private_component_sink_get_input_private_port(). This function accepts a bt_private_component object parameter and returns a bt_private_port object. The private port API has the bt_private_port_remove_from_component() function: thus only the owner component of a port can remove it from itself. Each private API has a bt_OBJ_from_private_OBJ() function which returns a _new reference_ to the equivalent public object of a private object to be able to call public functions. With all this, if a user calls a private function with a public object, the compiler emits a warning similar to: warning: assignment from incompatible pointer type With GCC and Clang, you can make this warning an error with: -Werror=incompatible-pointer-types Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 11 +- .../component/component-class-sink.h | 4 +- .../babeltrace/component/component-class.h | 33 +++--- .../component/component-filter-internal.h | 14 --- .../babeltrace/component/component-filter.h | 1 - .../babeltrace/component/component-internal.h | 18 ++- include/babeltrace/component/component-sink.h | 5 - .../component/component-source-internal.h | 14 --- .../babeltrace/component/component-source.h | 4 - include/babeltrace/component/component.h | 18 --- .../component/connection-internal.h | 15 +++ include/babeltrace/component/connection.h | 3 - .../notification/iterator-internal.h | 17 +++ .../component/notification/iterator.h | 20 ---- .../component/notification/private-iterator.h | 56 +++++++++ include/babeltrace/component/port-internal.h | 14 +++ .../component/private-component-filter.h | 75 ++++++++++++ .../component/private-component-sink.h | 57 +++++++++ .../component/private-component-source.h | 57 +++++++++ .../babeltrace/component/private-component.h | 48 ++++++++ .../babeltrace/component/private-connection.h | 45 ++++++++ include/babeltrace/component/private-port.h | 47 ++++++++ lib/component/component.c | 108 +++++------------- lib/component/connection.c | 99 +++++++++++++--- lib/component/filter.c | 92 +++++++++------ lib/component/iterator.c | 28 +++-- lib/component/port.c | 24 +++- lib/component/sink.c | 28 ++++- lib/component/source.c | 48 +++++--- plugins/ctf/fs/fs.c | 42 ++++--- plugins/ctf/fs/fs.h | 16 +-- plugins/ctf/lttng-live/lttng-live-internal.h | 6 +- plugins/ctf/lttng-live/lttng-live.c | 6 +- plugins/muxer/muxer.c | 12 +- plugins/text/text.c | 32 +++--- plugins/utils/dummy/dummy.c | 29 +++-- plugins/utils/dummy/dummy.h | 15 ++- plugins/utils/trimmer/iterator.c | 51 +++++---- plugins/utils/trimmer/iterator.h | 16 ++- plugins/utils/trimmer/trimmer.c | 13 ++- plugins/utils/trimmer/trimmer.h | 8 +- plugins/writer/writer.c | 31 ++--- tests/lib/test-plugin-plugins/sfs.c | 18 +-- 43 files changed, 907 insertions(+), 391 deletions(-) create mode 100644 include/babeltrace/component/notification/private-iterator.h create mode 100644 include/babeltrace/component/private-component-filter.h create mode 100644 include/babeltrace/component/private-component-sink.h create mode 100644 include/babeltrace/component/private-component-source.h create mode 100644 include/babeltrace/component/private-component.h create mode 100644 include/babeltrace/component/private-connection.h create mode 100644 include/babeltrace/component/private-port.h diff --git a/include/Makefile.am b/include/Makefile.am index b4d86ecc..94676992 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -49,7 +49,8 @@ babeltracecomponentnotifinclude_HEADERS = \ babeltrace/component/notification/packet.h \ babeltrace/component/notification/schema.h \ babeltrace/component/notification/stream.h \ - babeltrace/component/notification/heap.h + babeltrace/component/notification/heap.h \ + babeltrace/component/notification/private-iterator.h babeltracecomponentinclude_HEADERS = \ babeltrace/component/component.h \ @@ -62,7 +63,13 @@ babeltracecomponentinclude_HEADERS = \ babeltrace/component/graph.h \ babeltrace/component/component-source.h \ babeltrace/component/component-sink.h \ - babeltrace/component/component-filter.h + babeltrace/component/component-filter.h \ + babeltrace/component/private-connection.h \ + babeltrace/component/private-port.h \ + babeltrace/component/private-component.h \ + babeltrace/component/private-component-source.h \ + babeltrace/component/private-component-sink.h \ + babeltrace/component/private-component-filter.h noinst_HEADERS = \ babeltrace/align.h \ diff --git a/include/babeltrace/component/component-class-sink.h b/include/babeltrace/component/component-class-sink.h index 8b3ed62d..b93b51d6 100644 --- a/include/babeltrace/component/component-class-sink.h +++ b/include/babeltrace/component/component-class-sink.h @@ -25,7 +25,7 @@ * SOFTWARE. */ -#include +#include #ifdef __cplusplus extern "C" { @@ -34,7 +34,7 @@ extern "C" { struct bt_component_class; typedef enum bt_component_status (*bt_component_class_sink_consume_method)( - struct bt_component *); + struct bt_private_component *private_component); extern struct bt_component_class *bt_component_class_sink_create(const char *name, diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index 823301a2..f4761bea 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -34,10 +34,10 @@ extern "C" { struct bt_component_class; struct bt_component; -struct bt_port; -struct bt_connection; +struct bt_private_component; +struct bt_private_port; struct bt_value; -struct bt_notification_iterator; +struct bt_private_notification_iterator; /** * Component class type. @@ -56,38 +56,43 @@ enum bt_component_class_type { }; typedef enum bt_component_status (*bt_component_class_init_method)( - struct bt_component *component, struct bt_value *params, - void *init_method_data); + struct bt_private_component *private_component, + struct bt_value *params, void *init_method_data); -typedef void (*bt_component_class_destroy_method)(struct bt_component *component); +typedef void (*bt_component_class_destroy_method)( + struct bt_private_component *private_component); typedef enum bt_notification_iterator_status (*bt_component_class_notification_iterator_init_method)( - struct bt_component *component, - struct bt_notification_iterator *iterator, void *init_method_data); + struct bt_private_component *private_component, + struct bt_private_port *private_port, + struct bt_private_notification_iterator *private_notification_iterator); typedef void (*bt_component_class_notification_iterator_destroy_method)( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *private_notification_iterator); typedef struct bt_notification *(*bt_component_class_notification_iterator_get_method)( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *private_notification_iterator); typedef enum bt_notification_iterator_status (*bt_component_class_notification_iterator_next_method)( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *private_notification_iterator); typedef enum bt_notification_iterator_status (*bt_component_class_notification_iterator_seek_time_method)( - struct bt_notification_iterator *iterator, int64_t time); + struct bt_private_notification_iterator *private_notification_iterator, + int64_t time); typedef struct bt_value *(*bt_component_class_query_method)( struct bt_component_class *component_class, const char *object, struct bt_value *params); typedef enum bt_component_status (*bt_component_class_accept_port_connection_method)( - struct bt_component *component, struct bt_port *port); + struct bt_private_component *private_component, + struct bt_private_port *private_port); typedef void (*bt_component_class_port_disconnected_method)( - struct bt_component *component, struct bt_port *port); + 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, diff --git a/include/babeltrace/component/component-filter-internal.h b/include/babeltrace/component/component-filter-internal.h index 68598346..71690cad 100644 --- a/include/babeltrace/component/component-filter-internal.h +++ b/include/babeltrace/component/component-filter-internal.h @@ -61,18 +61,4 @@ BT_HIDDEN enum bt_component_status bt_component_filter_validate( struct bt_component *component); -/** - * Create an iterator on a component instance. - * - * @param component Component instance - * @returns Notification iterator instance - */ -BT_HIDDEN -struct bt_notification_iterator *bt_component_filter_create_notification_iterator( - struct bt_component *component); - -BT_HIDDEN -struct bt_notification_iterator *bt_component_filter_create_notification_iterator_with_init_method_data( - struct bt_component *component, void *init_method_data); - #endif /* BABELTRACE_COMPONENT_FILTER_INTERNAL_H */ diff --git a/include/babeltrace/component/component-filter.h b/include/babeltrace/component/component-filter.h index cda188eb..6f42d4e9 100644 --- a/include/babeltrace/component/component-filter.h +++ b/include/babeltrace/component/component-filter.h @@ -36,7 +36,6 @@ extern "C" { struct bt_port; struct bt_component; -struct bt_notification_iterator; extern enum bt_component_status bt_component_filter_get_input_port_count( struct bt_component *component, uint64_t *count); diff --git a/include/babeltrace/component/component-internal.h b/include/babeltrace/component/component-internal.h index 183db686..c12b3b36 100644 --- a/include/babeltrace/component/component-internal.h +++ b/include/babeltrace/component/component-internal.h @@ -47,7 +47,7 @@ struct bt_component { * Internal destroy function specific to a source, filter, or * sink component object. */ - bt_component_class_destroy_method destroy; + void (*destroy)(struct bt_component *); /* User-defined data */ void *user_data; @@ -63,9 +63,19 @@ struct bt_component { GPtrArray *output_ports; }; -BT_HIDDEN -struct bt_notification_iterator *bt_component_create_iterator( - struct bt_component *component, void *init_method_data); +static inline +struct bt_component *bt_component_from_private( + struct bt_private_component *private_component) +{ + return (void *) private_component; +} + +static inline +struct bt_private_component *bt_private_component_from_component( + struct bt_component *component) +{ + return (void *) component; +} BT_HIDDEN enum bt_component_status bt_component_accept_port_connection( diff --git a/include/babeltrace/component/component-sink.h b/include/babeltrace/component/component-sink.h index e5271621..924f8c74 100644 --- a/include/babeltrace/component/component-sink.h +++ b/include/babeltrace/component/component-sink.h @@ -42,11 +42,6 @@ extern struct bt_port *bt_component_sink_get_input_port( struct bt_component *component, const char *name); extern struct bt_port *bt_component_sink_get_input_port_at_index( struct bt_component *component, int index); - -/* Only allowed during the sink's initialization. */ -extern struct bt_port *bt_component_sink_add_input_port( - struct bt_component *component, const char *name); -/* Only allowed during the sink's initialization. */ extern struct bt_port *bt_component_sink_get_default_input_port( struct bt_component *component); diff --git a/include/babeltrace/component/component-source-internal.h b/include/babeltrace/component/component-source-internal.h index 458cc7d2..0a68e8a5 100644 --- a/include/babeltrace/component/component-source-internal.h +++ b/include/babeltrace/component/component-source-internal.h @@ -61,18 +61,4 @@ BT_HIDDEN enum bt_component_status bt_component_source_validate( struct bt_component *component); -/** - * Create an iterator on a component instance. - * - * @param component Component instance - * @returns Notification iterator instance - */ -BT_HIDDEN -struct bt_notification_iterator *bt_component_source_create_notification_iterator( - struct bt_component *component); - -BT_HIDDEN -struct bt_notification_iterator *bt_component_source_create_notification_iterator_with_init_method_data( - struct bt_component *component, void *init_method_data); - #endif /* BABELTRACE_COMPONENT_SOURCE_INTERNAL_H */ diff --git a/include/babeltrace/component/component-source.h b/include/babeltrace/component/component-source.h index 84e80c3a..94ebf707 100644 --- a/include/babeltrace/component/component-source.h +++ b/include/babeltrace/component/component-source.h @@ -46,10 +46,6 @@ extern struct bt_port *bt_component_source_get_output_port_at_index( extern struct bt_port *bt_component_source_get_default_output_port( struct bt_component *component); -/* Only allowed during the source's initialization. */ -extern struct bt_port *bt_component_source_add_output_port( - struct bt_component *component, const char *name); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/component.h b/include/babeltrace/component/component.h index 0a2f70d7..1d884968 100644 --- a/include/babeltrace/component/component.h +++ b/include/babeltrace/component/component.h @@ -85,24 +85,6 @@ extern struct bt_component *bt_component_create_with_init_method_data( struct bt_component_class *component_class, const char *name, struct bt_value *params, void *init_method_data); -/** - * Get a component's private data. - * - * @param component Component of which to get the private data - * @returns Component's private data - */ -extern void *bt_component_get_private_data(struct bt_component *component); - -/** - * Set a component's private data. - * - * @param component Component of which to set the private data - * @param data Component private data - * @returns One of #bt_component_status values - */ -extern enum bt_component_status bt_component_set_private_data( - struct bt_component *component, void *data); - /** * Get component's name. * diff --git a/include/babeltrace/component/connection-internal.h b/include/babeltrace/component/connection-internal.h index 74144cd5..10533aff 100644 --- a/include/babeltrace/component/connection-internal.h +++ b/include/babeltrace/component/connection-internal.h @@ -28,6 +28,7 @@ */ #include +#include #include struct bt_graph; @@ -49,6 +50,20 @@ struct bt_connection { struct bt_port *upstream_port; }; +static inline +struct bt_connection *bt_connection_from_private( + struct bt_private_connection *private_connection) +{ + return (void *) private_connection; +} + +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, diff --git a/include/babeltrace/component/connection.h b/include/babeltrace/component/connection.h index 4f79359c..4fe1d4c3 100644 --- a/include/babeltrace/component/connection.h +++ b/include/babeltrace/component/connection.h @@ -41,9 +41,6 @@ extern struct bt_port *bt_connection_get_downstream_port( extern struct bt_port *bt_connection_get_upstream_port( struct bt_connection *connection); -extern struct bt_notification_iterator * -bt_connection_create_notification_iterator(struct bt_connection *connection); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/notification/iterator-internal.h b/include/babeltrace/component/notification/iterator-internal.h index 8bad9f93..99e9617c 100644 --- a/include/babeltrace/component/notification/iterator-internal.h +++ b/include/babeltrace/component/notification/iterator-internal.h @@ -28,8 +28,10 @@ */ #include +#include #include #include +#include struct bt_notification_iterator { struct bt_object base; @@ -37,6 +39,21 @@ struct bt_notification_iterator { void *user_data; }; +static inline +struct bt_notification_iterator *bt_notification_iterator_from_private( + struct bt_private_notification_iterator *private_notification_iterator) +{ + return (void *) private_notification_iterator; +} + +static inline +struct bt_private_notification_iterator * +bt_private_notification_iterator_from_notification_iterator( + struct bt_notification_iterator *notification_iterator) +{ + return (void *) notification_iterator; +} + /** * Allocate a notification iterator. * diff --git a/include/babeltrace/component/notification/iterator.h b/include/babeltrace/component/notification/iterator.h index 26583c3a..bc226e13 100644 --- a/include/babeltrace/component/notification/iterator.h +++ b/include/babeltrace/component/notification/iterator.h @@ -126,26 +126,6 @@ extern enum bt_notification_iterator_status bt_notification_iterator_seek_time( extern struct bt_component *bt_notification_iterator_get_component( struct bt_notification_iterator *iterator); -/** - * Set an iterator's private data. - * - * @param iterator Notification iterator instance - * @param data Iterator private data - * @returns One of #bt_notification_iterator_status values - */ -extern enum bt_notification_iterator_status -bt_notification_iterator_set_private_data( - struct bt_notification_iterator *iterator, void *data); - -/** - * Get an iterator's private data. - * - * @param iterator Notification iterator instance - * @returns Iterator instance private data - */ -extern void *bt_notification_iterator_get_private_data( - struct bt_notification_iterator *iterator); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/notification/private-iterator.h b/include/babeltrace/component/notification/private-iterator.h new file mode 100644 index 00000000..9cc8c664 --- /dev/null +++ b/include/babeltrace/component/notification/private-iterator.h @@ -0,0 +1,56 @@ +#ifndef BABELTRACE_COMPONENT_NOTIFICATION_PRIVATE_ITERATOR_H +#define BABELTRACE_COMPONENT_NOTIFICATION_PRIVATE_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_notification_iterator; + +struct bt_notification_iterator * +bt_notification_iterator_from_private_notification_iterator( + struct bt_private_notification_iterator *private_notification_iterator); + +extern struct bt_private_component * +bt_private_notification_iterator_get_private_component( + struct bt_private_notification_iterator *private_notification_iterator); + +extern enum bt_notification_iterator_status +bt_private_notification_iterator_set_user_data( + struct bt_private_notification_iterator *private_notification_iterator, + void *user_data); + +extern void *bt_private_notification_iterator_get_user_data( + struct bt_private_notification_iterator *private_notification_iterator); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_NOTIFICATION_PRIVATE_ITERATOR_H */ diff --git a/include/babeltrace/component/port-internal.h b/include/babeltrace/component/port-internal.h index f693b2de..fb4ff727 100644 --- a/include/babeltrace/component/port-internal.h +++ b/include/babeltrace/component/port-internal.h @@ -40,6 +40,20 @@ struct bt_port { struct bt_connection *connection; }; +static inline +struct bt_port *bt_port_from_private( + struct bt_private_port *private_port) +{ + return (void *) private_port; +} + +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); diff --git a/include/babeltrace/component/private-component-filter.h b/include/babeltrace/component/private-component-filter.h new file mode 100644 index 00000000..e54ccc4a --- /dev/null +++ b/include/babeltrace/component/private-component-filter.h @@ -0,0 +1,75 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SINK_H +#define BABELTRACE_COMPONENT_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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_private_component; +struct bt_private_port; + +extern struct bt_private_port * +bt_private_component_filter_get_output_private_port( + struct bt_private_component *private_component, + const char *name); + +extern struct bt_private_port * +bt_private_component_filter_get_output_private_port_at_index( + struct bt_private_component *private_component, int index); + +extern struct bt_private_port * +bt_private_component_filter_get_default_output_private_port( + struct bt_private_component *private_component); + +extern struct bt_private_port * +bt_private_component_filter_add_output_private_port( + struct bt_private_component *private_component, + const char *name); + +extern struct bt_private_port * +bt_private_component_filter_get_input_private_port( + struct bt_private_component *private_component, + const char *name); + +extern struct bt_private_port * +bt_private_component_filter_get_input_private_port_at_index( + struct bt_private_component *private_component, int index); + +extern struct bt_private_port * +bt_private_component_filter_get_default_input_private_port( + struct bt_private_component *private_component); + +extern struct bt_private_port * +bt_private_component_filter_add_input_private_port( + struct bt_private_component *private_component, + const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SINK_H */ diff --git a/include/babeltrace/component/private-component-sink.h b/include/babeltrace/component/private-component-sink.h new file mode 100644 index 00000000..f1ba7a71 --- /dev/null +++ b/include/babeltrace/component/private-component-sink.h @@ -0,0 +1,57 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SINK_H +#define BABELTRACE_COMPONENT_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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_private_component; +struct bt_private_port; + +extern struct bt_private_port * +bt_private_component_sink_get_input_private_port( + struct bt_private_component *private_component, + const char *name); + +extern struct bt_private_port * +bt_private_component_sink_get_input_private_port_at_index( + struct bt_private_component *private_component, int index); + +extern struct bt_private_port * +bt_private_component_sink_get_default_input_private_port( + struct bt_private_component *private_component); + +extern struct bt_private_port * +bt_private_component_sink_add_input_private_port( + struct bt_private_component *private_component, + const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SINK_H */ diff --git a/include/babeltrace/component/private-component-source.h b/include/babeltrace/component/private-component-source.h new file mode 100644 index 00000000..b54bbfb8 --- /dev/null +++ b/include/babeltrace/component/private-component-source.h @@ -0,0 +1,57 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SOURCE_H +#define BABELTRACE_COMPONENT_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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_private_component; +struct bt_private_port; + +extern struct bt_private_port * +bt_private_component_source_get_output_private_port( + struct bt_private_component *private_component, + const char *name); + +extern struct bt_private_port * +bt_private_component_source_get_output_private_port_at_index( + struct bt_private_component *private_component, int index); + +extern struct bt_private_port * +bt_private_component_source_get_default_output_private_port( + struct bt_private_component *private_component); + +extern struct bt_private_port * +bt_private_component_source_add_output_private_port( + struct bt_private_component *private_component, + const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_PRIVATE_COMPONENT_SOURCE_H */ diff --git a/include/babeltrace/component/private-component.h b/include/babeltrace/component/private-component.h new file mode 100644 index 00000000..e19b6ff2 --- /dev/null +++ b/include/babeltrace/component/private-component.h @@ -0,0 +1,48 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_COMPONENT_H +#define BABELTRACE_COMPONENT_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. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_private_component; + +struct bt_component *bt_component_from_private_component( + 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_COMPONENT_PRIVATE_COMPONENT_H */ diff --git a/include/babeltrace/component/private-connection.h b/include/babeltrace/component/private-connection.h new file mode 100644 index 00000000..76294604 --- /dev/null +++ b/include/babeltrace/component/private-connection.h @@ -0,0 +1,45 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_CONNECTION_H +#define BABELTRACE_COMPONENT_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. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_connection; +struct bt_private_port; +struct bt_private_connection; + +struct bt_connection *bt_connection_from_private_connection( + struct bt_private_connection *private_connection); + +extern struct bt_notification_iterator * +bt_private_connection_create_notification_iterator( + struct bt_private_connection *private_connection); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_PRIVATE_CONNECTION_H */ diff --git a/include/babeltrace/component/private-port.h b/include/babeltrace/component/private-port.h new file mode 100644 index 00000000..2f0e49db --- /dev/null +++ b/include/babeltrace/component/private-port.h @@ -0,0 +1,47 @@ +#ifndef BABELTRACE_COMPONENT_PRIVATE_PORT_H +#define BABELTRACE_COMPONENT_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_from_private_port(struct bt_private_port *private_port); +extern struct bt_private_connection *bt_private_port_get_private_connection( + struct bt_private_port *private_port); +extern struct bt_private_component *bt_private_port_get_private_component( + struct bt_private_port *private_port); +extern int bt_private_port_remove_from_component( + struct bt_private_port *private_port); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_PRIVATE_PORT_H */ diff --git a/lib/component/component.c b/lib/component/component.c index d55526c8..9a239754 100644 --- a/lib/component/component.c +++ b/lib/component/component.c @@ -26,15 +26,18 @@ * SOFTWARE. */ +#include #include #include #include #include #include #include +#include #include #include #include +#include #include #include #include @@ -80,7 +83,8 @@ void bt_component_destroy(struct bt_object *obj) * instance. */ if (component->class->methods.destroy) { - component->class->methods.destroy(component); + component->class->methods.destroy( + bt_private_component_from_component(component)); } if (component->destroy) { @@ -100,84 +104,16 @@ void bt_component_destroy(struct bt_object *obj) g_free(component); } -enum bt_component_class_type bt_component_get_class_type( - struct bt_component *component) +struct bt_component *bt_component_from_private_component( + struct bt_private_component *private_component) { - return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN; + return bt_get(bt_component_from_private(private_component)); } -BT_HIDDEN -struct bt_notification_iterator *bt_component_create_iterator( - struct bt_component *component, void *init_method_data) +enum bt_component_class_type bt_component_get_class_type( + struct bt_component *component) { - enum bt_notification_iterator_status ret_iterator; - enum bt_component_class_type type; - struct bt_notification_iterator *iterator = NULL; - struct bt_component_class *class = component->class; - - if (!component) { - goto error; - } - - type = bt_component_get_class_type(component); - if (type != BT_COMPONENT_CLASS_TYPE_SOURCE && - type != BT_COMPONENT_CLASS_TYPE_FILTER) { - /* Unsupported operation. */ - goto error; - } - - iterator = bt_notification_iterator_create(component); - if (!iterator) { - goto error; - } - - switch (type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - struct bt_component_class_source *source_class; - enum bt_notification_iterator_status status; - - source_class = container_of(class, struct bt_component_class_source, parent); - - if (source_class->methods.iterator.init) { - status = source_class->methods.iterator.init(component, - iterator, init_method_data); - if (status < 0) { - goto error; - } - } - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - struct bt_component_class_filter *filter_class; - enum bt_notification_iterator_status status; - - filter_class = container_of(class, struct bt_component_class_filter, parent); - - if (filter_class->methods.iterator.init) { - status = filter_class->methods.iterator.init(component, - iterator, init_method_data); - if (status < 0) { - goto error; - } - } - break; - } - default: - /* Unreachable. */ - assert(0); - } - - ret_iterator = bt_notification_iterator_validate(iterator); - if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) { - goto error; - } - - return iterator; -error: - BT_PUT(iterator); - return iterator; + return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN; } static @@ -326,7 +262,8 @@ struct bt_component *bt_component_create_with_init_method_data( component->initializing = true; if (component_class->methods.init) { - ret = component_class->methods.init(component, params, + ret = component_class->methods.init( + bt_private_component_from_component(component), params, init_method_data); component->initializing = false; if (ret != BT_COMPONENT_STATUS_OK) { @@ -390,15 +327,21 @@ struct bt_component_class *bt_component_get_class( return component ? bt_get(component->class) : NULL; } -void *bt_component_get_private_data(struct bt_component *component) +void *bt_private_component_get_user_data( + struct bt_private_component *private_component) { + struct bt_component *component = + bt_component_from_private(private_component); + return component ? component->user_data : NULL; } -enum bt_component_status -bt_component_set_private_data(struct bt_component *component, +enum bt_component_status bt_private_component_set_user_data( + struct bt_private_component *private_component, void *data) { + struct bt_component *component = + bt_component_from_private(private_component); enum bt_component_status ret = BT_COMPONENT_STATUS_OK; if (!component || !component->initializing) { @@ -600,7 +543,8 @@ enum bt_component_status bt_component_accept_port_connection( if (comp->class->methods.accept_port_connection) { status = comp->class->methods.accept_port_connection( - comp, port); + bt_private_component_from_component(comp), + bt_private_port_from_port(port)); } return status; @@ -614,6 +558,8 @@ void bt_component_port_disconnected(struct bt_component *comp, assert(port); if (comp->class->methods.port_disconnected) { - comp->class->methods.port_disconnected(comp, port); + comp->class->methods.port_disconnected( + bt_private_component_from_component(comp), + bt_private_port_from_port(port)); } } diff --git a/lib/component/connection.c b/lib/component/connection.c index 702db81d..87d96778 100644 --- a/lib/component/connection.c +++ b/lib/component/connection.c @@ -26,10 +26,12 @@ * SOFTWARE. */ +#include #include #include #include #include +#include #include #include #include @@ -49,6 +51,12 @@ void bt_connection_destroy(struct bt_object *obj) g_free(connection); } +struct bt_connection *bt_connection_from_private_connection( + struct bt_private_connection *private_connection) +{ + return bt_get(bt_connection_from_private(private_connection)); +} + BT_HIDDEN struct bt_connection *bt_connection_create( struct bt_graph *graph, @@ -101,14 +109,12 @@ void bt_connection_disconnect_ports(struct bt_connection *conn, conn->upstream_port = NULL; } - if (downstream_comp && downstream_comp != acting_comp && - downstream_comp->class->methods.port_disconnected) { + if (downstream_comp && downstream_comp != acting_comp) { bt_component_port_disconnected(downstream_comp, downstream_port); } - if (upstream_comp && upstream_comp != acting_comp && - upstream_comp->class->methods.port_disconnected) { + if (upstream_comp && upstream_comp != acting_comp) { bt_component_port_disconnected(upstream_comp, upstream_port); } @@ -148,35 +154,94 @@ struct bt_port *bt_connection_get_downstream_port( } struct bt_notification_iterator * -bt_connection_create_notification_iterator(struct bt_connection *connection) +bt_private_connection_create_notification_iterator( + struct bt_private_connection *private_connection) { + enum bt_notification_iterator_status ret_iterator; + enum bt_component_class_type upstream_comp_class_type; + struct bt_notification_iterator *iterator = NULL; + struct bt_port *upstream_port = NULL; struct bt_component *upstream_component = NULL; - struct bt_notification_iterator *it = NULL; + struct bt_component_class *upstream_comp_class = NULL; + struct bt_connection *connection = NULL; + bt_component_class_notification_iterator_init_method init_method = NULL; - if (!connection) { - goto end; + if (!private_connection) { + goto error; } + connection = bt_connection_from_private(private_connection); + if (!connection->upstream_port || !connection->downstream_port) { - goto end; + goto error; } - upstream_component = bt_port_get_component(connection->upstream_port); + upstream_port = connection->upstream_port; + assert(upstream_port); + upstream_component = bt_port_get_component(upstream_port); assert(upstream_component); + upstream_comp_class = upstream_component->class; + + if (!upstream_component) { + goto error; + } + + upstream_comp_class_type = + bt_component_get_class_type(upstream_component); + if (upstream_comp_class_type != BT_COMPONENT_CLASS_TYPE_SOURCE && + upstream_comp_class_type != BT_COMPONENT_CLASS_TYPE_FILTER) { + /* Unsupported operation. */ + goto error; + } - switch (bt_component_get_class_type(upstream_component)) { + iterator = bt_notification_iterator_create(upstream_component); + if (!iterator) { + goto error; + } + + switch (upstream_comp_class_type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: - it = bt_component_source_create_notification_iterator( - upstream_component); + { + 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: - it = bt_component_filter_create_notification_iterator( - upstream_component); + { + 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: - goto end; + /* Unreachable. */ + assert(0); + } + + if (init_method) { + enum bt_notification_iterator_status status = init_method( + bt_private_component_from_component(upstream_component), + bt_private_port_from_port(upstream_port), + bt_private_notification_iterator_from_notification_iterator(iterator)); + if (status < 0) { + goto error; + } + } + + ret_iterator = bt_notification_iterator_validate(iterator); + if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + goto error; } + + goto end; + +error: + BT_PUT(iterator); + end: bt_put(upstream_component); - return it; + return iterator; } diff --git a/lib/component/filter.c b/lib/component/filter.c index da08c7fe..2b1eb51f 100644 --- a/lib/component/filter.c +++ b/lib/component/filter.c @@ -34,20 +34,6 @@ #include #include -BT_HIDDEN -struct bt_notification_iterator *bt_component_filter_create_notification_iterator( - struct bt_component *component) -{ - return bt_component_create_iterator(component, NULL); -} - -BT_HIDDEN -struct bt_notification_iterator *bt_component_filter_create_notification_iterator_with_init_method_data( - struct bt_component *component, void *init_method_data) -{ - return bt_component_create_iterator(component, init_method_data); -} - BT_HIDDEN void bt_component_filter_destroy(struct bt_component *component) { @@ -147,21 +133,6 @@ struct bt_port *bt_component_filter_get_default_input_port( DEFAULT_INPUT_PORT_NAME); } -struct bt_port *bt_component_filter_add_input_port( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; - - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - goto end; - } - - port = bt_component_add_input_port(component, name); -end: - return port; -} - enum bt_component_status bt_component_filter_get_output_port_count( struct bt_component *component, uint64_t *count) { @@ -215,10 +186,67 @@ struct bt_port *bt_component_filter_get_default_output_port( DEFAULT_OUTPUT_PORT_NAME); } -struct bt_port *bt_component_filter_add_output_port( - struct bt_component *component, const char *name) +struct bt_private_port * +bt_private_component_filter_get_input_private_port_at_index( + struct bt_private_component *private_component, int index) +{ + return bt_private_port_from_port( + bt_component_filter_get_input_port_at_index( + bt_component_from_private(private_component), index)); +} + +struct bt_private_port * +bt_private_component_filter_get_default_private_input_port( + struct bt_private_component *private_component) +{ + return bt_private_port_from_port( + bt_component_filter_get_default_input_port( + bt_component_from_private(private_component))); +} + +struct bt_private_port *bt_private_component_filter_add_input_private_port( + struct bt_private_component *private_component, + const char *name) +{ + struct bt_port *port = NULL; + struct bt_component *component = + bt_component_from_private(private_component); + + if (!component || + component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + goto end; + } + + port = bt_component_add_input_port(component, name); +end: + return bt_private_port_from_port(port); +} + +struct bt_private_port * +bt_private_component_filter_get_output_private_port_at_index( + struct bt_private_component *private_component, int index) +{ + return bt_private_port_from_port( + bt_component_filter_get_output_port_at_index( + bt_component_from_private(private_component), index)); +} + +struct bt_private_port * +bt_private_component_filter_get_default_private_output_port( + struct bt_private_component *private_component) +{ + return bt_private_port_from_port( + bt_component_filter_get_default_output_port( + bt_component_from_private(private_component))); +} + +struct bt_private_port *bt_private_component_filter_add_output_private_port( + struct bt_private_component *private_component, + const char *name) { struct bt_port *port = NULL; + struct bt_component *component = + bt_component_from_private(private_component); if (!component || component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { @@ -227,5 +255,5 @@ struct bt_port *bt_component_filter_add_output_port( port = bt_component_add_output_port(component, name); end: - return port; + return bt_private_port_from_port(port); } diff --git a/lib/component/iterator.c b/lib/component/iterator.c index cffa0d91..78a76c2a 100644 --- a/lib/component/iterator.c +++ b/lib/component/iterator.c @@ -55,7 +55,8 @@ void bt_notification_iterator_destroy(struct bt_object *obj) source_class = container_of(comp_class, struct bt_component_class_source, parent); if (source_class->methods.iterator.destroy) { - source_class->methods.iterator.destroy(iterator); + source_class->methods.iterator.destroy( + bt_private_notification_iterator_from_notification_iterator(iterator)); } break; } @@ -66,7 +67,8 @@ void bt_notification_iterator_destroy(struct bt_object *obj) filter_class = container_of(comp_class, struct bt_component_class_filter, parent); if (filter_class->methods.iterator.destroy) { - filter_class->methods.iterator.destroy(iterator); + filter_class->methods.iterator.destroy( + bt_private_notification_iterator_from_notification_iterator(iterator)); } break; } @@ -125,18 +127,24 @@ end: return ret; } -void *bt_notification_iterator_get_private_data( - struct bt_notification_iterator *iterator) +void *bt_private_notification_iterator_get_user_data( + struct bt_private_notification_iterator *private_iterator) { + struct bt_notification_iterator *iterator = + bt_notification_iterator_from_private(private_iterator); + return iterator ? iterator->user_data : NULL; } enum bt_notification_iterator_status -bt_notification_iterator_set_private_data( - struct bt_notification_iterator *iterator, void *data) +bt_private_notification_iterator_set_user_data( + struct bt_private_notification_iterator *private_iterator, + void *data) { enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct bt_notification_iterator *iterator = + bt_notification_iterator_from_private(private_iterator); if (!iterator) { ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; @@ -151,6 +159,8 @@ end: struct bt_notification *bt_notification_iterator_get_notification( struct bt_notification_iterator *iterator) { + struct bt_private_notification_iterator *priv_iterator = + bt_private_notification_iterator_from_notification_iterator(iterator); bt_component_class_notification_iterator_get_method get_method = NULL; assert(iterator); @@ -184,12 +194,14 @@ struct bt_notification *bt_notification_iterator_get_notification( } assert(get_method); - return get_method(iterator); + return get_method(priv_iterator); } enum bt_notification_iterator_status bt_notification_iterator_next(struct bt_notification_iterator *iterator) { + struct bt_private_notification_iterator *priv_iterator = + bt_private_notification_iterator_from_notification_iterator(iterator); bt_component_class_notification_iterator_next_method next_method = NULL; assert(iterator); @@ -223,7 +235,7 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator) } assert(next_method); - return next_method(iterator); + return next_method(priv_iterator); } struct bt_component *bt_notification_iterator_get_component( diff --git a/lib/component/port.c b/lib/component/port.c index e5fcd46c..ed4eda05 100644 --- a/lib/component/port.c +++ b/lib/component/port.c @@ -43,6 +43,12 @@ void bt_port_destroy(struct bt_object *obj) g_free(port); } +struct bt_port *bt_port_from_private_port( + struct bt_private_port *private_port) +{ + return bt_get(bt_port_from_private(private_port)); +} + BT_HIDDEN struct bt_port *bt_port_create(struct bt_component *parent_component, enum bt_port_type type, const char *name) @@ -104,6 +110,20 @@ struct bt_component *bt_port_get_component(struct bt_port *port) return (struct bt_component *) bt_object_get_parent(port); } +struct bt_private_connection *bt_private_port_get_private_connection( + struct bt_private_port *private_port) +{ + return bt_private_connection_from_connection(bt_port_get_connection( + bt_port_from_private(private_port))); +} + +struct bt_private_component *bt_private_port_get_private_component( + struct bt_private_port *private_port) +{ + return bt_private_component_from_component(bt_port_get_component( + bt_port_from_private(private_port))); +} + BT_HIDDEN void bt_port_set_connection(struct bt_port *port, struct bt_connection *connection) @@ -116,9 +136,11 @@ void bt_port_set_connection(struct bt_port *port, port->connection = connection; } -int bt_port_remove_from_component(struct bt_port *port) +int bt_private_port_remove_from_component( + struct bt_private_port *private_port) { int ret = 0; + struct bt_port *port = bt_port_from_private(private_port); struct bt_component *comp = NULL; if (!port) { diff --git a/lib/component/sink.c b/lib/component/sink.c index 338c2968..91fa2353 100644 --- a/lib/component/sink.c +++ b/lib/component/sink.c @@ -95,7 +95,7 @@ enum bt_component_status bt_component_sink_consume( sink_class = container_of(component->class, struct bt_component_class_sink, parent); assert(sink_class->methods.consume); - ret = sink_class->methods.consume(component); + ret = sink_class->methods.consume(bt_private_component_from_component(component)); end: return ret; } @@ -153,10 +153,30 @@ struct bt_port *bt_component_sink_get_default_input_port( DEFAULT_INPUT_PORT_NAME); } -struct bt_port *bt_component_sink_add_input_port( - struct bt_component *component, const char *name) +struct bt_private_port * +bt_private_component_sink_get_input_private_port_at_index( + struct bt_private_component *private_component, int index) +{ + return bt_private_port_from_port( + bt_component_sink_get_input_port_at_index( + bt_component_from_private(private_component), index)); +} + +struct bt_private_port *bt_private_component_sink_get_default_private_input_port( + struct bt_private_component *private_component) +{ + return bt_private_port_from_port( + bt_component_sink_get_default_input_port( + bt_component_from_private(private_component))); +} + +struct bt_private_port *bt_private_component_sink_add_input_private_port( + struct bt_private_component *private_component, + const char *name) { struct bt_port *port = NULL; + struct bt_component *component = + bt_component_from_private(private_component); if (!component || component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { @@ -165,5 +185,5 @@ struct bt_port *bt_component_sink_add_input_port( port = bt_component_add_input_port(component, name); end: - return port; + return bt_private_port_from_port(port); } diff --git a/lib/component/source.c b/lib/component/source.c index da40aa87..bddd2f6a 100644 --- a/lib/component/source.c +++ b/lib/component/source.c @@ -79,20 +79,6 @@ end: return source ? &source->parent : NULL; } -BT_HIDDEN -struct bt_notification_iterator *bt_component_source_create_notification_iterator( - struct bt_component *component) -{ - return bt_component_create_iterator(component, NULL); -} - -BT_HIDDEN -struct bt_notification_iterator *bt_component_source_create_notification_iterator_with_init_method_data( - struct bt_component *component, void *init_method_data) -{ - return bt_component_create_iterator(component, init_method_data); -} - enum bt_component_status bt_component_source_get_output_port_count( struct bt_component *component, uint64_t *count) { @@ -146,10 +132,38 @@ struct bt_port *bt_component_source_get_default_output_port( DEFAULT_OUTPUT_PORT_NAME); } -struct bt_port *bt_component_source_add_output_port( - struct bt_component *component, const char *name) +struct bt_private_port *bt_private_component_source_get_output_private_port( + struct bt_private_component *private_component, + const char *name) +{ + return bt_private_port_from_port(bt_component_source_get_output_port( + bt_component_from_private(private_component), name)); +} + +struct bt_private_port * +bt_private_component_source_get_output_private_port_at_index( + struct bt_private_component *private_component, int index) +{ + return bt_private_port_from_port( + bt_component_source_get_output_port_at_index( + bt_component_from_private(private_component), index)); +} + +struct bt_private_port *bt_private_component_source_get_default_output_private_port( + struct bt_private_component *private_component) +{ + return bt_private_port_from_port( + bt_component_source_get_default_output_port( + bt_component_from_private(private_component))); +} + +struct bt_private_port *bt_private_component_source_add_output_private_port( + struct bt_private_component *private_component, + const char *name) { struct bt_port *port = NULL; + struct bt_component *component = + bt_component_from_private(private_component); if (!component || component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { @@ -158,5 +172,5 @@ struct bt_port *bt_component_source_add_output_port( port = bt_component_add_output_port(component, name); end: - return port; + return bt_private_port_from_port(port); } diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index ee0c5606..4db53f06 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -28,7 +28,10 @@ #include #include +#include +#include #include +#include #include #include #include @@ -51,13 +54,14 @@ BT_HIDDEN bool ctf_fs_debug; enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); struct bt_notification *ctf_fs_iterator_get( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { struct ctf_fs_iterator *ctf_it = - bt_notification_iterator_get_private_data(iterator); + bt_private_notification_iterator_get_user_data( + iterator); if (!ctf_it->current_notification) { (void) ctf_fs_iterator_next(iterator); @@ -246,7 +250,7 @@ end: } enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { int heap_ret; struct bt_ctf_stream *stream = NULL; @@ -256,7 +260,8 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; struct ctf_fs_iterator *ctf_it = - bt_notification_iterator_get_private_data(iterator); + bt_private_notification_iterator_get_user_data( + iterator); notification = bt_notification_heap_pop(ctf_it->pending_notifications); if (!notification && !ctf_it->pending_streams) { @@ -365,9 +370,9 @@ void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it) g_free(ctf_it); } -void ctf_fs_iterator_destroy(struct bt_notification_iterator *it) +void ctf_fs_iterator_destroy(struct bt_private_notification_iterator *it) { - void *data = bt_notification_iterator_get_private_data(it); + void *data = bt_private_notification_iterator_get_user_data(it); ctf_fs_iterator_destroy_data(data); } @@ -584,9 +589,10 @@ end: return ret; } -enum bt_notification_iterator_status ctf_fs_iterator_init(struct bt_component *source, - struct bt_notification_iterator *it, - UNUSED_VAR void *init_method_data) +enum bt_notification_iterator_status ctf_fs_iterator_init( + struct bt_private_component *source, + struct bt_private_port *port, + struct bt_private_notification_iterator *it) { struct ctf_fs_iterator *ctf_it; struct ctf_fs_component *ctf_fs; @@ -594,7 +600,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_init(struct bt_component *s assert(source && it); - ctf_fs = bt_component_get_private_data(source); + ctf_fs = bt_private_component_get_user_data(source); if (!ctf_fs) { ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; goto end; @@ -627,7 +633,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_init(struct bt_component *s goto error; } - ret = bt_notification_iterator_set_private_data(it, ctf_it); + ret = bt_private_notification_iterator_set_user_data(it, ctf_it); if (ret) { goto error; } @@ -635,7 +641,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_init(struct bt_component *s end: return ret; error: - (void) bt_notification_iterator_set_private_data(it, NULL); + (void) bt_private_notification_iterator_set_user_data(it, NULL); ctf_fs_iterator_destroy_data(ctf_it); goto end; } @@ -656,9 +662,9 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs) g_free(ctf_fs); } -void ctf_fs_destroy(struct bt_component *component) +void ctf_fs_destroy(struct bt_private_component *component) { - void *data = bt_component_get_private_data(component); + void *data = bt_private_component_get_user_data(component); ctf_fs_destroy_data(data); } @@ -711,7 +717,7 @@ end: } BT_HIDDEN -enum bt_component_status ctf_fs_init(struct bt_component *source, +enum bt_component_status ctf_fs_init(struct bt_private_component *source, struct bt_value *params, UNUSED_VAR void *init_method_data) { struct ctf_fs_component *ctf_fs; @@ -725,14 +731,14 @@ enum bt_component_status ctf_fs_init(struct bt_component *source, goto end; } - ret = bt_component_set_private_data(source, ctf_fs); + ret = bt_private_component_set_user_data(source, ctf_fs); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } end: return ret; error: - (void) bt_component_set_private_data(source, NULL); + (void) bt_private_component_set_user_data(source, NULL); ctf_fs_destroy_data(ctf_fs); return ret; } diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 80e56c1b..3749137d 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -106,25 +106,25 @@ struct ctf_fs_component { }; BT_HIDDEN -enum bt_component_status ctf_fs_init(struct bt_component *source, +enum bt_component_status ctf_fs_init(struct bt_private_component *source, struct bt_value *params, void *init_method_data); BT_HIDDEN -void ctf_fs_destroy(struct bt_component *component); +void ctf_fs_destroy(struct bt_private_component *component); BT_HIDDEN enum bt_notification_iterator_status ctf_fs_iterator_init( - struct bt_component *source, - struct bt_notification_iterator *it, - void *init_method_data); + struct bt_private_component *source, + struct bt_private_port *port, + struct bt_private_notification_iterator *it); -void ctf_fs_iterator_destroy(struct bt_notification_iterator *it); +void ctf_fs_iterator_destroy(struct bt_private_notification_iterator *it); enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); struct bt_notification *ctf_fs_iterator_get( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); BT_HIDDEN struct bt_value *ctf_fs_query(struct bt_component_class *comp_class, diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index 17d8e87e..61c3f190 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -33,15 +33,15 @@ #define LTTNG_LIVE_COMPONENT_DESCRIPTION "Component implementing an LTTng-live client." BT_HIDDEN -enum bt_component_status lttng_live_init(struct bt_component *source, +enum bt_component_status lttng_live_init(struct bt_private_component *source, struct bt_value *params, void *init_method_data); BT_HIDDEN struct bt_notification *lttng_live_iterator_get( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); BT_HIDDEN enum bt_notification_iterator_status lttng_live_iterator_next( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H */ diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 5f082fcc..6b11e434 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -32,20 +32,20 @@ BT_HIDDEN struct bt_notification *lttng_live_iterator_get( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { return NULL; } BT_HIDDEN enum bt_notification_iterator_status lttng_live_iterator_next( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } BT_HIDDEN -enum bt_component_status lttng_live_init(struct bt_component *component, +enum bt_component_status lttng_live_init(struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { return BT_COMPONENT_STATUS_OK; diff --git a/plugins/muxer/muxer.c b/plugins/muxer/muxer.c index 745e0803..9a58310b 100644 --- a/plugins/muxer/muxer.c +++ b/plugins/muxer/muxer.c @@ -55,15 +55,15 @@ end: } static -void destroy_muxer(struct bt_component *component) +void destroy_muxer(struct bt_private_component *component) { - void *data = bt_component_get_private_data(component); + void *data = bt_private_component_get_user_data(component); destroy_muxer_data(data); } enum bt_component_status muxer_component_init( - struct bt_component *component, struct bt_value *params, + struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -74,7 +74,7 @@ enum bt_component_status muxer_component_init( goto end; } - ret = bt_component_set_private_data(component, muxer); + ret = bt_private_component_set_user_data(component, muxer); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } @@ -87,14 +87,14 @@ error: static struct bt_notification *muxer_iterator_get( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { return NULL; } static enum bt_notification_iterator_status muxer_iterator_next( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } diff --git a/plugins/text/text.c b/plugins/text/text.c index 70111631..ecd6bbea 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -29,9 +29,12 @@ #include #include +#include #include #include +#include #include +#include #include #include #include @@ -106,9 +109,9 @@ error: } static -void destroy_text(struct bt_component *component) +void destroy_text(struct bt_private_component *component) { - void *data = bt_component_get_private_data(component); + void *data = bt_private_component_get_user_data(component); destroy_text_data(data); } @@ -158,20 +161,21 @@ end: } static -enum bt_component_status text_accept_port_connection(struct bt_component *component, - struct bt_port *self_port) +enum bt_component_status text_accept_port_connection( + struct bt_private_component *component, + struct bt_private_port *self_port) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_connection *connection; + struct bt_private_connection *connection; struct text_component *text; - text = bt_component_get_private_data(component); + text = bt_private_component_get_user_data(component); assert(text); assert(!text->input_iterator); - connection = bt_port_get_connection(self_port); + connection = bt_private_port_get_private_connection(self_port); assert(connection); - text->input_iterator = bt_connection_create_notification_iterator( - connection); + text->input_iterator = + bt_private_connection_create_notification_iterator(connection); if (!text->input_iterator) { ret = BT_COMPONENT_STATUS_ERROR; @@ -182,12 +186,13 @@ enum bt_component_status text_accept_port_connection(struct bt_component *compon } static -enum bt_component_status run(struct bt_component *component) +enum bt_component_status run(struct bt_private_component *component) { enum bt_component_status ret; struct bt_notification *notification = NULL; struct bt_notification_iterator *it; - struct text_component *text = bt_component_get_private_data(component); + struct text_component *text = + bt_private_component_get_user_data(component); it = text->input_iterator; @@ -711,7 +716,8 @@ void init_stream_packet_context_quarks(void) static enum bt_component_status text_component_init( - struct bt_component *component, struct bt_value *params, + struct bt_private_component *component, + struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -738,7 +744,7 @@ enum bt_component_status text_component_init( set_use_colors(text); - ret = bt_component_set_private_data(component, text); + ret = bt_private_component_set_user_data(component, text); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } diff --git a/plugins/utils/dummy/dummy.c b/plugins/utils/dummy/dummy.c index 79b8f5ba..3487b6e7 100644 --- a/plugins/utils/dummy/dummy.c +++ b/plugins/utils/dummy/dummy.c @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #include #include #include @@ -38,17 +41,17 @@ void destroy_private_dummy_data(struct dummy *dummy) g_free(dummy); } -void dummy_destroy(struct bt_component *component) +void dummy_destroy(struct bt_private_component *component) { struct dummy *dummy; assert(component); - dummy = bt_component_get_private_data(component); + dummy = bt_private_component_get_user_data(component); assert(dummy); destroy_private_dummy_data(dummy); } -enum bt_component_status dummy_init(struct bt_component *component, +enum bt_component_status dummy_init(struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -66,7 +69,7 @@ enum bt_component_status dummy_init(struct bt_component *component, goto end; } - ret = bt_component_set_private_data(component, dummy); + ret = bt_private_component_set_user_data(component, dummy); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } @@ -77,21 +80,23 @@ error: return ret; } -enum bt_component_status dummy_accept_port_connection(struct bt_component *component, - struct bt_port *self_port) +enum bt_component_status dummy_accept_port_connection( + struct bt_private_component *component, + struct bt_private_port *self_port) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct dummy *dummy; - struct bt_connection *connection; struct bt_notification_iterator *iterator; + struct bt_private_connection *connection; - dummy = bt_component_get_private_data(component); + dummy = bt_private_component_get_user_data(component); assert(dummy); - connection = bt_port_get_connection(self_port); + connection = bt_private_port_get_private_connection(self_port); assert(connection); - iterator = bt_connection_create_notification_iterator(connection); + iterator = bt_private_connection_create_notification_iterator( + connection); if (!iterator) { ret = BT_COMPONENT_STATUS_ERROR; goto end; @@ -103,14 +108,14 @@ end: return ret; } -enum bt_component_status dummy_consume(struct bt_component *component) +enum bt_component_status dummy_consume(struct bt_private_component *component) { enum bt_component_status ret; struct bt_notification *notif = NULL; size_t i; struct dummy *dummy; - dummy = bt_component_get_private_data(component); + dummy = bt_private_component_get_user_data(component); assert(dummy); /* Consume one notification from each iterator. */ diff --git a/plugins/utils/dummy/dummy.h b/plugins/utils/dummy/dummy.h index 0d388cb3..4800d4ff 100644 --- a/plugins/utils/dummy/dummy.h +++ b/plugins/utils/dummy/dummy.h @@ -24,20 +24,19 @@ */ #include -#include -#include -#include +#include +#include struct dummy { GPtrArray *iterators; }; -enum bt_component_status dummy_init(struct bt_component *component, +enum bt_component_status dummy_init(struct bt_private_component *component, struct bt_value *params, void *init_method_data); -void dummy_destroy(struct bt_component *component); +void dummy_destroy(struct bt_private_component *component); enum bt_component_status dummy_accept_port_connection( - struct bt_component *component, - struct bt_port *own_port); -enum bt_component_status dummy_consume(struct bt_component *component); + struct bt_private_component *component, + struct bt_private_port *own_port); +enum bt_component_status dummy_consume(struct bt_private_component *component); #endif /* BABELTRACE_PLUGINS_UTILS_DUMMY_H */ diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index 652e3ac9..fff388b1 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -29,13 +29,16 @@ #include "trimmer.h" #include "iterator.h" #include +#include #include #include #include #include #include -#include -#include +#include +#include +#include +#include #include #include #include @@ -47,11 +50,11 @@ #include BT_HIDDEN -void trimmer_iterator_destroy(struct bt_notification_iterator *it) +void trimmer_iterator_destroy(struct bt_private_notification_iterator *it) { struct trimmer_iterator *it_data; - it_data = bt_notification_iterator_get_private_data(it); + it_data = bt_private_notification_iterator_get_user_data(it); assert(it_data); bt_put(it_data->current_notification); @@ -61,15 +64,15 @@ void trimmer_iterator_destroy(struct bt_notification_iterator *it) BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_init( - struct bt_component *component, - struct bt_notification_iterator *iterator, - UNUSED_VAR void *init_method_data) + struct bt_private_component *component, + struct bt_private_port *port, + struct bt_private_notification_iterator *iterator) { enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; enum bt_notification_iterator_status it_ret; - struct bt_port *input_port = NULL; - struct bt_connection *connection = NULL; + struct bt_private_port *input_port = NULL; + struct bt_private_connection *connection = NULL; struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1); if (!it_data) { @@ -78,19 +81,21 @@ enum bt_notification_iterator_status trimmer_iterator_init( } /* Create a new iterator on the upstream component. */ - input_port = bt_component_filter_get_default_input_port(component); + input_port = bt_private_component_filter_get_default_input_private_port( + component); assert(input_port); - connection = bt_port_get_connection(input_port); + connection = bt_private_port_get_private_connection(input_port); assert(connection); - it_data->input_iterator = bt_connection_create_notification_iterator( - connection); + it_data->input_iterator = + bt_private_connection_create_notification_iterator(connection); if (!it_data->input_iterator) { ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; goto end; } - it_ret = bt_notification_iterator_set_private_data(iterator, it_data); + it_ret = bt_private_notification_iterator_set_user_data(iterator, + it_data); if (it_ret) { goto end; } @@ -102,11 +107,11 @@ end: BT_HIDDEN struct bt_notification *trimmer_iterator_get( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { struct trimmer_iterator *trim_it; - trim_it = bt_notification_iterator_get_private_data(iterator); + trim_it = bt_private_notification_iterator_get_user_data(iterator); assert(trim_it); if (!trim_it->current_notification) { @@ -411,22 +416,23 @@ enum bt_notification_iterator_status evaluate_notification( BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_next( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *iterator) { struct trimmer_iterator *trim_it = NULL; - struct bt_component *component = NULL; + struct bt_private_component *component = NULL; struct trimmer *trimmer = NULL; struct bt_notification_iterator *source_it = NULL; enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; bool notification_in_range = false; - trim_it = bt_notification_iterator_get_private_data(iterator); + trim_it = bt_private_notification_iterator_get_user_data(iterator); assert(trim_it); - component = bt_notification_iterator_get_component(iterator); + component = bt_private_notification_iterator_get_private_component( + iterator); assert(component); - trimmer = bt_component_get_private_data(component); + trimmer = bt_private_component_get_user_data(component); assert(trimmer); source_it = trim_it->input_iterator; @@ -467,7 +473,8 @@ end: BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_seek_time( - struct bt_notification_iterator *iterator, int64_t time) + struct bt_private_notification_iterator *iterator, + int64_t time) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } diff --git a/plugins/utils/trimmer/iterator.h b/plugins/utils/trimmer/iterator.h index ef8c4eb8..2edbbc71 100644 --- a/plugins/utils/trimmer/iterator.h +++ b/plugins/utils/trimmer/iterator.h @@ -30,6 +30,8 @@ #include "trimmer.h" #include #include +#include +#include struct trimmer_iterator { /* Input iterator associated with this output iterator. */ @@ -39,22 +41,24 @@ struct trimmer_iterator { BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_init( - struct bt_component *component, - struct bt_notification_iterator *iterator, void *init_method_data); + struct bt_private_component *component, + struct bt_private_port *port, + struct bt_private_notification_iterator *iterator); BT_HIDDEN -void trimmer_iterator_destroy(struct bt_notification_iterator *it); +void trimmer_iterator_destroy(struct bt_private_notification_iterator *it); BT_HIDDEN struct bt_notification *trimmer_iterator_get( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_next( - struct bt_notification_iterator *iterator); + struct bt_private_notification_iterator *iterator); BT_HIDDEN enum bt_notification_iterator_status trimmer_iterator_seek_time( - struct bt_notification_iterator *iterator, int64_t time); + struct bt_private_notification_iterator *iterator, + int64_t time); #endif /* BABELTRACE_PLUGIN_TRIMMER_ITERATOR_H */ diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index af838d72..10078868 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -28,9 +28,11 @@ #include #include +#include #include #include #include +#include #include #include #include "trimmer.h" @@ -56,9 +58,9 @@ end: return trimmer; } -void destroy_trimmer(struct bt_component *component) +void destroy_trimmer(struct bt_private_component *component) { - void *data = bt_component_get_private_data(component); + void *data = bt_private_component_get_user_data(component); destroy_trimmer_data(data); } @@ -285,7 +287,8 @@ lazy: } static -enum bt_component_status init_from_params(struct trimmer *trimmer, struct bt_value *params) +enum bt_component_status init_from_params(struct trimmer *trimmer, + struct bt_value *params) { struct bt_value *value = NULL; bool gmt = false; @@ -349,7 +352,7 @@ end: } enum bt_component_status trimmer_component_init( - struct bt_component *component, struct bt_value *params, + struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -360,7 +363,7 @@ enum bt_component_status trimmer_component_init( goto end; } - ret = bt_component_set_private_data(component, trimmer); + ret = bt_private_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 655a60cb..fafb7ada 100644 --- a/plugins/utils/trimmer/trimmer.h +++ b/plugins/utils/trimmer/trimmer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #define NSEC_PER_SEC 1000000000LL @@ -51,9 +51,9 @@ struct trimmer { }; enum bt_component_status trimmer_component_init( - struct bt_component *component, struct bt_value *params, - void *init_method_data); + struct bt_private_component *component, + struct bt_value *params, void *init_method_data); -void destroy_trimmer(struct bt_component *component); +void destroy_trimmer(struct bt_private_component *component); #endif /* BABELTRACE_PLUGINS_UTILS_TRIMMER_H */ diff --git a/plugins/writer/writer.c b/plugins/writer/writer.c index ae01e555..360d0d68 100644 --- a/plugins/writer/writer.c +++ b/plugins/writer/writer.c @@ -29,9 +29,11 @@ #include #include #include +#include #include -#include -#include +#include +#include +#include #include #include #include @@ -55,10 +57,10 @@ void destroy_writer_component_data(struct writer_component *writer_component) } static -void destroy_writer_component(struct bt_component *component) +void destroy_writer_component(struct bt_private_component *component) { struct writer_component *writer_component = (struct writer_component *) - bt_component_get_private_data(component); + bt_private_component_get_user_data(component); destroy_writer_component_data(writer_component); g_free(writer_component); @@ -186,19 +188,20 @@ end: static enum bt_component_status writer_component_accept_port_connection( - struct bt_component *component, struct bt_port *self_port) + struct bt_private_component *component, + struct bt_private_port *self_port) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_connection *connection; + struct bt_private_connection *connection; struct writer_component *writer; - writer = bt_component_get_private_data(component); + writer = bt_private_component_get_user_data(component); assert(writer); assert(!writer->input_iterator); - connection = bt_port_get_connection(self_port); + connection = bt_private_port_get_private_connection(self_port); assert(connection); - writer->input_iterator = bt_connection_create_notification_iterator( - connection); + writer->input_iterator = + bt_private_connection_create_notification_iterator(connection); if (!writer->input_iterator) { ret = BT_COMPONENT_STATUS_ERROR; @@ -208,14 +211,14 @@ enum bt_component_status writer_component_accept_port_connection( } static -enum bt_component_status run(struct bt_component *component) +enum bt_component_status run(struct bt_private_component *component) { enum bt_component_status ret; enum bt_notification_iterator_status it_status; struct bt_notification *notification = NULL; struct bt_notification_iterator *it; struct writer_component *writer_component = - bt_component_get_private_data(component); + bt_private_component_get_user_data(component); it = writer_component->input_iterator; assert(it); @@ -241,7 +244,7 @@ end: static enum bt_component_status writer_component_init( - struct bt_component *component, struct bt_value *params, + struct bt_private_component *component, struct bt_value *params, UNUSED_VAR void *init_method_data) { enum bt_component_status ret; @@ -275,7 +278,7 @@ enum bt_component_status writer_component_init( goto error; } - ret = bt_component_set_private_data(component, writer_component); + ret = bt_private_component_set_user_data(component, writer_component); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index a3b7f84b..b1f8aea6 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -21,38 +21,40 @@ #include #include -static enum bt_component_status sink_consume(struct bt_component *component) +static enum bt_component_status sink_consume( + struct bt_private_component *private_component) { return BT_COMPONENT_STATUS_OK; } static enum bt_notification_iterator_status dummy_iterator_init_method( - struct bt_component *component, - struct bt_notification_iterator *iterator, - void *init_method_data) + struct bt_private_component *private_component, + struct bt_private_port *private_port, + struct bt_private_notification_iterator *private_iterator) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } static void dummy_iterator_destroy_method( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *private_iterator) { } static struct bt_notification *dummy_iterator_get_method( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *private_iterator) { return NULL; } static enum bt_notification_iterator_status dummy_iterator_next_method( - struct bt_notification_iterator *iterator) + struct bt_private_notification_iterator *private_iterator) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } static enum bt_notification_iterator_status dummy_iterator_seek_time_method( - struct bt_notification_iterator *iterator, int64_t time) + struct bt_private_notification_iterator *private_iterator, + int64_t time) { return BT_NOTIFICATION_ITERATOR_STATUS_OK; } -- 2.34.1