Refactor the component class and component API
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 26 Jan 2017 09:03:19 +0000 (04:03 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:37 +0000 (12:57 -0400)
This patch modifies the component class and component API so that the
user sets methods to the component class objects, not to the component
objects. This makes sense following the typical object-oriented
paradigm.

Changes:

* bt_component_class_create() is removed.

  You need to use a component class-specific function to create one,
  amongst:

  * bt_component_class_source_create()
  * bt_component_class_filter_create()
  * bt_component_class_sink_create()

  All the parameters of those functions are mandatory: they are the
  name and the mandatory _methods_ of the class, depending on the
  type.

* Component class-specific functions are declared in their own header:

  * babeltrace/component/component-class-source.h
  * babeltrace/component/component-class-filter.h
  * babeltrace/component/component-class-sink.h

  babeltrace/component/component-class.h only contains functions which
  you can use on any component class, whatever the type.

* enum bt_component_type and BT_COMPONENT_TYPE_* are renamed to
  enum bt_component_class_type and BT_COMPONENT_CLASS_TYPE_* since
  the type is a property of the component class.

* Once a component class is created, you can use functions to set
  optional methods:

  * bt_component_class_filter_set_add_iterator_method()
  * bt_component_class_sink_set_add_iterator_method()

  The component initialization and destroy methods are now both
  optional:

  * bt_component_class_set_init_method()
  * bt_component_class_set_destroy_method()

  You can also set the optional description with a function:

  * bt_component_class_set_description()

* New public utility function: bt_component_get_class_type(): returns
  the type of a component's class.

* Component functions which are specific to a class type are moved to
  their respective header in babeltrace/component
  (source.h, filter.h, sink.h).

* Plugin development interface (babeltrace/plugin/plugin-dev.h) is
  updated to follow the API changes. Component class descriptor macros
  contain the component class type in their name, for example:

      BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION()
      BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD()
      BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD()

* Existing plugins, tests, and the command-line converter are updated to
  follow the API changes.

* Other very minor fixes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
34 files changed:
converter/babeltrace.c
include/Makefile.am
include/babeltrace/component/component-class-filter.h [new file with mode: 0644]
include/babeltrace/component/component-class-internal.h
include/babeltrace/component/component-class-sink.h [new file with mode: 0644]
include/babeltrace/component/component-class-source.h [new file with mode: 0644]
include/babeltrace/component/component-class.h
include/babeltrace/component/component-internal.h
include/babeltrace/component/component.h
include/babeltrace/component/filter-internal.h
include/babeltrace/component/filter.h
include/babeltrace/component/sink-internal.h
include/babeltrace/component/sink.h
include/babeltrace/component/source-internal.h
include/babeltrace/plugin/plugin-dev.h
include/babeltrace/plugin/plugin.h
lib/component/component-class.c
lib/component/component.c
lib/component/filter.c
lib/component/iterator.c
lib/component/sink.c
lib/component/source.c
lib/plugin/plugin.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h
plugins/ctf/lttng-live/lttng-live-internal.h
plugins/ctf/lttng-live/lttng-live.c
plugins/ctf/plugin.c
plugins/muxer/muxer.c
plugins/text/text.c
plugins/trimmer/trimmer.c
plugins/writer/writer.c
tests/lib/test-plugin-plugins/sfs.c
tests/lib/test_plugin.c

index f884467eae97bfb3e7d9ff07e5f381e0b2ac8f29..ca94cb82b0877ae3ae9469b40423fa3ff2e06097 100644 (file)
@@ -81,7 +81,7 @@ struct bt_plugin *find_plugin(const char *name)
 static
 struct bt_component_class *find_component_class(const char *plugin_name,
                const char *comp_class_name,
-               enum bt_component_type comp_class_type)
+               enum bt_component_class_type comp_class_type)
 {
        struct bt_component_class *comp_class = NULL;
        struct bt_plugin *plugin = find_plugin(plugin_name);
@@ -98,16 +98,16 @@ end:
 }
 
 static
-const char *component_type_str(enum bt_component_type type)
+const char *component_type_str(enum bt_component_class_type type)
 {
        switch (type) {
-       case BT_COMPONENT_TYPE_SOURCE:
+       case BT_COMPONENT_CLASS_TYPE_SOURCE:
                return "source";
-       case BT_COMPONENT_TYPE_SINK:
+       case BT_COMPONENT_CLASS_TYPE_SINK:
                return "sink";
-       case BT_COMPONENT_TYPE_FILTER:
+       case BT_COMPONENT_CLASS_TYPE_FILTER:
                return "filter";
-       case BT_COMPONENT_TYPE_UNKNOWN:
+       case BT_COMPONENT_CLASS_TYPE_UNKNOWN:
        default:
                return "unknown";
        }
@@ -157,7 +157,7 @@ void print_component_classes_found(void)
                                bt_plugin_get_description(plugin);
                        const char *comp_class_description =
                                bt_component_class_get_description(comp_class);
-                       enum bt_component_type type =
+                       enum bt_component_class_type type =
                                bt_component_class_get_type(comp_class);
 
                        printf_verbose("[%s - %s (%s)]\n", plugin_name,
@@ -356,7 +356,7 @@ struct bt_component *create_trimmer(struct bt_config_component *source_cfg)
        }
 
        trimmer_class = find_component_class("utils", "trimmer",
-               BT_COMPONENT_TYPE_FILTER);
+               BT_COMPONENT_CLASS_TYPE_FILTER);
        if (!trimmer_class) {
                fprintf(stderr, "Could not find trimmer component class. Aborting...\n");
                goto end;
@@ -575,7 +575,7 @@ int main(int argc, const char **argv)
        source_params = bt_get(source_cfg->params);
        source_class = find_component_class(source_cfg->plugin_name->str,
                        source_cfg->component_name->str,
-                       BT_COMPONENT_TYPE_SOURCE);
+                       BT_COMPONENT_CLASS_TYPE_SOURCE);
        if (!source_class) {
                fprintf(stderr, "Could not find %s.%s source component class. Aborting...\n",
                                source_cfg->plugin_name->str,
@@ -588,7 +588,7 @@ int main(int argc, const char **argv)
        sink_params = bt_get(sink_cfg->params);
        sink_class = find_component_class(sink_cfg->plugin_name->str,
                        sink_cfg->component_name->str,
-                       BT_COMPONENT_TYPE_SINK);
+                       BT_COMPONENT_CLASS_TYPE_SINK);
        if (!sink_class) {
                fprintf(stderr, "Could not find %s.%s output component class. Aborting...\n",
                                sink_cfg->plugin_name->str,
index bcd1994acbaa0e4731d7d9f9f9baa03d9a98971d..33ac2673e3924aae4317f23be7b6ed2e8f5f5189 100644 (file)
@@ -44,6 +44,9 @@ babeltraceplugininclude_HEADERS = \
 babeltracecomponentinclude_HEADERS = \
        babeltrace/component/component.h \
        babeltrace/component/component-class.h \
+       babeltrace/component/component-class-source.h \
+       babeltrace/component/component-class-filter.h \
+       babeltrace/component/component-class-sink.h \
        babeltrace/component/component-connection.h \
        babeltrace/component/component-graph.h \
        babeltrace/component/source.h \
diff --git a/include/babeltrace/component/component-class-filter.h b/include/babeltrace/component/component-class-filter.h
new file mode 100644 (file)
index 0000000..9eaf4a0
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H
+#define BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H
+
+/*
+ * Babeltrace - Component Class Interface.
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * 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 <babeltrace/component/component.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_component_class;
+
+typedef enum bt_component_status (*bt_component_class_filter_init_iterator_method)(
+               struct bt_component *, struct bt_notification_iterator *);
+
+typedef enum bt_component_status (*bt_component_class_filter_add_iterator_method)(
+               struct bt_component *, struct bt_notification_iterator *);
+
+extern
+struct bt_component_class *bt_component_class_filter_create(const char *name,
+               bt_component_class_filter_init_iterator_method init_iterator_method);
+
+extern int bt_component_class_filter_set_add_iterator_method(
+               struct bt_component_class *component_class,
+               bt_component_class_filter_add_iterator_method add_iterator_method);
+
+#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H */
index 7ed0f1630f8aa9c7b516cfdd7d48f78b8e7907e0..320a7d93bd029a74cc71dcc4ceaa64c0dff574d1 100644 (file)
@@ -30,6 +30,9 @@
 
 #include <babeltrace/component/component.h>
 #include <babeltrace/component/component-class.h>
+#include <babeltrace/component/component-class-source.h>
+#include <babeltrace/component/component-class-filter.h>
+#include <babeltrace/component/component-class-sink.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/object-internal.h>
 #include <glib.h>
@@ -39,22 +42,47 @@ struct bt_component_class;
 typedef void (*bt_component_class_destroy_listener_func)(
                struct bt_component_class *class, void *data);
 
-struct bt_component_class_destroyer_listener {
+struct bt_component_class_destroy_listener {
        bt_component_class_destroy_listener_func func;
        void *data;
 };
 
 struct bt_component_class {
        struct bt_object base;
-       enum bt_component_type type;
+       enum bt_component_class_type type;
        GString *name;
        GString *description;
-       bt_component_init_cb init;
-
-       /* Array of struct bt_component_class_destroyer_listener */
+       struct {
+               bt_component_class_init_method init;
+               bt_component_class_destroy_method destroy;
+       } methods;
+       /* Array of struct bt_component_class_destroy_listener */
        GArray *destroy_listeners;
 };
 
+struct bt_component_class_source {
+       struct bt_component_class parent;
+       struct {
+               bt_component_class_source_init_iterator_method init_iterator;
+       } methods;
+};
+
+struct bt_component_class_sink {
+       struct bt_component_class parent;
+       struct {
+               bt_component_class_sink_consume_method consume;
+               bt_component_class_sink_add_iterator_method add_iterator;
+       } methods;
+};
+
+struct bt_component_class_filter {
+       struct bt_component_class parent;
+       struct {
+               bt_component_class_filter_init_iterator_method init_iterator;
+               bt_component_class_filter_add_iterator_method add_iterator;
+       } methods;
+};
+
 BT_HIDDEN
 int bt_component_class_add_destroy_listener(struct bt_component_class *class,
                bt_component_class_destroy_listener_func func, void *data);
diff --git a/include/babeltrace/component/component-class-sink.h b/include/babeltrace/component/component-class-sink.h
new file mode 100644 (file)
index 0000000..5f89bc8
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H
+#define BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H
+
+/*
+ * Babeltrace - Component Class Interface.
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * 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 <babeltrace/component/component.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_component_class;
+
+typedef enum bt_component_status (*bt_component_class_sink_consume_method)(
+        struct bt_component *);
+
+typedef enum bt_component_status (*bt_component_class_sink_add_iterator_method)(
+        struct bt_component *, struct bt_notification_iterator *);
+
+extern
+struct bt_component_class *bt_component_class_sink_create(const char *name,
+               bt_component_class_sink_consume_method consume_method);
+
+extern int bt_component_class_sink_set_add_iterator_method(
+               struct bt_component_class *component_class,
+               bt_component_class_sink_add_iterator_method add_iterator_method);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H */
diff --git a/include/babeltrace/component/component-class-source.h b/include/babeltrace/component/component-class-source.h
new file mode 100644 (file)
index 0000000..d0b9487
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H
+#define BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H
+
+/*
+ * Babeltrace - Component Class Interface.
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * 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 <babeltrace/component/component.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_component_class;
+
+typedef enum bt_component_status (*bt_component_class_source_init_iterator_method)(
+               struct bt_component *, struct bt_notification_iterator *);
+
+extern
+struct bt_component_class *bt_component_class_source_create(const char *name,
+               bt_component_class_source_init_iterator_method init_iterator_method);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H */
index c3359fe2e2c0f8a2ad9a5906f3446ac2cacb32a9..ad259b29c79534d6969d9e9eae866a0d085735b3 100644 (file)
 extern "C" {
 #endif
 
-struct bt_plugin;
 struct bt_component_class;
 
-extern struct bt_component_class *bt_component_class_create(
-               enum bt_component_type type, const char *name,
-               const char *description, bt_component_init_cb init);
+/**
+ * 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,
+};
+
+typedef enum bt_component_status (*bt_component_class_init_method)(
+               struct bt_component *component, struct bt_value *params);
+
+typedef void (*bt_component_class_destroy_method)(struct bt_component *component);
+
+extern int bt_component_class_set_init_method(
+               struct bt_component_class *component_class,
+               bt_component_class_init_method init_method);
+
+extern int bt_component_class_set_destroy_method(
+               struct bt_component_class *component_class,
+               bt_component_class_destroy_method destroy_method);
+
+extern int bt_component_class_set_description(
+               struct bt_component_class *component_class,
+               const char *description);
 
 /**
  * Get a component class' name.
@@ -65,7 +93,11 @@ extern const char *bt_component_class_get_description(
  * @param component_class      Component class of which to get the type
  * @returns                    One of #bt_component_type
  */
-extern enum bt_component_type bt_component_class_get_type(
+extern enum bt_component_class_type bt_component_class_get_type(
                struct bt_component_class *component_class);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_H */
index 7c18f494d1fd28b000f916657ae3e22aadbe5844..dadaa75b22665b93a54bc2d7eda4f6fb95c6cfdc 100644 (file)
@@ -38,12 +38,15 @@ struct bt_component {
        struct bt_object base;
        struct bt_component_class *class;
        GString *name;
-       /** Source, Sink or Filter destroy */
-       bt_component_destroy_cb destroy;
 
-       /** User-defined data and its destruction callback */
+       /**
+        * Internal destroy function specific to a source, filter, or
+        * sink component object.
+        */
+       bt_component_class_destroy_method destroy;
+
+       /** User-defined data */
        void *user_data;
-       bt_component_destroy_cb user_destroy;
 
        /**
         * Used to protect operations which may only be used during
@@ -54,10 +57,7 @@ struct bt_component {
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               bt_component_destroy_cb destroy);
-
-BT_HIDDEN
-enum bt_component_type bt_component_get_type(struct bt_component *component);
+               bt_component_class_destroy_method destroy);
 
 BT_HIDDEN
 struct bt_notification_iterator *bt_component_create_iterator(
index 2645c13c45f6f1f7889d85f17053f2da0b521bb3..08de0d74c8b3ace711233f8bcc8a653f117233df 100644 (file)
 extern "C" {
 #endif
 
-/**
- * Component type.
- */
-enum bt_component_type {
-       BT_COMPONENT_TYPE_UNKNOWN =     -1,
-
-       /** A source component is a notification generator. */
-       BT_COMPONENT_TYPE_SOURCE =      0,
-
-       /** A sink component handles incoming notifications. */
-       BT_COMPONENT_TYPE_SINK =        1,
-
-       /** A filter component implements both Source and Sink interfaces. */
-       BT_COMPONENT_TYPE_FILTER =      2,
-};
-
 /**
  * Status code. Errors are always negative.
  */
@@ -79,25 +63,16 @@ struct bt_component;
 struct bt_value;
 
 /**
- * Component private data deallocation function type.
- *
- * @param component    Component instance
- */
-typedef void (*bt_component_destroy_cb)(struct bt_component *component);
-
-/**
- * Component initialization function type.
- *
- * A component's private data and required callbacks must be set by this
- * function.
+ * Create an instance of a component from a component class.
  *
- * @param component    Component instance
- * @param params       A dictionary of component parameters
- * @returns            One of #bt_component_status values
+ * @param component_class      Component class of which to create an instance
+ * @param name                 Name of the new component instance, optional
+ * @param params               A dictionary of component parameters
+ * @returns                    Returns a pointer to a new component instance
  */
-typedef enum bt_component_status (*bt_component_init_cb)(
-               struct bt_component *component, struct bt_value *params);
-
+extern struct bt_component *bt_component_create(
+               struct bt_component_class *component_class, const char *name,
+               struct bt_value *params);
 
 /**
  * Get a component's private data.
@@ -117,181 +92,6 @@ extern void *bt_component_get_private_data(struct bt_component *component);
 extern enum bt_component_status bt_component_set_private_data(
                struct bt_component *component, void *data);
 
-/**
- * Set a component's private data cleanup function.
- *
- * @param component    Component of which to set the private data destruction
- *                     function
- * @param data         Component private data clean-up function
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status bt_component_set_destroy_cb(
-               struct bt_component *component,
-               bt_component_destroy_cb destroy);
-
-/** bt_component_souce */
-/**
- * Iterator initialization function type.
- *
- * A notification iterator's private data, deinitialization, next, and get
- * callbacks must be set by this function.
- *
- * @param source       Source component instance
- * @param iterator     Notification iterator instance
- */
-typedef enum bt_component_status (*bt_component_source_init_iterator_cb)(
-               struct bt_component *, struct bt_notification_iterator *);
-
-/**
- * Set a source component's iterator initialization function.
- *
- * @param source       Source component instance
- * @param init_iterator        Notification iterator initialization callback
- */
-extern enum bt_component_status
-bt_component_source_set_iterator_init_cb(struct bt_component *source,
-               bt_component_source_init_iterator_cb init_iterator);
-
-/** bt_component_sink */
-/**
- * Notification consumption function type.
- *
- * @param sink         Sink component instance
- * @returns            One of #bt_component_status values
- */
-typedef enum bt_component_status (*bt_component_sink_consume_cb)(
-               struct bt_component *);
-
-/**
- * Iterator addition function type.
- *
- * A sink component may choose to refuse the addition of an iterator
- * by not returning BT_COMPONENT_STATUS_OK.
- *
- * @param sink         Sink component instance
- * @returns            One of #bt_component_status values
- */
-typedef enum bt_component_status (*bt_component_sink_add_iterator_cb)(
-               struct bt_component *, struct bt_notification_iterator *);
-
-/**
- * Set a sink component's consumption callback.
- *
- * @param sink         Sink component instance
- * @param consume      Consumption callback
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status
-bt_component_sink_set_consume_cb(struct bt_component *sink,
-               bt_component_sink_consume_cb consume);
-
-/**
- * Set a sink component's iterator addition callback.
- *
- * @param sink         Sink component instance
- * @param add_iterator Iterator addition callback
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status
-bt_component_sink_set_add_iterator_cb(struct bt_component *sink,
-               bt_component_sink_add_iterator_cb add_iterator);
-
-/* Defaults to 1. */
-extern enum bt_component_status
-bt_component_sink_set_minimum_input_count(struct bt_component *sink,
-               unsigned int minimum);
-
-/* Defaults to 1. */
-extern enum bt_component_status
-bt_component_sink_set_maximum_input_count(struct bt_component *sink,
-               unsigned int maximum);
-
-extern enum bt_component_status
-bt_component_sink_get_input_count(struct bt_component *sink,
-               unsigned int *count);
-
-/* May return NULL after an interator has reached its end. */
-extern enum bt_component_status
-bt_component_sink_get_input_iterator(struct bt_component *sink,
-               unsigned int input, struct bt_notification_iterator **iterator);
-
-/** bt_component_filter */
-/**
- * Iterator initialization function type.
- *
- * A notification iterator's private data, deinitialization, next, and get
- * callbacks must be set by this function.
- *
- * @param filter       Filter component instance
- * @param iterator     Notification iterator instance
- */
-typedef enum bt_component_status (*bt_component_filter_init_iterator_cb)(
-               struct bt_component *, struct bt_notification_iterator *);
-
-/**
- * Iterator addition function type.
- *
- * A filter component may choose to refuse the addition of an iterator
- * by not returning BT_COMPONENT_STATUS_OK.
- *
- * @param filter       Filter component instance
- * @returns            One of #bt_component_status values
- */
-typedef enum bt_component_status (*bt_component_filter_add_iterator_cb)(
-               struct bt_component *, struct bt_notification_iterator *);
-
-/**
- * Set a filter component's iterator initialization function.
- *
- * @param filter       Filter component instance
- * @param init_iterator        Notification iterator initialization callback
- */
-extern enum bt_component_status
-bt_component_filter_set_iterator_init_cb(struct bt_component *filter,
-               bt_component_filter_init_iterator_cb init_iterator);
-
-/**
- * Set a filter component's iterator addition callback.
- *
- * @param filter       Filter component instance
- * @param add_iterator Iterator addition callback
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status
-bt_component_filter_set_add_iterator_cb(struct bt_component *filter,
-               bt_component_filter_add_iterator_cb add_iterator);
-
-/* Defaults to 1. */
-extern enum bt_component_status
-bt_component_filter_set_minimum_input_count(struct bt_component *filter,
-               unsigned int minimum);
-
-/* Defaults to 1. */
-extern enum bt_component_status
-bt_component_filter_set_maximum_input_count(struct bt_component *filter,
-               unsigned int maximum);
-
-extern enum bt_component_status
-bt_component_filter_get_input_count(struct bt_component *filter,
-               unsigned int *count);
-
-/* May return NULL after an interator has reached its end. */
-extern enum bt_component_status
-bt_component_filter_get_input_iterator(struct bt_component *filter,
-               unsigned int input, struct bt_notification_iterator **iterator);
-
-/**
- * Create an instance of a component from a component class.
- *
- * @param component_class      Component class of which to create an instance
- * @param name                 Name of the new component instance, optional
- * @param params               A dictionary of component parameters
- * @returns                    Returns a pointer to a new component instance
- */
-extern struct bt_component *bt_component_create(
-               struct bt_component_class *component_class, const char *name,
-               struct bt_value *params);
-
 /**
  * Get component's name.
  *
@@ -300,16 +100,6 @@ extern struct bt_component *bt_component_create(
  */
 extern const char *bt_component_get_name(struct bt_component *component);
 
-/**
- * Set component's name.
- *
- * @param component    Component instance of which to set the name
- * @param name         New component name (will be copied)
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status bt_component_set_name(
-               struct bt_component *component, const char *name);
-
 /**
  * Get component's class.
  *
@@ -319,6 +109,9 @@ extern enum bt_component_status bt_component_set_name(
 extern struct bt_component_class *bt_component_get_class(
                struct bt_component *component);
 
+extern enum bt_component_class_type bt_component_get_class_type(
+               struct bt_component *component);
+
 #ifdef __cplusplus
 }
 #endif
index 3a17aa0013e4bdbb586fc97d9a602078a1f87833..5ae007fa477c177d794dc4ab0f4a926fce53fef5 100644 (file)
 
 struct bt_value;
 
-struct bt_component_filter_class {
-       struct bt_component_class parent;
-};
-
 struct bt_component_filter {
        struct bt_component parent;
-       bt_component_filter_init_iterator_cb init_iterator;
-       bt_component_sink_add_iterator_cb add_iterator;
        struct component_input input;
 };
 
index f33d49f7ba978ee1f04c48ec3d4cdbd0d577d27e..64e6ef964f82397934df0892ff4d9b01449e34d7 100644 (file)
@@ -59,6 +59,25 @@ extern
 struct bt_notification_iterator *bt_component_filter_create_iterator(
                struct bt_component *component);
 
+/* Defaults to 1. */
+extern enum bt_component_status
+bt_component_filter_set_minimum_input_count(struct bt_component *filter,
+        unsigned int minimum);
+
+/* Defaults to 1. */
+extern enum bt_component_status
+bt_component_filter_set_maximum_input_count(struct bt_component *filter,
+        unsigned int maximum);
+
+extern enum bt_component_status
+bt_component_filter_get_input_count(struct bt_component *filter,
+        unsigned int *count);
+
+/* May return NULL after an interator has reached its end. */
+extern enum bt_component_status
+bt_component_filter_get_input_iterator(struct bt_component *filter,
+        unsigned int input, struct bt_notification_iterator **iterator);
+
 #ifdef __cplusplus
 }
 #endif
index 41733c39e49fa2b440c7a0d34a5f79da981774eb..30b066c646aba6a8d530d22b830805af66245402 100644 (file)
 
 struct bt_value;
 
-struct bt_component_sink_class {
-       struct bt_component_class parent;
-};
-
 //typedef uint32_t notification_mask_t;
 
 struct bt_component_sink {
        struct bt_component parent;
-       bt_component_sink_consume_cb consume;
-       bt_component_sink_add_iterator_cb add_iterator;
        struct component_input input;
 /*     notification_mask_t registered_notifications_mask;*/
 };
index 31b5b67f8cbf1e9d16f9601a355e67f6607162cb..a37221d55cb536cb976b3ed23503abc336deee8c 100644 (file)
@@ -58,6 +58,25 @@ extern
 enum bt_component_status bt_component_sink_consume(
                struct bt_component *component);
 
+/* Defaults to 1. */
+extern enum bt_component_status
+bt_component_sink_set_minimum_input_count(struct bt_component *sink,
+        unsigned int minimum);
+
+/* Defaults to 1. */
+extern enum bt_component_status
+bt_component_sink_set_maximum_input_count(struct bt_component *sink,
+        unsigned int maximum);
+
+extern enum bt_component_status
+bt_component_sink_get_input_count(struct bt_component *sink,
+        unsigned int *count);
+
+/* May return NULL after an interator has reached its end. */
+extern enum bt_component_status
+bt_component_sink_get_input_iterator(struct bt_component *sink,
+        unsigned int input, struct bt_notification_iterator **iterator);
+
 #ifdef __cplusplus
 }
 #endif
index 0a926fc710ac55de749f3f12accb3b7700e44105..fcf646dea657ba44119be1265fb72a78fc008449 100644 (file)
 
 struct bt_value;
 
-struct bt_component_source_class {
-       struct bt_component_class parent;
-};
-
 struct bt_component_source {
        struct bt_component parent;
-       bt_component_source_init_iterator_cb init_iterator;
 };
 
 /**
index 387cf89eca26e441a7c5769283491fab8ff4b42e..5224d466b607d0d8e6442abbe2b4ef15efb0d05d 100644 (file)
@@ -34,6 +34,9 @@
 #include <stdint.h>
 #include <babeltrace/plugin/plugin.h>
 #include <babeltrace/component/component-class.h>
+#include <babeltrace/component/component-class-source.h>
+#include <babeltrace/component/component-class-filter.h>
+#include <babeltrace/component/component-class-sink.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -93,7 +96,7 @@ struct __bt_plugin_descriptor_attribute {
        /* Name of the attribute's type for debug purposes */
        const char *type_name;
 
-       /* Attribute's value */
+       /* Attribute's value (depends on attribute's type) */
        union {
                /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT */
                bt_plugin_init_func init;
@@ -120,19 +123,38 @@ struct __bt_plugin_component_class_descriptor {
         */
        const struct __bt_plugin_descriptor *plugin_descriptor;
 
-       /* Component type */
-       enum bt_component_type type;
+       /* Component class type */
+       enum bt_component_class_type type;
 
        /* Component class name */
        const char *name;
 
-       /* Component initialization function */
-       bt_component_init_cb init_cb;
+       /* Mandatory methods (depends on component class type) */
+       union {
+               /* BT_COMPONENT_CLASS_TYPE_SOURCE */
+               struct {
+                       bt_component_class_source_init_iterator_method init_iterator;
+               } source;
+
+               /* BT_COMPONENT_CLASS_TYPE_FILTER */
+               struct {
+                       bt_component_class_filter_init_iterator_method init_iterator;
+               } filter;
+
+               /* BT_COMPONENT_CLASS_TYPE_SINK */
+               struct {
+                       bt_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_DESCRIPTION                 = 0,
+       BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD                 = 1,
+       BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD              = 2,
+       BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD  = 3,
+       BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD    = 4,
 };
 
 /* Component class attribute (internal use) */
@@ -149,10 +171,22 @@ struct __bt_plugin_component_class_descriptor_attribute {
        /* Name of the attribute's type for debug purposes */
        const char *type_name;
 
-       /* Attribute's value */
+       /* Attribute's value (depends on attribute's type) */
        union {
-               /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION */
+               /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION */
                const char *description;
+
+               /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD */
+               bt_component_class_init_method init_method;
+
+               /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD */
+               bt_component_class_destroy_method destroy_method;
+
+               /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD */
+               bt_component_class_filter_add_iterator_method filter_add_iterator_method;
+
+               /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD */
+               bt_component_class_sink_add_iterator_method sink_add_iterator_method;
        } value;
 } __attribute__((packed));
 
@@ -276,25 +310,75 @@ struct __bt_plugin_component_class_descriptor_attribute {
        __BT_PLUGIN_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _x)
 
 /*
- * Defines a component class descriptor with a custom ID.
+ * Declaration of start and stop symbols of component class descriptors
+ * section.
+ */
+#define __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP \
+       extern struct __bt_plugin_component_class_descriptor const *__start___bt_plugin_component_class_descriptors; \
+       extern struct __bt_plugin_component_class_descriptor const *__stop___bt_plugin_component_class_descriptors
+
+/*
+ * Defines a source component class descriptor with a custom ID.
  *
- * _id:            ID (any valid C identifier except `auto`).
- * _comp_class_id: Component class ID (C identifier).
- * _type:          Component class type (enum bt_component_type).
- * _name:          Component class name (C string).
- * _init_func:     Component class's initialization function
- *                 (bt_component_init_cb).
+ * _id:                   ID (any valid C identifier except `auto`).
+ * _comp_class_id:        Component class ID (C identifier).
+ * _name:                 Component class name (C string).
+ * _init_iterator_method: Component class's iterator initialization method
+ *                        (bt_component_class_source_init_iterator_method).
  */
-#define BT_PLUGIN_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _type, _name, _init_cb) \
-       static struct __bt_plugin_component_class_descriptor __bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type = { \
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \
+       static struct __bt_plugin_component_class_descriptor __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id = { \
                .plugin_descriptor = &__bt_plugin_descriptor_##_id,     \
-               .type = _type,                                          \
+               .type = BT_COMPONENT_CLASS_TYPE_SOURCE,                 \
                .name = _name,                                          \
-               .init_cb = _init_cb,                                    \
+               .methods.source = {                                     \
+                       .init_iterator = _init_iterator_method,         \
+               },                                                      \
        };                                                              \
-       static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type; \
-       extern struct __bt_plugin_component_class_descriptor const *__start___bt_plugin_component_class_descriptors; \
-       extern struct __bt_plugin_component_class_descriptor const *__stop___bt_plugin_component_class_descriptors
+       static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id; \
+       __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP
+
+/*
+ * 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).
+ * _init_iterator_method: Component class's iterator initialization method
+ *                        (bt_component_class_filter_init_iterator_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \
+       static struct __bt_plugin_component_class_descriptor __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id = { \
+               .plugin_descriptor = &__bt_plugin_descriptor_##_id,     \
+               .type = BT_COMPONENT_CLASS_TYPE_FILTER,                 \
+               .name = _name,                                          \
+               .methods.filter = {                                     \
+                       .init_iterator = _init_iterator_method,         \
+               },                                                      \
+       };                                                              \
+       static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id; \
+       __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP
+
+/*
+ * Defines a sink 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).
+ * _consume_method:     Component class's iterator consume method
+ *                      (bt_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 = { \
+               .plugin_descriptor = &__bt_plugin_descriptor_##_id,     \
+               .type = BT_COMPONENT_CLASS_TYPE_SINK,                   \
+               .name = _name,                                          \
+               .methods.sink = {                                       \
+                       .consume = _consume_method,                     \
+               },                                                      \
+       };                                                              \
+       static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id; \
+       __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP
 
 /*
  * Defines a component class descriptor attribute (generic, internal
@@ -302,34 +386,145 @@ struct __bt_plugin_component_class_descriptor_attribute {
  *
  * _id:            Plugin descriptor ID (C identifier).
  * _comp_class_id: Component class ID (C identifier).
- * _type:          Component class type (enum bt_component_type).
+ * _type:          Component class type (`source`, `filter`, or `sink`).
  * _attr_name:     Name of the attribute (C identifier).
  * _attr_type:     Type of the attribute
  *                 (enum __bt_plugin_descriptor_attribute_type).
  * _x:             Value.
  */
 #define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(_attr_name, _attr_type, _id, _comp_class_id, _type, _x) \
-       static struct __bt_plugin_component_class_descriptor_attribute __bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name = { \
-               .comp_class_descriptor = &__bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type, \
+       static struct __bt_plugin_component_class_descriptor_attribute __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name = { \
+               .comp_class_descriptor = &__bt_plugin_##_type##_component_class_descriptor_##_id##_##_comp_class_id, \
                .type = _attr_type,                                     \
                .type_name = #_attr_name,                               \
-               .value.description = _x,                                \
+               .value._attr_name = _x,                                 \
        };                                                              \
-       static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name; \
+       static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name; \
        extern struct __bt_plugin_component_class_descriptor_attribute const *__start___bt_plugin_component_class_descriptor_attributes; \
        extern struct __bt_plugin_component_class_descriptor_attribute const *__stop___bt_plugin_component_class_descriptor_attributes
 
 /*
- * Defines a description attribute attached to a specific component
- * class descriptor.
+ * Defines a description attribute attached to a specific source
+ * component class descriptor.
  *
  * _id:            Plugin descriptor ID (C identifier).
  * _comp_class_id: Component class descriptor ID (C identifier).
- * _type:          Component class type (enum bt_component_type).
  * _x:             Description (C string).
  */
-#define BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _type, _x) \
-       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, _type, _x)
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, source, _x)
+
+/*
+ * Defines a description 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:             Description (C string).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, filter, _x)
+
+/*
+ * Defines a description 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:             Description (C string).
+ */
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, sink, _x)
+
+/*
+ * Defines an initialization 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:             Initialization method (bt_component_class_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)
+
+/*
+ * Defines an initialization 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:             Initialization method (bt_component_class_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)
+
+/*
+ * Defines an initialization 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:             Initialization method (bt_component_class_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)
+
+/*
+ * Defines a destroy 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:             Destroy method (bt_component_class_destroy_method).
+ */
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, source, _x)
+
+/*
+ * Defines a destroy 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:             Destroy method (bt_component_class_destroy_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, filter, _x)
+
+/*
+ * Defines a destroy 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:             Destroy method (bt_component_class_destroy_method).
+ */
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, sink, _x)
+
+/*
+ * Defines an add iterator 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:             Add iterator method
+ *                 (bt_component_class_filter_add_iterator_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD, _id, _comp_class_id, filter, _x)
+
+/*
+ * Defines an add iterator 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:             Add iterator method
+ *                 (bt_component_class_sink_add_iterator_method).
+ */
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \
+       __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD, _id, _comp_class_id, sink, _x)
 
 /*
  * Defines a plugin descriptor with an automatic ID.
@@ -379,28 +574,157 @@ struct __bt_plugin_component_class_descriptor_attribute {
 #define BT_PLUGIN_DESCRIPTION(_x)      BT_PLUGIN_DESCRIPTION_WITH_ID(auto, _x)
 
 /*
- * Defines a component class attached to the automatic plugin
+ * Defines a source component class attached to the automatic plugin
+ * descriptor. Its ID is the same as its name, hence its name must be a
+ * C identifier in this version.
+ *
+ * _name:                 Component class name (C identifier).
+ * _init_iterator_method: Component class's iterator initialization method
+ *                        (bt_component_class_source_init_iterator_method).
+ */
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _init_iterator_method) \
+       BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method)
+
+/*
+ * Defines a filter component class attached to the automatic plugin
  * descriptor. Its ID is the same as its name, hence its name must be a
  * C identifier in this version.
  *
- * _type:          Component class type (enum bt_component_type).
- * _name:          Component class name (C identifier).
- * _init_cb:       Component class's initialization function
- *                 (bt_component_init_cb).
+ * _name:                 Component class name (C identifier).
+ * _init_iterator_method: Component class's iterator initialization method
+ *                        (bt_component_class_filter_init_iterator_method).
  */
-#define BT_PLUGIN_COMPONENT_CLASS(_type, _name, _init_cb) \
-       BT_PLUGIN_COMPONENT_CLASS_WITH_ID(auto, _name, _type, #_name, _init_cb)
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _init_iterator_method) \
+       BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method)
 
 /*
- * Defines a description attribute attached to a component class
+ * Defines a sink component class attached to the automatic plugin
+ * descriptor. Its ID is the same as its name, hence its name must be a
+ * C identifier in this version.
+ *
+ * _name:           Component class name (C identifier).
+ * _consume_method: Component class's consume method
+ *                  (bt_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)
+
+/*
+ * Defines a description attribute attached to a source component class
  * descriptor which is attached to the automatic plugin descriptor.
  *
- * _type:          Component class type (enum bt_component_type).
- * _name:          Component class name (C identifier).
- * _x: Description (C string).
+ * _name: Component class name (C identifier).
+ * _x:    Description (C string).
+ */
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(_name, _x) \
+       BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines a description attribute attached to a filter component class
+ * descriptor which is attached to the automatic plugin descriptor.
+ *
+ * _name: Component class name (C identifier).
+ * _x:    Description (C string).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(_name, _x) \
+       BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines a description attribute attached to a sink component class
+ * descriptor which is attached to the automatic plugin descriptor.
+ *
+ * _name: Component class name (C identifier).
+ * _x:    Description (C string).
+ */
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(_name, _x) \
+       BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines an initialization 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_init_method).
+ */
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD(_name, _x) \
+       BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines an initialization 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_init_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(_name, _x) \
+       BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines an initialization 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_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 destroy 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_destroy_method).
+ */
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \
+       BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines a destroy 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_destroy_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \
+       BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines a destroy 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_destroy_method).
+ */
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \
+       BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines an add iterator method attribute attached to a filter
+ * component class descriptor which is attached to the automatic plugin
+ * descriptor.
+ *
+ * _name: Component class name (C identifier).
+ * _x:    Add iterator method (bt_component_class_filter_add_iterator_method).
+ */
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \
+       BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x)
+
+/*
+ * Defines an add iterator method attribute attached to a sink
+ * component class descriptor which is attached to the automatic plugin
+ * descriptor.
+ *
+ * _name: Component class name (C identifier).
+ * _x:    Add iterator method (bt_component_class_sink_add_iterator_method).
  */
-#define BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(_type, _name, _x) \
-       BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _type, _x)
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \
+       BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x)
 
 #ifdef __cplusplus
 }
index 66436dfb47dbd44eab11d92ad5f1bbab6cc0bfda..1e5bf37b5e0f74b24d032b9fc5c89a0d0d820e18 100644 (file)
@@ -106,7 +106,7 @@ extern struct bt_component_class *bt_plugin_get_component_class(
 extern
 struct bt_component_class *bt_plugin_get_component_class_by_name_and_type(
                struct bt_plugin *plugin, const char *name,
-               enum bt_component_type type);
+               enum bt_component_class_type type);
 
 #ifdef __cplusplus
 }
index 660964c2de3b4d5f5f86dcd0f68a139ba40694fa..22551f88c54c60d55a3da428adab72b71937e30b 100644 (file)
@@ -42,9 +42,9 @@ void bt_component_class_destroy(struct bt_object *obj)
 
        /* Call destroy listeners in reverse registration order */
        for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
-               struct bt_component_class_destroyer_listener *listener =
+               struct bt_component_class_destroy_listener *listener =
                        &g_array_index(class->destroy_listeners,
-                               struct bt_component_class_destroyer_listener,
+                               struct bt_component_class_destroy_listener,
                                i);
 
                listener->func(class, listener->data);
@@ -63,46 +63,188 @@ void bt_component_class_destroy(struct bt_object *obj)
        g_free(class);
 }
 
-struct bt_component_class *bt_component_class_create(
-               enum bt_component_type type, const char *name,
-               const char *description, bt_component_init_cb init)
+static
+int bt_component_class_init(struct bt_component_class *class,
+               enum bt_component_class_type type, const char *name)
 {
-       struct bt_component_class *class = NULL;
+       int ret = 0;
+
+       bt_object_init(class, bt_component_class_destroy);
+       class->type = type;
+       class->name = g_string_new(name);
+       if (!class->name) {
+               goto error;
+       }
+
+       class->description = g_string_new(NULL);
+       if (!class->description) {
+               goto error;
+       }
+
+       class->destroy_listeners = g_array_new(FALSE, TRUE,
+               sizeof(struct bt_component_class_destroy_listener));
+       if (!class->destroy_listeners) {
+               goto error;
+       }
+
+       goto end;
 
-       if (!name) {
+error:
+       BT_PUT(class);
+       ret = -1;
+
+end:
+       return ret;
+}
+
+struct bt_component_class *bt_component_class_source_create(const char *name,
+               bt_component_class_source_init_iterator_method init_iterator_method)
+{
+       struct bt_component_class_source *source_class = NULL;
+       int ret;
+
+       if (!name || !init_iterator_method) {
                goto end;
        }
 
-       class = g_new0(struct bt_component_class, 1);
-       if (!class) {
+       source_class = g_new0(struct bt_component_class_source, 1);
+       if (!source_class) {
                goto end;
        }
 
-       bt_object_init(class, bt_component_class_destroy);
-       class->type = type;
-       class->init = init;
-       class->name = g_string_new(name);
-       if (!class->name) {
-               BT_PUT(class);
+       ret = bt_component_class_init(&source_class->parent,
+               BT_COMPONENT_CLASS_TYPE_SOURCE, name);
+       if (ret) {
+               /*
+                * If bt_component_class_init() fails, the component
+                * class is put, therefore its memory is already
+                * freed.
+                */
+               source_class = NULL;
+               goto end;
+       }
+
+       source_class->methods.init_iterator = init_iterator_method;
+
+end:
+       return &source_class->parent;
+}
+
+struct bt_component_class *bt_component_class_filter_create(const char *name,
+               bt_component_class_filter_init_iterator_method init_iterator_method)
+{
+       struct bt_component_class_filter *filter_class = NULL;
+       int ret;
+
+       if (!name || !init_iterator_method) {
                goto end;
        }
 
-       if (description) {
-               class->description = g_string_new(description);
-               if (!class->description) {
-                       BT_PUT(class);
-                       goto end;
-               }
+       filter_class = g_new0(struct bt_component_class_filter, 1);
+       if (!filter_class) {
+               goto end;
        }
 
-       class->destroy_listeners = g_array_new(FALSE, TRUE,
-               sizeof(struct bt_component_class_destroyer_listener));
-       if (!class->destroy_listeners) {
-               BT_PUT(class);
+       ret = bt_component_class_init(&filter_class->parent,
+               BT_COMPONENT_CLASS_TYPE_FILTER, name);
+       if (ret) {
+               /*
+                * If bt_component_class_init() fails, the component
+                * class is put, therefore its memory is already
+                * freed.
+                */
+               filter_class = NULL;
                goto end;
        }
+
+       filter_class->methods.init_iterator = init_iterator_method;
+
 end:
-       return class;
+       return &filter_class->parent;
+}
+
+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 *sink_class = NULL;
+       int ret;
+
+       if (!name || !consume_method) {
+               goto end;
+       }
+
+       sink_class = g_new0(struct bt_component_class_sink, 1);
+       if (!sink_class) {
+               goto end;
+       }
+
+       ret = bt_component_class_init(&sink_class->parent,
+               BT_COMPONENT_CLASS_TYPE_SINK, name);
+       if (ret) {
+               /*
+                * If bt_component_class_init() fails, the component
+                * class is put, therefore its memory is already
+                * freed.
+                */
+               sink_class = NULL;
+               goto end;
+       }
+
+       sink_class->methods.consume = consume_method;
+
+end:
+       return &sink_class->parent;
+}
+
+int bt_component_class_set_init_method(
+               struct bt_component_class *component_class,
+               bt_component_class_init_method init_method)
+{
+       int ret = 0;
+
+       if (!component_class || !init_method) {
+               ret = -1;
+               goto end;
+       }
+
+       component_class->methods.init = init_method;
+
+end:
+       return ret;
+}
+
+int bt_component_class_set_destroy_method(
+               struct bt_component_class *component_class,
+               bt_component_class_destroy_method destroy_method)
+{
+       int ret = 0;
+
+       if (!component_class || !destroy_method) {
+               ret = -1;
+               goto end;
+       }
+
+       component_class->methods.destroy = destroy_method;
+
+end:
+       return ret;
+}
+
+extern int bt_component_class_set_description(
+               struct bt_component_class *component_class,
+               const char *description)
+{
+       int ret = 0;
+
+       if (!component_class || !description) {
+               ret = -1;
+               goto end;
+       }
+
+       g_string_assign(component_class->description, description);
+
+end:
+       return ret;
 }
 
 const char *bt_component_class_get_name(
@@ -111,11 +253,11 @@ const char *bt_component_class_get_name(
        return component_class ? component_class->name->str : NULL;
 }
 
-enum bt_component_type bt_component_class_get_type(
+enum bt_component_class_type bt_component_class_get_type(
                struct bt_component_class *component_class)
 {
        return component_class ? component_class->type :
-                       BT_COMPONENT_TYPE_UNKNOWN;
+                       BT_COMPONENT_CLASS_TYPE_UNKNOWN;
 }
 
 const char *bt_component_class_get_description(
@@ -130,7 +272,7 @@ int bt_component_class_add_destroy_listener(struct bt_component_class *class,
                bt_component_class_destroy_listener_func func, void *data)
 {
        int ret = 0;
-       struct bt_component_class_destroyer_listener listener;
+       struct bt_component_class_destroy_listener listener;
 
        if (!class || !func) {
                ret = -1;
@@ -144,3 +286,46 @@ int bt_component_class_add_destroy_listener(struct bt_component_class *class,
 end:
        return ret;
 }
+
+extern int bt_component_class_sink_set_add_iterator_method(
+               struct bt_component_class *component_class,
+               bt_component_class_sink_add_iterator_method add_iterator_method)
+{
+       struct bt_component_class_sink *sink_class;
+       int ret = 0;
+
+       if (!component_class || !add_iterator_method ||
+                       component_class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
+               ret = -1;
+               goto end;
+       }
+
+       sink_class = container_of(component_class,
+               struct bt_component_class_sink, parent);
+       sink_class->methods.add_iterator = add_iterator_method;
+
+end:
+       return ret;
+}
+
+extern int bt_component_class_filter_set_add_iterator_method(
+               struct bt_component_class *component_class,
+               bt_component_class_filter_add_iterator_method add_iterator_method)
+{
+       struct bt_component_class_filter *filter_class;
+       int ret = 0;
+
+       if (!component_class || !add_iterator_method ||
+                       component_class->type !=
+                       BT_COMPONENT_CLASS_TYPE_FILTER) {
+               ret = -1;
+               goto end;
+       }
+
+       filter_class = container_of(component_class,
+               struct bt_component_class_filter, parent);
+       filter_class->methods.add_iterator = add_iterator_method;
+
+end:
+       return ret;
+}
index 4ad897c7cb32c8f359edfe673c2cbc2f404808df..d82ee0d8fd78d284ef7624fe357689e76b61ff2c 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <babeltrace/component/component.h>
 #include <babeltrace/component/component-internal.h>
+#include <babeltrace/component/component-class-internal.h>
 #include <babeltrace/component/source-internal.h>
 #include <babeltrace/component/filter-internal.h>
 #include <babeltrace/component/notification/iterator-internal.h>
 static
 struct bt_component * (* const component_create_funcs[])(
                struct bt_component_class *, struct bt_value *) = {
-       [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_create,
-       [BT_COMPONENT_TYPE_SINK] = bt_component_sink_create,
-       [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_create,
+       [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create,
+       [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create,
+       [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_create,
 };
 
 static
 enum bt_component_status (* const component_validation_funcs[])(
                struct bt_component *) = {
-       [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_validate,
-       [BT_COMPONENT_TYPE_SINK] = bt_component_sink_validate,
-       [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_validate,
+       [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_validate,
+       [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_validate,
+       [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_validate,
 };
 
 static
@@ -69,8 +70,8 @@ void bt_component_destroy(struct bt_object *obj)
         * User data is destroyed first, followed by the concrete component
         * instance.
         */
-       if (component->user_destroy) {
-               component->user_destroy(component);
+       if (component->class->methods.destroy) {
+               component->class->methods.destroy(component);
        }
 
        if (component->destroy) {
@@ -84,7 +85,7 @@ void bt_component_destroy(struct bt_object *obj)
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               bt_component_destroy_cb destroy)
+               bt_component_class_destroy_method destroy)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
@@ -98,10 +99,10 @@ end:
        return ret;
 }
 
-BT_HIDDEN
-enum bt_component_type bt_component_get_type(struct bt_component *component)
+enum bt_component_class_type bt_component_get_class_type(
+               struct bt_component *component)
 {
-       return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN;
+       return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN;
 }
 
 BT_HIDDEN
@@ -109,16 +110,17 @@ struct bt_notification_iterator *bt_component_create_iterator(
                struct bt_component *component)
 {
        enum bt_notification_iterator_status ret_iterator;
-       enum bt_component_type component_type;
+       enum bt_component_class_type type;
        struct bt_notification_iterator *iterator = NULL;
+       struct bt_component_class *class = component->class;
 
        if (!component) {
                goto error;
        }
 
-       component_type = bt_component_get_type(component);
-       if (component_type != BT_COMPONENT_TYPE_SOURCE &&
-                       component_type != BT_COMPONENT_TYPE_FILTER) {
+       type = bt_component_get_class_type(component);
+       if (type != BT_COMPONENT_CLASS_TYPE_SOURCE &&
+                       type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                /* Unsupported operation. */
                goto error;
        }
@@ -128,15 +130,16 @@ struct bt_notification_iterator *bt_component_create_iterator(
                goto error;
        }
 
-       switch (component_type) {
-       case BT_COMPONENT_TYPE_SOURCE:
+       switch (type) {
+       case BT_COMPONENT_CLASS_TYPE_SOURCE:
        {
-               struct bt_component_source *source;
+               struct bt_component_class_source *source_class;
                enum bt_component_status ret_component;
 
-               source = container_of(component, struct bt_component_source, parent);
-               assert(source->init_iterator);
-               ret_component = source->init_iterator(component, iterator);
+               source_class = container_of(class, struct bt_component_class_source, parent);
+               assert(source_class->methods.init_iterator);
+               ret_component =
+                       source_class->methods.init_iterator(component, iterator);
                if (ret_component != BT_COMPONENT_STATUS_OK) {
                        goto error;
                }
@@ -144,14 +147,15 @@ struct bt_notification_iterator *bt_component_create_iterator(
 
                break;
        }
-       case BT_COMPONENT_TYPE_FILTER:
+       case BT_COMPONENT_CLASS_TYPE_FILTER:
        {
-               struct bt_component_filter *filter;
+               struct bt_component_class_filter *filter_class;
                enum bt_component_status ret_component;
 
-               filter = container_of(component, struct bt_component_filter, parent);
-               assert(filter->init_iterator);
-               ret_component = filter->init_iterator(component, iterator);
+               filter_class = container_of(class, struct bt_component_class_filter, parent);
+               assert(filter_class->methods.init_iterator);
+               ret_component =
+                       filter_class->methods.init_iterator(component, iterator);
                if (ret_component != BT_COMPONENT_STATUS_OK) {
                        goto error;
                }
@@ -179,15 +183,16 @@ struct bt_component *bt_component_create(
 {
        int ret;
        struct bt_component *component = NULL;
-       enum bt_component_type type;
+       enum bt_component_class_type type;
 
        if (!component_class) {
                goto end;
        }
 
+
        type = bt_component_class_get_type(component_class);
-       if (type <= BT_COMPONENT_TYPE_UNKNOWN ||
-                       type > BT_COMPONENT_TYPE_FILTER) {
+       if (type <= BT_COMPONENT_CLASS_TYPE_UNKNOWN ||
+                       type > BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
@@ -204,12 +209,17 @@ struct bt_component *bt_component_create(
        }
 
        component->initializing = true;
-       ret = component_class->init(component, params);
-       component->initializing = false;
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               BT_PUT(component);
-               goto end;
+
+       if (component_class->methods.init) {
+               ret = component_class->methods.init(component, params);
+               component->initializing = false;
+               if (ret != BT_COMPONENT_STATUS_OK) {
+                       BT_PUT(component);
+                       goto end;
+               }
        }
+
+       component->initializing = false;
        ret = component_validation_funcs[type](component);
        if (ret != BT_COMPONENT_STATUS_OK) {
                BT_PUT(component);
@@ -273,18 +283,3 @@ bt_component_set_private_data(struct bt_component *component,
 end:
        return ret;
 }
-
-enum bt_component_status bt_component_set_destroy_cb(
-               struct bt_component *component, bt_component_destroy_cb destroy)
-{
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component || !component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       component->user_destroy = destroy;
-end:
-       return ret;
-}
index 2c9fb471aba62fc5e6f0bec0c6ba1aac5156e548..53c0091e97c147dae80c8cee6515cba0d3608e8d 100644 (file)
 #include <babeltrace/component/input.h>
 #include <babeltrace/component/filter-internal.h>
 #include <babeltrace/component/component-internal.h>
+#include <babeltrace/component/component-class-internal.h>
 #include <babeltrace/component/notification/notification.h>
 #include <babeltrace/component/notification/iterator-internal.h>
 
-enum bt_component_status bt_component_filter_set_iterator_init_cb(
-               struct bt_component *component,
-               bt_component_filter_init_iterator_cb init_iterator)
-{
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (component->class->type != BT_COMPONENT_TYPE_FILTER ||
-                       !component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->init_iterator = init_iterator;
-end:
-       return ret;
-}
-
-enum bt_component_status bt_component_filter_set_add_iterator_cb(
-               struct bt_component *component,
-               bt_component_filter_add_iterator_cb add_iterator)
-{
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->add_iterator = add_iterator;
-end:
-       return ret;
-}
-
 enum bt_component_status bt_component_filter_set_minimum_input_count(
                struct bt_component *component,
                unsigned int minimum)
@@ -93,7 +47,7 @@ enum bt_component_status bt_component_filter_set_minimum_input_count(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -121,7 +75,7 @@ enum bt_component_status bt_component_filter_set_maximum_input_count(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -149,7 +103,7 @@ bt_component_filter_get_input_count(struct bt_component *component,
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -172,7 +126,7 @@ bt_component_filter_get_input_iterator(struct bt_component *component,
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -194,13 +148,14 @@ enum bt_component_status bt_component_filter_add_iterator(
 {
        struct bt_component_filter *filter;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_component_class_filter *filter_class;
 
        if (!component || !iterator) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -211,8 +166,10 @@ enum bt_component_status bt_component_filter_add_iterator(
                goto end;
        }
 
-       if (filter->add_iterator) {
-               ret = filter->add_iterator(component, iterator);
+       filter_class = container_of(component->class, struct bt_component_class_filter, parent);
+
+       if (filter_class->methods.add_iterator) {
+               ret = filter_class->methods.add_iterator(component, iterator);
                if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
@@ -283,18 +240,12 @@ enum bt_component_status bt_component_filter_validate(
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_TYPE_FILTER) {
+       if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        filter = container_of(component, struct bt_component_filter, parent);
-       if (!filter->init_iterator) {
-               printf_error("Invalid filter component; no iterator initialization callback defined.");
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
        ret = component_input_validate(&filter->input);
        if (ret) {
                goto end;
index 188095cf856c46b3710ddbc1b122f9931d4cc425..98c4f3554a053ff3996eaebd379f9543a015bbe2 100644 (file)
@@ -53,17 +53,17 @@ BT_HIDDEN
 struct bt_notification_iterator *bt_notification_iterator_create(
                struct bt_component *component)
 {
-       enum bt_component_type type;
+       enum bt_component_class_type type;
        struct bt_notification_iterator *iterator = NULL;
 
        if (!component) {
                goto end;
        }
 
-       type = bt_component_get_type(component);
+       type = bt_component_get_class_type(component);
        switch (type) {
-       case BT_COMPONENT_TYPE_SOURCE:
-       case BT_COMPONENT_TYPE_FILTER:
+       case BT_COMPONENT_CLASS_TYPE_SOURCE:
+       case BT_COMPONENT_CLASS_TYPE_FILTER:
                break;
        default:
                goto end;
index 509ea89c60ad9f7f277539b0e690262accb74fc8..22ca5c99ee94822e1adf05a04bf9bbfb37ba0ca4 100644 (file)
@@ -49,18 +49,12 @@ enum bt_component_status bt_component_sink_validate(
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_TYPE_SINK) {
+       if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        sink = container_of(component, struct bt_component_sink, parent);
-       if (!sink->consume) {
-               printf_error("Invalid sink component; no notification consumption callback defined.");
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
        ret = component_input_validate(&sink->input);
        if (ret) {
                goto end;
@@ -131,13 +125,14 @@ enum bt_component_status bt_component_sink_consume(
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
        struct bt_component_sink *sink = NULL;
+       struct bt_component_class_sink *sink_class = NULL;
 
        if (!component) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -151,8 +146,9 @@ enum bt_component_status bt_component_sink_consume(
                sink->input.validated = true;
        }
 
-       assert(sink->consume);
-       ret = sink->consume(component);
+       sink_class = container_of(component->class, struct bt_component_class_sink, parent);
+       assert(sink_class->methods.consume);
+       ret = sink_class->methods.consume(component);
 end:
        return ret;
 }
@@ -169,7 +165,7 @@ enum bt_component_status bt_component_sink_register_notification_type(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -190,61 +186,6 @@ end:
        return ret;
 }
 */
-enum bt_component_status bt_component_sink_set_consume_cb(
-               struct bt_component *component,
-               bt_component_sink_consume_cb consume)
-{
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->consume = consume;
-end:
-       return ret;
-}
-
-enum bt_component_status bt_component_sink_set_add_iterator_cb(
-               struct bt_component *component,
-               bt_component_sink_add_iterator_cb add_iterator)
-{
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->add_iterator = add_iterator;
-end:
-       return ret;
-}
 
 enum bt_component_status bt_component_sink_set_minimum_input_count(
                struct bt_component *component,
@@ -258,7 +199,7 @@ enum bt_component_status bt_component_sink_set_minimum_input_count(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -286,7 +227,7 @@ enum bt_component_status bt_component_sink_set_maximum_input_count(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -314,7 +255,7 @@ bt_component_sink_get_input_count(struct bt_component *component,
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -337,7 +278,7 @@ bt_component_sink_get_input_iterator(struct bt_component *component,
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -359,13 +300,14 @@ bt_component_sink_add_iterator(struct bt_component *component,
 {
        struct bt_component_sink *sink;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_component_class_sink *sink_class;
 
        if (!component || !iterator) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
@@ -376,8 +318,10 @@ bt_component_sink_add_iterator(struct bt_component *component,
                goto end;
        }
 
-       if (sink->add_iterator) {
-               ret = sink->add_iterator(component, iterator);
+       sink_class = container_of(component->class, struct bt_component_class_sink, parent);
+
+       if (sink_class->methods.add_iterator) {
+               ret = sink_class->methods.add_iterator(component, iterator);
                if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
index a0a21d1b893901a8dd080394c936850b34bf76b0..7b51590c7214117fc3a080b67f07f3d8c94c82af 100644 (file)
@@ -38,7 +38,6 @@ enum bt_component_status bt_component_source_validate(
                struct bt_component *component)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_component_source *source;
 
        if (!component) {
                ret = BT_COMPONENT_STATUS_INVALID;
@@ -50,16 +49,11 @@ enum bt_component_status bt_component_source_validate(
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_TYPE_SOURCE) {
+       if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       source = container_of(component, struct bt_component_source, parent);
-       if (!source->init_iterator) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
 end:
        return ret;
 }
@@ -86,25 +80,6 @@ end:
        return source ? &source->parent : NULL;
 }
 
-enum bt_component_status
-bt_component_source_set_iterator_init_cb(struct bt_component *component,
-               bt_component_source_init_iterator_cb init_iterator)
-{
-       struct bt_component_source *source;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (component->class->type != BT_COMPONENT_TYPE_SOURCE ||
-                       !component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       source = container_of(component, struct bt_component_source, parent);
-       source->init_iterator = init_iterator;
-end:
-       return ret;
-}
-
 struct bt_notification_iterator *bt_component_source_create_iterator(
                struct bt_component *component)
 {
index 5a72b42e49283f944299f3ad624bb4fe9fc068fb..e79db448e2296e0ebce278e4c15ffa67294deb55 100644 (file)
@@ -237,6 +237,33 @@ end:
        return plugin;
 }
 
+/*
+ * This function does the following:
+ *
+ * 1. Iterate on the plugin descriptor attributes section and set the
+ *    plugin's attributes depending on the attribute types. This
+ *    includes the name of the plugin, its description, and its
+ *    initialization function, for example.
+ *
+ * 2. Iterate on the component class descriptors section and create one
+ *    "full descriptor" (temporary structure) for each one that is found
+ *    and attached to our plugin descriptor.
+ *
+ * 3. Iterate on the component class descriptor attributes section and
+ *    set the corresponding full descriptor's attributes depending on
+ *    the attribute types. This includes the description of the
+ *    component class, as well as its initialization and destroy
+ *    methods.
+ *
+ * 4. Call the user's plugin initialization function, if any is
+ *    defined.
+ *
+ * 5. For each full component class descriptor, create a component class
+ *    object, set its optional attributes, and add it to the plugin
+ *    object.
+ *
+ * 6. Freeze the plugin object.
+ */
 static
 enum bt_plugin_status bt_plugin_init(
                struct bt_plugin *plugin,
@@ -255,6 +282,10 @@ enum bt_plugin_status bt_plugin_init(
        struct comp_class_full_descriptor {
                const struct __bt_plugin_component_class_descriptor *descriptor;
                const char *description;
+               bt_component_class_init_method init_method;
+               bt_component_class_destroy_method destroy_method;
+               bt_component_class_filter_add_iterator_method filter_add_iterator_method;
+               bt_component_class_sink_add_iterator_method sink_add_iterator_method;
        };
 
        enum bt_plugin_status status = BT_PLUGIN_STATUS_OK;
@@ -263,6 +294,7 @@ enum bt_plugin_status bt_plugin_init(
        struct __bt_plugin_component_class_descriptor_attribute const * const *cur_cc_descr_attr_ptr;
        GArray *comp_class_full_descriptors;
        size_t i;
+       int ret;
 
        comp_class_full_descriptors = g_array_new(FALSE, TRUE,
                sizeof(struct comp_class_full_descriptor));
@@ -319,14 +351,13 @@ enum bt_plugin_status bt_plugin_init(
        for (cur_cc_descr_ptr = cc_descriptors_begin; cur_cc_descr_ptr != cc_descriptors_end; cur_cc_descr_ptr++) {
                const struct __bt_plugin_component_class_descriptor *cur_cc_descr =
                        *cur_cc_descr_ptr;
-               struct comp_class_full_descriptor full_descriptor;
+               struct comp_class_full_descriptor full_descriptor = {0};
 
                if (cur_cc_descr->plugin_descriptor != descriptor) {
                        continue;
                }
 
                full_descriptor.descriptor = cur_cc_descr;
-               full_descriptor.description = NULL;
                g_array_append_val(comp_class_full_descriptors,
                        full_descriptor);
        }
@@ -358,6 +389,22 @@ enum bt_plugin_status bt_plugin_init(
                                        cc_full_descr->description =
                                                cur_cc_descr_attr->value.description;
                                        break;
+                               case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD:
+                                       cc_full_descr->init_method =
+                                               cur_cc_descr_attr->value.init_method;
+                                       break;
+                               case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD:
+                                       cc_full_descr->destroy_method =
+                                               cur_cc_descr_attr->value.destroy_method;
+                                       break;
+                               case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD:
+                                       cc_full_descr->filter_add_iterator_method =
+                                               cur_cc_descr_attr->value.filter_add_iterator_method;
+                                       break;
+                               case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD:
+                                       cc_full_descr->sink_add_iterator_method =
+                                               cur_cc_descr_attr->value.sink_add_iterator_method;
+                                       break;
                                default:
                                        printf_verbose("WARNING: Unknown attribute \"%s\" (type %d) for component class %s (type %d) in plugin %s\n",
                                                cur_cc_descr_attr->type_name,
@@ -383,22 +430,97 @@ enum bt_plugin_status bt_plugin_init(
 
        plugin->shared_lib_handle->init_called = true;
 
+       /* Add described component classes to plugin */
        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);
                struct bt_component_class *comp_class;
 
-               comp_class = bt_component_class_create(
-                       cc_full_descr->descriptor->type,
-                       cc_full_descr->descriptor->name,
-                       cc_full_descr->description,
-                       cc_full_descr->descriptor->init_cb);
+               switch (cc_full_descr->descriptor->type) {
+               case BT_COMPONENT_CLASS_TYPE_SOURCE:
+                       comp_class = bt_component_class_source_create(
+                               cc_full_descr->descriptor->name,
+                               cc_full_descr->descriptor->methods.source.init_iterator);
+                       break;
+               case BT_COMPONENT_CLASS_TYPE_FILTER:
+                       comp_class = bt_component_class_filter_create(
+                               cc_full_descr->descriptor->name,
+                               cc_full_descr->descriptor->methods.filter.init_iterator);
+                       break;
+               case BT_COMPONENT_CLASS_TYPE_SINK:
+                       comp_class = bt_component_class_sink_create(
+                               cc_full_descr->descriptor->name,
+                               cc_full_descr->descriptor->methods.sink.consume);
+                       break;
+               default:
+                       printf_verbose("WARNING: Unknown component class type %d for component class %s in plugin %s\n",
+                               cc_full_descr->descriptor->type,
+                               cc_full_descr->descriptor->name,
+                               descriptor->name);
+                       continue;
+               }
+
                if (!comp_class) {
                        status = BT_PLUGIN_STATUS_ERROR;
                        goto end;
                }
 
+               if (cc_full_descr->description) {
+                       ret = bt_component_class_set_description(comp_class,
+                               cc_full_descr->description);
+                       if (ret) {
+                               status = BT_PLUGIN_STATUS_ERROR;
+                               BT_PUT(comp_class);
+                               goto end;
+                       }
+               }
+
+               if (cc_full_descr->init_method) {
+                       ret = bt_component_class_set_init_method(comp_class,
+                               cc_full_descr->init_method);
+                       if (ret) {
+                               status = BT_PLUGIN_STATUS_ERROR;
+                               BT_PUT(comp_class);
+                               goto end;
+                       }
+               }
+
+               if (cc_full_descr->destroy_method) {
+                       ret = bt_component_class_set_destroy_method(comp_class,
+                               cc_full_descr->destroy_method);
+                       if (ret) {
+                               status = BT_PLUGIN_STATUS_ERROR;
+                               BT_PUT(comp_class);
+                               goto end;
+                       }
+               }
+
+               if (cc_full_descr->descriptor->type ==
+                               BT_COMPONENT_CLASS_TYPE_FILTER &&
+                               cc_full_descr->filter_add_iterator_method) {
+                       ret = bt_component_class_filter_set_add_iterator_method(comp_class,
+                               cc_full_descr->filter_add_iterator_method);
+                       if (ret) {
+                               status = BT_PLUGIN_STATUS_ERROR;
+                               BT_PUT(comp_class);
+                               goto end;
+                       }
+               }
+
+               if (cc_full_descr->descriptor->type ==
+                               BT_COMPONENT_CLASS_TYPE_SINK &&
+                               cc_full_descr->sink_add_iterator_method) {
+                       ret = bt_component_class_sink_set_add_iterator_method(comp_class,
+                               cc_full_descr->sink_add_iterator_method);
+                       if (ret) {
+                               status = BT_PLUGIN_STATUS_ERROR;
+                               BT_PUT(comp_class);
+                               goto end;
+                       }
+               }
+
+               /* Add component class to the plugin object */
                status = bt_plugin_add_component_class(plugin,
                        comp_class);
                BT_PUT(comp_class);
@@ -454,7 +576,7 @@ struct bt_plugin **bt_plugin_create_all_from_sections(
        printf_verbose("Section: Plugin component class descriptors: [%p - %p], (%zu elements)\n",
                cc_descriptors_begin, cc_descriptors_end, cc_descriptors_count);
        printf_verbose("Section: Plugin component class descriptor attributes: [%p - %p], (%zu elements)\n",
-               cc_descr_attrs_begin, cc_descr_attrs_end, attrs_count);
+               cc_descr_attrs_begin, cc_descr_attrs_end, cc_descr_attrs_count);
        plugins = calloc(descriptor_count + 1, sizeof(*plugins));
        if (!plugins) {
                goto error;
@@ -878,7 +1000,7 @@ end:
 
 struct bt_component_class *bt_plugin_get_component_class_by_name_and_type(
                struct bt_plugin *plugin, const char *name,
-               enum bt_component_type type)
+               enum bt_component_class_type type)
 {
        struct bt_component_class *comp_class = NULL;
        size_t i;
@@ -892,7 +1014,7 @@ struct bt_component_class *bt_plugin_get_component_class_by_name_and_type(
                        g_ptr_array_index(plugin->comp_classes, i);
                const char *comp_class_cand_name =
                        bt_component_class_get_name(comp_class_candidate);
-               enum bt_component_type comp_class_cand_type =
+               enum bt_component_class_type comp_class_cand_type =
                        bt_component_class_get_type(comp_class_candidate);
 
                assert(comp_class_cand_name);
index f08f06a5daee3387763ad7e9ceabad70b9c6e321..d3fcf0f0f735694ff273f44697970ddef3d8e79d 100644 (file)
@@ -583,7 +583,6 @@ end:
        return ret;
 }
 
-static
 enum bt_component_status ctf_fs_iterator_init(struct bt_component *source,
                struct bt_notification_iterator *it)
 {
@@ -668,7 +667,6 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs)
        g_free(ctf_fs);
 }
 
-static
 void ctf_fs_destroy(struct bt_component *component)
 {
        void *data = bt_component_get_private_data(component);
@@ -738,21 +736,10 @@ enum bt_component_status ctf_fs_init(struct bt_component *source,
                goto end;
        }
 
-       ret = bt_component_set_destroy_cb(source, ctf_fs_destroy);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = bt_component_set_private_data(source, ctf_fs);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
-
-       ret = bt_component_source_set_iterator_init_cb(source,
-                       ctf_fs_iterator_init);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
 end:
        return ret;
 error:
index 2c0972e6da91fd5c8b2efc3c4411ba1b0c066f12..2cef5fb5d06ea8fe6d3305d75b54d001fd21d4f9 100644 (file)
@@ -109,4 +109,11 @@ BT_HIDDEN
 enum bt_component_status ctf_fs_init(struct bt_component *source,
                struct bt_value *params);
 
+BT_HIDDEN
+void ctf_fs_destroy(struct bt_component *component);
+
+BT_HIDDEN
+enum bt_component_status ctf_fs_iterator_init(struct bt_component *source,
+               struct bt_notification_iterator *it);
+
 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
index 4891b0d256bd7aae9509337a2e5f53f61f1c7ccd..d26ec853b6adbdf97269ad536ef47f7df22fe97b 100644 (file)
 
 #define LTTNG_LIVE_COMPONENT_DESCRIPTION "Component implementing an LTTng-live client."
 
+BT_HIDDEN
+enum bt_component_status lttng_live_iterator_init(struct bt_component *source,
+        struct bt_notification_iterator *it);
+
 BT_HIDDEN
 enum bt_component_status lttng_live_init(struct bt_component *source,
                struct bt_value *params);
index 5cef2aa99f1936b54781bcb7b442272b723fc64c..9bbf4b17e02d6d985f0fd5338b96ac01d3f943c8 100644 (file)
 #include "lttng-live-internal.h"
 #include <babeltrace/component/source.h>
 
+BT_HIDDEN
+enum bt_component_status lttng_live_iterator_init(struct bt_component *source,
+               struct bt_notification_iterator *it)
+{
+}
+
 BT_HIDDEN
 enum bt_component_status lttng_live_init(struct bt_component *component,
                struct bt_value *params)
index ff168d691c901fbfff377dcde2e870d70f18a3bf..77f5057bf650cf534317fce68071fdb96af7adbc 100644 (file)
@@ -37,10 +37,14 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
 
 /* Declare component classes implemented by this plug-in. */
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SOURCE, fs, ctf_fs_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SOURCE, fs,
-        CTF_FS_COMPONENT_DESCRIPTION);
-BT_PLUGIN_COMPONENT_CLASS_WITH_ID(auto, lttng_live,
-        BT_COMPONENT_TYPE_SOURCE, "lttng-live", lttng_live_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, lttng_live,
-        BT_COMPONENT_TYPE_SOURCE, LTTNG_LIVE_COMPONENT_DESCRIPTION);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS(fs, ctf_fs_iterator_init);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD(fs, ctf_fs_init);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD(fs, ctf_fs_destroy);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(fs, CTF_FS_COMPONENT_DESCRIPTION);
+
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, lttng_live, "lttng-live",
+       lttng_live_iterator_init);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, lttng_live,
+       lttng_live_init);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, lttng_live,
+        LTTNG_LIVE_COMPONENT_DESCRIPTION);
index 2700be6ed5671e5613842712a1d28e48d6f1012b..04171d75525f58f41b14716eb1c2bd42db8e9635 100644 (file)
@@ -72,12 +72,6 @@ enum bt_component_status muxer_component_init(
                goto end;
        }
 
-       ret = bt_component_set_destroy_cb(component,
-                       destroy_muxer);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = bt_component_set_private_data(component, muxer);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
@@ -89,12 +83,20 @@ error:
        return ret;
 }
 
+enum bt_component_status muxer_init_iterator(
+               struct bt_component *component,
+               struct bt_notification_iterator *iter)
+{
+       return BT_COMPONENT_STATUS_OK;
+}
+
 /* Initialize plug-in entry points. */
 BT_PLUGIN(muxer);
 BT_PLUGIN_DESCRIPTION("Babeltrace Trace Muxer Plug-In.");
 BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, muxer,
-       muxer_component_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, muxer,
+BT_PLUGIN_FILTER_COMPONENT_CLASS(muxer, muxer_init_iterator);
+BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(muxer,
        "Time-correlate multiple traces.");
+BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(muxer, muxer_component_init);
+BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(muxer, destroy_muxer);
index 370fb2d3478fdb9892e57d916314893a6a714be4..4ddca35cfa1310f828e5dd4c9887475a351554f3 100644 (file)
@@ -628,22 +628,10 @@ enum bt_component_status text_component_init(
                goto error;
        }
 
-       ret = bt_component_set_destroy_cb(component,
-                       destroy_text);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = bt_component_set_private_data(component, text);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
-
-       ret = bt_component_sink_set_consume_cb(component,
-                       run);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
 end:
        return ret;
 error:
@@ -656,7 +644,9 @@ BT_PLUGIN(text);
 BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in.");
 BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, text,
-               text_component_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, text,
+BT_PLUGIN_SINK_COMPONENT_CLASS(text, run);
+BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(text, destroy_text);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text,
        "Formats CTF-IR to text. Formerly known as ctf-text.");
+
index 49be358b621d58831e242a25b37411d87bf79255..6d94ddf2b69287acd71ecd8946d59eb912eceef5 100644 (file)
@@ -359,23 +359,11 @@ enum bt_component_status trimmer_component_init(
                goto end;
        }
 
-       ret = bt_component_set_destroy_cb(component,
-                       destroy_trimmer);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = bt_component_set_private_data(component, trimmer);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
 
-       ret = bt_component_filter_set_iterator_init_cb(component,
-                       trimmer_iterator_init);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = init_from_params(trimmer, params);
 end:
        return ret;
@@ -389,7 +377,8 @@ BT_PLUGIN(utils);
 BT_PLUGIN_DESCRIPTION("Babeltrace Trace Trimmer Plug-In.");
 BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, trimmer,
-               trimmer_component_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, trimmer,
+BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_init);
+BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(trimmer,
        "Ensure that trace notifications outside of a given range are filtered-out.");
+BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(trimmer, trimmer_component_init);
+BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(trimmer, destroy_trimmer);
index 971e6bf8a61b26facedce6ac3b1daddd16c107c8..089a3d595d2a38ea77f046551af174707bd682a2 100644 (file)
@@ -246,23 +246,11 @@ enum bt_component_status writer_component_init(
                goto error;
        }
 
-       ret = bt_component_set_destroy_cb(component,
-                       destroy_writer_component);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
        ret = bt_component_set_private_data(component, writer_component);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
        }
 
-       ret = bt_component_sink_set_consume_cb(component,
-                       run);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
 end:
        return ret;
 error:
@@ -276,7 +264,7 @@ BT_PLUGIN(writer);
 BT_PLUGIN_DESCRIPTION("Babeltrace CTF-Writer output plug-in.");
 BT_PLUGIN_AUTHOR("Jérémie Galarneau");
 BT_PLUGIN_LICENSE("MIT");
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, writer,
-       writer_component_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, writer,
-       "Formats CTF-IR to CTF.");
+BT_PLUGIN_SINK_COMPONENT_CLASS(writer, run);
+BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(writer, writer_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(writer, destroy_writer_component);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(writer, "Formats CTF-IR to CTF.");
index 943efbebf25b8f9f2ab47cf602bc521f7656b90e..037deced4d2e6e2c726e18352a00a02f76cc13b5 100644 (file)
 #include <babeltrace/plugin/plugin-dev.h>
 #include <babeltrace/component/component.h>
 
-static int sink_value = 42;
-
-static enum bt_component_status sink_run(struct bt_component *component)
-{
-       return BT_COMPONENT_STATUS_OK;
-}
-
-static enum bt_component_status comp_class_sink_init(
-               struct bt_component *component, struct bt_value *params)
+static enum bt_component_status sink_consume(struct bt_component *component)
 {
-       enum bt_component_status ret;
-
-       ret = bt_component_set_private_data(component, &sink_value);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               return BT_COMPONENT_STATUS_ERROR;
-       }
-
-       ret = bt_component_sink_set_consume_cb(component, sink_run);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               return BT_COMPONENT_STATUS_ERROR;
-       }
-
        return BT_COMPONENT_STATUS_OK;
 }
 
-static enum bt_component_status comp_class_dummy_init(
-               struct bt_component *component, struct bt_value *params)
+enum bt_component_status dummy_init_iterator_method(
+               struct bt_component *component, struct bt_notification_iterator *iter)
 {
        return BT_COMPONENT_STATUS_OK;
 }
@@ -54,11 +34,11 @@ BT_PLUGIN_DESCRIPTION("Babeltrace plugin with source, sink, and filter component
 BT_PLUGIN_AUTHOR("Janine Sutto");
 BT_PLUGIN_LICENSE("Beerware");
 
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SOURCE, source, comp_class_dummy_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SOURCE, source, "A source.");
+BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_init_iterator_method);
+BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(source, "A source.");
 
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, sink, comp_class_sink_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, sink, "A sink.");
+BT_PLUGIN_SINK_COMPONENT_CLASS(sink, sink_consume);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(sink, "A sink.");
 
-BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, filter, comp_class_dummy_init);
-BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, filter, "A filter.");
+BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_init_iterator_method);
+BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(filter, "A filter.");
index 9b4ea84f706ccb4beda87832b6ed6734a85e5453..a2fc129aac4ac4fb007114138473b7b5eba5c711 100644 (file)
@@ -144,22 +144,22 @@ static void test_sfs(const char *plugin_dir)
                "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_TYPE_SOURCE);
+               plugin, "source", BT_COMPONENT_CLASS_TYPE_SOURCE);
        ok(source_comp_class,
                "bt_plugin_get_component_class_by_name_and_type() finds a source component class");
 
        sink_comp_class = bt_plugin_get_component_class_by_name_and_type(
-               plugin, "sink", BT_COMPONENT_TYPE_SINK);
+               plugin, "sink", BT_COMPONENT_CLASS_TYPE_SINK);
 
        ok(sink_comp_class,
                "bt_plugin_get_component_class_by_name_and_type() finds a sink component class");
        filter_comp_class = bt_plugin_get_component_class_by_name_and_type(
-               plugin, "filter", BT_COMPONENT_TYPE_FILTER);
+               plugin, "filter", BT_COMPONENT_CLASS_TYPE_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_TYPE_SOURCE),
+               BT_COMPONENT_CLASS_TYPE_SOURCE),
                "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type");
 
        diag("> putting the plugin object here");
This page took 0.066767 seconds and 4 git commands to generate.