summaryrefslogtreecommitdiff
path: root/src/plugin-connection.c
blob: dcbb74bc6e7268f78a5f9ce6565c7763b643ce50 (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
/*
 * plugin-connection.c — API for telepathy-gabble plugins
 * Copyright © 2012 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
 */

#include "config.h"

#include "gabble/plugin-connection.h"

#include <glib-object.h>
#include <gabble/types.h>
#include <telepathy-glib/telepathy-glib.h>
#include <debug.h>


static guint sig_id_porter_available = 0;

/**
 * SECTION: gabble-plugin-connection
 * @title: GabblePluginConnection
 * @short_description: Object representing gabble connection, implemented by
 *    Gabble internals.
 *
 * This Object represents Gabble Connection.
 *
 * Virtual methods in GabblePluginConnectionInterface interface are implemented
 * by GabbleConnection object. And only Gabble should implement this interface.
 */
G_DEFINE_INTERFACE (GabblePluginConnection,
    gabble_plugin_connection,
    G_TYPE_OBJECT);

static void
gabble_plugin_connection_default_init (GabblePluginConnectionInterface *iface)
{
  static gsize once = 0;

  if (g_once_init_enter (&once))
    {
      /**
       * @self: a connection interface
       * @porter: a porter
       *
       * Emitted when the WockyPorter becomes available.
       */
      sig_id_porter_available = g_signal_new (
          "porter-available",
          G_OBJECT_CLASS_TYPE (iface),
          G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0, NULL, NULL,
          g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, WOCKY_TYPE_PORTER);
      g_once_init_leave (&once, 1);
    }
}

gchar *
gabble_plugin_connection_add_sidecar_own_caps (
    GabblePluginConnection *plugin_connection,
    const GabbleCapabilitySet *cap_set,
    const GPtrArray *identities)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->add_sidecar_own_caps != NULL, NULL);
  
  return iface->add_sidecar_own_caps (plugin_connection, cap_set, identities);
}

gchar *
gabble_plugin_connection_add_sidecar_own_caps_full (
    GabblePluginConnection *plugin_connection,
    const GabbleCapabilitySet *cap_set,
    const GPtrArray *identities,
    GPtrArray *data_forms)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->add_sidecar_own_caps_full != NULL, NULL);
  
  return iface->add_sidecar_own_caps_full (plugin_connection, cap_set, identities,
      data_forms);
}

WockySession *
gabble_plugin_connection_get_session (
    GabblePluginConnection *plugin_connection)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->get_session != NULL, NULL);

  return iface->get_session (plugin_connection);
}

gchar *
gabble_plugin_connection_get_full_jid (
    GabblePluginConnection *plugin_connection)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->get_full_jid != NULL, NULL);

  return iface->get_full_jid (plugin_connection);
}

const gchar *
gabble_plugin_connection_get_jid_for_caps (
    GabblePluginConnection *plugin_connection,
    WockyXep0115Capabilities *caps)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->get_jid_for_caps != NULL, NULL);

  return iface->get_jid_for_caps (plugin_connection, caps);
}

const gchar *
gabble_plugin_connection_pick_best_resource_for_caps (
    GabblePluginConnection *plugin_connection,
    const gchar *jid,
    GabbleCapabilitySetPredicate predicate,
    gconstpointer user_data)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->pick_best_resource_for_caps != NULL, NULL);

  return iface->pick_best_resource_for_caps (plugin_connection, jid, predicate,
      user_data);
}

TpBaseContactList *
gabble_plugin_connection_get_contact_list (
    GabblePluginConnection *plugin_connection)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->get_contact_list != NULL, NULL);

  return iface->get_contact_list (plugin_connection);
}

WockyXep0115Capabilities *
gabble_plugin_connection_get_caps (
    GabblePluginConnection *plugin_connection,
    TpHandle handle)
{
  GabblePluginConnectionInterface *iface =
    GABBLE_PLUGIN_CONNECTION_GET_IFACE (plugin_connection);

  g_return_val_if_fail (iface != NULL, NULL);
  g_return_val_if_fail (iface->get_contact_list != NULL, NULL);

  return iface->get_caps (plugin_connection, handle);
}