diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2014-07-28 15:11:15 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-07-31 18:42:51 +0200 |
commit | 1d27aaf21fbf342a6209cd12c6f0e8f0c74a9e17 (patch) | |
tree | ed29d15d851c4edf72e47fa55aa527dfa26aab8f | |
parent | 3b4adb2734ca07479e6284b2736be8737d6954e8 (diff) | |
download | libmbim-1d27aaf21fbf342a6209cd12c6f0e8f0c74a9e17.tar.gz |
libmbim-glib,proxy: reorder code a bit
-rw-r--r-- | src/libmbim-glib/mbim-proxy.c | 186 |
1 files changed, 99 insertions, 87 deletions
diff --git a/src/libmbim-glib/mbim-proxy.c b/src/libmbim-glib/mbim-proxy.c index 17ea7d9..507c711 100644 --- a/src/libmbim-glib/mbim-proxy.c +++ b/src/libmbim-glib/mbim-proxy.c @@ -100,6 +100,7 @@ mbim_proxy_get_n_devices (MbimProxy *self) } /*****************************************************************************/ +/* Client info */ typedef struct { MbimUuid uuid; @@ -120,17 +121,6 @@ typedef struct { MbimEventEntry **mbim_event_entry_array; } Client; -typedef struct { - MbimProxy *proxy; - Client *client; -} DeviceOpenContext; - -typedef struct { - MbimProxy *proxy; - Client *client; - MbimMessage *response; -} DeviceNewContext; - static gboolean connection_readable_cb (GSocket *socket, GIOCondition condition, Client *client); static void @@ -232,29 +222,6 @@ send_message (Client *client, } static void -complete_internal_proxy_open (Client *client) -{ - MbimMessage *response; - GError *error = NULL; - - g_debug ("connection to MBIM device '%s' established", mbim_device_get_path (client->device)); - - g_assert (client->internal_proxy_open_request != NULL); - response = mbim_message_open_done_new (mbim_message_get_transaction_id (client->internal_proxy_open_request), - MBIM_STATUS_ERROR_NONE); - - if (!send_message (client, response, &error)) { - mbim_message_unref (response); - connection_close (client); - return; - } - - mbim_message_unref (response); - mbim_message_unref (client->internal_proxy_open_request); - client->internal_proxy_open_request = NULL; -} - -static void indication_cb (MbimDevice *device, MbimMessage *message, Client *client) @@ -303,6 +270,15 @@ indication_cb (MbimDevice *device, } } + +/*****************************************************************************/ +/* Proxy open */ + +typedef struct { + MbimProxy *proxy; + Client *client; +} DeviceOpenContext; + static void proxy_device_removed_cb (MbimDevice *device, MbimProxy *self) @@ -321,7 +297,6 @@ client_device_removed_cb (MbimDevice *device, connection_close (client); } - static void client_device_connect_signals (Client *client) { @@ -336,6 +311,29 @@ client_device_connect_signals (Client *client) } static void +complete_internal_proxy_open (Client *client) +{ + MbimMessage *response; + GError *error = NULL; + + g_debug ("connection to MBIM device '%s' established", mbim_device_get_path (client->device)); + + g_assert (client->internal_proxy_open_request != NULL); + response = mbim_message_open_done_new (mbim_message_get_transaction_id (client->internal_proxy_open_request), + MBIM_STATUS_ERROR_NONE); + + if (!send_message (client, response, &error)) { + mbim_message_unref (response); + connection_close (client); + return; + } + + mbim_message_unref (response); + mbim_message_unref (client->internal_proxy_open_request); + client->internal_proxy_open_request = NULL; +} + +static void device_open_ready (MbimDevice *device, GAsyncResult *res, DeviceOpenContext *ctx) @@ -364,6 +362,69 @@ device_open_ready (MbimDevice *device, complete_internal_proxy_open (client); } +static gboolean +process_internal_proxy_open (Client *client, + MbimMessage *message) +{ + MbimProxy *self = client->proxy; + DeviceOpenContext *ctx; + + /* Keep it */ + client->internal_proxy_open_request = mbim_message_ref (message); + + if (!client->device) { + /* device should've been created in process_internal_proxy_config() */ + g_debug ("can't find device for path, send MBIM_CID_PROXY_CONTROL_CONFIGURATION first"); + complete_internal_proxy_open (client); + return FALSE; + } else if (!mbim_device_is_open (client->device)) { + /* device found but not open, open it */ + ctx = g_slice_new0 (DeviceOpenContext); + ctx->proxy = self; + ctx->client = client; + + mbim_device_open (client->device, + 30, + NULL, + (GAsyncReadyCallback)device_open_ready, + ctx); + return TRUE; + } + + complete_internal_proxy_open (client); + return FALSE; +} + +/*****************************************************************************/ +/* Proxy close */ + +static gboolean +process_internal_proxy_close (Client *client, + MbimMessage *message) +{ + MbimMessage *response; + GError *error = NULL; + + response = mbim_message_close_done_new (mbim_message_get_transaction_id (message), MBIM_STATUS_ERROR_NONE); + if (!send_message (client, response, &error)) { + mbim_message_unref (response); + connection_close (client); + return FALSE; + } + + mbim_message_unref (response); + return TRUE; +} + +/*****************************************************************************/ +/* Proxy config */ + +typedef struct { + MbimProxy *proxy; + Client *client; + MbimMessage *response; +} DeviceNewContext; + static void complete_internal_proxy_config (Client *client, MbimMessage *response) @@ -426,63 +487,12 @@ device_new_ready (GObject *source, /* Register for device indications */ client_device_connect_signals (client); - + g_slice_free (DeviceNewContext, ctx); complete_internal_proxy_config (client, response); } static gboolean -process_internal_proxy_open (Client *client, - MbimMessage *message) -{ - MbimProxy *self = client->proxy; - DeviceOpenContext *ctx; - - /* Keep it */ - client->internal_proxy_open_request = mbim_message_ref (message); - - if (!client->device) { - /* device should've been created in process_internal_proxy_config() */ - g_debug ("can't find device for path, send MBIM_CID_PROXY_CONTROL_CONFIGURATION first"); - complete_internal_proxy_open (client); - return FALSE; - } else if (!mbim_device_is_open (client->device)) { - /* device found but not open, open it */ - ctx = g_slice_new0 (DeviceOpenContext); - ctx->proxy = self; - ctx->client = client; - - mbim_device_open (client->device, - 30, - NULL, - (GAsyncReadyCallback)device_open_ready, - ctx); - return TRUE; - } - - complete_internal_proxy_open (client); - return FALSE; -} - -static gboolean -process_internal_proxy_close (Client *client, - MbimMessage *message) -{ - MbimMessage *response; - GError *error = NULL; - - response = mbim_message_close_done_new (mbim_message_get_transaction_id (message), MBIM_STATUS_ERROR_NONE); - if (!send_message (client, response, &error)) { - mbim_message_unref (response); - connection_close (client); - return FALSE; - } - - mbim_message_unref (response); - return TRUE; -} - -static gboolean process_internal_proxy_config (Client *client, MbimMessage *message) { @@ -543,6 +553,8 @@ process_internal_proxy_config (Client *client, return TRUE; } +/*****************************************************************************/ + static MbimEventEntry ** standard_service_subscribe_list_new (void) { |