1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* simple-channel-dispatch-operation.c - a simple channel dispatch operation
* service.
*
* Copyright © 2010 Collabora Ltd. <http://www.collabora.co.uk/>
*
* Copying and distribution of this file, with or without modification,
* are permitted in any medium without royalty provided the copyright
* notice and this notice are preserved.
*/
#include "config.h"
#include "simple-channel-dispatch-operation.h"
#include "util.h"
#include <telepathy-glib/telepathy-glib.h>
#include <telepathy-glib/telepathy-glib-dbus.h>
static void channel_dispatch_operation_iface_init (gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelDispatchOperation,
tp_tests_simple_channel_dispatch_operation,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_DISPATCH_OPERATION,
channel_dispatch_operation_iface_init);
)
/* TP_IFACE_CHANNEL_DISPATCH_OPERATION is implied */
static const char *CHANNEL_DISPATCH_OPERATION_INTERFACES[] = { NULL };
static const gchar *CHANNEL_DISPATCH_OPERATION_POSSIBLE_HANDLERS[] = {
TP_CLIENT_BUS_NAME_BASE ".Badger", NULL, };
enum
{
PROP_0,
PROP_INTERFACES,
PROP_CONNECTION,
PROP_ACCOUNT,
PROP_CHANNEL,
PROP_CHANNEL_PROPERTIES,
PROP_POSSIBLE_HANDLERS,
};
struct _SimpleChannelDispatchOperationPrivate
{
gchar *conn_path;
gchar *account_path;
gchar *chan_path;
GHashTable *chan_props;
};
static void
tp_tests_simple_channel_dispatch_operation_handle_with (
TpSvcChannelDispatchOperation *iface,
const gchar *handler,
gint64 user_action_timestamp,
GDBusMethodInvocation *context)
{
if (!tp_strdiff (handler, "FAIL"))
{
GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "Nope" };
g_dbus_method_invocation_return_gerror (context, &error);
return;
}
g_dbus_method_invocation_return_value (context, NULL);
}
static void
tp_tests_simple_channel_dispatch_operation_claim (
TpSvcChannelDispatchOperation *iface,
GDBusMethodInvocation *context)
{
tp_svc_channel_dispatch_operation_emit_finished (iface, "", "");
g_dbus_method_invocation_return_value (context, NULL);
}
static void
channel_dispatch_operation_iface_init (gpointer klass,
gpointer unused G_GNUC_UNUSED)
{
#define IMPLEMENT(x) tp_svc_channel_dispatch_operation_implement_##x (\
klass, tp_tests_simple_channel_dispatch_operation_##x)
IMPLEMENT(handle_with);
IMPLEMENT(claim);
#undef IMPLEMENT
}
static void
tp_tests_simple_channel_dispatch_operation_init (TpTestsSimpleChannelDispatchOperation *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
TP_TESTS_TYPE_SIMPLE_CHANNEL_DISPATCH_OPERATION,
TpTestsSimpleChannelDispatchOperationPrivate);
/* we need something of the appropriate type so GetAll() won't crash */
self->priv->chan_path = g_strdup ("/");
self->priv->account_path = g_strdup ("/");
self->priv->conn_path = g_strdup ("/");
self->priv->chan_props = tp_asv_new (NULL, NULL);
}
static void
tp_tests_simple_channel_dispatch_operation_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *spec)
{
TpTestsSimpleChannelDispatchOperation *self =
TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION (object);
switch (property_id) {
case PROP_INTERFACES:
g_value_set_boxed (value, CHANNEL_DISPATCH_OPERATION_INTERFACES);
break;
case PROP_ACCOUNT:
g_value_set_boxed (value, self->priv->account_path);
break;
case PROP_CONNECTION:
g_value_set_boxed (value, self->priv->conn_path);
break;
case PROP_CHANNEL:
g_value_set_boxed (value, self->priv->chan_path);
break;
case PROP_CHANNEL_PROPERTIES:
g_value_set_boxed (value, self->priv->chan_props);
break;
case PROP_POSSIBLE_HANDLERS:
g_value_set_boxed (value, CHANNEL_DISPATCH_OPERATION_POSSIBLE_HANDLERS);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, spec);
break;
}
}
static void
tp_tests_simple_channel_dispatch_operation_finalize (GObject *object)
{
TpTestsSimpleChannelDispatchOperation *self =
TP_TESTS_SIMPLE_CHANNEL_DISPATCH_OPERATION (object);
void (*finalize) (GObject *) =
G_OBJECT_CLASS (tp_tests_simple_channel_dispatch_operation_parent_class)->finalize;
g_free (self->priv->conn_path);
g_free (self->priv->account_path);
g_free (self->priv->chan_path);
tp_clear_pointer (&self->priv->chan_props, g_hash_table_unref);
if (finalize != NULL)
finalize (object);
}
/**
* This class currently only provides the minimum for
* tp_channel_dispatch_operation_prepare to succeed. This turns out to be only a working
* Properties.GetAll().
*/
static void
tp_tests_simple_channel_dispatch_operation_class_init (TpTestsSimpleChannelDispatchOperationClass *klass)
{
GObjectClass *object_class = (GObjectClass *) klass;
GParamSpec *param_spec;
static TpDBusPropertiesMixinPropImpl a_props[] = {
{ "Interfaces", "interfaces", NULL },
{ "Connection", "connection", NULL },
{ "Account", "account", NULL },
{ "Channel", "channel", NULL },
{ "ChannelProperties", "channel-properties", NULL },
{ "PossibleHandlers", "possible-handlers", NULL },
{ NULL }
};
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
{ TP_IFACE_CHANNEL_DISPATCH_OPERATION,
tp_dbus_properties_mixin_getter_gobject_properties,
NULL,
a_props
},
{ NULL },
};
g_type_class_add_private (klass, sizeof (TpTestsSimpleChannelDispatchOperationPrivate));
object_class->get_property = tp_tests_simple_channel_dispatch_operation_get_property;
object_class->finalize = tp_tests_simple_channel_dispatch_operation_finalize;
param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
"In this case we only implement ChannelDispatchOperation, so none.",
G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
param_spec = g_param_spec_boxed ("connection", "connection path",
"Connection path",
DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
param_spec = g_param_spec_boxed ("account", "account path",
"Account path",
DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec);
param_spec = g_param_spec_boxed ("channel", "channel path",
"Channel path",
DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CHANNEL, param_spec);
param_spec = g_param_spec_boxed ("channel-properties", "channel properties",
"Channel properties",
TP_HASH_TYPE_STRING_VARIANT_MAP,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CHANNEL_PROPERTIES,
param_spec);
param_spec = g_param_spec_boxed ("possible-handlers", "possible handlers",
"possible handles",
G_TYPE_STRV,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_POSSIBLE_HANDLERS,
param_spec);
klass->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (TpTestsSimpleChannelDispatchOperationClass, dbus_props_class));
}
void
tp_tests_simple_channel_dispatch_operation_set_conn_path (
TpTestsSimpleChannelDispatchOperation *self,
const gchar *conn_path)
{
g_free (self->priv->conn_path);
self->priv->conn_path = g_strdup (conn_path);
}
void
tp_tests_simple_channel_dispatch_operation_set_channel (
TpTestsSimpleChannelDispatchOperation *self,
TpChannel *chan)
{
g_hash_table_unref (self->priv->chan_props);
g_free (self->priv->chan_path);
self->priv->chan_path = g_strdup (tp_proxy_get_object_path (chan));
self->priv->chan_props = tp_tests_dup_channel_props_asv (chan);
}
void
tp_tests_simple_channel_dispatch_operation_set_account_path (
TpTestsSimpleChannelDispatchOperation *self,
const gchar *account_path)
{
g_free (self->priv->account_path);
self->priv->account_path = g_strdup (account_path);
}
|