summaryrefslogtreecommitdiff
path: root/doc/gupnp-binding-tool.xml.in
blob: 2ec69042629f34736f6dc20fa4495de93261cb1a (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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">

<refentry id="gupnp-binding-tool" xmlns:xi="http://www.w3.org/2003/XInclude">
  <refmeta>
    <refentrytitle>gupnp-binding-tool-@GUPNP_API_VERSION@</refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo class="source">GUPnP</refmiscinfo>
    <refmiscinfo class="version"><xi:include href="version.xml" parse="text"><xi:fallback /></xi:include></refmiscinfo>
  </refmeta>
  
  <refnamediv>
    <refname>gupnp-binding-tool-@GUPNP_API_VERSION@</refname>
    <refpurpose>creates C convenience wrappers for UPnP services</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <cmdsynopsis>
      <command>gupnp-binding-tool-@GUPNP_API_VERSION@</command>
      <arg choice="opt">--prefix <arg choice="req">PREFIX</arg></arg>
      <arg choice="opt">--mode <arg choice="req">client|server</arg></arg>
      <arg choice="req">SCPD file</arg>
    </cmdsynopsis>
  </refsynopsisdiv>
  
  <refsect1>
    <title>Description</title>
    <para>
      <command>gupnp-binding-tool-@GUPNP_API_VERSION@</command> takes a <glossterm
      linkend="scpd">SCPD file</glossterm> and generates convenience C functions
      which call the actual GUPnP functions. The client-side bindings can be seen
      as a service-specific version of the GUPnPServiceProxy API and the 
      service-side bindings are the same for GUPnPService.
    </para>
    <para>
      These generated functions are less verbose and also safer as function call
      parameters are correctly typed. Action, variable and query names are easier
      to get correct with bindings (or at least the errors will be compile-time
      errors instead of run-time), and are also available in editor 
      autocompletion.
    </para>
  </refsect1>
  <refsect1>
    <title>Client side bindings</title>
    <para>
      As an example, this action:
    </para>
    <programlisting><![CDATA[<action>
  <name>DeletePortMapping</name>
  <argumentList>
    <argument>
      <name>NewRemoteHost</name>
      <direction>in</direction>
      <relatedStateVariable>RemoteHost</relatedStateVariable>
    </argument>
    <argument>
      <name>NewExternalPort</name>
      <direction>in</direction>
      <relatedStateVariable>ExternalPort</relatedStateVariable>
    </argument>
    <argument>
      <name>NewProtocol</name>
      <direction>in</direction>
      <relatedStateVariable>PortMappingProtocol</relatedStateVariable>
    </argument>
  </argumentList>
</action>]]></programlisting>
    <para>
      Will generate the following synchronous client-side (control point) 
      function:
    </para>
    <programlisting>static inline gboolean
igd_delete_port_mapping (GUPnPServiceProxy *proxy,
                         const gchar *in_new_remote_host,
                         const guint in_new_external_port,
                         const gchar *in_new_protocol,
                         GError **error);
</programlisting>
    <para>
      As can be seen, the arguments have the correct types and are prefixed with
      the argument direction. 
    </para>
    <para>
      <command>gupnp-binding-tool-@GUPNP_API_VERSION@</command> generates both synchronous and
      asynchronous wrappers.  The <function>igd_delete_port_mapping</function> example
      above is the synchronous form, the asynchronous form is as follows:
    </para>
    <programlisting>typedef void (*igd_delete_port_mapping_reply) (GUPnPServiceProxy *proxy,
                                               GError *error,
                                               gpointer userdata);

static inline GUPnPServiceProxyAction *
igd_delete_port_mapping_async (GUPnPServiceProxy *proxy,
                               const gchar *in_new_remote_host,
                               const guint in_new_external_port,
                               const gchar *in_new_protocol,
                               igd_delete_port_mapping_reply callback,
                               gpointer userdata);</programlisting>
    <para>
      The asynchronous form (implemented using
      <function>gupnp_service_proxy_begin_action()</function> and
      <function>gupnp_service_proxy_end_action()</function>) will return without
      blocking and later invoke the callback from the main loop when the reply
      is received.
    </para>
    <para>
      The tool also creates bindings for state variable notifications. This state 
      variable definition:
    </para>
    <programlisting><![CDATA[<stateVariable sendEvents="yes">
  <name>ExternalIPAddress</name>
  <dataType>string</dataType>
</stateVariable>]]></programlisting>
    <para>
      will create this client binding that can be used to get notifications on 
      "ExternalIPAddress" changes:
    </para>
    <programlisting>typedef void
(*igd_external_ip_address_changed_callback) (GUPnPServiceProxy *proxy,
                                             const gchar *external_ip_address,
                                             gpointer userdata);

static inline gboolean
igd_external_ip_address_add_notify (GUPnPServiceProxy *proxy,
                                    igd_external_ip_address_changed_callback callback,
                                    gpointer userdata);</programlisting>
    
    <para>
      All of the examples were produced with <filename>gupnp-binding-tool-@GUPNP_API_VERSION@
      --prefix igd --mode client WANIPConnection.xml</filename>.
    </para>
  </refsect1>
  <refsect1>
    <title>Server side bindings</title>
    <para>
      The corresponding server bindings for the same UPnP action 
      (DeletePortMapping) look like this:
    </para>
    <programlisting>void
igd_delete_port_mapping_action_get (GUPnPServiceAction *action,
                                    gchar **in_new_remote_host,
                                    guint *in_new_external_port,
                                    gchar **in_new_protocol);

gulong
igd_delete_port_mapping_action_connect (GUPnPService *service,
                                        GCallback callback,
                                        gpointer userdata);</programlisting>
    <para>
      The generated *_action_connect() function can be used to connect the action
      handler. The *_action_get() and *_action_set() functions can then 
      be used inside the action handler to get/set action variables. If notified
      variables are modified, the *_variable_notify() should be used to send 
      the notifications (see below).  
    </para>
    <programlisting>typedef gchar *(*igd_external_ip_address_query_callback) (GUPnPService *service,
                                                          gpointer userdata);

gulong
igd_external_ip_address_query_connect (GUPnPService *service,
                                       igd_external_ip_address_query_callback callback,
                                       gpointer userdata);
void
igd_external_ip_address_variable_notify (GUPnPService *service,
                                         const gchar *external_ip_address);</programlisting>
    <para>
      The *_query_connect() function can be used to connect the service-specific 
      query handler. The return value of the handler is the returned state 
      variable value.
    </para>
    <para>
      All of the examples were produced with <filename>gupnp-binding-tool-@GUPNP_API_VERSION@
      --prefix igd --mode server WANIPConnection.xml</filename>.
    </para>
  </refsect1>
</refentry>