summaryrefslogtreecommitdiff
path: root/telepathy-glib/core-proxy.c
blob: 47474bf26458e6fcb1e58821c379abc696d28306 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * core-proxy.c - parts of TpProxy needed to link generated code
 *
 * Copyright © 2007-2012 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright © 2007-2008 Nokia Corporation
 *
 * 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
 */

#include "config.h"

#include "telepathy-glib/proxy-subclass.h"
#include "telepathy-glib/proxy-internal.h"

#include <string.h>

#define DEBUG_FLAG TP_DEBUG_PROXY
#include "debug-internal.h"

/**
 * tp_proxy_dbus_g_proxy_claim_for_signal_adding:
 * @proxy: a #DBusGProxy
 *
 * Attempt to "claim" a #DBusGProxy for addition of signal signatures.
 * If this function has not been called on @proxy before, %TRUE is
 * returned, and the caller may safely call dbus_g_proxy_add_signal()
 * on @proxy. If this function has already been caled, %FALSE is
 * returned, and the caller may not safely call dbus_g_proxy_add_signal().
 *
 * This is intended for use by auto-generated signal-adding functions,
 * to allow interfaces provided as local extensions to override those in
 * telepathy-glib without causing assertion failures.
 *
 * Returns: %TRUE if it is safe to call dbus_g_proxy_add_signal()
 * Since: 0.7.6
 */
gboolean
tp_proxy_dbus_g_proxy_claim_for_signal_adding (DBusGProxy *proxy)
{
  static GQuark q = 0;

  g_return_val_if_fail (proxy != NULL, FALSE);

  if (G_UNLIKELY (q == 0))
    {
      q = g_quark_from_static_string (
          "tp_proxy_dbus_g_proxy_claim_for_signal_adding@0.7.6");
    }

  if (g_object_get_qdata ((GObject *) proxy, q) != NULL)
    {
      /* Someone else has already added signal signatures for this interface.
       * We can't do it again or it'll cause an assertion */
      return FALSE;
    }

  /* the proxy is just used as qdata here because it's a convenient
   * non-NULL pointer */
  g_object_set_qdata ((GObject *) proxy, q, proxy);
  return TRUE;
}

static TpProxyImplementation _tp_proxy_implementation = { NULL };

DBusGProxy *
tp_proxy_get_interface_by_id (TpProxy *proxy,
    GQuark iface,
    GError **error)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  return _tp_proxy_implementation.get_interface_by_id (proxy, iface, error);
}

gboolean
tp_proxy_check_interface_by_id (gpointer proxy,
    GQuark iface,
    GError **error)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  return _tp_proxy_implementation.check_interface_by_id (proxy, iface, error);
}

TpProxyPendingCall *
tp_proxy_pending_call_v0_new (TpProxy *proxy,
    GQuark iface,
    const gchar *member,
    DBusGProxy *iface_proxy,
    TpProxyInvokeFunc invoke_callback,
    GCallback callback,
    gpointer user_data,
    GDestroyNotify destroy,
    GObject *weak_object,
    gboolean cancel_must_raise)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  return _tp_proxy_implementation.pending_call_new (proxy, iface, member,
      iface_proxy, invoke_callback, callback, user_data, destroy,
      weak_object, cancel_must_raise);
}

void
tp_proxy_pending_call_v0_take_pending_call (TpProxyPendingCall *pc,
    DBusGProxyCall *pending_call)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  _tp_proxy_implementation.pending_call_take_pending_call (pc, pending_call);
}

void
tp_proxy_pending_call_v0_completed (gpointer p)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  _tp_proxy_implementation.pending_call_completed (p);
}

void
tp_proxy_pending_call_v0_take_results (TpProxyPendingCall *pc,
    GError *error,
    GValueArray *args)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  _tp_proxy_implementation.pending_call_take_results (pc, error, args);
}

TpProxySignalConnection *
tp_proxy_signal_connection_v0_new (TpProxy *self,
    GQuark iface,
    const gchar *member,
    const GType *expected_types,
    GCallback collect_args,
    TpProxyInvokeFunc invoke_callback,
    GCallback callback,
    gpointer user_data,
    GDestroyNotify destroy,
    GObject *weak_object,
    GError **error)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  return _tp_proxy_implementation.signal_connection_new (self, iface, member,
      expected_types, collect_args, invoke_callback, callback, user_data,
      destroy, weak_object, error);
}

void
tp_proxy_signal_connection_v0_take_results (TpProxySignalConnection *sc,
    GValueArray *args)
{
  g_assert (_tp_proxy_implementation.version != NULL);
  _tp_proxy_implementation.signal_connection_take_results (sc, args);
}

void
tp_private_proxy_set_implementation (TpProxyImplementation *impl)
{
  /* not using tp_strdiff because it isn't available in the core library */
  g_assert (strcmp (impl->version, VERSION) == 0);
  g_assert (impl->size == sizeof (TpProxyImplementation));
  g_assert (strcmp (g_type_name (impl->type), "TpProxy") == 0);
  g_assert (_tp_proxy_implementation.version == NULL);

  g_assert (impl->get_interface_by_id != NULL);
  g_assert (impl->check_interface_by_id != NULL);
  g_assert (impl->pending_call_new != NULL);
  g_assert (impl->pending_call_take_pending_call != NULL);
  g_assert (impl->pending_call_take_results != NULL);
  g_assert (impl->pending_call_completed != NULL);
  g_assert (impl->signal_connection_new != NULL);
  g_assert (impl->signal_connection_take_results != NULL);

  memcpy (&_tp_proxy_implementation, impl, sizeof (TpProxyImplementation));

  g_assert (strcmp (_tp_proxy_implementation.version, VERSION) == 0);
}