cli: add command to monitor modem additions and removals
This commit is contained in:
66
cli/main.c
66
cli/main.c
@@ -42,6 +42,7 @@ static GCancellable *cancellable;
|
|||||||
static gboolean version_flag;
|
static gboolean version_flag;
|
||||||
static gboolean async_flag;
|
static gboolean async_flag;
|
||||||
static gboolean list_modems_flag;
|
static gboolean list_modems_flag;
|
||||||
|
static gboolean monitor_modems_flag;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
|
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
|
||||||
@@ -56,6 +57,10 @@ static GOptionEntry entries[] = {
|
|||||||
"List available modems",
|
"List available modems",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
{ "monitor-modems", 'm', 0, G_OPTION_ARG_NONE, &monitor_modems_flag,
|
||||||
|
"List available modems and monitor additions and removals",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,6 +143,26 @@ enumerate_devices_ready (MMManager *manager,
|
|||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
device_added (MMManager *manager,
|
||||||
|
const gchar *path)
|
||||||
|
{
|
||||||
|
g_print ("%s: '%s'\n",
|
||||||
|
"Added modem",
|
||||||
|
path);
|
||||||
|
fflush (stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
device_removed (MMManager *manager,
|
||||||
|
const gchar *path)
|
||||||
|
{
|
||||||
|
g_print ("%s: '%s'\n",
|
||||||
|
"Removed modem",
|
||||||
|
path);
|
||||||
|
fflush (stdout);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
asynchronous (MMManager *manager)
|
asynchronous (MMManager *manager)
|
||||||
{
|
{
|
||||||
@@ -146,6 +171,18 @@ asynchronous (MMManager *manager)
|
|||||||
/* Setup global cancellable */
|
/* Setup global cancellable */
|
||||||
cancellable = g_cancellable_new ();
|
cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
|
/* Request to monitor modems? */
|
||||||
|
if (monitor_modems_flag) {
|
||||||
|
g_signal_connect (manager,
|
||||||
|
"device-added",
|
||||||
|
G_CALLBACK (device_added),
|
||||||
|
NULL);
|
||||||
|
g_signal_connect (manager,
|
||||||
|
"device-removed",
|
||||||
|
G_CALLBACK (device_removed),
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Request to list modems? */
|
/* Request to list modems? */
|
||||||
if (list_modems_flag) {
|
if (list_modems_flag) {
|
||||||
mm_manager_enumerate_devices_async (manager,
|
mm_manager_enumerate_devices_async (manager,
|
||||||
@@ -174,6 +211,32 @@ synchronous (MMManager *manager)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ensure_single_action (void)
|
||||||
|
{
|
||||||
|
guint n_actions;
|
||||||
|
|
||||||
|
n_actions = (list_modems_flag +
|
||||||
|
monitor_modems_flag);
|
||||||
|
|
||||||
|
if (n_actions == 0)
|
||||||
|
print_version_and_exit ();
|
||||||
|
|
||||||
|
if (n_actions > 1) {
|
||||||
|
g_printerr ("error, too many actions requested\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Additional fixes to the modem monitoring request */
|
||||||
|
if (monitor_modems_flag) {
|
||||||
|
/* Do not stop loop after listing initial modems */
|
||||||
|
keep_loop = TRUE;
|
||||||
|
/* Assume an implicit list modems request */
|
||||||
|
list_modems_flag = TRUE;
|
||||||
|
/* Monitoring always asynchronously */
|
||||||
|
async_flag = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
main (gint argc, gchar **argv)
|
main (gint argc, gchar **argv)
|
||||||
@@ -192,6 +255,9 @@ main (gint argc, gchar **argv)
|
|||||||
if (version_flag)
|
if (version_flag)
|
||||||
print_version_and_exit ();
|
print_version_and_exit ();
|
||||||
|
|
||||||
|
/* We must have exactly 1 action requested */
|
||||||
|
ensure_single_action ();
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
/* Setup signals */
|
/* Setup signals */
|
||||||
|
Reference in New Issue
Block a user