Maintainer | koomi+mqtt@hackerspace-bamberg.de |
---|---|
Safe Haskell | None |
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 {
- msParseCC :: ParseCC
- msUnconsumed :: ByteString
- msWaiting :: [AwaitMessage]
- type ParseCC = ByteString -> IResult ByteString SomeMessage
- data Input
- = InMsg SomeMessage
- | InErr Terminated
- | InCmd Command
- 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 CommandsSource
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 whereSource
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 TerminatedSource
type WaitTerminate = STM ()Source
type SendSignal = MVar ()Source
Internal state for the main loop
MqttState | |
|
type ParseCC = ByteString -> IResult ByteString SomeMessageSource
handleMessage :: Config -> WaitTerminate -> SomeMessage -> StateT MqttState IO ()Source
Misc
secToMicro :: Int -> IntSource