summaryrefslogtreecommitdiff
path: root/tests/lib/simple-channel-manager.c
blob: 46523c673a0201813effd40b6c3592eb08582042 (plain)
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
/*
 * simple-channel-manager.c
 *
 * Copyright (C) 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 <telepathy-glib/telepathy-glib.h>

#include "simple-channel-manager.h"
#include "util.h"
#include "echo-chan.h"

static void channel_manager_iface_init (gpointer, gpointer);

G_DEFINE_TYPE_WITH_CODE (TpTestsSimpleChannelManager,
    tp_tests_simple_channel_manager, G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_MANAGER, channel_manager_iface_init);
    )

/* signals */
enum {
  REQUEST,
  LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];

static void
tp_tests_simple_channel_manager_class_init (TpTestsSimpleChannelManagerClass *klass)
{
  signals[REQUEST] = g_signal_new ("request",
      G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST,
      0, NULL, NULL, NULL,
      G_TYPE_NONE, 1, G_TYPE_HASH_TABLE);
}

static void
tp_tests_simple_channel_manager_init (TpTestsSimpleChannelManager *self)
{
}

static gboolean
tp_tests_simple_channel_manager_request (TpChannelManager *manager,
    gpointer request_token,
    GHashTable *request_properties)
{
  TpTestsSimpleChannelManager *self =
    TP_TESTS_SIMPLE_CHANNEL_MANAGER (manager);
  GSList *tokens;
  TpExportableChannel *channel;
  TpHandle handle = tp_asv_get_uint32 (request_properties,
      TP_PROP_CHANNEL_TARGET_HANDLE, NULL);
  gchar *path;

  g_signal_emit (manager, signals[REQUEST], 0, request_properties);

  tokens = g_slist_append (NULL, request_token);

  path = g_strdup_printf ("%s/Channel",
      tp_base_connection_get_object_path (self->conn));

  channel = tp_tests_object_new_static_class (
      TP_TESTS_TYPE_ECHO_CHANNEL,
      "connection", self->conn,
      "object-path", path,
      "handle", handle,
      NULL);

  tp_channel_manager_emit_new_channel (manager, channel, tokens);

  g_free (path);
  g_slist_free (tokens);
  g_object_unref (channel);

  return TRUE;
}

static void
channel_manager_iface_init (gpointer g_iface,
    gpointer giface_data G_GNUC_UNUSED)
{
  TpChannelManagerIface *iface = g_iface;

  iface->create_channel = tp_tests_simple_channel_manager_request;
  iface->ensure_channel = tp_tests_simple_channel_manager_request;
  iface->request_channel = tp_tests_simple_channel_manager_request;
}