* @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.
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(
*/
#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;
};
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 */
+#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 */
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,
*/
#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.
*
* @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);
/**
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 *);
/**
*/
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.
*
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
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 */
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
}
* SOFTWARE.
*/
+#include <babeltrace/plugin/component.h>
#include <babeltrace/plugin/component-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler.h>
+/*
+ * 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);
+}
/*
* sink.c
*
- * Babeltrace Source Component
+ * Babeltrace Sink Component
*
* Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
#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)
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;
}
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;
+}