TnyMaemoConicDevice: slight cleanup
- From: Murray Cumming <murrayc murrayc com>
- To: tinymail-devel-list gnome org
- Subject: TnyMaemoConicDevice: slight cleanup
- Date: Thu, 26 Apr 2007 15:01:34 +0200
This patch is not very necessary, but it makes me feel better. Could
someone apply it, or give me rights to apply it, please.
--
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
Index: libtinymail-maemo/tny-maemo-conic-device.c
===================================================================
--- libtinymail-maemo/tny-maemo-conic-device.c (revision 1839)
+++ libtinymail-maemo/tny-maemo-conic-device.c (working copy)
@@ -29,7 +29,7 @@
typedef struct {
ConIcConnection *cnx;
gboolean is_online;
- const gchar *iap;
+ gchar *iap;
} TnyMaemoConicDevicePriv;
#define TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE(o) \
@@ -48,7 +48,7 @@
{
TnyMaemoConicDevice *device;
TnyMaemoConicDevicePriv *priv;
- gboolean is_online;
+ gboolean is_online = FALSE;
g_return_if_fail (CON_IC_IS_CONNECTION(cnx));
g_return_if_fail (user_data);
@@ -82,7 +82,7 @@
switch (con_ic_connection_event_get_status(event)) {
case CON_IC_STATUS_CONNECTED:
- priv->iap = con_ic_event_get_iap_id ((ConIcEvent*)(event));
+ priv->iap = g_strdup (con_ic_event_get_iap_id ((ConIcEvent*)(event)));
is_online = TRUE;
break;
case CON_IC_STATUS_DISCONNECTED:
@@ -116,11 +116,13 @@
gboolean
tny_maemo_conic_device_connect (TnyMaemoConicDevice *self, const gchar* iap_id)
{
- TnyMaemoConicDevicePriv *priv;
+ TnyMaemoConicDevicePriv *priv;
g_return_if_fail (TNY_IS_DEVICE(self));
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
+ g_return_val_if_fail (priv->cnx, FALSE);
+
if (iap_id) {
if (!con_ic_connection_connect_by_id (priv->cnx, iap_id, CON_IC_CONNECT_FLAG_NONE)) {
g_warning ("could not send connect_by_id dbus message");
@@ -152,8 +154,11 @@
TnyMaemoConicDevicePriv *priv;
g_return_if_fail (TNY_IS_MAEMO_CONIC_DEVICE(self));
+ g_return_val_if_fail (priv->cnx, FALSE);
+
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
+
if (iap_id) {
if (!con_ic_connection_disconnect_by_id (priv->cnx, iap_id)) {
g_warning ("could not send disconnect_by_id dbus message");
@@ -211,6 +216,7 @@
g_return_val_if_fail (TNY_IS_MAEMO_CONIC_DEVICE(self), NULL);
g_return_val_if_fail (iap_id, NULL);
+ g_return_val_if_fail (priv->cnx, NULL);
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
@@ -234,6 +240,7 @@
TnyMaemoConicDevicePriv *priv;
g_return_val_if_fail (TNY_IS_MAEMO_CONIC_DEVICE(self), NULL);
+ g_return_val_if_fail (priv->cnx, NULL);
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
@@ -271,6 +278,8 @@
#endif /*MAEMO_CONIC_DUMMY*/
g_return_if_fail (TNY_IS_DEVICE(self));
+ g_return_if_fail (priv->cnx);
+
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
if (!con_ic_connection_connect (priv->cnx, CON_IC_CONNECT_FLAG_NONE))
@@ -288,6 +297,8 @@
#endif /*MAEMO_CONIC_DUMMY*/
g_return_if_fail (TNY_IS_DEVICE(self));
+ g_return_if_fail (priv->cnx);
+
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
if (!con_ic_connection_disconnect (priv->cnx))
@@ -312,8 +323,24 @@
tny_maemo_conic_device_instance_init (GTypeInstance *instance, gpointer g_class)
{
TnyMaemoConicDevice *self = (TnyMaemoConicDevice *)instance;
+
TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
+ priv->iap = NULL;
+ priv->cnx = con_ic_connection_new ();
+ if (!priv->cnx) {
+ g_warning ("con_ic_connection_new failed. The TnyMaemoConicDevice will be useless.");
+ }
+ g_signal_connect (priv->cnx, "connection-event",
+ G_CALLBACK(on_connection_event), self);
+
+ /*
+ * this will get us in connected state only if there is already a connection.
+ * thus, this will setup our state correctly when we receive the signals
+ */
+ if (!con_ic_connection_connect (priv->cnx, CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED))
+ g_warning ("could not send connect dbus message");
+
priv->is_online = FALSE;
}
@@ -327,29 +354,7 @@
TnyDevice*
tny_maemo_conic_device_new (void)
{
- TnyMaemoConicDevice *self;
- TnyMaemoConicDevicePriv *priv;
-
- self = g_object_new (TNY_TYPE_MAEMO_CONIC_DEVICE, NULL);
- priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self);
-
- priv->iap = NULL;
- priv->cnx = con_ic_connection_new ();
- if (!priv->cnx) {
- g_warning ("con_ic_connection_new failed");
- g_object_unref (self);
- return NULL;
- }
- g_signal_connect (priv->cnx, "connection-event",
- G_CALLBACK(on_connection_event), self);
-
- /*
- * this will get us in connected state only if there is already a connection.
- * thus, this will setup our state correctly when we receive the signals
- */
- if (!con_ic_connection_connect (priv->cnx, CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED))
- g_warning ("could not send connect dbus message");
-
+ TnyMaemoConicDevice *self = g_object_new (TNY_TYPE_MAEMO_CONIC_DEVICE, NULL);
return TNY_DEVICE (self);
}
@@ -358,13 +363,17 @@
{
TnyMaemoConicDevicePriv *priv;
priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (obj);
- if (CON_IC_IS_CONNECTION(priv->cnx)) {
+ if (priv->cnx && CON_IC_IS_CONNECTION(priv->cnx)) {
if (!con_ic_connection_disconnect (priv->cnx))
g_warning ("failed to send disconnect dbus message");
g_object_unref (priv->cnx);
priv->cnx = NULL;
+ }
+
+ if (priv->iap) {
+ g_free (priv->iap);
priv->iap = NULL;
- }
+ }
(*parent_class->finalize) (obj);
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 1839)
+++ ChangeLog (working copy)
@@ -1,3 +1,22 @@
+2007-04-26 Murray Cumming <murrayc murrayc com>
+
+ * libtinymail-maemo/tny-maemo-conic-device.c:
+ (tny_maemo_conic_device_instance_init),
+ (tny_maemo_conic_device_new): Do all the initialization in init, because
+ _new functions should just call g_object_new() and not access private API,
+ because they are just C convenience functions.
+ (on_connection_event), (tny_maemo_conic_device_connect),
+ (tny_maemo_conic_device_disconnect),
+ (tny_maemo_conic_device_get_iap),
+ (tny_maemo_conic_device_get_iap_list),
+ (tny_maemo_conic_device_force_online),
+ (tny_maemo_conic_device_force_offline),
+ (tny_maemo_conic_device_finalize):
+ Copy the iap string instead of just storing the pointer, because we have no
+ guarantees about the lifetime of the string that con_ic_event_get_iap_id()
+ returns. Free it in finalize.
+ Added g_return_if*() checks for priv->cnx, without which nothing could work.
+
2007-04-23 Philip Van Hoof <pvanhoof gnome org>
* tny_folder_change_set_received_msg,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]