+ const bt_component_class *comp_cls = NULL;
+ const bt_value *results = NULL;
+ bt_value *params = NULL;
+ const bt_value *map = NULL;
+ const bt_value *v = NULL;
+ static const char * const plugin_name = "ctf";
+ static const char * const comp_cls_name = "lttng-live";
+ static const bt_component_class_type comp_cls_type =
+ BT_COMPONENT_CLASS_TYPE_SOURCE;
+ int64_t array_size, i;
+ const char *fail_reason = NULL;
+ FILE *out_stream = stdout;
+
+ BT_ASSERT(cfg->cmd_data.print_lttng_live_sessions.url);
+ comp_cls = find_component_class(plugin_name, comp_cls_name,
+ comp_cls_type);
+ if (!comp_cls) {
+ BT_LOGE("Cannot find component class: plugin-name=\"%s\", "
+ "comp-cls-name=\"%s\", comp-cls-type=%d",
+ plugin_name, comp_cls_name,
+ BT_COMPONENT_CLASS_TYPE_SOURCE);
+ fprintf(stderr, "%s%sCannot find component class %s",
+ bt_common_color_bold(),
+ bt_common_color_fg_red(),
+ bt_common_color_reset());
+ print_plugin_comp_cls_opt(stderr, plugin_name,
+ comp_cls_name, comp_cls_type);
+ fprintf(stderr, "\n");
+ goto error;
+ }
+
+ params = bt_value_map_create();
+ if (!params) {
+ goto error;
+ }
+
+ ret = bt_value_map_insert_string_entry(params, "url",
+ cfg->cmd_data.print_lttng_live_sessions.url->str);
+ if (ret) {
+ goto error;
+ }
+
+ ret = query(comp_cls, "sessions", params,
+ &results, &fail_reason);
+ if (ret) {
+ goto failed;
+ }
+
+ BT_ASSERT(results);
+
+ if (!bt_value_is_array(results)) {
+ BT_LOGE_STR("Expecting an array for sessions query.");
+ fprintf(stderr, "%s%sUnexpected type returned by session query%s\n",
+ bt_common_color_bold(),
+ bt_common_color_fg_red(),
+ bt_common_color_reset());
+ goto error;
+ }
+
+ if (cfg->cmd_data.print_lttng_live_sessions.output_path->len > 0) {
+ out_stream =
+ fopen(cfg->cmd_data.print_lttng_live_sessions.output_path->str,
+ "w");
+ if (!out_stream) {
+ ret = -1;
+ BT_LOGE_ERRNO("Cannot open file for writing",
+ ": path=\"%s\"",
+ cfg->cmd_data.print_lttng_live_sessions.output_path->str);
+ goto end;
+ }
+ }
+
+ array_size = bt_value_array_get_size(results);
+ for (i = 0; i < array_size; i++) {
+ const char *url_text;
+ int64_t timer_us, streams, clients;
+
+ map = bt_value_array_borrow_element_by_index_const(results, i);
+ if (!map) {
+ BT_LOGE_STR("Unexpected empty array entry.");
+ goto error;
+ }
+ if (!bt_value_is_map(map)) {
+ BT_LOGE_STR("Unexpected entry type.");
+ goto error;
+ }
+
+ v = bt_value_map_borrow_entry_value_const(map, "url");
+ if (!v) {
+ BT_LOGE_STR("Unexpected empty array \"url\" entry.");
+ goto error;
+ }
+ url_text = bt_value_string_get(v);
+ fprintf(out_stream, "%s", url_text);
+ v = bt_value_map_borrow_entry_value_const(map, "timer-us");
+ if (!v) {
+ BT_LOGE_STR("Unexpected empty array \"timer-us\" entry.");
+ goto error;
+ }
+ timer_us = bt_value_signed_integer_get(v);
+ fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
+ v = bt_value_map_borrow_entry_value_const(map, "stream-count");
+ if (!v) {
+ BT_LOGE_STR("Unexpected empty array \"stream-count\" entry.");
+ goto error;
+ }
+ streams = bt_value_signed_integer_get(v);
+ fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
+ v = bt_value_map_borrow_entry_value_const(map, "client-count");
+ if (!v) {
+ BT_LOGE_STR("Unexpected empty array \"client-count\" entry.");
+ goto error;
+ }
+ clients = bt_value_signed_integer_get(v);
+ fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
+ }
+
+ goto end;
+
+failed:
+ BT_LOGE("Failed to query for sessions: %s", fail_reason);
+ fprintf(stderr, "%s%sFailed to request sessions: %s%s\n",
+ bt_common_color_bold(),
+ bt_common_color_fg_red(),
+ fail_reason,
+ bt_common_color_reset());
+
+error:
+ ret = -1;
+
+end:
+ bt_value_put_ref(results);
+ bt_value_put_ref(params);
+ bt_component_class_put_ref(comp_cls);
+
+ if (out_stream && out_stream != stdout) {
+ int fclose_ret = fclose(out_stream);
+
+ if (fclose_ret) {
+ BT_LOGE_ERRNO("Cannot close file stream",
+ ": path=\"%s\"",
+ cfg->cmd_data.print_lttng_live_sessions.output_path->str);
+ }
+ }
+
+ return ret;
+}
+
+static
+int cmd_print_ctf_metadata(struct bt_config *cfg)
+{
+ int ret = 0;
+ const bt_component_class *comp_cls = NULL;
+ const bt_value *results = NULL;
+ bt_value *params = NULL;
+ const bt_value *metadata_text_value = NULL;