X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fwriter%2Fwriter.c;h=3bca09b61f79f466756c8a50c0ea109f791b58b4;hb=fa054faf3a18fd8003510c32718c1fd4fbf3dd46;hp=a01b5c4a53497e02e91e21b93f43194eedf4365e;hpb=9057f0376ea389c66bc9a3f19790ccc193e1de60;p=babeltrace.git diff --git a/plugins/writer/writer.c b/plugins/writer/writer.c index a01b5c4a..3bca09b6 100644 --- a/plugins/writer/writer.c +++ b/plugins/writer/writer.c @@ -27,21 +27,28 @@ */ #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include "writer.h" +#include 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); @@ -50,10 +57,10 @@ void destroy_writer_component_data(struct writer_component *writer_component) } static -void destroy_writer_component(struct bt_component *component) +void finalize_writer_component(struct bt_private_component *component) { struct writer_component *writer_component = (struct writer_component *) - bt_component_get_private_data(component); + bt_private_component_get_user_data(component); destroy_writer_component_data(writer_component); g_free(writer_component); @@ -62,22 +69,19 @@ void destroy_writer_component(struct bt_component *component) static void unref_stream_class(struct bt_ctf_stream_class *writer_stream_class) { - BT_PUT(writer_stream_class); - g_free(writer_stream_class); + bt_put(writer_stream_class); } static void unref_stream(struct bt_ctf_stream_class *writer_stream) { - BT_PUT(writer_stream); - g_free(writer_stream); + bt_put(writer_stream); } static void unref_trace(struct bt_ctf_writer *writer) { - BT_PUT(writer); - g_free(writer); + bt_put(writer); } static @@ -93,6 +97,7 @@ struct writer_component *create_writer_component(void) writer_component->err = stderr; writer_component->trace_id = 0; writer_component->trace_name_base = g_string_new("trace"); + writer_component->processed_first_event = false; if (!writer_component->trace_name_base) { g_free(writer_component); writer_component = NULL; @@ -126,10 +131,10 @@ enum bt_component_status handle_notification( } 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; @@ -143,7 +148,7 @@ enum bt_component_status handle_notification( 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; @@ -180,22 +185,62 @@ end: } static -enum bt_component_status run(struct bt_component *component) +void writer_component_port_connected( + struct bt_private_component *component, + struct bt_private_port *self_port, + struct bt_port *other_port) +{ + struct bt_private_connection *connection; + struct writer_component *writer; + + writer = bt_private_component_get_user_data(component); + assert(writer); + assert(!writer->input_iterator); + connection = bt_private_port_get_private_connection(self_port); + assert(connection); + writer->input_iterator = + bt_private_connection_create_notification_iterator(connection, + NULL); + + if (!writer->input_iterator) { + writer->error = true; + } + + bt_put(connection); +} + +static +enum bt_component_status run(struct bt_private_component *component) { enum bt_component_status ret; struct bt_notification *notification = NULL; struct bt_notification_iterator *it; struct writer_component *writer_component = - bt_component_get_private_data(component); + bt_private_component_get_user_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); + + if (unlikely(writer_component->error)) { + ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = bt_notification_iterator_next(it); - if (ret != BT_COMPONENT_STATUS_OK) { - goto end; + if (likely(writer_component->processed_first_event)) { + enum bt_notification_iterator_status it_ret; + + it_ret = bt_notification_iterator_next(it); + switch (it_ret) { + case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_COMPONENT_STATUS_END; + BT_PUT(writer_component->input_iterator); + goto end; + default: + break; + } } notification = bt_notification_iterator_get_notification(it); @@ -205,27 +250,38 @@ enum bt_component_status run(struct bt_component *component) } ret = handle_notification(writer_component, notification); + writer_component->processed_first_event = true; end: - bt_put(it); bt_put(notification); return ret; } static enum bt_component_status writer_component_init( - struct bt_component *component, struct bt_value *params) + struct bt_private_component *component, struct bt_value *params, + UNUSED_VAR void *init_method_data) { enum bt_component_status ret; enum bt_value_status value_ret; struct writer_component *writer_component = create_writer_component(); struct bt_value *value = NULL; const char *path; + void *priv_port; if (!writer_component) { ret = BT_COMPONENT_STATUS_NOMEM; goto end; } + priv_port = bt_private_component_sink_add_input_private_port(component, + "in", NULL); + if (!priv_port) { + ret = BT_COMPONENT_STATUS_NOMEM; + goto end; + } + + bt_put(priv_port); + value = bt_value_map_get(params, "path"); if (!value || bt_value_is_null(value) || !bt_value_is_string(value)) { fprintf(writer_component->err, @@ -239,6 +295,7 @@ enum bt_component_status writer_component_init( ret = BT_COMPONENT_STATUS_INVALID; goto error; } + bt_put(value); writer_component->base_path = g_string_new(path); if (!writer_component) { @@ -246,19 +303,7 @@ enum bt_component_status writer_component_init( goto error; } - ret = bt_component_set_destroy_cb(component, - destroy_writer_component); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - - ret = bt_component_set_private_data(component, writer_component); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - - ret = bt_component_sink_set_consume_cb(component, - run); + ret = bt_private_component_set_user_data(component, writer_component); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } @@ -267,17 +312,18 @@ 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_PORT_CONNECTED_METHOD(writer, + writer_component_port_connected); +BT_PLUGIN_SINK_COMPONENT_CLASS_FINALIZE_METHOD(writer, finalize_writer_component); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(writer, "Formats CTF-IR to CTF.");