2
* protocol.c - an example Protocol
4
* Copyright © 2007-2010 Collabora Ltd.
6
* Copying and distribution of this file, with or without modification,
7
* are permitted in any medium without royalty provided the copyright
8
* notice and this notice are preserved.
13
#include <telepathy-glib/telepathy-glib.h>
16
#include "media-manager.h"
18
G_DEFINE_TYPE (ExampleCallableProtocol,
19
example_callable_protocol,
20
TP_TYPE_BASE_PROTOCOL)
23
example_callable_protocol_init (
24
ExampleCallableProtocol *self)
29
example_callable_protocol_check_contact_id (const gchar *id,
33
g_return_val_if_fail (id != NULL, FALSE);
37
g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_HANDLE,
38
"ID must not be empty");
43
*normal = g_utf8_normalize (id, -1, G_NORMALIZE_ALL_COMPOSE);
49
account_param_filter (const TpCMParamSpec *paramspec,
53
const gchar *id = g_value_get_string (value);
55
return example_callable_protocol_check_contact_id (id, NULL, error);
58
static const TpCMParamSpec example_callable_example_params[] = {
59
{ "account", "s", G_TYPE_STRING,
60
TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
61
NULL, /* no default */
62
0, /* unused, formerly struct offset */
64
NULL, /* filter data, unused here */
65
NULL }, /* setter data, now unused */
66
{ "simulation-delay", "u", G_TYPE_UINT,
67
TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
68
GUINT_TO_POINTER (1000), /* default */
69
0, /* unused, formerly struct offset */
71
NULL, /* filter data, unused here */
72
NULL }, /* setter data, now unused */
76
static const TpCMParamSpec *
77
get_parameters (TpBaseProtocol *self)
79
return example_callable_example_params;
82
static TpBaseConnection *
83
new_connection (TpBaseProtocol *protocol,
87
ExampleCallableConnection *conn;
91
account = tp_asv_get_string (asv, "account");
92
/* telepathy-glib checked this for us */
93
g_assert (account != NULL);
95
sim_delay = tp_asv_get_uint32 (asv, "simulation-delay", NULL);
97
conn = EXAMPLE_CALLABLE_CONNECTION (
98
g_object_new (EXAMPLE_TYPE_CALLABLE_CONNECTION,
100
"protocol", tp_base_protocol_get_name (protocol),
101
"simulation-delay", sim_delay,
104
return (TpBaseConnection *) conn;
108
normalize_contact (TpBaseProtocol *self G_GNUC_UNUSED,
109
const gchar *contact,
114
if (example_callable_protocol_check_contact_id (contact, &normal, error))
121
identify_account (TpBaseProtocol *self G_GNUC_UNUSED,
125
const gchar *account = tp_asv_get_string (asv, "account");
128
return normalize_contact (self, account, error);
130
g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
131
"'account' parameter not given");
136
get_interfaces (TpBaseProtocol *self)
142
get_connection_details (TpBaseProtocol *self G_GNUC_UNUSED,
143
GStrv *connection_interfaces,
144
GType **channel_managers,
146
gchar **english_name,
149
if (connection_interfaces != NULL)
151
*connection_interfaces = g_strdupv (
152
(GStrv) example_callable_connection_get_possible_interfaces ());
155
if (channel_managers != NULL)
157
GType types[] = { EXAMPLE_TYPE_CALLABLE_MEDIA_MANAGER, G_TYPE_INVALID };
159
*channel_managers = g_memdup (types, sizeof (types));
162
if (icon_name != NULL)
163
*icon_name = g_strdup ("face-smile");
165
if (english_name != NULL)
166
*english_name = g_strdup ("Example with StreamedMedia calls");
168
if (vcard_field != NULL)
169
*vcard_field = g_strdup ("x-telepathy-example");
173
example_callable_protocol_class_init (
174
ExampleCallableProtocolClass *klass)
176
TpBaseProtocolClass *base_class =
177
(TpBaseProtocolClass *) klass;
179
base_class->get_parameters = get_parameters;
180
base_class->new_connection = new_connection;
182
base_class->normalize_contact = normalize_contact;
183
base_class->identify_account = identify_account;
184
base_class->get_interfaces = get_interfaces;
185
base_class->get_connection_details = get_connection_details;