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 ()
16 synFun s channels = catchAll (
17 tcpconnect s.host s.port channels {ConnectionHandlers|
19 whileConnected=whileConnected,
20 onDisconnect=onDisconnect} @! ())
21 (\v->traceValue v @! ())
23 onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
24 onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
26 whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
27 whileConnected mnewData acc (msgs,send,sendStopped)
28 | not (trace_tn (printToString (map decode (maybeToList mnewData)))) = undef
29 = (Ok acc, Just (msgs ++ map decode (maybeToList mnewData),[],sendStopped), map encode send, False)
31 onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
32 onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)