1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4 <refentry id="gupnp-binding-tool" xmlns:xi="http://www.w3.org/2003/XInclude">
6 <refentrytitle>gupnp-binding-tool</refentrytitle>
7 <manvolnum>1</manvolnum>
8 <refmiscinfo class="source">GUPnP</refmiscinfo>
9 <refmiscinfo class="version"><xi:include href="version.xml" parse="text"/></refmiscinfo>
13 <refname>gupnp-binding-tool</refname>
14 <refpurpose>creates C convenience wrappers for UPnP services</refpurpose>
19 <command>gupnp-binding-tool</command>
20 <arg choice="opt">--prefix <arg choice="req">PREFIX</arg></arg>
21 <arg choice="opt">--mode <arg choice="req">client|server</arg></arg>
22 <arg choice="req">SCPD file</arg>
27 <title>Description</title>
29 <command>gupnp-binding-tool</command> takes a <glossterm
30 linkend="scpd">SCPD file</glossterm> and generates convenience C functions
31 which call the actual GUPnP functions. The client-side bindings can be seen
32 as a service-specific version of the GUPnPServiceProxy API and the
33 service-side bindings are the same for GUPnPService.
36 These generated functions are less verbose and also safer as function call
37 parameters are correctly typed. Action, variable and query names are easier
38 to get correct with bindings (or at least the errors will be compile-time
39 errors instead of run-time), and are also available in editor
44 <title>Client side bindings</title>
46 As an example, this action:
48 <programlisting><![CDATA[<action>
49 <name>DeletePortMapping</name>
52 <name>NewRemoteHost</name>
53 <direction>in</direction>
54 <relatedStateVariable>RemoteHost</relatedStateVariable>
57 <name>NewExternalPort</name>
58 <direction>in</direction>
59 <relatedStateVariable>ExternalPort</relatedStateVariable>
62 <name>NewProtocol</name>
63 <direction>in</direction>
64 <relatedStateVariable>PortMappingProtocol</relatedStateVariable>
67 </action>]]></programlisting>
69 Will generate the following synchronous client-side (control point)
72 <programlisting>static inline gboolean
73 igd_delete_port_mapping (GUPnPServiceProxy *proxy,
74 const gchar *in_new_remote_host,
75 const guint in_new_external_port,
76 const gchar *in_new_protocol,
80 As can be seen, the arguments have the correct types and are prefixed with
81 the argument direction.
84 <command>gupnp-binding-tool</command> generates both synchronous and
85 asynchronous wrappers. The <function>igd_delete_port_mapping</function> example
86 above is the synchronous form, the asynchronous form is as follows:
88 <programlisting>typedef void (*igd_delete_port_mapping_reply) (GUPnPServiceProxy *proxy,
92 static inline GUPnPServiceProxyAction *
93 igd_delete_port_mapping_async (GUPnPServiceProxy *proxy,
94 const gchar *in_new_remote_host,
95 const guint in_new_external_port,
96 const gchar *in_new_protocol,
97 igd_delete_port_mapping_reply callback,
98 gpointer userdata);</programlisting>
100 The asynchronous form (implemented using
101 <function>gupnp_service_proxy_begin_action()</function> and
102 <function>gupnp_service_proxy_end_action()</function>) will return without
103 blocking and later invoke the callback from the main loop when the reply
107 The tool also creates bindings for state variable notifications. This state
110 <programlisting><![CDATA[<stateVariable sendEvents="yes">
111 <name>ExternalIPAddress</name>
112 <dataType>string</dataType>
113 </stateVariable>]]></programlisting>
115 will create this client binding that can be used to get notifications on
116 "ExternalIPAddress" changes:
118 <programlisting>typedef void
119 (*igd_external_ip_address_changed_callback) (GUPnPServiceProxy *proxy,
120 const gchar *external_ip_address,
123 static inline gboolean
124 igd_external_ip_address_add_notify (GUPnPServiceProxy *proxy,
125 igd_external_ip_address_changed_callback callback,
126 gpointer userdata);</programlisting>
129 All of the examples were produced with <filename>gupnp-binding-tool
130 --prefix igd --mode client WANIPConnection.xml</filename>.
134 <title>Server side bindings</title>
136 The corresponding server bindings for the same UPnP action
137 (DeletePortMapping) look like this:
140 igd_delete_port_mapping_action_get (GUPnPServiceAction *action,
141 gchar **in_new_remote_host,
142 guint *in_new_external_port,
143 gchar **in_new_protocol);
146 igd_delete_port_mapping_action_connect (GUPnPService *service,
148 gpointer userdata);</programlisting>
150 The generated *_action_connect() function can be used to connect the action
151 handler. The *_action_get() and *_action_set() functions can then
152 be used inside the action handler to get/set action variables. If notified
153 variables are modified, the *_variable_notify() should be used to send
154 the notifications (see below).
156 <programlisting>typedef gchar *(*igd_external_ip_address_query_callback) (GUPnPService *service,
160 igd_external_ip_address_query_connect (GUPnPService *service,
161 igd_external_ip_address_query_callback callback,
164 igd_external_ip_address_variable_notify (GUPnPService *service,
165 const gchar *external_ip_address);</programlisting>
167 The *_query_connect() function can be used to connect the service-specific
168 query handler. The return value of the handler is the returned state
172 All of the examples were produced with <filename>gupnp-binding-tool
173 --prefix igd --mode server WANIPConnection.xml</filename>.