#include <babeltrace/graph/notification-iterator.h>
#include <babeltrace/graph/notification-event.h>
#include <babeltrace/graph/notification-packet.h>
+#include <babeltrace/graph/notification-stream.h>
#include <plugins-common.h>
#include <stdio.h>
#include <stdbool.h>
#include "writer.h"
#include <assert.h>
+gboolean empty_trace_map(gpointer key, gpointer value, gpointer user_data)
+{
+ struct fs_writer *fs_writer = value;
+ struct writer_component *writer_component = user_data;
+
+ fs_writer->trace_static = 1;
+ writer_close(writer_component, fs_writer);
+
+ return TRUE;
+}
+
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_foreach_remove(writer_component->trace_map,
+ empty_trace_map, writer_component);
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
-void unref_stream_class(struct bt_ctf_stream_class *writer_stream_class)
-{
- bt_put(writer_stream_class);
-}
-
-static
-void unref_stream(struct bt_ctf_stream_class *writer_stream)
+void free_fs_writer(struct fs_writer *fs_writer)
{
- bt_put(writer_stream);
-}
-
-static
-void unref_trace(struct bt_ctf_writer *writer)
-{
- bt_put(writer);
+ bt_put(fs_writer->writer);
+ g_free(fs_writer);
}
static
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;
* Reader to writer corresponding structures.
*/
writer_component->trace_map = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, NULL, (GDestroyNotify) unref_trace);
- writer_component->stream_class_map = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, NULL, (GDestroyNotify) unref_stream_class);
- writer_component->stream_map = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, NULL, (GDestroyNotify) unref_stream);
+ g_direct_equal, NULL, (GDestroyNotify) free_fs_writer);
end:
return writer_component;
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
- ret = BT_COMPONENT_STATUS_OK;
ret = writer_output_event(writer_component, event);
bt_put(event);
if (ret != BT_COMPONENT_STATUS_OK) {
}
break;
}
+ case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
+ {
+ struct bt_ctf_stream *stream =
+ bt_notification_stream_begin_get_stream(notification);
+
+ if (!stream) {
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+ ret = writer_stream_begin(writer_component, stream);
+ bt_put(stream);
+ break;
+ }
case BT_NOTIFICATION_TYPE_STREAM_END:
+ {
+ struct bt_ctf_stream *stream =
+ bt_notification_stream_end_get_stream(notification);
+
+ if (!stream) {
+ ret = BT_COMPONENT_STATUS_ERROR;
+ goto end;
+ }
+ ret = writer_stream_end(writer_component, stream);
+ bt_put(stream);
break;
+ }
default:
puts("Unhandled notification type");
}
{
struct bt_private_connection *connection;
struct writer_component *writer;
+ static const enum bt_notification_type notif_types[] = {
+ BT_NOTIFICATION_TYPE_EVENT,
+ BT_NOTIFICATION_TYPE_PACKET_BEGIN,
+ BT_NOTIFICATION_TYPE_PACKET_END,
+ BT_NOTIFICATION_TYPE_STREAM_BEGIN,
+ BT_NOTIFICATION_TYPE_STREAM_END,
+ BT_NOTIFICATION_TYPE_SENTINEL,
+ };
writer = bt_private_component_get_user_data(component);
assert(writer);
assert(connection);
writer->input_iterator =
bt_private_connection_create_notification_iterator(connection,
- NULL);
+ notif_types);
if (!writer->input_iterator) {
writer->error = true;
struct bt_notification_iterator *it;
struct writer_component *writer_component =
bt_private_component_get_user_data(component);
-
- it = writer_component->input_iterator;
- assert(it);
+ enum bt_notification_iterator_status it_ret;
if (unlikely(writer_component->error)) {
ret = BT_COMPONENT_STATUS_ERROR;
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;
- }
- }
+ it = writer_component->input_iterator;
+ assert(it);
+ it_ret = bt_notification_iterator_next(it);
- notification = bt_notification_iterator_get_notification(it);
- if (!notification) {
+ switch (it_ret) {
+ case BT_NOTIFICATION_ITERATOR_STATUS_END:
+ ret = BT_COMPONENT_STATUS_END;
+ BT_PUT(writer_component->input_iterator);
+ goto end;
+ case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+ ret = BT_COMPONENT_STATUS_AGAIN;
+ goto end;
+ case BT_NOTIFICATION_ITERATOR_STATUS_OK:
+ break;
+ default:
ret = BT_COMPONENT_STATUS_ERROR;
goto end;
}
+ notification = bt_notification_iterator_get_notification(it);
+ assert(notification);
ret = handle_notification(writer_component, notification);
- writer_component->processed_first_event = true;
end:
bt_put(notification);
return ret;