cli: enable printing modem info

This commit is contained in:
Aleksander Morgado
2011-12-09 19:10:08 +01:00
parent 4624846015
commit 82693cf523
3 changed files with 139 additions and 170 deletions

View File

@@ -265,3 +265,16 @@ mmcli_get_state_reason_string (MMModemStateChangeReason reason)
g_warn_if_reached (); g_warn_if_reached ();
return NULL; return NULL;
} }
const gchar *
mmcli_get_lock_string (MMModemLock lock)
{
static GEnumClass *enum_class = NULL;
GEnumValue *value;
if (!enum_class)
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_LOCK));
value = g_enum_get_value (enum_class, lock);
return value->value_nick;
}

View File

@@ -38,5 +38,6 @@ MMObject *mmcli_get_modem_sync (GDBusConnection *connection,
const gchar *mmcli_get_state_string (MMModemState state); const gchar *mmcli_get_state_string (MMModemState state);
const gchar *mmcli_get_state_reason_string (MMModemStateChangeReason reason); const gchar *mmcli_get_state_reason_string (MMModemStateChangeReason reason);
const gchar *mmcli_get_lock_string (MMModemLock lock);
#endif /* _MMCLI_COMMON_H_ */ #endif /* _MMCLI_COMMON_H_ */

View File

@@ -145,172 +145,141 @@ mmcli_modem_shutdown (void)
context_free (ctx); context_free (ctx);
} }
/* static gchar * */ static void
/* prefix_newlines (const gchar *prefix, */ cancelled (GCancellable *cancellable)
/* const gchar *str) */ {
/* { */ mmcli_async_operation_done ();
/* GString *prefixed_string = NULL; */ }
/* const gchar *line_start = str; */
/* const gchar *line_end; */
/* while ((line_end = strchr (line_start, '\n'))) { */ static gchar *
/* gssize line_length; */ prefix_newlines (const gchar *prefix,
const gchar *str)
{
GString *prefixed_string = NULL;
const gchar *line_start = str;
const gchar *line_end;
/* line_length = line_end - line_start; */ while ((line_end = strchr (line_start, '\n'))) {
/* if (line_start[line_length - 1] == '\r') */ gssize line_length;
/* line_length--; */
/* if (line_length > 0) { */ line_length = line_end - line_start;
/* if (prefixed_string) { */ if (line_start[line_length - 1] == '\r')
/* /\* If not the first line, add the prefix *\/ */ line_length--;
/* g_string_append_printf (prefixed_string, */
/* "\n%s", prefix); */
/* } else { */
/* prefixed_string = g_string_new (""); */
/* } */
/* g_string_append_len (prefixed_string, */ if (line_length > 0) {
/* line_start, */ if (prefixed_string) {
/* line_length); */ /* If not the first line, add the prefix */
/* } */ g_string_append_printf (prefixed_string,
"\n%s", prefix);
} else {
prefixed_string = g_string_new ("");
}
/* line_start = line_end + 1; */ g_string_append_len (prefixed_string,
/* } */ line_start,
line_length);
}
/* return (prefixed_string ? */ line_start = line_end + 1;
/* g_string_free (prefixed_string, FALSE) : */ }
/* NULL); */
/* } */
/* static void */ return (prefixed_string ?
/* get_info_process_reply (gboolean result, */ g_string_free (prefixed_string, FALSE) :
/* const GError *error, */ NULL);
/* const gchar *manufacturer, */ }
/* const gchar *model, */
/* const gchar *revision) */
/* { */
/* gchar *prefixed_revision; */
/* gchar *master_device; */
/* gchar *device; */
/* gchar *device_id; */
/* gchar *equipment_id; */
/* gchar *driver; */
/* gchar *plugin; */
/* MMModemType type; */
/* gboolean enabled; */
/* gchar *unlock_required; */
/* guint32 unlock_retries; */
/* gchar *unlock; */
/* MMModemIpMethod ip_method; */
/* MMModemState state; */
/* if (!result) { */ static void
/* g_printerr ("couldn't get info from modem: '%s'\n", */ print_modem_info (void)
/* error ? error->message : "unknown error"); */ {
/* exit (EXIT_FAILURE); */ GError *error = NULL;
/* } */ MMSim *sim;
MMModemLock unlock_required;
gchar *prefixed_revision;
gchar *unlock;
/* /\* Get additional info from properties *\/ */ /* Not the best thing to do, as we may be doing _get() calls twice, but
/* master_device = mm_modem_get_master_device (ctxt.modem); */ * easiest to maintain */
/* device = mm_modem_get_device (ctxt.modem); */ #define VALIDATE(str) (str ? str : "unknown")
/* device_id = mm_modem_get_device_identifier (ctxt.modem); */
/* equipment_id = mm_modem_get_equipment_identifier (ctxt.modem); */
/* driver = mm_modem_get_driver (ctxt.modem); */
/* plugin = mm_modem_get_plugin (ctxt.modem); */
/* type = mm_modem_get_modem_type (ctxt.modem); */
/* enabled = mm_modem_get_enabled (ctxt.modem); */
/* unlock_required = mm_modem_get_unlock_required (ctxt.modem); */
/* unlock_retries = mm_modem_get_unlock_retries (ctxt.modem); */
/* ip_method = mm_modem_get_ip_method (ctxt.modem); */
/* state = mm_modem_get_state (ctxt.modem); */
/* /\* Strings with mixed properties *\/ */ /* Strings with mixed properties */
/* unlock = (unlock_required ? */ unlock_required = mm_modem_get_unlock_required (ctx->modem);
/* g_strdup_printf ("%s (%u retries)", */ switch (unlock_required) {
/* unlock_required, */ case MM_MODEM_LOCK_NONE:
/* unlock_retries) : */ unlock = g_strdup ("not required");
/* g_strdup ("not required")); */ break;
case MM_MODEM_LOCK_UNKNOWN:
unlock = g_strdup ("unknown");
break;
default:
unlock = g_strdup_printf ("%s (%u retries)",
mmcli_get_lock_string (unlock_required),
mm_modem_get_unlock_retries (ctx->modem));
break;
}
/* /\* Rework possible multiline strings *\/ */ /* Rework possible multiline strings */
/* prefixed_revision = prefix_newlines (" | ", */ prefixed_revision = prefix_newlines (" | ",
/* revision); */ mm_modem_get_revision (ctx->modem));
/* g_print ("\n" */ /* Global IDs */
/* "%s\n" */ g_print ("\n"
/* " -------------------------\n" */ "%s (device id '%s')\n",
/* " Hardware | manufacturer: '%s'\n" */ VALIDATE (mm_modem_get_path (ctx->modem)),
/* " | model: '%s'\n" */ VALIDATE (mm_modem_get_device_identifier (ctx->modem)));
/* " | revision: '%s'\n" */
/* " | type: '%s'\n" */
/* " -------------------------\n" */
/* " System | master device: '%s'\n" */
/* " | device: '%s'\n" */
/* " | device id: '%s'\n" */
/* " | equipment id: '%s'\n" */
/* " | driver: '%s'\n" */
/* " | plugin: '%s'\n" */
/* " -------------------------\n" */
/* " Status | enabled: '%s'\n" */
/* " | unlock: '%s'\n" */
/* " | IP method: '%s'\n" */
/* " | state: '%s'\n" */
/* "\n", */
/* ctxt.modem_str, */
/* manufacturer, */
/* model, */
/* prefixed_revision ? prefixed_revision : revision, */
/* get_modem_type_string (type), */
/* master_device, */
/* device, */
/* device_id, */
/* equipment_id, */
/* driver, */
/* plugin, */
/* enabled ? "yes" : "no", */
/* unlock, */
/* get_ip_method_string (ip_method), */
/* get_state_string (state)); */
/* g_free (prefixed_revision); */ /* Hardware related stuff */
/* g_free (master_device); */ g_print (" -------------------------\n"
/* g_free (device); */ " Hardware | manufacturer: '%s'\n"
/* g_free (device_id); */ " | model: '%s'\n"
/* g_free (equipment_id); */ " | revision: '%s'\n"
/* g_free (driver); */ " | capabilities: '%s'\n"
/* g_free (plugin); */ " | equipment id: '%s'\n",
/* g_free (unlock_required); */ VALIDATE (mm_modem_get_manufacturer (ctx->modem)),
/* g_free (unlock); */ VALIDATE (mm_modem_get_model (ctx->modem)),
/* } */ VALIDATE (prefixed_revision),
VALIDATE (mm_modem_get_capabilities_string (mm_modem_get_modem_capabilities (ctx->modem))),
VALIDATE (mm_modem_get_equipment_identifier (ctx->modem)));
/* static void */ /* System related stuff */
/* get_info_ready (MMModem *modem, */ g_print (" -------------------------\n"
/* GAsyncResult *result, */ " System | device: '%s'\n"
/* gpointer nothing) */ " | driver: '%s'\n"
/* { */ " | plugin: '%s'\n",
/* gboolean operation_result; */ VALIDATE (mm_modem_get_device (ctx->modem)),
/* gchar *manufacturer = NULL; */ VALIDATE (mm_modem_get_driver (ctx->modem)),
/* gchar *model = NULL; */ VALIDATE (mm_modem_get_plugin (ctx->modem)));
/* gchar *revision = NULL; */
/* GError *error = NULL; */
/* operation_result = mm_modem_get_info_finish (modem, */ /* Status related stuff */
/* result, */ g_print (" -------------------------\n"
/* &manufacturer, */ " Status | unlock: '%s'\n"
/* &model, */ " | state: '%s'\n",
/* &revision, */ VALIDATE (unlock),
/* &error); */ VALIDATE (mmcli_get_state_string (mm_modem_get_state (ctx->modem))));
/* get_info_process_reply (operation_result, */
/* error, */
/* manufacturer, */
/* model, */
/* revision); */
/* g_free (manufacturer); */ /* SIM related stuff */
/* g_free (model); */ sim = mm_modem_get_sim_sync (ctx->modem, NULL, &error);
/* g_free (revision); */ if (error) {
g_warning ("Couldn't get SIM: '%s'", error->message);
g_error_free (error);
}
if (sim) {
g_print (" -------------------------\n"
" SIM | imsi : '%s'\n"
" | id : '%s'\n"
" | operator id : '%s'\n"
" | operator name : '%s'\n",
VALIDATE (mm_sim_get_imsi (sim)),
VALIDATE (mm_sim_get_identifier (sim)),
VALIDATE (mm_sim_get_operator_identifier (sim)),
VALIDATE (mm_sim_get_operator_name (sim)));
g_object_unref (sim);
}
/* mmcli_async_operation_done (); */ g_print ("\n");
/* } */
g_free (prefixed_revision);
g_free (unlock);
}
static void static void
enable_process_reply (gboolean result, enable_process_reply (gboolean result,
@@ -459,6 +428,11 @@ get_modem_ready (GObject *source,
mm_object_get_path (ctx->object), mm_object_get_path (ctx->object),
mmcli_get_state_string (current)); mmcli_get_state_string (current));
/* If we get cancelled, operation done */
g_cancellable_connect (ctx->cancellable,
G_CALLBACK (cancelled),
NULL,
NULL);
return; return;
} }
@@ -538,27 +512,8 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
/* Request to get info from modem? */ /* Request to get info from modem? */
if (info_flag) { if (info_flag) {
/* TODO */ g_debug ("Printing modem info...");
print_modem_info ();
/* gboolean result; */
/* gchar *manufacturer = NULL; */
/* gchar *model = NULL; */
/* gchar *revision = NULL; */
/* result = mm_modem_get_info (ctxt.modem, */
/* &manufacturer, */
/* &model, */
/* &revision, */
/* &error); */
/* get_info_process_reply (result, */
/* error, */
/* manufacturer, */
/* model, */
/* revision); */
/* g_free (manufacturer); */
/* g_free (model); */
/* g_free (revision); */
return; return;
} }