diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-05-10 18:24:10 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 16:08:51 +0200 |
commit | 82f6a856f4c7fc6f19ec453d968a322a369ee6ff (patch) | |
tree | 382a0e0ae0868d4ec3e1f3a98b5c85ec4f2a1c3c /cli/qmicli-dms.c | |
parent | 4e2cfbf5eadde8ef7e31f27025988573d7a8a0cb (diff) | |
download | external_libqmi-82f6a856f4c7fc6f19ec453d968a322a369ee6ff.zip external_libqmi-82f6a856f4c7fc6f19ec453d968a322a369ee6ff.tar.gz external_libqmi-82f6a856f4c7fc6f19ec453d968a322a369ee6ff.tar.bz2 |
cli: allocate/release client logic common to all services
Moved the logic to allocate and release clients to part of the initialization,
along with the QmiDevice creation, so that all service-specific implementations
share it.
Diffstat (limited to 'cli/qmicli-dms.c')
-rw-r--r-- | cli/qmicli-dms.c | 65 |
1 files changed, 11 insertions, 54 deletions
diff --git a/cli/qmicli-dms.c b/cli/qmicli-dms.c index 9586a1e..391a77a 100644 --- a/cli/qmicli-dms.c +++ b/cli/qmicli-dms.c @@ -102,36 +102,14 @@ context_free (Context *ctx) } static void -release_client_ready (QmiDevice *device, - GAsyncResult *res) +shutdown (void) { - GError *error = NULL; - - if (!qmi_device_release_client_finish (device, res, &error)) { - g_printerr ("error: couldn't release client: %s", error->message); - exit (EXIT_FAILURE); - } - - g_debug ("Client released"); - /* Cleanup context and finish async operation */ context_free (ctx); qmicli_async_operation_done (); } static void -shutdown (void) -{ - qmi_device_release_client (ctx->device, - QMI_CLIENT (ctx->client), - QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID, - 10, - NULL, - (GAsyncReadyCallback)release_client_ready, - NULL); -} - -static void get_ids_ready (QmiClientDms *client, GAsyncResult *res) { @@ -166,18 +144,17 @@ get_ids_ready (QmiClientDms *client, shutdown (); } -static void -allocate_client_ready (QmiDevice *device, - GAsyncResult *res) +void +qmicli_dms_run (QmiDevice *device, + QmiClientDms *client, + GCancellable *cancellable) { - GError *error = NULL; - - ctx->client = (QmiClientDms *)qmi_device_allocate_client_finish (device, res, &error); - if (!ctx->client) { - g_printerr ("error: couldn't create DMS client: %s\n", - error->message); - exit (EXIT_FAILURE); - } + /* Initialize context */ + ctx = g_slice_new (Context); + ctx->device = g_object_ref (device); + ctx->client = g_object_ref (client); + if (cancellable) + ctx->cancellable = g_object_ref (cancellable); /* Request to get IDs? */ if (get_ids_flag) { @@ -192,23 +169,3 @@ allocate_client_ready (QmiDevice *device, g_warn_if_reached (); } - -void -qmicli_dms_run (QmiDevice *device, - GCancellable *cancellable) -{ - /* Initialize context */ - ctx = g_slice_new (Context); - ctx->device = g_object_ref (device); - if (cancellable) - ctx->cancellable = g_object_ref (cancellable); - - /* Create a new DMS client */ - qmi_device_allocate_client (device, - QMI_SERVICE_DMS, - QMI_CID_NONE, - 10, - cancellable, - (GAsyncReadyCallback)allocate_client_ready, - NULL); -} |