diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-03 20:24:57 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-04 13:57:38 +0000 |
commit | 33d38beed46dcc491759b70784b8a8c3b8c747e2 (patch) | |
tree | c16529a8ac9023d5977185c8aa9c4c1576da36d5 /mission-control-plugins | |
parent | 7290f4e00a5eb3cd155998d7a0a81a14028ced7c (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>
Diffstat (limited to 'mission-control-plugins')
-rw-r--r-- | mission-control-plugins/account-storage.c | 90 | ||||
-rw-r--r-- | mission-control-plugins/account-storage.h | 21 |
2 files changed, 111 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, |