This file is indexed.

/usr/share/doc/libtelepathy-glib-doc/telepathy-glib/telepathy-glib-svc.html is in libtelepathy-glib-doc 0.24.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The TpSvc* interfaces: telepathy-glib API Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="telepathy-glib API Reference Manual">
<link rel="up" href="ch-service-dbus.html" title="Service-side D-Bus interfaces">
<link rel="prev" href="ch-service-dbus.html" title="Service-side D-Bus interfaces">
<link rel="next" href="telepathy-glib-svc-generic.html" title="Generic service-side interfaces">
<meta name="generator" content="GTK-Doc V1.25 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="ch-service-dbus.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="ch-service-dbus.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="telepathy-glib-svc-generic.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="telepathy-glib-svc"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">
      The TpSvc* interfaces
    </span></h2>
<p>The TpSvc* interfaces — How to export Telepathy objects</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<p>
    The GInterfaces whose names start with TpSvc are generated automatically
    from the Telepathy specification, and can be used to make it easier
    to export methods and signals onto D-Bus. By implementing these
    GInterfaces you can avoid needing to generate any "glue" using the
    dbus-glib tools - this is all done internally inside telepathy-glib.
  </p>
<p>
    The media session interface makes a convenient example
    because it only has two methods (Error() and Ready())
    and one signal (NewStreamHandler), and media session handlers
    aren't expected to implement any other interfaces.
  </p>
<p>
    The first thing to do is pre-declare the interface init function,
    and define the type you'll be using, declaring it to implement the
    media stream handler interface:
  </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span> <span class="function">stream_handler_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>

<span class="function">G_DEFINE_TYPE_WITH_CODE</span><span class="gtkdoc opt">(</span>GabbleMediaStream<span class="gtkdoc opt">,</span>
    gabble_media_stream<span class="gtkdoc opt">,</span>
    G_TYPE_OBJECT<span class="gtkdoc opt">,</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_MEDIA_STREAM_HANDLER<span class="gtkdoc opt">,</span>
      stream_handler_iface_init<span class="gtkdoc opt">)</span>
    <span class="gtkdoc opt">)</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    Here we're using a subclass of G_TYPE_OBJECT. You can of course subclass
    any type.
  </p>
<p>
    If you're implementing more than one interface on the same object,
    define more than one init function, and call G_IMPLEMENT_INTERFACE
    more than once. The interface init functions can even be extern
    if you want to separate off chunks of functionality into a different
    .c file. For instance, here's GabbleConnection:
  </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="comment">/* in header files */</span>
<span class="gtkdoc kwb">void</span> <span class="function">conn_aliasing_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>
<span class="gtkdoc kwb">void</span> <span class="function">conn_avatars_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>
<span class="gtkdoc kwb">void</span> <span class="function">conn_presence_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>

<span class="comment">/* in gabble-connection.c */</span>
<span class="gtkdoc kwb">static void</span> <span class="function">conn_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>
<span class="gtkdoc kwb">static void</span> <span class="function">capabilities_iface_init</span> <span class="gtkdoc opt">(</span>gpointer<span class="gtkdoc opt">,</span> gpointer<span class="gtkdoc opt">);</span>

<span class="function">G_DEFINE_TYPE_WITH_CODE</span><span class="gtkdoc opt">(</span>GabbleConnection<span class="gtkdoc opt">,</span>
    gabble_connection<span class="gtkdoc opt">,</span>
    TP_TYPE_BASE_CONNECTION<span class="gtkdoc opt">,</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_CONNECTION<span class="gtkdoc opt">,</span>
      conn_iface_init<span class="gtkdoc opt">);</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING<span class="gtkdoc opt">,</span>
      conn_aliasing_iface_init<span class="gtkdoc opt">);</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_CONNECTION_INTERFACE_AVATARS<span class="gtkdoc opt">,</span>
      conn_avatars_iface_init<span class="gtkdoc opt">);</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_CONNECTION_INTERFACE_CAPABILITIES<span class="gtkdoc opt">,</span>
      capabilities_init<span class="gtkdoc opt">);</span>
    <span class="function">G_IMPLEMENT_INTERFACE</span> <span class="gtkdoc opt">(</span>TP_TYPE_SVC_CONNECTION_INTERFACE_PRESENCE<span class="gtkdoc opt">,</span>
      conn_presence_iface_init<span class="gtkdoc opt">);</span>
    <span class="gtkdoc opt">)</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    The _class_init, _init etc. functions are just like normal, so I
    won't describe them here. One thing to note, though, is that for
    signals which are defined by the GInterface, you do not need to do
    anything in the _class_init - the GInterface has already set the
    signal up for you.
  </p>
<p>
    For each exported D-Bus method, there's a typedef ending with _impl
    giving the signature you should use for your method implementation.
    For example, here's the signature for the Error method on the
    media session handler interface:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">void</span> <span class="gtkdoc opt">(*</span>tp_svc_media_session_handler_error_impl<span class="gtkdoc opt">)</span>
  <span class="gtkdoc opt">(</span>TpSvcMediaSessionHandler <span class="gtkdoc opt">*</span>self<span class="gtkdoc opt">,</span> guint errno<span class="gtkdoc opt">,</span> <span class="gtkdoc kwb">const char</span> <span class="gtkdoc opt">*</span>message<span class="gtkdoc opt">,</span>
   DBusGMethodInvocation <span class="gtkdoc opt">*</span>context<span class="gtkdoc opt">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    and here's the beginning of the corresponding implementation:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span>
<span class="function">gabble_media_session_error</span> <span class="gtkdoc opt">(</span>TpSvcMediaSessionHandler <span class="gtkdoc opt">*</span>iface<span class="gtkdoc opt">,</span>
                            guint errno<span class="gtkdoc opt">,</span>
                            <span class="gtkdoc kwb">const char</span> <span class="gtkdoc opt">*</span>message<span class="gtkdoc opt">,</span>
                            DBusGMethodInvocation <span class="gtkdoc opt">*</span>context<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
  GabbleMediaSession <span class="gtkdoc opt">*</span>self <span class="gtkdoc opt">=</span> <span class="function">GABBLE_MEDIA_SESSION</span> <span class="gtkdoc opt">(</span>iface<span class="gtkdoc opt">);</span>

  <span class="comment">/* do stuff with self here */</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    All service methods in telepathy-glib are asynchronous - you can of
    course implement them synchronously if you like, but you have to return
    the result or error to D-Bus by calling a callback rather than by
    returning from a function.
  </p>
<p>
    The method implementation's last parameter is a DBusGMethodInvocation.
    To send the reply, you must either call dbus_g_method_return_error
    (for a failure), dbus_g_method_return (for a successful return),
    or an inline function whose name contains "_return_from_" provided by
    the TpSvc interface. For example, for Error there's an inline function
    tp_svc_media_session_handler_return_from_error(). These inline functions
    are just a simple wrapper around dbus_g_method_return() to make it
    type-safe - it's recommended that you use them where possible.
  </p>
<p>
    For instance, Error doesn't return anything, so
    tp_svc_media_session_handler_return_from_error() doesn't take any
    parameters apart from the DBusGMethodInvocation:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span>
<span class="function">gabble_media_session_error</span> <span class="gtkdoc opt">(</span>TpSvcMediaSessionHandler <span class="gtkdoc opt">*</span>iface<span class="gtkdoc opt">,</span>
                            guint errno<span class="gtkdoc opt">,</span>
                            <span class="gtkdoc kwb">const char</span> <span class="gtkdoc opt">*</span>message<span class="gtkdoc opt">,</span>
                            DBusGMethodInvocation <span class="gtkdoc opt">*</span>context<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
  GabbleMediaSession <span class="gtkdoc opt">*</span>self <span class="gtkdoc opt">=</span> <span class="function">GABBLE_MEDIA_SESSION</span> <span class="gtkdoc opt">(</span>iface<span class="gtkdoc opt">);</span>

  <span class="comment">/* do stuff with self here */</span>

  <span class="function"><a href="telepathy-glib-svc-media-interfaces.html#tp-svc-media-session-handler-return-from-error">tp_svc_media_session_handler_return_from_error</a></span> <span class="gtkdoc opt">(</span>context<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
  </p>
<p>
    As for signals, they're named as dictated by dbus-glib. This normally
    gives you a sensible lower-case name - for instance NewStreamHandler
    is mapped to "new-stream-handler".
  </p>
<p>
    To emit a signal, the generated code contains another convenience
    function whose name contains _emit_. This is prototyped to take
    the correct arguments for the signal, and emits it efficiently:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="function"><a href="telepathy-glib-svc-media-interfaces.html#tp-svc-media-session-handler-emit-new-stream-handler">tp_svc_media_session_handler_emit_new_stream_handler</a></span> <span class="gtkdoc opt">(</span>session<span class="gtkdoc opt">,</span>
  object_path<span class="gtkdoc opt">,</span> id<span class="gtkdoc opt">,</span> media_type<span class="gtkdoc opt">,</span> TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL<span class="gtkdoc opt">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
  </p>
<p>
    Finally, the interface init function needs to be written. Normally
    you'd set the fields of a vtable to be pointers to your method
    implementations. However, we couldn't do this in telepathy-glib
    because that would mean breaking the ABI every time we added methods
    to an interface. Instead, you call functions, with pointers to your
    method implementations as a parameter:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span>
<span class="function">session_handler_iface_init</span> <span class="gtkdoc opt">(</span>gpointer g_iface<span class="gtkdoc opt">,</span> gpointer iface_data<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
  TpSvcMediaSessionHandlerClass <span class="gtkdoc opt">*</span>klass <span class="gtkdoc opt">=</span>
    <span class="gtkdoc opt">(</span>TpSvcMediaSessionHandlerClass <span class="gtkdoc opt">*)</span>g_iface<span class="gtkdoc opt">;</span>

  <span class="function"><a href="telepathy-glib-svc-media-interfaces.html#tp-svc-media-session-handler-implement-error">tp_svc_media_session_handler_implement_error</a></span> <span class="gtkdoc opt">(</span>klass<span class="gtkdoc opt">,</span>
      gabble_media_session_error<span class="gtkdoc opt">);</span>
  <span class="function"><a href="telepathy-glib-svc-media-interfaces.html#tp-svc-media-session-handler-implement-ready">tp_svc_media_session_handler_implement_ready</a></span> <span class="gtkdoc opt">(</span>klass<span class="gtkdoc opt">,</span>
      gabble_media_session_ready<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
    This is obviously quite repetitive if there are a lot of methods, so
    the convention I've used in telepathy-glib, Gabble and
    telepathy-sofiasip is to define a temporary macro called IMPLEMENT:
    </p>
<div class="informalexample">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="gtkdoc kwb">static void</span>
<span class="function">session_handler_iface_init</span> <span class="gtkdoc opt">(</span>gpointer g_iface<span class="gtkdoc opt">,</span> gpointer iface_data<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
  TpSvcMediaSessionHandlerClass <span class="gtkdoc opt">*</span>klass <span class="gtkdoc opt">=</span>
    <span class="gtkdoc opt">(</span>TpSvcMediaSessionHandlerClass <span class="gtkdoc opt">*)</span>g_iface<span class="gtkdoc opt">;</span>

<span class="gtkdoc ppc">#define IMPLEMENT(x) tp_svc_media_session_handler_implement_##x (\</span>
<span class="gtkdoc ppc">    klass, gabble_media_session_##x)</span>
  <span class="function">IMPLEMENT</span><span class="gtkdoc opt">(</span>error<span class="gtkdoc opt">);</span>
  <span class="function">IMPLEMENT</span><span class="gtkdoc opt">(</span>ready<span class="gtkdoc opt">);</span>
<span class="gtkdoc ppc">#undef IMPLEMENT</span>
<span class="gtkdoc opt">}</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

<p>
  </p>
<p>
    If you're implementing many interfaces, just write many similar
    interface init functions.
  </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.25</div>
</body>
</html>