cli: start to port Modem actions to use the new libmm-glib
This commit is contained in:
@@ -12,6 +12,8 @@ mmcli_CPPFLAGS = \
|
|||||||
mmcli_SOURCES = \
|
mmcli_SOURCES = \
|
||||||
mmcli.h \
|
mmcli.h \
|
||||||
mmcli.c \
|
mmcli.c \
|
||||||
|
mmcli-common.h \
|
||||||
|
mmcli-common.c \
|
||||||
mmcli-manager.c \
|
mmcli-manager.c \
|
||||||
mmcli-modem.c
|
mmcli-modem.c
|
||||||
|
|
||||||
|
237
cli/mmcli-common.c
Normal file
237
cli/mmcli-common.c
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* mmcli -- Control modem status & access information from the command line
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mmcli-common.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
manager_new_ready (GDBusConnection *connection,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GSimpleAsyncResult *simple)
|
||||||
|
{
|
||||||
|
MMManager *manager;
|
||||||
|
gchar *name_owner;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
manager = mm_manager_new_finish (res, &error);
|
||||||
|
if (!manager) {
|
||||||
|
g_printerr ("error: couldn't create manager: %s\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
|
||||||
|
if (!name_owner) {
|
||||||
|
g_printerr ("error: couldn't find the ModemManager process in the bus\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_debug ("ModemManager process found at '%s'", name_owner);
|
||||||
|
g_free (name_owner);
|
||||||
|
|
||||||
|
g_simple_async_result_set_op_res_gpointer (simple, manager, NULL);
|
||||||
|
g_simple_async_result_complete (simple);
|
||||||
|
g_object_unref (simple);
|
||||||
|
}
|
||||||
|
|
||||||
|
MMManager *
|
||||||
|
mmcli_get_manager_finish (GAsyncResult *res)
|
||||||
|
{
|
||||||
|
return g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mmcli_get_manager (GDBusConnection *connection,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
|
||||||
|
result = g_simple_async_result_new (G_OBJECT (connection),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
mmcli_get_manager);
|
||||||
|
mm_manager_new (connection,
|
||||||
|
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
||||||
|
cancellable,
|
||||||
|
(GAsyncReadyCallback)manager_new_ready,
|
||||||
|
result);
|
||||||
|
}
|
||||||
|
|
||||||
|
MMManager *
|
||||||
|
mmcli_get_manager_sync (GDBusConnection *connection)
|
||||||
|
{
|
||||||
|
MMManager *manager;
|
||||||
|
gchar *name_owner;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
manager = mm_manager_new_sync (connection,
|
||||||
|
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
||||||
|
NULL,
|
||||||
|
&error);
|
||||||
|
if (!manager) {
|
||||||
|
g_printerr ("error: couldn't create manager: %s\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
|
||||||
|
if (!name_owner) {
|
||||||
|
g_printerr ("error: couldn't find the ModemManager process in the bus\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_debug ("ModemManager process found at '%s'", name_owner);
|
||||||
|
g_free (name_owner);
|
||||||
|
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MODEM_PATH_TAG "modem-path-tag"
|
||||||
|
|
||||||
|
static MMModem *
|
||||||
|
find_modem (MMManager *manager,
|
||||||
|
const gchar *modem_path)
|
||||||
|
{
|
||||||
|
GList *modems;
|
||||||
|
GList *l;
|
||||||
|
MMModem *found = NULL;
|
||||||
|
|
||||||
|
modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
|
||||||
|
for (l = modems; l; l = g_list_next (l)) {
|
||||||
|
MMModem *modem = MM_MODEM (l->data);
|
||||||
|
|
||||||
|
if (g_str_equal (mm_modem_get_path (modem),
|
||||||
|
modem_path)) {
|
||||||
|
found = g_object_ref (modem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_list_foreach (modems, (GFunc)g_object_unref, NULL);
|
||||||
|
g_list_free (modems);
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
g_printerr ("error: couldn't find the Modem at '%s'\n", modem_path);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_debug ("Modem found at '%s'", modem_path);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
get_modem_path (const gchar *modem_str)
|
||||||
|
{
|
||||||
|
gchar *modem_path;
|
||||||
|
|
||||||
|
/* We must have a given modem specified */
|
||||||
|
if (!modem_str) {
|
||||||
|
g_printerr ("error: no modem was specified\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Modem path may come in two ways: full DBus path or just modem index.
|
||||||
|
* If it is a modem index, we'll need to generate the DBus path ourselves */
|
||||||
|
if (modem_str[0] == '/')
|
||||||
|
modem_path = g_strdup (modem_str);
|
||||||
|
else {
|
||||||
|
if (g_ascii_isdigit (modem_str[0]))
|
||||||
|
modem_path = g_strdup_printf (MM_DBUS_PATH "/Modems/%s", modem_str);
|
||||||
|
else {
|
||||||
|
g_printerr ("error: invalid modem string specified: '%s'\n",
|
||||||
|
modem_str);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return modem_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
get_manager_ready (GDBusConnection *connection,
|
||||||
|
GAsyncResult *res,
|
||||||
|
GSimpleAsyncResult *simple)
|
||||||
|
{
|
||||||
|
MMManager *manager;
|
||||||
|
MMModem *found;
|
||||||
|
const gchar *modem_path;
|
||||||
|
|
||||||
|
manager = mmcli_get_manager_finish (res);
|
||||||
|
modem_path = g_object_get_data (G_OBJECT (simple), MODEM_PATH_TAG);
|
||||||
|
found = find_modem (manager, modem_path);
|
||||||
|
g_object_unref (manager);
|
||||||
|
|
||||||
|
g_simple_async_result_set_op_res_gpointer (simple, found, NULL);
|
||||||
|
g_simple_async_result_complete (simple);
|
||||||
|
g_object_unref (simple);
|
||||||
|
}
|
||||||
|
|
||||||
|
MMModem *
|
||||||
|
mmcli_get_modem_finish (GAsyncResult *res)
|
||||||
|
{
|
||||||
|
return g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mmcli_get_modem (GDBusConnection *connection,
|
||||||
|
const gchar *modem_str,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GSimpleAsyncResult *result;
|
||||||
|
gchar *modem_path;
|
||||||
|
|
||||||
|
modem_path = get_modem_path (modem_str);
|
||||||
|
result = g_simple_async_result_new (G_OBJECT (connection),
|
||||||
|
callback,
|
||||||
|
user_data,
|
||||||
|
mmcli_get_modem);
|
||||||
|
g_object_set_data_full (G_OBJECT (result),
|
||||||
|
MODEM_PATH_TAG,
|
||||||
|
modem_path,
|
||||||
|
g_free);
|
||||||
|
|
||||||
|
mmcli_get_manager (connection,
|
||||||
|
cancellable,
|
||||||
|
(GAsyncReadyCallback)get_manager_ready,
|
||||||
|
result);
|
||||||
|
}
|
||||||
|
|
||||||
|
MMModem *
|
||||||
|
mmcli_get_modem_sync (GDBusConnection *connection,
|
||||||
|
const gchar *modem_str)
|
||||||
|
{
|
||||||
|
MMManager *manager;
|
||||||
|
MMModem *found;
|
||||||
|
gchar *modem_path;
|
||||||
|
|
||||||
|
manager = mmcli_get_manager_sync (connection);
|
||||||
|
modem_path = get_modem_path (modem_str);
|
||||||
|
|
||||||
|
found = find_modem (manager, modem_path);
|
||||||
|
g_object_unref (manager);
|
||||||
|
g_free (modem_path);
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
39
cli/mmcli-common.h
Normal file
39
cli/mmcli-common.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _MMCLI_COMMON_H_
|
||||||
|
#define _MMCLI_COMMON_H_
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#include <libmm-glib.h>
|
||||||
|
|
||||||
|
void mmcli_get_manager (GDBusConnection *connection,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
MMManager *mmcli_get_manager_finish (GAsyncResult *res);
|
||||||
|
MMManager *mmcli_get_manager_sync (GDBusConnection *connection);
|
||||||
|
|
||||||
|
|
||||||
|
void mmcli_get_modem (GDBusConnection *connection,
|
||||||
|
const gchar *modem_str,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GAsyncReadyCallback callback,
|
||||||
|
gpointer user_data);
|
||||||
|
MMModem *mmcli_get_modem_finish (GAsyncResult *res);
|
||||||
|
MMModem *mmcli_get_modem_sync (GDBusConnection *connection,
|
||||||
|
const gchar *modem_str);
|
||||||
|
|
||||||
|
#endif /* _MMCLI_COMMON_H_ */
|
@@ -32,6 +32,7 @@
|
|||||||
#include "libmm-glib.h"
|
#include "libmm-glib.h"
|
||||||
|
|
||||||
#include "mmcli.h"
|
#include "mmcli.h"
|
||||||
|
#include "mmcli-common.h"
|
||||||
|
|
||||||
/* Context */
|
/* Context */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -90,7 +91,7 @@ mmcli_manager_options_enabled (void)
|
|||||||
n_actions = (list_modems_flag +
|
n_actions = (list_modems_flag +
|
||||||
monitor_modems_flag +
|
monitor_modems_flag +
|
||||||
scan_modems_flag +
|
scan_modems_flag +
|
||||||
(set_logging_str ? 1 : 0));
|
!!set_logging_str);
|
||||||
|
|
||||||
if (n_actions > 1) {
|
if (n_actions > 1) {
|
||||||
g_printerr ("error: too many manager actions requested\n");
|
g_printerr ("error: too many manager actions requested\n");
|
||||||
@@ -206,11 +207,14 @@ list_current_modems (MMManager *manager)
|
|||||||
else {
|
else {
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
g_print ("Found %u modems\n", g_list_length (modems));
|
g_print ("Found %u modems:\n", g_list_length (modems));
|
||||||
for (l = modems; l; l = g_list_next (l)) {
|
for (l = modems; l; l = g_list_next (l)) {
|
||||||
g_print ("\t[TODO: Print path]\n");
|
MMModem *modem = MM_MODEM (l->data);
|
||||||
g_object_unref (l->data);
|
|
||||||
|
g_print ("\t%s\n",
|
||||||
|
mm_modem_get_path (modem));
|
||||||
}
|
}
|
||||||
|
g_list_foreach (modems, (GFunc)g_object_unref, NULL);
|
||||||
g_list_free (modems);
|
g_list_free (modems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,28 +226,11 @@ cancelled (GCancellable *cancellable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
manager_new_ready (GObject *source,
|
get_manager_ready (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer none)
|
gpointer none)
|
||||||
{
|
{
|
||||||
gchar *name_owner;
|
ctx->manager = mmcli_get_manager_finish (result);
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
ctx->manager = mm_manager_new_finish (result, &error);
|
|
||||||
if (!ctx->manager) {
|
|
||||||
g_printerr ("error: couldn't create manager: %s\n",
|
|
||||||
error ? error->message : "unknown error");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (ctx->manager));
|
|
||||||
if (!name_owner) {
|
|
||||||
g_printerr ("error: couldn't find the ModemManager process in the bus\n");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_debug ("ModemManager process found at '%s'", name_owner);
|
|
||||||
g_free (name_owner);
|
|
||||||
|
|
||||||
/* Request to set log level? */
|
/* Request to set log level? */
|
||||||
if (set_logging_str) {
|
if (set_logging_str) {
|
||||||
@@ -304,17 +291,15 @@ mmcli_manager_run_asynchronous (GDBusConnection *connection,
|
|||||||
ctx->cancellable = g_object_ref (cancellable);
|
ctx->cancellable = g_object_ref (cancellable);
|
||||||
|
|
||||||
/* Create a new Manager object asynchronously */
|
/* Create a new Manager object asynchronously */
|
||||||
mm_manager_new (connection,
|
mmcli_get_manager (connection,
|
||||||
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
cancellable,
|
||||||
cancellable,
|
(GAsyncReadyCallback)get_manager_ready,
|
||||||
(GAsyncReadyCallback)manager_new_ready,
|
NULL);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mmcli_manager_run_synchronous (GDBusConnection *connection)
|
mmcli_manager_run_synchronous (GDBusConnection *connection)
|
||||||
{
|
{
|
||||||
gchar *name_owner;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (monitor_modems_flag) {
|
if (monitor_modems_flag) {
|
||||||
@@ -324,24 +309,7 @@ mmcli_manager_run_synchronous (GDBusConnection *connection)
|
|||||||
|
|
||||||
/* Initialize context */
|
/* Initialize context */
|
||||||
ctx = g_new0 (Context, 1);
|
ctx = g_new0 (Context, 1);
|
||||||
ctx->manager = mm_manager_new_sync (connection,
|
ctx->manager = mmcli_get_manager_sync (connection);
|
||||||
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
|
||||||
NULL,
|
|
||||||
&error);
|
|
||||||
if (!ctx->manager) {
|
|
||||||
g_printerr ("error: couldn't create manager: %s\n",
|
|
||||||
error ? error->message : "unknown error");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (ctx->manager));
|
|
||||||
if (!name_owner) {
|
|
||||||
g_printerr ("error: couldn't find the ModemManager process in the bus\n");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_debug ("ModemManager process found at '%s'", name_owner);
|
|
||||||
g_free (name_owner);
|
|
||||||
|
|
||||||
/* Request to set log level? */
|
/* Request to set log level? */
|
||||||
if (set_logging_str) {
|
if (set_logging_str) {
|
||||||
|
@@ -28,51 +28,53 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
|
||||||
#include <libmm.h>
|
#include <libmm-glib.h>
|
||||||
|
|
||||||
#include "mmcli.h"
|
#include "mmcli.h"
|
||||||
|
#include "mmcli-common.h"
|
||||||
|
|
||||||
/* Context */
|
/* Context */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Input options */
|
GCancellable *cancellable;
|
||||||
gchar *modem_str;
|
|
||||||
gboolean info_flag;
|
|
||||||
gboolean monitor_state_flag;
|
|
||||||
gboolean enable_flag;
|
|
||||||
gboolean disable_flag;
|
|
||||||
gboolean reset_flag;
|
|
||||||
gchar *factory_reset_str;
|
|
||||||
/* The modem proxy */
|
|
||||||
MMModem *modem;
|
MMModem *modem;
|
||||||
} Context;
|
} Context;
|
||||||
static Context ctxt;
|
static Context *ctx;
|
||||||
|
|
||||||
|
/* Options */
|
||||||
|
static gchar *modem_str;
|
||||||
|
static gboolean info_flag;
|
||||||
|
static gboolean monitor_state_flag;
|
||||||
|
static gboolean enable_flag;
|
||||||
|
static gboolean disable_flag;
|
||||||
|
static gboolean reset_flag;
|
||||||
|
static gchar *factory_reset_str;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "modem", 'm', 0, G_OPTION_ARG_STRING, &ctxt.modem_str,
|
{ "modem", 'm', 0, G_OPTION_ARG_STRING, &modem_str,
|
||||||
"Specify modem by path or index",
|
"Specify modem by path or index",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "info", 'i', 0, G_OPTION_ARG_NONE, &ctxt.info_flag,
|
{ "info", 'i', 0, G_OPTION_ARG_NONE, &info_flag,
|
||||||
"Get information of a given modem",
|
"Get information of a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &ctxt.monitor_state_flag,
|
{ "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag,
|
||||||
"Monitor state of a given modem",
|
"Monitor state of a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "enable", 'e', 0, G_OPTION_ARG_NONE, &ctxt.enable_flag,
|
{ "enable", 'e', 0, G_OPTION_ARG_NONE, &enable_flag,
|
||||||
"Enable a given modem",
|
"Enable a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "disable", 'd', 0, G_OPTION_ARG_NONE, &ctxt.disable_flag,
|
{ "disable", 'd', 0, G_OPTION_ARG_NONE, &disable_flag,
|
||||||
"Disable a given modem",
|
"Disable a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "reset", 'r', 0, G_OPTION_ARG_NONE, &ctxt.reset_flag,
|
{ "reset", 'r', 0, G_OPTION_ARG_NONE, &reset_flag,
|
||||||
"Reset a given modem",
|
"Reset a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
{ "factory-reset", 0, 0, G_OPTION_ARG_STRING, &ctxt.factory_reset_str,
|
{ "factory-reset", 0, 0, G_OPTION_ARG_STRING, &factory_reset_str,
|
||||||
"Reset a given modem to its factory state",
|
"Reset a given modem to its factory state",
|
||||||
"[CODE]"
|
"[CODE]"
|
||||||
},
|
},
|
||||||
@@ -100,12 +102,12 @@ mmcli_modem_options_enabled (void)
|
|||||||
{
|
{
|
||||||
guint n_actions;
|
guint n_actions;
|
||||||
|
|
||||||
n_actions = (ctxt.info_flag +
|
n_actions = (info_flag +
|
||||||
ctxt.monitor_state_flag +
|
monitor_state_flag +
|
||||||
ctxt.enable_flag +
|
enable_flag +
|
||||||
ctxt.disable_flag +
|
disable_flag +
|
||||||
ctxt.reset_flag +
|
reset_flag +
|
||||||
!!ctxt.factory_reset_str);
|
!!factory_reset_str);
|
||||||
|
|
||||||
if (n_actions > 1) {
|
if (n_actions > 1) {
|
||||||
g_printerr ("error: too many modem actions requested\n");
|
g_printerr ("error: too many modem actions requested\n");
|
||||||
@@ -116,293 +118,236 @@ mmcli_modem_options_enabled (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init (GDBusConnection *connection)
|
context_free (Context *ctx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
if (!ctx)
|
||||||
|
return;
|
||||||
|
|
||||||
/* We must have a given modem specified */
|
if (ctx->cancellable)
|
||||||
if (!ctxt.modem_str) {
|
g_object_unref (ctx->cancellable);
|
||||||
g_printerr ("error: no modem was specified\n");
|
if (ctx->modem)
|
||||||
exit (EXIT_FAILURE);
|
g_object_unref (ctx->modem);
|
||||||
}
|
g_free (ctx);
|
||||||
|
|
||||||
/* Modem path may come in two ways: full DBus path or just modem index.
|
|
||||||
* If it is a modem index, we'll need to generate the DBus path ourselves */
|
|
||||||
if (ctxt.modem_str[0] != '/') {
|
|
||||||
if (g_ascii_isdigit (ctxt.modem_str[0])) {
|
|
||||||
gchar *tmp;
|
|
||||||
|
|
||||||
tmp = g_strdup_printf (MM_DBUS_PATH "/Modems/%s", ctxt.modem_str);
|
|
||||||
g_free (ctxt.modem_str);
|
|
||||||
ctxt.modem_str = tmp;
|
|
||||||
} else {
|
|
||||||
g_printerr ("error: invalid modem string specified: '%s'\n",
|
|
||||||
ctxt.modem_str);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create new modem */
|
|
||||||
ctxt.modem = mm_modem_new (ctxt.modem_str, connection, NULL, &error);
|
|
||||||
if (!ctxt.modem) {
|
|
||||||
g_printerr ("error: couldn't find modem '%s': %s\n",
|
|
||||||
ctxt.modem_str,
|
|
||||||
error ? error->message : "unknown error");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mmcli_modem_shutdown (void)
|
mmcli_modem_shutdown (void)
|
||||||
{
|
{
|
||||||
g_free (ctxt.modem_str);
|
context_free (ctx);
|
||||||
g_object_unref (ctxt.modem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
/* static gchar * */
|
||||||
prefix_newlines (const gchar *prefix,
|
/* prefix_newlines (const gchar *prefix, */
|
||||||
const gchar *str)
|
/* const gchar *str) */
|
||||||
{
|
/* { */
|
||||||
GString *prefixed_string = NULL;
|
/* GString *prefixed_string = NULL; */
|
||||||
const gchar *line_start = str;
|
/* const gchar *line_start = str; */
|
||||||
const gchar *line_end;
|
/* const gchar *line_end; */
|
||||||
|
|
||||||
while ((line_end = strchr (line_start, '\n'))) {
|
/* while ((line_end = strchr (line_start, '\n'))) { */
|
||||||
gssize line_length;
|
/* gssize line_length; */
|
||||||
|
|
||||||
line_length = line_end - line_start;
|
/* line_length = line_end - line_start; */
|
||||||
if (line_start[line_length - 1] == '\r')
|
/* if (line_start[line_length - 1] == '\r') */
|
||||||
line_length--;
|
/* line_length--; */
|
||||||
|
|
||||||
if (line_length > 0) {
|
/* if (line_length > 0) { */
|
||||||
if (prefixed_string) {
|
/* if (prefixed_string) { */
|
||||||
/* If not the first line, add the prefix */
|
/* /\* If not the first line, add the prefix *\/ */
|
||||||
g_string_append_printf (prefixed_string,
|
/* g_string_append_printf (prefixed_string, */
|
||||||
"\n%s", prefix);
|
/* "\n%s", prefix); */
|
||||||
} else {
|
/* } else { */
|
||||||
prefixed_string = g_string_new ("");
|
/* prefixed_string = g_string_new (""); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
g_string_append_len (prefixed_string,
|
/* g_string_append_len (prefixed_string, */
|
||||||
line_start,
|
/* line_start, */
|
||||||
line_length);
|
/* line_length); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
line_start = line_end + 1;
|
/* line_start = line_end + 1; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
return (prefixed_string ?
|
/* return (prefixed_string ? */
|
||||||
g_string_free (prefixed_string, FALSE) :
|
/* g_string_free (prefixed_string, FALSE) : */
|
||||||
NULL);
|
/* NULL); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static const gchar *
|
/* static const gchar * */
|
||||||
get_ip_method_string (MMModemIpMethod ip_method)
|
/* get_state_string (MMModemState state) */
|
||||||
{
|
/* { */
|
||||||
switch (ip_method) {
|
/* switch (state) { */
|
||||||
case MM_MODEM_IP_METHOD_PPP:
|
/* case MM_MODEM_STATE_UNKNOWN: */
|
||||||
return "PPP";
|
/* return "Unknown"; */
|
||||||
case MM_MODEM_IP_METHOD_STATIC:
|
/* case MM_MODEM_STATE_DISABLED: */
|
||||||
return "Static";
|
/* return "Disabled"; */
|
||||||
case MM_MODEM_IP_METHOD_DHCP:
|
/* case MM_MODEM_STATE_DISABLING: */
|
||||||
return "DHCP";
|
/* return "Disabling"; */
|
||||||
}
|
/* case MM_MODEM_STATE_ENABLING: */
|
||||||
|
/* return "Enabling"; */
|
||||||
|
/* case MM_MODEM_STATE_ENABLED: */
|
||||||
|
/* return "Enabled"; */
|
||||||
|
/* case MM_MODEM_STATE_SEARCHING: */
|
||||||
|
/* return "Searching"; */
|
||||||
|
/* case MM_MODEM_STATE_REGISTERED: */
|
||||||
|
/* return "Registered"; */
|
||||||
|
/* case MM_MODEM_STATE_DISCONNECTING: */
|
||||||
|
/* return "Disconnecting"; */
|
||||||
|
/* case MM_MODEM_STATE_CONNECTING: */
|
||||||
|
/* return "Connecting"; */
|
||||||
|
/* case MM_MODEM_STATE_CONNECTED: */
|
||||||
|
/* return "Connected"; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
g_warn_if_reached ();
|
/* g_warn_if_reached (); */
|
||||||
return NULL;
|
/* return NULL; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static const gchar *
|
/* static const gchar * */
|
||||||
get_modem_type_string (MMModemType type)
|
/* get_state_reason_string (MMModemStateReason reason) */
|
||||||
{
|
/* { */
|
||||||
switch (type) {
|
/* switch (reason) { */
|
||||||
case MM_MODEM_TYPE_UNKNOWN:
|
/* case MM_MODEM_STATE_REASON_NONE: */
|
||||||
return "Unknown";
|
/* return "None or unknown"; */
|
||||||
case MM_MODEM_TYPE_GSM:
|
/* case MM_MODEM_STATE_REASON_USER_REQUESTED: */
|
||||||
return "GSM";
|
/* return "User request"; */
|
||||||
case MM_MODEM_TYPE_CDMA:
|
/* case MM_MODEM_STATE_REASON_SUSPEND: */
|
||||||
return "CDMA";
|
/* return "Suspend"; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
g_warn_if_reached ();
|
/* g_warn_if_reached (); */
|
||||||
return NULL;
|
/* return NULL; */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
static const gchar *
|
/* static void */
|
||||||
get_state_string (MMModemState state)
|
/* get_info_process_reply (gboolean result, */
|
||||||
{
|
/* const GError *error, */
|
||||||
switch (state) {
|
/* const gchar *manufacturer, */
|
||||||
case MM_MODEM_STATE_UNKNOWN:
|
/* const gchar *model, */
|
||||||
return "Unknown";
|
/* const gchar *revision) */
|
||||||
case MM_MODEM_STATE_DISABLED:
|
/* { */
|
||||||
return "Disabled";
|
/* gchar *prefixed_revision; */
|
||||||
case MM_MODEM_STATE_DISABLING:
|
/* gchar *master_device; */
|
||||||
return "Disabling";
|
/* gchar *device; */
|
||||||
case MM_MODEM_STATE_ENABLING:
|
/* gchar *device_id; */
|
||||||
return "Enabling";
|
/* gchar *equipment_id; */
|
||||||
case MM_MODEM_STATE_ENABLED:
|
/* gchar *driver; */
|
||||||
return "Enabled";
|
/* gchar *plugin; */
|
||||||
case MM_MODEM_STATE_SEARCHING:
|
/* MMModemType type; */
|
||||||
return "Searching";
|
/* gboolean enabled; */
|
||||||
case MM_MODEM_STATE_REGISTERED:
|
/* gchar *unlock_required; */
|
||||||
return "Registered";
|
/* guint32 unlock_retries; */
|
||||||
case MM_MODEM_STATE_DISCONNECTING:
|
/* gchar *unlock; */
|
||||||
return "Disconnecting";
|
/* MMModemIpMethod ip_method; */
|
||||||
case MM_MODEM_STATE_CONNECTING:
|
/* MMModemState state; */
|
||||||
return "Connecting";
|
|
||||||
case MM_MODEM_STATE_CONNECTED:
|
|
||||||
return "Connected";
|
|
||||||
}
|
|
||||||
|
|
||||||
g_warn_if_reached ();
|
/* if (!result) { */
|
||||||
return NULL;
|
/* g_printerr ("couldn't get info from modem: '%s'\n", */
|
||||||
}
|
/* error ? error->message : "unknown error"); */
|
||||||
|
/* exit (EXIT_FAILURE); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
static const gchar *
|
/* /\* Get additional info from properties *\/ */
|
||||||
get_state_reason_string (MMModemStateReason reason)
|
/* master_device = mm_modem_get_master_device (ctxt.modem); */
|
||||||
{
|
/* device = mm_modem_get_device (ctxt.modem); */
|
||||||
switch (reason) {
|
/* device_id = mm_modem_get_device_identifier (ctxt.modem); */
|
||||||
case MM_MODEM_STATE_REASON_NONE:
|
/* equipment_id = mm_modem_get_equipment_identifier (ctxt.modem); */
|
||||||
return "None or unknown";
|
/* driver = mm_modem_get_driver (ctxt.modem); */
|
||||||
case MM_MODEM_STATE_REASON_USER_REQUESTED:
|
/* plugin = mm_modem_get_plugin (ctxt.modem); */
|
||||||
return "User request";
|
/* type = mm_modem_get_modem_type (ctxt.modem); */
|
||||||
case MM_MODEM_STATE_REASON_SUSPEND:
|
/* enabled = mm_modem_get_enabled (ctxt.modem); */
|
||||||
return "Suspend";
|
/* 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); */
|
||||||
|
|
||||||
g_warn_if_reached ();
|
/* /\* Strings with mixed properties *\/ */
|
||||||
return NULL;
|
/* unlock = (unlock_required ? */
|
||||||
}
|
/* g_strdup_printf ("%s (%u retries)", */
|
||||||
|
/* unlock_required, */
|
||||||
|
/* unlock_retries) : */
|
||||||
|
/* g_strdup ("not required")); */
|
||||||
|
|
||||||
static void
|
/* /\* Rework possible multiline strings *\/ */
|
||||||
get_info_process_reply (gboolean result,
|
/* prefixed_revision = prefix_newlines (" | ", */
|
||||||
const GError *error,
|
/* revision); */
|
||||||
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) {
|
/* g_print ("\n" */
|
||||||
g_printerr ("couldn't get info from modem: '%s'\n",
|
/* "%s\n" */
|
||||||
error ? error->message : "unknown error");
|
/* " -------------------------\n" */
|
||||||
exit (EXIT_FAILURE);
|
/* " Hardware | manufacturer: '%s'\n" */
|
||||||
}
|
/* " | model: '%s'\n" */
|
||||||
|
/* " | 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)); */
|
||||||
|
|
||||||
/* Get additional info from properties */
|
/* g_free (prefixed_revision); */
|
||||||
master_device = mm_modem_get_master_device (ctxt.modem);
|
/* g_free (master_device); */
|
||||||
device = mm_modem_get_device (ctxt.modem);
|
/* g_free (device); */
|
||||||
device_id = mm_modem_get_device_identifier (ctxt.modem);
|
/* g_free (device_id); */
|
||||||
equipment_id = mm_modem_get_equipment_identifier (ctxt.modem);
|
/* g_free (equipment_id); */
|
||||||
driver = mm_modem_get_driver (ctxt.modem);
|
/* g_free (driver); */
|
||||||
plugin = mm_modem_get_plugin (ctxt.modem);
|
/* g_free (plugin); */
|
||||||
type = mm_modem_get_modem_type (ctxt.modem);
|
/* g_free (unlock_required); */
|
||||||
enabled = mm_modem_get_enabled (ctxt.modem);
|
/* g_free (unlock); */
|
||||||
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 */
|
/* static void */
|
||||||
unlock = (unlock_required ?
|
/* get_info_ready (MMModem *modem, */
|
||||||
g_strdup_printf ("%s (%u retries)",
|
/* GAsyncResult *result, */
|
||||||
unlock_required,
|
/* gpointer nothing) */
|
||||||
unlock_retries) :
|
/* { */
|
||||||
g_strdup ("not required"));
|
/* gboolean operation_result; */
|
||||||
|
/* gchar *manufacturer = NULL; */
|
||||||
|
/* gchar *model = NULL; */
|
||||||
|
/* gchar *revision = NULL; */
|
||||||
|
/* GError *error = NULL; */
|
||||||
|
|
||||||
/* Rework possible multiline strings */
|
/* operation_result = mm_modem_get_info_finish (modem, */
|
||||||
prefixed_revision = prefix_newlines (" | ",
|
/* result, */
|
||||||
revision);
|
/* &manufacturer, */
|
||||||
|
/* &model, */
|
||||||
|
/* &revision, */
|
||||||
|
/* &error); */
|
||||||
|
/* get_info_process_reply (operation_result, */
|
||||||
|
/* error, */
|
||||||
|
/* manufacturer, */
|
||||||
|
/* model, */
|
||||||
|
/* revision); */
|
||||||
|
|
||||||
g_print ("\n"
|
/* g_free (manufacturer); */
|
||||||
"%s\n"
|
/* g_free (model); */
|
||||||
" -------------------------\n"
|
/* g_free (revision); */
|
||||||
" Hardware | manufacturer: '%s'\n"
|
|
||||||
" | model: '%s'\n"
|
|
||||||
" | 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);
|
/* mmcli_async_operation_done (); */
|
||||||
g_free (master_device);
|
/* } */
|
||||||
g_free (device);
|
|
||||||
g_free (device_id);
|
|
||||||
g_free (equipment_id);
|
|
||||||
g_free (driver);
|
|
||||||
g_free (plugin);
|
|
||||||
g_free (unlock_required);
|
|
||||||
g_free (unlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
get_info_ready (MMModem *modem,
|
|
||||||
GAsyncResult *result,
|
|
||||||
gpointer nothing)
|
|
||||||
{
|
|
||||||
gboolean operation_result;
|
|
||||||
gchar *manufacturer = NULL;
|
|
||||||
gchar *model = NULL;
|
|
||||||
gchar *revision = NULL;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
operation_result = mm_modem_get_info_finish (modem,
|
|
||||||
result,
|
|
||||||
&manufacturer,
|
|
||||||
&model,
|
|
||||||
&revision,
|
|
||||||
&error);
|
|
||||||
get_info_process_reply (operation_result,
|
|
||||||
error,
|
|
||||||
manufacturer,
|
|
||||||
model,
|
|
||||||
revision);
|
|
||||||
|
|
||||||
g_free (manufacturer);
|
|
||||||
g_free (model);
|
|
||||||
g_free (revision);
|
|
||||||
|
|
||||||
mmcli_async_operation_done ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable_process_reply (gboolean result,
|
enable_process_reply (gboolean result,
|
||||||
@@ -520,90 +465,109 @@ factory_reset_ready (MMModem *modem,
|
|||||||
mmcli_async_operation_done ();
|
mmcli_async_operation_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static void */
|
||||||
|
/* state_changed (MMModem *modem, */
|
||||||
|
/* MMModemState old_state, */
|
||||||
|
/* MMModemState new_state, */
|
||||||
|
/* MMModemStateReason reason) */
|
||||||
|
/* { */
|
||||||
|
/* g_print ("State changed: '%s' --> '%s' (Reason: %s)\n", */
|
||||||
|
/* get_state_string (old_state), */
|
||||||
|
/* get_state_string (new_state), */
|
||||||
|
/* get_state_reason_string (reason)); */
|
||||||
|
/* fflush (stdout); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
state_changed (MMModem *modem,
|
get_modem_ready (GObject *source,
|
||||||
MMModemState old_state,
|
GAsyncResult *result,
|
||||||
MMModemState new_state,
|
gpointer none)
|
||||||
MMModemStateReason reason)
|
|
||||||
{
|
{
|
||||||
g_print ("State changed: '%s' --> '%s' (Reason: %s)\n",
|
ctx->modem = mmcli_get_modem_finish (result);
|
||||||
get_state_string (old_state),
|
|
||||||
get_state_string (new_state),
|
/* Request to get info from modem? */
|
||||||
get_state_reason_string (reason));
|
if (info_flag) {
|
||||||
fflush (stdout);
|
/* TODO */
|
||||||
|
|
||||||
|
/* mm_modem_get_info_async (ctxt.modem, */
|
||||||
|
/* cancellable, */
|
||||||
|
/* (GAsyncReadyCallback)get_info_ready, */
|
||||||
|
/* NULL); */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request to monitor modems? */
|
||||||
|
if (monitor_state_flag) {
|
||||||
|
/* TODO */
|
||||||
|
|
||||||
|
/* MMModemState current; */
|
||||||
|
|
||||||
|
/* g_signal_connect (ctxt.modem, */
|
||||||
|
/* "state-changed", */
|
||||||
|
/* G_CALLBACK (state_changed), */
|
||||||
|
/* NULL); */
|
||||||
|
|
||||||
|
/* current = mm_modem_get_state (ctxt.modem); */
|
||||||
|
/* g_print ("Initial state: '%s'\n", get_state_string (current)); */
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request to enable the modem? */
|
||||||
|
if (enable_flag) {
|
||||||
|
mm_modem_enable (ctx->modem,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)enable_ready,
|
||||||
|
NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request to disable the modem? */
|
||||||
|
if (disable_flag) {
|
||||||
|
mm_modem_disable (ctx->modem,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)disable_ready,
|
||||||
|
NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request to reset the modem? */
|
||||||
|
if (reset_flag) {
|
||||||
|
mm_modem_reset (ctx->modem,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)reset_ready,
|
||||||
|
NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request to reset the modem to factory state? */
|
||||||
|
if (factory_reset_str) {
|
||||||
|
mm_modem_factory_reset (ctx->modem,
|
||||||
|
factory_reset_str,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)factory_reset_ready,
|
||||||
|
NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
/* Initialize context */
|
/* Initialize context */
|
||||||
init (connection);
|
ctx = g_new0 (Context, 1);
|
||||||
|
if (cancellable)
|
||||||
|
ctx->cancellable = g_object_ref (cancellable);
|
||||||
|
|
||||||
/* Request to get info from modem? */
|
/* Get proper modem */
|
||||||
if (ctxt.info_flag) {
|
mmcli_get_modem (connection,
|
||||||
mm_modem_get_info_async (ctxt.modem,
|
modem_str,
|
||||||
cancellable,
|
cancellable,
|
||||||
(GAsyncReadyCallback)get_info_ready,
|
(GAsyncReadyCallback)get_modem_ready,
|
||||||
NULL);
|
NULL);
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request to monitor modems? */
|
|
||||||
if (ctxt.monitor_state_flag) {
|
|
||||||
MMModemState current;
|
|
||||||
|
|
||||||
g_signal_connect (ctxt.modem,
|
|
||||||
"state-changed",
|
|
||||||
G_CALLBACK (state_changed),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
current = mm_modem_get_state (ctxt.modem);
|
|
||||||
g_print ("Initial state: '%s'\n", get_state_string (current));
|
|
||||||
|
|
||||||
/* We need to keep the loop */
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request to enable the modem? */
|
|
||||||
if (ctxt.enable_flag) {
|
|
||||||
mm_modem_enable_async (ctxt.modem,
|
|
||||||
cancellable,
|
|
||||||
(GAsyncReadyCallback)enable_ready,
|
|
||||||
NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request to disable the modem? */
|
|
||||||
if (ctxt.disable_flag) {
|
|
||||||
mm_modem_disable_async (ctxt.modem,
|
|
||||||
cancellable,
|
|
||||||
(GAsyncReadyCallback)disable_ready,
|
|
||||||
NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request to reset the modem? */
|
|
||||||
if (ctxt.reset_flag) {
|
|
||||||
mm_modem_reset_async (ctxt.modem,
|
|
||||||
cancellable,
|
|
||||||
(GAsyncReadyCallback)reset_ready,
|
|
||||||
NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Request to reset the modem to factory state? */
|
|
||||||
if (ctxt.factory_reset_str) {
|
|
||||||
mm_modem_factory_reset_async (ctxt.modem,
|
|
||||||
ctxt.factory_reset_str,
|
|
||||||
cancellable,
|
|
||||||
(GAsyncReadyCallback)factory_reset_ready,
|
|
||||||
NULL);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_warn_if_reached ();
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -611,70 +575,74 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (ctxt.monitor_state_flag) {
|
if (monitor_state_flag) {
|
||||||
g_printerr ("error: monitoring state cannot be done synchronously\n");
|
g_printerr ("error: monitoring state cannot be done synchronously\n");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize context */
|
ctx->modem = mmcli_get_modem_sync (connection, modem_str);
|
||||||
init (connection);
|
|
||||||
|
|
||||||
/* Request to get info from modem? */
|
/* Request to get info from modem? */
|
||||||
if (ctxt.info_flag) {
|
if (info_flag) {
|
||||||
gboolean result;
|
/* TODO */
|
||||||
gchar *manufacturer = NULL;
|
|
||||||
gchar *model = NULL;
|
|
||||||
gchar *revision = NULL;
|
|
||||||
|
|
||||||
result = mm_modem_get_info (ctxt.modem,
|
/* gboolean result; */
|
||||||
&manufacturer,
|
/* gchar *manufacturer = NULL; */
|
||||||
&model,
|
/* gchar *model = NULL; */
|
||||||
&revision,
|
/* gchar *revision = NULL; */
|
||||||
&error);
|
|
||||||
get_info_process_reply (result,
|
|
||||||
error,
|
|
||||||
manufacturer,
|
|
||||||
model,
|
|
||||||
revision);
|
|
||||||
|
|
||||||
g_free (manufacturer);
|
/* result = mm_modem_get_info (ctxt.modem, */
|
||||||
g_free (model);
|
/* &manufacturer, */
|
||||||
g_free (revision);
|
/* &model, */
|
||||||
|
/* &revision, */
|
||||||
|
/* &error); */
|
||||||
|
/* get_info_process_reply (result, */
|
||||||
|
/* error, */
|
||||||
|
/* manufacturer, */
|
||||||
|
/* model, */
|
||||||
|
/* revision); */
|
||||||
|
|
||||||
|
/* g_free (manufacturer); */
|
||||||
|
/* g_free (model); */
|
||||||
|
/* g_free (revision); */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request to enable the modem? */
|
/* Request to enable the modem? */
|
||||||
if (ctxt.enable_flag) {
|
if (enable_flag) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
result = mm_modem_enable (ctxt.modem, &error);
|
result = mm_modem_enable_sync (ctx->modem, NULL, &error);
|
||||||
enable_process_reply (result, error);
|
enable_process_reply (result, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request to disable the modem? */
|
/* Request to disable the modem? */
|
||||||
if (ctxt.disable_flag) {
|
if (disable_flag) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
result = mm_modem_disable (ctxt.modem, &error);
|
result = mm_modem_disable_sync (ctx->modem, NULL, &error);
|
||||||
disable_process_reply (result, error);
|
disable_process_reply (result, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request to reset the modem? */
|
/* Request to reset the modem? */
|
||||||
if (ctxt.reset_flag) {
|
if (reset_flag) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
result = mm_modem_reset (ctxt.modem, &error);
|
result = mm_modem_reset_sync (ctx->modem, NULL, &error);
|
||||||
reset_process_reply (result, error);
|
reset_process_reply (result, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request to reset the modem to factory state? */
|
/* Request to reset the modem to factory state? */
|
||||||
if (ctxt.factory_reset_str) {
|
if (factory_reset_str) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
result = mm_modem_factory_reset (ctxt.modem, ctxt.factory_reset_str, &error);
|
result = mm_modem_factory_reset_sync (ctx->modem,
|
||||||
|
factory_reset_str,
|
||||||
|
NULL,
|
||||||
|
&error);
|
||||||
factory_reset_process_reply (result, error);
|
factory_reset_process_reply (result, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -158,14 +158,11 @@ main (gint argc, gchar **argv)
|
|||||||
mmcli_manager_run_asynchronous (connection, cancellable);
|
mmcli_manager_run_asynchronous (connection, cancellable);
|
||||||
else
|
else
|
||||||
mmcli_manager_run_synchronous (connection);
|
mmcli_manager_run_synchronous (connection);
|
||||||
} else {
|
|
||||||
g_printerr ("error: no actions specified\n");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
/* Modem options? */
|
/* Modem options? */
|
||||||
else if (mmcli_modem_options_enabled ()) {
|
else if (mmcli_modem_options_enabled ()) {
|
||||||
if (async_flag)
|
if (async_flag)
|
||||||
keep_loop = mmcli_modem_run_asynchronous (connection, cancellable);
|
mmcli_modem_run_asynchronous (connection, cancellable);
|
||||||
else
|
else
|
||||||
mmcli_modem_run_synchronous (connection);
|
mmcli_modem_run_synchronous (connection);
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ void mmcli_manager_shutdown (void);
|
|||||||
/* Modem group */
|
/* Modem group */
|
||||||
GOptionGroup *mmcli_modem_get_option_group (void);
|
GOptionGroup *mmcli_modem_get_option_group (void);
|
||||||
gboolean mmcli_modem_options_enabled (void);
|
gboolean mmcli_modem_options_enabled (void);
|
||||||
gboolean mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
void mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
||||||
GCancellable *cancellable);
|
GCancellable *cancellable);
|
||||||
void mmcli_modem_run_synchronous (GDBusConnection *connection);
|
void mmcli_modem_run_synchronous (GDBusConnection *connection);
|
||||||
void mmcli_modem_shutdown (void);
|
void mmcli_modem_shutdown (void);
|
||||||
|
@@ -1304,3 +1304,4 @@ mm_modem_get_sim_sync (MMModem *self,
|
|||||||
cancellable,
|
cancellable,
|
||||||
error));
|
error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user