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 :: forall a. IsValue a => a -> Type
typeOf = forall a. IsValue a => a -> Type
DBus.Internal.Types.typeOf
typeOf' :: IsValue a => Proxy a -> Type
typeOf' :: forall a. IsValue a => Proxy a -> Type
typeOf' = 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 (forall a. a -> Maybe a
Just InterfaceName
iface) MemberName
member forall a. Maybe a
Nothing 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 forall a. Maybe a
Nothing 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 forall a. Maybe a
Nothing 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 forall a. Maybe a
Nothing 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 :: forall msg.
Message msg =>
Endianness -> Serial -> msg -> Either MarshalError ByteString
marshal = forall msg.
Message msg =>
Endianness -> Serial -> msg -> 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
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
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
Ord, Int -> UUID -> ShowS
[UUID] -> ShowS
UUID -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [UUID] -> ShowS
$cshowList :: [UUID] -> ShowS
show :: UUID -> [Char]
$cshow :: UUID -> [Char]
showsPrec :: Int -> UUID -> ShowS
$cshowsPrec :: Int -> UUID -> ShowS
Show)
formatUUID :: UUID -> String
formatUUID :: UUID -> [Char]
formatUUID (UUID ByteString
bytes) = ByteString -> [Char]
Char8.unpack ByteString
bytes
randomUUID :: IO UUID
randomUUID :: IO UUID
randomUUID = do
let hexInt16 :: Int -> t
hexInt16 Int
i = forall r. PrintfType r => [Char] -> r
printf [Char]
"%04x" (Int
i :: Int)
[Int]
int16s <- forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
8 (forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (Int
0, forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall a. Bounded a => a
maxBound :: Word16)))
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> UUID
UUID ([Char] -> ByteString
Char8.pack (forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall {t}. PrintfType t => Int -> t
hexInt16 [Int]
int16s)))