mmcli: allow passing bearer index in --delete-bearer
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
|
||||
/* Context */
|
||||
typedef struct {
|
||||
GDBusConnection *connection;
|
||||
MMManager *manager;
|
||||
GCancellable *cancellable;
|
||||
MMObject *object;
|
||||
@@ -105,7 +106,7 @@ static GOptionEntry entries[] = {
|
||||
},
|
||||
{ "delete-bearer", 0, 0, G_OPTION_ARG_STRING, &delete_bearer_str,
|
||||
"Delete a data bearer from a given modem",
|
||||
"[PATH]"
|
||||
"[PATH|INDEX]"
|
||||
},
|
||||
{ "set-current-capabilities", 0, 0, G_OPTION_ARG_STRING, &set_current_capabilities_str,
|
||||
"Set current modem capabilities.",
|
||||
@@ -214,6 +215,8 @@ context_free (Context *ctx)
|
||||
g_object_unref (ctx->object);
|
||||
if (ctx->manager)
|
||||
g_object_unref (ctx->manager);
|
||||
if (ctx->connection)
|
||||
g_object_unref (ctx->connection);
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
@@ -810,6 +813,30 @@ delete_bearer_ready (MMModem *modem,
|
||||
mmcli_async_operation_done ();
|
||||
}
|
||||
|
||||
static void
|
||||
get_bearer_to_delete_ready (GDBusConnection *connection,
|
||||
GAsyncResult *res)
|
||||
{
|
||||
MMBearer *bearer;
|
||||
MMObject *obj = NULL;
|
||||
|
||||
bearer = mmcli_get_bearer_finish (res, NULL, &obj);
|
||||
if (!g_str_equal (mm_object_get_path (obj), mm_modem_get_path (ctx->modem))) {
|
||||
g_printerr ("error: bearer '%s' not owned by modem '%s'",
|
||||
mm_bearer_get_path (bearer),
|
||||
mm_modem_get_path (ctx->modem));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
mm_modem_delete_bearer (ctx->modem,
|
||||
mm_bearer_get_path (bearer),
|
||||
ctx->cancellable,
|
||||
(GAsyncReadyCallback)delete_bearer_ready,
|
||||
NULL);
|
||||
g_object_unref (bearer);
|
||||
g_object_unref (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
set_current_capabilities_process_reply (gboolean result,
|
||||
const GError *error)
|
||||
@@ -1116,11 +1143,11 @@ get_modem_ready (GObject *source,
|
||||
|
||||
/* Request to delete a given bearer? */
|
||||
if (delete_bearer_str) {
|
||||
mm_modem_delete_bearer (ctx->modem,
|
||||
delete_bearer_str,
|
||||
ctx->cancellable,
|
||||
(GAsyncReadyCallback)delete_bearer_ready,
|
||||
NULL);
|
||||
mmcli_get_bearer (ctx->connection,
|
||||
delete_bearer_str,
|
||||
ctx->cancellable,
|
||||
(GAsyncReadyCallback)get_bearer_to_delete_ready,
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1179,6 +1206,7 @@ mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
||||
ctx = g_new0 (Context, 1);
|
||||
if (cancellable)
|
||||
ctx->cancellable = g_object_ref (cancellable);
|
||||
ctx->connection = g_object_ref (connection);
|
||||
|
||||
/* Get proper modem */
|
||||
mmcli_get_modem (connection,
|
||||
@@ -1339,11 +1367,26 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
||||
/* Request to delete a given bearer? */
|
||||
if (delete_bearer_str) {
|
||||
gboolean result;
|
||||
MMBearer *bearer;
|
||||
MMObject *obj = NULL;
|
||||
|
||||
bearer = mmcli_get_bearer_sync (connection,
|
||||
delete_bearer_str,
|
||||
NULL,
|
||||
&obj);
|
||||
if (!g_str_equal (mm_object_get_path (obj), mm_modem_get_path (ctx->modem))) {
|
||||
g_printerr ("error: bearer '%s' not owned by modem '%s'",
|
||||
mm_bearer_get_path (bearer),
|
||||
mm_modem_get_path (ctx->modem));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
result = mm_modem_delete_bearer_sync (ctx->modem,
|
||||
delete_bearer_str,
|
||||
mm_bearer_get_path (bearer),
|
||||
NULL,
|
||||
&error);
|
||||
g_object_unref (bearer);
|
||||
g_object_unref (obj);
|
||||
|
||||
delete_bearer_process_reply (result, error);
|
||||
return;
|
||||
|
Reference in New Issue
Block a user