Portability | portable |
---|---|
Stability | experimental |
Maintainer | Stefan Schmidt (stefanschmidt@web.de) |
Version : 0.1
General functions for the transmission of messages over the Holumbus-Ports. You don't need these functions, but they make your life much easier.
The mailbox concept doesn't deal with the request and response scheme very well, but with this module, all the boring stuff is solved. The function performPortAction will do everything for you. If you find it boring to write a seperate listener-thread for every mailbox you want to read from, you might look at the startRequestDispatcher and stopRequestDispatcher functions.
- class RspMsg m where
- isError :: m -> Bool
- getErrorMsg :: m -> String
- isUnknown :: m -> Bool
- mkErrorMsg :: String -> m
- performPortAction :: (Show a, Binary a, Show b, Binary b, RspMsg b) => Port a -> Stream b -> Int -> a -> (b -> IO (Maybe c)) -> IO c
- startRequestDispatcher :: (Binary a, Show a, Show b, Binary b, RspMsg b) => Thread -> Stream a -> (a -> Port b -> IO ()) -> IO ()
- stopRequestDispatcher :: Thread -> IO ()
- handleRequest :: (Show b, Binary b, RspMsg b) => Port b -> IO c -> (c -> b) -> IO ()
Message-Class
The typeclass for the response messages. We want to react if an error message is received an this interface helps us to detect and create such a message. The unknown message will be send back, if the server doesn't understand our request.
getErrorMsg :: m -> StringSource
mkErrorMsg :: String -> mSource
RspMsg ClientResponseMessage | |
RspMsg ServerResponseMessage | |
RspMsg PortRegistryResponseMessage |
Port-Handling
:: (Show a, Binary a, Show b, Binary b, RspMsg b) | |
=> Port a | request port |
-> Stream b | response Stream |
-> Int | timeout for the response in mikroseconds (1000000 = 1 sec) (0 = wait for ever) |
-> a | request message |
-> (b -> IO (Maybe c)) | response handler |
-> IO c |
Sends a request to the server (stream) and handles the response and all error cases. Very helpful when simulating a request response scheme with the mailboxes.
Stream-Handling
:: (Binary a, Show a, Show b, Binary b, RspMsg b) | |
=> Thread | threadId, to be filled |
-> Stream a | request-Stream (this is where the messages come in) |
-> (a -> Port b -> IO ()) | the dispatcher (create a reply message) |
-> IO () |
The server-side request dispatcher handles all incomming responses. The dispatcher runs in its own thread and should not be killed by any exceptions which will be raised in the handling process.
stopRequestDispatcher :: Thread -> IO ()Source
Stops the request dispatcher.