IO.dcl 2.51 KB
Newer Older
1 2 3 4 5 6
definition module iTasks.WF.Tasks.IO
/**
* This modules provides tasks that support interaction with other systems.
* Either by running external programs, creating network clients and servers, or exchanging files
*/
import iTasks.WF.Definition
7
import iTasks.SDS.Definition
8
from iTasks.Internal.IWorld import :: ConnectionId
9
from iTasks.UI.Prompt import class toPrompt
10
from System.FilePath import :: FilePath
11
from System.Process import :: ProcessPtyOptions
12 13 14
from Data.Error import :: MaybeError, :: MaybeErrorString

:: ConnectionHandlers l r w = 
15 16 17 18
    { onConnect         :: !(ConnectionId String   r -> (!MaybeErrorString l, Maybe w, ![String], !Bool))
    , onData            :: !(			  String l r -> (!MaybeErrorString l, Maybe w, ![String], !Bool))
    , onShareChange     :: !(                    l r -> (!MaybeErrorString l, Maybe w, ![String], !Bool))
    , onDisconnect      :: !(       		     l r -> (!MaybeErrorString l, Maybe w                  ))
19 20 21
	}

/**
22 23 24 25 26 27 28 29 30 31 32
 * Execute an external process. Data placed in the stdin sds is sent to the process, data received is placed in the (stdout, stderr) sds.
 *
 * @param Poll rate
 * @param Path to executable
 * @param Command line arguments
 * @param Startup directory
 * @param Stdin queue
 * @param (stdout, stderr) queue
 * @param Pseudotty settings
 * @result Task returning the exit code on termination
 */
33
externalProcess :: !Timespec !FilePath ![String] !(Maybe FilePath) !(Maybe ProcessPtyOptions) !(sds1 () [String] [String]) !(sds2 () ([String], [String]) ([String], [String])) -> Task Int | RWShared sds1 & RWShared sds2
34

35 36 37 38 39 40 41
/**
* Connect to an external system using TCP. This task's value becomes stable when the connection is closed
* @param Hostname
* @param Port
* @param A reference to shared data the task has access to
* @param The event handler functions
*/
42
tcpconnect :: !String !Int !(sds () r w) (ConnectionHandlers l r w) -> Task l | iTask l & iTask r & iTask w & RWShared sds
43 44 45 46 47 48 49 50
/**
* Listen for connections from external systems using TCP.
* @param Port
* @param Remove closed connections. If this is true, closed connections are removed from the task value, if not they are kept in the list
* @param A reference to shared data the task has access to
* @param Initialization function: function that is called when a new connection is established
* @param Communication function: function that is called when data arrives, the connection is closed or the observed share changes.
*/
51
tcplisten :: !Int !Bool !(sds () r w) (ConnectionHandlers l r w) -> Task [l] | iTask l & iTask r & iTask w & RWShared sds