Refactoring: introduce lttng_tracker_ids data structure
[lttng-tools.git] / src / bin / lttng / commands / list.c
index fb891beb727a529c1724c034f502a82e6dd89955..229648e07cebe7018d2dfa80fc67151fff97a15c 100644 (file)
@@ -26,6 +26,7 @@
 #include <common/mi-lttng.h>
 #include <common/time.h>
 #include <lttng/constant.h>
+#include <lttng/tracker.h>
 
 #include "../command.h"
 
@@ -1538,16 +1539,23 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type)
 {
        int ret = 0;
        int enabled = 1;
-       struct lttng_tracker_id *ids = NULL;
+       struct lttng_tracker_ids *ids = NULL;
        size_t nr_ids, i;
+       const struct lttng_tracker_id *id;
 
-       ret = lttng_list_tracker_ids(handle, tracker_type, &ids, &nr_ids);
+       ret = lttng_list_tracker_ids(handle, tracker_type, &ids);
        if (ret) {
                return ret;
        }
-       if (nr_ids == 1 && ids[0].type == LTTNG_ID_ALL) {
-               enabled = 0;
+
+       nr_ids = lttng_tracker_ids_get_count(ids);
+       if (nr_ids == 1) {
+               id = lttng_tracker_ids_get_at_index(ids, 0);
+               if (id && lttng_tracker_id_get_type(id) == LTTNG_ID_ALL) {
+                       enabled = 0;
+               }
        }
+
        if (enabled) {
                _MSG("%s tracker: [", get_tracker_str(tracker_type));
 
@@ -1561,23 +1569,55 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type)
                }
 
                for (i = 0; i < nr_ids; i++) {
-                       struct lttng_tracker_id *id = &ids[i];
+                       enum lttng_tracker_id_status status =
+                                       LTTNG_TRACKER_ID_STATUS_OK;
+                       int value;
+                       const char *value_string;
+
+                       id = lttng_tracker_ids_get_at_index(ids, i);
+                       if (!id) {
+                               ret = CMD_ERROR;
+                               goto end;
+                       }
+
+                       switch (lttng_tracker_id_get_type(id)) {
+                       case LTTNG_ID_ALL:
+                               break;
+                       case LTTNG_ID_VALUE:
+                               status = lttng_tracker_id_get_value(id, &value);
+                               break;
+                       case LTTNG_ID_STRING:
+                               status = lttng_tracker_id_get_string(
+                                               id, &value_string);
+                               break;
+                       case LTTNG_ID_UNKNOWN:
+                               ret = CMD_ERROR;
+                               goto end;
+                       }
+
+                       if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+                               ERR("Invalid state for tracker id");
+                               ret = CMD_ERROR;
+                               goto end;
+                       }
 
                        if (i) {
                                _MSG(",");
                        }
-                       switch (id->type) {
+                       switch (lttng_tracker_id_get_type(id)) {
                        case LTTNG_ID_ALL:
                                _MSG(" *");
                                break;
                        case LTTNG_ID_VALUE:
-                               _MSG(" %d", ids[i].value);
+                               _MSG(" %d", value);
                                break;
                        case LTTNG_ID_STRING:
-                               _MSG(" %s", ids[i].string);
+                               _MSG(" %s", value_string);
                                break;
                        case LTTNG_ID_UNKNOWN:
-                               return CMD_ERROR;
+                               ERR("Invalid state for tracker id");
+                               ret = CMD_ERROR;
+                               goto end;
                        }
 
                        /* Mi */
@@ -1600,10 +1640,7 @@ static int list_tracker_ids(enum lttng_tracker_type tracker_type)
                }
        }
 end:
-       for (i = 0; i < nr_ids; i++) {
-               free(ids[i].string);
-       }
-       free(ids);
+       lttng_tracker_ids_destroy(ids);
        return ret;
 }
 
@@ -1612,7 +1649,7 @@ end:
  */
 static int list_trackers(const struct lttng_domain *domain)
 {
-       int ret;
+       int ret = 0;
 
        /* Trackers listing */
        if (lttng_opt_mi) {
This page took 0.024846 seconds and 4 git commands to generate.