diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2009-01-10 00:15:02 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2009-01-10 00:15:02 +0800 |
commit | bfdd834b3b8e3f22f82ffc47f41e553f902e8200 (patch) | |
tree | 09b30d6b279d377b1a8eaf6c39e21e06e0635593 /libempathy | |
parent | 67582abc7e901b5de7670bcf2434a15e18938835 (diff) | |
download | gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar.gz gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar.bz2 gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar.lz gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar.xz gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.tar.zst gsoc2013-empathy-bfdd834b3b8e3f22f82ffc47f41e553f902e8200.zip |
Move the dispatcher to the new singleton policy
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2181
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-dispatcher.c | 45 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.h | 2 |
2 files changed, 32 insertions, 15 deletions
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index 7ea3515ea..e065326e1 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -786,6 +786,29 @@ dispatcher_account_connection_cb (EmpathyAccountManager *manager, dispatcher_update_account (dispatcher, account); } + +static GObject* +dispatcher_constructor (GType type, guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *retval; + + if (dispatcher == NULL) + { + retval = G_OBJECT_CLASS (empathy_dispatcher_parent_class)->constructor + (type, n_construct_params, construct_params); + + dispatcher = EMPATHY_DISPATCHER (retval); + g_object_add_weak_pointer (retval, (gpointer *) &dispatcher); + } + else + { + retval = g_object_ref (dispatcher); + } + + return retval; +} + static void dispatcher_finalize (GObject *object) { @@ -808,6 +831,7 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = dispatcher_finalize; + object_class->constructor = dispatcher_constructor; signals[OBSERVE] = g_signal_new ("observe", @@ -879,16 +903,9 @@ empathy_dispatcher_init (EmpathyDispatcher *dispatcher) } EmpathyDispatcher * -empathy_get_dispatcher (void) +empathy_dispatcher_dup_singleton (void) { - if (!dispatcher) { - dispatcher = g_object_new (EMPATHY_TYPE_DISPATCHER, NULL); - g_object_add_weak_pointer (G_OBJECT (dispatcher), (gpointer) &dispatcher); - } else { - g_object_ref (dispatcher); - } - - return dispatcher; + return EMPATHY_DISPATCHER (g_object_new (EMPATHY_TYPE_DISPATCHER, NULL)); } static void @@ -1006,7 +1023,7 @@ void empathy_dispatcher_call_with_contact ( EmpathyContact *contact, EmpathyDispatcherRequestCb *callback, gpointer user_data) { - EmpathyDispatcher *dispatcher = empathy_get_dispatcher(); + EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton(); EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); McAccount *account; TpConnection *connection; @@ -1052,7 +1069,7 @@ empathy_dispatcher_chat_with_contact (EmpathyContact *contact, ConnectionData *connection_data; DispatcherRequestData *request_data; - dispatcher = empathy_get_dispatcher(); + dispatcher = empathy_dispatcher_dup_singleton(); priv = GET_PRIV (dispatcher); account = empathy_contact_get_account (contact); @@ -1078,7 +1095,7 @@ void empathy_dispatcher_chat_with_contact_id (McAccount *account, const gchar *contact_id, EmpathyDispatcherRequestCb *callback, gpointer user_data) { - EmpathyDispatcher *dispatcher = empathy_get_dispatcher (); + EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton (); EmpathyContactFactory *factory; EmpathyContact *contact; @@ -1135,7 +1152,7 @@ empathy_dispatcher_join_muc (McAccount *account, const gchar *roomname, ConnectionData *connection_data; const gchar *names[] = { roomname, NULL }; - dispatcher = empathy_get_dispatcher(); + dispatcher = empathy_dispatcher_dup_singleton(); priv = GET_PRIV (dispatcher); connection = g_hash_table_lookup (priv->accounts, account); @@ -1199,7 +1216,7 @@ empathy_dispatcher_send_file_to_contact (EmpathyContact *contact, const gchar *content_type, EmpathyDispatcherRequestCb *callback, gpointer user_data) { - EmpathyDispatcher *dispatcher = empathy_get_dispatcher(); + EmpathyDispatcher *dispatcher = empathy_dispatcher_dup_singleton(); EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); McAccount *account = empathy_contact_get_account (contact); TpConnection *connection = g_hash_table_lookup (priv->accounts, account); diff --git a/libempathy/empathy-dispatcher.h b/libempathy/empathy-dispatcher.h index 1c1793f90..fd45610e9 100644 --- a/libempathy/empathy-dispatcher.h +++ b/libempathy/empathy-dispatcher.h @@ -91,7 +91,7 @@ void empathy_dispatcher_join_muc (McAccount *account, gpointer user_data); /* Get the dispatcher singleton */ -EmpathyDispatcher * empathy_get_dispatcher (void); +EmpathyDispatcher * empathy_dispatcher_dup_singleton (void); GType empathy_dispatcher_tube_get_type (void); /* tube stuff */ |