Add iterator and source implementations
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 10 Jul 2015 21:15:17 +0000 (17:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:25 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
12 files changed:
include/babeltrace/plugin/component-factory-internal.h
include/babeltrace/plugin/component-factory.h
include/babeltrace/plugin/component-internal.h
include/babeltrace/plugin/notification/iterator-internal.h
include/babeltrace/plugin/notification/iterator.h
include/babeltrace/plugin/plugin-system.h
include/babeltrace/plugin/source-internal.h
include/babeltrace/plugin/source.h
plugins/component.c
plugins/iterator.c
plugins/sink.c
plugins/source.c

index 4810e9cad450bc567ec90f58eb18edf71933f922..69c16419396c908949e9f4ce91af87c113f76582 100644 (file)
  * @param name                 Component instance name (will be copied)
  * @param private_data         Private component implementation data
  * @param destroy_cb           Component private data clean-up callback
- * @param iterator_create_cb   Iterator creation callback
+ * @param iterator_init_cb     Iterator initialization 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);
+               bt_component_source_iterator_init_cb iterator_init_cb);
 
 /**
  * Allocate a sink component.
index 06c613799a99f69c494e5c3b76757b8d4f477b40..29e2eb5fe643384a1c4c34f56217bcefd7d857bd 100644 (file)
@@ -37,12 +37,6 @@ extern "C" {
 
 struct bt_component_factory;
 
-typedef struct bt_component *(*bt_component_init_cb)(
-               struct bt_component *component);
-
-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(
index 6c8689aaabd5cd2dfd781bd2bdac35b3f31bd439..ea6c489daf681d64bc3b22fe615c4e9218c4be84 100644 (file)
  */
 
 #include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/plugin/plugin.h>
-#include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/plugin-system.h>
+#include <babeltrace/plugin/component.h>
 #include <babeltrace/ctf-writer/ref-internal.h>
 #include <glib.h>
 #include <stdio.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct bt_notification;
-
 struct bt_component {
        struct bt_ctf_ref ref_count;
        GString *name;
@@ -54,14 +47,10 @@ struct bt_component {
 };
 
 BT_HIDDEN
-enum bt_component_status bt_component_init(struct bt_component *plugin,
+enum bt_component_status bt_component_init(struct bt_component *component,
                const char *name, void *user_data,
                bt_component_destroy_cb destroy_func,
                enum bt_component_type component_type,
                bt_component_destroy_cb component_destroy);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6d1676e1d8733704f38c933807f1d35ae5354caf 100644 (file)
@@ -0,0 +1,70 @@
+#ifndef BABELTRACE_PLUGIN_ITERATOR_INTERNAL_H
+#define BABELTRACE_PLUGIN_ITERATOR_INTERNAL_H
+
+/*
+ * BabelTrace - Notification Iterator Internal
+ *
+ * Copyright 2015 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/plugin-system.h>
+#include <babeltrace/ctf-writer/ref-internal.h>
+
+struct bt_notification_iterator {
+       struct bt_ctf_ref ref_count;
+       bt_notification_iterator_get_cb get;
+       bt_notification_iterator_next_cb next;
+       void *user_data;
+};
+
+/**
+ * Allocate a notification iterator.
+ *
+ * @param component            Component instance
+ * @returns                    A notification iterator instance
+ */
+BT_HIDDEN
+struct bt_notification_iterator *bt_notification_iterator_create(
+               struct bt_component *component);
+
+/**
+ * Validate a notification iterator.
+ *
+ * @param iterator             Notification iterator instance
+ * @returns                    One of #bt_component_status values
+ */
+BT_HIDDEN
+enum bt_notification_iterator_status bt_notification_iterator_validate(
+               struct bt_notification_iterator *iterator);
+
+/**
+ * Destroy a notification iterator.
+ *
+ * @param iterator             Notification iterator instance
+ */
+BT_HIDDEN
+void bt_notification_iterator_destroy(
+               struct bt_notification_iterator *iterator);
+
+#endif /* BABELTRACE_PLUGIN_ITERATOR_INTERNAL_H */
index 18ee4f625a0d818013affa723d0fc0b5cf5f6757..22807e41ab6f509c0660f7f2e7aea0603f5f98e6 100644 (file)
@@ -42,7 +42,7 @@ struct bt_notification_iterator;
 enum bt_notification_iterator_status {
        /** Invalid arguments. */
        /* -22 for compatibility with -EINVAL */
-       BT_NOTIFICATION_ITERATOR_STATUS_EINVAL = -22,
+       BT_NOTIFICATION_ITERATOR_STATUS_INVAL = -22,
 
        /** End of trace. */
        BT_NOTIFICATION_ITERATOR_STATUS_EOT = -3,
index e7ca01a58dca2bbc58f8c83b0c797fd850885120..9a9332006a477b0e2345fb2ad9b44e71c59351d8 100644 (file)
  */
 
 #include <babeltrace/objects.h>
-#include <babeltrace/plugin/notification/iterator.h>
+#include <babeltrace/objects.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct bt_notification;
+struct bt_notification_iterator;
+struct bt_component;
 
 /**
  * Component private data deallocation function type.
@@ -51,8 +53,14 @@ typedef void (*bt_component_destroy_cb)(struct bt_component *component);
  *
  * @param component    Component instance
  */
-typedef struct bt_notification_iterator *(
-               *bt_component_source_iterator_create_cb)(
+typedef enum bt_component_status (*bt_component_source_iterator_init_cb)(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator);
+
+typedef struct bt_component *(*bt_component_init_cb)(
+               struct bt_component *component);
+
+typedef struct bt_component *(*bt_component_fini_cb)(
                struct bt_component *component);
 
 /**
@@ -65,10 +73,10 @@ typedef struct bt_notification_iterator *(
 typedef enum bt_component_status (*bt_component_sink_handle_notification_cb)(
                struct bt_component *, struct bt_notification *);
 
-typedef struct bt_notification *(bt_notification_iterator_get_notification_cb)(
+typedef struct bt_notification *(*bt_notification_iterator_get_cb)(
                struct bt_notification_iterator *);
 
-typedef enum bt_notification_iterator_status (bt_notification_iterator_next_cb)(
+typedef enum bt_notification_iterator_status (*bt_notification_iterator_next_cb)(
                struct bt_notification_iterator *);
 
 /**
@@ -79,6 +87,21 @@ typedef enum bt_notification_iterator_status (bt_notification_iterator_next_cb)(
  */
 extern void *bt_component_get_private_data(struct bt_component *component);
 
+extern enum bt_notification_iterator_status
+bt_notification_iterator_set_get_cb(struct bt_notification_iterator *iterator,
+               bt_notification_iterator_get_cb get);
+
+extern enum bt_notification_iterator_status
+bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator,
+               bt_notification_iterator_next_cb next);
+
+extern enum bt_notification_iterator_status
+bt_notification_iterator_set_private_data(
+               struct bt_notification_iterator *iterator, void *data);
+
+extern void *bt_notification_iterator_get_private_data(
+               struct bt_notification_iterator *iterator);
+
 /**
  * Set a component's private (implementation) data.
  *
@@ -89,21 +112,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);
 
-
-/** Notification iterator functions */
-/**
- * Allocate a notification iterator.
- *
- * @param component            Component instance
- * @param next_cb              Callback advancing to the next notification
- * @param notification_cb      Callback providing the current notification
- * @returns                    A notification iterator instance
- */
-extern struct bt_notification_iterator *bt_notification_iterator_create(
-               struct bt_component *component,
-               bt_notification_iterator_next_cb next_cb,
-               bt_notification_iterator_get_notification_cb notification_cb);
-
 #ifdef __cplusplus
 }
 #endif
index 75508dce8a902a2599fc5a0583ea6d317ccf720b..0388105309bec560497b53019315ea9e276d314c 100644 (file)
@@ -35,7 +35,7 @@ struct bt_component_source {
        struct bt_component parent;
 
        /* Component implementation callbacks */
-       bt_component_source_iterator_create_cb create_iterator;
+       bt_component_source_iterator_init_cb init_iterator;
 };
 
 #endif /* BABELTRACE_PLUGIN_SOURCE_INTERNAL_H */
index a333e392632f4fdfccc7e6fcef4c9d8d82dda5af..13faedd0a5ffd0266dcfe1f64a5040d807be3e40 100644 (file)
 extern "C" {
 #endif
 
-struct bt_plugin;
+struct bt_component;
 struct bt_notification_iterator;
 
 /**
- * Create an iterator on a plug-in instance.
+ * Create an iterator on a component instance.
  *
- * @param plugin       Plug-in instance
+ * @param component    Component instance
  * @returns            Notification iterator instance
  */
-struct bt_notification_iterator *bt_plugin_source_create_iterator(
-               struct bt_plugin *plugin);
+struct bt_notification_iterator *bt_component_source_create_iterator(
+               struct bt_component *component);
 
 #ifdef __cplusplus
 }
index 5b7a23b3666472484f9a6e389030be920ea5c83a..f977c837e0c7afa5372774af0e4cd85e72abc811 100644 (file)
@@ -26,6 +26,7 @@
  * SOFTWARE.
  */
 
+#include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/component-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler.h>
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..66f918c8dbe629a266fd14380c5e915943d970fa 100644 (file)
@@ -0,0 +1,91 @@
+/*
+ * iterator.c
+ *
+ * Babeltrace Notification Iterator
+ *
+ * Copyright 2015 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/plugin/component.h>
+#include <babeltrace/plugin/source-internal.h>
+#include <babeltrace/plugin/notification/iterator.h>
+#include <babeltrace/plugin/notification/iterator-internal.h>
+
+static
+void bt_notification_iterator_destroy(struct bt_notification_iterator *iterator)
+{
+       
+}
+
+BT_HIDDEN
+struct bt_notification_iterator *bt_notification_iterator_create(
+               struct bt_component *component)
+{
+       struct bt_notification_iterator *iterator = NULL;
+
+       if (!component || bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
+               goto end;
+       }
+
+       iterator = g_new0(struct bt_notification_iterator, 1);
+       if (!iterator) {
+               goto end;
+       }
+
+       bt_ctf_ref_init(&iterator->ref_count);
+end:
+       return iterator;
+}
+
+BT_HIDDEN
+enum bt_notification_iterator_status bt_notification_iterator_validate(
+               struct bt_notification_iterator *iterator)
+{
+       enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
+
+       if (!iterator || !iterator->get || !iterator->next) {
+               ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+void bt_notification_iterator_get(struct bt_notification_iterator *iterator)
+{
+       if (!iterator) {
+               return;
+       }
+
+       bt_ctf_ref_get(&iterator->ref_count);
+}
+
+void bt_notification_iterator_put(struct bt_notification_iterator *iterator)
+{
+       if (!iterator) {
+               return;
+       }
+
+       bt_ctf_ref_put(&iterator->ref_count, bt_notification_iterator_destroy);
+}
index ea7d799373e02757fe45a3eb7912e6548ee7149c..fcbc94857f215e57db05e6ff38a1e05f871f2e95 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * sink.c
  *
- * Babeltrace Source Component
+ * Babeltrace Sink Component
  *
  * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
index d32fa2a7071df83e2a24990c71ae32a1f8678c8b..b722059bd0823273cbee62b6c86fc1ebde804dc6 100644 (file)
@@ -29,6 +29,8 @@
 #include <babeltrace/compiler.h>
 #include <babeltrace/plugin/source-internal.h>
 #include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/notification/iterator.h>
+#include <babeltrace/plugin/notification/iterator-internal.h>
 
 static
 void bt_component_source_destroy(struct bt_component *component)
@@ -45,12 +47,12 @@ void bt_component_source_destroy(struct bt_component *component)
 
 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)
+               bt_component_source_iterator_init_cb iterator_init_cb)
 {
        struct bt_component_source *source = NULL;
        enum bt_component_status ret;
 
-       if (!iterator_create_cb) {
+       if (!iterator_init_cb) {
                goto end;
        }
 
@@ -68,7 +70,46 @@ struct bt_component *bt_component_source_create(const char *name,
                goto end;
        }
 
-       source->create_iterator = iterator_create_cb;
+       source->init_iterator = iterator_init_cb;
 end:
        return source ? &source->parent : NULL;
 }
+
+struct bt_notification_iterator *bt_plugin_source_create_iterator(
+               struct bt_component *component)
+{
+       enum bt_component_status ret_component;
+       enum bt_notification_iterator_status ret_iterator;
+       struct bt_component_source *source;
+       struct bt_notification_iterator *iterator = NULL;
+
+       if (!component) {
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
+               goto end;
+       }
+
+       iterator = bt_notification_iterator_create(component);
+       if (!iterator) {
+               goto end;
+       }
+
+       source = container_of(component, struct bt_component_source, parent);
+       assert(source->init_iterator);
+       ret_component = source->init_iterator(component, iterator);
+       if (ret_component != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       ret_iterator = bt_notification_iterator_validate(iterator);
+       if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+               goto error;
+       }
+end:
+       return iterator;
+error:
+       bt_notification_iterator_put(iterator);
+       return NULL;
+}
This page took 0.032398 seconds and 4 git commands to generate.