summaryrefslogtreecommitdiff
path: root/tests/tpl-channel-test.c
blob: f571e6bddbb5f1c42553c27b2bf6e5aa2fae0756 (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
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
 */

/*
 * This object acts as a Text Channel context, handling a automaton to
 * set up all the needed information before connect to Text iface
 * signals.
 */

#include "tpl-channel-test.h"

#include <telepathy-logger/action-chain-internal.h>
#include <telepathy-logger/channel-internal.h>

static void call_when_ready_wrapper (TplChannel *tpl_chan, GAsyncReadyCallback
    cb, gpointer user_data);
static void pendingproc_prepare_tpl_channel (TplActionChain *ctx,
    gpointer user_data);
static void got_tpl_chan_ready_cb (GObject *obj, GAsyncResult *result,
    gpointer user_data);


struct _TplChannelTestPriv
{
  gpointer nonempty;
};

G_DEFINE_TYPE (TplChannelTest, tpl_channel_test, TPL_TYPE_CHANNEL)

static void
dispose (GObject *obj)
{
  G_OBJECT_CLASS (tpl_channel_test_parent_class)->dispose (obj);
}

static void
finalize (GObject *obj)
{
  G_OBJECT_CLASS (tpl_channel_test_parent_class)->finalize (obj);
}


static void
tpl_channel_test_class_init (TplChannelTestClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  TplChannelClass *tpl_chan_class = TPL_CHANNEL_CLASS (klass);

  object_class->dispose = dispose;
  object_class->finalize = finalize;

  tpl_chan_class->call_when_ready = call_when_ready_wrapper;

  g_type_class_add_private (object_class, sizeof (TplChannelTestPriv));
}


static void
tpl_channel_test_init (TplChannelTest *self)
{
  TplChannelTestPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
      TPL_TYPE_CHANNEL_TEST, TplChannelTestPriv);
  self->priv = priv;
}


/**
 * @conn: TpConnection instance owning the channel
 * @object_path: the channel's DBus path
 * @tp_chan_props: channel's immutable properties, obtained for example by
 * %tp_channel_borrow_immutable_properties()
 * @error: location of the GError, used in case a problem is raised while
 * creating the channel
 *
 * Convenience function to create a new TPL Channel Text proxy. The returned
 * #TplChannelTest is not guaranteed to be ready at the point of return. Use #TpChannel
 * methods casting the #TplChannelTest instance to a TpChannel
 *
 * TplChannelTest instances are subclasses or the abstract TplChannel which is
 * subclass of TpChannel.
 *
 * Returns: the TplChannelTest instance or %NULL in @object_path is not valid
 */
TplChannelTest *
tpl_channel_test_new (TpConnection *conn,
    const gchar *object_path,
    GHashTable *tp_chan_props,
    TpAccount *account,
    GError **error)
{
  return g_object_new (TPL_TYPE_CHANNEL_TEST,
      "account", account,
      NULL);
}


static void
call_when_ready_wrapper (TplChannel *tpl_chan,
    GAsyncReadyCallback cb,
    gpointer user_data)
{
  tpl_channel_test_call_when_ready (TPL_CHANNEL_TEST (tpl_chan), cb, user_data);
}

void
tpl_channel_test_call_when_ready (TplChannelTest *self,
    GAsyncReadyCallback cb, gpointer user_data)
{
  TplActionChain *actions;

  /* first: connect signals, so none are lost
   * second: prepare all TplChannel
   * then: us TpContact to cache my contact and the remote one.
   * If for any reason, the order is changed, it's need to check what objects
   * are unreferenced by g_object_unref: after the order change, it might
   * happend that an object still has to be created after the change */
  actions = _tpl_action_chain_new_async (G_OBJECT (self), cb, user_data);
  _tpl_action_chain_append (actions, pendingproc_prepare_tpl_channel, NULL);
  /* start the queue consuming */
  _tpl_action_chain_continue (actions);
}


static void
pendingproc_prepare_tpl_channel (TplActionChain *ctx,
    gpointer user_data)
{
  TplChannel *tpl_chan = TPL_CHANNEL (_tpl_action_chain_get_object (ctx));

  g_debug ("prepare tpl");
  TPL_CHANNEL_GET_CLASS (tpl_chan)->call_when_ready_protected (tpl_chan,
      got_tpl_chan_ready_cb, ctx);
}


static void
got_tpl_chan_ready_cb (GObject *obj,
    GAsyncResult *result,
    gpointer user_data)
{
  TplActionChain *ctx = user_data;
  g_debug ("PREPARE");

  if (_tpl_action_chain_new_finish (result) == TRUE)
    _tpl_action_chain_continue (ctx);
  return;
}