implementation module Devices.mTaskTCP import GenPrint import StdDebug import Devices.mTaskDevice import iTasks derive class iTask TCPSettings derive gPrint MTaskMSGRecv getmTaskTCPDevice :: Task MTaskResource getmTaskTCPDevice = TCPDevice <$> enterInformation "Settings" [] instance MTaskDuplex TCPSettings where synFun :: TCPSettings (Shared Channels) -> Task () synFun s channels = catchAll ( tcpconnect s.host s.port channels {ConnectionHandlers| onConnect=onConnect, whileConnected=whileConnected, onDisconnect=onDisconnect} @! ()) (\v->traceValue v @! ()) where onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False) whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool) whileConnected mnewData acc (msgs,send,sendStopped) | not (trace_tn (printToString (map decode (maybeToList mnewData)))) = undef = (Ok acc, Just (msgs ++ map decode (maybeToList mnewData),[],sendStopped), map encode send, False) onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool)) onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)