2
* conn.c - an example connection
4
* Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
5
* Copyright (C) 2007 Nokia Corporation
7
* Copying and distribution of this file, with or without modification,
8
* are permitted in any medium without royalty provided the copyright
9
* notice and this notice are preserved.
14
#include <dbus/dbus-glib.h>
16
#include <telepathy-glib/dbus.h>
17
#include <telepathy-glib/errors.h>
18
#include <telepathy-glib/handle-repo-dynamic.h>
19
#include <telepathy-glib/interfaces.h>
21
#include "im-manager.h"
23
G_DEFINE_TYPE (ExampleEcho2Connection,
24
example_echo_2_connection,
25
TP_TYPE_BASE_CONNECTION)
33
struct _ExampleEcho2ConnectionPrivate
39
example_echo_2_connection_init (ExampleEcho2Connection *self)
41
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
42
EXAMPLE_TYPE_ECHO_2_CONNECTION,
43
ExampleEcho2ConnectionPrivate);
47
get_property (GObject *object,
52
ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
54
switch (property_id) {
56
g_value_set_string (value, self->priv->account);
59
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
64
set_property (GObject *object,
69
ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
71
switch (property_id) {
73
g_free (self->priv->account);
74
self->priv->account = g_utf8_strdown (g_value_get_string (value), -1);
77
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
82
finalize (GObject *object)
84
ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (object);
86
g_free (self->priv->account);
88
G_OBJECT_CLASS (example_echo_2_connection_parent_class)->finalize (object);
92
get_unique_connection_name (TpBaseConnection *conn)
94
ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (conn);
96
return g_strdup (self->priv->account);
100
example_normalize_contact (TpHandleRepoIface *repo,
107
g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_HANDLE,
108
"ID must not be empty");
112
return g_utf8_strdown (id, -1);
116
create_handle_repos (TpBaseConnection *conn,
117
TpHandleRepoIface *repos[NUM_TP_HANDLE_TYPES])
119
repos[TP_HANDLE_TYPE_CONTACT] = tp_dynamic_handle_repo_new
120
(TP_HANDLE_TYPE_CONTACT, example_normalize_contact, NULL);
124
create_channel_managers (TpBaseConnection *conn)
126
GPtrArray *ret = g_ptr_array_sized_new (1);
128
g_ptr_array_add (ret, g_object_new (EXAMPLE_TYPE_ECHO_2_IM_MANAGER,
136
start_connecting (TpBaseConnection *conn,
139
ExampleEcho2Connection *self = EXAMPLE_ECHO_2_CONNECTION (conn);
140
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
141
TP_HANDLE_TYPE_CONTACT);
143
/* In a real connection manager we'd ask the underlying implementation to
144
* start connecting, then go to state CONNECTED when finished, but here
145
* we can do it immediately. */
147
conn->self_handle = tp_handle_ensure (contact_repo, self->priv->account,
150
tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTED,
151
TP_CONNECTION_STATUS_REASON_REQUESTED);
157
shut_down (TpBaseConnection *conn)
159
/* In a real connection manager we'd ask the underlying implementation to
160
* start shutting down, then call this function when finished, but here
161
* we can do it immediately. */
162
tp_base_connection_finish_shutdown (conn);
166
example_echo_2_connection_class_init (ExampleEcho2ConnectionClass *klass)
168
static const gchar *interfaces_always_present[] = {
169
TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
171
TpBaseConnectionClass *base_class =
172
(TpBaseConnectionClass *) klass;
173
GObjectClass *object_class = (GObjectClass *) klass;
174
GParamSpec *param_spec;
176
object_class->get_property = get_property;
177
object_class->set_property = set_property;
178
object_class->finalize = finalize;
179
g_type_class_add_private (klass, sizeof (ExampleEcho2ConnectionPrivate));
181
base_class->create_handle_repos = create_handle_repos;
182
base_class->get_unique_connection_name = get_unique_connection_name;
183
base_class->create_channel_managers = create_channel_managers;
184
base_class->start_connecting = start_connecting;
185
base_class->shut_down = shut_down;
186
base_class->interfaces_always_present = interfaces_always_present;
188
param_spec = g_param_spec_string ("account", "Account name",
189
"The username of this user", NULL,
190
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
191
G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB);
192
g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec);