*/
#include <babeltrace/ctf-ir/packet.h>
-#include <babeltrace/plugin/plugin-macros.h>
-#include <babeltrace/plugin/component.h>
-#include <babeltrace/plugin/sink.h>
-#include <babeltrace/plugin/notification/notification.h>
-#include <babeltrace/plugin/notification/iterator.h>
-#include <babeltrace/plugin/notification/event.h>
-#include <babeltrace/plugin/notification/packet.h>
+#include <babeltrace/plugin/plugin-dev.h>
+#include <babeltrace/component/component.h>
+#include <babeltrace/component/component-sink.h>
+#include <babeltrace/component/port.h>
+#include <babeltrace/component/connection.h>
+#include <babeltrace/component/notification/notification.h>
+#include <babeltrace/component/notification/iterator.h>
+#include <babeltrace/component/notification/event.h>
+#include <babeltrace/component/notification/packet.h>
+#include <plugins-common.h>
#include <stdio.h>
#include <stdbool.h>
#include <glib.h>
#include "writer.h"
+#include <assert.h>
static
void destroy_writer_component_data(struct writer_component *writer_component)
{
+ bt_put(writer_component->input_iterator);
g_hash_table_destroy(writer_component->stream_map);
g_hash_table_destroy(writer_component->stream_class_map);
g_hash_table_destroy(writer_component->trace_map);
+ g_string_free(writer_component->base_path, true);
+ g_string_free(writer_component->trace_name_base, true);
}
static
writer_component->err = stderr;
writer_component->trace_id = 0;
- snprintf(writer_component->trace_name_base, NAME_MAX, "trace");
+ writer_component->trace_name_base = g_string_new("trace");
+ if (!writer_component->trace_name_base) {
+ g_free(writer_component);
+ writer_component = NULL;
+ goto end;
+ }
/*
* Reader to writer corresponding structures.
}
switch (bt_notification_get_type(notification)) {
- case BT_NOTIFICATION_TYPE_PACKET_START:
+ case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
{
struct bt_ctf_packet *packet =
- bt_notification_packet_start_get_packet(notification);
+ bt_notification_packet_begin_get_packet(notification);
if (!packet) {
ret = BT_COMPONENT_STATUS_ERROR;
case BT_NOTIFICATION_TYPE_PACKET_END:
{
struct bt_ctf_packet *packet =
- bt_notification_packet_start_get_packet(notification);
+ bt_notification_packet_end_get_packet(notification);
if (!packet) {
ret = BT_COMPONENT_STATUS_ERROR;
return ret;
}
+static
+enum bt_component_status writer_component_new_connection(
+ struct bt_port *own_port, struct bt_connection *connection)
+{
+ enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+ struct bt_component *component;
+ struct writer_component *writer;
+
+ component = bt_port_get_component(own_port);
+ assert(component);
+ writer = bt_component_get_private_data(component);
+ assert(writer);
+ assert(!writer->input_iterator);
+ writer->input_iterator = bt_connection_create_notification_iterator(
+ connection);
+
+ if (!writer->input_iterator) {
+ ret = BT_COMPONENT_STATUS_ERROR;
+ }
+ bt_put(component);
+ return ret;
+}
+
static
enum bt_component_status run(struct bt_component *component)
{
struct writer_component *writer_component =
bt_component_get_private_data(component);
- ret = bt_component_sink_get_input_iterator(component, 0, &it);
- if (ret != BT_COMPONENT_STATUS_OK) {
+ it = writer_component->input_iterator;
+ assert(it);
+
+ notification = bt_notification_iterator_get_notification(it);
+ if (!notification) {
+ ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
goto end;
}
- notification = bt_notification_iterator_get_notification(it);
- if (!notification) {
- ret = BT_COMPONENT_STATUS_ERROR;
- goto end;
- }
-
ret = handle_notification(writer_component, notification);
end:
bt_put(it);
static
enum bt_component_status writer_component_init(
- struct bt_component *component, struct bt_value *params)
+ struct bt_component *component, struct bt_value *params,
+ UNUSED_VAR void *init_method_data)
{
enum bt_component_status ret;
enum bt_value_status value_ret;
goto error;
}
- strncpy(writer_component->base_path, path, PATH_MAX);
-
- ret = bt_component_set_destroy_cb(component,
- destroy_writer_component);
- if (ret != BT_COMPONENT_STATUS_OK) {
+ writer_component->base_path = g_string_new(path);
+ if (!writer_component) {
+ ret = BT_COMPONENT_STATUS_ERROR;
goto error;
}
goto error;
}
- ret = bt_component_sink_set_consume_cb(component,
- run);
- if (ret != BT_COMPONENT_STATUS_OK) {
- goto error;
- }
-
end:
return ret;
error:
destroy_writer_component_data(writer_component);
+ g_free(writer_component);
return ret;
}
/* Initialize plug-in entry points. */
-BT_PLUGIN_NAME("writer");
+BT_PLUGIN(writer);
BT_PLUGIN_DESCRIPTION("Babeltrace CTF-Writer output plug-in.");
BT_PLUGIN_AUTHOR("Jérémie Galarneau");
BT_PLUGIN_LICENSE("MIT");
-
-BT_PLUGIN_COMPONENT_CLASSES_BEGIN
-BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY("writer",
- "Formats CTF-IR to CTF.",
- writer_component_init)
-BT_PLUGIN_COMPONENT_CLASSES_END
+BT_PLUGIN_SINK_COMPONENT_CLASS(writer, run);
+BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(writer, writer_component_init);
+BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD(writer,
+ writer_component_new_connection);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(writer, destroy_writer_component);
+BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(writer, "Formats CTF-IR to CTF.");