Make bt_private_component_*_add_*_port() return a status code
[babeltrace.git] / plugins / utils / trimmer / trimmer.c
index af838d723e8adfbed3b938e6e4662f5e3d57ef8c..2a8bd5e0b83c5fb4ae8d21977134a4cd432c536e 100644 (file)
  * SOFTWARE.
  */
 
+#include <babeltrace/compat/utc-internal.h>
 #include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/component-filter.h>
-#include <babeltrace/component/notification/notification.h>
-#include <babeltrace/component/notification/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"
@@ -56,9 +60,9 @@ end:
        return trimmer;
 }
 
-void destroy_trimmer(struct bt_component *component)
+void finalize_trimmer(struct bt_private_component *component)
 {
-       void *data = bt_component_get_private_data(component);
+       void *data = bt_private_component_get_user_data(component);
 
        destroy_trimmer_data(data);
 }
@@ -81,7 +85,7 @@ void destroy_trimmer(struct bt_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;
@@ -103,7 +107,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;
                        }
@@ -149,7 +153,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;
                                }
@@ -197,7 +201,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;
                        }
@@ -241,7 +245,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;
                                }
@@ -285,10 +289,11 @@ lazy:
 }
 
 static
-enum bt_component_status init_from_params(struct trimmer *trimmer, struct bt_value *params)
+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);
@@ -349,7 +354,7 @@ end:
 }
 
 enum bt_component_status trimmer_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;
@@ -360,7 +365,20 @@ enum bt_component_status trimmer_component_init(
                goto end;
        }
 
-       ret = bt_component_set_private_data(component, trimmer);
+       /* 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;
        }
@@ -370,5 +388,6 @@ end:
        return ret;
 error:
        destroy_trimmer_data(trimmer);
+       ret = BT_COMPONENT_STATUS_ERROR;
        return ret;
 }
This page took 0.02542 seconds and 4 git commands to generate.