Plugins are alive!
[babeltrace.git] / converter / babeltrace.c
index fd025b6c8700f31e3a8d3a80a65cab73f55be814..e563c0a4fd6b18c98d101ba5ed1d989f02739a12 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,15 @@ 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;
 
        ret = parse_options(argc, argv);
        if (ret < 0) {
@@ -206,6 +212,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");
 
@@ -223,32 +243,78 @@ int main(int argc, char **argv)
                goto end;
        }
 
-       ret = bt_component_factory_load(component_factory, opt_plugin_path);
+       ret = bt_component_factory_load_recursive(component_factory, opt_plugin_path);
        if (ret) {
                fprintf(stderr, "Failed to load plugins.\n");
                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 output 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");
                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);
-       goto end;
+       it = bt_component_source_create_iterator(source);
+       if (!it) {
+               fprintf(stderr, "Failed to instantiate source iterator. Aborting...\n");
+               ret = -1;
+               goto end;
+       }
 
+       do {
+               enum bt_component_status sink_status;
+               struct bt_notification *notification =
+                               bt_notification_iterator_get_notification(it);
+
+               if (!notification) {
+                       /*
+                        * Should never happen in final code except after next
+                        * has returned BT_NOTIFICATION_ITERATOR_STATUS_END.
+                        *
+                        * Right now it happens at the first event since the
+                        * iterator is not completely initialized and we don't
+                        * have a notification "heap" in place.
+                        */
+                       continue;
+               }
+
+               sink_status = bt_component_sink_handle_notification(sink,
+                               notification);
+               BT_PUT(notification);
+               if (sink_status != BT_COMPONENT_STATUS_OK) {
+                       fprintf(stderr, "Sink component returned an error, aborting...\n");
+                       break;
+               }
+       } while (bt_notification_iterator_next(it) ==
+                       BT_NOTIFICATION_ITERATOR_STATUS_OK);
        /* teardown and exit */
 end:
        BT_PUT(component_factory);
@@ -258,5 +324,6 @@ end:
        BT_PUT(sink);
        BT_PUT(source_params);
        BT_PUT(sink_params);
+       BT_PUT(it);
        return ret ? 1 : 0;
 }
This page took 0.029323 seconds and 4 git commands to generate.