module DBus
(
Message
, MethodCall
, methodCall
, methodCallPath
, methodCallInterface
, methodCallMember
, methodCallSender
, methodCallDestination
, methodCallAutoStart
, methodCallReplyExpected
, methodCallBody
, MethodReturn
, methodReturn
, methodReturnSerial
, methodReturnSender
, methodReturnDestination
, methodReturnBody
, MethodError
, methodError
, methodErrorName
, methodErrorSerial
, methodErrorSender
, methodErrorDestination
, methodErrorBody
, methodErrorMessage
, Signal
, signal
, signalPath
, signalMember
, signalInterface
, signalSender
, signalDestination
, signalBody
, ReceivedMessage(ReceivedMethodCall, ReceivedMethodReturn, ReceivedMethodError, ReceivedSignal)
, receivedMessageSerial
, receivedMessageSender
, receivedMessageBody
, Variant
, IsVariant(..)
, variantType
, IsAtom
, IsValue
, typeOf
, typeOf'
, Signature
, Type(..)
, signature
, signature_
, signatureTypes
, formatSignature
, parseSignature
, ObjectPath
, objectPath_
, formatObjectPath
, parseObjectPath
, InterfaceName
, interfaceName_
, formatInterfaceName
, parseInterfaceName
, MemberName
, memberName_
, formatMemberName
, parseMemberName
, ErrorName
, errorName_
, formatErrorName
, parseErrorName
, BusName
, busName_
, formatBusName
, parseBusName
, Structure
, structureItems
, Array
, arrayItems
, Dictionary
, dictionaryItems
, Address
, addressMethod
, addressParameters
, address
, formatAddress
, formatAddresses
, parseAddress
, parseAddresses
, getSystemAddress
, getSessionAddress
, getStarterAddress
, Endianness (..)
, marshal
, MarshalError
, marshalErrorMessage
, unmarshal
, UnmarshalError
, unmarshalErrorMessage
, Serial
, serialValue
, firstSerial
, nextSerial
, UUID
, formatUUID
, randomUUID
) where
import Control.Monad (replicateM)
import qualified Data.ByteString.Char8 as Char8
import Data.Proxy (Proxy(..))
import Data.Word (Word16)
import System.Random (randomRIO)
import Text.Printf (printf)
import DBus.Internal.Address
import DBus.Internal.Message
import qualified DBus.Internal.Types
import DBus.Internal.Types hiding (typeOf)
import DBus.Internal.Wire
typeOf :: IsValue a => a -> Type
typeOf :: a -> Type
typeOf = a -> Type
forall a. IsValue a => a -> Type
DBus.Internal.Types.typeOf
typeOf' :: IsValue a => Proxy a -> Type
typeOf' :: Proxy a -> Type
typeOf' = Proxy a -> Type
forall a. IsValue a => Proxy a -> Type
DBus.Internal.Types.typeOf_
methodCall :: ObjectPath -> InterfaceName -> MemberName -> MethodCall
methodCall :: ObjectPath -> InterfaceName -> MemberName -> MethodCall
methodCall ObjectPath
path InterfaceName
iface MemberName
member = ObjectPath
-> Maybe InterfaceName
-> MemberName
-> Maybe BusName
-> Maybe BusName
-> Bool
-> Bool
-> [Variant]
-> MethodCall
MethodCall ObjectPath
path (InterfaceName -> Maybe InterfaceName
forall a. a -> Maybe a
Just InterfaceName
iface) MemberName
member Maybe BusName
forall a. Maybe a
Nothing Maybe BusName
forall a. Maybe a
Nothing Bool
True Bool
True []
methodReturn :: Serial -> MethodReturn
methodReturn :: Serial -> MethodReturn
methodReturn Serial
s = Serial
-> Maybe BusName -> Maybe BusName -> [Variant] -> MethodReturn
MethodReturn Serial
s Maybe BusName
forall a. Maybe a
Nothing Maybe BusName
forall a. Maybe a
Nothing []
methodError :: Serial -> ErrorName -> MethodError
methodError :: Serial -> ErrorName -> MethodError
methodError Serial
s ErrorName
name = ErrorName
-> Serial
-> Maybe BusName
-> Maybe BusName
-> [Variant]
-> MethodError
MethodError ErrorName
name Serial
s Maybe BusName
forall a. Maybe a
Nothing Maybe BusName
forall a. Maybe a
Nothing []
signal :: ObjectPath -> InterfaceName -> MemberName -> Signal
signal :: ObjectPath -> InterfaceName -> MemberName -> Signal
signal ObjectPath
path InterfaceName
iface MemberName
member = ObjectPath
-> InterfaceName
-> MemberName
-> Maybe BusName
-> Maybe BusName
-> [Variant]
-> Signal
Signal ObjectPath
path InterfaceName
iface MemberName
member Maybe BusName
forall a. Maybe a
Nothing Maybe BusName
forall a. Maybe a
Nothing []
receivedMessageSerial :: ReceivedMessage -> Serial
receivedMessageSerial :: ReceivedMessage -> Serial
receivedMessageSerial (ReceivedMethodCall Serial
s MethodCall
_) = Serial
s
receivedMessageSerial (ReceivedMethodReturn Serial
s MethodReturn
_) = Serial
s
receivedMessageSerial (ReceivedMethodError Serial
s MethodError
_) = Serial
s
receivedMessageSerial (ReceivedSignal Serial
s Signal
_) = Serial
s
receivedMessageSerial (ReceivedUnknown Serial
s UnknownMessage
_) = Serial
s
receivedMessageSender :: ReceivedMessage -> Maybe BusName
receivedMessageSender :: ReceivedMessage -> Maybe BusName
receivedMessageSender (ReceivedMethodCall Serial
_ MethodCall
msg) = MethodCall -> Maybe BusName
methodCallSender MethodCall
msg
receivedMessageSender (ReceivedMethodReturn Serial
_ MethodReturn
msg) = MethodReturn -> Maybe BusName
methodReturnSender MethodReturn
msg
receivedMessageSender (ReceivedMethodError Serial
_ MethodError
msg) = MethodError -> Maybe BusName
methodErrorSender MethodError
msg
receivedMessageSender (ReceivedSignal Serial
_ Signal
msg) = Signal -> Maybe BusName
signalSender Signal
msg
receivedMessageSender (ReceivedUnknown Serial
_ UnknownMessage
msg) = UnknownMessage -> Maybe BusName
unknownMessageSender UnknownMessage
msg
receivedMessageBody :: ReceivedMessage -> [Variant]
receivedMessageBody :: ReceivedMessage -> [Variant]
receivedMessageBody (ReceivedMethodCall Serial
_ MethodCall
msg) = MethodCall -> [Variant]
methodCallBody MethodCall
msg
receivedMessageBody (ReceivedMethodReturn Serial
_ MethodReturn
msg) = MethodReturn -> [Variant]
methodReturnBody MethodReturn
msg
receivedMessageBody (ReceivedMethodError Serial
_ MethodError
msg) = MethodError -> [Variant]
methodErrorBody MethodError
msg
receivedMessageBody (ReceivedSignal Serial
_ Signal
msg) = Signal -> [Variant]
signalBody Signal
msg
receivedMessageBody (ReceivedUnknown Serial
_ UnknownMessage
msg) = UnknownMessage -> [Variant]
unknownMessageBody UnknownMessage
msg
marshal :: Message msg => Endianness -> Serial -> msg -> Either MarshalError Char8.ByteString
marshal :: Endianness -> Serial -> msg -> Either MarshalError ByteString
marshal = Endianness -> Serial -> msg -> Either MarshalError ByteString
forall a.
Message a =>
Endianness -> Serial -> a -> Either MarshalError ByteString
marshalMessage
unmarshal :: Char8.ByteString -> Either UnmarshalError ReceivedMessage
unmarshal :: ByteString -> Either UnmarshalError ReceivedMessage
unmarshal = ByteString -> Either UnmarshalError ReceivedMessage
unmarshalMessage
newtype UUID = UUID Char8.ByteString
deriving (UUID -> UUID -> Bool
(UUID -> UUID -> Bool) -> (UUID -> UUID -> Bool) -> Eq UUID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UUID -> UUID -> Bool
$c/= :: UUID -> UUID -> Bool
== :: UUID -> UUID -> Bool
$c== :: UUID -> UUID -> Bool
Eq, Eq UUID
Eq UUID
-> (UUID -> UUID -> Ordering)
-> (UUID -> UUID -> Bool)
-> (UUID -> UUID -> Bool)
-> (UUID -> UUID -> Bool)
-> (UUID -> UUID -> Bool)
-> (UUID -> UUID -> UUID)
-> (UUID -> UUID -> UUID)
-> Ord UUID
UUID -> UUID -> Bool
UUID -> UUID -> Ordering
UUID -> UUID -> UUID
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UUID -> UUID -> UUID
$cmin :: UUID -> UUID -> UUID
max :: UUID -> UUID -> UUID
$cmax :: UUID -> UUID -> UUID
>= :: UUID -> UUID -> Bool
$c>= :: UUID -> UUID -> Bool
> :: UUID -> UUID -> Bool
$c> :: UUID -> UUID -> Bool
<= :: UUID -> UUID -> Bool
$c<= :: UUID -> UUID -> Bool
< :: UUID -> UUID -> Bool
$c< :: UUID -> UUID -> Bool
compare :: UUID -> UUID -> Ordering
$ccompare :: UUID -> UUID -> Ordering
$cp1Ord :: Eq UUID
Ord, Int -> UUID -> ShowS
[UUID] -> ShowS
UUID -> String
(Int -> UUID -> ShowS)
-> (UUID -> String) -> ([UUID] -> ShowS) -> Show UUID
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UUID] -> ShowS
$cshowList :: [UUID] -> ShowS
show :: UUID -> String
$cshow :: UUID -> String
showsPrec :: Int -> UUID -> ShowS
$cshowsPrec :: Int -> UUID -> ShowS
Show)
formatUUID :: UUID -> String
formatUUID :: UUID -> String
formatUUID (UUID ByteString
bytes) = ByteString -> String
Char8.unpack ByteString
bytes
randomUUID :: IO UUID
randomUUID :: IO UUID
randomUUID = do
let hexInt16 :: Int -> t
hexInt16 Int
i = String -> Int -> t
forall r. PrintfType r => String -> r
printf String
"%04x" (Int
i :: Int)
[Int]
int16s <- Int -> IO Int -> IO [Int]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
8 ((Int, Int) -> IO Int
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (Int
0, Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16
forall a. Bounded a => a
maxBound :: Word16)))
UUID -> IO UUID
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> UUID
UUID (String -> ByteString
Char8.pack ((Int -> String) -> [Int] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Int -> String
forall t. PrintfType t => Int -> t
hexInt16 [Int]
int16s)))