[Telepathy-commits] [telepathy-mission-control/master] Keep all accounts in a single hash table.
Alberto Mardegan
alberto.mardegan at nokia.com
Mon Feb 16 02:00:22 PST 2009
Remove the invalid_accounts GHashTable and keep all accounts in the same HT.
This simplifies some code.
Other modules also needed to be changed; in particular, the AccountManager's
Query interface now will also return invalid accounts in the results.
---
src/mcd-account-manager-query.c | 2 +-
src/mcd-account-manager.c | 61 ++++++++-----------------------
src/mcd-account-manager.h | 2 +-
src/mcd-master.c | 27 +++++++-------
src/mcd-presence-frame.c | 6 ++-
xml/Account_Manager_Interface_Query.xml | 11 ++----
6 files changed, 37 insertions(+), 72 deletions(-)
diff --git a/src/mcd-account-manager-query.c b/src/mcd-account-manager-query.c
index ccbed56..f537476 100644
--- a/src/mcd-account-manager-query.c
+++ b/src/mcd-account-manager-query.c
@@ -320,7 +320,7 @@ account_manager_find_accounts (McSvcAccountManagerInterfaceQuery *self,
{
GHashTable *accounts;
fd.accounts = g_ptr_array_sized_new (16);
- accounts = mcd_account_manager_get_valid_accounts (account_manager);
+ accounts = mcd_account_manager_get_accounts (account_manager);
g_hash_table_foreach (accounts, find_accounts, &fd);
}
g_array_free (fd.params, TRUE);
diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c
index 8d988dd..7bf36a7 100644
--- a/src/mcd-account-manager.c
+++ b/src/mcd-account-manager.c
@@ -80,7 +80,6 @@ struct _McdAccountManagerPrivate
GKeyFile *keyfile; /* configuration file */
GHashTable *accounts;
- GHashTable *invalid_accounts;
};
typedef struct
@@ -118,33 +117,8 @@ static void
on_account_validity_changed (McdAccount *account, gboolean valid,
McdAccountManager *account_manager)
{
- McdAccountManagerPrivate *priv = account_manager->priv;
- const gchar *name, *object_path;
- GHashTable *ht_old, *ht_new;
- gboolean found_old, found_new;
-
- if (valid)
- {
- ht_old = priv->invalid_accounts;
- ht_new = priv->accounts;
- }
- else
- {
- ht_old = priv->accounts;
- ht_new = priv->invalid_accounts;
- }
+ const gchar *object_path;
- name = mcd_account_get_unique_name (account);
- found_old = g_hash_table_steal (ht_old, name);
- if (!found_old)
- g_warning ("%s (%d): account %s not found in list",
- G_STRFUNC, valid, name);
- found_new = g_hash_table_lookup (ht_new, name) ? TRUE : FALSE;
- if (found_new)
- g_warning ("%s (%d): account %s is already in list",
- G_STRFUNC, valid, name);
- else
- g_hash_table_insert (ht_new, (gchar *)name, account);
object_path = mcd_account_get_object_path (account);
mc_svc_account_manager_emit_account_validity_changed (account_manager,
object_path,
@@ -161,10 +135,7 @@ on_account_removed (McdAccount *account, McdAccountManager *account_manager)
mc_svc_account_manager_emit_account_removed (account_manager, object_path);
name = mcd_account_get_unique_name (account);
- if (mcd_account_is_valid (account))
- g_hash_table_remove (priv->accounts, name);
- else
- g_hash_table_remove (priv->invalid_accounts, name);
+ g_hash_table_remove (priv->accounts, name);
}
static gboolean
@@ -176,10 +147,7 @@ add_account (McdAccountManager *account_manager, McdAccount *account)
name = mcd_account_get_unique_name (account);
valid = mcd_account_is_valid (account);
- if (valid)
- g_hash_table_insert (priv->accounts, (gchar *)name, account);
- else
- g_hash_table_insert (priv->invalid_accounts, (gchar *)name, account);
+ g_hash_table_insert (priv->accounts, (gchar *)name, account);
/* if we have to connect to any signals from the account object, this is
* the place to do it */
@@ -379,12 +347,13 @@ account_manager_iface_init (McSvcAccountManagerClass *iface,
}
static void
-accounts_to_gvalue (GHashTable *accounts, GValue *value)
+accounts_to_gvalue (GHashTable *accounts, gboolean valid, GValue *value)
{
static GType ao_type = G_TYPE_INVALID;
GPtrArray *account_array;
GHashTableIter iter;
- gpointer k, v;
+ McdAccount *account;
+ gpointer k;
if (G_UNLIKELY (ao_type == G_TYPE_INVALID))
ao_type = dbus_g_type_get_collection ("GPtrArray",
@@ -394,9 +363,12 @@ accounts_to_gvalue (GHashTable *accounts, GValue *value)
g_hash_table_iter_init (&iter, accounts);
- while (g_hash_table_iter_next (&iter, &k, &v))
- g_ptr_array_add (account_array,
- g_strdup (mcd_account_get_object_path (v)));
+ while (g_hash_table_iter_next (&iter, &k, (gpointer)&account))
+ {
+ if (mcd_account_is_valid (account) == valid)
+ g_ptr_array_add (account_array,
+ g_strdup (mcd_account_get_object_path (account)));
+ }
g_value_init (value, ao_type);
g_value_take_boxed (value, account_array);
@@ -410,7 +382,7 @@ get_valid_accounts (TpSvcDBusProperties *self, const gchar *name,
McdAccountManagerPrivate *priv = account_manager->priv;
g_debug ("%s called", G_STRFUNC);
- accounts_to_gvalue (priv->accounts, value);
+ accounts_to_gvalue (priv->accounts, TRUE, value);
}
static void
@@ -421,7 +393,7 @@ get_invalid_accounts (TpSvcDBusProperties *self, const gchar *name,
McdAccountManagerPrivate *priv = account_manager->priv;
g_debug ("%s called", G_STRFUNC);
- accounts_to_gvalue (priv->invalid_accounts, value);
+ accounts_to_gvalue (priv->accounts, FALSE, value);
}
static const McdDBusProp account_manager_properties[] = {
@@ -632,7 +604,6 @@ _mcd_account_manager_finalize (GObject *object)
g_key_file_free (priv->keyfile);
g_hash_table_destroy (priv->accounts);
- g_hash_table_destroy (priv->invalid_accounts);
G_OBJECT_CLASS (mcd_account_manager_parent_class)->finalize (object);
}
@@ -684,8 +655,6 @@ mcd_account_manager_init (McdAccountManager *account_manager)
priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_object_unref);
- priv->invalid_accounts = g_hash_table_new_full (g_str_hash, g_str_equal,
- NULL, g_object_unref);
priv->keyfile = g_key_file_new ();
conf_filename = get_account_conf_filename ();
@@ -751,7 +720,7 @@ mcd_account_manager_write_conf (McdAccountManager *account_manager)
}
GHashTable *
-mcd_account_manager_get_valid_accounts (McdAccountManager *account_manager)
+mcd_account_manager_get_accounts (McdAccountManager *account_manager)
{
return account_manager->priv->accounts;
}
diff --git a/src/mcd-account-manager.h b/src/mcd-account-manager.h
index b78fbc3..4b4273d 100644
--- a/src/mcd-account-manager.h
+++ b/src/mcd-account-manager.h
@@ -88,7 +88,7 @@ McdAccount *mcd_account_manager_lookup_account_by_path (McdAccountManager *accou
/* for interfaces only */
G_GNUC_INTERNAL
-GHashTable *mcd_account_manager_get_valid_accounts (McdAccountManager *account_manager);
+GHashTable *mcd_account_manager_get_accounts (McdAccountManager *account_manager);
typedef void (*McdGetAccountCb) (McdAccountManager *account_manager,
McdAccount *account,
diff --git a/src/mcd-master.c b/src/mcd-master.c
index 360ee9e..77552d9 100644
--- a/src/mcd-master.c
+++ b/src/mcd-master.c
@@ -150,7 +150,8 @@ check_account_transport (gpointer key, gpointer value, gpointer userdata)
/* get all enabled accounts, which have the "ConnectAutomatically" flag set
* and that are not connected */
- if (!mcd_account_is_enabled (account) ||
+ if (!mcd_account_is_valid (account) ||
+ !mcd_account_is_enabled (account) ||
!mcd_account_get_connect_automatically (account) ||
mcd_account_get_connection_status (account) ==
TP_CONNECTION_STATUS_CONNECTED)
@@ -175,7 +176,7 @@ mcd_master_transport_connected (McdMaster *master, McdTransportPlugin *plugin,
McdTransport *transport)
{
McdMasterPrivate *priv = MCD_MASTER_PRIV (master);
- GHashTable *valid_accounts;
+ GHashTable *accounts;
TransportData td;
g_debug ("%s: %s", G_STRFUNC, mcd_transport_get_name (plugin, transport));
@@ -184,9 +185,8 @@ mcd_master_transport_connected (McdMaster *master, McdTransportPlugin *plugin,
td.plugin = plugin;
td.transport = transport;
- valid_accounts =
- mcd_account_manager_get_valid_accounts (priv->account_manager);
- g_hash_table_foreach (valid_accounts, check_account_transport, &td);
+ accounts = mcd_account_manager_get_accounts (priv->account_manager);
+ g_hash_table_foreach (accounts, check_account_transport, &td);
}
static void
@@ -221,7 +221,7 @@ mcd_master_transport_disconnected (McdMaster *master, McdTransportPlugin *plugin
McdTransport *transport)
{
McdMasterPrivate *priv = MCD_MASTER_PRIV (master);
- GHashTable *valid_accounts;
+ GHashTable *accounts;
TransportData td;
g_debug ("%s: %s", G_STRFUNC, mcd_transport_get_name (plugin, transport));
@@ -230,27 +230,26 @@ mcd_master_transport_disconnected (McdMaster *master, McdTransportPlugin *plugin
td.plugin = plugin;
td.transport = transport;
- valid_accounts =
- mcd_account_manager_get_valid_accounts (priv->account_manager);
- g_hash_table_foreach (valid_accounts, disconnect_account_transport, &td);
+ accounts = mcd_account_manager_get_accounts (priv->account_manager);
+ g_hash_table_foreach (accounts, disconnect_account_transport, &td);
}
static void
mcd_master_connect_automatic_accounts (McdMaster *master)
{
McdMasterPrivate *priv = MCD_MASTER_PRIV (master);
- GHashTable *valid_accounts;
+ GHashTable *accounts;
GHashTableIter iter;
gpointer ht_key, ht_value;
- valid_accounts =
- mcd_account_manager_get_valid_accounts (priv->account_manager);
- g_hash_table_iter_init (&iter, valid_accounts);
+ accounts = mcd_account_manager_get_accounts (priv->account_manager);
+ g_hash_table_iter_init (&iter, accounts);
while (g_hash_table_iter_next (&iter, &ht_key, &ht_value))
{
McdAccount *account = MCD_ACCOUNT (ht_value);
- if (mcd_account_is_enabled (account) &&
+ if (mcd_account_is_valid (account) &&
+ mcd_account_is_enabled (account) &&
mcd_account_get_connect_automatically (account) &&
mcd_account_get_connection_status (account) ==
TP_CONNECTION_STATUS_DISCONNECTED)
diff --git a/src/mcd-presence-frame.c b/src/mcd-presence-frame.c
index 2743634..aa53f52 100644
--- a/src/mcd-presence-frame.c
+++ b/src/mcd-presence-frame.c
@@ -202,6 +202,7 @@ request_presence (gpointer key, gpointer value, gpointer userdata)
McdAccount *account = value;
McdPresence *p = userdata;
+ if (!mcd_account_is_valid (account)) return;
mcd_account_request_presence (account,
(TpConnectionPresenceType)p->presence,
presence_statuses[p->presence],
@@ -218,7 +219,7 @@ presence_requested_signal (McdPresenceFrame *presence_frame,
if (!priv->account_manager) return;
- accounts = mcd_account_manager_get_valid_accounts (priv->account_manager);
+ accounts = mcd_account_manager_get_accounts (priv->account_manager);
p.presence = presence;
p.message = (gchar *)presence_message;
g_hash_table_foreach (accounts, request_presence, &p);
@@ -652,6 +653,7 @@ add_account (gpointer key, gpointer value, gpointer userdata)
McdPresenceFrame *presence_frame = userdata;
McdAccount *account = value;
+ if (!mcd_account_is_valid (account)) return;
mcd_presence_frame_add_account (presence_frame, account);
}
@@ -679,7 +681,7 @@ mcd_presence_frame_set_account_manager (McdPresenceFrame *presence_frame,
g_object_ref (account_manager);
priv->account_manager = account_manager;
- accounts = mcd_account_manager_get_valid_accounts (priv->account_manager);
+ accounts = mcd_account_manager_get_accounts (priv->account_manager);
g_hash_table_foreach (accounts, add_account, presence_frame);
diff --git a/xml/Account_Manager_Interface_Query.xml b/xml/Account_Manager_Interface_Query.xml
index a207c11..f75fe7f 100644
--- a/xml/Account_Manager_Interface_Query.xml
+++ b/xml/Account_Manager_Interface_Query.xml
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</
<tp:requires interface="org.freedesktop.Telepathy.AccountManager"/>
<tp:docstring xmlns="http://www.w3.org/1999/xhtml">
<p>The Query interface provides a convienient way for clients to retrieve
- a subset of the <em>valid</em> accounts satisfying certain conditions.</p>
+ a subset of the accounts satisfying certain conditions.</p>
<tp:rationale>
<p>This is basically the same API proposed by Zdra</p>
@@ -29,13 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</
<method name="FindAccounts">
<tp:docstring xmlns="http://www.w3.org/1999/xhtml">
- <p>Find all valid accounts which match the search query.</p>
- <p>An empty parameter should return all valid accounts</p>
-
- <tp:rationale>
- <p>It doesn't seem worth to provide a similar API for invalid
- accounts, or anyway to include invalid accounts into the results.</p>
- </tp:rationale>
+ <p>Find all accounts which match the search query.</p>
+ <p>An empty parameter should return all accounts</p>
</tp:docstring>
<arg direction="in" name="params" type="a{sv}" tp:type="String_Variant_Map">
--
1.5.6.5
More information about the telepathy-commits
mailing list