From ec30daa1c5fd29c7ccebdb0eb80d928e895dd654 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 13 Oct 2014 12:52:04 +0200 Subject: libqmi-glib,device: new 'device-no-file-check' property If set to TRUE, this property will make the QmiDevice not check for the existence and file type of the given GFile. This is a construct write-only property, and should be only used when building the QmiDevice with g_async_initable_new_async() explicitly (i.e. no library helper method given). --- src/libqmi-glib/qmi-device.c | 82 +++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 27 deletions(-) (limited to 'src/libqmi-glib/qmi-device.c') diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c index 8e6fa8b..ffe7e04 100644 --- a/src/libqmi-glib/qmi-device.c +++ b/src/libqmi-glib/qmi-device.c @@ -17,7 +17,8 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * Copyright (C) 2012 Aleksander Morgado + * Copyright (C) 2012 Lanedo GmbH + * Copyright (C) 2012 - 2014 Aleksander Morgado */ #include @@ -68,6 +69,7 @@ G_DEFINE_TYPE_EXTENDED (QmiDevice, qmi_device, G_TYPE_OBJECT, 0, enum { PROP_0, PROP_FILE, + PROP_NO_FILE_CHECK, PROP_LAST }; @@ -84,6 +86,7 @@ struct _QmiDevicePrivate { GFile *file; gchar *path; gchar *path_display; + gboolean no_file_check; /* Implicit CTL client */ QmiClientCtl *client_ctl; @@ -2326,32 +2329,9 @@ sync_indication_cb (QmiClientCtl *client_ctl, } static void -query_info_async_ready (GFile *file, - GAsyncResult *res, - InitContext *ctx) +client_ctl_setup (InitContext *ctx) { GError *error = NULL; - GFileInfo *info; - - info = g_file_query_info_finish (file, res, &error); - if (!info) { - g_prefix_error (&error, - "Couldn't query file info: "); - g_simple_async_result_take_error (ctx->result, error); - init_context_complete_and_free (ctx); - return; - } - - /* Our QMI device must be of SPECIAL type */ - if (g_file_info_get_file_type (info) != G_FILE_TYPE_SPECIAL) { - g_simple_async_result_set_error (ctx->result, - QMI_CORE_ERROR, - QMI_CORE_ERROR_FAILED, - "Wrong file type"); - init_context_complete_and_free (ctx); - return; - } - g_object_unref (info); /* Create the implicit CTL client */ ctx->self->priv->client_ctl = g_object_new (QMI_TYPE_CLIENT_CTL, @@ -2379,6 +2359,35 @@ query_info_async_ready (GFile *file, } static void +query_info_async_ready (GFile *file, + GAsyncResult *res, + InitContext *ctx) +{ + GError *error = NULL; + GFileInfo *info; + + info = g_file_query_info_finish (file, res, &error); + if (!info) { + g_prefix_error (&error, + "Couldn't query file info: "); + g_simple_async_result_take_error (ctx->result, error); + init_context_complete_and_free (ctx); + return; + } + + /* Our QMI device must be of SPECIAL type */ + if (g_file_info_get_file_type (info) != G_FILE_TYPE_SPECIAL) { + g_simple_async_result_set_error (ctx->result, + QMI_CORE_ERROR, + QMI_CORE_ERROR_FAILED, + "Wrong file type"); + init_context_complete_and_free (ctx); + return; + } + g_object_unref (info); +} + +static void initable_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, @@ -2406,6 +2415,12 @@ initable_init_async (GAsyncInitable *initable, return; } + /* If no file check requested, don't do it */ + if (ctx->self->priv->no_file_check) { + client_ctl_setup (ctx); + return; + } + /* Check the file type. Note that this is just a quick check to avoid * creating QmiDevices pointing to a location already known not to be a QMI * device. */ @@ -2432,8 +2447,13 @@ set_property (GObject *object, case PROP_FILE: g_assert (self->priv->file == NULL); self->priv->file = g_value_dup_object (value); - self->priv->path = g_file_get_path (self->priv->file); - self->priv->path_display = g_filename_display_name (self->priv->path); + if (self->priv->file) { + self->priv->path = g_file_get_path (self->priv->file); + self->priv->path_display = g_filename_display_name (self->priv->path); + } + break; + case PROP_NO_FILE_CHECK: + self->priv->no_file_check = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2581,6 +2601,14 @@ 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_NO_FILE_CHECK] = + g_param_spec_boolean (QMI_DEVICE_NO_FILE_CHECK, + "No file check", + "Don't check for file existence when creating the Qmi device.", + FALSE, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (object_class, PROP_NO_FILE_CHECK, properties[PROP_NO_FILE_CHECK]); + /** * QmiClientDms::event-report: * @object: A #QmiClientDms. -- cgit v1.1