gupnp-binding-tool

gupnp-binding-tool — create C convenience wrappers for calling UPnP actions

Synopsis

gupnp-binding-tool {SCPD file}

Description

gupnp-binding-tool takes a SCPD file and generates C functions which call the action using GUPnP.

These generated function are less verbose than direct calls to gupnp_service_proxy_send_call() because they have the correct argument types.

For example, this action:

<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>

Will generate the following prototype:

static inline gboolean
DeletePortMapping (GUPnPServiceProxy *proxy,
                   char * in_NewRemoteHost,
                   unsigned int in_NewExternalPort,
                   char * in_NewProtocol,
                   GError **error);

As can be seen, the arguments have the correct types and are prefixed with the argument direction.

gupnp-binding-tool generates both synchronous and asynchronous wrappers. The DeletePortMapping example above is the synchronous form, the asynchronous form is as follows:

typedef void (*DeletePortMapping_reply) (GUPnPServiceProxy *proxy,
                                         GError *error,
                                         gpointer userdata);

static inline GUPnPServiceProxyAction *
DeletePortMapping_async (GUPnPServiceProxy *proxy,
                         char * in_NewRemoteHost,
                         unsigned int in_NewExternalPort,
                         char * in_NewProtocol,
                         DeletePortMapping_reply callback,
                         gpointer userdata);

The asynchronous form (implemented using gupnp_service_proxy_begin_action() and gupnp_service_proxy_end_action()) will return without blocking and later invoke the callback from the main loop when the reply is received.