[Telepathy] tp_cli_connection_manager_run_request_connection(): What parameter types.
Will Thompson
will.thompson at collabora.co.uk
Sat Oct 25 03:14:41 PDT 2008
On 24/10/08 17:17, Murray Cumming wrote:
> The GHashTable* in_parameters argument for
> tp_cli_connection_manager_run_request_connection()
> http://library.gnome.org/devel/telepathy-glib/unstable/telepathy-glib-connection-manager.html#tp-cli-connection-manager-run-request-connection
> is documented as "A dictionary mapping parameter name to the variant
> boxed value"
>
> That looks like D-Bus language. So what types should I use with
> telepathy-glib? Just using a string leads to a crash in
> marshal_variant() in D-Bus:
>
The values should be GValues. Also, the parameter names don't need to be
prefixed with their D-Bus type. (Looking at the specification, from
which the documentation for these auto-generated bindings is derived,
it's not obvious; created
http://bugs.freedesktop.org/show_bug.cgi?id=18219 .) So the middle
section of your example:
> GHashTable *parameters = g_hash_table_new (NULL, NULL);
> g_hash_table_insert (parameters, "s:account", "murrayc at murrayc.com");
> g_hash_table_insert (parameters, "s:server", "murrayc.com");
> g_hash_table_insert (parameters, "s:password", "TODO");
>
should become something like (untested):
GValue *value;
GHashTable *parameters = g_hash_table_new_full (NULL, NULL, NULL, tp_g_value_slice_free);
value = tp_g_value_slice_new (G_TYPE_STRING);
g_value_set_static_string (value, "murrayc at murrayc.com");
g_hash_table_insert (parameters, "account", value);
/* on XMPP, you shouldn't need to set the server parameter, since presumably you have an appropriate SRV record on murrayc.com. */
value = tp_g_value_slice_new (G_TYPE_STRING);
g_value_set_static_string (value, "myhovercraftisfullofeels");
g_hash_table_insert (parameters, "password", value);
Telepathy-GLib has helper methods to get values of various types out of
such string → GValue maps (namely tp_asv_get_…, where “a{sv}” is the
D-Bus type signature of these dictionaries), but none to set values. We
should add some (created
http://bugs.freedesktop.org/show_bug.cgi?id=18220 ); then this would
become:
GHashTable *parameters = g_hash_table_new (NULL, NULL, NULL, tp_g_value_slice_free);
tp_asv_set_static_string (parameters, "account", "murrayc at murrayc.com");
tp_asv_set_static_string (parameters, "password", "myzeppelinisfullofbees");
which is somewhat more palatable, and is (sadly) about the best we could
hope for in a C binding for such a D-Bus API. We could conceivably add
tp_connection_parameters_set_password (GHashTable *parameters, const
gchar *password) etc. for each well-known parameter name, but any
non-trivial program which has to care about connection parameters will
have to deal with un-specced parameters (since every CM in existence has
some bizarre protocol-specific parameters) so will wind up falling back
to tp_asv_…
In related news, I have been investigating the list_all_protocols
example in telepathy-doc, and have found some race conditions in the
initialization of TpConnectionManager which means that got-info might
never (visibly) fire… This is probably the least well-tested area of the
client-side API, which is particularly unfortunate as it's one of the
first things you'd have to deal with to write a full Telepathy client
from scratch. :(
--
Will
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://lists.freedesktop.org/archives/telepathy/attachments/20081025/5821304a/attachment.pgp
More information about the Telepathy
mailing list