Cleanup: identical code for different branches
[babeltrace.git] / plugins / utils / trimmer / trimmer.c
index 1007886857d4e7a2624a5452e6ceabf865f5504d..352b0cffa3405d2cdab76985548c00e249cb9f33 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-UTILS-TRIMMER-FLT"
+#include "logging.h"
+
+#include <babeltrace/compat/utc-internal.h>
 #include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/private-component.h>
-#include <babeltrace/component/component-filter.h>
-#include <babeltrace/component/notification/notification.h>
-#include <babeltrace/component/notification/iterator.h>
-#include <babeltrace/component/notification/private-iterator.h>
-#include <babeltrace/component/notification/event.h>
+#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/private-component.h>
+#include <babeltrace/graph/component-filter.h>
+#include <babeltrace/graph/notification.h>
+#include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/private-notification-iterator.h>
+#include <babeltrace/graph/private-component-filter.h>
+#include <babeltrace/graph/notification-event.h>
 #include <plugins-common.h>
 #include "trimmer.h"
 #include "iterator.h"
@@ -48,17 +53,10 @@ void destroy_trimmer_data(struct trimmer *trimmer)
 static
 struct trimmer *create_trimmer_data(void)
 {
-       struct trimmer *trimmer;
-
-       trimmer = g_new0(struct trimmer, 1);
-       if (!trimmer) {
-               goto end;
-       }
-end:
-       return trimmer;
+       return g_new0(struct trimmer, 1);
 }
 
-void destroy_trimmer(struct bt_private_component *component)
+void finalize_trimmer(struct bt_private_component *component)
 {
        void *data = bt_private_component_get_user_data(component);
 
@@ -83,7 +81,7 @@ void destroy_trimmer(struct bt_private_component *component)
  */
 static
 int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
-               struct trimmer_bound *result_bound, bool gmt)
+               struct trimmer_bound *result_bound, bt_bool gmt)
 {
        int ret;
        int64_t value;
@@ -105,7 +103,7 @@ int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
                time_t result;
 
                if (gmt) {
-                       result = timegm(&tm);
+                       result = bt_timegm(&tm);
                        if (result < 0) {
                                return -1;
                        }
@@ -151,7 +149,7 @@ int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
                        time_t result;
 
                        if (gmt) {
-                               result = timegm(&tm);
+                               result = bt_timegm(&tm);
                                if (result < 0) {
                                        return -1;
                                }
@@ -199,7 +197,7 @@ int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
                };
 
                if (gmt) {
-                       value = timegm(&tm);
+                       value = bt_timegm(&tm);
                        if (value < 0) {
                                return -1;
                        }
@@ -243,7 +241,7 @@ int timestamp_from_arg(const char *arg, struct trimmer *trimmer,
                        time_t result;
 
                        if (gmt) {
-                               result = timegm(&tm);
+                               result = bt_timegm(&tm);
                                if (result < 0) {
                                        return -1;
                                }
@@ -291,7 +289,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                struct bt_value *params)
 {
        struct bt_value *value = NULL;
-       bool gmt = false;
+       bt_bool gmt = BT_FALSE;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
        assert(params);
@@ -303,7 +301,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                value_ret = bt_value_bool_get(value, &gmt);
                if (value_ret) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve clock-gmt value. Expecting a boolean");
+                       BT_LOGE_STR("Failed to retrieve clock-gmt value. Expecting a boolean");
                }
        }
        bt_put(value);
@@ -320,7 +318,7 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                if (value_ret || timestamp_from_arg(str,
                                trimmer, &trimmer->begin, gmt)) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve begin value. Expecting a timestamp string");
+                       BT_LOGE_STR("Failed to retrieve begin value. Expecting a timestamp string");
                }
        }
        bt_put(value);
@@ -337,14 +335,14 @@ enum bt_component_status init_from_params(struct trimmer *trimmer,
                if (value_ret || timestamp_from_arg(str,
                                trimmer, &trimmer->end, gmt)) {
                        ret = BT_COMPONENT_STATUS_INVALID;
-                       printf_error("Failed to retrieve end value. Expecting a timestamp string");
+                       BT_LOGE_STR("Failed to retrieve end value. Expecting a timestamp string");
                }
        }
        bt_put(value);
 end:
        if (trimmer->begin.set && trimmer->end.set) {
                if (trimmer->begin.value > trimmer->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");
                        ret = BT_COMPONENT_STATUS_INVALID;
                }
        }
@@ -363,6 +361,19 @@ enum bt_component_status trimmer_component_init(
                goto end;
        }
 
+       /* Create input and output ports */
+       ret = bt_private_component_filter_add_input_private_port(
+               component, "in", NULL, NULL);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       ret = bt_private_component_filter_add_output_private_port(
+               component, "out", NULL, NULL);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
        ret = bt_private_component_set_user_data(component, trimmer);
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto error;
@@ -373,5 +384,6 @@ end:
        return ret;
 error:
        destroy_trimmer_data(trimmer);
+       ret = BT_COMPONENT_STATUS_ERROR;
        return ret;
 }
This page took 0.026807 seconds and 4 git commands to generate.