summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-02-03 20:24:57 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-02-04 13:57:38 +0000
commit33d38beed46dcc491759b70784b8a8c3b8c747e2 (patch)
treec16529a8ac9023d5977185c8aa9c4c1576da36d5
parent7290f4e00a5eb3cd155998d7a0a81a14028ced7c (diff)
mcp_account_storage_get_flags: add
The initial flag is STORES_TYPES, which can be used to decide whether to try to attach types to untyped parameters. Of our built-in plugins, the default keyfile/variant-file storage and the D-Bus test plugin have STORES_TYPES, but the "diversion" plugin does not. Flags are account-specific in case they ever need to vary per-account (e.g. a FROM_TELEPATHY_0 flag might be one way to deal with migration from Telepathy 0.x to 1.0). Also add some convenience API (has_all_flags, has_any_flag) to make code that uses these flags easier to understand. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71093 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
-rw-r--r--mission-control-plugins/account-storage.c90
-rw-r--r--mission-control-plugins/account-storage.h21
-rw-r--r--src/mcd-account-manager-default.c8
-rw-r--r--tests/twisted/dbus-account-plugin.c8
4 files changed, 127 insertions, 0 deletions
diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index d93d2c1b..f36ed25c 100644
--- a/mission-control-plugins/account-storage.c
+++ b/mission-control-plugins/account-storage.c
@@ -56,6 +56,7 @@
* iface->desc = "The FOO storage backend";
* iface->provider = "org.freedesktop.Telepathy.MissionControl5.FooStorage";
*
+ * iface->get_flags = foo_plugin_get_flags;
* iface->delete_async = foo_plugin_delete_async;
* iface->delete_finish = foo_plugin_delete_finish;
* iface->commit = foo_plugin_commit;
@@ -101,6 +102,15 @@
#endif /* ENABLE_DEBUG */
+/**
+ * McpAccountStorageFlags:
+ * @MCP_ACCOUNT_STORAGE_FLAG_NONE: no particular flags
+ * @MCP_ACCOUNT_STORAGE_FLAG_STORES_TYPES: this backend can store parameter
+ * values' types
+ *
+ * Flags describing the features and capabilities of a backend.
+ */
+
enum
{
CREATED,
@@ -215,6 +225,13 @@ default_list_untyped_parameters (McpAccountStorage *storage,
return NULL;
}
+static McpAccountStorageFlags
+default_get_flags (McpAccountStorage *storage,
+ const gchar *account)
+{
+ return MCP_ACCOUNT_STORAGE_FLAG_NONE;
+}
+
static void
class_init (gpointer klass,
gpointer data)
@@ -222,6 +239,7 @@ class_init (gpointer klass,
GType type = G_TYPE_FROM_CLASS (klass);
McpAccountStorageIface *iface = klass;
+ iface->get_flags = default_get_flags;
iface->create = default_create;
iface->delete_async = default_delete_async;
iface->delete_finish = default_delete_finish;
@@ -1205,3 +1223,75 @@ mcp_account_storage_emit_reconnect (McpAccountStorage *storage,
SDEBUG (storage, "%s", account);
g_signal_emit (storage, signals[RECONNECT], 0, account);
}
+
+/**
+ * mcp_account_storage_get_flags:
+ * @storage: an #McpAccountStorage instance
+ * @account: the unique name of the account to inspect
+ *
+ * Get the backend's features and capabilities. The default implementation
+ * returns %MCP_ACCOUNT_STORAGE_FLAG_NONE. Additionally providing
+ * %MCP_ACCOUNT_STORAGE_FLAG_STORES_TYPES is strongly recommended.
+ *
+ * Returns: a bitmask of API features that apply to @account
+ */
+McpAccountStorageFlags
+mcp_account_storage_get_flags (McpAccountStorage *storage,
+ const gchar *account)
+{
+ McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
+
+ g_return_val_if_fail (iface != NULL, MCP_ACCOUNT_STORAGE_FLAG_NONE);
+ g_return_val_if_fail (iface->get_flags != NULL,
+ MCP_ACCOUNT_STORAGE_FLAG_NONE);
+
+ return iface->get_flags (storage, account);
+}
+
+/**
+ * mcp_account_storage_has_all_flags:
+ * @storage: an #McpAccountStorage instance
+ * @account: the unique name of the account to inspect
+ * @require_all: bitwise "or" of zero or more flags
+ *
+ * Return whether this account has all of the specified flags,
+ * according to mcp_account_storage_get_flags().
+ *
+ * If @require_all is 0, the result will always be %TRUE
+ * (the account has all of the flags in the empty set).
+ *
+ * Returns: %TRUE if @account has every flag in @require_all
+ */
+gboolean
+mcp_account_storage_has_all_flags (McpAccountStorage *storage,
+ const gchar *account,
+ McpAccountStorageFlags require_all)
+{
+ return ((mcp_account_storage_get_flags (storage, account) & require_all) ==
+ require_all);
+}
+
+
+/**
+ * mcp_account_storage_has_any_flag:
+ * @storage: an #McpAccountStorage instance
+ * @account: the unique name of the account to inspect
+ * @require_one: bitwise "or" of one or more flags
+ *
+ * Return whether this account has at least one of the required flags,
+ * according to mcp_account_storage_get_flags().
+ *
+ * If @require_one is 0, the result will always be %FALSE
+ * (it is not true that the account has at least one of the flags
+ * in the empty set).
+ *
+ * Returns: %TRUE if @account has every flag in @require_all
+ */
+gboolean
+mcp_account_storage_has_any_flag (McpAccountStorage *storage,
+ const gchar *account,
+ McpAccountStorageFlags require_one)
+{
+ return ((mcp_account_storage_get_flags (storage, account) & require_one)
+ != 0);
+}
diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h
index c1a1ece6..95ffcc14 100644
--- a/mission-control-plugins/account-storage.h
+++ b/mission-control-plugins/account-storage.h
@@ -47,6 +47,12 @@ typedef enum {
MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED
} McpAccountStorageSetResult;
+typedef enum /*< flags >*/
+{
+ MCP_ACCOUNT_STORAGE_FLAG_NONE = 0,
+ MCP_ACCOUNT_STORAGE_FLAG_STORES_TYPES = (1 << 0)
+} McpAccountStorageFlags;
+
/* API for plugins to implement */
typedef struct _McpAccountStorage McpAccountStorage;
typedef struct _McpAccountStorageIface McpAccountStorageIface;
@@ -162,6 +168,9 @@ struct _McpAccountStorageIface
gchar **(*list_untyped_parameters) (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account);
+
+ McpAccountStorageFlags (*get_flags) (McpAccountStorage *storage,
+ const gchar *account);
};
/* virtual methods */
@@ -246,6 +255,18 @@ McpAccountStorageSetResult mcp_account_storage_set_parameter (
GVariant *value,
McpParameterFlags flags);
+McpAccountStorageFlags mcp_account_storage_get_flags (
+ McpAccountStorage *storage,
+ const gchar *account);
+gboolean mcp_account_storage_has_all_flags (
+ McpAccountStorage *storage,
+ const gchar *account,
+ McpAccountStorageFlags require_all);
+gboolean mcp_account_storage_has_any_flag (
+ McpAccountStorage *storage,
+ const gchar *account,
+ McpAccountStorageFlags require_one);
+
void mcp_account_storage_emit_created (McpAccountStorage *storage,
const gchar *account);
void mcp_account_storage_emit_altered_one (McpAccountStorage *storage,
diff --git a/src/mcd-account-manager-default.c b/src/mcd-account-manager-default.c
index f4abd844..e6fc14fc 100644
--- a/src/mcd-account-manager-default.c
+++ b/src/mcd-account-manager-default.c
@@ -1026,6 +1026,13 @@ _list (McpAccountStorage *self,
return rval;
}
+static McpAccountStorageFlags
+get_flags (McpAccountStorage *storage,
+ const gchar *account)
+{
+ return MCP_ACCOUNT_STORAGE_FLAG_STORES_TYPES;
+}
+
static void
account_storage_iface_init (McpAccountStorageIface *iface,
gpointer unused G_GNUC_UNUSED)
@@ -1034,6 +1041,7 @@ account_storage_iface_init (McpAccountStorageIface *iface,
iface->desc = PLUGIN_DESCRIPTION;
iface->priority = PLUGIN_PRIORITY;
+ iface->get_flags = get_flags;
iface->get_attribute = get_attribute;
iface->get_parameter = get_parameter;
iface->list_typed_parameters = list_typed_parameters;
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c
index 36f78914..487d35d9 100644
--- a/tests/twisted/dbus-account-plugin.c
+++ b/tests/twisted/dbus-account-plugin.c
@@ -1543,6 +1543,13 @@ test_dbus_account_plugin_get_restrictions (McpAccountStorage *storage,
return account->restrictions;
}
+static McpAccountStorageFlags
+test_dbus_account_plugin_get_flags (McpAccountStorage *storage,
+ const gchar *account)
+{
+ return MCP_ACCOUNT_STORAGE_FLAG_STORES_TYPES;
+}
+
static void
account_storage_iface_init (McpAccountStorageIface *iface)
{
@@ -1551,6 +1558,7 @@ account_storage_iface_init (McpAccountStorageIface *iface)
/* this should be higher priority than the diverted-keyfile one */
iface->priority = MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_NORMAL + 100;
+ iface->get_flags = test_dbus_account_plugin_get_flags;
iface->get_attribute = test_dbus_account_plugin_get_attribute;
iface->get_parameter = test_dbus_account_plugin_get_parameter;
iface->list_typed_parameters =