summaryrefslogtreecommitdiff
path: root/telepathy-glib/client-channel-factory.c
blob: 3dbf7afb41f86738faeb0a4230af531a81af1f31 (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
166
167
168
169
170
171
172
/*
 * Interface for channel factories
 *
 * Copyright © 2010 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
 */

/**
 * SECTION:client-channel-factory
 * @title: TpClientChannelFactoryInterface
 * @short_description: an interface for client channel factories
 *
 * Client channel factories are used to create channel proxies. An application
 * wanting to use its own #TpChannel subclass has to implement an object
 * implementing the #TpClientChannelFactoryInterface interface.
 *
 * Once a channel has been created by a factory using
 * tp_client_channel_factory_create_channel(), the caller should then prepare
 * on it the channel features returned by
 * tp_client_channel_factory_dup_channel_features() using
 * tp_proxy_prepare_async().
 *
 * Since: 0.13.2
 */

/**
 * TpClientChannelFactory:
 *
 * Opaque typedef representing a #GObject that implements
 * the %TP_TYPE_CLIENT_CHANNEL_FACTORY interface.
 *
 * Since: 0.13.6
 */

/**
 * TpClientChannelFactoryInterface:
 * @parent: the parent
 * @create_channel: obsolete version of @obj_create_channel which does not
 *  receive the object instance as an argument
 * @dup_channel_features: obsolete version of @obj_dup_channel_features which
 *  does not receive the object instance as an argument
 * @obj_create_channel: virtual method used to create channels;
 *  see tp_client_channel_factory_create_channel()
 * @obj_dup_channel_features: virtual method returning channel features that
 *  have to be prepared on newly created channels;
 *  see tp_client_channel_factory_dup_channel_features()
 *
 * Interface for a channel factory
 *
 * Since: 0.13.2
 */

#include "config.h"

#include "telepathy-glib/client-channel-factory.h"

#include <telepathy-glib/util.h>

#define DEBUG_FLAG TP_DEBUG_CLIENT
#include "telepathy-glib/debug-internal.h"

G_DEFINE_INTERFACE(TpClientChannelFactory, tp_client_channel_factory,
    G_TYPE_OBJECT)

/* Deprecated module can use deprecated APIs */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS

static void
tp_client_channel_factory_default_init (TpClientChannelFactoryInterface *iface)
{
}

/**
 * tp_client_channel_factory_create_channel:
 * @self: a client channel factory
 * @conn: a #TpConnection
 * @path: the object path of the channel
 * @properties: (transfer none) (element-type utf8 GObject.Value):
 * the immutable properties of the channel
 * @error: used to indicate the error if %NULL is returned
 *
 * Function called when a channel need to be created.
 * Implementation can return a subclass of #TpChannel if they need to.
 *
 * Changed in 0.13.6: the function's signature was previously wrong;
 * it expected an object instance as its first parameter, but the type of the
 * parameter was the type of the interface vtable.
 *
 * Returns: (transfer full): a new channel proxy, or %NULL on invalid arguments
 *
 * Since: 0.13.2
 */
TpChannel *
tp_client_channel_factory_create_channel (TpClientChannelFactory *self,
    TpConnection *conn,
    const gchar *path,
    GHashTable *properties,
    GError **error)
{
  TpClientChannelFactoryInterface *iface = TP_CLIENT_CHANNEL_FACTORY_GET_IFACE (
      self);

  g_return_val_if_fail (TP_IS_CLIENT_CHANNEL_FACTORY (self), NULL);
  g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
  g_return_val_if_fail (path != NULL, NULL);
  g_return_val_if_fail (properties != NULL, NULL);

  if (iface->obj_create_channel != NULL)
    return iface->obj_create_channel (self, conn, path, properties, error);

  if (iface->create_channel != NULL)
    return iface->create_channel (iface, conn, path, properties, error);

  return tp_channel_new_from_properties (conn, path, properties, error);
}

/**
 * tp_client_channel_factory_dup_channel_features:
 * @self: a client channel factory
 * @channel: a #TpChannel
 *
 * Return a zero terminated #GArray containing the #TpChannel features that
 * should be prepared on @channel.
 *
 * Changed in 0.13.6: the function's signature was previously wrong;
 * it expected an object instance as its first parameter, but the type of the
 * parameter was the type of the interface vtable.
 *
 * Returns: (transfer full) (element-type GQuark): a newly allocated #GArray
 *
 * Since: 0.13.3
 */
GArray *
tp_client_channel_factory_dup_channel_features (
    TpClientChannelFactory *self,
    TpChannel *channel)
{
  TpClientChannelFactoryInterface *iface = TP_CLIENT_CHANNEL_FACTORY_GET_IFACE (
      self);
  GArray *arr;
  GQuark feature = TP_CHANNEL_FEATURE_CORE;

  g_return_val_if_fail (TP_IS_CLIENT_CHANNEL_FACTORY (self), NULL);
  g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);

  if (iface->obj_dup_channel_features != NULL)
    return iface->obj_dup_channel_features (self, channel);

  if (iface->dup_channel_features != NULL)
    return iface->dup_channel_features (iface, channel);

  arr = g_array_sized_new (TRUE, FALSE, sizeof (GQuark), 1);

  g_array_append_val (arr, feature);

  return arr;
}

G_GNUC_END_IGNORE_DEPRECATIONS