Skip to content

Commit

Permalink
Add generated client for org.freedesktop.DBus
Browse files Browse the repository at this point in the history
  • Loading branch information
colonelpanic8 committed Mar 16, 2018
1 parent 86a695d commit 9e232c7
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dbus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extra-source-files:
examples/export.hs
examples/introspect.hs
examples/list-names.hs
idlxml/dbus.xml

source-repository head
type: git
Expand All @@ -84,6 +85,7 @@ library
, cereal
, containers
, deepseq
, filepath
, lens
, libxml-sax
, mtl
Expand Down
141 changes: 141 additions & 0 deletions idlxml/dbus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<node>
<interface name="org.freedesktop.DBus">
<method name="Hello">
<arg direction="out" type="s"/>
</method>
<method name="RequestName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="ReleaseName">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="StartServiceByName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="UpdateActivationEnvironment">
<arg direction="in" type="a{ss}"/>
</method>
<method name="NameHasOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="b"/>
</method>
<method name="ListNames">
<arg direction="out" type="as"/>
</method>
<method name="ListActivatableNames">
<arg direction="out" type="as"/>
</method>
<method name="AddMatch">
<arg direction="in" type="s"/>
</method>
<method name="RemoveMatch">
<arg direction="in" type="s"/>
</method>
<method name="GetNameOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="s"/>
</method>
<method name="ListQueuedOwners">
<arg direction="in" type="s"/>
<arg direction="out" type="as"/>
</method>
<method name="GetConnectionUnixUser">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetConnectionUnixProcessID">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetAdtAuditSessionData">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="GetConnectionSELinuxSecurityContext">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="ReloadConfig">
</method>
<method name="GetId">
<arg direction="out" type="s"/>
</method>
<method name="GetConnectionCredentials">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<property name="Features" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="Interfaces" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<signal name="NameOwnerChanged">
<arg type="s"/>
<arg type="s"/>
<arg type="s"/>
</signal>
<signal name="NameLost">
<arg type="s"/>
</signal>
<signal name="NameAcquired">
<arg type="s"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="out" type="v"/>
</method>
<method name="GetAll">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="Set">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="in" type="v"/>
</method>
<signal name="PropertiesChanged">
<arg type="s" name="interface_name"/>
<arg type="a{sv}" name="changed_properties"/>
<arg type="as" name="invalidated_properties"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Monitoring">
<method name="BecomeMonitor">
<arg direction="in" type="as"/>
<arg direction="in" type="u"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Debug.Stats">
<method name="GetStats">
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetConnectionStats">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetAllMatchRules">
<arg direction="out" type="a{sas}"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="GetMachineId">
<arg direction="out" type="s"/>
</method>
<method name="Ping">
</method>
</interface>
</node>
3 changes: 3 additions & 0 deletions lib/DBus/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ module DBus.Client
, defaultClientOptions
, connectWith

, dbusName
, dbusPath

, errorInvalidParameters
) where

Expand Down
13 changes: 12 additions & 1 deletion lib/DBus/Generation.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module DBus.Generation where

import DBus.Client as C
import qualified DBus.Internal.Message as M
import qualified DBus.Internal.Types as T
import qualified DBus.Introspection as I
import qualified Data.ByteString as BS
import qualified Data.Char as Char
import Data.Coerce
import Data.Functor ((<$>))
import Data.Int
import Data.List
import qualified Data.ByteString as BS
import qualified Data.Map as Map
import Data.Maybe
import Data.String
import Data.Traversable
import Data.Word
import Language.Haskell.TH
import Prelude hiding (mapM)
import System.IO.Unsafe
import System.Posix.Types (Fd(..))

data GenerationParams = GenerationParams
Expand Down Expand Up @@ -472,3 +474,12 @@ generateSignal GenerationParams
, makeHandlerSignature, makeHandlerFunction
, registerSignature, registerFunction
]

generateFromFilePath :: GenerationParams -> FilePath -> Q [Dec]
generateFromFilePath generationParams filepath =
let obj = unsafePerformIO $
head . maybeToList . I.parseXML "/" <$> readFile filepath
interface = head $ I.objectInterfaces obj
signals = generateSignalsFromInterface generationParams interface
client = generateClient generationParams interface
in fmap (++) signals <*> client
12 changes: 10 additions & 2 deletions lib/DBus/TH.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module DBus.TH where

import DBus.Client
import DBus.Generation
import DBus.Client
import DBus.Generation
import qualified DBus.Introspection as I
import System.FilePath


generateSignalsFromInterface defaultGenerationParams $
buildIntrospectionInterface $
buildPropertiesInterface undefined

generateFromFilePath defaultGenerationParams { genBusName = Just dbusName
, genObjectPath = Just dbusPath
} $ "idlxml" </> "dbus.xml"

0 comments on commit 9e232c7

Please sign in to comment.