bearer: simplify handling of the bearer configuration

The base MMBearer object will receive the MMBearerProperties configuration,
which contains every generic and plugin-specific set up. Not every configuration
parameter will be used by every implementation (e.g. not every bearer needs
user/password).

The Bearer object will expose every configuration parameter received in its
`Properties' property in the interface, even if it's not really used.
This commit is contained in:
Aleksander Morgado
2012-05-06 17:12:36 +02:00
parent 1984c155ad
commit caeeae2721
13 changed files with 141 additions and 596 deletions
+3 -15
View File
@@ -385,21 +385,9 @@ disconnect (MMBearer *self,
/*****************************************************************************/
static gboolean
cmp_properties (MMBearer *self,
MMBearerProperties *properties)
{
return (mm_bearer_properties_get_apn (properties) == NULL &&
mm_bearer_properties_get_ip_type (properties) == NULL &&
mm_bearer_properties_get_number (properties) == NULL &&
mm_bearer_properties_get_rm_protocol (properties) == MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN &&
mm_bearer_properties_get_allow_roaming (properties));
}
/*****************************************************************************/
MMBearer *
mm_bearer_iridium_new (MMBroadbandModemIridium *modem)
mm_bearer_iridium_new (MMBroadbandModemIridium *modem,
MMBearerProperties *config)
{
MMBearer *bearer;
@@ -408,6 +396,7 @@ mm_bearer_iridium_new (MMBroadbandModemIridium *modem)
* g_object_get() here */
bearer = g_object_new (MM_TYPE_BEARER_IRIDIUM,
MM_BEARER_MODEM, modem,
MM_BEARER_CONFIG, config,
"ip-timeout", MM_BEARER_IRIDIUM_IP_TIMEOUT_DEFAULT,
NULL);
@@ -428,7 +417,6 @@ mm_bearer_iridium_class_init (MMBearerIridiumClass *klass)
MMBearerClass *bearer_class = MM_BEARER_CLASS (klass);
/* Virtual methods */
bearer_class->cmp_properties = cmp_properties;
bearer_class->connect = connect;
bearer_class->connect_finish = connect_finish;
bearer_class->disconnect = disconnect;
+2 -1
View File
@@ -48,6 +48,7 @@ GType mm_bearer_iridium_get_type (void);
/* Iridium bearer creation implementation.
* NOTE it is *not* a broadband bearer, so not async-initable */
MMBearer *mm_bearer_iridium_new (MMBroadbandModemIridium *modem);
MMBearer *mm_bearer_iridium_new (MMBroadbandModemIridium *modem,
MMBearerProperties *config);
#endif /* MM_BEARER_IRIDIUM_H */
+2 -3
View File
@@ -360,10 +360,9 @@ create_bearer (MMIfaceModem *self,
callback,
user_data,
create_bearer);
/* We just create a MMBearerIridium
* Note that we do not need to use properties here */
mm_dbg ("Creating Iridium bearer...");
bearer = mm_bearer_iridium_new (MM_BROADBAND_MODEM_IRIDIUM (self));
bearer = mm_bearer_iridium_new (MM_BROADBAND_MODEM_IRIDIUM (self),
properties);
g_simple_async_result_set_op_res_gpointer (result,
bearer,
(GDestroyNotify)g_object_unref);
+14 -141
View File
@@ -36,26 +36,11 @@
G_DEFINE_TYPE (MMBroadbandBearerNovatel, mm_broadband_bearer_novatel, MM_TYPE_BROADBAND_BEARER);
enum {
PROP_0,
PROP_USER,
PROP_PASSWORD,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
/*****************************************************************************/
struct _MMBroadbandBearerNovatelPrivate {
/* timeout id for checking whether we're still connected */
guint connection_poller;
/* Username for authenticating to APN */
gchar *user;
/* Password for authenticating to APN */
gchar *password;
};
typedef struct {
@@ -255,7 +240,7 @@ connect_3gpp_qmiconnect_ready (MMBaseModem *modem,
* happened. Instead, we need to poll the modem to see if it's
* ready.
*/
g_timeout_add_seconds(1, (GSourceFunc)connect_3gpp_qmistatus, ctx);
g_timeout_add_seconds (1, (GSourceFunc)connect_3gpp_qmistatus, ctx);
}
static void
@@ -268,9 +253,9 @@ connect_3gpp (MMBroadbandBearer *bearer,
GAsyncReadyCallback callback,
gpointer user_data)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (bearer);
DetailedConnectContext *ctx;
gchar *command, *apn, *user, *password;
MMBearerProperties *config;
ctx = detailed_connect_context_new (bearer,
modem,
@@ -280,9 +265,10 @@ connect_3gpp (MMBroadbandBearer *bearer,
callback,
user_data);
apn = mm_at_serial_port_quote_string (mm_broadband_bearer_get_3gpp_apn (bearer));
user = mm_at_serial_port_quote_string (self->priv->user);
password = mm_at_serial_port_quote_string (self->priv->password);
config = mm_bearer_peek_config (MM_BEARER (bearer));
apn = mm_at_serial_port_quote_string (mm_bearer_properties_get_apn (config));
user = mm_at_serial_port_quote_string (mm_bearer_properties_get_user (config));
password = mm_at_serial_port_quote_string (mm_bearer_properties_get_password (config));
command = g_strdup_printf ("$NWQMICONNECT=,,,,,,%s,,,%s,%s",
apn, user, password);
g_free (apn);
@@ -298,7 +284,6 @@ connect_3gpp (MMBroadbandBearer *bearer,
g_free (command);
}
typedef struct {
MMBroadbandBearer *self;
MMBaseModem *modem;
@@ -308,7 +293,6 @@ typedef struct {
GSimpleAsyncResult *result;
} DetailedDisconnectContext;
static DetailedDisconnectContext *
detailed_disconnect_context_new (MMBroadbandBearer *self,
MMBroadbandModem *modem,
@@ -374,13 +358,12 @@ disconnect_3gpp_status_complete (MMBaseModem *modem,
}
result = mm_strip_tag (result, "$NWQMISTATUS:");
if (g_strrstr(result, "QMI State: DISCONNECTED"))
if (g_strrstr (result, "QMI State: DISCONNECTED"))
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
detailed_disconnect_context_complete_and_free (ctx);
}
static void
disconnect_3gpp_check_status (MMBaseModem *modem,
GAsyncResult *res,
@@ -435,100 +418,17 @@ disconnect_3gpp (MMBroadbandBearer *self,
ctx); /* user_data */
}
static void
finalize (GObject *object)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (object);
g_free (self->priv->user);
g_free (self->priv->password);
if (self->priv->connection_poller)
g_source_remove (self->priv->connection_poller);
G_OBJECT_CLASS (mm_broadband_bearer_novatel_parent_class)->finalize (object);
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (object);
switch (prop_id) {
case PROP_USER:
g_free (self->priv->user);
self->priv->user = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (self->priv->password);
self->priv->password = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (object);
switch (prop_id) {
case PROP_USER:
g_value_set_string (value, self->priv->user);
break;
case PROP_PASSWORD:
g_value_set_string (value, self->priv->password);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
cmp_properties (MMBearer *bearer,
MMBearerProperties *properties)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (bearer);
return ((mm_broadband_bearer_get_allow_roaming (MM_BROADBAND_BEARER (self)) ==
mm_bearer_properties_get_allow_roaming (properties)) &&
(!g_strcmp0 (mm_broadband_bearer_get_ip_type (MM_BROADBAND_BEARER (self)),
mm_bearer_properties_get_ip_type (properties))) &&
(!g_strcmp0 (mm_broadband_bearer_get_3gpp_apn (MM_BROADBAND_BEARER (self)),
mm_bearer_properties_get_apn (properties))) &&
(!g_strcmp0 (self->priv->user,
mm_bearer_properties_get_user (properties))) &&
(!g_strcmp0 (self->priv->password,
mm_bearer_properties_get_password (properties))));
}
static MMBearerProperties *
expose_properties (MMBearer *bearer)
{
MMBroadbandBearerNovatel *self = MM_BROADBAND_BEARER_NOVATEL (bearer);
MMBearerProperties *properties;
properties = mm_bearer_properties_new ();
mm_bearer_properties_set_apn (properties,
mm_broadband_bearer_get_3gpp_apn (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_ip_type (properties,
mm_broadband_bearer_get_ip_type (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_allow_roaming (properties,
mm_broadband_bearer_get_allow_roaming (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_user (properties, self->priv->user);
mm_bearer_properties_set_password (properties, self->priv->user);
return properties;
}
static void
mm_broadband_bearer_novatel_init (MMBroadbandBearerNovatel *self)
{
@@ -536,8 +436,6 @@ mm_broadband_bearer_novatel_init (MMBroadbandBearerNovatel *self)
MM_TYPE_BROADBAND_BEARER_NOVATEL,
MMBroadbandBearerNovatelPrivate);
self->priv->user = NULL;
self->priv->password = NULL;
self->priv->connection_poller = 0;
}
@@ -545,38 +443,16 @@ static void
mm_broadband_bearer_novatel_class_init (MMBroadbandBearerNovatelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MMBearerClass *bearer_class = MM_BEARER_CLASS (klass);
MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMBroadbandBearerNovatelPrivate));
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->finalize = finalize;
bearer_class->cmp_properties = cmp_properties;
bearer_class->expose_properties = expose_properties;
broadband_bearer_class->connect_3gpp = connect_3gpp;
broadband_bearer_class->connect_3gpp_finish = connect_3gpp_finish;
broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
broadband_bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
properties[PROP_USER] =
g_param_spec_string (MM_BROADBAND_BEARER_NOVATEL_USER,
"User",
"Username to authenticate to APN",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_USER, properties[PROP_USER]);
properties[PROP_PASSWORD] =
g_param_spec_string (MM_BROADBAND_BEARER_NOVATEL_PASSWORD,
"Password",
"Password to authenticate to APN",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_PASSWORD, properties[PROP_PASSWORD]);
}
MMBearer *
@@ -599,11 +475,12 @@ mm_broadband_bearer_novatel_new_finish (GAsyncResult *res,
return MM_BEARER (bearer);
}
void mm_broadband_bearer_novatel_new (MMBroadbandModemNovatel *modem,
MMBearerProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
void
mm_broadband_bearer_novatel_new (MMBroadbandModemNovatel *modem,
MMBearerProperties *config,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_async_initable_new_async (
MM_TYPE_BROADBAND_BEARER_NOVATEL,
@@ -612,10 +489,6 @@ void mm_broadband_bearer_novatel_new (MMBroadbandModemNovatel *modem,
callback,
user_data,
MM_BEARER_MODEM, modem,
MM_BROADBAND_BEARER_3GPP_APN, mm_bearer_properties_get_apn (properties),
MM_BROADBAND_BEARER_IP_TYPE, mm_bearer_properties_get_ip_type (properties),
MM_BROADBAND_BEARER_ALLOW_ROAMING, mm_bearer_properties_get_allow_roaming (properties),
MM_BROADBAND_BEARER_NOVATEL_USER, mm_bearer_properties_get_user (properties),
MM_BROADBAND_BEARER_NOVATEL_PASSWORD, mm_bearer_properties_get_password (properties),
MM_BEARER_CONFIG, config,
NULL);
}
+10 -138
View File
@@ -36,20 +36,8 @@
G_DEFINE_TYPE (MMBroadbandBearerHso, mm_broadband_bearer_hso, MM_TYPE_BROADBAND_BEARER);
enum {
PROP_0,
PROP_USER,
PROP_PASSWORD,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
struct _MMBroadbandBearerHsoPrivate {
gchar *user;
gchar *password;
guint auth_idx;
gpointer connect_pending;
guint connect_pending_id;
gulong connect_cancellable_id;
@@ -544,6 +532,8 @@ static void
authenticate (Dial3gppContext *ctx)
{
gchar *command;
const gchar *user;
const gchar *password;
if (!auth_commands[ctx->auth_idx]) {
g_simple_async_result_set_error (ctx->result,
@@ -554,8 +544,11 @@ authenticate (Dial3gppContext *ctx)
return;
}
user = mm_bearer_properties_get_user (mm_bearer_peek_config (MM_BEARER (ctx->self)));
password = mm_bearer_properties_get_password (mm_bearer_peek_config (MM_BEARER (ctx->self)));
/* Both user and password are required; otherwise firmware returns an error */
if (!ctx->self->priv->user || !ctx->self->priv->password)
if (!user || !password)
command = g_strdup_printf ("%s=%d,0",
auth_commands[ctx->auth_idx],
ctx->cid);
@@ -563,8 +556,8 @@ authenticate (Dial3gppContext *ctx)
command = g_strdup_printf ("%s=%d,1,\"%s\",\"%s\"",
auth_commands[ctx->auth_idx],
ctx->cid,
ctx->self->priv->password,
ctx->self->priv->user);
password,
user);
mm_base_modem_at_command_full (ctx->modem,
ctx->primary,
@@ -683,44 +676,6 @@ disconnect_3gpp (MMBroadbandBearer *self,
/*****************************************************************************/
static gboolean
cmp_properties (MMBearer *self,
MMBearerProperties *properties)
{
MMBroadbandBearerHso *hso = MM_BROADBAND_BEARER_HSO (self);
return ((mm_broadband_bearer_get_allow_roaming (MM_BROADBAND_BEARER (self)) ==
mm_bearer_properties_get_allow_roaming (properties)) &&
(!g_strcmp0 (mm_broadband_bearer_get_ip_type (MM_BROADBAND_BEARER (self)),
mm_bearer_properties_get_ip_type (properties))) &&
(!g_strcmp0 (mm_broadband_bearer_get_3gpp_apn (MM_BROADBAND_BEARER (self)),
mm_bearer_properties_get_apn (properties))) &&
(!g_strcmp0 (hso->priv->user,
mm_bearer_properties_get_user (properties))) &&
(!g_strcmp0 (hso->priv->password,
mm_bearer_properties_get_password (properties))));
}
static MMBearerProperties *
expose_properties (MMBearer *self)
{
MMBroadbandBearerHso *hso = MM_BROADBAND_BEARER_HSO (self);
MMBearerProperties *properties;
properties = mm_bearer_properties_new ();
mm_bearer_properties_set_apn (properties,
mm_broadband_bearer_get_3gpp_apn (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_ip_type (properties,
mm_broadband_bearer_get_ip_type (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_allow_roaming (properties,
mm_broadband_bearer_get_allow_roaming (MM_BROADBAND_BEARER (self)));
mm_bearer_properties_set_user (properties, hso->priv->user);
mm_bearer_properties_set_password (properties, hso->priv->user);
return properties;
}
/*****************************************************************************/
MMBearer *
mm_broadband_bearer_hso_new_finish (GAsyncResult *res,
GError **error)
@@ -743,7 +698,7 @@ mm_broadband_bearer_hso_new_finish (GAsyncResult *res,
void
mm_broadband_bearer_hso_new (MMBroadbandModemHso *modem,
MMBearerProperties *properties,
MMBearerProperties *config,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -755,58 +710,10 @@ mm_broadband_bearer_hso_new (MMBroadbandModemHso *modem,
callback,
user_data,
MM_BEARER_MODEM, modem,
MM_BROADBAND_BEARER_3GPP_APN, mm_bearer_properties_get_apn (properties),
MM_BROADBAND_BEARER_IP_TYPE, mm_bearer_properties_get_ip_type (properties),
MM_BROADBAND_BEARER_ALLOW_ROAMING, mm_bearer_properties_get_allow_roaming (properties),
MM_BROADBAND_BEARER_HSO_USER, mm_bearer_properties_get_user (properties),
MM_BROADBAND_BEARER_HSO_PASSWORD, mm_bearer_properties_get_password (properties),
MM_BEARER_CONFIG, config,
NULL);
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MMBroadbandBearerHso *self = MM_BROADBAND_BEARER_HSO (object);
switch (prop_id) {
case PROP_USER:
g_free (self->priv->user);
self->priv->user = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (self->priv->password);
self->priv->password = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MMBroadbandBearerHso *self = MM_BROADBAND_BEARER_HSO (object);
switch (prop_id) {
case PROP_USER:
g_value_set_string (value, self->priv->user);
break;
case PROP_PASSWORD:
g_value_set_string (value, self->priv->password);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
mm_broadband_bearer_hso_init (MMBroadbandBearerHso *self)
{
@@ -816,53 +723,18 @@ mm_broadband_bearer_hso_init (MMBroadbandBearerHso *self)
MMBroadbandBearerHsoPrivate);
}
static void
finalize (GObject *object)
{
MMBroadbandBearerHso *self = MM_BROADBAND_BEARER_HSO (object);
g_free (self->priv->user);
g_free (self->priv->password);
G_OBJECT_CLASS (mm_broadband_bearer_hso_parent_class)->finalize (object);
}
static void
mm_broadband_bearer_hso_class_init (MMBroadbandBearerHsoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MMBearerClass *bearer_class = MM_BEARER_CLASS (klass);
MMBroadbandBearerClass *broadband_bearer_class = MM_BROADBAND_BEARER_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMBroadbandBearerHsoPrivate));
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->finalize = finalize;
bearer_class->cmp_properties = cmp_properties;
bearer_class->expose_properties = expose_properties;
broadband_bearer_class->dial_3gpp = dial_3gpp;
broadband_bearer_class->dial_3gpp_finish = dial_3gpp_finish;
broadband_bearer_class->get_ip_config_3gpp = get_ip_config_3gpp;
broadband_bearer_class->get_ip_config_3gpp_finish = get_ip_config_3gpp_finish;
broadband_bearer_class->disconnect_3gpp = disconnect_3gpp;
broadband_bearer_class->disconnect_3gpp_finish = disconnect_3gpp_finish;
properties[PROP_USER] =
g_param_spec_string (MM_BROADBAND_BEARER_HSO_USER,
"User",
"Username to use to authenticate the connection",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_USER, properties[PROP_USER]);
properties[PROP_PASSWORD] =
g_param_spec_string (MM_BROADBAND_BEARER_HSO_PASSWORD,
"Password",
"Password to use to authenticate the connection",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_PASSWORD, properties[PROP_PASSWORD]);
}
+1 -4
View File
@@ -31,9 +31,6 @@
#define MM_IS_BROADBAND_BEARER_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BROADBAND_BEARER_HSO))
#define MM_BROADBAND_BEARER_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BROADBAND_BEARER_HSO, MMBroadbandBearerHsoClass))
#define MM_BROADBAND_BEARER_HSO_USER "broadband-bearer-hso-user"
#define MM_BROADBAND_BEARER_HSO_PASSWORD "broadband-bearer-hso-password"
typedef enum {
MM_BROADBAND_BEARER_HSO_CONNECTION_STATUS_UNKNOWN,
MM_BROADBAND_BEARER_HSO_CONNECTION_STATUS_CONNECTED,
@@ -58,7 +55,7 @@ GType mm_broadband_bearer_hso_get_type (void);
/* Default 3GPP bearer creation implementation */
void mm_broadband_bearer_hso_new (MMBroadbandModemHso *modem,
MMBearerProperties *properties,
MMBearerProperties *config,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);