core: make sure objects retrieved with g_object_get() are valid in the ifaces

The interfaces usually retrieve objects (e.g. skeletons) from the Modem object
using g_object_get(), but we didn't make sure that these objects were actually
valid before using them.

This should clean up errors happening when the modem gets unplugged and still
some actions are ongoing.

Should fix https://bugzilla.gnome.org/show_bug.cgi?id=685933
This commit is contained in:
Aleksander Morgado
2012-10-11 11:41:15 +02:00
parent 224b737099
commit c16bcdf68c
9 changed files with 749 additions and 828 deletions

View File

@@ -184,7 +184,8 @@ update_network_timezone_dictionary (MMIfaceModemTime *self,
g_object_get (self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &skeleton,
NULL);
g_assert (skeleton != NULL);
if (!skeleton)
return;
dictionary = mm_network_timezone_get_dictionary (tz);
mm_gdbus_modem_time_set_network_timezone (skeleton, dictionary);
@@ -374,6 +375,8 @@ mm_iface_modem_time_update_network_time (MMIfaceModemTime *self,
g_object_get (self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &skeleton,
NULL);
if (!skeleton)
return;
/* Notify about the updated network time */
mm_gdbus_modem_time_emit_network_time_changed (skeleton, network_time);
@@ -401,35 +404,14 @@ struct _DisablingContext {
MmGdbusModemTime *skeleton;
};
static DisablingContext *
disabling_context_new (MMIfaceModemTime *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
DisablingContext *ctx;
ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
disabling_context_new);
ctx->step = DISABLING_STEP_FIRST;
g_object_get (ctx->self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &ctx->skeleton,
NULL);
g_assert (ctx->skeleton != NULL);
return ctx;
}
static void
disabling_context_complete_and_free (DisablingContext *ctx)
{
g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self);
g_object_unref (ctx->result);
g_object_unref (ctx->skeleton);
if (ctx->skeleton)
g_object_unref (ctx->skeleton);
g_free (ctx);
}
@@ -548,9 +530,28 @@ mm_iface_modem_time_disable (MMIfaceModemTime *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
interface_disabling_step (disabling_context_new (self,
callback,
user_data));
DisablingContext *ctx;
ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_iface_modem_time_disable);
ctx->step = DISABLING_STEP_FIRST;
g_object_get (ctx->self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &ctx->skeleton,
NULL);
if (!ctx->skeleton) {
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't get interface skeleton");
disabling_context_complete_and_free (ctx);
return;
}
interface_disabling_step (ctx);
}
/*****************************************************************************/
@@ -574,30 +575,6 @@ struct _EnablingContext {
MmGdbusModemTime *skeleton;
};
static EnablingContext *
enabling_context_new (MMIfaceModemTime *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
EnablingContext *ctx;
ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self);
ctx->cancellable = g_object_ref (cancellable);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
enabling_context_new);
ctx->step = ENABLING_STEP_FIRST;
g_object_get (ctx->self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &ctx->skeleton,
NULL);
g_assert (ctx->skeleton != NULL);
return ctx;
}
static void
enabling_context_complete_and_free (EnablingContext *ctx)
{
@@ -605,7 +582,8 @@ enabling_context_complete_and_free (EnablingContext *ctx)
g_object_unref (ctx->self);
g_object_unref (ctx->result);
g_object_unref (ctx->cancellable);
g_object_unref (ctx->skeleton);
if (ctx->skeleton)
g_object_unref (ctx->skeleton);
g_free (ctx);
}
@@ -768,10 +746,29 @@ mm_iface_modem_time_enable (MMIfaceModemTime *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
interface_enabling_step (enabling_context_new (self,
cancellable,
callback,
user_data));
EnablingContext *ctx;
ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self);
ctx->cancellable = g_object_ref (cancellable);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_iface_modem_time_enable);
ctx->step = ENABLING_STEP_FIRST;
g_object_get (ctx->self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &ctx->skeleton,
NULL);
if (!ctx->skeleton) {
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't get interface skeleton");
enabling_context_complete_and_free (ctx);
return;
}
interface_enabling_step (ctx);
}
/*****************************************************************************/
@@ -794,29 +791,6 @@ struct _InitializationContext {
InitializationStep step;
};
static InitializationContext *
initialization_context_new (MMIfaceModemTime *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
InitializationContext *ctx;
ctx = g_new0 (InitializationContext, 1);
ctx->self = g_object_ref (self);
ctx->cancellable = g_object_ref (cancellable);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
initialization_context_new);
ctx->step = INITIALIZATION_STEP_FIRST;
g_object_get (ctx->self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &ctx->skeleton,
NULL);
g_assert (ctx->skeleton != NULL);
return ctx;
}
static void
initialization_context_complete_and_free (InitializationContext *ctx)
{
@@ -955,9 +929,6 @@ mm_iface_modem_time_initialize_finish (MMIfaceModemTime *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_IFACE_MODEM_TIME (self), FALSE);
g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
}
@@ -967,35 +938,38 @@ mm_iface_modem_time_initialize (MMIfaceModemTime *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
InitializationContext *ctx;
MmGdbusModemTime *skeleton = NULL;
g_return_if_fail (MM_IS_IFACE_MODEM_TIME (self));
/* Did we already create it? */
g_object_get (self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, &skeleton,
NULL);
if (!skeleton) {
skeleton = mm_gdbus_modem_time_skeleton_new ();
g_object_set (self,
MM_IFACE_MODEM_TIME_DBUS_SKELETON, skeleton,
NULL);
}
/* Perform async initialization here */
interface_initialization_step (initialization_context_new (self,
cancellable,
callback,
user_data));
g_object_unref (skeleton);
ctx = g_new0 (InitializationContext, 1);
ctx->self = g_object_ref (self);
ctx->cancellable = g_object_ref (cancellable);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_iface_modem_time_initialize);
ctx->step = INITIALIZATION_STEP_FIRST;
ctx->skeleton = skeleton;
interface_initialization_step (ctx);
}
void
mm_iface_modem_time_shutdown (MMIfaceModemTime *self)
{
g_return_if_fail (MM_IS_IFACE_MODEM_TIME (self));
/* Unexport DBus interface and remove the skeleton */
mm_gdbus_object_skeleton_set_modem_time (MM_GDBUS_OBJECT_SKELETON (self), NULL);
g_object_set (self,