From 0d884c50d1a934e65bf6893b0232b0e7fdecf70a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 8 Jul 2015 15:48:42 -0400 Subject: [PATCH] Build fix and sink implementation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 1 - .../plugin/component-factory-internal.h | 36 +++++++++ include/babeltrace/plugin/component-factory.h | 9 ++- .../babeltrace/plugin/component-internal.h | 6 +- include/babeltrace/plugin/plugin-system.h | 8 +- include/babeltrace/plugin/sink-internal.h | 41 ++++++++++ include/babeltrace/plugin/source-internal.h | 12 +-- plugins/Makefile.am | 2 +- plugins/component.c | 7 +- plugins/sink.c | 74 +++++++++++++++++++ plugins/source.c | 31 ++++---- 11 files changed, 191 insertions(+), 36 deletions(-) diff --git a/include/Makefile.am b/include/Makefile.am index f6b11bfc..d26647b2 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -43,7 +43,6 @@ babeltraceplugininclude_HEADERS = \ babeltrace/plugin/source.h \ babeltrace/plugin/sink.h \ babeltrace/plugin/filter.h \ - babeltrace/plugin/plugin-lib.h \ babeltrace/plugin/plugin-system.h \ babeltrace/plugin/notification/eot.h \ babeltrace/plugin/notification/notification.h \ diff --git a/include/babeltrace/plugin/component-factory-internal.h b/include/babeltrace/plugin/component-factory-internal.h index e6d368da..4810e9ca 100644 --- a/include/babeltrace/plugin/component-factory-internal.h +++ b/include/babeltrace/plugin/component-factory-internal.h @@ -1,3 +1,35 @@ +#ifndef BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H +#define BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H + +/* + * BabelTrace - Component Factory Internal + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include /** Component initialization functions */ /** @@ -9,6 +41,7 @@ * @param iterator_create_cb Iterator creation callback * @returns A source component instance */ +BT_HIDDEN extern struct bt_component *bt_component_source_create(const char *name, void *private_data, bt_component_destroy_cb destroy_func, bt_component_source_iterator_create_cb iterator_create_cb); @@ -22,6 +55,9 @@ extern struct bt_component *bt_component_source_create(const char *name, * @param notification_cb Notification handling callback * @returns A sink component instance */ +BT_HIDDEN extern struct bt_component *bt_component_sink_create(const char *name, void *private_data, bt_component_destroy_cb destroy_func, bt_component_sink_handle_notification_cb notification_cb); + +#endif /* BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H */ diff --git a/include/babeltrace/plugin/component-factory.h b/include/babeltrace/plugin/component-factory.h index 8b8c81bf..06c61379 100644 --- a/include/babeltrace/plugin/component-factory.h +++ b/include/babeltrace/plugin/component-factory.h @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -36,22 +37,22 @@ extern "C" { struct bt_component_factory; -typedef struct bt_component *(*bt_component_init)( +typedef struct bt_component *(*bt_component_init_cb)( struct bt_component *component); -typedef struct bt_component *(*bt_component_fini)( +typedef struct bt_component *(*bt_component_fini_cb)( struct bt_component *component); enum bt_component_status bt_component_factory_create(const char *path); enum bt_component_status bt_component_factory_register_source_component_class( struct bt_component_factory *factory, const char *name, - bt_component_init init, bt_component_fini fini, + bt_component_init_cb init, bt_component_fini_cb fini, bt_component_source_iterator_create_cb iterator_create_cb); enum bt_component_status bt_component_factory_register_sink_component_class( struct bt_component_factory *factory, const char *name, - bt_component_init init, bt_component_fini fini, + bt_component_init_cb init, bt_component_fini_cb fini, bt_component_sink_handle_notification_cb handle_notification_cb); void bt_component_factory_destroy(struct bt_component_factory *factory); diff --git a/include/babeltrace/plugin/component-internal.h b/include/babeltrace/plugin/component-internal.h index 3fc85c85..6c8689aa 100644 --- a/include/babeltrace/plugin/component-internal.h +++ b/include/babeltrace/plugin/component-internal.h @@ -44,13 +44,13 @@ struct bt_notification; struct bt_component { struct bt_ctf_ref ref_count; GString *name; - enum bt_plugin_type type; + enum bt_component_type type; /** No ownership taken */ FILE *error_stream; void *user_data; - bt_plugin_destroy_cb user_data_destroy; - bt_plugin_destroy_cb destroy; + bt_component_destroy_cb user_data_destroy; + bt_component_destroy_cb destroy; }; BT_HIDDEN diff --git a/include/babeltrace/plugin/plugin-system.h b/include/babeltrace/plugin/plugin-system.h index 6d6614da..e7ca01a5 100644 --- a/include/babeltrace/plugin/plugin-system.h +++ b/include/babeltrace/plugin/plugin-system.h @@ -75,6 +75,7 @@ typedef enum bt_notification_iterator_status (bt_notification_iterator_next_cb)( * Get a component's private (implementation) data. * * @param component Component of which to get the private data + * @returns Component's private data */ extern void *bt_component_get_private_data(struct bt_component *component); @@ -82,10 +83,11 @@ extern void *bt_component_get_private_data(struct bt_component *component); * Set a component's private (implementation) data. * * @param component Component of which to set the private data - * @param data Component private data + * @param data Component private data + * @returns One of #bt_component_status values */ -extern enum bt_component_status bt_component_set_private_data(struct bt_component *component, - void *data); +extern enum bt_component_status bt_component_set_private_data( + struct bt_component *component, void *data); /** Notification iterator functions */ diff --git a/include/babeltrace/plugin/sink-internal.h b/include/babeltrace/plugin/sink-internal.h index e69de29b..30617789 100644 --- a/include/babeltrace/plugin/sink-internal.h +++ b/include/babeltrace/plugin/sink-internal.h @@ -0,0 +1,41 @@ +#ifndef BABELTRACE_PLUGIN_SINK_INTERNAL_H +#define BABELTRACE_PLUGIN_SINK_INTERNAL_H + +/* + * BabelTrace - Sink Component internal + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +struct bt_component_sink { + struct bt_component parent; + + /* Component implementation callbacks */ + bt_component_sink_handle_notification_cb handle_notification; +}; + +#endif /* BABELTRACE_PLUGIN_SINK_INTERNAL_H */ diff --git a/include/babeltrace/plugin/source-internal.h b/include/babeltrace/plugin/source-internal.h index 38bf7f89..54af8b70 100644 --- a/include/babeltrace/plugin/source-internal.h +++ b/include/babeltrace/plugin/source-internal.h @@ -2,7 +2,7 @@ #define BABELTRACE_PLUGIN_SOURCE_INTERNAL_H /* - * BabelTrace - Source Plug-in internal + * BabelTrace - Source Component internal * * Copyright 2015 Jérémie Galarneau * @@ -28,18 +28,18 @@ */ #include -#include +#include #include #ifdef __cplusplus extern "C" { #endif -struct bt_plugin_source { - struct bt_plugin parent; +struct bt_component_source { + struct bt_component parent; - /* Plug-in implementation callbacks */ - bt_plugin_source_iterator_create_cb create_iterator; + /* Component implementation callbacks */ + bt_component_source_iterator_create_cb create_iterator; }; #ifdef __cplusplus diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ffb0295b..ec8248ff 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -SUBDIRS = . ctf +SUBDIRS = . lib_LTLIBRARIES = libbabeltrace-plugin.la diff --git a/plugins/component.c b/plugins/component.c index 6036fd50..5b7a23b3 100644 --- a/plugins/component.c +++ b/plugins/component.c @@ -107,8 +107,9 @@ void bt_component_put(struct bt_component *component) } BT_HIDDEN -enum bt_component_status bt_component_init(struct bt_component *component, const char *name, - void *user_data, bt_component_destroy_cb user_destroy_func, +enum bt_component_status bt_component_init(struct bt_component *component, + const char *name, void *user_data, + bt_component_destroy_cb user_destroy_func, enum bt_component_type component_type, bt_component_destroy_cb component_destroy) { @@ -137,7 +138,7 @@ end: void *bt_component_get_private_data(struct bt_component *component) { - void *ret = NULL; + void *ret = NULL; if (!component) { goto end; diff --git a/plugins/sink.c b/plugins/sink.c index e69de29b..911b5e84 100644 --- a/plugins/sink.c +++ b/plugins/sink.c @@ -0,0 +1,74 @@ +/* + * sink.c + * + * Babeltrace Source Component + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +static +void bt_component_sink_destroy(struct bt_component *component) +{ + struct bt_component_sink *sink; + + if (!component) { + return; + } + + sink = container_of(component, struct bt_component_sink, parent); + g_free(sink); +} + +struct bt_component *bt_component_sink_create(const char *name, + void *private_data, bt_component_destroy_cb destroy_func, + bt_component_sink_handle_notification_cb notification_cb) +{ + struct bt_component_sink *sink = NULL; + enum bt_component_status ret; + + if (!notification_cb) { + goto end; + } + + sink = g_new0(struct bt_component_sink, 1); + if (!sink) { + goto end; + } + + ret = bt_component_init(&sink->parent, name, private_data, + destroy_func, BT_COMPONENT_TYPE_SINK, + bt_component_sink_destroy); + if (ret != BT_COMPONENT_STATUS_OK) { + g_free(sink); + sink = NULL; + goto end; + } + + sink->handle_notification = notification_cb; +end: + return sink ? &sink->parent : NULL; +} diff --git a/plugins/source.c b/plugins/source.c index 6b115abe..d32fa2a7 100644 --- a/plugins/source.c +++ b/plugins/source.c @@ -1,7 +1,7 @@ /* * source.c * - * Babeltrace Source Plugin + * Babeltrace Source Component * * Copyright 2015 Jérémie Galarneau * @@ -28,40 +28,41 @@ #include #include -#include +#include static -void bt_plugin_source_destroy(struct bt_plugin *plugin) +void bt_component_source_destroy(struct bt_component *component) { - struct bt_plugin_source *source; + struct bt_component_source *source; - if (!plugin) { + if (!component) { return; } - source = container_of(plugin, struct bt_plugin_source, parent); + source = container_of(component, struct bt_component_source, parent); g_free(source); } -struct bt_plugin *bt_plugin_source_create(const char *name, - void *private_data, bt_plugin_destroy_cb destroy_func, - bt_plugin_source_iterator_create_cb iterator_create_cb) +struct bt_component *bt_component_source_create(const char *name, + void *private_data, bt_component_destroy_cb destroy_func, + bt_component_source_iterator_create_cb iterator_create_cb) { - struct bt_plugin_source *source = NULL; - enum bt_plugin_status ret; + struct bt_component_source *source = NULL; + enum bt_component_status ret; if (!iterator_create_cb) { goto end; } - source = g_new0(struct bt_plugin_source, 1); + source = g_new0(struct bt_component_source, 1); if (!source) { goto end; } - ret = bt_plugin_init(&source->parent, name, private_data, - destroy_func, BT_PLUGIN_TYPE_SOURCE, bt_plugin_source_destroy); - if (ret != BT_PLUGIN_STATUS_OK) { + ret = bt_component_init(&source->parent, name, private_data, + destroy_func, BT_COMPONENT_TYPE_SOURCE, + bt_component_source_destroy); + if (ret != BT_COMPONENT_STATUS_OK) { g_free(source); source = NULL; goto end; -- 2.34.1