Sinks own their input iterators
[babeltrace.git] / converter / babeltrace.c
index 035c4a250badf04c0fe683671dd16cb35afb3d07..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>
 
 
 static char *opt_plugin_path;
+static char *opt_input_path;
 
 enum {
        OPT_NONE = 0,
        OPT_PLUGIN_PATH,
+       OPT_INPUT_PATH,
        OPT_VERBOSE,
        OPT_DEBUG,
        OPT_HELP,
@@ -60,6 +63,7 @@ enum {
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        { "plugin-path", 0, POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+       { "input-path", 0, POPT_ARG_STRING, NULL, OPT_INPUT_PATH, NULL, NULL },
        { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
        { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL },
        { NULL, 0, 0, NULL, 0, NULL, NULL },
@@ -95,7 +99,7 @@ static int parse_options(int argc, char **argv)
                        if (!opt_plugin_path) {
                                ret = -EINVAL;
                                goto end;
-                       }                       ;
+                       }
                        break;
                case OPT_VERBOSE:
                        babeltrace_verbose = 1;
@@ -103,6 +107,13 @@ static int parse_options(int argc, char **argv)
                case OPT_DEBUG:
                        babeltrace_debug = 1;
                        break;
+               case OPT_INPUT_PATH:
+                       opt_input_path = (char *) poptGetOptArg(pc);
+                       if (!opt_input_path) {
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       break;
                default:
                        ret = -EINVAL;
                        goto end;
@@ -133,7 +144,7 @@ const char *component_type_str(enum bt_component_type type)
 }
 
 static
-void print_detected_component_classes(struct bt_component_factory *factory)
+void print_found_component_classes(struct bt_component_factory *factory)
 {
        int count, i;
 
@@ -183,20 +194,16 @@ void print_detected_component_classes(struct bt_component_factory *factory)
        }
 }
 
-static
-void test_sink_notifications(struct bt_component *sink)
-{
-       return;
-}
-
 int main(int argc, char **argv)
 {
        int ret;
+       enum bt_value_status value_status;
        struct bt_component_factory *component_factory = NULL;
-       struct bt_component_class *source_class = NULL;
-       struct bt_component_class *sink_class = NULL;
+       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) {
@@ -206,6 +213,20 @@ int main(int argc, char **argv)
                exit(EXIT_SUCCESS);
        }
 
+       source_params = bt_value_map_create();
+       if (!source_params) {
+               fprintf(stderr, "Failed to create source parameters map, aborting...\n");
+               ret = -1;
+               goto end;
+       }
+
+       value_status = bt_value_map_insert_string(source_params, "path",
+                       opt_input_path);
+       if (value_status != BT_VALUE_STATUS_OK) {
+               ret = -1;
+               goto end;
+       }
+
        printf_verbose("Verbose mode active.\n");
        printf_debug("Debug mode active.\n");
 
@@ -229,25 +250,70 @@ int main(int argc, char **argv)
                goto end;
        }
 
-       print_detected_component_classes(component_factory);
+       print_found_component_classes(component_factory);
+
+       source_class = bt_component_factory_get_component_class(
+                       component_factory, "ctf", BT_COMPONENT_TYPE_SOURCE,
+                       "fs");
+       if (!source_class) {
+               fprintf(stderr, "Could not find ctf-fs source component class. Aborting...\n");
+               ret = -1;
+               goto end;
+       }
 
        sink_class = bt_component_factory_get_component_class(component_factory,
-                       NULL, BT_COMPONENT_TYPE_SINK, "text");
+                       "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;
+       }
+
+       source = bt_component_create(source_class, "ctf-fs", source_params);
+       if (!source) {
+               fprintf(stderr, "Failed to instantiate source component. Aborting...\n");
                ret = -1;
                goto end;
        }
 
        sink = bt_component_create(sink_class, "bt_text_output", sink_params);
        if (!sink) {
-               fprintf(stderr, "Failed to instanciate text output. Aborting...\n");
+               fprintf(stderr, "Failed to instantiate output component. Aborting...\n");
                ret = -1;
                goto end;
        }
 
-       test_sink_notifications(sink);
+       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);
@@ -257,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.033104 seconds and 4 git commands to generate.