Copyright | Lukas Braun 2014-2016 |
---|---|
License | GPL-3 |
Maintainer | koomi+mqtt@hackerspace-bamberg.de |
Safe Haskell | None |
Language | Haskell2010 |
MQTT Internals.
Use with care and expected changes.
- data Config = Config {}
- data Terminated
- data Command
- newtype Commands = Cmds {}
- mkCommands :: IO Commands
- send :: SingI t => Config -> Message t -> IO ()
- await :: SingI t => Config -> MVar (Message t) -> Maybe MsgID -> IO AwaitMessage
- data AwaitMessage where
- AwaitMessage :: SingI t => MVar (Message t) -> Maybe MsgID -> AwaitMessage
- stopWaiting :: Config -> AwaitMessage -> IO ()
- sendAwait :: (SingI t, SingI r) => Config -> Message t -> SMsgType r -> IO (Message r)
- writeCmd :: Config -> Command -> IO ()
- mainLoop :: Config -> Handle -> WaitTerminate -> SendSignal -> IO Terminated
- type WaitTerminate = STM ()
- type SendSignal = MVar ()
- data MqttState = MqttState {}
- type ParseCC = ByteString -> IResult ByteString SomeMessage
- data Input
- waitForInput :: Config -> Handle -> StateT MqttState IO Input
- parseBytes :: Monad m => ByteString -> StateT MqttState m (Maybe Input)
- handleMessage :: Config -> WaitTerminate -> SomeMessage -> StateT MqttState IO ()
- publishHandler :: Config -> Message PUBLISH -> IO ()
- secToMicro :: Int -> Int
User interaction
The various options when establishing a connection. See below for available accessors.
Config | |
|
data Terminated Source #
Reasons for why the connection was terminated.
ParseFailed [String] String | at the context in |
ConnectFailed ConnectError | |
UserRequested |
|
Commands from the user for the mainLoop
.
mkCommands :: IO Commands Source #
Create a new Commands
channel.
There should be one channel per MQTT connection. It might be reused by subsequent connections, but never by multiple connections concurrently.
data AwaitMessage where Source #
AwaitMessage :: SingI t => MVar (Message t) -> Maybe MsgID -> AwaitMessage |
stopWaiting :: Config -> AwaitMessage -> IO () Source #
Stop waiting for the described Message
.
sendAwait :: (SingI t, SingI r) => Config -> Message t -> SMsgType r -> IO (Message r) Source #
Execute the common pattern of sending a message and awaiting
a response in a safe, non-racy way. The message message is retransmitted
if no response has been received after cResendTimeout
seconds, with
exponential backoff for further retransmissions
An incoming message is considered a response if it is of the
requested type and the MsgID
s match (if present).
Main loop
mainLoop :: Config -> Handle -> WaitTerminate -> SendSignal -> IO Terminated Source #
type WaitTerminate = STM () Source #
type SendSignal = MVar () Source #
Internal state for the main loop
MqttState | |
|
type ParseCC = ByteString -> IResult ByteString SomeMessage Source #
parseBytes :: Monad m => ByteString -> StateT MqttState m (Maybe Input) Source #
Parse the given ByteString
and update the current MqttState
.
Returns Nothing
if more input is needed.
handleMessage :: Config -> WaitTerminate -> SomeMessage -> StateT MqttState IO () Source #
Misc
secToMicro :: Int -> Int Source #