libmm-glib,simple-connect-properties: improve documentation

This commit is contained in:
Aleksander Morgado
2012-10-03 14:10:40 +02:00
parent 4f5dd8afaa
commit 8185f24e64
3 changed files with 400 additions and 184 deletions

View File

@@ -572,33 +572,36 @@ mm_modem_simple_get_type
<FILE>mm-simple-connect-properties</FILE> <FILE>mm-simple-connect-properties</FILE>
<TITLE>MMSimpleConnectProperties</TITLE> <TITLE>MMSimpleConnectProperties</TITLE>
MMSimpleConnectProperties MMSimpleConnectProperties
MMSimpleConnectPropertiesClass <SUBSECTION New>
mm_simple_connect_properties_get_allow_roaming
mm_simple_connect_properties_get_allowed_modes
mm_simple_connect_properties_get_apn
mm_simple_connect_properties_get_bands
mm_simple_connect_properties_get_bearer_properties
mm_simple_connect_properties_get_dictionary
mm_simple_connect_properties_get_ip_type
mm_simple_connect_properties_get_number
mm_simple_connect_properties_get_operator_id
mm_simple_connect_properties_get_password
mm_simple_connect_properties_get_pin
mm_simple_connect_properties_get_user
mm_simple_connect_properties_new mm_simple_connect_properties_new
<SUBSECTION GettersSetters>
mm_simple_connect_properties_get_pin
mm_simple_connect_properties_set_pin
mm_simple_connect_properties_get_operator_id
mm_simple_connect_properties_set_operator_id
mm_simple_connect_properties_get_bands
mm_simple_connect_properties_set_bands
mm_simple_connect_properties_get_allowed_modes
mm_simple_connect_properties_set_allowed_modes
mm_simple_connect_properties_get_apn
mm_simple_connect_properties_set_apn
mm_simple_connect_properties_set_user
mm_simple_connect_properties_get_user
mm_simple_connect_properties_get_password
mm_simple_connect_properties_set_password
mm_simple_connect_properties_get_ip_type
mm_simple_connect_properties_set_ip_type
mm_simple_connect_properties_get_allow_roaming
mm_simple_connect_properties_set_allow_roaming
mm_simple_connect_properties_get_number
mm_simple_connect_properties_set_number
<SUBSECTION Private>
mm_simple_connect_properties_get_bearer_properties
mm_simple_connect_properties_new_from_dictionary mm_simple_connect_properties_new_from_dictionary
mm_simple_connect_properties_new_from_string mm_simple_connect_properties_new_from_string
mm_simple_connect_properties_set_allow_roaming mm_simple_connect_properties_get_dictionary
mm_simple_connect_properties_set_allowed_modes
mm_simple_connect_properties_set_apn
mm_simple_connect_properties_set_bands
mm_simple_connect_properties_set_ip_type
mm_simple_connect_properties_set_number
mm_simple_connect_properties_set_operator_id
mm_simple_connect_properties_set_password
mm_simple_connect_properties_set_pin
mm_simple_connect_properties_set_user
<SUBSECTION Standard> <SUBSECTION Standard>
MMSimpleConnectPropertiesClass
MMSimpleConnectPropertiesPrivate MMSimpleConnectPropertiesPrivate
MM_IS_SIMPLE_CONNECT_PROPERTIES MM_IS_SIMPLE_CONNECT_PROPERTIES
MM_IS_SIMPLE_CONNECT_PROPERTIES_CLASS MM_IS_SIMPLE_CONNECT_PROPERTIES_CLASS

View File

@@ -19,6 +19,18 @@
#include "mm-common-helpers.h" #include "mm-common-helpers.h"
#include "mm-simple-connect-properties.h" #include "mm-simple-connect-properties.h"
/**
* SECTION: mm-simple-connect-properties
* @title: MMSimpleConnectProperties
* @short_description: Helper object to handle connection properties.
*
* The #MMSimpleConnectProperties is an object handling the properties requested
* to ModemManager when launching a connection with the Simple interface.
*
* This object is created by the user and passed to ModemManager with either
* mm_modem_simple_connect() or mm_modem_simple_connect_sync().
*/
G_DEFINE_TYPE (MMSimpleConnectProperties, mm_simple_connect_properties, G_TYPE_OBJECT); G_DEFINE_TYPE (MMSimpleConnectProperties, mm_simple_connect_properties, G_TYPE_OBJECT);
#define PROPERTY_PIN "pin" #define PROPERTY_PIN "pin"
@@ -46,6 +58,13 @@ struct _MMSimpleConnectPropertiesPrivate {
/*****************************************************************************/ /*****************************************************************************/
/**
* mm_simple_connect_properties_set_pin:
* @self: a #MMSimpleConnectProperties.
* @pin: PIN code.
*
* Sets the PIN code to use when unlocking the modem.
*/
void void
mm_simple_connect_properties_set_pin (MMSimpleConnectProperties *self, mm_simple_connect_properties_set_pin (MMSimpleConnectProperties *self,
const gchar *pin) const gchar *pin)
@@ -56,6 +75,31 @@ mm_simple_connect_properties_set_pin (MMSimpleConnectProperties *self,
self->priv->pin = g_strdup (pin); self->priv->pin = g_strdup (pin);
} }
/**
* mm_simple_connect_properties_get_pin:
* @self: a #MMSimpleConnectProperties.
*
* Gets the PIN code to use when unlocking the modem.
*
* Returns: (transfer none): the PIN, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar *
mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return self->priv->pin;
}
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_operator_id:
* @self: a #MMSimpleConnectProperties.
* @operator_id: operator ID, given as MCC/MNC.
*
* Sets the ID of the network to which register before connecting.
*/
void void
mm_simple_connect_properties_set_operator_id (MMSimpleConnectProperties *self, mm_simple_connect_properties_set_operator_id (MMSimpleConnectProperties *self,
const gchar *operator_id) const gchar *operator_id)
@@ -66,6 +110,32 @@ mm_simple_connect_properties_set_operator_id (MMSimpleConnectProperties *self,
self->priv->operator_id = g_strdup (operator_id); self->priv->operator_id = g_strdup (operator_id);
} }
/**
* mm_simple_connect_properties_get_operator_id:
* @self: a #MMSimpleConnectProperties.
*
* Gets the ID of the network to which register before connecting.
*
* Returns: (transfer none): the operator ID, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar *
mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return self->priv->operator_id;
}
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_bands:
* @self: a #MMSimpleConnectProperties.
* @bands: array of #MMModemBand values.
* @n_bands: number of elements in @bands.
*
* Sets the frequency bands to use.
*/
void void
mm_simple_connect_properties_set_bands (MMSimpleConnectProperties *self, mm_simple_connect_properties_set_bands (MMSimpleConnectProperties *self,
const MMModemBand *bands, const MMModemBand *bands,
@@ -82,104 +152,16 @@ mm_simple_connect_properties_set_bands (MMSimpleConnectProperties *self,
self->priv->bands_set = TRUE; self->priv->bands_set = TRUE;
} }
void /**
mm_simple_connect_properties_set_allowed_modes (MMSimpleConnectProperties *self, * mm_simple_connect_properties_get_bands:
MMModemMode allowed, * @self: a #MMSimpleConnectProperties.
MMModemMode preferred) * @bands: (out): location for the array of #MMModemBand values. Do not free the returned value, it is owned by @self.
{ * @n_bands: (out) number of elements in @bands.
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self)); *
* Gets the frequency bands to use.
self->priv->allowed_modes = allowed; *
self->priv->preferred_mode = preferred; * Returns: %TRUE if @bands is set, %FALSE otherwise.
self->priv->allowed_modes_set = TRUE; */
}
void
mm_simple_connect_properties_set_apn (MMSimpleConnectProperties *self,
const gchar *apn)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_apn (self->priv->bearer_properties,
apn);
}
void
mm_simple_connect_properties_set_user (MMSimpleConnectProperties *self,
const gchar *user)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_user (self->priv->bearer_properties,
user);
}
void
mm_simple_connect_properties_set_password (MMSimpleConnectProperties *self,
const gchar *password)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_password (self->priv->bearer_properties,
password);
}
void
mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *self,
MMBearerIpFamily ip_type)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_ip_type (self->priv->bearer_properties,
ip_type);
}
void
mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *self,
gboolean allow_roaming)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_allow_roaming (self->priv->bearer_properties,
allow_roaming);
}
void
mm_simple_connect_properties_set_number (MMSimpleConnectProperties *self,
const gchar *number)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_number (self->priv->bearer_properties,
number);
}
/*****************************************************************************/
MMBearerProperties *
mm_simple_connect_properties_get_bearer_properties (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return g_object_ref (self->priv->bearer_properties);
}
const gchar *
mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return self->priv->pin;
}
const gchar *
mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return self->priv->operator_id;
}
gboolean gboolean
mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *self, mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *self,
const MMModemBand **bands, const MMModemBand **bands,
@@ -198,6 +180,38 @@ mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *self,
return FALSE; return FALSE;
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_allowed_modes:
* @self: a #MMSimpleConnectProperties.
* @allowed: bitmask of #MMModemMode values specifying which are allowed.
* @preferred: a #MMModemMode value, specifying which of the ones in @allowed is preferred, if any.
*
* Sets the modes allowed to use, and which of them is preferred.
*/
void
mm_simple_connect_properties_set_allowed_modes (MMSimpleConnectProperties *self,
MMModemMode allowed,
MMModemMode preferred)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
self->priv->allowed_modes = allowed;
self->priv->preferred_mode = preferred;
self->priv->allowed_modes_set = TRUE;
}
/**
* mm_simple_connect_properties_get_allowed_modes:
* @self: a #MMSimpleConnectProperties.
* @allowed: (out): location for the bitmask of #MMModemMode values specifying which are allowed.
* @preferred: (out): loction for a #MMModemMode value, specifying which of the ones in @allowed is preferred, if any.
*
* Gets the modes allowed to use, and which of them is preferred.
*
* Returns: %TRUE if @allowed and @preferred are set, %FALSE otherwise.
*/
gboolean gboolean
mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *self, mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *self,
MMModemMode *allowed, MMModemMode *allowed,
@@ -216,6 +230,33 @@ mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *self,
return FALSE; return FALSE;
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_apn:
* @self: a #MMSimpleConnectProperties.
* @apn: Name of the access point.
*
* Sets the name of the access point to use when connecting.
*/
void
mm_simple_connect_properties_set_apn (MMSimpleConnectProperties *self,
const gchar *apn)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_apn (self->priv->bearer_properties,
apn);
}
/**
* mm_simple_connect_properties_get_apn:
* @self: a #MMSimpleConnectProperties.
*
* Gets the name of the access point to use when connecting.
*
* Returns: (transfer none): the access point, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar * const gchar *
mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self)
{ {
@@ -224,6 +265,33 @@ mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self)
return mm_bearer_properties_get_apn (self->priv->bearer_properties); return mm_bearer_properties_get_apn (self->priv->bearer_properties);
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_user:
* @self: a #MMSimpleConnectProperties.
* @user: the username
*
* Sets the username used to authenticate with the access point.
*/
void
mm_simple_connect_properties_set_user (MMSimpleConnectProperties *self,
const gchar *user)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_user (self->priv->bearer_properties,
user);
}
/**
* mm_simple_connect_properties_get_user:
* @self: a #MMSimpleConnectProperties.
*
* Gets the username used to authenticate with the access point.
*
* Returns: (transfer none): the username, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar * const gchar *
mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self)
{ {
@@ -232,6 +300,33 @@ mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self)
return mm_bearer_properties_get_user (self->priv->bearer_properties); return mm_bearer_properties_get_user (self->priv->bearer_properties);
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_password:
* @self: a #MMSimpleConnectProperties.
* @password: the password
*
* Sets the password used to authenticate with the access point.
*/
void
mm_simple_connect_properties_set_password (MMSimpleConnectProperties *self,
const gchar *password)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_password (self->priv->bearer_properties,
password);
}
/**
* mm_simple_connect_properties_get_password:
* @self: a #MMSimpleConnectProperties.
*
* Gets the password used to authenticate with the access point.
*
* Returns: (transfer none): the password, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar * const gchar *
mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self)
{ {
@@ -240,6 +335,33 @@ mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self)
return mm_bearer_properties_get_password (self->priv->bearer_properties); return mm_bearer_properties_get_password (self->priv->bearer_properties);
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_ip_type:
* @self: a #MMSimpleConnectProperties.
* @ip_type: a #MMBearerIpFamily.
*
* Sets the IP type to use.
*/
void
mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *self,
MMBearerIpFamily ip_type)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_ip_type (self->priv->bearer_properties,
ip_type);
}
/**
* mm_simple_connect_properties_get_ip_type:
* @self: a #MMSimpleConnectProperties.
*
* Sets the IP type to use.
*
* Returns: a #MMBearerIpFamily.
*/
MMBearerIpFamily MMBearerIpFamily
mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self)
{ {
@@ -248,6 +370,34 @@ mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self)
return mm_bearer_properties_get_ip_type (self->priv->bearer_properties); return mm_bearer_properties_get_ip_type (self->priv->bearer_properties);
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_allow_roaming:
* @self: a #MMSimpleConnectProperties.
* @allow_roaming: boolean value.
*
* Sets the flag to indicate whether roaming is allowed or not in the
* connection.
*/
void
mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *self,
gboolean allow_roaming)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_allow_roaming (self->priv->bearer_properties,
allow_roaming);
}
/**
* mm_simple_connect_properties_get_allow_roaming:
* @self: a #MMSimpleConnectProperties.
*
* Checks whether roaming is allowed in the connection.
*
* Returns: %TRUE if roaming is allowed, %FALSE otherwise..
*/
gboolean gboolean
mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self)
{ {
@@ -256,6 +406,34 @@ mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self)
return mm_bearer_properties_get_allow_roaming (self->priv->bearer_properties); return mm_bearer_properties_get_allow_roaming (self->priv->bearer_properties);
} }
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_number:
* @self: a #MMSimpleConnectProperties.
* @number: the number.
*
* Sets the number to use when performing the connection.
*/
void
mm_simple_connect_properties_set_number (MMSimpleConnectProperties *self,
const gchar *number)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_number (self->priv->bearer_properties,
number);
}
/**
* mm_simple_connect_properties_get_number:
* @self: a #MMSimpleConnectProperties.
*
* Gets the number to use when performing the connection.
*
* Returns: (transfer none): the number, or #NULL if not set. Do not free the returned value, it is owned by @self.
*/
const gchar * const gchar *
mm_simple_connect_properties_get_number (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_number (MMSimpleConnectProperties *self)
{ {
@@ -266,6 +444,16 @@ mm_simple_connect_properties_get_number (MMSimpleConnectProperties *self)
/*****************************************************************************/ /*****************************************************************************/
MMBearerProperties *
mm_simple_connect_properties_get_bearer_properties (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), NULL);
return g_object_ref (self->priv->bearer_properties);
}
/*****************************************************************************/
GVariant * GVariant *
mm_simple_connect_properties_get_dictionary (MMSimpleConnectProperties *self) mm_simple_connect_properties_get_dictionary (MMSimpleConnectProperties *self)
{ {
@@ -332,7 +520,7 @@ mm_simple_connect_properties_get_dictionary (MMSimpleConnectProperties *self)
/*****************************************************************************/ /*****************************************************************************/
typedef struct { typedef struct {
MMSimpleConnectProperties *properties; MMSimpleConnectProperties *self;
GError *error; GError *error;
gchar *allowed_modes_str; gchar *allowed_modes_str;
gchar *preferred_mode_str; gchar *preferred_mode_str;
@@ -344,22 +532,22 @@ key_value_foreach (const gchar *key,
ParseKeyValueContext *ctx) ParseKeyValueContext *ctx)
{ {
/* First, check if we can consume this as bearer properties */ /* First, check if we can consume this as bearer properties */
if (mm_bearer_properties_consume_string (ctx->properties->priv->bearer_properties, if (mm_bearer_properties_consume_string (ctx->self->priv->bearer_properties,
key, value, key, value,
NULL)) NULL))
return TRUE; return TRUE;
if (g_str_equal (key, PROPERTY_PIN)) if (g_str_equal (key, PROPERTY_PIN))
mm_simple_connect_properties_set_pin (ctx->properties, value); mm_simple_connect_properties_set_pin (ctx->self, value);
else if (g_str_equal (key, PROPERTY_OPERATOR_ID)) else if (g_str_equal (key, PROPERTY_OPERATOR_ID))
mm_simple_connect_properties_set_operator_id (ctx->properties, value); mm_simple_connect_properties_set_operator_id (ctx->self, value);
else if (g_str_equal (key, PROPERTY_BANDS)) { else if (g_str_equal (key, PROPERTY_BANDS)) {
MMModemBand *bands = NULL; MMModemBand *bands = NULL;
guint n_bands = 0; guint n_bands = 0;
mm_common_get_bands_from_string (value, &bands, &n_bands, &ctx->error); mm_common_get_bands_from_string (value, &bands, &n_bands, &ctx->error);
if (!ctx->error) { if (!ctx->error) {
mm_simple_connect_properties_set_bands (ctx->properties, bands, n_bands); mm_simple_connect_properties_set_bands (ctx->self, bands, n_bands);
g_free (bands); g_free (bands);
} }
} else if (g_str_equal (key, PROPERTY_ALLOWED_MODES)) { } else if (g_str_equal (key, PROPERTY_ALLOWED_MODES)) {
@@ -385,7 +573,7 @@ mm_simple_connect_properties_new_from_string (const gchar *str,
ctx.error = NULL; ctx.error = NULL;
ctx.allowed_modes_str = NULL; ctx.allowed_modes_str = NULL;
ctx.preferred_mode_str = NULL; ctx.preferred_mode_str = NULL;
ctx.properties = mm_simple_connect_properties_new (); ctx.self = mm_simple_connect_properties_new ();
mm_common_parse_key_value_string (str, mm_common_parse_key_value_string (str,
&ctx.error, &ctx.error,
@@ -395,8 +583,8 @@ mm_simple_connect_properties_new_from_string (const gchar *str,
/* If error, destroy the object */ /* If error, destroy the object */
if (ctx.error) { if (ctx.error) {
g_propagate_error (error, ctx.error); g_propagate_error (error, ctx.error);
g_object_unref (ctx.properties); g_object_unref (ctx.self);
ctx.properties = NULL; ctx.self = NULL;
} }
else if (ctx.allowed_modes_str || ctx.preferred_mode_str) { else if (ctx.allowed_modes_str || ctx.preferred_mode_str) {
MMModemMode allowed_modes; MMModemMode allowed_modes;
@@ -415,11 +603,11 @@ mm_simple_connect_properties_new_from_string (const gchar *str,
if (ctx.error) { if (ctx.error) {
g_propagate_error (error, ctx.error); g_propagate_error (error, ctx.error);
g_object_unref (ctx.properties); g_object_unref (ctx.self);
ctx.properties = NULL; ctx.self = NULL;
} else { } else {
mm_simple_connect_properties_set_allowed_modes ( mm_simple_connect_properties_set_allowed_modes (
ctx.properties, ctx.self,
allowed_modes, allowed_modes,
preferred_mode); preferred_mode);
} }
@@ -428,7 +616,7 @@ mm_simple_connect_properties_new_from_string (const gchar *str,
g_free (ctx.allowed_modes_str); g_free (ctx.allowed_modes_str);
g_free (ctx.preferred_mode_str); g_free (ctx.preferred_mode_str);
return ctx.properties; return ctx.self;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -441,13 +629,13 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
GVariantIter iter; GVariantIter iter;
gchar *key; gchar *key;
GVariant *value; GVariant *value;
MMSimpleConnectProperties *properties; MMSimpleConnectProperties *self;
GVariant *allowed_modes_variant = NULL; GVariant *allowed_modes_variant = NULL;
GVariant *preferred_mode_variant = NULL; GVariant *preferred_mode_variant = NULL;
properties = mm_simple_connect_properties_new (); self = mm_simple_connect_properties_new ();
if (!dictionary) if (!dictionary)
return properties; return self;
if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) { if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) {
g_set_error (error, g_set_error (error,
@@ -455,7 +643,7 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
MM_CORE_ERROR_INVALID_ARGS, MM_CORE_ERROR_INVALID_ARGS,
"Cannot create Simple Connect properties from dictionary: " "Cannot create Simple Connect properties from dictionary: "
"invalid variant type received"); "invalid variant type received");
g_object_unref (properties); g_object_unref (self);
return NULL; return NULL;
} }
@@ -464,23 +652,23 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
g_variant_iter_next (&iter, "{sv}", &key, &value)) { g_variant_iter_next (&iter, "{sv}", &key, &value)) {
/* First, check if we can consume this as bearer properties */ /* First, check if we can consume this as bearer properties */
if (!mm_bearer_properties_consume_variant (properties->priv->bearer_properties, if (!mm_bearer_properties_consume_variant (self->priv->bearer_properties,
key, value, key, value,
NULL)) { NULL)) {
if (g_str_equal (key, PROPERTY_PIN)) if (g_str_equal (key, PROPERTY_PIN))
mm_simple_connect_properties_set_pin ( mm_simple_connect_properties_set_pin (
properties, self,
g_variant_get_string (value, NULL)); g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_OPERATOR_ID)) else if (g_str_equal (key, PROPERTY_OPERATOR_ID))
mm_simple_connect_properties_set_operator_id ( mm_simple_connect_properties_set_operator_id (
properties, self,
g_variant_get_string (value, NULL)); g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_BANDS)) { else if (g_str_equal (key, PROPERTY_BANDS)) {
GArray *array; GArray *array;
array = mm_common_bands_variant_to_garray (value); array = mm_common_bands_variant_to_garray (value);
mm_simple_connect_properties_set_bands ( mm_simple_connect_properties_set_bands (
properties, self,
(MMModemBand *)array->data, (MMModemBand *)array->data,
array->len); array->len);
g_array_unref (array); g_array_unref (array);
@@ -504,13 +692,13 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
/* If error, destroy the object */ /* If error, destroy the object */
if (inner_error) { if (inner_error) {
g_propagate_error (error, inner_error); g_propagate_error (error, inner_error);
g_object_unref (properties); g_object_unref (self);
properties = NULL; self = NULL;
} }
/* If we got allowed modes variant, check if we got preferred mode */ /* If we got allowed modes variant, check if we got preferred mode */
else if (allowed_modes_variant) { else if (allowed_modes_variant) {
mm_simple_connect_properties_set_allowed_modes ( mm_simple_connect_properties_set_allowed_modes (
properties, self,
g_variant_get_uint32 (allowed_modes_variant), g_variant_get_uint32 (allowed_modes_variant),
(preferred_mode_variant ? (preferred_mode_variant ?
g_variant_get_uint32 (preferred_mode_variant) : g_variant_get_uint32 (preferred_mode_variant) :
@@ -519,7 +707,7 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
/* If we only got preferred mode, assume allowed is ANY */ /* If we only got preferred mode, assume allowed is ANY */
else if (preferred_mode_variant) { else if (preferred_mode_variant) {
mm_simple_connect_properties_set_allowed_modes ( mm_simple_connect_properties_set_allowed_modes (
properties, self,
MM_MODEM_MODE_ANY, MM_MODEM_MODE_ANY,
g_variant_get_uint32 (preferred_mode_variant)); g_variant_get_uint32 (preferred_mode_variant));
} }
@@ -530,11 +718,18 @@ mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
if (preferred_mode_variant) if (preferred_mode_variant)
g_variant_unref (preferred_mode_variant); g_variant_unref (preferred_mode_variant);
return properties; return self;
} }
/*****************************************************************************/ /*****************************************************************************/
/**
* mm_simple_connect_properties_new:
*
* Creates a new empty #MMSimpleConnectProperties.
*
* Returns: (transfer full): a #MMSimpleConnectProperties. The returned value should be freed with g_object_unref().
*/
MMSimpleConnectProperties * MMSimpleConnectProperties *
mm_simple_connect_properties_new (void) mm_simple_connect_properties_new (void)
{ {

View File

@@ -38,64 +38,82 @@ typedef struct _MMSimpleConnectProperties MMSimpleConnectProperties;
typedef struct _MMSimpleConnectPropertiesClass MMSimpleConnectPropertiesClass; typedef struct _MMSimpleConnectPropertiesClass MMSimpleConnectPropertiesClass;
typedef struct _MMSimpleConnectPropertiesPrivate MMSimpleConnectPropertiesPrivate; typedef struct _MMSimpleConnectPropertiesPrivate MMSimpleConnectPropertiesPrivate;
/**
* MMSimpleConnectProperties:
*
* The #MMSimpleConnectProperties structure contains private data and should
* only be accessed using the provided API.
*/
struct _MMSimpleConnectProperties { struct _MMSimpleConnectProperties {
/*< private >*/
GObject parent; GObject parent;
MMSimpleConnectPropertiesPrivate *priv; MMSimpleConnectPropertiesPrivate *priv;
}; };
struct _MMSimpleConnectPropertiesClass { struct _MMSimpleConnectPropertiesClass {
/*< private >*/
GObjectClass parent; GObjectClass parent;
}; };
GType mm_simple_connect_properties_get_type (void); GType mm_simple_connect_properties_get_type (void);
MMSimpleConnectProperties *mm_simple_connect_properties_new (void); MMSimpleConnectProperties *mm_simple_connect_properties_new (void);
void mm_simple_connect_properties_set_pin (MMSimpleConnectProperties *self,
const gchar *pin);
void mm_simple_connect_properties_set_operator_id (MMSimpleConnectProperties *self,
const gchar *operator_id);
void mm_simple_connect_properties_set_bands (MMSimpleConnectProperties *self,
const MMModemBand *bands,
guint n_bands);
void mm_simple_connect_properties_set_allowed_modes (MMSimpleConnectProperties *self,
MMModemMode allowed,
MMModemMode preferred);
void mm_simple_connect_properties_set_apn (MMSimpleConnectProperties *self,
const gchar *apn);
void mm_simple_connect_properties_set_user (MMSimpleConnectProperties *self,
const gchar *user);
void mm_simple_connect_properties_set_password (MMSimpleConnectProperties *self,
const gchar *password);
void mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *self,
MMBearerIpFamily ip_type);
void mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *self,
gboolean allow_roaming);
void mm_simple_connect_properties_set_number (MMSimpleConnectProperties *self,
const gchar *number);
const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *self);
gboolean mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *self,
const MMModemBand **bands,
guint *n_bands);
gboolean mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *self,
MMModemMode *allowed,
MMModemMode *preferred);
const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self);
MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self);
gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_number (MMSimpleConnectProperties *self);
/*****************************************************************************/
/* ModemManager/libmm-glib/mmcli specific methods */
#if defined (_LIBMM_INSIDE_MM) || \
defined (_LIBMM_INSIDE_MMCLI) || \
defined (LIBMM_GLIB_COMPILATION)
MMSimpleConnectProperties *mm_simple_connect_properties_new_from_string (const gchar *str, MMSimpleConnectProperties *mm_simple_connect_properties_new_from_string (const gchar *str,
GError **error); GError **error);
MMSimpleConnectProperties *mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary, MMSimpleConnectProperties *mm_simple_connect_properties_new_from_dictionary (GVariant *dictionary,
GError **error); GError **error);
void mm_simple_connect_properties_set_pin (MMSimpleConnectProperties *properties,
const gchar *pin);
void mm_simple_connect_properties_set_operator_id (MMSimpleConnectProperties *properties,
const gchar *operator_id);
void mm_simple_connect_properties_set_bands (MMSimpleConnectProperties *properties,
const MMModemBand *bands,
guint n_bands);
void mm_simple_connect_properties_set_allowed_modes (MMSimpleConnectProperties *properties,
MMModemMode allowed,
MMModemMode preferred);
void mm_simple_connect_properties_set_apn (MMSimpleConnectProperties *properties,
const gchar *apn);
void mm_simple_connect_properties_set_user (MMSimpleConnectProperties *properties,
const gchar *user);
void mm_simple_connect_properties_set_password (MMSimpleConnectProperties *properties,
const gchar *password);
void mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *properties,
MMBearerIpFamily ip_type);
void mm_simple_connect_properties_set_allow_roaming (MMSimpleConnectProperties *properties,
gboolean allow_roaming);
void mm_simple_connect_properties_set_number (MMSimpleConnectProperties *properties,
const gchar *number);
const gchar *mm_simple_connect_properties_get_pin (MMSimpleConnectProperties *properties);
const gchar *mm_simple_connect_properties_get_operator_id (MMSimpleConnectProperties *properties);
gboolean mm_simple_connect_properties_get_bands (MMSimpleConnectProperties *properties,
const MMModemBand **bands,
guint *n_bands);
gboolean mm_simple_connect_properties_get_allowed_modes (MMSimpleConnectProperties *properties,
MMModemMode *allowed,
MMModemMode *preferred);
const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *properties);
const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *properties);
const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *properties);
MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *properties);
gboolean mm_simple_connect_properties_get_allow_roaming (MMSimpleConnectProperties *properties);
const gchar *mm_simple_connect_properties_get_number (MMSimpleConnectProperties *properties);
MMBearerProperties *mm_simple_connect_properties_get_bearer_properties (MMSimpleConnectProperties *properties); MMBearerProperties *mm_simple_connect_properties_get_bearer_properties (MMSimpleConnectProperties *properties);
GVariant *mm_simple_connect_properties_get_dictionary (MMSimpleConnectProperties *self); GVariant *mm_simple_connect_properties_get_dictionary (MMSimpleConnectProperties *self);
#endif
G_END_DECLS G_END_DECLS