Fix libadd referring to text plugin
[babeltrace.git] / converter / babeltrace.c
index cd7bd7c48b3cd0746ce03cbb9b36435c55580cf5..e3436afa28a4272e180db25069363dd50c80e8b5 100644 (file)
@@ -30,6 +30,7 @@
 #include <babeltrace/plugin/component-factory.h>
 #include <babeltrace/plugin/plugin.h>
 #include <babeltrace/plugin/component-class.h>
+#include <babeltrace/plugin/notification/iterator.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/values.h>
 #include <stdlib.h>
@@ -201,6 +202,8 @@ int main(int argc, char **argv)
        struct bt_component_class *source_class = NULL, *sink_class = NULL;
        struct bt_component *source = NULL, *sink = NULL;
        struct bt_value *source_params = NULL, *sink_params = NULL;
+       struct bt_notification_iterator *it = NULL;
+       enum bt_component_status sink_status;
 
        ret = parse_options(argc, argv);
        if (ret < 0) {
@@ -253,7 +256,7 @@ int main(int argc, char **argv)
                        component_factory, "ctf", BT_COMPONENT_TYPE_SOURCE,
                        "fs");
        if (!source_class) {
-               fprintf(stderr, "Could not find ctf-fs output component class. Aborting...\n");
+               fprintf(stderr, "Could not find ctf-fs source component class. Aborting...\n");
                ret = -1;
                goto end;
        }
@@ -261,7 +264,7 @@ int main(int argc, char **argv)
        sink_class = bt_component_factory_get_component_class(component_factory,
                        "text", BT_COMPONENT_TYPE_SINK, "text");
        if (!sink_class) {
-               fprintf(stderr, "Could not find text output component class. Aborting...\n");
+               fprintf(stderr, "Could not find text sink component class. Aborting...\n");
                ret = -1;
                goto end;
        }
@@ -280,6 +283,37 @@ int main(int argc, char **argv)
                goto end;
        }
 
+       it = bt_component_source_create_iterator(source);
+       if (!it) {
+               fprintf(stderr, "Failed to instantiate source iterator. Aborting...\n");
+               ret = -1;
+               goto end;
+       }
+
+       sink_status = bt_component_sink_add_iterator(sink, it);
+       if (sink_status != BT_COMPONENT_STATUS_OK) {
+               ret = -1;
+               goto end;
+       }
+
+       while (true) {
+               sink_status = bt_component_sink_consume(sink);
+
+               switch (sink_status) {
+               case BT_COMPONENT_STATUS_AGAIN:
+                       /* Wait for an arbitraty 500 ms. */
+                       usleep(500000);
+                       break;
+               case BT_COMPONENT_STATUS_OK:
+                       break;
+               case BT_COMPONENT_STATUS_END:
+                       goto end;
+               default:
+                       fprintf(stderr, "Sink component returned an error, aborting...\n");
+                       ret = -1;
+                       goto end;
+               }
+       }
        /* teardown and exit */
 end:
        BT_PUT(component_factory);
@@ -289,5 +323,6 @@ end:
        BT_PUT(sink);
        BT_PUT(source_params);
        BT_PUT(sink_params);
+       BT_PUT(it);
        return ret ? 1 : 0;
 }
This page took 0.025046 seconds and 4 git commands to generate.