Add filter component type
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 20 Sep 2016 03:13:36 +0000 (23:13 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:06 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
12 files changed:
configure.ac
include/babeltrace/plugin/component-factory.h
include/babeltrace/plugin/filter-internal.h
include/babeltrace/plugin/filter.h
include/babeltrace/plugin/plugin-macros.h
include/babeltrace/plugin/plugin-system.h
include/babeltrace/plugin/source.h
lib/plugin-system/component-factory.c
lib/plugin-system/filter.c [new file with mode: 0644]
plugins/Makefile.am
plugins/correlator/Makefile.am [new file with mode: 0644]
plugins/correlator/correlator.c [new file with mode: 0644]

index 5ad18a0063cd7d7e9bc555733b597845e2fb0c84..ac7e43934a6b8a1c749c89198a2f4e0df432f637 100644 (file)
@@ -383,6 +383,7 @@ AC_CONFIG_FILES([
        plugins/ctf/common/notif-iter/Makefile
        plugins/ctf/fs/Makefile
        plugins/ctf/lttng-live/Makefile
+       plugins/correlator/Makefile
        plugins/text/Makefile
        babeltrace.pc
        babeltrace-ctf.pc
index a04ee3d1ee63d84a4cc0bbf381e194c8e4400d25..a36d6b72eae2a189d583677c600bd09e589dff2e 100644 (file)
@@ -148,6 +148,11 @@ bt_component_factory_register_sink_component_class(
                struct bt_component_factory *factory, const char *name,
                const char *description, bt_component_init_cb init);
 
+extern enum bt_component_factory_status
+bt_component_factory_register_filter_component_class(
+               struct bt_component_factory *factory, const char *name,
+               const char *description, bt_component_init_cb init);
+
 #ifdef __cplusplus
 }
 #endif
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..271db63f02fe81948c82b94d58f1db15c6f38386 100644 (file)
@@ -0,0 +1,67 @@
+#ifndef BABELTRACE_PLUGIN_FILTER_INTERNAL_H
+#define BABELTRACE_PLUGIN_FILTER_INTERNAL_H
+
+/*
+ * BabelTrace - Filter Component Internal
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: 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/babeltrace-internal.h>
+#include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/component-class-internal.h>
+#include <babeltrace/plugin/plugin-system.h>
+
+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;
+};
+
+/**
+ * Allocate a filter component.
+ *
+ * @param class                        Component class
+ * @param params               A dictionary of component parameters
+ * @returns                    A filter component instance
+ */
+BT_HIDDEN
+struct bt_component *bt_component_filter_create(
+               struct bt_component_class *class, struct bt_value *params);
+
+/**
+ * Validate a filter component.
+ *
+ * @param component            Filter component instance to validate
+ * @returns                    One of #bt_component_status
+ */
+BT_HIDDEN
+enum bt_component_status bt_component_filter_validate(
+               struct bt_component *component);
+
+#endif /* BABELTRACE_PLUGIN_FILTER_INTERNAL_H */
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a3a8984ca9589e0ed4b65b2fe5133d3c61eb7e33 100644 (file)
@@ -0,0 +1,64 @@
+#ifndef BABELTRACE_PLUGIN_FILTER_H
+#define BABELTRACE_PLUGIN_FILTER_H
+
+/*
+ * BabelTrace - Filter Plug-in Interface
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: 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 <stdint.h>
+#include <babeltrace/plugin/component.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_component;
+struct bt_notification_iterator;
+
+/**
+ * Add a notification iterator to a filter component.
+ *
+ * @param component    Component instance
+ * @param iterator     Notification iterator to add
+ * @returns            One of #bt_component_status values
+ */
+enum bt_component_status bt_component_filter_add_iterator(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator);
+
+/**
+ * Create an iterator on a component instance.
+ *
+ * @param component    Component instance
+ * @returns            Notification iterator instance
+ */
+struct bt_notification_iterator *bt_component_filter_create_iterator(
+               struct bt_component *component);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_PLUGIN_FILTER_H */
index 26c3ebc35e8e91341fe14ee3b65881c5a37c533b..4fb107f938943092ee0440fd307a66fc57025ed1 100644 (file)
        bt_component_factory_register_sink_component_class(factory,             \
                        _name, _description, _init);
 
+#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ENTRY(_name, _description, _init)     \
+       bt_component_factory_register_filter_component_class(factory,           \
+                       _name, _description, _init);
+
 #define BT_PLUGIN_COMPONENT_CLASSES_END                                                \
        return BT_COMPONENT_STATUS_OK;                                          \
 }                                                                              \
index ec84b872926bdc369c2d16ed43e504bf16774024..70b67cfddf5c6b78c6aca7364d9877feb9ffe548 100644 (file)
@@ -183,6 +183,71 @@ 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);
+
 /** bt_notification_iterator */
 /**
  * Function returning an iterator's current notification.
index 7329eeebe9bd927d97923484df0eb6c2ba20dcc1..51df185d45d4ce101aaa42f8a4cbd9b4cedbf164 100644 (file)
@@ -4,7 +4,7 @@
 /*
  * BabelTrace - Source Plug-in Interface
  *
- * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
index 3fb02057c4a042db71c7176a8022c2164234630c..8fe32f816647531c37b08a3121c3f09089aa50e5 100644 (file)
@@ -458,3 +458,12 @@ bt_component_factory_register_sink_component_class(
        return add_component_class(factory, name, description, init,
                        BT_COMPONENT_TYPE_SINK);
 }
+
+enum bt_component_factory_status
+bt_component_factory_register_filter_component_class(
+               struct bt_component_factory *factory, const char *name,
+               const char *description, bt_component_init_cb init)
+{
+       return add_component_class(factory, name, description, init,
+                       BT_COMPONENT_TYPE_FILTER);
+}
diff --git a/lib/plugin-system/filter.c b/lib/plugin-system/filter.c
new file mode 100644 (file)
index 0000000..33cceae
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * filter.c
+ *
+ * Babeltrace Filter Component
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: 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/compiler.h>
+#include <babeltrace/values.h>
+#include <babeltrace/plugin/filter-internal.h>
+#include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/notification/notification.h>
+
+
index 41568098be3d3fc7d225b9b3e3c3731f471fd858..eee1349797b78f60841daff86586616b7d8be5f0 100644 (file)
@@ -1 +1 @@
-SUBDIRS = ctf text
+SUBDIRS = ctf text correlator
diff --git a/plugins/correlator/Makefile.am b/plugins/correlator/Makefile.am
new file mode 100644 (file)
index 0000000..43e2616
--- /dev/null
@@ -0,0 +1,16 @@
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+SUBDIRS = .
+
+plugindir = "$(PLUGINSDIR)"
+plugin_LTLIBRARIES = libbabeltrace-plugin-correlator.la
+
+libbabeltrace_plugin_correlator_la_SOURCES = \
+       correlator.h correlator.c
+
+libbabeltrace_plugin_correlator_la_LDFLAGS = \
+       -version-info $(BABELTRACE_LIBRARY_VERSION)
+
+libbabeltrace_plugin_ctf_text_la_LIBADD = \
+       $(top_builddir)/lib/libbabeltrace.la \
+       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
diff --git a/plugins/correlator/correlator.c b/plugins/correlator/correlator.c
new file mode 100644 (file)
index 0000000..c0c9dc7
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * correlator.c
+ *
+ * Babeltrace Trace Correlator
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: 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/plugin/plugin-macros.h>
+#include <babeltrace/plugin/component.h>
+#include <babeltrace/plugin/filter.h>
+#include <babeltrace/plugin/notification/notification.h>
+#include <babeltrace/plugin/notification/iterator.h>
+#include <babeltrace/plugin/notification/event.h>
+#include "correlator.h"
+
+static
+void destroy_correlator_data(struct correlator *correlator)
+{
+       g_free(correlator);
+}
+
+static
+struct correlator *create_correlator(void)
+{
+       struct correlator *correlator;
+
+       correlator = g_new0(struct correlator, 1);
+       if (!correlator) {
+               goto end;
+       }
+end:
+       return correlator;
+}
+
+static
+void destroy_correlator(struct bt_component *component)
+{
+       void *data = bt_component_get_private_data(component);
+
+       destroy_correlator_data(data);
+}
+
+enum bt_component_status correlator_component_init(
+       struct bt_component *component, struct bt_value *params)
+{
+       enum bt_component_status ret;
+       struct correlator *correlator = create_correlator();
+
+       if (!correlator) {
+               ret = BT_COMPONENT_STATUS_NOMEM;
+               goto end;
+       }
+
+       ret = bt_component_set_destroy_cb(component,
+                       destroy_correlator);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       ret = bt_component_set_private_data(component, correlator);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+end:
+       return ret;
+error:
+       destroy_correlator_data(correlator);
+       return ret;
+}
+
+/* Initialize plug-in entry points. */
+BT_PLUGIN_NAME("correlator");
+BT_PLUGIN_DESCRIPTION("Babeltrace Trace Correlator Plug-In.");
+BT_PLUGIN_AUTHOR("Jérémie Galarneau");
+BT_PLUGIN_LICENSE("MIT");
+
+BT_PLUGIN_COMPONENT_CLASSES_BEGIN
+BT_PLUGIN_FILTER_COMPONENT_CLASS_ENTRY("correlator",
+               "Time-correlate multiple traces.",
+               correlator_component_init)
+BT_PLUGIN_COMPONENT_CLASSES_END
This page took 0.032381 seconds and 4 git commands to generate.