aboutsummaryrefslogtreecommitdiff
path: root/src/mm-bearer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mm-bearer.c')
-rw-r--r--src/mm-bearer.c305
1 files changed, 79 insertions, 226 deletions
diff --git a/src/mm-bearer.c b/src/mm-bearer.c
index 14f57b8d..459377c1 100644
--- a/src/mm-bearer.c
+++ b/src/mm-bearer.c
@@ -43,12 +43,6 @@ enum {
PROP_PATH,
PROP_CONNECTION,
PROP_MODEM,
- PROP_CAPABILITY,
- PROP_CONNECTION_APN,
- PROP_CONNECTION_IP_TYPE,
- PROP_CONNECTION_USER,
- PROP_CONNECTION_PASSWORD,
- PROP_CONNECTION_NUMBER,
PROP_LAST
};
@@ -61,36 +55,75 @@ struct _MMBearerPrivate {
MMBaseModem *modem;
/* The path where the BEARER object is exported */
gchar *path;
- /* Capability of this bearer */
- MMModemCapability capability;
-
- /* Input properties configured */
- gchar *connection_apn;
- gchar *connection_ip_type;
- gchar *connection_user;
- gchar *connection_password;
- gchar *connection_number;
};
/*****************************************************************************/
/* CONNECT */
+static void
+handle_connect_ready (MMBearer *self,
+ GAsyncResult *res,
+ GDBusMethodInvocation *invocation)
+{
+ GError *error = NULL;
+
+ if (!MM_BEARER_GET_CLASS (self)->connect_finish (self, res, &error))
+ g_dbus_method_invocation_take_error (invocation, error);
+ else
+ mm_gdbus_bearer_complete_connect (MM_GDBUS_BEARER (self), invocation);
+
+ g_object_unref (invocation);
+}
+
static gboolean
handle_connect (MMBearer *self,
GDBusMethodInvocation *invocation,
- const gchar *arg_number)
+ const gchar *number)
{
+ if (MM_BEARER_GET_CLASS (self)->connect != NULL &&
+ MM_BEARER_GET_CLASS (self)->connect_finish != NULL) {
+ MM_BEARER_GET_CLASS (self)->connect (
+ self,
+ number,
+ (GAsyncReadyCallback)handle_connect_ready,
+ g_object_ref (invocation));
+ return TRUE;
+ }
+
return FALSE;
}
/*****************************************************************************/
/* DISCONNECT */
+static void
+handle_disconnect_ready (MMBearer *self,
+ GAsyncResult *res,
+ GDBusMethodInvocation *invocation)
+{
+ GError *error = NULL;
+
+ if (!MM_BEARER_GET_CLASS (self)->disconnect_finish (self, res, &error))
+ g_dbus_method_invocation_take_error (invocation, error);
+ else
+ mm_gdbus_bearer_complete_disconnect (MM_GDBUS_BEARER (self), invocation);
+
+ g_object_unref (invocation);
+}
+
static gboolean
handle_disconnect (MMBearer *self,
- GDBusMethodInvocation *invocation,
- const gchar *arg_number)
+ GDBusMethodInvocation *invocation)
{
+ if (MM_BEARER_GET_CLASS (self)->disconnect != NULL &&
+ MM_BEARER_GET_CLASS (self)->disconnect_finish != NULL) {
+ MM_BEARER_GET_CLASS (self)->disconnect (
+ self,
+ (GAsyncReadyCallback)handle_disconnect_ready,
+ g_object_ref (invocation));
+ return TRUE;
+ }
+
return FALSE;
}
@@ -145,126 +178,34 @@ mm_bearer_get_path (MMBearer *self)
/*****************************************************************************/
-static gboolean
-parse_input_properties (MMBearer *bearer,
- MMModemCapability bearer_capability,
- GVariant *properties,
- GError **error)
+void
+mm_bearer_expose_properties (MMBearer *bearer,
+ const gchar *first_property_name,
+ ...)
{
- GVariantIter iter;
- gchar *key;
- gchar *value;
+ va_list va_args;
+ const gchar *key;
+ GVariantBuilder builder;
- g_variant_iter_init (&iter, properties);
- while (g_variant_iter_loop (&iter, "{ss}", &key, &value)) {
- gchar *previous = NULL;
+ va_start (va_args, first_property_name);
- g_object_get (G_OBJECT (bearer),
- key, &previous,
- NULL);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ key = first_property_name;
+ while (key) {
+ const gchar *value;
- if (previous) {
- if (g_str_equal (previous, value)) {
- /* no big deal */
- g_free (previous);
- continue;
- }
-
- g_free (previous);
- g_set_error (error,
- MM_CORE_ERROR,
- MM_CORE_ERROR_INVALID_ARGS,
- "Invalid input properties: duplicated key '%s'",
- key);
- return FALSE;
- }
-
- g_object_set (G_OBJECT (bearer),
- key, value,
- NULL);
- }
+ /* If a key with NULL value is given, just ignore it. */
+ value = va_arg (va_args, gchar *);
+ if (value)
+ g_variant_builder_add (&builder, "{ss}", key, value);
- /* Check mandatory properties for each capability */
-#define CHECK_MANDATORY_PROPERTY(NAME, PROPERTY) do \
- { \
- gchar *value; \
- \
- g_object_get (G_OBJECT (bearer), \
- PROPERTY, &value, \
- NULL); \
- if (!value) { \
- g_set_error (error, \
- MM_CORE_ERROR, \
- MM_CORE_ERROR_INVALID_ARGS, \
- "Invalid input properties: %s bearer requires '%s'", \
- NAME, \
- PROPERTY); \
- return FALSE; \
- } \
- g_free (value); \
- } while (0)
-
- /* POTS bearer? */
- if (bearer_capability & MM_MODEM_CAPABILITY_POTS) {
- CHECK_MANDATORY_PROPERTY ("POTS", MM_BEARER_CONNECTION_NUMBER);
- }
- /* CDMA bearer? */
- else if (bearer_capability & MM_MODEM_CAPABILITY_CDMA_EVDO) {
- /* No mandatory properties here */
- }
- /* 3GPP bearer? */
- else {
- CHECK_MANDATORY_PROPERTY ("3GPP", MM_BEARER_CONNECTION_APN);
+ key = va_arg (va_args, gchar *);
}
-
-#undef CHECK_MANDATORY_PROPERTY
+ va_end (va_args);
/* Keep the whole list of properties in the interface */
- mm_gdbus_bearer_set_properties (MM_GDBUS_BEARER (bearer), properties);
- return TRUE;
-}
-
-MMBearer *
-mm_bearer_new (MMBaseModem *modem,
- GVariant *properties,
- MMModemCapability capability,
- GError **error)
-{
- static guint32 id = 0;
- gchar *path;
- MMBearer *bearer;
-
- /* Ensure only one capability is set */
- g_assert_cmpuint (mm_count_bits_set (capability), ==, 1);
-
- /* Create the object */
- bearer = g_object_new (MM_TYPE_BEARER,
- MM_BEARER_CAPABILITY, capability,
- NULL);
-
- /* Parse and set input properties */
- if (!parse_input_properties (bearer, capability, properties, error)) {
- g_object_unref (bearer);
- return NULL;
- }
-
- /* Set defaults */
- mm_gdbus_bearer_set_interface (MM_GDBUS_BEARER (bearer), NULL);
- mm_gdbus_bearer_set_connected (MM_GDBUS_BEARER (bearer), FALSE);
- mm_gdbus_bearer_set_suspended (MM_GDBUS_BEARER (bearer), FALSE);
- mm_gdbus_bearer_set_ip4_config (MM_GDBUS_BEARER (bearer), NULL);
- mm_gdbus_bearer_set_ip6_config (MM_GDBUS_BEARER (bearer), NULL);
-
- /* Set modem and path ONLY after having checked input properties, so that
- * we don't export invalid bearers. */
- path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "%d", id++);
- g_object_set (bearer,
- MM_BEARER_PATH, path,
- MM_BEARER_MODEM, modem,
- NULL);
- g_free (path);
-
- return bearer;
+ mm_gdbus_bearer_set_properties (MM_GDBUS_BEARER (bearer),
+ g_variant_builder_end (&builder));
}
static void
@@ -302,29 +243,6 @@ set_property (GObject *object,
self, MM_BEARER_CONNECTION,
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
break;
- case PROP_CAPABILITY:
- self->priv->capability = g_value_get_flags (value);
- break;
- case PROP_CONNECTION_APN:
- g_free (self->priv->connection_apn);
- self->priv->connection_apn = g_value_dup_string (value);
- break;
- case PROP_CONNECTION_IP_TYPE:
- g_free (self->priv->connection_ip_type);
- self->priv->connection_ip_type = g_value_dup_string (value);
- break;
- case PROP_CONNECTION_USER:
- g_free (self->priv->connection_user);
- self->priv->connection_user = g_value_dup_string (value);
- break;
- case PROP_CONNECTION_PASSWORD:
- g_free (self->priv->connection_password);
- self->priv->connection_password = g_value_dup_string (value);
- break;
- case PROP_CONNECTION_NUMBER:
- g_free (self->priv->connection_number);
- self->priv->connection_number = g_value_dup_string (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -349,24 +267,6 @@ get_property (GObject *object,
case PROP_MODEM:
g_value_set_object (value, self->priv->modem);
break;
- case PROP_CAPABILITY:
- g_value_set_flags (value, self->priv->capability);
- break;
- case PROP_CONNECTION_APN:
- g_value_set_string (value, self->priv->connection_apn);
- break;
- case PROP_CONNECTION_IP_TYPE:
- g_value_set_string (value, self->priv->connection_ip_type);
- break;
- case PROP_CONNECTION_USER:
- g_value_set_string (value, self->priv->connection_user);
- break;
- case PROP_CONNECTION_PASSWORD:
- g_value_set_string (value, self->priv->connection_password);
- break;
- case PROP_CONNECTION_NUMBER:
- g_value_set_string (value, self->priv->connection_number);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -380,6 +280,14 @@ mm_bearer_init (MMBearer *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
MM_TYPE_BEARER,
MMBearerPrivate);
+
+ /* Set defaults */
+ mm_gdbus_bearer_set_interface (MM_GDBUS_BEARER (self), NULL);
+ mm_gdbus_bearer_set_connected (MM_GDBUS_BEARER (self), FALSE);
+ mm_gdbus_bearer_set_suspended (MM_GDBUS_BEARER (self), FALSE);
+ mm_gdbus_bearer_set_ip4_config (MM_GDBUS_BEARER (self), NULL);
+ mm_gdbus_bearer_set_ip6_config (MM_GDBUS_BEARER (self), NULL);
+ mm_gdbus_bearer_set_properties (MM_GDBUS_BEARER (self), NULL);
}
static void
@@ -389,12 +297,6 @@ finalize (GObject *object)
g_free (self->priv->path);
- g_free (self->priv->connection_apn);
- g_free (self->priv->connection_ip_type);
- g_free (self->priv->connection_user);
- g_free (self->priv->connection_password);
- g_free (self->priv->connection_number);
-
G_OBJECT_CLASS (mm_bearer_parent_class)->finalize (object);
}
@@ -450,53 +352,4 @@ mm_bearer_class_init (MMBearerClass *klass)
MM_TYPE_BASE_MODEM,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_MODEM, properties[PROP_MODEM]);
-
- properties[PROP_CAPABILITY] =
- g_param_spec_flags (MM_BEARER_CAPABILITY,
- "Capability",
- "The Capability supported by this Bearer",
- MM_TYPE_MODEM_CAPABILITY,
- MM_MODEM_CAPABILITY_NONE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CAPABILITY, properties[PROP_CAPABILITY]);
-
- properties[PROP_CONNECTION_APN] =
- g_param_spec_string (MM_BEARER_CONNECTION_APN,
- "Connection APN",
- "Access Point Name to use in the connection",
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_APN, properties[PROP_CONNECTION_APN]);
-
- properties[PROP_CONNECTION_IP_TYPE] =
- g_param_spec_string (MM_BEARER_CONNECTION_IP_TYPE,
- "Connection IP type",
- "IP setup to use in the connection",
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_IP_TYPE, properties[PROP_CONNECTION_IP_TYPE]);
-
- properties[PROP_CONNECTION_USER] =
- g_param_spec_string (MM_BEARER_CONNECTION_USER,
- "Connection User",
- "User to use in the connection",
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_USER, properties[PROP_CONNECTION_USER]);
-
- properties[PROP_CONNECTION_PASSWORD] =
- g_param_spec_string (MM_BEARER_CONNECTION_PASSWORD,
- "Connection Password",
- "Password to use in the connection",
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_PASSWORD, properties[PROP_CONNECTION_PASSWORD]);
-
- properties[PROP_CONNECTION_NUMBER] =
- g_param_spec_string (MM_BEARER_CONNECTION_NUMBER,
- "Connection Number",
- "Number to use in the connection",
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONNECTION_NUMBER, properties[PROP_CONNECTION_NUMBER]);
}