diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-09 19:56:29 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-04-10 13:26:44 +0100 |
commit | b6b4a2ec4b1ddbf9ae4856e2fe172f9cc52a5c08 (patch) | |
tree | 2e9f045b93153da8143f1b7afde8148a1f9aacc3 | |
parent | 5a63f14b41e1868af77c8724d5c31992418ce2e9 (diff) |
Simplify TpPresenceMixin by removing all support for non-message parameters
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77191
Reviewed-by: Xavier Claessens
-rw-r--r-- | docs/reference/telepathy-glib/telepathy-glib-sections.txt | 1 | ||||
-rw-r--r-- | examples/cm/call/conn.c | 54 | ||||
-rw-r--r-- | examples/cm/contactlist/conn.c | 9 | ||||
-rw-r--r-- | examples/cm/contactlist/contact-list.c | 10 | ||||
-rw-r--r-- | telepathy-glib/base-protocol.c | 18 | ||||
-rw-r--r-- | telepathy-glib/presence-mixin.c | 133 | ||||
-rw-r--r-- | telepathy-glib/presence-mixin.h | 26 | ||||
-rw-r--r-- | tests/lib/contacts-conn.c | 53 |
8 files changed, 56 insertions, 248 deletions
diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt index ed33c3e86..dacfb66a8 100644 --- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt @@ -1703,7 +1703,6 @@ TpBaseRoomConfigPrivate <SECTION> <INCLUDE>telepathy-glib/telepathy-glib.h</INCLUDE> <FILE>presence-mixin</FILE> -TpPresenceStatusOptionalArgumentSpec TpPresenceStatusSpec tp_presence_status_spec_can_set_on_self tp_presence_status_spec_get_name diff --git a/examples/cm/call/conn.c b/examples/cm/call/conn.c index 44172c448..d64dcacfd 100644 --- a/examples/cm/call/conn.c +++ b/examples/cm/call/conn.c @@ -239,11 +239,7 @@ get_contact_status (GObject *object, EXAMPLE_CALL_CONNECTION (object); TpBaseConnection *base = TP_BASE_CONNECTION (object); ExampleCallPresence presence; - GHashTable *parameters; - TpPresenceStatus *result; - - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); + const gchar *message; /* we know our own status from the connection; for this example CM, * everyone else's status is assumed to be "available" */ @@ -251,19 +247,15 @@ get_contact_status (GObject *object, { presence = (self->priv->away ? EXAMPLE_CALL_PRESENCE_AWAY : EXAMPLE_CALL_PRESENCE_AVAILABLE); - - if (self->priv->presence_message[0] != '\0') - g_hash_table_insert (parameters, "message", - tp_g_value_slice_new_string (self->priv->presence_message)); + message = self->priv->presence_message; } else { presence = EXAMPLE_CALL_PRESENCE_AVAILABLE; + message = NULL; } - result = tp_presence_status_new (presence, parameters); - g_hash_table_unref (parameters); - return result; + return tp_presence_status_new (presence, message); } static gboolean @@ -275,24 +267,10 @@ set_own_status (GObject *object, EXAMPLE_CALL_CONNECTION (object); TpBaseConnection *base = TP_BASE_CONNECTION (object); GHashTable *presences; - const gchar *message = ""; - - if (status->optional_arguments != NULL) - { - GValue *v = g_hash_table_lookup (status->optional_arguments, "message"); - - if (v != NULL && G_VALUE_HOLDS_STRING (v)) - { - message = g_value_get_string (v); - - if (message == NULL) - message = ""; - } - } if (status->index == EXAMPLE_CALL_PRESENCE_AWAY) { - if (self->priv->away && !tp_strdiff (message, + if (self->priv->away && !tp_strdiff (status->message, self->priv->presence_message)) return TRUE; @@ -300,7 +278,7 @@ set_own_status (GObject *object, } else { - if (!self->priv->away && !tp_strdiff (message, + if (!self->priv->away && !tp_strdiff (status->message, self->priv->presence_message)) return TRUE; @@ -308,7 +286,7 @@ set_own_status (GObject *object, } g_free (self->priv->presence_message); - self->priv->presence_message = g_strdup (message); + self->priv->presence_message = g_strdup (status->message); presences = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL); @@ -320,25 +298,19 @@ set_own_status (GObject *object, if (!self->priv->away) { - g_signal_emit (self, signals[SIGNAL_AVAILABLE], 0, message); + g_signal_emit (self, signals[SIGNAL_AVAILABLE], 0, status->message); } return TRUE; } -static const TpPresenceStatusOptionalArgumentSpec can_have_message[] = { - { "message", "s", NULL, NULL }, - { NULL } -}; - /* Must be kept in sync with ExampleCallPresence enum in header */ static const TpPresenceStatusSpec presence_statuses[] = { - { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL }, - { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL }, - { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, NULL }, - { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, can_have_message }, - { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, - can_have_message }, + { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, FALSE }, + { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, FALSE }, + { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, FALSE }, + { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, TRUE }, + { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, TRUE }, { NULL } }; diff --git a/examples/cm/contactlist/conn.c b/examples/cm/contactlist/conn.c index 60e64f01a..4b1a9f301 100644 --- a/examples/cm/contactlist/conn.c +++ b/examples/cm/contactlist/conn.c @@ -303,8 +303,6 @@ get_contact_status (GObject *object, EXAMPLE_CONTACT_LIST_CONNECTION (object); TpBaseConnection *base = TP_BASE_CONNECTION (object); ExampleContactListPresence presence; - GHashTable *parameters; - TpPresenceStatus *result; /* we get our own status from the connection, and everyone else's status * from the contact lists */ @@ -319,12 +317,7 @@ get_contact_status (GObject *object, self->priv->contact_list, contact); } - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); - result = tp_presence_status_new (presence, parameters); - g_hash_table_unref (parameters); - - return result; + return tp_presence_status_new (presence, ""); } static gboolean diff --git a/examples/cm/contactlist/contact-list.c b/examples/cm/contactlist/contact-list.c index c52a9e786..3a5ca8501 100644 --- a/examples/cm/contactlist/contact-list.c +++ b/examples/cm/contactlist/contact-list.c @@ -22,11 +22,11 @@ /* this array must be kept in sync with the enum * ExampleContactListPresence in contact-list.h */ static const TpPresenceStatusSpec _statuses[] = { - { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL }, - { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL }, - { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, NULL }, - { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, NULL }, - { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, NULL }, + { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, FALSE }, + { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, FALSE }, + { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, FALSE }, + { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, FALSE }, + { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, FALSE }, { NULL } }; diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index 708eb9cf0..822ad6b32 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -976,28 +976,12 @@ protocol_prop_presence_getter (GObject *object, { GValueArray *val = NULL; gchar *key = NULL; - gboolean message = FALSE; gboolean settable = status->self; + gboolean message = (settable && status->has_message); TpConnectionPresenceType type = status->presence_type; key = g_strdup (status->name); - /* look for a string argument named 'message' */ - if (settable && status->optional_arguments != NULL) - { - const TpPresenceStatusOptionalArgumentSpec *arg = - status->optional_arguments; - - for (; !message && arg->name != NULL; arg++) - { - if (tp_strdiff (arg->dtype, "s") || - tp_strdiff (arg->name, "message")) - continue; - - message = TRUE; - } - } - val = tp_value_array_build (3, G_TYPE_UINT, type, G_TYPE_BOOLEAN, settable, diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c index 6f711dad0..36509c665 100644 --- a/telepathy-glib/presence-mixin.c +++ b/telepathy-glib/presence-mixin.c @@ -94,33 +94,15 @@ */ /** - * TpPresenceStatusOptionalArgumentSpec: - * @name: Name of the argument as passed over D-Bus - * @dtype: D-Bus type signature of the argument - * - * Structure specifying a supported optional argument for a presence status. - * - * In addition to the fields documented here, there are two gpointer fields - * which must currently be %NULL. A meaning may be defined for these in a - * future version of telepathy-glib. - */ - -/** * TpPresenceStatusSpec: * @name: String identifier of the presence status * @presence_type: A type value, as specified by #TpConnectionPresenceType * @self: Indicates if this status may be set on yourself - * @optional_arguments: An array of #TpPresenceStatusOptionalArgumentSpec - * structures representing the optional arguments for this status, terminated - * by a NULL name. If there are no optional arguments for a status, this can - * be NULL. In modern Telepathy connection managers, the only optional - * argument should be a string (type "s") named "message" on statuses - * that have an optional human-readable message. All other optional arguments - * are deprecated. + * @has_message: %TRUE if a human-readable message can accompany this status. * * Structure specifying a supported presence status. * - * In addition to the fields documented here, there are two gpointer fields + * In addition to the fields documented here, there are some reserved fields * which must currently be %NULL. A meaning may be defined for these in a * future version of telepathy-glib. */ @@ -129,20 +111,13 @@ * TpPresenceStatus: * @index: Index of the presence status in the provided supported presence * statuses array - * @optional_arguments: A GHashTable mapping of string identifiers to GValues - * of the optional status arguments, if any. If there are no optional - * arguments, this pointer may be NULL. + * @message: the non-%NULL human-readable status message * * Structure representing a presence status. * - * In addition to the fields documented here, there are two gpointer fields + * In addition to the fields documented here, there are some gpointer fields * which must currently be %NULL. A meaning may be defined for these in a * future version of telepathy-glib. - * - * In modern Telepathy connection managers, the only optional - * argument should be a %G_TYPE_STRING named "message", on statuses - * that have an optional human-readable message. All other optional arguments - * are deprecated. */ /** @@ -192,12 +167,6 @@ * reset the user's own status back to the "default" one with a %NULL status * argument. * - * The optional_arguments hash table in @status, if not NULL, will have been - * filtered so it only contains recognised parameters, so the callback - * need not (and cannot) check for unrecognised parameters. However, the - * types of the parameters are not currently checked, so the callback is - * responsible for doing so. - * * The callback is responsible for emitting PresenceUpdate, if appropriate, * by calling tp_presence_mixin_emit_presence_update(). * @@ -287,51 +256,29 @@ static GHashTable *construct_presence_hash ( const TpPresenceStatusSpec *supported_statuses, GHashTable *contact_statuses); -/* - * deep_copy_hashtable - * - * Make a deep copy of a GHashTable. - */ -static GHashTable * -deep_copy_hashtable (GHashTable *hash_table) -{ - GValue value = {0, }; - - if (!hash_table) - return NULL; - - g_value_init (&value, TP_HASH_TYPE_STRING_VARIANT_MAP); - g_value_take_boxed (&value, hash_table); - return g_value_dup_boxed (&value); -} - - /** * tp_presence_status_new: (skip) * @which: Index of the presence status in the provided supported presence * statuses array - * @optional_arguments: Optional arguments for the presence statuses. Can be - * NULL if there are no optional arguments. The presence status object makes a - * copy of the hashtable, so you should free the original. + * @message: (allow-none): a human-readable status message, or %NULL * * Construct a presence status structure. You should free the returned * structure with #tp_presence_status_free. * - * In modern Telepathy connection managers, the only optional - * argument should be a %G_TYPE_STRING named "message", on statuses - * that have an optional human-readable message. All other optional arguments - * are deprecated. - * * Returns: A pointer to the newly allocated presence status structure. */ TpPresenceStatus * tp_presence_status_new (guint which, - GHashTable *optional_arguments) + const gchar *message) { TpPresenceStatus *status = g_slice_new (TpPresenceStatus); status->index = which; - status->optional_arguments = deep_copy_hashtable (optional_arguments); + + if (message == NULL) + message = ""; + + status->message = g_strdup (message); return status; } @@ -349,9 +296,7 @@ tp_presence_status_free (TpPresenceStatus *status) if (!status) return; - if (status->optional_arguments) - g_hash_table_unref (status->optional_arguments); - + g_free (status->message); g_slice_free (TpPresenceStatus, status); } @@ -776,7 +721,6 @@ tp_presence_mixin_set_presence ( TpPresenceStatus status_to_set = { 0, }; int s; GError *error = NULL; - GHashTable *optional_arguments = NULL; DEBUG ("called."); @@ -784,19 +728,16 @@ tp_presence_mixin_set_presence ( if (s == -1) goto out; - status_to_set.index = s; + if (message == NULL) + message = ""; - if (*message != '\0') - { - optional_arguments = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, (GDestroyNotify) tp_g_value_slice_free); - g_hash_table_insert (optional_arguments, "message", - tp_g_value_slice_new_string (message)); - status_to_set.optional_arguments = optional_arguments; - } + status_to_set.index = s; + status_to_set.message = g_strdup (message); mixin_cls->set_own_status (obj, &status_to_set, &error); + g_free (status_to_set.message); + out: if (error == NULL) { @@ -808,9 +749,6 @@ out: g_dbus_method_invocation_return_gerror (context, error); g_error_free (error); } - - if (optional_arguments != NULL) - g_hash_table_unref (optional_arguments); } static GValueArray * @@ -825,13 +763,7 @@ construct_presence_value_array (TpPresenceStatus *status, status_name = supported_statuses[status->index].name; status_type = supported_statuses[status->index].presence_type; - if (status->optional_arguments != NULL) - { - GValue *val; - val = g_hash_table_lookup (status->optional_arguments, "message"); - if (val != NULL) - message = g_value_get_string (val); - } + message = status->message; if (message == NULL) message = ""; @@ -1013,20 +945,9 @@ tp_presence_status_spec_can_set_on_self (const TpPresenceStatusSpec *self) gboolean tp_presence_status_spec_has_message (const TpPresenceStatusSpec *self) { - const TpPresenceStatusOptionalArgumentSpec *arg; - g_return_val_if_fail (self != NULL, FALSE); - if (self->optional_arguments == NULL) - return FALSE; - - for (arg = self->optional_arguments; arg->name != NULL; arg++) - { - if (!tp_strdiff (arg->name, "message") && !tp_strdiff (arg->dtype, "s")) - return TRUE; - } - - return FALSE; + return self->has_message; } /** @@ -1050,10 +971,6 @@ tp_presence_status_spec_new (const gchar *name, gboolean has_message) { TpPresenceStatusSpec *ret; - static const TpPresenceStatusOptionalArgumentSpec yes_it_has_a_message[] = { - { "message", "s" }, - { NULL } - }; g_return_val_if_fail (!tp_str_empty (name), NULL); g_return_val_if_fail (type >= 0 && type < TP_NUM_CONNECTION_PRESENCE_TYPES, @@ -1064,11 +981,7 @@ tp_presence_status_spec_new (const gchar *name, ret->name = g_strdup (name); ret->presence_type = type; ret->self = can_set_on_self; - - if (has_message) - ret->optional_arguments = yes_it_has_a_message; - else - ret->optional_arguments = NULL; + ret->has_message = has_message; /* dummy marker for "this is on the heap" rather than a real struct */ ret->priv = (TpPresenceStatusSpecPrivate *) ret; @@ -1082,10 +995,6 @@ tp_presence_status_spec_new (const gchar *name, * * Copy a presence status specification. * - * If @self has optional arguments other than a string named "message", - * they are not copied. Optional arguments with other names or types - * are deprecated. - * * Returns: (transfer full): a new #TpPresenceStatusSpec resembling @self * Since: 0.99.5 */ diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h index 649c03271..27a5a992a 100644 --- a/telepathy-glib/presence-mixin.h +++ b/telepathy-glib/presence-mixin.h @@ -32,28 +32,17 @@ G_BEGIN_DECLS -typedef struct _TpPresenceStatusOptionalArgumentSpec - TpPresenceStatusOptionalArgumentSpec; typedef struct _TpPresenceStatusSpec TpPresenceStatusSpec; typedef struct _TpPresenceStatusSpecPrivate TpPresenceStatusSpecPrivate; -struct _TpPresenceStatusOptionalArgumentSpec { - const gchar *name; - const gchar *dtype; - - /*<private>*/ - gpointer _future1; - gpointer _future2; -}; - struct _TpPresenceStatusSpec { const gchar *name; TpConnectionPresenceType presence_type; gboolean self; - const TpPresenceStatusOptionalArgumentSpec *optional_arguments; + gboolean has_message; /*<private>*/ - gpointer _future1; + GCallback _future[10]; TpPresenceStatusSpecPrivate *priv; }; @@ -93,15 +82,14 @@ typedef struct _TpPresenceStatus TpPresenceStatus; struct _TpPresenceStatus { guint index; - GHashTable *optional_arguments; + gchar *message; /*<private>*/ - gpointer _future1; - gpointer _future2; + gpointer _future[6]; }; TpPresenceStatus *tp_presence_status_new (guint which, - GHashTable *optional_arguments) G_GNUC_WARN_UNUSED_RESULT; + const gchar *message) G_GNUC_WARN_UNUSED_RESULT; void tp_presence_status_free (TpPresenceStatus *status); typedef gboolean (*TpPresenceMixinStatusAvailableFunc) (GObject *obj, @@ -135,9 +123,7 @@ struct _TpPresenceMixinClass { TpPresenceMixinGetMaximumStatusMessageLengthFunc get_maximum_status_message_length; /*<private>*/ - gpointer _future1; - gpointer _future2; - gpointer _future3; + GCallback _future[10]; }; struct _TpPresenceMixin { diff --git a/tests/lib/contacts-conn.c b/tests/lib/contacts-conn.c index 787aea314..79a5c4b82 100644 --- a/tests/lib/contacts-conn.c +++ b/tests/lib/contacts-conn.c @@ -373,20 +373,14 @@ constructed (GObject *object) G_STRUCT_OFFSET (TpTestsContactsConnection, presence_mixin)); } -static const TpPresenceStatusOptionalArgumentSpec can_have_message[] = { - { "message", "s", NULL, NULL }, - { NULL } -}; - /* Must match TpTestsContactsConnectionPresenceStatusIndex in the .h */ static const TpPresenceStatusSpec my_statuses[] = { - { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, - can_have_message }, - { "busy", TP_CONNECTION_PRESENCE_TYPE_BUSY, TRUE, can_have_message }, - { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, can_have_message }, - { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, NULL }, - { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, NULL }, - { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, NULL }, + { "available", TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE, TRUE}, + { "busy", TP_CONNECTION_PRESENCE_TYPE_BUSY, TRUE, TRUE }, + { "away", TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE, TRUE }, + { "offline", TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE, FALSE }, + { "unknown", TP_CONNECTION_PRESENCE_TYPE_UNKNOWN, FALSE, FALSE }, + { "error", TP_CONNECTION_PRESENCE_TYPE_ERROR, FALSE, FALSE }, { NULL } }; @@ -404,28 +398,16 @@ my_get_contact_status (GObject *object, TpHandle contact) { TpTestsContactsConnection *self = TP_TESTS_CONTACTS_CONNECTION (object); - TpPresenceStatus *result; gpointer key = GUINT_TO_POINTER (contact); TpTestsContactsConnectionPresenceStatusIndex index; const gchar *presence_message; - GHashTable *parameters; index = GPOINTER_TO_UINT (g_hash_table_lookup ( self->priv->presence_statuses, key)); presence_message = g_hash_table_lookup ( self->priv->presence_messages, key); - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); - - if (presence_message != NULL) - g_hash_table_insert (parameters, (gpointer) "message", - tp_g_value_slice_new_string (presence_message)); - - result = tp_presence_status_new (index, parameters); - g_hash_table_unref (parameters); - - return result; + return tp_presence_status_new (index, presence_message); } static gboolean @@ -435,17 +417,9 @@ my_set_own_status (GObject *object, { TpBaseConnection *base_conn = TP_BASE_CONNECTION (object); TpTestsContactsConnectionPresenceStatusIndex index = status->index; - const gchar *message = ""; + const gchar *message = status->message; TpHandle self_handle; - if (status->optional_arguments != NULL) - { - message = g_hash_table_lookup (status->optional_arguments, "message"); - - if (message == NULL) - message = ""; - } - self_handle = tp_base_connection_get_self_handle (base_conn); tp_tests_contacts_connection_change_presences (TP_TESTS_CONTACTS_CONNECTION (object), 1, &self_handle, &index, &message); @@ -625,7 +599,6 @@ tp_tests_contacts_connection_change_presences ( for (i = 0; i < n; i++) { - GHashTable *parameters; gpointer key = GUINT_TO_POINTER (handles[i]); DEBUG ("contact#%u -> %s \"%s\"", handles[i], @@ -636,16 +609,8 @@ tp_tests_contacts_connection_change_presences ( g_hash_table_insert (self->priv->presence_messages, key, g_strdup (messages[i])); - parameters = g_hash_table_new_full (g_str_hash, - g_str_equal, NULL, (GDestroyNotify) tp_g_value_slice_free); - - if (messages[i] != NULL && messages[i][0] != '\0') - g_hash_table_insert (parameters, (gpointer) "message", - tp_g_value_slice_new_string (messages[i])); - g_hash_table_insert (presences, key, tp_presence_status_new (indexes[i], - parameters)); - g_hash_table_unref (parameters); + messages[i])); } tp_presence_mixin_emit_presence_update ((GObject *) self, |