bearer: make bearer creation an asynchronous operation

We may want to do some checks while creating a new bearer.
This commit is contained in:
Aleksander Morgado
2012-03-15 14:14:47 +01:00
parent 6a38bcf1a1
commit 7db16d2279
9 changed files with 230 additions and 107 deletions
+34 -9
View File
@@ -777,21 +777,42 @@ disconnect (MMBearer *self,
/*****************************************************************************/
MMBearer *
mm_bearer_3gpp_new (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error)
mm_bearer_3gpp_new_finish (MMIfaceModem3gpp *modem,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
return MM_BEARER (g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))));
}
void
mm_bearer_3gpp_new (MMIfaceModem3gpp *modem,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
static guint id = 0;
MMBearer3gpp *bearer;
gchar *path;
result = g_simple_async_result_new (G_OBJECT (modem),
callback,
user_data,
mm_bearer_3gpp_new);
/* Check mandatory properties */
if (!mm_common_bearer_properties_get_apn (properties)) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid input properties: 3GPP bearer requires 'apn'");
return NULL;
g_simple_async_result_set_error (
result,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid input properties: 3GPP bearer requires 'apn'");
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
return;
}
/* Create the object */
@@ -810,7 +831,11 @@ mm_bearer_3gpp_new (MMBaseModem *modem,
NULL);
g_free (path);
return MM_BEARER (bearer);
g_simple_async_result_set_op_res_gpointer (result,
bearer,
(GDestroyNotify)g_object_unref);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
}
static void
+8 -4
View File
@@ -22,7 +22,7 @@
#include <glib-object.h>
#include "mm-bearer.h"
#include "mm-base-modem.h"
#include "mm-iface-modem-3gpp.h"
#define MM_TYPE_BEARER_3GPP (mm_bearer_3gpp_get_type ())
#define MM_BEARER_3GPP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BEARER_3GPP, MMBearer3gpp))
@@ -54,9 +54,13 @@ struct _MMBearer3gppClass {
GType mm_bearer_3gpp_get_type (void);
/* Default 3GPP bearer creation implementation */
MMBearer *mm_bearer_3gpp_new (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error);
void mm_bearer_3gpp_new (MMIfaceModem3gpp *modem,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer *mm_bearer_3gpp_new_finish (MMIfaceModem3gpp *modem,
GAsyncResult *res,
GError **error);
const gchar *mm_bearer_3gpp_get_apn (MMBearer3gpp *self);
const gchar *mm_bearer_3gpp_get_ip_type (MMBearer3gpp *self);
+26 -4
View File
@@ -95,14 +95,32 @@ disconnect (MMBearer *self,
/*****************************************************************************/
MMBearer *
mm_bearer_cdma_new (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error)
mm_bearer_cdma_new_finish (MMIfaceModemCdma *modem,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
return MM_BEARER (g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res))));
}
void
mm_bearer_cdma_new (MMIfaceModemCdma *modem,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *result;
static guint id = 0;
MMBearerCdma *bearer;
gchar *path;
result = g_simple_async_result_new (G_OBJECT (modem),
callback,
user_data,
mm_bearer_cdma_new);
/* Create the object */
bearer = g_object_new (MM_TYPE_BEARER_CDMA,
MM_BEARER_CDMA_RM_PROTOCOL, mm_common_bearer_properties_get_rm_protocol (properties),
@@ -118,7 +136,11 @@ mm_bearer_cdma_new (MMBaseModem *modem,
NULL);
g_free (path);
return MM_BEARER (bearer);
g_simple_async_result_set_op_res_gpointer (result,
bearer,
(GDestroyNotify)g_object_unref);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
}
static void
+8 -4
View File
@@ -22,7 +22,7 @@
#include <glib-object.h>
#include "mm-bearer.h"
#include "mm-base-modem.h"
#include "mm-iface-modem-cdma.h"
#define MM_TYPE_BEARER_CDMA (mm_bearer_cdma_get_type ())
#define MM_BEARER_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BEARER_CDMA, MMBearerCdma))
@@ -52,9 +52,13 @@ struct _MMBearerCdmaClass {
GType mm_bearer_cdma_get_type (void);
/* Default CDMA bearer creation implementation */
MMBearer *mm_bearer_cdma_new (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error);
void mm_bearer_cdma_new (MMIfaceModemCdma *modem,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer *mm_bearer_cdma_new_finish (MMIfaceModemCdma *modem,
GAsyncResult *res,
GError **error);
guint mm_bearer_cdma_get_rm_protocol (MMBearerCdma *self);
+83 -50
View File
@@ -133,6 +133,44 @@ modem_create_bearer_finish (MMIfaceModem *self,
return g_object_ref (bearer);
}
static void
modem_cdma_create_bearer_ready (MMIfaceModemCdma *self,
GAsyncResult *res,
GSimpleAsyncResult *simple)
{
MMBearer *bearer = NULL;
GError *error = NULL;
bearer = mm_iface_modem_cdma_create_bearer_finish (self, res, &error);
if (!bearer)
g_simple_async_result_take_error (simple, error);
else
g_simple_async_result_set_op_res_gpointer (simple,
bearer,
(GDestroyNotify)g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
static void
modem_3gpp_create_bearer_ready (MMIfaceModem3gpp *self,
GAsyncResult *res,
GSimpleAsyncResult *simple)
{
MMBearer *bearer = NULL;
GError *error = NULL;
bearer = mm_iface_modem_3gpp_create_bearer_finish (self, res, &error);
if (!bearer)
g_simple_async_result_take_error (simple, error);
else
g_simple_async_result_set_op_res_gpointer (simple,
bearer,
(GDestroyNotify)g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
static void
modem_create_bearer (MMIfaceModem *self,
MMCommonBearerProperties *properties,
@@ -140,63 +178,56 @@ modem_create_bearer (MMIfaceModem *self,
gpointer user_data)
{
GSimpleAsyncResult *result;
MMBearer *bearer = NULL;
GError *error = NULL;
/* On 3GPP-only modems, new 3GPP bearer */
if (mm_iface_modem_is_3gpp_only (self)) {
mm_dbg ("Creating 3GPP Bearer in 3GPP-only modem");
bearer = mm_iface_modem_3gpp_create_bearer (MM_IFACE_MODEM_3GPP (self),
properties,
&error);
}
/* On CDMA-only modems, new CDMA bearer */
else if (mm_iface_modem_is_cdma_only (self)) {
mm_dbg ("Creating CDMA Bearer in CDMA-only modem");
bearer = mm_iface_modem_cdma_create_bearer (MM_IFACE_MODEM_CDMA (self),
properties,
&error);
}
/* On mixed LTE and CDMA modems, we'll default to building a 3GPP bearer.
* Plugins supporting mixed LTE+CDMA modems can override this and provide
* their own specific and detailed logic. */
else if (mm_iface_modem_is_cdma (self) &&
mm_iface_modem_is_3gpp_lte (self)) {
mm_dbg ("Creating 3GPP Bearer in mixed CDMA+LTE modem");
bearer = mm_iface_modem_3gpp_create_bearer (MM_IFACE_MODEM_3GPP (self),
properties,
&error);
}
else {
g_set_error (&error,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot create bearer in modem of unknown type. "
"CDMA: %s, 3GPP: %s (LTE: %s)",
mm_iface_modem_is_cdma (self) ? "yes" : "no",
mm_iface_modem_is_3gpp (self) ? "yes" : "no",
mm_iface_modem_is_3gpp_lte (self) ? "yes" : "no");
}
if (!bearer) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (self),
callback,
user_data,
error);
return;
}
/* Expose all properties used during creation */
mm_bearer_expose_properties (bearer, properties);
/* Set a new ref to the bearer object as result */
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_create_bearer);
g_simple_async_result_set_op_res_gpointer (result,
bearer,
(GDestroyNotify)g_object_unref);
/* On 3GPP-only modems, new 3GPP bearer */
if (mm_iface_modem_is_3gpp_only (self)) {
mm_dbg ("Creating 3GPP Bearer in 3GPP-only modem");
mm_iface_modem_3gpp_create_bearer (MM_IFACE_MODEM_3GPP (self),
properties,
(GAsyncReadyCallback)modem_3gpp_create_bearer_ready,
result);
return;
}
/* On CDMA-only modems, new CDMA bearer */
if (mm_iface_modem_is_cdma_only (self)) {
mm_dbg ("Creating CDMA Bearer in CDMA-only modem");
mm_iface_modem_cdma_create_bearer (MM_IFACE_MODEM_CDMA (self),
properties,
(GAsyncReadyCallback)modem_cdma_create_bearer_ready,
result);
return;
}
/* On mixed LTE and CDMA modems, we'll default to building a 3GPP bearer.
* Plugins supporting mixed LTE+CDMA modems can override this and provide
* their own specific and detailed logic. */
if (mm_iface_modem_is_cdma (self) &&
mm_iface_modem_is_3gpp_lte (self)) {
mm_dbg ("Creating 3GPP Bearer in mixed CDMA+LTE modem");
mm_iface_modem_3gpp_create_bearer (MM_IFACE_MODEM_3GPP (self),
properties,
(GAsyncReadyCallback)modem_3gpp_create_bearer_ready,
result);
return;
}
g_simple_async_result_set_error (
result,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot create bearer in modem of unknown type. "
"CDMA: %s, 3GPP: %s (LTE: %s)",
mm_iface_modem_is_cdma (self) ? "yes" : "no",
mm_iface_modem_is_3gpp (self) ? "yes" : "no",
mm_iface_modem_is_3gpp_lte (self) ? "yes" : "no");
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
}
@@ -4630,6 +4661,7 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
iface->scan_networks = scan_networks;
iface->scan_networks_finish = scan_networks_finish;
iface->create_3gpp_bearer = mm_bearer_3gpp_new;
iface->create_3gpp_bearer_finish = mm_bearer_3gpp_new_finish;
}
static void
@@ -4655,6 +4687,7 @@ iface_modem_cdma_init (MMIfaceModemCdma *iface)
/* Additional actions */
iface->create_cdma_bearer = mm_bearer_cdma_new;
iface->create_cdma_bearer_finish = mm_bearer_cdma_new_finish;
}
static void
+21 -12
View File
@@ -359,24 +359,20 @@ handle_scan (MmGdbusModem3gpp *skeleton,
}
/*****************************************************************************/
/* Create new 3GPP bearer */
MMBearer *
mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
MMCommonBearerProperties *properties,
GError **error)
mm_iface_modem_3gpp_create_bearer_finish (MMIfaceModem3gpp *self,
GAsyncResult *res,
GError **error)
{
MMModem3gppRegistrationState current_state;
MMBearer *bearer;
g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer != NULL);
/* Create new 3GPP bearer using the method set in the interface, so that
* plugins can subclass it and implement their own. */
bearer = MM_BEARER (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer (
MM_BASE_MODEM (self),
properties,
error));
g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer_finish != NULL);
bearer = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer_finish (self,
res,
error);
if (!bearer)
return NULL;
@@ -403,6 +399,19 @@ mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
return bearer;
}
void
mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_assert (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer != NULL);
MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer (self,
properties,
callback,
user_data);
}
/*****************************************************************************/
typedef struct {
+14 -6
View File
@@ -172,9 +172,13 @@ struct _MMIfaceModem3gpp {
GError **error);
/* Create 3GPP bearer */
MMBearer * (* create_3gpp_bearer) (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error);
void (* create_3gpp_bearer) (MMIfaceModem3gpp *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer * (* create_3gpp_bearer_finish) (MMIfaceModem3gpp *self,
GAsyncResult *res,
GError **error);
};
GType mm_iface_modem_3gpp_get_type (void);
@@ -226,9 +230,13 @@ gboolean mm_iface_modem_3gpp_run_all_registration_checks_finish (MMIfaceModem3gp
GError **error);
/* Create new 3GPP bearer */
MMBearer *mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
MMCommonBearerProperties *properties,
GError **error);
void mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer *mm_iface_modem_3gpp_create_bearer_finish (MMIfaceModem3gpp *self,
GAsyncResult *res,
GError **error);
/* Allow registering in the network */
gboolean mm_iface_modem_3gpp_register_in_network_finish (MMIfaceModem3gpp *self,
+22 -12
View File
@@ -370,28 +370,25 @@ handle_activate_manual (MmGdbusModemCdma *skeleton,
}
/*****************************************************************************/
/* Create new CDMA bearer */
MMBearer *
mm_iface_modem_cdma_create_bearer (MMIfaceModemCdma *self,
MMCommonBearerProperties *properties,
GError **error)
mm_iface_modem_cdma_create_bearer_finish (MMIfaceModemCdma *self,
GAsyncResult *res,
GError **error)
{
MMModemCdmaRegistrationState cdma1x_current_state;
MMModemCdmaRegistrationState evdo_current_state;
MMBearer *bearer;
g_assert (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer != NULL);
/* Create new CDMA bearer using the method set in the interface, so that
* plugins can subclass it and implement their own. */
bearer = MM_BEARER (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer (
MM_BASE_MODEM (self),
properties,
error));
g_assert (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer_finish != NULL);
bearer = MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer_finish (self,
res,
error);
if (!bearer)
return NULL;
g_object_get (self,
MM_IFACE_MODEM_CDMA_CDMA1X_REGISTRATION_STATE, &cdma1x_current_state,
MM_IFACE_MODEM_CDMA_EVDO_REGISTRATION_STATE, &evdo_current_state,
@@ -418,6 +415,19 @@ mm_iface_modem_cdma_create_bearer (MMIfaceModemCdma *self,
return bearer;
}
void
mm_iface_modem_cdma_create_bearer (MMIfaceModemCdma *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_assert (MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer != NULL);
MM_IFACE_MODEM_CDMA_GET_INTERFACE (self)->create_cdma_bearer (self,
properties,
callback,
user_data);
}
/*****************************************************************************/
typedef struct _RunAllRegistrationChecksContext RunAllRegistrationChecksContext;
+14 -6
View File
@@ -141,9 +141,13 @@ struct _MMIfaceModemCdma {
GError **error);
/* Create CDMA bearer */
MMBearer * (* create_cdma_bearer) (MMBaseModem *modem,
MMCommonBearerProperties *properties,
GError **error);
void (* create_cdma_bearer) (MMIfaceModemCdma *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer * (* create_cdma_bearer_finish) (MMIfaceModemCdma *self,
GAsyncResult *res,
GError **error);
};
GType mm_iface_modem_cdma_get_type (void);
@@ -211,9 +215,13 @@ gboolean mm_iface_modem_cdma_run_all_registration_checks_finish (MMIfaceModemCdm
GError **error);
/* Create new CDMA bearer */
MMBearer *mm_iface_modem_cdma_create_bearer (MMIfaceModemCdma *self,
MMCommonBearerProperties *properties,
GError **error);
void mm_iface_modem_cdma_create_bearer (MMIfaceModemCdma *self,
MMCommonBearerProperties *properties,
GAsyncReadyCallback callback,
gpointer user_data);
MMBearer *mm_iface_modem_cdma_create_bearer_finish (MMIfaceModemCdma *self,
GAsyncResult *res,
GError **error);
/* Bind properties for simple GetStatus() */
void mm_iface_modem_cdma_bind_simple_status (MMIfaceModemCdma *self,