-serialDeviceBackgroundTask :: (Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) !*IWorld -> (MaybeError TaskException (), *IWorld)
-serialDeviceBackgroundTask rw iworld
- = case read rw iworld of
- (Error e, iworld) = (Error $ exception "share couldn't be read", iworld)
- (Ok (r,s,ss), iworld)
- # (Just (TTYd tty)) = iworld.resources
- # tty = writet (map encode s) tty
- # (ml, tty) = case TTYavailable tty of
- (False, tty) = ([], tty)
- (_, tty)
- # (l, tty) = TTYreadline tty
- = ([decode l], tty)
- # iworld = {iworld & resources=Just (TTYd tty)}
- = case write (r++ml,[],False) rw iworld of
- (Error e, iworld) = (Error $ exception "share couldn't be written", iworld)
- (Ok _, iworld) = case notify rw iworld of
- (Error e, iworld) = (Error $ exception "share couldn't be notified", iworld)
- (Ok _, iworld) = (Ok (), iworld)
- where
- writet :: [String] -> (*TTY -> *TTY)
- writet [] = id
- writet [x:xs] = writet xs o TTYwrite x
-
-
-syncNetworkChannel :: String Int (Shared ([MTaskMSGRecv], [MTaskMSGSend], Bool)) -> Task ()
-syncNetworkChannel server port channel
- = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! ()
- 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 Nothing acc (msgs,send,sendStopped)
- = (Ok acc, Nothing, [], False)
-// = (Ok acc, Just (msgs,[],sendStopped), map encode send, False)
-
- whileConnected (Just newData) acc (msgs,send,sendStopped)
- | sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
- = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False)
-
- onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
- onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)
+ process :: MTaskDevice (Shared Channels) -> Task ()
+ process device ch = forever (watch ch >>* [OnValue (
+ ifValue (not o isEmpty o fst3)
+ (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))])
+ where
+ proc :: [MTaskMSGRecv] -> Task ()
+ proc [] = treturn ()
+ proc [MTEmpty:ms] = proc ms
+ proc [m:ms] = traceValue (toString m) >>| (case m of
+// MTSDSAck i = traceValue (toString m) @! ()
+// MTSDSDelAck i = traceValue (toString m) @! ()
+ MTPub i val = updateShareFromPublish device i val @! ()
+ MTTaskAck i mem = deviceTaskAcked device i mem @! ()
+ MTTaskDelAck i = deviceTaskDeleteAcked device i @! ()
+ MTDevSpec s = deviceAddSpec device s @! ()
+ _ = treturn ()
+ ) >>| proc ms