@hackage dbus-th-introspection0.1.2.0

Generate bindings for DBus calls by using DBus introspection and dbus-th

This package is aimed to simplify writing bindings for DBus interfaces by using DBus introspection and dbus-th package.

The synopsis is:

dbus-introspect-hs [OPTIONS] [SERVICE.NAME] [/PATH/TO/OBJECT] [INTERFACE.NAME] Introspect specified DBus object/interface and generate TemplateHaskell source for calling all functions from Haskell

Common flags: -m --module=NAME --modulename Haskell module name -o --output=FILE --outputfile Output file -s --system Use system bus instead of sesion bus -d --dynamic --dynamicobject If specified - generated functions will get object path as 2nd argument

If service name is not provided, the program will generate bindings for all services available (Warning: you can receive a very large file). If object path is not provided, the program will generate bindings for all objects provided by specified service. Similarly, if interface name is not proviced, the program will generate bindings for all interfaces provided by speciifed object.

If -d option is specified, the program will generate bindings by using "interface'" instead of "interface"; so, all generated functions will get object path as their second argument.

For example, one may run

$ dbus-introspect-hs --dynamic --session -m Session \
  org.freedesktop.login1 /org/freedesktop/login1/session/self \
  org.freedesktop.login1.Session

and receive:

{-# LANGUAGE TemplateHaskell #-}
module Session where

import DBus.TH
import DBus.TH.Introspection

-- Service BusName "org.freedesktop.login1"
-- Interface org.freedesktop.login1.Session
interface' "org.freedesktop.login1" Nothing "org.freedesktop.login1.Session" Nothing [
    "Terminate" =:: Return ''(),
    "Activate" =:: Return ''(),
    "Lock" =:: Return ''(),
    "Unlock" =:: Return ''(),
    "SetIdleHint" =:: ''Bool :-> Return ''(),
    "Kill" =:: ''String :-> ''Int32 :-> Return ''(),
    "TakeControl" =:: ''Bool :-> Return ''(),
    "ReleaseControl" =:: Return ''(),
    -- Error: method TakeDevice: Method TakeDevice has more than one out parameter,
    "ReleaseDevice" =:: ''Word32 :-> ''Word32 :-> Return ''(),
    "PauseDeviceComplete" =:: ''Word32 :-> ''Word32 :-> Return ''()
  ]

After "import Session", the functions like activate :: Client -> String -> IO () will be available.

Note that many DBus services provide one interface for many objects; and in one interface, there could be several functions with the same name (but with different signatures). In this case, the source generated by this program would not compile due to duplicated declaration names.

So, the sources generated by this program are primarily intended for hand inspection and editing (change declaration names, remove unneded or duplicated declarations); not for automatic compilation during some package build process.