From f6c708f710a0e300c4fb5e33e417b37ea418dda7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 13 Sep 2012 17:57:35 +0100 Subject: [PATCH 06/21] replace sealed struct members with getters and use TpProtocol Originally two patches for 'next' by Jonny Lamb. Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55391 --- src/mcd-account-manager.c | 4 +- src/mcd-account.c | 98 ++++++++++++++++++++++++--------------- src/mcd-channel.c | 4 +- src/mcd-connection.c | 7 +-- src/mcd-dispatcher.c | 2 +- src/mcd-manager-priv.h | 2 +- src/mcd-manager.c | 18 +++---- src/mcd-master.c | 6 +-- tests/twisted/mc-debug-server.c | 4 +- 9 files changed, 85 insertions(+), 60 deletions(-) diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index e7b2161..57796e6 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -1387,7 +1387,7 @@ migrate_accounts (McdAccountManager *self, if (cm == NULL) continue; - if (!tp_strdiff (cm->name, "butterfly")) + if (!tp_strdiff (tp_connection_manager_get_name (cm), "butterfly")) migrate_butterfly_account (self, account, lad); } } @@ -1481,7 +1481,7 @@ register_dbus_service (McdAccountManager *account_manager) if (priv->dbus_registered) return; - dbus_connection = TP_PROXY (priv->dbus_daemon)->dbus_connection; + dbus_connection = tp_proxy_get_dbus_connection (TP_PROXY (priv->dbus_daemon)); if (!tp_dbus_daemon_request_name (priv->dbus_daemon, TP_ACCOUNT_MANAGER_BUS_NAME, diff --git a/src/mcd-account.c b/src/mcd-account.c index 256575b..3e3e232 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -2187,10 +2187,17 @@ properties_iface_init (TpSvcDBusPropertiesClass *iface, gpointer iface_data) static GType mc_param_type (const TpConnectionManagerParam *param) { - if (G_UNLIKELY (param == NULL)) return G_TYPE_INVALID; - if (G_UNLIKELY (!param->dbus_signature)) return G_TYPE_INVALID; + const gchar *dbus_signature; - switch (param->dbus_signature[0]) + if (G_UNLIKELY (param == NULL)) + return G_TYPE_INVALID; + + dbus_signature = tp_connection_manager_param_get_dbus_signature (param); + + if (G_UNLIKELY (!dbus_signature)) + return G_TYPE_INVALID; + + switch (dbus_signature[0]) { case DBUS_TYPE_STRING: return G_TYPE_STRING; @@ -2222,13 +2229,13 @@ mc_param_type (const TpConnectionManagerParam *param) return G_TYPE_UINT64; case DBUS_TYPE_ARRAY: - if (param->dbus_signature[1] == DBUS_TYPE_STRING) + if (dbus_signature[1] == DBUS_TYPE_STRING) return G_TYPE_STRV; /* other array types are not supported: * fall through the default case */ default: g_warning ("skipping parameter %s, unknown type %s", - param->name, param->dbus_signature); + tp_connection_manager_param_get_name (param), dbus_signature); } return G_TYPE_INVALID; } @@ -2341,8 +2348,9 @@ mcd_account_check_parameters (McdAccount *account, gpointer user_data) { McdAccountPrivate *priv = account->priv; - TpConnectionManagerProtocol *protocol; - const TpConnectionManagerParam *param; + TpProtocol *protocol; + GList *params = NULL; + GList *iter; GError *error = NULL; g_return_if_fail (callback != NULL); @@ -2358,15 +2366,20 @@ mcd_account_check_parameters (McdAccount *account, goto out; } - for (param = protocol->params; param->name != NULL; param++) + params = tp_protocol_dup_params (protocol); + + for (iter = params; iter != NULL; iter = iter->next) { - if (!(param->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED)) + TpConnectionManagerParam *param = iter->data; + const gchar *param_name = tp_connection_manager_param_get_name (param); + + if (!tp_connection_manager_param_is_required ((param))) continue; - if (!mcd_account_get_parameter (account, param->name, NULL, NULL)) + if (!mcd_account_get_parameter (account, param_name, NULL, NULL)) { g_set_error (&error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "missing required parameter '%s'", param->name); + "missing required parameter '%s'", param_name); goto out; } } @@ -2379,7 +2392,9 @@ out: callback (account, error, user_data); g_clear_error (&error); - tp_clear_pointer (&protocol, tp_connection_manager_protocol_free); + g_list_free_full (params, + (GDestroyNotify) tp_connection_manager_param_free); + g_clear_object (&protocol); } static void @@ -2437,24 +2452,26 @@ set_parameter_changed (GHashTable *dbus_properties, const TpConnectionManagerParam *param, const GValue *new_value) { - DEBUG ("Parameter %s changed", param->name); + const gchar *name = tp_connection_manager_param_get_name (param); + + DEBUG ("Parameter %s changed", name); /* can the param be updated on the fly? If yes, prepare to do so; and if * not, prepare to reset the connection */ - if (param->flags & TP_CONN_MGR_PARAM_FLAG_DBUS_PROPERTY) + if (tp_connection_manager_param_is_dbus_property (param)) { - g_hash_table_insert (dbus_properties, g_strdup (param->name), + g_hash_table_insert (dbus_properties, g_strdup (name), tp_g_value_slice_dup (new_value)); } else { - g_ptr_array_add (not_yet, g_strdup (param->name)); + g_ptr_array_add (not_yet, g_strdup (name)); } } static gboolean check_one_parameter_update (McdAccount *account, - TpConnectionManagerProtocol *protocol, + TpProtocol *protocol, GHashTable *dbus_properties, GPtrArray *not_yet, const gchar *name, @@ -2462,14 +2479,14 @@ check_one_parameter_update (McdAccount *account, GError **error) { const TpConnectionManagerParam *param = - tp_connection_manager_protocol_get_param (protocol, name); + tp_protocol_get_param (protocol, name); GType type; if (param == NULL) { g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "Protocol '%s' does not have parameter '%s'", - protocol->name, name); + tp_protocol_get_name (protocol), name); return FALSE; } @@ -2480,7 +2497,7 @@ check_one_parameter_update (McdAccount *account, /* FIXME: use D-Bus type names, not GType names. */ g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "parameter '%s' must be of type %s, not %s", - param->name, + tp_connection_manager_param_get_name (param), g_type_name (type), G_VALUE_TYPE_NAME (new_value)); return FALSE; } @@ -2493,7 +2510,7 @@ check_one_parameter_update (McdAccount *account, /* Check if the parameter's current value (or its default, if it has * one and it's not set to anything) matches the new value. */ - if (mcd_account_get_parameter (account, param->name, + if (mcd_account_get_parameter (account, tp_connection_manager_param_get_name (param), ¤t_value, NULL) || tp_connection_manager_param_get_default (param, ¤t_value)) { @@ -2517,14 +2534,14 @@ check_one_parameter_update (McdAccount *account, static gboolean check_one_parameter_unset (McdAccount *account, - TpConnectionManagerProtocol *protocol, + TpProtocol *protocol, GHashTable *dbus_properties, GPtrArray *not_yet, const gchar *name, GError **error) { const TpConnectionManagerParam *param = - tp_connection_manager_protocol_get_param (protocol, name); + tp_protocol_get_param (protocol, name); /* The spec decrees that “If the given parameters […] do not exist at all, * the account manager MUST accept this without error.”. Thus this function @@ -2536,8 +2553,8 @@ check_one_parameter_unset (McdAccount *account, { GValue current_value = G_VALUE_INIT; - if (mcd_account_get_parameter (account, param->name, ¤t_value, - NULL)) + if (mcd_account_get_parameter (account, tp_connection_manager_param_get_name (param), + ¤t_value, NULL)) { /* There's an existing value; let's see if it's the same as the * default, if any. @@ -2557,7 +2574,7 @@ check_one_parameter_unset (McdAccount *account, /* It has no default; we're gonna have to reconnect to make * this take effect. */ - g_ptr_array_add (not_yet, g_strdup (param->name)); + g_ptr_array_add (not_yet, g_strdup (tp_connection_manager_param_get_name (param))); } g_value_unset (¤t_value); @@ -2569,7 +2586,7 @@ check_one_parameter_unset (McdAccount *account, static gboolean check_parameters (McdAccount *account, - TpConnectionManagerProtocol *protocol, + TpProtocol *protocol, GHashTable *params, const gchar **unset, GHashTable *dbus_properties, @@ -2622,7 +2639,7 @@ _mcd_account_set_parameters (McdAccount *account, GHashTable *params, GHashTable *dbus_properties = NULL; GPtrArray *not_yet = NULL; GError *error = NULL; - TpConnectionManagerProtocol *protocol = NULL; + TpProtocol *protocol = NULL; DEBUG ("called"); if (G_UNLIKELY (!priv->manager && !load_manager (account))) @@ -2669,7 +2686,7 @@ out: g_clear_error (&error); tp_clear_pointer (&dbus_properties, g_hash_table_unref); tp_clear_pointer (¬_yet, g_ptr_array_unref); - tp_clear_pointer (&protocol, tp_connection_manager_protocol_free); + g_clear_object (&protocol); } static void @@ -2804,7 +2821,7 @@ register_dbus_service (McdAccount *self, dbus_daemon = self->priv->dbus_daemon; g_return_if_fail (dbus_daemon != NULL); - dbus_connection = TP_PROXY (dbus_daemon)->dbus_connection; + dbus_connection = tp_proxy_get_dbus_connection (TP_PROXY (dbus_daemon)); if (G_LIKELY (dbus_connection)) dbus_g_connection_register_g_object (dbus_connection, @@ -3532,8 +3549,9 @@ GHashTable * _mcd_account_dup_parameters (McdAccount *account) { McdAccountPrivate *priv; - TpConnectionManagerProtocol *protocol; - const TpConnectionManagerParam *param; + TpProtocol *protocol; + GList *protocol_params; + GList *iter; GHashTable *params; g_return_val_if_fail (MCD_IS_ACCOUNT (account), NULL); @@ -3569,19 +3587,25 @@ _mcd_account_dup_parameters (McdAccount *account) g_free, (GDestroyNotify) tp_g_value_slice_free); - for (param = protocol->params; param->name != NULL; param++) + protocol_params = tp_protocol_dup_params (protocol); + + for (iter = protocol_params; iter != NULL; iter = iter->next) { + TpConnectionManagerParam *param = iter->data; + const gchar *name = tp_connection_manager_param_get_name (param); GValue v = G_VALUE_INIT; - if (mcd_account_get_parameter (account, param->name, &v, NULL)) + if (mcd_account_get_parameter (account, name, &v, NULL)) { - g_hash_table_insert (params, g_strdup (param->name), + g_hash_table_insert (params, g_strdup (name), tp_g_value_slice_dup (&v)); g_value_unset (&v); } } - tp_connection_manager_protocol_free (protocol); + g_list_free_full (protocol_params, + (GDestroyNotify) tp_connection_manager_param_free); + g_object_unref (protocol); return params; } @@ -4704,7 +4728,7 @@ mcd_account_parameter_is_secret (McdAccount *self, const gchar *name) priv->protocol_name, name); return (param != NULL && - (param->flags & TP_CONN_MGR_PARAM_FLAG_SECRET) != 0); + tp_connection_manager_param_is_secret (param)); } void diff --git a/src/mcd-channel.c b/src/mcd-channel.c index 3d6b066..4f0a893 100644 --- a/src/mcd-channel.c +++ b/src/mcd-channel.c @@ -749,7 +749,7 @@ mcd_channel_get_object_path (McdChannel *channel) { McdChannelPrivate *priv = MCD_CHANNEL_PRIV (channel); - return priv->tp_chan ? TP_PROXY (priv->tp_chan)->object_path : NULL; + return priv->tp_chan ? tp_proxy_get_object_path (priv->tp_chan) : NULL; } /* @@ -825,7 +825,7 @@ mcd_channel_get_error (McdChannel *channel) return priv->error; if (priv->tp_chan) - return TP_PROXY (priv->tp_chan)->invalidated; + return tp_proxy_get_invalidated (priv->tp_chan); return NULL; } diff --git a/src/mcd-connection.c b/src/mcd-connection.c index f251849..8fc7aa3 100644 --- a/src/mcd-connection.c +++ b/src/mcd-connection.c @@ -494,7 +494,8 @@ _mcd_connection_call_disconnect (McdConnection *connection) { TpConnection *tp_conn = connection->priv->tp_conn; - if (!tp_conn || TP_PROXY (tp_conn)->invalidated != NULL) return; + if (!tp_conn || tp_proxy_get_invalidated (TP_PROXY (tp_conn)) != NULL) + return; if (tp_connection_get_status (tp_conn, NULL) == TP_CONNECTION_STATUS_DISCONNECTED) return; @@ -2536,7 +2537,7 @@ mcd_connection_get_object_path (McdConnection *connection) McdConnectionPrivate *priv = connection->priv; if (priv->tp_conn) - return TP_PROXY (priv->tp_conn)->object_path; + return tp_proxy_get_object_path (TP_PROXY (priv->tp_conn)); else return NULL; } @@ -2547,7 +2548,7 @@ mcd_connection_get_name (McdConnection *connection) McdConnectionPrivate *priv = connection->priv; if (priv->tp_conn) - return TP_PROXY (priv->tp_conn)->bus_name; + return tp_proxy_get_bus_name (TP_PROXY (priv->tp_conn)); else return NULL; } diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c index 48ebc83..23c943d 100644 --- a/src/mcd-dispatcher.c +++ b/src/mcd-dispatcher.c @@ -788,7 +788,7 @@ mcd_dispatcher_constructed (GObject *object) G_CALLBACK (mcd_dispatcher_client_registry_ready_cb), object); - dgc = TP_PROXY (priv->dbus_daemon)->dbus_connection; + dgc = tp_proxy_get_dbus_connection (TP_PROXY (priv->dbus_daemon)); if (!tp_dbus_daemon_request_name (priv->dbus_daemon, TP_CHANNEL_DISPATCHER_BUS_NAME, diff --git a/src/mcd-manager-priv.h b/src/mcd-manager-priv.h index 3dc8a42..76c97cd 100644 --- a/src/mcd-manager-priv.h +++ b/src/mcd-manager-priv.h @@ -31,7 +31,7 @@ G_BEGIN_DECLS -TpConnectionManagerProtocol *_mcd_manager_dup_protocol (McdManager *manager, +TpProtocol *_mcd_manager_dup_protocol (McdManager *manager, const gchar *protocol); G_END_DECLS diff --git a/src/mcd-manager.c b/src/mcd-manager.c index 5c0e9fb..39d09ea 100644 --- a/src/mcd-manager.c +++ b/src/mcd-manager.c @@ -338,21 +338,21 @@ mcd_manager_get_name (McdManager *manager) return priv->name; } -TpConnectionManagerProtocol * +TpProtocol * _mcd_manager_dup_protocol (McdManager *manager, const gchar *protocol) { - const TpConnectionManagerProtocol *p; + TpProtocol *p; g_return_val_if_fail (MCD_IS_MANAGER (manager), NULL); g_return_val_if_fail (protocol != NULL, NULL); - p = tp_connection_manager_get_protocol (manager->priv->tp_conn_mgr, - protocol); + p = tp_connection_manager_get_protocol_object (manager->priv->tp_conn_mgr, + protocol); if (p == NULL) return NULL; else - return tp_connection_manager_protocol_copy (p); + return g_object_ref (p); } const TpConnectionManagerParam * @@ -360,7 +360,7 @@ mcd_manager_get_protocol_param (McdManager *manager, const gchar *protocol, const gchar *param) { McdManagerPrivate *priv; - const TpConnectionManagerProtocol *cm_protocol; + TpProtocol *cm_protocol; g_return_val_if_fail (MCD_IS_MANAGER (manager), NULL); g_return_val_if_fail (protocol != NULL, NULL); @@ -368,13 +368,13 @@ mcd_manager_get_protocol_param (McdManager *manager, const gchar *protocol, priv = manager->priv; - cm_protocol = tp_connection_manager_get_protocol (priv->tp_conn_mgr, - protocol); + cm_protocol = tp_connection_manager_get_protocol_object (priv->tp_conn_mgr, + protocol); if (cm_protocol == NULL) return NULL; - return tp_connection_manager_protocol_get_param (cm_protocol, param); + return tp_protocol_get_param (cm_protocol, param); } McdConnection * diff --git a/src/mcd-master.c b/src/mcd-master.c index ccf34d6..c7f1d97 100644 --- a/src/mcd-master.c +++ b/src/mcd-master.c @@ -287,8 +287,8 @@ _mcd_master_get_property (GObject * obj, guint prop_id, g_value_set_object (val, priv->dbus_daemon); break; case PROP_DBUS_CONNECTION: - g_value_set_pointer (val, - TP_PROXY (priv->dbus_daemon)->dbus_connection); + g_value_set_pointer (val, tp_proxy_get_dbus_connection ( + TP_PROXY (priv->dbus_daemon))); break; case PROP_ACCOUNT_MANAGER: g_value_set_object (val, priv->account_manager); @@ -389,7 +389,7 @@ mcd_master_constructor (GType type, guint n_params, dbus_connection_set_exit_on_disconnect ( dbus_g_connection_get_connection ( - TP_PROXY (priv->dbus_daemon)->dbus_connection), + tp_proxy_get_dbus_connection (TP_PROXY (priv->dbus_daemon))), TRUE); mcd_kludge_transport_install (master); diff --git a/tests/twisted/mc-debug-server.c b/tests/twisted/mc-debug-server.c index 03055e8..15944fe 100644 --- a/tests/twisted/mc-debug-server.c +++ b/tests/twisted/mc-debug-server.c @@ -73,7 +73,7 @@ billy_idle (gpointer user_data) { DBusMessage *reply = user_data; DBusConnection *connection = dbus_g_connection_get_connection ( - ((TpProxy *) bus_daemon)->dbus_connection); + tp_proxy_get_dbus_connection (bus_daemon)); if (!dbus_connection_send (connection, reply, NULL)) g_error ("Out of memory"); @@ -192,7 +192,7 @@ main (int argc, char **argv) * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any * effect, we need to install it as soon as possible */ connection = dbus_g_connection_get_connection ( - ((TpProxy *) bus_daemon)->dbus_connection); + tp_proxy_get_dbus_connection (bus_daemon)); dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL); #if ENABLE_GNOME_KEYRING -- 1.7.10.4