X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Futils%2Ftrimmer%2Fiterator.c;h=d8d8b0c6c9166880baee82d03c737c18fad2556b;hb=3bfc4183e4026c21bad8c817125b1f6d31d6d89d;hp=f159e9f0a3c0b8c3ff14e48f8ca53c560c077f4f;hpb=907b1704ad8e46f9e969b7bd8d7f9a4efe940b60;p=babeltrace.git diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index f159e9f0..d8d8b0c6 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -26,6 +26,11 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT-ITER" +#include "logging.h" + +#include +#include #include #include #include @@ -37,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -51,17 +57,28 @@ #include "iterator.h" #include "copy.h" +static +gboolean close_packets(gpointer key, gpointer value, gpointer user_data) +{ + struct bt_ctf_packet *writer_packet = value; + + bt_put(writer_packet); + return TRUE; +} + BT_HIDDEN void trimmer_iterator_finalize(struct bt_private_notification_iterator *it) { - struct trimmer_iterator *it_data; + struct trimmer_iterator *trim_it; - it_data = bt_private_notification_iterator_get_user_data(it); - assert(it_data); + trim_it = bt_private_notification_iterator_get_user_data(it); + assert(trim_it); - bt_put(it_data->input_iterator); - g_hash_table_destroy(it_data->packet_map); - g_free(it_data); + bt_put(trim_it->input_iterator); + g_hash_table_foreach_remove(trim_it->packet_map, + close_packets, NULL); + g_hash_table_destroy(trim_it->packet_map); + g_free(trim_it); } BT_HIDDEN @@ -72,6 +89,7 @@ enum bt_notification_iterator_status trimmer_iterator_init( enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; enum bt_notification_iterator_status it_ret; + enum bt_connection_status conn_status; struct bt_private_port *input_port = NULL; struct bt_private_connection *connection = NULL; struct bt_private_component *component = @@ -97,11 +115,10 @@ enum bt_notification_iterator_status trimmer_iterator_init( connection = bt_private_port_get_private_connection(input_port); assert(connection); - it_data->input_iterator = - bt_private_connection_create_notification_iterator(connection, - notif_types); - if (!it_data->input_iterator) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + conn_status = bt_private_connection_create_notification_iterator(connection, + notif_types, &it_data->input_iterator); + if (conn_status != BT_CONNECTION_STATUS_OK) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; goto end; } @@ -139,23 +156,23 @@ int update_lazy_bound(struct trimmer_bound *bound, const char *name, if (bound->lazy_values.gmt) { /* Get day, month, year. */ - if (!gmtime_r(&timeval, &tm)) { - printf_error("Failure in gmtime_r()"); + if (!bt_gmtime_r(&timeval, &tm)) { + BT_LOGE_STR("Failure in bt_gmtime_r()."); goto error; } tm.tm_sec = bound->lazy_values.ss; tm.tm_min = bound->lazy_values.mm; tm.tm_hour = bound->lazy_values.hh; - timeval = timegm(&tm); + timeval = bt_timegm(&tm); if (timeval < 0) { - printf_error("Failure in timegm(), incorrectly formatted %s timestamp", + BT_LOGE("Failure in bt_timegm(), incorrectly formatted %s timestamp", name); goto error; } } else { /* Get day, month, year. */ - if (!localtime_r(&timeval, &tm)) { - printf_error("Failure in localtime_r()"); + if (!bt_localtime_r(&timeval, &tm)) { + BT_LOGE_STR("Failure in bt_localtime_r()."); goto error; } tm.tm_sec = bound->lazy_values.ss; @@ -163,7 +180,7 @@ int update_lazy_bound(struct trimmer_bound *bound, const char *name, tm.tm_hour = bound->lazy_values.hh; timeval = mktime(&tm); if (timeval < 0) { - printf_error("Failure in mktime(), incorrectly formatted %s timestamp", + BT_LOGE("Failure in mktime(), incorrectly formatted %s timestamp", name); goto error; } @@ -229,14 +246,14 @@ struct bt_notification *evaluate_event_notification( clock_value = bt_ctf_event_get_clock_value(event, clock_class); if (!clock_value) { - printf_error("Failed to retrieve clock value"); + BT_LOGE_STR("Failed to retrieve clock value."); goto error; } clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch( clock_value, &ts); if (clock_ret) { - printf_error("Failed to retrieve clock value timestamp"); + BT_LOGE_STR("Failed to retrieve clock value timestamp."); goto error; } if (update_lazy_bound(begin, "begin", ts, &lazy_update)) { @@ -247,7 +264,7 @@ struct bt_notification *evaluate_event_notification( } if (lazy_update && begin->set && end->set) { if (begin->value > end->value) { - printf_error("Unexpected: time range begin value is above end value"); + BT_LOGE_STR("Unexpected: time range begin value is above end value."); goto error; } } @@ -303,6 +320,7 @@ int ns_from_integer_field(struct bt_ctf_field *integer, int64_t *ns) } } else { /* Signed clock values are unsupported. */ + ret = -1; goto end; } @@ -450,7 +468,7 @@ struct bt_notification *evaluate_packet_notification( } if (lazy_update && begin->set && end->set) { if (begin->value > end->value) { - printf_error("Unexpected: time range begin value is above end value"); + BT_LOGE_STR("Unexpected: time range begin value is above end value."); goto end_no_notif; } } @@ -617,11 +635,3 @@ end: bt_put(component); return ret; } - -BT_HIDDEN -enum bt_notification_iterator_status trimmer_iterator_seek_time( - struct bt_private_notification_iterator *iterator, - int64_t time) -{ - return BT_NOTIFICATION_ITERATOR_STATUS_OK; -}