[Haskell] ANNOUNCE: dbus-core 0.9
John Millikin
jmillikin at gmail.com
Sat Jul 23 08:29:01 CEST 2011
================================================
D-Bus implementation for Haskell (dbus-core_0.9)
================================================
This is the first significant release to dbus-core in a while, and it contains
some significant improvements to both the API and implementation. Users are
advised to upgrade, as the 0.8 branch will no longer be receiving improvements
or corrections.
* Release announcement: https://john-millikin.com/releases/dbus-core/0.9/
* API documentation: http://hackage.haskell.org/package/dbus-core
* Source code (literate PDF):
https://john-millikin.com/downloads/dbus-core_0.9.pdf
* Source code (tarball):
https://john-millikin.com/downloads/dbus-core_0.9.tar.gz
Changes in release 0.9
======================
The biggest change in this release is that dbus-client has been merged into
dbus-core. The original purpose of dbus-client (as a very high-level,
often-updated support library) never materialized, and the split packaging
caused issues with dependencies and versioning. The parts of dbus-client that
were commonly used were moved into the DBus.Client and DBus.Client.Simple
modules. Users are highly encouraged to use these modules in their applications.
Other changes and improvements include:
* The Array, Dictionary, and Structure types are no longer needed for most
users. You can cast containers directly to corresponding standard types,
such as Vector and Map.
* Smart constructors for magic strings have been renamed so they're easier to
read and type; for example, mkBusName is now just busName.
* Support for custom transports and authentication mechanisms.
* Removed some seldom-used modules, such as MatchRule and NameReservation.
Their functionality has been merged into the new client modules.
* Performance improvements for marshaling and unmarshaling messages.
How to use the new simple client API
====================================
The new API makes calling and exporting methods very easy; take a look at
these examples!
Getting a list of connected clients
-----------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Data.List (sort)
import DBus.Client.Simple
main :: IO ()
main = do
client <- connectSession
-- Request a list of connected clients from the bus
bus <- proxy client "org.freedesktop.DBus" "/org/freedesktop/DBus"
reply <- call bus "org.freedesktop.DBus" "ListNames" []
-- org.freedesktop.DBus.ListNames returns a single value, which is
-- a list of names.
let Just names = fromVariant (reply !! 0)
-- Print each name on a line, sorted so reserved names are below
-- temporary names.
mapM_ putStrLn (sort names)
Exporting methods
-----------------
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
import DBus.Client.Simple
onEcho :: String -> IO String
onEcho str = do
putStrLn str
return str
onDivide :: Double -> Double -> IO Double
onDivide x y = if y == 0
then throwError "com.example.DivisionByZero" "Divided by zero" []
else return (x / y)
main :: IO ()
main = do
client <- connectSession
-- Request a unique name on the bus. If the name is already
-- in use, continue without it.
requestName client "com.example.ExportExample" []
-- Export an example object at "/divide"
export client "/divide"
[ method "com.example.Echo" "Echo" onEcho
, method "com.example.Math" "Divide" onDivide
]
-- Wait forever for method calls
forever (threadDelay 50000)
More information about the Haskell
mailing list