Common Trace Format 2 generation
[deliverable/lttng-tools.git] / src / bin / lttng / commands / list_triggers.cpp
index 9a57714b6f9cfa1ba9a5a073da37732278e82489..723fc2da02a331ca16ed00fe4684efcbb369c438 100644 (file)
@@ -7,20 +7,21 @@
 
 #include <stdio.h>
 
-#include "../command.h"
+#include "../command.hpp"
 
 #include "common/argpar/argpar.h"
-#include "common/dynamic-array.h"
-#include "common/mi-lttng.h"
+#include "common/argpar-utils/argpar-utils.hpp"
+#include "common/dynamic-array.hpp"
+#include "common/mi-lttng.hpp"
 /* For lttng_condition_type_str(). */
-#include "lttng/condition/condition-internal.h"
+#include "lttng/condition/condition-internal.hpp"
 #include "lttng/condition/event-rule-matches.h"
-#include "lttng/condition/event-rule-matches-internal.h"
+#include "lttng/condition/event-rule-matches-internal.hpp"
 /* For lttng_domain_type_str(). */
-#include "lttng/domain-internal.h"
+#include "lttng/domain-internal.hpp"
 /* For lttng_event_rule_kernel_syscall_emission_site_str() */
-#include "lttng/event-rule/kernel-syscall-internal.h"
-#include "../loglevel.h"
+#include "lttng/event-rule/kernel-syscall-internal.hpp"
+#include "../loglevel.hpp"
 #include <lttng/lttng.h>
 
 #ifdef LTTNG_EMBED_HELP
@@ -1317,27 +1318,39 @@ static enum lttng_error_code mi_error_query_condition_callback(
 int cmd_list_triggers(int argc, const char **argv)
 {
        int ret;
-       struct argpar_parse_ret argpar_parse_ret = {};
+       struct argpar_iter *argpar_iter = NULL;
+       const struct argpar_item *argpar_item = NULL;
        struct lttng_triggers *triggers = NULL;
-       int i;
        struct mi_writer *mi_writer = NULL;
 
-       argpar_parse_ret = argpar_parse(
-                       argc - 1, argv + 1, list_trigger_options, true);
-       if (!argpar_parse_ret.items) {
-               ERR("%s", argpar_parse_ret.error);
+       argc--;
+       argv++;
+
+       argpar_iter = argpar_iter_create(argc, argv, list_trigger_options);
+       if (!argpar_iter) {
+               ERR("Failed to allocate an argpar iter.");
                goto error;
        }
 
-       for (i = 0; i < argpar_parse_ret.items->n_items; i++) {
-               const struct argpar_item *item =
-                               argpar_parse_ret.items->items[i];
+       while (true) {
+               enum parse_next_item_status status;
+
+               status = parse_next_item(argpar_iter, &argpar_item, 1, argv,
+                       true, NULL, NULL);
+               if (status == PARSE_NEXT_ITEM_STATUS_ERROR ||
+                               status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) {
+                       goto error;
+               } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
+                       break;
+               }
+
+               assert(status == PARSE_NEXT_ITEM_STATUS_OK);
 
-               if (item->type == ARGPAR_ITEM_TYPE_OPT) {
-                       const struct argpar_item_opt *item_opt =
-                                       (const struct argpar_item_opt *) item;
+               if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+                       const struct argpar_opt_descr *descr =
+                               argpar_item_opt_descr(argpar_item);
 
-                       switch (item_opt->descr->id) {
+                       switch (descr->id) {
                        case OPT_HELP:
                                SHOW_HELP();
                                ret = 0;
@@ -1354,10 +1367,8 @@ int cmd_list_triggers(int argc, const char **argv)
                        }
 
                } else {
-                       const struct argpar_item_non_opt *item_non_opt =
-                               (const struct argpar_item_non_opt *) item;
-
-                       ERR("Unexpected argument: %s", item_non_opt->arg);
+                       ERR("Unexpected argument: %s",
+                               argpar_item_non_opt_arg(argpar_item));
                }
        }
 
@@ -1438,7 +1449,8 @@ error:
        ret = 1;
 
 end:
-       argpar_parse_ret_fini(&argpar_parse_ret);
+       argpar_item_destroy(argpar_item);
+       argpar_iter_destroy(argpar_iter);
        lttng_triggers_destroy(triggers);
        /* Mi clean-up. */
        if (mi_writer && mi_lttng_writer_destroy(mi_writer)) {
This page took 0.02796 seconds and 5 git commands to generate.