diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2014-02-06 12:15:32 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-09-05 11:30:24 +0200 |
commit | d20f3e5d6002cb64d5e0f55fc1085b889da75c3f (patch) | |
tree | dd81a189ebaf394ee42269bf02c6297e791db5d2 | |
parent | 72f4aa75d79b22cdcfec4612d7ab9916c4660181 (diff) |
iface-modem-location: handle setting SUPL server
-rw-r--r-- | src/mm-iface-modem-location.c | 116 | ||||
-rw-r--r-- | src/mm-iface-modem-location.h | 9 |
2 files changed, 125 insertions, 0 deletions
diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index d67c4270..898de337 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -915,6 +915,118 @@ typedef struct { MmGdbusModemLocation *skeleton; GDBusMethodInvocation *invocation; MMIfaceModemLocation *self; + gchar *supl; +} HandleSetSuplServerContext; + +static void +handle_set_supl_server_context_free (HandleSetSuplServerContext *ctx) +{ + g_object_unref (ctx->skeleton); + g_object_unref (ctx->invocation); + g_object_unref (ctx->self); + g_free (ctx->supl); + g_slice_free (HandleSetSuplServerContext, ctx); +} + +static void +set_supl_server_ready (MMIfaceModemLocation *self, + GAsyncResult *res, + HandleSetSuplServerContext *ctx) +{ + GError *error = NULL; + + if (!MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->set_supl_server_finish (self, res, &error)) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_modem_location_complete_set_supl_server (ctx->skeleton, ctx->invocation); + + handle_set_supl_server_context_free (ctx); +} + +static void +handle_set_supl_server_auth_ready (MMBaseModem *self, + GAsyncResult *res, + HandleSetSuplServerContext *ctx) +{ + GError *error = NULL; + MMModemState modem_state; + + if (!mm_base_modem_authorize_finish (self, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_set_supl_server_context_free (ctx); + return; + } + + modem_state = MM_MODEM_STATE_UNKNOWN; + g_object_get (self, + MM_IFACE_MODEM_STATE, &modem_state, + NULL); + if (modem_state < MM_MODEM_STATE_ENABLED) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_WRONG_STATE, + "Cannot set SUPL server: " + "device not yet enabled"); + handle_set_supl_server_context_free (ctx); + return; + } + + /* If A-GPS is NOT supported, set error */ + if (!(mm_gdbus_modem_location_get_capabilities (ctx->skeleton) & MM_MODEM_LOCATION_SOURCE_AGPS)) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Cannot set SUPL server: A-GPS not supported"); + handle_set_supl_server_context_free (ctx); + return; + } + + /* Check if plugin implements it */ + if (!MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->set_supl_server || + !MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->set_supl_server_finish) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Cannot set SUPL server: not implemented"); + handle_set_supl_server_context_free (ctx); + return; + } + + /* Request to change SUPL server */ + MM_IFACE_MODEM_LOCATION_GET_INTERFACE (self)->set_supl_server (ctx->self, + ctx->supl, + (GAsyncReadyCallback)set_supl_server_ready, + ctx); +} + +static gboolean +handle_set_supl_server (MmGdbusModemLocation *skeleton, + GDBusMethodInvocation *invocation, + const gchar *supl, + MMIfaceModemLocation *self) +{ + HandleSetSuplServerContext *ctx; + + ctx = g_slice_new (HandleSetSuplServerContext); + ctx->skeleton = g_object_ref (skeleton); + ctx->invocation = g_object_ref (invocation); + ctx->self = g_object_ref (self); + ctx->supl = g_strdup (supl); + + mm_base_modem_authorize (MM_BASE_MODEM (self), + invocation, + MM_AUTHORIZATION_DEVICE_CONTROL, + (GAsyncReadyCallback)handle_set_supl_server_auth_ready, + ctx); + return TRUE; +} + +/*****************************************************************************/ + +typedef struct { + MmGdbusModemLocation *skeleton; + GDBusMethodInvocation *invocation; + MMIfaceModemLocation *self; } HandleGetLocationContext; static void @@ -1355,6 +1467,10 @@ interface_initialization_step (InitializationContext *ctx) G_CALLBACK (handle_setup), ctx->self); g_signal_connect (ctx->skeleton, + "handle-set-supl-server", + G_CALLBACK (handle_set_supl_server), + ctx->self); + g_signal_connect (ctx->skeleton, "handle-get-location", G_CALLBACK (handle_get_location), ctx->self); diff --git a/src/mm-iface-modem-location.h b/src/mm-iface-modem-location.h index 1508efa6..fde00ced 100644 --- a/src/mm-iface-modem-location.h +++ b/src/mm-iface-modem-location.h @@ -59,6 +59,15 @@ struct _MMIfaceModemLocation { gboolean (*disable_location_gathering_finish) (MMIfaceModemLocation *self, GAsyncResult *res, GError **error); + + /* Set SUPL server (async) */ + void (* set_supl_server) (MMIfaceModemLocation *self, + const gchar *supl, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*set_supl_server_finish) (MMIfaceModemLocation *self, + GAsyncResult *res, + GError **error); }; GType mm_iface_modem_location_get_type (void); |