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
|
/*
* simple-client.c - a simple client
*
* 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-client.h"
#include <string.h>
#include <dbus/dbus-glib.h>
#include <telepathy-glib/telepathy-glib.h>
#include <telepathy-glib/telepathy-glib-dbus.h>
#include "tests/lib/util.h"
G_DEFINE_TYPE (TpTestsSimpleClient, tp_tests_simple_client, TP_TYPE_BASE_CLIENT)
static void
simple_observe_channels (
TpBaseClient *client,
TpAccount *account,
TpConnection *connection,
GList *channels,
TpChannelDispatchOperation *dispatch_operation,
GList *requests,
TpObserveChannelsContext *context)
{
TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client);
GHashTable *info;
gboolean fail;
GList *l;
/* Fail if caller set the fake "FAIL" info */
g_object_get (context, "observer-info", &info, NULL);
fail = tp_asv_get_boolean (info, "FAIL", NULL);
g_hash_table_unref (info);
if (self->observe_ctx != NULL)
{
g_object_unref (self->observe_ctx);
self->observe_ctx = NULL;
}
if (fail)
{
GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
"No observation for you!" };
tp_observe_channels_context_fail (context, &error);
return;
}
g_assert (TP_IS_ACCOUNT (account));
g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE));
g_assert (TP_IS_CONNECTION (connection));
g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE));
g_assert_cmpuint (g_list_length (channels), >, 0);
for (l = channels; l != NULL; l = g_list_next (l))
{
TpChannel *channel = l->data;
g_assert (TP_IS_CHANNEL (channel));
g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) ||
tp_proxy_get_invalidated (channel) != NULL);
}
if (dispatch_operation != NULL)
g_assert (TP_IS_CHANNEL_DISPATCH_OPERATION (dispatch_operation));
for (l = requests; l != NULL; l = g_list_next (l))
{
TpChannelRequest *request = l->data;
g_assert (TP_IS_CHANNEL_REQUEST (request));
}
self->observe_ctx = g_object_ref (context);
tp_observe_channels_context_accept (context);
}
static void
simple_add_dispatch_operation (
TpBaseClient *client,
TpAccount *account,
TpConnection *connection,
GList *channels,
TpChannelDispatchOperation *dispatch_operation,
TpAddDispatchOperationContext *context)
{
TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client);
GList *l;
g_assert (TP_IS_ACCOUNT (account));
g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE));
g_assert (TP_IS_CONNECTION (connection));
g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE));
g_assert (TP_IS_CHANNEL_DISPATCH_OPERATION (dispatch_operation));
g_assert (tp_proxy_is_prepared (dispatch_operation,
TP_CHANNEL_DISPATCH_OPERATION_FEATURE_CORE) ||
tp_proxy_get_invalidated (dispatch_operation) != NULL);
if (self->add_dispatch_ctx != NULL)
{
g_object_unref (self->add_dispatch_ctx);
self->add_dispatch_ctx = NULL;
}
g_assert_cmpuint (g_list_length (channels), >, 0);
for (l = channels; l != NULL; l = g_list_next (l))
{
TpChannel *channel = l->data;
g_assert (TP_IS_CHANNEL (channel));
g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) ||
tp_proxy_get_invalidated (channel) != NULL);
}
self->add_dispatch_ctx = g_object_ref (context);
tp_add_dispatch_operation_context_accept (context);
}
static void
simple_handle_channels (TpBaseClient *client,
TpAccount *account,
TpConnection *connection,
GList *channels,
GList *requests_satisfied,
gint64 user_action_time,
TpHandleChannelsContext *context)
{
TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (client);
GList *l;
if (self->handle_channels_ctx != NULL)
{
g_object_unref (self->handle_channels_ctx);
self->handle_channels_ctx = NULL;
}
g_assert (TP_IS_ACCOUNT (account));
g_assert (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE));
g_assert (TP_IS_CONNECTION (connection));
g_assert (tp_proxy_is_prepared (connection, TP_CONNECTION_FEATURE_CORE));
g_assert_cmpuint (g_list_length (channels), >, 0);
for (l = channels; l != NULL; l = g_list_next (l))
{
TpChannel *channel = l->data;
g_assert (TP_IS_CHANNEL (channel));
g_assert (tp_proxy_is_prepared (channel, TP_CHANNEL_FEATURE_CORE) ||
tp_proxy_get_invalidated (channel) != NULL);
}
for (l = requests_satisfied; l != NULL; l = g_list_next (l))
{
TpChannelRequest *request = l->data;
g_assert (TP_IS_CHANNEL_REQUEST (request));
}
self->handle_channels_ctx = g_object_ref (context);
tp_handle_channels_context_accept (context);
}
static void
tp_tests_simple_client_init (TpTestsSimpleClient *self)
{
}
static void
tp_tests_simple_client_dispose (GObject *object)
{
TpTestsSimpleClient *self = TP_TESTS_SIMPLE_CLIENT (object);
void (*dispose) (GObject *) =
G_OBJECT_CLASS (tp_tests_simple_client_parent_class)->dispose;
if (self->observe_ctx != NULL)
{
g_object_unref (self->observe_ctx);
self->observe_ctx = NULL;
}
if (self->add_dispatch_ctx != NULL)
{
g_object_unref (self->add_dispatch_ctx);
self->add_dispatch_ctx = NULL;
}
if (self->handle_channels_ctx != NULL)
{
g_object_unref (self->handle_channels_ctx);
self->handle_channels_ctx = NULL;
}
if (dispose != NULL)
dispose (object);
}
static void
tp_tests_simple_client_class_init (TpTestsSimpleClientClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
TpBaseClientClass *base_class = TP_BASE_CLIENT_CLASS (klass);
object_class->dispose = tp_tests_simple_client_dispose;
tp_base_client_implement_observe_channels (base_class,
simple_observe_channels);
tp_base_client_implement_add_dispatch_operation (base_class,
simple_add_dispatch_operation);
tp_base_client_implement_handle_channels (base_class,
simple_handle_channels);
}
TpTestsSimpleClient *
tp_tests_simple_client_new (TpDBusDaemon *dbus_daemon,
const gchar *name,
gboolean uniquify_name)
{
return tp_tests_object_new_static_class (TP_TESTS_TYPE_SIMPLE_CLIENT,
"dbus-daemon", dbus_daemon,
"name", name,
"uniquify-name", uniquify_name,
NULL);
}
|