diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-10-27 14:46:38 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-11-26 16:51:35 +0000 |
commit | b0fba14b1e122522a1db2581779ffb94ee7cfa37 (patch) | |
tree | f0ab362f9e124b7f01f8c7e1b97a84d0c40f3edc /cli/mmcli-modem-oma.c | |
parent | cafc40245d2007ad3a9a33875fc6b71d25e6a254 (diff) |
cli: allow multiple output format types
In addition to the standard human-friendly output, we now allow a
machine-friendly key-value pair output, much easier to parse and use
by programs that look at the mmcli output.
This new key-value pair output should be treated as API from now on, so
third-party programs can assume the output is compatible from one
release to another.
Diffstat (limited to 'cli/mmcli-modem-oma.c')
-rw-r--r-- | cli/mmcli-modem-oma.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/cli/mmcli-modem-oma.c b/cli/mmcli-modem-oma.c index 63e23aeb..0c615303 100644 --- a/cli/mmcli-modem-oma.c +++ b/cli/mmcli-modem-oma.c @@ -33,6 +33,7 @@ #include "mmcli.h" #include "mmcli-common.h" +#include "mmcli-output.h" /* Context */ typedef struct { @@ -160,32 +161,19 @@ mmcli_modem_oma_shutdown (void) static void print_oma_status (void) { - gchar *features_str; + gchar *features_str; const MMOmaPendingNetworkInitiatedSession *pending_sessions; - guint n_pending_sessions; - -#undef VALIDATE_UNKNOWN -#define VALIDATE_UNKNOWN(str) (str ? str : "unknown") + guint n_pending_sessions; + const gchar *current_session_type = NULL; + const gchar *current_session_state = NULL; + GPtrArray *aux = NULL; features_str = mm_oma_feature_build_string_from_mask (mm_modem_oma_get_features (ctx->modem_oma)); - /* Global IDs */ - g_print ("\n" - "%s\n", - VALIDATE_UNKNOWN (mm_modem_oma_get_path (ctx->modem_oma))); - - /* Overall setup */ - g_print (" -------------------------\n" - " Setup | features: '%s'\n", - VALIDATE_UNKNOWN (features_str)); - /* Current session */ if (mm_modem_oma_get_session_type (ctx->modem_oma) != MM_OMA_SESSION_TYPE_UNKNOWN) { - g_print (" -------------------------\n" - " Current session | type: '%s'\n" - " | state: '%s'\n", - VALIDATE_UNKNOWN (mm_oma_session_type_get_string (mm_modem_oma_get_session_type (ctx->modem_oma))), - VALIDATE_UNKNOWN (mm_oma_session_state_get_string (mm_modem_oma_get_session_state (ctx->modem_oma)))); + current_session_type = mm_oma_session_type_get_string (mm_modem_oma_get_session_type (ctx->modem_oma)); + current_session_state = mm_oma_session_state_get_string (mm_modem_oma_get_session_state (ctx->modem_oma)); } /* If 1 or more pending sessions... */ @@ -193,18 +181,24 @@ print_oma_status (void) n_pending_sessions > 0) { guint i; - g_print (" -------------------------\n" - " Pending sessions |\n"); + aux = g_ptr_array_new (); + for (i = 0; i < n_pending_sessions; i++) { - g_print (" [%u] | type: '%s'\n" - " | id: '%u'\n", - i, - VALIDATE_UNKNOWN (mm_oma_session_type_get_string (pending_sessions[i].session_type)), - pending_sessions[i].session_id); + gchar *info; + + info = g_strdup_printf ("id: %u, type: %s", + pending_sessions[i].session_id, + mm_oma_session_type_get_string (pending_sessions[i].session_type)); + g_ptr_array_add (aux, info); } + g_ptr_array_add (aux, NULL); } - g_free (features_str); + mmcli_output_string_take (MMC_F_OMA_FEATURES, features_str); + mmcli_output_string (MMC_F_OMA_CURRENT_TYPE, current_session_type); + mmcli_output_string (MMC_F_OMA_CURRENT_STATE, current_session_state); + mmcli_output_string_array_take (MMC_F_OMA_PENDING_SESSIONS, aux ? (gchar **) g_ptr_array_free (aux, FALSE) : NULL, TRUE); + mmcli_output_dump (); } static void |