1 implementation module Devices.mTaskTCP
3 import Devices.mTaskDevice
6 derive class iTask TCPSettings
8 getmTaskTCPDevice :: Task MTaskResource
9 getmTaskTCPDevice = TCPDevice <$> enterInformation "Settings" []
11 instance MTaskDuplex TCPSettings where
12 synFun :: TCPSettings (Shared Channels) -> Task ()
13 synFun s channels = catchAll (
14 tcpconnect s.host s.port channels {ConnectionHandlers|
16 whileConnected=whileConnected,
17 onDisconnect=onDisconnect} @! ())
18 (\v->traceValue v @! ())
20 onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
21 onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
23 whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
24 whileConnected Nothing acc (msgs,send,sendStopped) = (Ok acc, Nothing, [], False)
25 whileConnected (Just newData) acc (msgs,send,sendStopped) = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
27 onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
28 onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)