Append "library" to pkg-config packages names
[babeltrace.git] / src / plugins / utils / trimmer / trimmer.c
index 1275750d7a40dd78b50d4574a0d87e412fe48d4e..87cdb3e104f220e120fae0189ca9af47766a7c87 100644 (file)
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT"
-#include "logging.h"
+#define BT_COMP_LOG_SELF_COMP (trimmer_comp->self_comp)
+#define BT_LOG_OUTPUT_LEVEL (trimmer_comp->log_level)
+#define BT_LOG_TAG "PLUGIN/FLT.UTILS.TRIMMER"
+#include "plugins/comp-logging.h"
 
 #include "compat/utc.h"
 #include "compat/time.h"
@@ -70,6 +72,8 @@ struct trimmer_bound {
 struct trimmer_comp {
        struct trimmer_bound begin, end;
        bool is_gmt;
+       bt_logging_level log_level;
+       bt_self_component *self_comp;
 };
 
 enum trimmer_iterator_state {
@@ -238,8 +242,8 @@ end:
  * TODO: Check overflows.
  */
 static
-int set_bound_from_str(const char *str, struct trimmer_bound *bound,
-               bool is_gmt)
+int set_bound_from_str(struct trimmer_comp *trimmer_comp,
+               const char *str, struct trimmer_bound *bound, bool is_gmt)
 {
        int ret = 0;
        int s_ret;
@@ -336,7 +340,7 @@ int set_bound_from_str(const char *str, struct trimmer_bound *bound,
                goto end;
        }
 
-       BT_LOGE("Invalid date/time format: param=\"%s\"", str);
+       BT_COMP_LOGE("Invalid date/time format: param=\"%s\"", str);
        ret = -1;
 
 end:
@@ -350,7 +354,8 @@ end:
  * Returns a negative value if anything goes wrong.
  */
 static
-int set_bound_from_param(const char *param_name, const bt_value *param,
+int set_bound_from_param(struct trimmer_comp *trimmer_comp,
+               const char *param_name, const bt_value *param,
                struct trimmer_bound *bound, bool is_gmt)
 {
        int ret;
@@ -369,21 +374,21 @@ int set_bound_from_param(const char *param_name, const bt_value *param,
        } else if (bt_value_is_string(param)) {
                arg = bt_value_string_get(param);
        } else {
-               BT_LOGE("`%s` parameter must be an integer or a string value.",
+               BT_COMP_LOGE("`%s` parameter must be an integer or a string value.",
                        param_name);
                ret = -1;
                goto end;
        }
 
-       ret = set_bound_from_str(arg, bound, is_gmt);
+       ret = set_bound_from_str(trimmer_comp, arg, bound, is_gmt);
 
 end:
        return ret;
 }
 
 static
-int validate_trimmer_bounds(struct trimmer_bound *begin,
-               struct trimmer_bound *end)
+int validate_trimmer_bounds(struct trimmer_comp *trimmer_comp,
+               struct trimmer_bound *begin, struct trimmer_bound *end)
 {
        int ret = 0;
 
@@ -392,7 +397,7 @@ int validate_trimmer_bounds(struct trimmer_bound *begin,
 
        if (!begin->is_infinite && !end->is_infinite &&
                        begin->ns_from_origin > end->ns_from_origin) {
-               BT_LOGE("Trimming time range's beginning time is greater than end time: "
+               BT_COMP_LOGE("Trimming time range's beginning time is greater than end time: "
                        "begin-ns-from-origin=%" PRId64 ", "
                        "end-ns-from-origin=%" PRId64,
                        begin->ns_from_origin,
@@ -402,7 +407,7 @@ int validate_trimmer_bounds(struct trimmer_bound *begin,
        }
 
        if (!begin->is_infinite && begin->ns_from_origin == INT64_MIN) {
-               BT_LOGE("Invalid trimming time range's beginning time: "
+               BT_COMP_LOGE("Invalid trimming time range's beginning time: "
                        "ns-from-origin=%" PRId64,
                        begin->ns_from_origin);
                ret = -1;
@@ -410,7 +415,7 @@ int validate_trimmer_bounds(struct trimmer_bound *begin,
        }
 
        if (!end->is_infinite && end->ns_from_origin == INT64_MIN) {
-               BT_LOGE("Invalid trimming time range's end time: "
+               BT_COMP_LOGE("Invalid trimming time range's end time: "
                        "ns-from-origin=%" PRId64,
                        end->ns_from_origin);
                ret = -1;
@@ -436,7 +441,7 @@ int init_trimmer_comp_from_params(struct trimmer_comp *trimmer_comp,
 
         value = bt_value_map_borrow_entry_value_const(params, "begin");
        if (value) {
-               if (set_bound_from_param("begin", value,
+               if (set_bound_from_param(trimmer_comp, "begin", value,
                                &trimmer_comp->begin, trimmer_comp->is_gmt)) {
                        /* set_bound_from_param() logs errors */
                        ret = BT_SELF_COMPONENT_STATUS_ERROR;
@@ -449,7 +454,7 @@ int init_trimmer_comp_from_params(struct trimmer_comp *trimmer_comp,
 
         value = bt_value_map_borrow_entry_value_const(params, "end");
        if (value) {
-               if (set_bound_from_param("end", value,
+               if (set_bound_from_param(trimmer_comp, "end", value,
                                &trimmer_comp->end, trimmer_comp->is_gmt)) {
                        /* set_bound_from_param() logs errors */
                        ret = BT_SELF_COMPONENT_STATUS_ERROR;
@@ -463,33 +468,37 @@ int init_trimmer_comp_from_params(struct trimmer_comp *trimmer_comp,
 end:
        if (trimmer_comp->begin.is_set && trimmer_comp->end.is_set) {
                /* validate_trimmer_bounds() logs errors */
-               ret = validate_trimmer_bounds(&trimmer_comp->begin,
-                       &trimmer_comp->end);
+               ret = validate_trimmer_bounds(trimmer_comp,
+                       &trimmer_comp->begin, &trimmer_comp->end);
        }
 
        return ret;
 }
 
-bt_self_component_status trimmer_init(bt_self_component_filter *self_comp,
+bt_self_component_status trimmer_init(bt_self_component_filter *self_comp_flt,
                const bt_value *params, void *init_data)
 {
        int ret;
        bt_self_component_status status;
        struct trimmer_comp *trimmer_comp = create_trimmer_comp();
-
+       bt_self_component *self_comp =
+               bt_self_component_filter_as_self_component(self_comp_flt);
        if (!trimmer_comp) {
                status = BT_SELF_COMPONENT_STATUS_NOMEM;
                goto error;
        }
 
+       trimmer_comp->log_level = bt_component_get_logging_level(
+               bt_self_component_as_component(self_comp));
+       trimmer_comp->self_comp = self_comp;
        status = bt_self_component_filter_add_input_port(
-               self_comp, in_port_name, NULL, NULL);
+               self_comp_flt, in_port_name, NULL, NULL);
        if (status != BT_SELF_COMPONENT_STATUS_OK) {
                goto error;
        }
 
        status = bt_self_component_filter_add_output_port(
-               self_comp, "out", NULL, NULL);
+               self_comp_flt, "out", NULL, NULL);
        if (status != BT_SELF_COMPONENT_STATUS_OK) {
                goto error;
        }
@@ -500,9 +509,7 @@ bt_self_component_status trimmer_init(bt_self_component_filter *self_comp,
                goto error;
        }
 
-       bt_self_component_set_data(
-               bt_self_component_filter_as_self_component(self_comp),
-               trimmer_comp);
+       bt_self_component_set_data(self_comp, trimmer_comp);
        goto end;
 
 error:
@@ -760,9 +767,11 @@ void put_messages(bt_message_array_const msgs, uint64_t count)
 }
 
 static inline
-int set_trimmer_iterator_bound(struct trimmer_bound *bound,
-               int64_t ns_from_origin, bool is_gmt)
+int set_trimmer_iterator_bound(struct trimmer_iterator *trimmer_it,
+               struct trimmer_bound *bound, int64_t ns_from_origin,
+               bool is_gmt)
 {
+       struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
        struct tm tm;
        time_t time_seconds = (time_t) (ns_from_origin / NS_PER_S);
        int ret = 0;
@@ -778,7 +787,7 @@ int set_trimmer_iterator_bound(struct trimmer_bound *bound,
        }
 
        if (errno) {
-               BT_LOGE_ERRNO("Cannot convert timestamp to date and time",
+               BT_COMP_LOGE_ERRNO("Cannot convert timestamp to date and time",
                        "ts=%" PRId64, (int64_t) time_seconds);
                ret = -1;
                goto end;
@@ -843,7 +852,7 @@ bt_self_message_iterator_status state_set_trimmer_iterator_bounds(
 found:
        if (!trimmer_it->begin.is_set) {
                BT_ASSERT(!trimmer_it->begin.is_infinite);
-               ret = set_trimmer_iterator_bound(&trimmer_it->begin,
+               ret = set_trimmer_iterator_bound(trimmer_it, &trimmer_it->begin,
                        ns_from_origin, trimmer_comp->is_gmt);
                if (ret) {
                        goto error;
@@ -852,15 +861,15 @@ found:
 
        if (!trimmer_it->end.is_set) {
                BT_ASSERT(!trimmer_it->end.is_infinite);
-               ret = set_trimmer_iterator_bound(&trimmer_it->end,
+               ret = set_trimmer_iterator_bound(trimmer_it, &trimmer_it->end,
                        ns_from_origin, trimmer_comp->is_gmt);
                if (ret) {
                        goto error;
                }
        }
 
-       ret = validate_trimmer_bounds(&trimmer_it->begin,
-               &trimmer_it->end);
+       ret = validate_trimmer_bounds(trimmer_it->trimmer_comp,
+               &trimmer_it->begin, &trimmer_it->end);
        if (ret) {
                goto error;
        }
@@ -879,6 +888,7 @@ static
 bt_self_message_iterator_status state_seek_initially(
                struct trimmer_iterator *trimmer_it)
 {
+       struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
        bt_self_message_iterator_status status =
                BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
 
@@ -887,7 +897,7 @@ bt_self_message_iterator_status state_seek_initially(
        if (trimmer_it->begin.is_infinite) {
                if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
                                trimmer_it->upstream_iter)) {
-                       BT_LOGE_STR("Cannot make upstream message iterator initially seek its beginning.");
+                       BT_COMP_LOGE_STR("Cannot make upstream message iterator initially seek its beginning.");
                        status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
                        goto end;
                }
@@ -898,7 +908,7 @@ bt_self_message_iterator_status state_seek_initially(
                if (!bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
                                trimmer_it->upstream_iter,
                                trimmer_it->begin.ns_from_origin)) {
-                       BT_LOGE("Cannot make upstream message iterator initially seek: "
+                       BT_COMP_LOGE("Cannot make upstream message iterator initially seek: "
                                "seek-ns-from-origin=%" PRId64,
                                trimmer_it->begin.ns_from_origin);
                        status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
@@ -1664,6 +1674,7 @@ bt_self_message_iterator_status handle_message(
        bool skip;
        int ret;
        struct trimmer_iterator_stream_state *sstate = NULL;
+       struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
 
        /* Find message's associated stream */
        switch (bt_message_get_type(msg)) {
@@ -1721,7 +1732,7 @@ bt_self_message_iterator_status handle_message(
                         */
                        sc = bt_stream_borrow_class_const(stream);
                        if (!bt_stream_class_borrow_default_clock_class_const(sc)) {
-                               BT_LOGE("Unsupported stream: stream class does "
+                               BT_COMP_LOGE("Unsupported stream: stream class does "
                                        "not have a default clock class: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
@@ -1741,7 +1752,7 @@ bt_self_message_iterator_status handle_message(
                         */
                        if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(
                                        sc)) {
-                               BT_LOGE("Unsupported stream: packets have "
+                               BT_COMP_LOGE("Unsupported stream: packets have "
                                        "no beginning clock snapshot: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
@@ -1754,7 +1765,7 @@ bt_self_message_iterator_status handle_message(
 
                        if (!bt_stream_class_packets_have_end_default_clock_snapshot(
                                        sc)) {
-                               BT_LOGE("Unsupported stream: packets have "
+                               BT_COMP_LOGE("Unsupported stream: packets have "
                                        "no end clock snapshot: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
@@ -1767,7 +1778,7 @@ bt_self_message_iterator_status handle_message(
 
                        if (bt_stream_class_supports_discarded_events(sc) &&
                                        !bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
-                               BT_LOGE("Unsupported stream: discarded events "
+                               BT_COMP_LOGE("Unsupported stream: discarded events "
                                        "have no clock snapshots: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
@@ -1780,7 +1791,7 @@ bt_self_message_iterator_status handle_message(
 
                        if (bt_stream_class_supports_discarded_packets(sc) &&
                                        !bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
-                               BT_LOGE("Unsupported stream: discarded packets "
+                               BT_COMP_LOGE("Unsupported stream: discarded packets "
                                        "have no clock snapshots: "
                                        "stream-addr=%p, "
                                        "stream-id=%" PRIu64 ", "
This page took 0.028251 seconds and 4 git commands to generate.