diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-05 09:16:20 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-05 09:25:56 +0200 |
commit | 52a340b1fdf48b64b40c4e3e1b7b2e340b9a6e44 (patch) | |
tree | a89bcde9c240e977f7ab61abe5b2493be1e7d60f | |
parent | 1d9636c1e7b0d08b5363daa96550e327f7a3f109 (diff) |
libqmi-glib,device: provide support for setting instance ID when opening
The instance ID value is given when the `QmiDevice' gets created, and set in the
remote device optionally when the device gets opened. A new flag is provided to
decide whether the "Set Instance ID" message needs to be sent:
QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID
-rw-r--r-- | cli/qmicli.c | 1 | ||||
-rw-r--r-- | libqmi-glib/qmi-device.c | 99 | ||||
-rw-r--r-- | libqmi-glib/qmi-device.h | 23 |
3 files changed, 114 insertions, 9 deletions
diff --git a/cli/qmicli.c b/cli/qmicli.c index d24dabe..a78c528 100644 --- a/cli/qmicli.c +++ b/cli/qmicli.c @@ -389,6 +389,7 @@ int main (int argc, char **argv) /* Launch QmiDevice creation */ qmi_device_new (file, + QMI_DEVICE_INSTANCE_ID_DEFAULT, cancellable, (GAsyncReadyCallback)device_new_ready, GUINT_TO_POINTER (service)); diff --git a/libqmi-glib/qmi-device.c b/libqmi-glib/qmi-device.c index 170795d..c16087e 100644 --- a/libqmi-glib/qmi-device.c +++ b/libqmi-glib/qmi-device.c @@ -44,6 +44,7 @@ G_DEFINE_TYPE_EXTENDED (QmiDevice, qmi_device, G_TYPE_OBJECT, 0, enum { PROP_0, PROP_FILE, + PROP_INSTANCE_ID, PROP_CLIENT_CTL, PROP_LAST }; @@ -56,6 +57,9 @@ struct _QmiDevicePrivate { gchar *path; gchar *path_display; + /* Instance ID */ + guint instance_id; + /* Implicit CTL client */ QmiClientCtl *client_ctl; @@ -319,6 +323,22 @@ qmi_device_get_path_display (QmiDevice *self) } /** + * qmi_device_get_instance_id: + * @self: a #QmiDevice. + * + * Get the instance ID of this #QmiDevice. + * + * Returns: the instance ID. + */ +guint8 +qmi_device_get_instance_id (QmiDevice *self) +{ + g_return_val_if_fail (QMI_IS_DEVICE (self), QMI_DEVICE_INSTANCE_ID_DEFAULT); + + return (guint8)self->priv->instance_id; +} + +/** * qmi_device_is_open: * @self: a #QmiDevice. * @@ -1222,6 +1242,41 @@ version_info_ready (QmiClientCtl *client_ctl, } static void +instance_id_ready (QmiClientCtl *client_ctl, + GAsyncResult *res, + DeviceOpenContext *ctx) +{ + QmiMessageCtlSetInstanceIdOutput *output; + GError *error = NULL; + guint16 link_id; + + /* Check result of the async operation */ + output = qmi_client_ctl_set_instance_id_finish (client_ctl, res, &error); + if (!output) { + g_simple_async_result_take_error (ctx->result, error); + device_open_context_complete_and_free (ctx); + return; + } + + /* Check result of the QMI operation */ + if (!qmi_message_ctl_set_instance_id_output_get_result (output, &error)) { + g_simple_async_result_take_error (ctx->result, error); + device_open_context_complete_and_free (ctx); + qmi_message_ctl_set_instance_id_output_unref (output); + return; + } + + qmi_message_ctl_set_instance_id_output_get_link_id (output, &link_id, NULL); + g_debug ("[%s] Instance ID set in device, link ID: '%" G_GUINT16_FORMAT "'", + ctx->self->priv->path_display, + link_id); + + /* Keep on with next flags */ + process_open_flags (ctx); + qmi_message_ctl_set_instance_id_output_unref (output); +} + +static void process_open_flags (DeviceOpenContext *ctx) { /* Query version info? */ @@ -1239,6 +1294,29 @@ process_open_flags (DeviceOpenContext *ctx) return; } + /* Set instance ID? */ + if (ctx->flags & QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID) { + QmiMessageCtlSetInstanceIdInput *input; + + ctx->flags &= ~QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID; + + /* Notify device about our instance ID */ + g_debug ("Setting instance ID (%u)...", ctx->self->priv->instance_id); + input = qmi_message_ctl_set_instance_id_input_new (); + qmi_message_ctl_set_instance_id_input_set_id ( + input, + (guint8)ctx->self->priv->instance_id, + NULL); + qmi_client_ctl_set_instance_id (ctx->self->priv->client_ctl, + input, + 1, + ctx->cancellable, + (GAsyncReadyCallback)instance_id_ready, + ctx); + qmi_message_ctl_set_instance_id_input_unref (input); + return; + } + /* Sync? */ if (ctx->flags & QMI_DEVICE_OPEN_FLAGS_SYNC) { g_debug ("Running sync..."); @@ -1516,6 +1594,7 @@ qmi_device_new_finish (GAsyncResult *res, /** * qmi_device_new: * @file: a #GFile. + * @instance_id: the instance ID of this #QmiDevice, or #QMI_DEVICE_INSTANCE_ID_DEFAULT. * @cancellable: optional #GCancellable object, #NULL to ignore. * @callback: a #GAsyncReadyCallback to call when the initialization is finished. * @user_data: the data to pass to callback function. @@ -1526,6 +1605,7 @@ qmi_device_new_finish (GAsyncResult *res, */ void qmi_device_new (GFile *file, + guint8 instance_id, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -1535,7 +1615,8 @@ qmi_device_new (GFile *file, cancellable, callback, user_data, - QMI_DEVICE_FILE, file, + QMI_DEVICE_FILE, file, + QMI_DEVICE_INSTANCE_ID, (guint)instance_id, NULL); } @@ -1670,6 +1751,9 @@ set_property (GObject *object, self->priv->path = g_file_get_path (self->priv->file); self->priv->path_display = g_filename_display_name (self->priv->path); break; + case PROP_INSTANCE_ID: + self->priv->instance_id = g_value_get_uint (value); + break; case PROP_CLIENT_CTL: /* Not writable */ g_assert_not_reached (); @@ -1692,6 +1776,9 @@ get_property (GObject *object, case PROP_FILE: g_value_set_object (value, self->priv->file); break; + case PROP_INSTANCE_ID: + g_value_set_uint (value, self->priv->instance_id); + break; case PROP_CLIENT_CTL: g_value_set_object (value, self->priv->client_ctl); break; @@ -1802,6 +1889,16 @@ qmi_device_class_init (QmiDeviceClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_FILE, properties[PROP_FILE]); + properties[PROP_INSTANCE_ID] = + g_param_spec_uint (QMI_DEVICE_INSTANCE_ID, + "Instance ID", + "Instance ID of this QMI device", + 0, + G_MAXUINT8, + QMI_DEVICE_INSTANCE_ID_DEFAULT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_INSTANCE_ID, properties[PROP_INSTANCE_ID]); + properties[PROP_CLIENT_CTL] = g_param_spec_object (QMI_DEVICE_CLIENT_CTL, "CTL client", diff --git a/libqmi-glib/qmi-device.h b/libqmi-glib/qmi-device.h index 79272d8..5c66df2 100644 --- a/libqmi-glib/qmi-device.h +++ b/libqmi-glib/qmi-device.h @@ -31,6 +31,8 @@ G_BEGIN_DECLS +#define QMI_DEVICE_INSTANCE_ID_DEFAULT 0 + #define QMI_TYPE_DEVICE (qmi_device_get_type ()) #define QMI_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QMI_TYPE_DEVICE, QmiDevice)) #define QMI_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QMI_TYPE_DEVICE, QmiDeviceClass)) @@ -42,8 +44,9 @@ typedef struct _QmiDevice QmiDevice; typedef struct _QmiDeviceClass QmiDeviceClass; typedef struct _QmiDevicePrivate QmiDevicePrivate; -#define QMI_DEVICE_FILE "device-file" -#define QMI_DEVICE_CLIENT_CTL "device-client-ctl" +#define QMI_DEVICE_FILE "device-file" +#define QMI_DEVICE_INSTANCE_ID "device-instance-id" +#define QMI_DEVICE_CLIENT_CTL "device-client-ctl" struct _QmiDevice { GObject parent; @@ -56,10 +59,11 @@ struct _QmiDeviceClass { GType qmi_device_get_type (void); -void qmi_device_new (GFile *file, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +void qmi_device_new (GFile *file, + guint8 instance_id, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); QmiDevice *qmi_device_new_finish (GAsyncResult *res, GError **error); @@ -67,11 +71,13 @@ GFile *qmi_device_get_file (QmiDevice *self); GFile *qmi_device_peek_file (QmiDevice *self); const gchar *qmi_device_get_path (QmiDevice *self); const gchar *qmi_device_get_path_display (QmiDevice *self); +guint8 qmi_device_get_instance_id (QmiDevice *self); gboolean qmi_device_is_open (QmiDevice *self); /** * QmiDeviceOpenFlags: * @QMI_DEVICE_OPEN_FLAGS_NONE: No flags. + * @QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID: Set the instance ID of the control point just after opening the device. * @QMI_DEVICE_OPEN_FLAGS_VERSION_INFO: Run version info check when opening. * @QMI_DEVICE_OPEN_FLAGS_SYNC: Synchronize with endpoint once the device is open. Will release any previously allocated client ID. * @@ -79,8 +85,9 @@ gboolean qmi_device_is_open (QmiDevice *self); */ typedef enum { QMI_DEVICE_OPEN_FLAGS_NONE = 0, - QMI_DEVICE_OPEN_FLAGS_VERSION_INFO = 1 << 0, - QMI_DEVICE_OPEN_FLAGS_SYNC = 1 << 1 + QMI_DEVICE_OPEN_FLAGS_INSTANCE_ID = 1 << 0, + QMI_DEVICE_OPEN_FLAGS_VERSION_INFO = 1 << 1, + QMI_DEVICE_OPEN_FLAGS_SYNC = 1 << 2 } QmiDeviceOpenFlags; void qmi_device_open (QmiDevice *self, |