cli: allow modifying default DBus timeout with `--timeout'

By default 30s will be used for every operation.
This commit is contained in:
Aleksander Morgado
2012-07-25 10:04:20 +02:00
parent 8a34e41794
commit 8f8bcd7724
12 changed files with 100 additions and 3 deletions

View File

@@ -248,6 +248,9 @@ get_manager_ready (GObject *source,
{
ctx->manager = mmcli_get_manager_finish (result);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->manager));
/* Request to set log level? */
if (set_logging_str) {
mm_manager_set_logging (ctx->manager,
@@ -327,6 +330,9 @@ mmcli_manager_run_synchronous (GDBusConnection *connection)
ctx = g_new0 (Context, 1);
ctx->manager = mmcli_get_manager_sync (connection);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->manager));
/* Request to set log level? */
if (set_logging_str) {
gboolean result;

View File

@@ -405,6 +405,12 @@ get_modem_ready (GObject *source,
ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
ctx->modem_3gpp_ussd = mm_object_get_modem_3gpp_ussd (ctx->object);
/* Setup operation timeout */
if (ctx->modem_3gpp)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
if (ctx->modem_3gpp_ussd)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp_ussd));
ensure_modem_3gpp ();
if (ussd_status_flag)
@@ -502,6 +508,12 @@ mmcli_modem_3gpp_run_synchronous (GDBusConnection *connection)
ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
ctx->modem_3gpp_ussd = mm_object_get_modem_3gpp_ussd (ctx->object);
/* Setup operation timeout */
if (ctx->modem_3gpp)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
if (ctx->modem_3gpp_ussd)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp_ussd));
ensure_modem_3gpp ();
if (scan_flag)

View File

@@ -162,6 +162,10 @@ get_modem_ready (GObject *source,
ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
/* Setup operation timeout */
if (ctx->modem_cdma)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
ensure_modem_cdma ();
/* Request to activate the modem? */
@@ -207,6 +211,10 @@ mmcli_modem_cdma_run_synchronous (GDBusConnection *connection)
&ctx->manager);
ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
/* Setup operation timeout */
if (ctx->modem_cdma)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
ensure_modem_cdma ();
/* Request to activate the modem? */

View File

@@ -407,6 +407,10 @@ get_modem_ready (GObject *source,
ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
ctx->modem_location = mm_object_get_modem_location (ctx->object);
/* Setup operation timeout */
if (ctx->modem_location)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_location));
ensure_modem_location ();
if (status_flag)
@@ -473,6 +477,10 @@ mmcli_modem_location_run_synchronous (GDBusConnection *connection)
&ctx->manager);
ctx->modem_location = mm_object_get_modem_location (ctx->object);
/* Setup operation timeout */
if (ctx->modem_location)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_location));
ensure_modem_location ();
/* Request to get location status? */

View File

@@ -252,6 +252,10 @@ get_modem_ready (GObject *source,
ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);
/* Setup operation timeout */
if (ctx->modem_messaging)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));
ensure_modem_messaging ();
/* Request to list SMS? */
@@ -327,6 +331,10 @@ mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
&ctx->manager);
ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);
/* Setup operation timeout */
if (ctx->modem_messaging)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));
ensure_modem_messaging ();
/* Request to list the SMS? */

View File

@@ -323,6 +323,10 @@ get_modem_ready (GObject *source,
ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
ctx->modem_simple = mm_object_get_modem_simple (ctx->object);
/* Setup operation timeout */
if (ctx->modem_simple)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_simple));
ensure_modem_simple ();
/* Request to connect the modem? */
@@ -402,6 +406,10 @@ mmcli_modem_simple_run_synchronous (GDBusConnection *connection)
&ctx->manager);
ctx->modem_simple = mm_object_get_modem_simple (ctx->object);
/* Setup operation timeout */
if (ctx->modem_simple)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_simple));
ensure_modem_simple ();
if (connect_str)

View File

@@ -202,6 +202,10 @@ get_modem_ready (GObject *source,
ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
ctx->modem_time = mm_object_get_modem_time (ctx->object);
/* Setup operation timeout */
if (ctx->modem_time)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_time));
ensure_modem_time ();
/* Request to get network time from the modem? */
@@ -247,6 +251,10 @@ mmcli_modem_time_run_synchronous (GDBusConnection *connection)
&ctx->manager);
ctx->modem_time = mm_object_get_modem_time (ctx->object);
/* Setup operation timeout */
if (ctx->modem_time)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_time));
ensure_modem_time ();
/* Request to get network time from the modem? */

View File

@@ -771,6 +771,14 @@ get_modem_ready (GObject *source,
ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
/* Setup operation timeout */
if (ctx->modem)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem));
if (ctx->modem_3gpp)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
if (ctx->modem_cdma)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
if (info_flag)
g_assert_not_reached ();
@@ -958,6 +966,14 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
/* Setup operation timeout */
if (ctx->modem)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem));
if (ctx->modem_3gpp)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
if (ctx->modem_cdma)
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
/* Request to get info from modem? */
if (info_flag) {
g_debug ("Printing modem info...");

View File

@@ -315,6 +315,9 @@ get_sim_ready (GObject *source,
&ctx->manager,
&ctx->object);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sim));
if (info_flag)
g_assert_not_reached ();
@@ -402,6 +405,9 @@ mmcli_sim_run_synchronous (GDBusConnection *connection)
&ctx->manager,
&ctx->object);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sim));
/* Request to get info from SIM? */
if (info_flag) {
g_debug ("Printing sim info...");

View File

@@ -220,6 +220,8 @@ get_sms_ready (GObject *source,
ctx->sms = mmcli_get_sms_finish (result,
&ctx->manager,
&ctx->object);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sms));
if (info_flag)
g_assert_not_reached ();
@@ -274,6 +276,9 @@ mmcli_sms_run_synchronous (GDBusConnection *connection)
&ctx->manager,
&ctx->object);
/* Setup operation timeout */
mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sms));
/* Request to get info from SMS? */
if (info_flag) {
g_debug ("Printing SMS info...");

View File

@@ -45,6 +45,7 @@ static GCancellable *cancellable;
static gboolean verbose_flag;
static gboolean version_flag;
static gboolean async_flag;
static gint timeout = 30; /* by default, use 30s for all operations */
static GOptionEntry main_entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag,
@@ -59,6 +60,10 @@ static GOptionEntry main_entries[] = {
"Use asynchronous methods",
NULL
},
{ "timeout", 0, 0, G_OPTION_ARG_INT, &timeout,
"Timeout for the operation",
"[SECONDS]"
},
{ NULL }
};
@@ -163,6 +168,12 @@ mmcli_force_sync_operation (void)
}
}
void
mmcli_force_operation_timeout (GDBusProxy *proxy)
{
g_dbus_proxy_set_default_timeout (proxy, timeout * 1000);
}
gint
main (gint argc, gchar **argv)
{

View File

@@ -24,9 +24,10 @@
#define __MMCLI_H__
/* Common */
void mmcli_async_operation_done (void);
void mmcli_force_async_operation (void);
void mmcli_force_sync_operation (void);
void mmcli_async_operation_done (void);
void mmcli_force_async_operation (void);
void mmcli_force_sync_operation (void);
void mmcli_force_operation_timeout (GDBusProxy *proxy);
/* Manager group */
GOptionGroup *mmcli_manager_get_option_group (void);