1 implementation module Devices.mTaskTCP
5 import Devices.mTaskDevice
8 derive class iTask TCPSettings
9 derive gPrint MTaskMSGRecv
11 getmTaskTCPDevice :: Task MTaskResource
12 getmTaskTCPDevice = TCPDevice <$> enterInformation "Settings" []
14 instance MTaskDuplex TCPSettings where
15 synFun :: TCPSettings (Shared Channels) -> Task ()
17 tcpconnect s.host s.port channels {ConnectionHandlers|
19 whileConnected=whileConnected,
20 onDisconnect=onDisconnect} @! ()
22 onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
23 onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
25 whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
26 whileConnected Nothing _ (_,[],_) = (Ok "", Nothing, [], False)
27 whileConnected md _ (msgs,send,sendStopped)
28 = (Ok "", Just (msgs++map decode (maybeToList md),[],sendStopped), map encode send, False)
30 onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
31 onDisconnect _ (msgs,send,sendStopped) = (Ok "", Nothing)