#include <babeltrace/plugin/component-internal.h>
#include <babeltrace/plugin/plugin-system.h>
-/** Component initialization functions */
-/**
- * Allocate a source component.
- *
- * @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_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_init_cb iterator_init_cb);
-
-/**
- * Allocate a sink component.
- *
- * @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 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);
+struct bt_component_factory {
+ int a;
+};
#endif /* BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H */
enum bt_component_status bt_component_factory_register_source_component_class(
struct bt_component_factory *factory, const char *name,
- bt_component_init_cb init, bt_component_fini_cb fini,
- bt_component_source_iterator_create_cb iterator_create_cb);
+ bt_component_source_init_cb init);
enum bt_component_status bt_component_factory_register_sink_component_class(
struct bt_component_factory *factory, const char *name,
- bt_component_init_cb init, bt_component_fini_cb fini,
- bt_component_sink_handle_notification_cb handle_notification_cb);
+ bt_component_sink_init_cb init);
void bt_component_factory_destroy(struct bt_component_factory *factory);
enum bt_component_type type;
/** No ownership taken */
FILE *error_stream;
+ /** source, sink or filter destroy */
+ bt_component_destroy_cb destroy;
void *user_data;
- bt_component_destroy_cb user_data_destroy;
- bt_component_destroy_cb destroy;
+ bt_component_destroy_cb user_destroy;
};
BT_HIDDEN
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);
+ const char *name, enum bt_component_type component_type,
+ bt_component_destroy_cb destroy);
#endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
bt_notification_iterator_get_cb get;
bt_notification_iterator_next_cb next;
void *user_data;
+ bt_notification_iterator_destroy_cb user_destroy;
};
/**
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 */
* @see bt_notification_iterator_get_notification()
*/
extern enum bt_notification_iterator_status *bt_notification_iterator_seek(
- struct bt_notification_iterator *iterator,
- int whence,
+ struct bt_notification_iterator *iterator, int whence,
int64_t time);
/**
typedef void (*bt_component_destroy_cb)(struct bt_component *component);
/**
- * Iterator creation function type.
+ * Source component initialization function type.
+ *
+ * A source component's iterator initialization callback, private data and
+ * deinitialization callback must be set by this function.
+ *
+ * @param component Component instance
+ */
+typedef struct bt_component *(*bt_component_source_init_cb)(
+ struct bt_component *component);
+
+/**
+ * Sink component initialization function type.
+ *
+ * A sink component's notification handling callback, private data and
+ * deinitialization callback must be set by this function.
*
* @param component Component instance
*/
+typedef struct bt_component *(*bt_component_sink_init_cb)(
+ struct bt_component *component);
+
+/**
+ * Iterator initialization function type.
+ *
+ * @param component Component instance
+ * @param iterator Iterator instance
+ */
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);
+/**
+ * Get a component's private 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);
-typedef struct bt_component *(*bt_component_fini_cb)(
- struct bt_component *component);
+/**
+ * Set a component's private data.
+ *
+ * @param component Component of which to set the 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);
+
+/**
+ * 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 component Component instance
+ * @param iterator Notification iterator instance
+ */
+typedef enum bt_component_status (*bt_component_source_init_iterator_cb)(
+ struct bt_component *component,
+ struct bt_notification_iterator *iterator);
+/**
+ * Set a source component's iterator initialization function.
+ *
+ * @param component Component instance
+ * @param init_iterator Notification iterator initialization callback
+ */
+extern enum bt_component_status
+bt_component_source_set_iterator_init_cb(struct bt_component *component,
+ bt_component_source_init_iterator_cb init_iterator);
+
+/** bt_component_sink */
/**
* Notification handling function type.
*
typedef enum bt_component_status (*bt_component_sink_handle_notification_cb)(
struct bt_component *, struct bt_notification *);
+/**
+ * Set a sink component's notification handling callback.
+ *
+ * @param component Component instance
+ * @param handle_notification Notification handling callback
+ * @returns One of #bt_component_status values
+ */
+extern enum bt_component_status
+bt_component_sink_set_handle_notification_cb(struct bt_component *component,
+ bt_component_sink_handle_notification_cb handle_notification);
+
+/** bt_component_notification_iterator */
+/**
+ * Function returning an iterator's current notification.
+ *
+ * @param iterator Notification iterator instance
+ * @returns A notification instance
+ */
typedef struct bt_notification *(*bt_notification_iterator_get_cb)(
- struct bt_notification_iterator *);
+ struct bt_notification_iterator *iterator);
+/**
+ * Function advancing an iterator's position.
+ *
+ * @param iterator Notification iterator instance
+ * @returns One of #bt_notification_iterator_status values
+ */
typedef enum bt_notification_iterator_status (*bt_notification_iterator_next_cb)(
- struct bt_notification_iterator *);
+ struct bt_notification_iterator *iterator);
/**
- * Get a component's private (implementation) data.
+ * Function cleaning-up an iterator's private data on destruction.
*
- * @param component Component of which to get the private data
- * @returns Component's private data
+ * @param iterator Notification iterator instance
*/
-extern void *bt_component_get_private_data(struct bt_component *component);
+typedef void (*bt_notification_iterator_destroy_cb)(
+ struct bt_notification_iterator *iterator);
extern enum bt_notification_iterator_status
bt_notification_iterator_set_get_cb(struct bt_notification_iterator *iterator,
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_destroy_cb(
+ struct bt_notification_iterator *iterator,
+ bt_notification_iterator_destroy_cb destroy);
+
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.
- *
- * @param component Component of which to set the 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);
-
#ifdef __cplusplus
}
#endif
struct bt_component_factory *factory)\
{
-#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init, _fini, _it_cr) \
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init) \
bt_component_factory_register_source_component_class(factory, \
- _name, _init, _fini, _it_cr);
+ _name, _init);
-#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init, _fini, _hd_notif) \
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init) \
bt_component_factory_register_sink_component_class(factory, \
- _name, _init, _fini, _hd_notif);
+ _name, _init);
#define BT_PLUGIN_COMPONENT_CLASSES_END\
\
bt_component_sink_handle_notification_cb handle_notification;
};
+/**
+ * Allocate a sink component.
+ *
+ * @param name Component instance name (will be copied)
+ * @returns A sink component instance
+ */
+BT_HIDDEN
+extern struct bt_component *bt_component_sink_create(const char *name);
+
#endif /* BABELTRACE_PLUGIN_SINK_INTERNAL_H */
struct bt_component parent;
/* Component implementation callbacks */
- bt_component_source_iterator_init_cb init_iterator;
+ bt_component_source_init_iterator_cb init_iterator;
};
+/**
+ * Allocate a source component.
+ *
+ * @param name Component instance name (will be copied)
+ * @returns A source component instance
+ */
+BT_HIDDEN
+extern struct bt_component *bt_component_source_create(const char *name);
+
#endif /* BABELTRACE_PLUGIN_SOURCE_INTERNAL_H */
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_type component_type,
- bt_component_destroy_cb component_destroy)
+ const char *name, enum bt_component_type component_type,
+ bt_component_destroy_cb destroy)
{
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
- if (!component || !name || name[0] == '\0' ||
- !user_destroy_func || !user_data || !component_destroy) {
+ if (!component || !name || name[0] == '\0' || destroy) {
ret = BT_COMPONENT_STATUS_INVAL;
goto end;
}
bt_ctf_ref_init(&component->ref_count);
component->type = component_type;
- component->user_data = user_data;
- component->user_data_destroy = user_destroy_func;
- component->destroy = component_destroy;
-
component->name = g_string_new(name);
if (!component->name) {
ret = BT_COMPONENT_STATUS_NOMEM;
goto end;
}
+ component->destroy = destroy;
end:
return ret;
}
* User data is destroyed first, followed by the concrete component
* instance.
*/
- assert(!component->user_data || component->user_data_destroy);
- component->user_data_destroy(component->user_data);
+ assert(!component->user_data || component->user_destroy);
+ component->user_destroy(component->user_data);
g_string_free(component->name, TRUE);
#include <babeltrace/plugin/notification/iterator-internal.h>
static
-void bt_notification_iterator_destroy(struct bt_notification_iterator *iterator)
+void bt_notification_iterator_destroy(struct bt_ctf_ref *ref)
{
-
+ struct bt_notification_iterator *iterator;
+
+ if (!ref) {
+ return;
+ }
+
+ iterator = container_of(ref, struct bt_notification_iterator,
+ ref_count);
+ assert(iterator->user_destroy || !iterator->user_data);
+ iterator->user_destroy(iterator);
+ g_free(iterator);
}
BT_HIDDEN
{
struct bt_notification_iterator *iterator = NULL;
- if (!component || bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
+ if (!component ||
+ bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
goto end;
}
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;
+ enum bt_notification_iterator_status ret =
+ BT_NOTIFICATION_ITERATOR_STATUS_OK;
if (!iterator || !iterator->get || !iterator->next) {
ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
bt_ctf_ref_put(&iterator->ref_count, bt_notification_iterator_destroy);
}
+
+enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
+ struct bt_notification_iterator *iterator,
+ bt_notification_iterator_get_cb get)
+{
+ enum bt_notification_iterator_status ret;
+
+ if (!iterator || !get) {
+ ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
+ goto end;
+ }
+
+
+end:
+ return ret;
+}
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)
+BT_HIDDEN
+struct bt_component *bt_component_sink_create(const char *name)
{
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);
+ ret = bt_component_init(&sink->parent, name, 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;
}
g_free(source);
}
-struct bt_component *bt_component_source_create(const char *name,
- void *private_data, bt_component_destroy_cb destroy_func,
- bt_component_source_iterator_init_cb iterator_init_cb)
+BT_HIDDEN
+struct bt_component *bt_component_source_create(const char *name)
{
struct bt_component_source *source = NULL;
enum bt_component_status ret;
-
- if (!iterator_init_cb) {
- goto end;
- }
-
source = g_new0(struct bt_component_source, 1);
if (!source) {
goto end;
}
- ret = bt_component_init(&source->parent, name, private_data,
- destroy_func, BT_COMPONENT_TYPE_SOURCE,
- bt_component_source_destroy);
+ ret = bt_component_init(&source->parent, name,
+ BT_COMPONENT_TYPE_SOURCE, bt_component_source_destroy);
if (ret != BT_COMPONENT_STATUS_OK) {
g_free(source);
source = NULL;
goto end;
}
-
- source->init_iterator = iterator_init_cb;
end:
return source ? &source->parent : NULL;
}