summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-03-19 18:36:26 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-03-19 18:36:26 +0000
commite1f992dc0dbb0b75684e1a8c981316cfb84809e8 (patch)
tree824dd758957290ca7e6f4023abdf66cacbbdaa4e
parent404f67814a6bbf71fba965211becbf8cbd9a64af (diff)
parentf3fef7babc1003737455bb1984fcd09442ab53cc (diff)
Merge branch 'master' into next
Conflicts: src/mcd-storage.c
-rw-r--r--mission-control-plugins/account-storage.c74
-rw-r--r--mission-control-plugins/account-storage.h6
-rw-r--r--src/mcd-account-manager.c140
-rw-r--r--src/mcd-account.c10
-rw-r--r--src/mcd-storage.c242
-rw-r--r--tests/twisted/Makefile.am12
-rw-r--r--tests/twisted/dbus-account-plugin.c204
-rw-r--r--tests/twisted/run-test.sh.in35
8 files changed, 356 insertions, 367 deletions
diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index efae5c9c..c8ce282a 100644
--- a/mission-control-plugins/account-storage.c
+++ b/mission-control-plugins/account-storage.c
@@ -61,7 +61,6 @@
* iface->delete_finish = foo_plugin_delete_finish;
* iface->commit = foo_plugin_commit;
* iface->list = foo_plugin_list;
- * iface->ready = foo_plugin_ready;
* iface->get_identifier = foo_plugin_get_identifier;
* iface->get_additional_info = foo_plugin_get_additional_info;
* iface->get_restrictions = foo_plugin_get_restrictions;
@@ -166,13 +165,6 @@ default_create (McpAccountStorage *storage,
}
static void
-default_ready (McpAccountStorage *storage,
- McpAccountManager *am)
-{
- /* do nothing */
-}
-
-static void
default_get_identifier (McpAccountStorage *storage,
const gchar *account,
GValue *identifier)
@@ -244,7 +236,6 @@ class_init (gpointer klass,
iface->delete_async = default_delete_async;
iface->delete_finish = default_delete_finish;
iface->commit = default_commit;
- iface->ready = default_ready;
iface->get_identifier = default_get_identifier;
iface->get_additional_info = default_get_additional_info;
iface->get_restrictions = default_get_restrictions;
@@ -265,8 +256,10 @@ class_init (gpointer klass,
* Emitted if an external entity creates an account
* in the backend the emitting plugin handles.
*
- * Should not be fired until mcp_account_storage_ready() has been called
- *
+ * This signal does not need to be emitted before mcp_account_storage_list()
+ * returns (if it is, it will be ignored). All accounts that exist
+ * at the time that mcp_account_storage_list() returns must be included
+ * in its result, even if they were also signalled via this signal.
*/
signals[CREATED] = g_signal_new ("created",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -291,8 +284,6 @@ class_init (gpointer klass,
* mcp_account_storage_list_typed_parameters() and
* mcp_account_storage_set_parameter() do not use the
* "param-" prefix, but this signal does.
- *
- * Should not be fired until mcp_account_storage_ready() has been called
*/
signals[ALTERED_ONE] = g_signal_new ("altered-one",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -306,9 +297,6 @@ class_init (gpointer klass,
*
* Emitted if an external entity deletes an account
* in the backend the emitting plugin handles.
- *
- * Should not be fired until mcp_account_storage_ready() has been called
- *
*/
signals[DELETED] = g_signal_new ("deleted",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -328,9 +316,6 @@ class_init (gpointer klass,
* Before emitting this signal, the plugin must update its
* internal cache (if any) so that mcp_account_storage_get_attribute()
* will return the new value for Enabled when queried.
- *
- * Should not be fired until mcp_account_storage_ready() has been called
- *
*/
signals[TOGGLED] = g_signal_new ("toggled",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -343,8 +328,6 @@ class_init (gpointer klass,
*
* emitted if an external entity modified important parameters of the
* account and a reconnection is required in order to apply them.
- *
- * Should not be fired until mcp_account_storage_ready() has been called
**/
signals[RECONNECT] = g_signal_new ("reconnect",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -397,17 +380,24 @@ mcp_account_storage_get_type (void)
* @name: returned by mcp_account_storage_name()
* @desc: returned by mcp_account_storage_description()
* @provider: returned by mcp_account_storage_provider()
- * @set: implementation of mcp_account_storage_set()
- * @get: implementation of mcp_account_storage_get()
- * @delete: implementation of mcp_account_storage_delete()
+ * @delete_async: implementation of mcp_account_storage_delete_async()
+ * @delete_finish: implementation of mcp_account_storage_delete_finish()
* @commit: implementation of mcp_account_storage_commit()
* @list: implementation of mcp_account_storage_list()
- * @ready: implementation of mcp_account_storage_ready()
* @get_identifier: implementation of mcp_account_storage_get_identifier()
* @get_additional_info: implementation of
* mcp_account_storage_get_additional_info()
* @get_restrictions: implementation of mcp_account_storage_get_restrictions()
* @create: implementation of mcp_account_storage_create()
+ * @get_attribute: implementation of mcp_account_storage_get_attribute()
+ * @get_parameter: implementation of mcp_account_storage_get_parameter()
+ * @set_attribute: implementation of mcp_account_storage_set_attribute()
+ * @set_parameter: implementation of mcp_account_storage_set_parameter()
+ * @list_typed_parameters: implementation
+ * of mcp_account_storage_list_typed_parameters()
+ * @list_untyped_parameters: implementation
+ * of mcp_account_storage_list_untyped_parameters()
+ * @get_flags: implementation of mcp_account_storage_get_flags()
*
* The interface vtable for an account storage plugin.
*/
@@ -939,40 +929,6 @@ mcp_account_storage_list (McpAccountStorage *storage,
}
/**
- * McpAccountStorageReadyFunc:
- * @storage: an #McpAccountStorage instance
- * @am: an #McpAccountManager instance
- *
- * An implementation of mcp_account_storage_ready().
- */
-
-/**
- * mcp_account_storage_ready:
- * @storage: an #McpAccountStorage instance
- * @am: an #McpAccountManager instance
- *
- * Informs the plugin that it is now permitted to create new accounts,
- * ie it can now fire its "created", "altered-one", "toggled" and "deleted"
- * signals.
- *
- * The default implementation does nothing. It should be overridden by
- * any plugin that will emit "created", "altered-one", "toggled" and/or
- * "deleted".
- */
-void
-mcp_account_storage_ready (McpAccountStorage *storage,
- McpAccountManager *am)
-{
- McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
-
- SDEBUG (storage, "");
- g_return_if_fail (iface != NULL);
- g_return_if_fail (iface->ready != NULL);
-
- iface->ready (storage, am);
-}
-
-/**
* McpAccountStorageGetIdentifierFunc:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h
index 95ffcc14..b8015217 100644
--- a/mission-control-plugins/account-storage.h
+++ b/mission-control-plugins/account-storage.h
@@ -116,9 +116,6 @@ struct _McpAccountStorageIface
GList * (*list) (McpAccountStorage *storage,
McpAccountManager *am);
- void (*ready) (McpAccountStorage *storage,
- McpAccountManager *am);
-
void (*get_identifier) (McpAccountStorage *storage,
const gchar *account,
GValue *identifier);
@@ -193,9 +190,6 @@ gboolean mcp_account_storage_delete_finish (McpAccountStorage *storage,
GAsyncResult *result,
GError **error);
-void mcp_account_storage_ready (McpAccountStorage *storage,
- McpAccountManager *am);
-
gboolean
mcp_account_storage_commit (McpAccountStorage *storage,
McpAccountManager *am,
diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c
index c3f4485a..8b82e254 100644
--- a/src/mcd-account-manager.c
+++ b/src/mcd-account-manager.c
@@ -100,6 +100,7 @@ typedef struct
McpAccountStorage *storage_plugin;
McdAccount *account;
gint account_lock;
+ gboolean holds_setup_lock;
} McdLoadAccountsData;
typedef struct
@@ -173,7 +174,8 @@ async_altered_one_manager_cb (McdManager *cm,
static void
-altered_one_cb (McpAccountStorage *storage,
+altered_one_cb (McdStorage *storage,
+ McpAccountStorage *plugin,
const gchar *account_name,
const gchar *key,
gpointer data)
@@ -183,7 +185,6 @@ altered_one_cb (McpAccountStorage *storage,
McdAccount *account = NULL;
McdManager *cm = NULL;
const gchar *cm_name = NULL;
- McpAccountStorage *its_plugin;
account = mcd_account_manager_lookup_account (am, account_name);
@@ -193,18 +194,6 @@ altered_one_cb (McpAccountStorage *storage,
return;
}
- its_plugin = mcd_account_get_storage_plugin (account);
-
- if (storage != its_plugin)
- {
- DEBUG ("Ignoring altered-one from plugin %s because account %s "
- "belongs to %s",
- mcp_account_storage_name (storage),
- account_name,
- mcp_account_storage_name (its_plugin));
- return;
- }
-
/* in theory, the CM is already ready by this point, but make sure: */
cm_name = mcd_account_get_manager_name (account);
@@ -270,7 +259,8 @@ async_created_manager_cb (McdManager *cm, const GError *error, gpointer data)
* to fetch the named account explicitly at this point (ie it's a read, not *
* not a write, from the plugin's POV: */
static void
-created_cb (GObject *storage_plugin_obj,
+created_cb (McdStorage *storage,
+ GObject *storage_plugin_obj,
const gchar *name,
gpointer data)
{
@@ -279,35 +269,25 @@ created_cb (GObject *storage_plugin_obj,
McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (am);
McdLoadAccountsData *lad = NULL;
McdAccount *account = NULL;
- McdStorage *storage = priv->storage;
McdMaster *master = mcd_master_get_default ();
McdManager *cm = NULL;
const gchar *cm_name = NULL;
- GError *error = NULL;
- /* actually fetch the data into our cache from the plugin: */
- if (mcd_storage_add_account_from_plugin (storage, plugin, name, &error))
- {
- account = mcd_account_new (am, name, priv->minotaur, plugin);
- g_assert (MCD_IS_ACCOUNT (account));
-
- lad = g_slice_new (McdLoadAccountsData);
- lad->account_manager = am;
- lad->storage_plugin = plugin;
- lad->account_lock = 1; /* released at the end of this function */
- lad->account = account;
- }
- else
- {
- WARNING ("%s", error->message);
- g_clear_error (&error);
- goto finish;
- }
+ g_return_if_fail (storage == priv->storage);
- if (G_UNLIKELY (!account))
+ account = mcd_account_new (am, name, priv->minotaur, plugin);
+ g_assert (MCD_IS_ACCOUNT (account));
+
+ lad = g_slice_new (McdLoadAccountsData);
+ lad->account_manager = g_object_ref (am);
+ lad->storage_plugin = g_object_ref (plugin);
+ lad->account_lock = 1; /* released at the end of this function */
+ lad->account = g_object_ref (account);
+
+ if (am->priv->setup_lock > 0)
{
- g_warning ("%s: account %s failed to instantiate", G_STRFUNC, name);
- goto finish;
+ lad->holds_setup_lock = TRUE;
+ am->priv->setup_lock++;
}
cm_name = mcd_account_get_manager_name (account);
@@ -329,19 +309,20 @@ created_cb (GObject *storage_plugin_obj,
g_object_unref (account);
}
-finish:
- if (lad != NULL)
- release_load_accounts_lock (lad);
+ release_load_accounts_lock (lad);
}
static void
-toggled_cb (GObject *plugin, const gchar *name, gboolean on, gpointer data)
+toggled_cb (McdStorage *storage,
+ GObject *plugin,
+ const gchar *name,
+ gboolean on,
+ gpointer data)
{
McpAccountStorage *storage_plugin = MCP_ACCOUNT_STORAGE (plugin);
McdAccountManager *manager = MCD_ACCOUNT_MANAGER (data);
McdAccount *account = NULL;
GError *error = NULL;
- McpAccountStorage *its_plugin;
account = mcd_account_manager_lookup_account (manager, name);
@@ -355,18 +336,6 @@ toggled_cb (GObject *plugin, const gchar *name, gboolean on, gpointer data)
return;
}
- its_plugin = mcd_account_get_storage_plugin (account);
-
- if (storage_plugin != its_plugin)
- {
- DEBUG ("Ignoring toggled signal from plugin %s because account %s "
- "belongs to %s",
- mcp_account_storage_name (storage_plugin),
- name,
- mcp_account_storage_name (its_plugin));
- return;
- }
-
_mcd_account_set_enabled (account, on, FALSE,
MCD_DBUS_PROP_SET_FLAG_ALREADY_IN_STORAGE, &error);
@@ -378,7 +347,10 @@ toggled_cb (GObject *plugin, const gchar *name, gboolean on, gpointer data)
}
static void
-reconnect_cb (GObject *plugin, const gchar *name, gpointer data)
+reconnect_cb (McdStorage *storage,
+ GObject *plugin,
+ const gchar *name,
+ gpointer data)
{
McpAccountStorage *storage_plugin = MCP_ACCOUNT_STORAGE (plugin);
McdAccountManager *manager = MCD_ACCOUNT_MANAGER (data);
@@ -427,7 +399,10 @@ mcd_account_delete_debug_cb (GObject *source,
/* a backend plugin notified us that an account was vaporised: remove it */
static void
-deleted_cb (GObject *plugin, const gchar *name, gpointer data)
+deleted_cb (McdStorage *storage,
+ GObject *plugin,
+ const gchar *name,
+ gpointer data)
{
McpAccountStorage *storage_plugin = MCP_ACCOUNT_STORAGE (plugin);
McdAccountManager *manager = MCD_ACCOUNT_MANAGER (data);
@@ -441,18 +416,6 @@ deleted_cb (GObject *plugin, const gchar *name, gpointer data)
if (account != NULL)
{
const gchar * object_path = mcd_account_get_object_path (account);
- McpAccountStorage *its_plugin = mcd_account_get_storage_plugin (
- account);
-
- if (storage_plugin != its_plugin)
- {
- DEBUG ("Ignoring deleted signal from plugin %s because account %s "
- "belongs to %s",
- mcp_account_storage_name (storage_plugin),
- name,
- mcp_account_storage_name (its_plugin));
- return;
- }
g_object_ref (account);
/* this unhooks the account's signal handlers */
@@ -1135,6 +1098,13 @@ release_load_accounts_lock (McdLoadAccountsData *lad)
if (lad->account_lock == 0)
{
+ if (lad->holds_setup_lock)
+ release_setup_lock (lad->account_manager);
+
+ g_object_unref (lad->account_manager);
+ g_object_unref (lad->storage_plugin);
+ g_object_unref (lad->account);
+
g_slice_free (McdLoadAccountsData, lad);
}
}
@@ -1432,6 +1402,20 @@ _mcd_account_manager_setup (McdAccountManager *account_manager)
(GObject *)account_manager);
accounts = mcd_storage_get_accounts (storage);
+
+ /* as soon as we've listed the initial set, connect to signals
+ * for any subsequently-added accounts */
+ g_signal_connect_object (priv->storage, "altered-one",
+ G_CALLBACK (altered_one_cb), account_manager, 0);
+ g_signal_connect_object (priv->storage, "created",
+ G_CALLBACK (created_cb), account_manager, 0);
+ g_signal_connect_object (priv->storage, "toggled",
+ G_CALLBACK (toggled_cb), account_manager, 0);
+ g_signal_connect_object (priv->storage, "deleted",
+ G_CALLBACK (deleted_cb), account_manager, 0);
+ g_signal_connect_object (priv->storage, "reconnect",
+ G_CALLBACK (reconnect_cb), account_manager, 0);
+
g_hash_table_iter_init (&iter, accounts);
while (g_hash_table_iter_next (&iter, &k, &v))
@@ -1495,9 +1479,6 @@ _mcd_account_manager_setup (McdAccountManager *account_manager)
mcd_storage_commit (storage, k);
}
- /* uncork signals from storage plugins */
- mcd_storage_ready (priv->storage);
-
migrate_accounts (account_manager);
release_setup_lock (account_manager);
@@ -1664,14 +1645,6 @@ _mcd_account_manager_constructed (GObject *obj)
{
McdAccountManager *account_manager = MCD_ACCOUNT_MANAGER (obj);
McdAccountManagerPrivate *priv = account_manager->priv;
- guint i = 0;
- static struct { const gchar *name; GCallback handler; } sig[] =
- { { "created", G_CALLBACK (created_cb) },
- { "toggled", G_CALLBACK (toggled_cb) },
- { "deleted", G_CALLBACK (deleted_cb) },
- { "altered-one", G_CALLBACK (altered_one_cb) },
- { "reconnect", G_CALLBACK (reconnect_cb) },
- { NULL, NULL } };
DEBUG ("");
@@ -1689,13 +1662,6 @@ _mcd_account_manager_constructed (GObject *obj)
DEBUG ("loading plugins");
mcd_storage_load (priv->storage);
- /* hook up all the storage plugin signals to their handlers: */
- for (i = 0; sig[i].name != NULL; i++)
- {
- mcd_storage_connect_signal (sig[i].name, sig[i].handler,
- account_manager);
- }
-
/* initializes the interfaces */
mcd_dbus_init_interfaces_instances (account_manager);
}
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 437b1af6..f28b0a18 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -3627,6 +3627,9 @@ mcd_account_get_object_path (McdAccount *account)
/*
* Like _mcd_account_dup_parameters(), but return the parameters as they
* would be passed to RequestConnection for the given protocol.
+ *
+ * Returns: A GHashTable with g_strdup'ed keys and tp_g_value_slice_dup'ed
+ * values. Be careful: callers rely on that memory allocation model.
*/
static GHashTable *
mcd_account_coerce_parameters (McdAccount *account,
@@ -5050,6 +5053,13 @@ _mcd_account_connection_begin (McdAccount *account,
ctx->params = mcd_account_coerce_parameters (account, protocol);
g_assert (ctx->params != NULL);
+
+ /* Inject "account-path-suffix" parameter if supported by the protocol */
+ if (tp_protocol_has_param (protocol, "account-path-suffix"))
+ {
+ g_hash_table_insert (ctx->params, g_strdup ("account-path-suffix"),
+ tp_g_value_slice_new_string (account->priv->unique_name));
+ }
g_object_unref (protocol);
_mcd_account_set_connection_status (account,
diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index d5a6486d..9bb14ff1 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -50,6 +50,17 @@ enum {
PROP_CLIENT_FACTORY = 1,
};
+enum {
+ SIGNAL_CREATED,
+ SIGNAL_TOGGLED,
+ SIGNAL_DELETED,
+ SIGNAL_ALTERED_ONE,
+ SIGNAL_RECONNECT,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS] = { 0 };
+
struct _McdStorageClass {
GObjectClass parent;
};
@@ -147,6 +158,31 @@ mcd_storage_class_init (McdStorageClass *cls)
object_class->finalize = storage_finalize;
g_object_class_install_property (object_class, PROP_CLIENT_FACTORY, spec);
+
+ signals[SIGNAL_CREATED] = g_signal_new ("created",
+ MCD_TYPE_STORAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE,
+ 2, MCP_TYPE_ACCOUNT_STORAGE, G_TYPE_STRING);
+
+ signals[SIGNAL_ALTERED_ONE] = g_signal_new ("altered-one",
+ MCD_TYPE_STORAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE,
+ 3, MCP_TYPE_ACCOUNT_STORAGE, G_TYPE_STRING, G_TYPE_STRING);
+
+ signals[SIGNAL_DELETED] = g_signal_new ("deleted",
+ MCD_TYPE_STORAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE,
+ 2, MCP_TYPE_ACCOUNT_STORAGE, G_TYPE_STRING);
+
+ signals[SIGNAL_TOGGLED] = g_signal_new ("toggled",
+ MCD_TYPE_STORAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE,
+ 3, MCP_TYPE_ACCOUNT_STORAGE, G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+ signals[SIGNAL_RECONNECT] = g_signal_new ("reconnect",
+ MCD_TYPE_STORAGE, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ NULL, G_TYPE_NONE,
+ 2, MCP_TYPE_ACCOUNT_STORAGE, G_TYPE_STRING);
}
McdStorage *
@@ -464,21 +500,119 @@ sort_and_cache_plugins ()
plugins_cached = TRUE;
}
-void
-mcd_storage_connect_signal (const gchar *signame,
- GCallback func,
- gpointer user_data)
+static void
+created_cb (McpAccountStorage *plugin,
+ const gchar *account_name,
+ McdStorage *self)
{
- GList *p;
+ GError *error = NULL;
- for (p = stores; p != NULL; p = g_list_next (p))
+ g_return_if_fail (MCP_IS_ACCOUNT_STORAGE (plugin));
+ g_return_if_fail (MCD_IS_STORAGE (self));
+
+ if (mcd_storage_add_account_from_plugin (self, plugin, account_name, &error))
{
- McpAccountStorage *plugin = p->data;
+ DEBUG ("%s", account_name);
+ g_signal_emit (self, signals[SIGNAL_CREATED], 0, plugin, account_name);
+ }
+ else
+ {
+ WARNING ("%s", error->message);
+ g_error_free (error);
+ }
+}
+
+static gboolean
+check_is_responsible (McdStorage *self,
+ McpAccountStorage *plugin,
+ const gchar *account_name,
+ const gchar *changing,
+ GError **error)
+{
+ McpAccountStorage *other = g_hash_table_lookup (self->accounts,
+ account_name);
+
+ if (other == NULL)
+ {
+ WARNING ("account %s does not exist, preventing plugin '%s' from "
+ "%s it", account_name, mcp_account_storage_name (plugin), changing);
+ return FALSE;
+ }
- DEBUG ("connecting handler to %s plugin signal %s ",
- mcp_account_storage_name (plugin), signame);
- g_signal_connect (plugin, signame, func, user_data);
+ if (other != plugin)
+ {
+ WARNING ("account %s is in plugin '%s', preventing plugin '%s' from "
+ "%s it", account_name, mcp_account_storage_name (other),
+ mcp_account_storage_name (plugin), changing);
+ return FALSE;
}
+
+ return TRUE;
+}
+
+static void
+toggled_cb (McpAccountStorage *plugin,
+ const gchar *account_name,
+ gboolean on,
+ McdStorage *self)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (MCP_IS_ACCOUNT_STORAGE (plugin));
+ g_return_if_fail (MCD_IS_STORAGE (self));
+
+ if (check_is_responsible (self, plugin, account_name, "toggling", &error))
+ g_signal_emit (self, signals[SIGNAL_TOGGLED], 0, plugin,
+ account_name, on);
+}
+
+static void
+deleted_cb (McpAccountStorage *plugin,
+ const gchar *account_name,
+ McdStorage *self)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (MCP_IS_ACCOUNT_STORAGE (plugin));
+ g_return_if_fail (MCD_IS_STORAGE (self));
+
+ if (check_is_responsible (self, plugin, account_name, "deleting",
+ &error))
+ g_signal_emit (self, signals[SIGNAL_DELETED], 0, plugin,
+ account_name);
+}
+
+static void
+altered_one_cb (McpAccountStorage *plugin,
+ const gchar *account_name,
+ const gchar *key,
+ McdStorage *self)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (MCP_IS_ACCOUNT_STORAGE (plugin));
+ g_return_if_fail (MCD_IS_STORAGE (self));
+
+ if (check_is_responsible (self, plugin, account_name, "altering",
+ &error))
+ g_signal_emit (self, signals[SIGNAL_ALTERED_ONE], 0, plugin,
+ account_name, key);
+}
+
+static void
+reconnect_cb (McpAccountStorage *plugin,
+ const gchar *account_name,
+ McdStorage *self)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (MCP_IS_ACCOUNT_STORAGE (plugin));
+ g_return_if_fail (MCD_IS_STORAGE (self));
+
+ if (check_is_responsible (self, plugin, account_name, "reconnecting",
+ &error))
+ g_signal_emit (self, signals[SIGNAL_RECONNECT], 0, plugin,
+ account_name);
}
/*
@@ -505,11 +639,28 @@ mcd_storage_load (McdStorage *self)
{
GList *account;
McpAccountStorage *plugin = store->data;
- GList *stored = mcp_account_storage_list (plugin, ma);
+ GList *stored;
const gchar *pname = mcp_account_storage_name (plugin);
const gint prio = mcp_account_storage_priority (plugin);
- DEBUG ("listing from plugin %s [prio: %d]", pname, prio);
+ DEBUG ("listing initial accounts from plugin %s [prio: %d]", pname, prio);
+ stored = mcp_account_storage_list (plugin, ma);
+
+ /* Connect to signals for non-initial accounts. We only do this
+ * after we have called list(), to make sure the plugins don't need
+ * to queue up change-notification signals until after we've
+ * called the old "ready" vfunc. */
+ g_signal_connect_object (plugin, "created", G_CALLBACK (created_cb),
+ self, 0);
+ g_signal_connect_object (plugin, "toggled", G_CALLBACK (toggled_cb),
+ self, 0);
+ g_signal_connect_object (plugin, "deleted", G_CALLBACK (deleted_cb),
+ self, 0);
+ g_signal_connect_object (plugin, "altered-one",
+ G_CALLBACK (altered_one_cb), self, 0);
+ g_signal_connect_object (plugin, "reconnect", G_CALLBACK (reconnect_cb),
+ self, 0);
+
for (account = stored; account != NULL; account = g_list_next (account))
{
GError *error = NULL;
@@ -915,6 +1066,29 @@ mcd_keyfile_get_variant (GKeyFile *keyfile,
}
break;
+ case G_VARIANT_CLASS_INT16:
+ {
+ GError *e = NULL;
+ gint v_int = g_key_file_get_integer (keyfile, group,
+ key, &e);
+
+ if (e != NULL)
+ {
+ g_propagate_error (error, e);
+ }
+ else if (v_int < G_MININT16 || v_int > G_MAXINT16)
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+ "integer %d out of range [%d,%d]",
+ v_int, G_MININT16, G_MAXINT16);
+ }
+ else
+ {
+ ret = g_variant_new_int16 (v_int);
+ }
+ }
+ break;
+
case G_VARIANT_CLASS_INT32:
{
GError *e = NULL;
@@ -949,6 +1123,28 @@ mcd_keyfile_get_variant (GKeyFile *keyfile,
}
break;
+ case G_VARIANT_CLASS_UINT16:
+ {
+ GError *e = NULL;
+ gint v_int = g_key_file_get_integer (keyfile, group,
+ key, &e);
+
+ if (e != NULL)
+ {
+ g_propagate_error (error, e);
+ }
+ else if (v_int < 0 || (unsigned) v_int > G_MAXUINT16)
+ {
+ g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+ "integer %d out of range [0,%d]", v_int, G_MAXUINT16);
+ }
+ else
+ {
+ ret = g_variant_new_uint16 (v_int);
+ }
+ }
+ break;
+
case G_VARIANT_CLASS_UINT32:
{
GError *e = NULL;
@@ -1884,22 +2080,6 @@ mcd_storage_set_strv (McdStorage *storage,
return ret;
}
-void
-mcd_storage_ready (McdStorage *self)
-{
- GList *store;
- McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self);
-
- for (store = stores; store != NULL; store = g_list_next (store))
- {
- McpAccountStorage *plugin = store->data;
- const gchar *plugin_name = mcp_account_storage_name (plugin);
-
- DEBUG ("Unblocking async account ops by %s", plugin_name);
- mcp_account_storage_ready (plugin, ma);
- }
-}
-
static GVariant *
mcpa_unescape_variant_from_keyfile (const McpAccountManager *mcpa,
const gchar *escaped,
@@ -2098,7 +2278,6 @@ mcd_storage_maybe_migrate_parameters (McdStorage *self,
const gchar *param_name = untyped_parameters[i];
const TpConnectionManagerParam *param = tp_protocol_get_param (protocol,
param_name);
- GError *error = NULL;
GVariantType *type = NULL;
GVariant *value;
McpAccountStorageSetResult res;
@@ -2123,10 +2302,7 @@ mcd_storage_maybe_migrate_parameters (McdStorage *self,
if (value == NULL)
{
- DEBUG ("cannot migrate parameter '%s': %s #%d: %s",
- param_name, g_quark_to_string (error->domain), error->code,
- error->message);
- g_error_free (error);
+ DEBUG ("cannot migrate parameter '%s'", param_name);
goto next_param;
}
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 128ef2d0..467cbde1 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -122,6 +122,14 @@ TWISTED_OTHER_FILES = \
mc-twisted-tests.list:
$(AM_V_GEN)echo $(TWISTED_BASIC_TESTS) $(TWISTED_SEPARATE_TESTS) > $@
+twisted-tests.test: Makefile
+ $(AM_V_GEN)( echo '[Test]'; \
+ echo 'Exec=${twistedtestsdir}/run-test.sh'; \
+ echo 'Type=session'; \
+ echo 'Output=TAP' ) > $@.tmp
+ @chmod +x $@.tmp
+ @mv $@.tmp $@
+
run-test.sh: run-test.sh.in Makefile
$(AM_V_GEN)sed \
-e "s|[@]mctestsdir[@]|@mctestsdir@|g" \
@@ -130,6 +138,9 @@ run-test.sh: run-test.sh.in Makefile
@chmod +x $@
if ENABLE_INSTALLED_TESTS
+insttestdir = ${datadir}/installed-tests/telepathy-mission-control
+nodist_insttest_DATA = twisted-tests.test
+
# Install files in each directory. They could be tests, pristine data files,
# scripts or built source
twistedtestsdir = @mctestsdir@/twisted
@@ -161,6 +172,7 @@ config.py: Makefile
BUILT_SOURCES = \
config.py \
mc-twisted-tests.list \
+ twisted-tests.test \
run-test.sh \
$(NULL)
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c
index 934d5e2f..04341910 100644
--- a/tests/twisted/dbus-account-plugin.c
+++ b/tests/twisted/dbus-account-plugin.c
@@ -122,29 +122,6 @@ async_data_free (AsyncData *ad)
g_slice_free (AsyncData, ad);
}
-typedef enum {
- EVENT_PARAMS,
- EVENT_ATTRS,
- EVENT_CREATION,
- EVENT_DELETION
-} EventType;
-
-typedef struct {
- EventType type;
- GVariant *args;
-} Event;
-
-static Event *
-event_new (EventType type,
- GVariant *args)
-{
- Event *e = g_slice_new0 (Event);
-
- e->type = type;
- e->args = g_variant_ref_sink (args);
- return e;
-}
-
static Account *
lookup_account (TestDBusAccountPlugin *self,
const gchar *account_name)
@@ -311,9 +288,15 @@ test_dbus_account_plugin_add_account (TestDBusAccountPlugin *self,
}
static void
-test_dbus_account_plugin_process_account_creation (TestDBusAccountPlugin *self,
- GVariant *args)
+account_created_cb (GDBusConnection *bus,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *iface_name,
+ const gchar *signal_name,
+ GVariant *tuple,
+ gpointer user_data)
{
+ TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
const gchar *account_name;
Account *account;
GVariant *attrs;
@@ -323,7 +306,7 @@ test_dbus_account_plugin_process_account_creation (TestDBusAccountPlugin *self,
GVariant *param_flags;
guint32 restrictions;
- g_variant_get (args, "(&s@a{sv}@a{su}@a{sv}@a{ss}@a{su}u)",
+ g_variant_get (tuple, "(&s@a{sv}@a{su}@a{sv}@a{ss}@a{su}u)",
&account_name, &attrs, &attr_flags,
&params, &untyped_params, &param_flags,
&restrictions);
@@ -361,13 +344,19 @@ test_dbus_account_plugin_process_account_creation (TestDBusAccountPlugin *self,
}
static void
-test_dbus_account_plugin_process_account_deletion (TestDBusAccountPlugin *self,
- GVariant *args)
+account_deleted_cb (GDBusConnection *bus,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *iface_name,
+ const gchar *signal_name,
+ GVariant *tuple,
+ gpointer user_data)
{
+ TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
const gchar *account_name;
Account *account;
- g_variant_get (args, "(&s)", &account_name);
+ g_variant_get (tuple, "(&s)", &account_name);
DEBUG ("%s", account_name);
account = lookup_account (self, account_name);
@@ -395,16 +384,22 @@ test_dbus_account_plugin_process_account_deletion (TestDBusAccountPlugin *self,
}
static void
-test_dbus_account_plugin_process_attributes (TestDBusAccountPlugin *self,
- GVariant *args)
+attributes_changed_cb (GDBusConnection *bus,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *iface_name,
+ const gchar *signal_name,
+ GVariant *tuple,
+ gpointer user_data)
{
+ TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
const gchar *account_name;
Account *account;
GVariant *attrs;
GVariant *attr_flags;
GVariant *deleted;
- g_variant_get (args, "(&s@a{sv}@a{su}@as)",
+ g_variant_get (tuple, "(&s@a{sv}@a{su}@as)",
&account_name, &attrs, &attr_flags, &deleted);
DEBUG ("%s", account_name);
account = lookup_account (self, account_name);
@@ -501,9 +496,15 @@ test_dbus_account_plugin_process_attributes (TestDBusAccountPlugin *self,
}
static void
-test_dbus_account_plugin_process_parameters (TestDBusAccountPlugin *self,
- GVariant *args)
+parameters_changed_cb (GDBusConnection *bus,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *iface_name,
+ const gchar *signal_name,
+ GVariant *tuple,
+ gpointer user_data)
{
+ TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
const gchar *account_name;
Account *account;
GVariant *params;
@@ -511,7 +512,7 @@ test_dbus_account_plugin_process_parameters (TestDBusAccountPlugin *self,
GVariant *param_flags;
GVariant *deleted;
- g_variant_get (args, "(&s@a{sv}@a{ss}@a{su}@as)",
+ g_variant_get (tuple, "(&s@a{sv}@a{ss}@a{su}@as)",
&account_name, &params, &untyped_params, &param_flags, &deleted);
DEBUG ("%s", account_name);
account = lookup_account (self, account_name);
@@ -630,123 +631,6 @@ test_dbus_account_plugin_process_parameters (TestDBusAccountPlugin *self,
g_variant_unref (deleted);
}
-static void
-test_dbus_account_plugin_process_events (TestDBusAccountPlugin *self)
-{
- Event *event;
-
- if (self->feedback == NULL)
- return;
-
- while ((event = g_queue_pop_head (&self->events)) != NULL)
- {
- switch (event->type)
- {
- case EVENT_CREATION:
- test_dbus_account_plugin_process_account_creation (self,
- event->args);
- break;
-
- case EVENT_DELETION:
- test_dbus_account_plugin_process_account_deletion (self,
- event->args);
- break;
-
- case EVENT_ATTRS:
- test_dbus_account_plugin_process_attributes (self,
- event->args);
- break;
-
- case EVENT_PARAMS:
- test_dbus_account_plugin_process_parameters (self,
- event->args);
- break;
- }
-
- g_variant_unref (event->args);
- g_slice_free (Event, event);
- }
-}
-
-static void
-account_created_cb (GDBusConnection *bus,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *iface_name,
- const gchar *signal_name,
- GVariant *tuple,
- gpointer user_data)
-{
- TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
- const gchar *account_name;
-
- g_variant_get (tuple, "(&s@a{sv}@a{su}@a{sv}@a{ss}@a{su}u)",
- &account_name, NULL, NULL, NULL, NULL, NULL, NULL);
- DEBUG ("%s", account_name);
-
- g_queue_push_tail (&self->events, event_new (EVENT_CREATION, tuple));
- test_dbus_account_plugin_process_events (self);
-}
-
-static void
-account_deleted_cb (GDBusConnection *bus,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *iface_name,
- const gchar *signal_name,
- GVariant *tuple,
- gpointer user_data)
-{
- TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
- const gchar *account_name;
-
- g_variant_get (tuple, "(&s)", &account_name);
- DEBUG ("%s", account_name);
-
- g_queue_push_tail (&self->events, event_new (EVENT_DELETION, tuple));
- test_dbus_account_plugin_process_events (self);
-}
-
-static void
-attributes_changed_cb (GDBusConnection *bus,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *iface_name,
- const gchar *signal_name,
- GVariant *tuple,
- gpointer user_data)
-{
- TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
- const gchar *account_name;
-
- g_variant_get (tuple, "(&s@a{sv}@a{su}@as)", &account_name,
- NULL, NULL, NULL);
- DEBUG ("%s", account_name);
-
- g_queue_push_tail (&self->events, event_new (EVENT_ATTRS, tuple));
- test_dbus_account_plugin_process_events (self);
-}
-
-static void
-parameters_changed_cb (GDBusConnection *bus,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *iface_name,
- const gchar *signal_name,
- GVariant *tuple,
- gpointer user_data)
-{
- TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (user_data);
- const gchar *account_name;
-
- g_variant_get (tuple, "(&s@a{sv}@a{ss}@a{su}@as)", &account_name,
- NULL, NULL, NULL, NULL);
- DEBUG ("%s", account_name);
-
- g_queue_push_tail (&self->events, event_new (EVENT_PARAMS, tuple));
- test_dbus_account_plugin_process_events (self);
-}
-
static GList *
test_dbus_account_plugin_list (McpAccountStorage *storage,
McpAccountManager *am)
@@ -857,21 +741,6 @@ test_dbus_account_plugin_list (McpAccountStorage *storage,
return ret;
}
-static void
-test_dbus_account_plugin_ready (McpAccountStorage *storage,
- McpAccountManager *am)
-{
- TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (storage);
-
- DEBUG ("called");
- g_dbus_connection_emit_signal (self->bus, NULL,
- TEST_DBUS_ACCOUNT_PLUGIN_PATH, TEST_DBUS_ACCOUNT_PLUGIN_IFACE,
- "Ready", NULL, NULL);
- self->feedback = MCP_ACCOUNT_MANAGER (am);
-
- test_dbus_account_plugin_process_events (self);
-}
-
static gchar *
test_dbus_account_plugin_create (McpAccountStorage *storage,
McpAccountManager *am,
@@ -1568,7 +1437,6 @@ account_storage_iface_init (McpAccountStorageIface *iface)
iface->set_attribute = test_dbus_account_plugin_set_attribute;
iface->set_parameter = test_dbus_account_plugin_set_parameter;
iface->list = test_dbus_account_plugin_list;
- iface->ready = test_dbus_account_plugin_ready;
iface->delete_async = test_dbus_account_plugin_delete_async;
iface->delete_finish = test_dbus_account_plugin_delete_finish;
iface->commit = test_dbus_account_plugin_commit;
diff --git a/tests/twisted/run-test.sh.in b/tests/twisted/run-test.sh.in
index d9dfcec2..1c502b42 100644
--- a/tests/twisted/run-test.sh.in
+++ b/tests/twisted/run-test.sh.in
@@ -19,7 +19,7 @@ export MC_TEST_CURDIR
if test "x$MC_TEST_UNINSTALLED" = x; then
script_fullname=`readlink -e "@mctestsdir@/twisted/run-test.sh"`
if [ `readlink -e "$0"` != "$script_fullname" ] ; then
- echo "This script is meant to be installed at $script_fullname" >&2
+ echo "Bail out! This script is meant to be installed at $script_fullname"
exit 1
fi
@@ -35,11 +35,11 @@ if test "x$MC_TEST_UNINSTALLED" = x; then
export MC_TWISTED_PATH
else
if test -z "$MC_ABS_TOP_SRCDIR"; then
- echo "MC_ABS_TOP_SRCDIR must be set" >&2
+ echo "Bail out! MC_ABS_TOP_SRCDIR must be set"
exit 1
fi
if test -z "$MC_ABS_TOP_BUILDDIR"; then
- echo "MC_ABS_TOP_BUILDDIR must be set" >&2
+ echo "Bail out! MC_ABS_TOP_BUILDDIR must be set"
exit 1
fi
@@ -80,12 +80,19 @@ else
fi
n=0
-n_failed=0
for i in $list ; do
n=$(( $n + 1 ))
- echo "Testing $i ..."
+done
+
+echo "1..$n"
+
+i=0
+n_failed=0
+for t in $list ; do
+ i=$(( $i + 1 ))
+ echo "# Testing $i/$n: $t ..."
- tmp="${MC_TEST_CURDIR}/tmp-`echo $i | tr ./ __`"
+ tmp="${MC_TEST_CURDIR}/tmp-`echo $t | tr ./ __`"
rm -fr "$tmp"
mkdir "$tmp"
@@ -113,37 +120,37 @@ for i in $list ; do
--also-for-system \
--config-file="${config_file}" \
-- \
- @TEST_PYTHON@ -u "${test_src}/twisted/$i" \
+ @TEST_PYTHON@ -u "${test_src}/twisted/$t" \
> "$tmp"/test.log 2>&1 || e=$?
case "$e" in
(0)
- echo "PASS: $i"
+ echo "ok $i - $t"
if test -z "$MC_TEST_KEEP_TEMP"; then
rm -fr "$tmp"
fi
;;
(77)
- echo "SKIP: $i"
+ echo "ok $i # SKIP $t"
if test -z "$MC_TEST_KEEP_TEMP"; then
rm -fr "$tmp"
fi
;;
(*)
n_failed=$(( $n_failed + 1 ))
- echo "FAIL: $i ($e)"
+ echo "not ok $i - $t ($e)"
(
cd $tmp && for x in *.log; do
- echo "===== log file: $x ====="
- cat "$x"
+ echo "# ===== log file: $x ====="
+ sed 's/^/# /' "$x"
done
- echo "===== end of log files for $i ====="
+ echo "# ===== end of log files for $t ====="
)
;;
esac
done
if test $n_failed != 0; then
- echo "Tests run: $n; tests failed: $n_failed"
+ echo "# Tests run: $n; tests failed: $n_failed"
exit 1
else
exit 0