summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-05 09:18:55 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-05 09:27:03 +0200
commitb9ef5504c784e6aa9162067b598109d597eb49cc (patch)
tree04f2ae852c7a5851da2466a35fd5a24ffb117b14
parent52a340b1fdf48b64b40c4e3e1b7b2e340b9a6e44 (diff)
cli: new `--device-open-instance-id' optional switchinstance-id
This new switch allows user to decide whether the instance ID needs to be explicitly set when the `QmiDevice' gets opened. This new option requires a string containing the instance ID to be set, e.g.: $ sudo qmicli --dms-get-manufacturer \ -d /dev/cdc-wdm0 \ --device-open-instance-id=5
-rw-r--r--cli/qmicli.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/qmicli.c b/cli/qmicli.c
index a78c528..60cdab3 100644
--- a/cli/qmicli.c
+++ b/cli/qmicli.c
@@ -46,6 +46,7 @@ static gboolean operation_status;
/* Main options */
static gchar *device_str;
+static gchar *device_open_instance_id_str;
static gboolean device_open_version_info_flag;
static gboolean device_open_sync_flag;
static gchar *client_cid_str;
@@ -59,6 +60,10 @@ static GOptionEntry main_entries[] = {
"Specify device path",
"[PATH]"
},
+ { "device-open-instance-id", 0, 0, G_OPTION_ARG_STRING, &device_open_instance_id_str,
+ "Set instance ID when opening device",
+ "[Instance ID]"
+ },
{ "device-open-version-info", 0, 0, G_OPTION_ARG_NONE, &device_open_version_info_flag,
"Run version info check when opening device",
NULL
@@ -310,6 +315,8 @@ device_new_ready (GObject *unused,
}
/* Setup device open flags */
+ if (device_open_instance_id_str)
+ open_flags |= QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID;
if (device_open_version_info_flag)
open_flags |= QMI_DEVICE_OPEN_FLAGS_VERSION_INFO;
if (device_open_sync_flag)
@@ -330,6 +337,7 @@ int main (int argc, char **argv)
{
GError *error = NULL;
GFile *file;
+ gint instance_id;
GOptionContext *context;
setlocale (LC_ALL, "");
@@ -364,6 +372,25 @@ int main (int argc, char **argv)
/* Build new GFile from the commandline arg */
file = g_file_new_for_commandline_arg (device_str);
+ /* Instance ID given? */
+ if (device_open_instance_id_str) {
+ if (g_str_equal (device_open_instance_id_str, "0"))
+ instance_id = 0;
+ else {
+ instance_id = atoi (device_open_instance_id_str);
+ if (instance_id == 0) {
+ g_printerr ("error: invalid instance ID given: '%s'\n", device_open_instance_id_str);
+ exit (EXIT_FAILURE);
+ } else if (instance_id < 0 || instance_id > G_MAXUINT8) {
+ g_printerr ("error: given instance ID is out of range [0,%u]: '%s'\n",
+ G_MAXUINT8,
+ device_open_instance_id_str);
+ exit (EXIT_FAILURE);
+ }
+ }
+ } else
+ instance_id = QMI_DEVICE_INSTANCE_ID_DEFAULT;
+
/* Setup signals */
signal (SIGINT, signals_handler);
signal (SIGHUP, signals_handler);
@@ -389,7 +416,7 @@ int main (int argc, char **argv)
/* Launch QmiDevice creation */
qmi_device_new (file,
- QMI_DEVICE_INSTANCE_ID_DEFAULT,
+ (guint8)instance_id,
cancellable,
(GAsyncReadyCallback)device_new_ready,
GUINT_TO_POINTER (service));