bearers: base bearer creation in the new bearer properties object
This commit is contained in:
+14
-13
@@ -787,28 +787,29 @@ disconnect (MMBearer *self,
|
||||
|
||||
MMBearer *
|
||||
mm_bearer_3gpp_new (MMBaseModem *modem,
|
||||
const gchar *apn,
|
||||
const gchar *ip_type,
|
||||
gboolean allow_roaming)
|
||||
MMCommonBearerProperties *properties,
|
||||
GError **error)
|
||||
{
|
||||
static guint id = 0;
|
||||
MMBearer3gpp *bearer;
|
||||
gchar *path;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Create the object */
|
||||
bearer = g_object_new (MM_TYPE_BEARER_3GPP,
|
||||
MM_BEARER_3GPP_APN, apn,
|
||||
MM_BEARER_3GPP_IP_TYPE, ip_type,
|
||||
MM_BEARER_3GPP_ALLOW_ROAMING, allow_roaming,
|
||||
MM_BEARER_3GPP_APN, mm_common_bearer_properties_get_apn (properties),
|
||||
MM_BEARER_3GPP_IP_TYPE, mm_common_bearer_properties_get_ip_type (properties),
|
||||
MM_BEARER_3GPP_ALLOW_ROAMING, mm_common_bearer_properties_get_allow_roaming (properties),
|
||||
NULL);
|
||||
|
||||
/* Build dict with all properties */
|
||||
mm_bearer_expose_properties (MM_BEARER (bearer),
|
||||
"apn", apn,
|
||||
"ip-type", ip_type,
|
||||
"allow-roaming", allow_roaming,
|
||||
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_3GPP_PREFIX "/%d", id++);
|
||||
|
||||
@@ -56,9 +56,8 @@ GType mm_bearer_3gpp_get_type (void);
|
||||
|
||||
/* Default 3GPP bearer creation implementation */
|
||||
MMBearer *mm_bearer_3gpp_new (MMBaseModem *modem,
|
||||
const gchar *apn,
|
||||
const gchar *ip_type,
|
||||
gboolean allow_roaming);
|
||||
MMCommonBearerProperties *properties,
|
||||
GError **error);
|
||||
|
||||
const gchar *mm_bearer_3gpp_get_apn (MMBearer3gpp *self);
|
||||
const gchar *mm_bearer_3gpp_get_ip_type (MMBearer3gpp *self);
|
||||
|
||||
+5
-29
@@ -480,39 +480,15 @@ mm_bearer_set_connection_forbidden (MMBearer *self,
|
||||
|
||||
void
|
||||
mm_bearer_expose_properties (MMBearer *bearer,
|
||||
const gchar *first_property_name,
|
||||
...)
|
||||
MMCommonBearerProperties *properties)
|
||||
{
|
||||
va_list va_args;
|
||||
const gchar *key;
|
||||
GVariantBuilder builder;
|
||||
|
||||
va_start (va_args, first_property_name);
|
||||
|
||||
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
|
||||
key = first_property_name;
|
||||
while (key) {
|
||||
if (g_str_equal (key, "allow-roaming")) {
|
||||
gboolean value;
|
||||
|
||||
value = va_arg (va_args, gboolean);
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_boolean (value));
|
||||
} else {
|
||||
const gchar *value;
|
||||
|
||||
/* If a key with NULL value is given, just ignore it. */
|
||||
value = va_arg (va_args, gchar *);
|
||||
if (value)
|
||||
g_variant_builder_add (&builder, "{sv}", key, g_variant_new_string (value));
|
||||
}
|
||||
|
||||
key = va_arg (va_args, gchar *);
|
||||
}
|
||||
va_end (va_args);
|
||||
GVariant *dictionary;
|
||||
|
||||
/* Keep the whole list of properties in the interface */
|
||||
dictionary = mm_common_bearer_properties_get_dictionary (properties);
|
||||
mm_gdbus_bearer_set_properties (MM_GDBUS_BEARER (bearer),
|
||||
g_variant_builder_end (&builder));
|
||||
dictionary);
|
||||
g_variant_unref (dictionary);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
+3
-3
@@ -21,7 +21,8 @@
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include <mm-gdbus-bearer.h>
|
||||
#include <libmm-common.h>
|
||||
|
||||
#include "mm-base-modem.h"
|
||||
|
||||
#define MM_TYPE_BEARER (mm_bearer_get_type ())
|
||||
@@ -89,8 +90,7 @@ GType mm_bearer_get_type (void);
|
||||
const gchar *mm_bearer_get_path (MMBearer *bearer);
|
||||
|
||||
void mm_bearer_expose_properties (MMBearer *bearer,
|
||||
const gchar *first_property_name,
|
||||
...);
|
||||
MMCommonBearerProperties *properties);
|
||||
|
||||
void mm_bearer_set_connection_allowed (MMBearer *bearer);
|
||||
void mm_bearer_set_connection_forbidden (MMBearer *bearer,
|
||||
|
||||
@@ -102,7 +102,7 @@ modem_create_bearer_finish (MMIfaceModem *self,
|
||||
|
||||
static void
|
||||
modem_create_bearer (MMIfaceModem *self,
|
||||
GVariant *properties,
|
||||
MMCommonBearerProperties *properties,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
@@ -116,9 +116,9 @@ modem_create_bearer (MMIfaceModem *self,
|
||||
|
||||
/* New 3GPP bearer */
|
||||
if (MM_BROADBAND_MODEM (self)->priv->modem_3gpp_dbus_skeleton) {
|
||||
bearer = mm_iface_modem_3gpp_create_bearer_from_properties (MM_IFACE_MODEM_3GPP (self),
|
||||
properties,
|
||||
&error);
|
||||
bearer = mm_iface_modem_3gpp_create_bearer (MM_IFACE_MODEM_3GPP (self),
|
||||
properties,
|
||||
&error);
|
||||
} else {
|
||||
g_set_error (&error,
|
||||
MM_CORE_ERROR,
|
||||
@@ -134,6 +134,9 @@ modem_create_bearer (MMIfaceModem *self,
|
||||
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,
|
||||
|
||||
@@ -320,9 +320,8 @@ handle_scan (MmGdbusModem3gpp *skeleton,
|
||||
/* Create new 3GPP bearer */
|
||||
MMBearer *
|
||||
mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
|
||||
const gchar *apn,
|
||||
const gchar *ip_type,
|
||||
gboolean allow_roaming)
|
||||
MMCommonBearerProperties *properties,
|
||||
GError **error)
|
||||
{
|
||||
MMModem3gppRegistrationState current_state;
|
||||
MMBearer *bearer;
|
||||
@@ -331,11 +330,12 @@ mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
|
||||
|
||||
/* 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),
|
||||
apn,
|
||||
ip_type,
|
||||
allow_roaming));
|
||||
bearer = MM_BEARER (MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->create_3gpp_bearer (
|
||||
MM_BASE_MODEM (self),
|
||||
properties,
|
||||
error));
|
||||
if (!bearer)
|
||||
return NULL;
|
||||
|
||||
g_object_get (self,
|
||||
MM_IFACE_MODEM_3GPP_REGISTRATION_STATE, ¤t_state,
|
||||
@@ -360,60 +360,6 @@ mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
|
||||
return bearer;
|
||||
}
|
||||
|
||||
MMBearer *
|
||||
mm_iface_modem_3gpp_create_bearer_from_properties (MMIfaceModem3gpp *self,
|
||||
GVariant *properties,
|
||||
GError **error)
|
||||
{
|
||||
GVariantIter iter;
|
||||
const gchar *key;
|
||||
GVariant *value;
|
||||
gchar *apn = NULL;
|
||||
gchar *ip_type = NULL;
|
||||
gboolean allow_roaming = FALSE;
|
||||
gboolean allow_roaming_found = FALSE;
|
||||
|
||||
mm_dbg ("Creating 3GPP bearer with properties...");
|
||||
g_variant_iter_init (&iter, properties);
|
||||
while (g_variant_iter_loop (&iter, "{sv}", &key, &value)) {
|
||||
if (g_str_equal (key, "apn")) {
|
||||
if (apn)
|
||||
mm_warn ("Duplicate 'apn' property found, ignoring value '%s'",
|
||||
g_variant_get_string (value, NULL));
|
||||
else
|
||||
apn = g_variant_dup_string (value, NULL);
|
||||
} else if (g_str_equal (key, "ip-type")) {
|
||||
if (ip_type)
|
||||
mm_warn ("Duplicate 'ip-type' property found, ignoring value '%s'",
|
||||
g_variant_get_string (value, NULL));
|
||||
else
|
||||
ip_type = g_variant_dup_string (value, NULL);
|
||||
} else if (g_str_equal (key, "allow-roaming")) {
|
||||
if (allow_roaming_found)
|
||||
mm_warn ("Duplicate 'allow-roaming' property found, ignoring value '%s'",
|
||||
g_variant_get_string (value, NULL));
|
||||
else {
|
||||
allow_roaming_found = TRUE;
|
||||
allow_roaming = g_variant_get_boolean (value);
|
||||
}
|
||||
}
|
||||
else
|
||||
mm_dbg ("Ignoring property '%s' in 3GPP bearer", key);
|
||||
}
|
||||
|
||||
/* Check mandatory properties */
|
||||
if (!apn) {
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_INVALID_ARGS,
|
||||
"Invalid input properties: 3GPP bearer requires 'apn'");
|
||||
g_free (ip_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mm_iface_modem_3gpp_create_bearer (self, apn, ip_type, allow_roaming);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <libmm-common.h>
|
||||
|
||||
#include "mm-at-serial-port.h"
|
||||
|
||||
#define MM_TYPE_IFACE_MODEM_3GPP (mm_iface_modem_3gpp_get_type ())
|
||||
@@ -145,9 +147,8 @@ struct _MMIfaceModem3gpp {
|
||||
|
||||
/* Create 3GPP bearer */
|
||||
MMBearer * (* create_3gpp_bearer) (MMBaseModem *modem,
|
||||
const gchar *apn,
|
||||
const gchar *ip_type,
|
||||
gboolean allow_roaming);
|
||||
MMCommonBearerProperties *properties,
|
||||
GError **error);
|
||||
};
|
||||
|
||||
GType mm_iface_modem_3gpp_get_type (void);
|
||||
@@ -198,12 +199,8 @@ gboolean mm_iface_modem_3gpp_run_all_registration_checks_finish (MMIfaceModem3gp
|
||||
|
||||
/* Create new 3GPP bearer */
|
||||
MMBearer *mm_iface_modem_3gpp_create_bearer (MMIfaceModem3gpp *self,
|
||||
const gchar *apn,
|
||||
const gchar *ip_type,
|
||||
gboolean allow_roaming);
|
||||
MMBearer *mm_iface_modem_3gpp_create_bearer_from_properties (MMIfaceModem3gpp *self,
|
||||
GVariant *properties,
|
||||
GError **error);
|
||||
MMCommonBearerProperties *properties,
|
||||
GError **error);
|
||||
|
||||
/* Allow registering in the network */
|
||||
gboolean mm_iface_modem_3gpp_register_in_network_finish (MMIfaceModem3gpp *self,
|
||||
|
||||
+86
-19
@@ -124,10 +124,25 @@ bearer_status_changed (MMBearer *bearer,
|
||||
}
|
||||
}
|
||||
|
||||
gchar *
|
||||
mm_iface_modem_create_bearer_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *path;
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
|
||||
return NULL;
|
||||
|
||||
path = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
|
||||
|
||||
return g_strdup (path);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_create_bearer_ready (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
DbusCallContext *ctx)
|
||||
create_bearer_ready (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *simple)
|
||||
{
|
||||
MMBearer *bearer;
|
||||
GError *error = NULL;
|
||||
@@ -136,7 +151,7 @@ handle_create_bearer_ready (MMIfaceModem *self,
|
||||
res,
|
||||
&error);
|
||||
if (error)
|
||||
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else {
|
||||
MMBearerList *list = NULL;
|
||||
|
||||
@@ -145,7 +160,7 @@ handle_create_bearer_ready (MMIfaceModem *self,
|
||||
NULL);
|
||||
|
||||
if (!mm_bearer_list_add_bearer (list, bearer, &error))
|
||||
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else {
|
||||
/* If bearer properly created and added to the list, follow its
|
||||
* status */
|
||||
@@ -153,21 +168,25 @@ handle_create_bearer_ready (MMIfaceModem *self,
|
||||
"notify::" MM_BEARER_STATUS,
|
||||
(GCallback)bearer_status_changed,
|
||||
self);
|
||||
|
||||
mm_gdbus_modem_complete_create_bearer (ctx->skeleton,
|
||||
ctx->invocation,
|
||||
mm_bearer_get_path (bearer));
|
||||
/* It is safe to set the static path here because we're not completing
|
||||
* in idle */
|
||||
g_simple_async_result_set_op_res_gpointer (simple,
|
||||
(gchar *)mm_bearer_get_path (bearer),
|
||||
NULL);
|
||||
}
|
||||
g_object_unref (bearer);
|
||||
g_object_unref (list);
|
||||
}
|
||||
dbus_call_context_free (ctx);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_create_bearer (MmGdbusModem *skeleton,
|
||||
GDBusMethodInvocation *invocation,
|
||||
GVariant *arg_properties,
|
||||
MMIfaceModem *self)
|
||||
void
|
||||
mm_iface_modem_create_bearer (MMIfaceModem *self,
|
||||
MMCommonBearerProperties *properties,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBearerList *list = NULL;
|
||||
|
||||
@@ -176,8 +195,10 @@ handle_create_bearer (MmGdbusModem *skeleton,
|
||||
NULL);
|
||||
|
||||
if (mm_bearer_list_get_count (list) == mm_bearer_list_get_max (list)) {
|
||||
g_dbus_method_invocation_return_error (
|
||||
invocation,
|
||||
g_simple_async_report_error_in_idle (
|
||||
G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_TOO_MANY,
|
||||
"Cannot add new bearer: already reached maximum (%u)",
|
||||
@@ -185,14 +206,60 @@ handle_create_bearer (MmGdbusModem *skeleton,
|
||||
} else {
|
||||
MM_IFACE_MODEM_GET_INTERFACE (self)->create_bearer (
|
||||
self,
|
||||
arg_properties,
|
||||
properties,
|
||||
(GAsyncReadyCallback)create_bearer_ready,
|
||||
g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
mm_iface_modem_create_bearer));
|
||||
}
|
||||
|
||||
g_object_unref (list);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_create_bearer_ready (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
DbusCallContext *ctx)
|
||||
{
|
||||
gchar *bearer_path;
|
||||
GError *error = NULL;
|
||||
|
||||
bearer_path = mm_iface_modem_create_bearer_finish (self, res, &error);
|
||||
if (!bearer_path)
|
||||
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||
else {
|
||||
mm_gdbus_modem_complete_create_bearer (ctx->skeleton,
|
||||
ctx->invocation,
|
||||
bearer_path);
|
||||
g_free (bearer_path);
|
||||
}
|
||||
dbus_call_context_free (ctx);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_create_bearer (MmGdbusModem *skeleton,
|
||||
GDBusMethodInvocation *invocation,
|
||||
GVariant *dictionary,
|
||||
MMIfaceModem *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
MMCommonBearerProperties *properties;
|
||||
|
||||
properties = mm_common_bearer_properties_new_from_dictionary (dictionary, &error);
|
||||
if (!properties) {
|
||||
g_dbus_method_invocation_take_error (invocation, error);
|
||||
} else {
|
||||
mm_iface_modem_create_bearer (
|
||||
self,
|
||||
properties,
|
||||
(GAsyncReadyCallback)handle_create_bearer_ready,
|
||||
dbus_call_context_new (skeleton,
|
||||
invocation,
|
||||
self));
|
||||
g_object_unref (properties);
|
||||
}
|
||||
|
||||
g_object_unref (list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -232,7 +232,7 @@ struct _MMIfaceModem {
|
||||
|
||||
/* Create bearer */
|
||||
void (*create_bearer) (MMIfaceModem *self,
|
||||
GVariant *properties,
|
||||
MMCommonBearerProperties *properties,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
MMBearer * (*create_bearer_finish) (MMIfaceModem *self,
|
||||
@@ -323,4 +323,13 @@ gboolean mm_iface_modem_set_allowed_bands_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
/* Allow creating bearers */
|
||||
void mm_iface_modem_create_bearer (MMIfaceModem *self,
|
||||
MMCommonBearerProperties *properties,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gchar *mm_iface_modem_create_bearer_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_IFACE_MODEM_H */
|
||||
|
||||
Reference in New Issue
Block a user