haskell-dbus: D-Bus implementation for Haskell

Code: https://john-millikin.com/code/haskell-dbus (GitHub mirror)


This was my first real effort at writing a Haskell library. I developed it for several years, and used it as both a desktop automation system and a network-transparent RPC protocol.

Over time my opinion of the D-Bus protocol decreased. I believe its type system is fundamentally flawed, and many of its design decisions (XML-based introspection, lack of named structure fields) are significant drawbacks compared to alternatives developed outside of the Free Software community.

For all things D-Bus once did, I now use gRPC instead.

Calling Methods

Authors of client applications should import DBus.Client, which provides an easy RPC-oriented interface to D-Bus methods and signals.

{-# LANGUAGE OverloadedStrings #-}

import Data.List (sort)
import DBus
import DBus.Client

main = do
	client <- connectSession

	-- Request a list of connected clients from the bus
	reply <- call_ client (methodCall "/org/freedesktop/DBus" "org.freedesktop.DBus" "ListNames")
		{ methodCallDestination = Just "org.freedesktop.DBus"

	-- org.freedesktop.DBus.ListNames() returns a single value, which is
	-- a list of names (here represented as [String])
	let Just names = fromVariant (methodReturnBody reply !! 0)

	-- Print each name on a line, sorted so reserved names are below
	-- temporary names.
	mapM_ putStrLn (sort names)
Change Feed