Re: [PATCH 5/7] time: implement ModemTime in ModemBase
- From: Aleksander Morgado <aleksander lanedo com>
- To: Thomas Tuttle <ttuttle chromium org>
- Cc: networkmanager-list gnome org
- Subject: Re: [PATCH 5/7] time: implement ModemTime in ModemBase
- Date: Sat, 21 Jan 2012 10:58:00 +0100
>
> +static GValue *
> +int_to_gvalue (gint i)
> +{
> + GValue *v = g_slice_new0 (GValue);
> + g_value_init (v, G_TYPE_INT);
> + g_value_set_int (v, i);
> + return v;
> +}
> +
> +static void
> +value_destroy (gpointer data)
> +{
> + GValue *v = (GValue *) data;
> + g_value_unset (v);
> + g_slice_free (GValue, v);
> +}
> +
> +void
> +mm_modem_base_set_network_timezone (MMModemBase *self, gint *offset,
> + gint *dst_offset, gint *leap_seconds)
> +{
> + MMModemBasePrivate *priv;
> +
> + g_return_if_fail (self != NULL);
> + g_return_if_fail (MM_IS_MODEM_BASE (self));
> +
> + priv = MM_MODEM_BASE_GET_PRIVATE (self);
> +
> + if (offset)
> + g_hash_table_replace (priv->tz_data, "offset", int_to_gvalue (*offset));
> + else
> + g_hash_table_remove (priv->tz_data, "offset");
> +
> + if (dst_offset)
> + g_hash_table_replace (priv->tz_data, "dst_offset", int_to_gvalue (*dst_offset));
> + else
> + g_hash_table_remove (priv->tz_data, "dst_offset");
> +
> + if (leap_seconds)
> + g_hash_table_replace (priv->tz_data, "leap_seconds", int_to_gvalue (*leap_seconds));
> + else
> + g_hash_table_remove (priv->tz_data, "leap_seconds");
> +
> + g_object_notify (G_OBJECT (self), MM_MODEM_TIME_NETWORK_TIMEZONE);
> +}
If you just need to store a signed integer as the value of an entry in
the hash table, you can better use GINT_TO_POINTER (integer) and
GPOINTER_TO_INT (pointer), instead of packing the integer into a GValue.
> +
> /*************************************************************************/
> static void
> card_info_simple_invoke (MMCallbackInfo *info)
> @@ -693,6 +744,36 @@ modem_auth_finish (MMModem *modem, MMAuthRequest *req, GError **error)
> /*****************************************************************************/
>
> static void
> +get_network_time_invoke (MMCallbackInfo *info)
> +{
> + MMModemTimeGetNetworkTimeFn callback = (MMModemTimeGetNetworkTimeFn) info->callback;
> + MMModemTime *modem = MM_MODEM_TIME (info->modem);
> + char *network_time = (char *) mm_callback_info_get_result (info);
> +
> + callback (modem, network_time, info->error, info->user_data);
> +}
> +
> +static void
> +get_network_time (MMModemTime *modem,
> + MMModemTimeGetNetworkTimeFn callback,
> + gpointer user_data)
> +{
> + MMModemBase *self = MM_MODEM_BASE (modem);
> + MMCallbackInfo *info;
> +
> + char *network_time = g_strdup("");
> +
> + info = mm_callback_info_new_full (MM_MODEM (self),
> + get_network_time_invoke,
> + G_CALLBACK (callback),
> + user_data);
> + mm_callback_info_set_result (info, network_time, g_free);
> + mm_callback_info_schedule (info);
> +}
Given that the network time will be reported upon request, I would
really just return a "not implemented" error instead of the empty string
when the network time query is not implemented.
--
Aleksander
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]