IWorld.dcl 7.64 KB
Newer Older
1
definition module iTasks._Framework.IWorld
2

3
from System.FilePath		import :: FilePath
4 5 6
from Data.Void				import :: Void
from Data.Map				import :: Map
from Data.Maybe				import :: Maybe
7 8 9 10
from Data.Set               import :: Set
from StdFile			                import class FileSystem		
from System.Time				        import :: Timestamp
from Text.JSON				            import :: JSONNode
11
from iTasks.API.Core.Types		        import :: Date, :: Time, :: DateTime, :: Config, :: InstanceNo, :: TaskNo, :: TaskId, :: TaskListItem, :: ParallelTaskType, :: TaskTime, :: SessionId
12 13 14 15 16 17
from iTasks._Framework.UIDefinition		import :: UIDef, :: UIControl, :: UIEditletOpts
from iTasks._Framework.UIDiff			import :: UIUpdate, :: UIEditletDiffs, :: ReferenceVersion, :: MessageType
from iTasks._Framework.TaskState		import :: ParallelTaskState, :: TIMeta, :: DeferredJSON
from iTasks._Framework.Task             import :: TaskValue, :: ConnectionTask, :: BackgroundTask
from iTasks._Framework.SDS import :: SDSNotifyRequest, :: BasicShareId
from iTasks._Framework.SDS import :: RWShared, :: ReadWriteShared, :: Shared, :: JSONShared
18

19 20
from Sapl.Linker.LazyLinker import :: LoaderState
from Sapl.Linker.SaplLinkerShared import :: LineType, :: FuncTypeMap
21
from Sapl.Target.Flavour import :: Flavour
22
from Sapl.SaplParser import :: ParserState
23
from TCPIP import :: TCP_Listener, :: TCP_Listener_, :: TCP_RChannel_, :: TCP_SChannel_, :: TCP_DuplexChannel, :: DuplexChannel, :: IPAddress, :: ByteSeq
24

25 26
:: *IWorld		=	{ server                :: !ServerInfo                              // Static server info, initialized at startup
					, config				:: !Config									// Server configuration
27
                    , clocks                :: !SystemClocks                            // Server side clocks
28 29 30
                    , current               :: !TaskEvalState                           // Shared state during task evaluation

                    , random                :: [Int]                                    // Infinite random stream
31

32
                    , sdsNotifyRequests     :: ![SDSNotifyRequest]                      // Notification requests from previously read sds's
33 34
                    , memoryShares          :: !Map (String,String) Dynamic             // Run-time memory shares
                    , cachedShares          :: !ShareCache                              // Cached json file shares
35
					, exposedShares			:: !Map String (Dynamic, JSONShared)        // Shared source
36

37 38 39 40 41
					, jsCompilerState 		:: (!LoaderState 							// State of the lazy loader
											   ,!FuncTypeMap							// Function name -> source code mapping
											   ,!Flavour								// Clean flavour for JS compilation
											   ,!Maybe ParserState						// Some information collected by the parser for the code generator
											   ,!Map InstanceNo (Set String))			// Per client information of the names of the already generated functions
42

43

44
                    , refreshQueue          :: ![(!InstanceNo,!Maybe String)]           // Instances that need refreshing (optionally with an explanation)
45

46 47
                    , ioTasks                :: !*IOTasks                                // The low-level input/output tasks
                    , ioStates               :: !IOStates                                // Results of low-level io tasks, indexed by the high-level taskid that it is linked to
Bas Lijnse's avatar
Bas Lijnse committed
48

49
					, world					:: !*World									// The outside world
50 51

                    //Experimental database connection cache
52
                    , resources             :: !*(Maybe *Resource)
53
                    , onClient				:: !Bool									// "False" on the server, "True" on the client
54
					, shutdown				:: !Bool									// Flag that signals the server function to shut down
55
					}
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70
:: ServerInfo =
    { serverName      :: !String				// The name of the server application
	, serverURL		  :: !String				// URL of the server like "//any.com:80"
	, buildID		  :: !String				// The date/time identifier of the server's build
    , paths           :: !SystemPaths           // Filesystem paths that are used by iTasks
    , customCSS       :: !Bool                  // Does the application use a custom css stylesheet
    }

:: SystemPaths =
    { appDirectory			:: !FilePath		// Location of the application's executable
	, dataDirectory			:: !FilePath		// Location of the applications data files
    , publicWebDirectories  :: ![FilePath]      // List of directories that contain files that are served publicly by the iTask webserver
    }

71 72 73 74 75 76 77
:: SystemClocks =
    { localDate             :: !Date
    , localTime             :: !Time
    , utcDate               :: !Date
    , utcTime               :: !Time
    }

78 79
:: ShareCache :== Map (String,String) (Dynamic,Bool,Maybe DeferredJSON)

80
:: TaskEvalState =
81 82 83 84 85 86 87
    { taskTime				 :: !TaskTime								// The 'virtual' time for the task. Increments at every event
	, taskInstance		     :: !InstanceNo								// The current evaluated task instance
    , sessionInstance        :: !Maybe InstanceNo                        // If we are evaluating a task in response to an event from a session
    , attachmentChain        :: ![TaskId]                                // The current way the evaluated task instance is attached to other instances
    , nextTaskNo			 :: !TaskNo									// The next task number to assign
    , eventRoute			 :: !Map TaskId Int							// Index of parallel branches the event is targeted at
    , editletDiffs           :: !UIEditletDiffs                          // Diffs of editlets
88 89
    }

90 91 92
:: *IOTasks =
    { done :: !*[IOTaskInstance]
    , todo :: !*[IOTaskInstance]
93 94
    }

95
:: *IOTaskInstance
96 97
    = ListenerInstance !ListenerInstanceOpts !*TCP_Listener
    | ConnectionInstance !ConnectionInstanceOpts !*TCP_DuplexChannel
98 99
    | BackgroundInstance !BackgroundTask

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
:: ListenerInstanceOpts =
    { taskId                :: !TaskId          //Reference to the task that created the listener
    , nextConnectionId      :: !ConnectionId    
    , port                  :: !Int
    , connectionTask        :: !ConnectionTask
    , removeOnClose         :: !Bool            //If this flag is set, states of connections accepted by this listener are removed when the connection is closed
    }

:: ConnectionInstanceOpts =
    { taskId                :: !TaskId          //Reference to the task that created the connection
    , connectionId          :: !ConnectionId    //Unique connection id (per listener/outgoing connection)
    , remoteHost            :: !IPAddress      
    , connectionTask        :: !ConnectionTask  //The io task definition that defines how the connection is handled
    , removeOnClose         :: !Bool            //If this flag is set, the connection state is removed when the connection is closed
    }

:: ConnectionId             :== Int

:: IOStates :== Map TaskId IOState
:: IOState
    = IOActive      !(Map ConnectionId (!Dynamic,!Bool))
    | IODestroyed   !(Map ConnectionId (!Dynamic,!Bool))
    | IOException   !String
:: IOConnectionState =
    { connectionTaskState   :: !Dynamic //The persisted local state of the connection task that handles the connection
    , closed                :: !Bool
    }
Bas Lijnse's avatar
Bas Lijnse committed
127

128 129
:: *Resource = Resource | .. //Extensible resource type for caching database connections etc...

130 131 132 133 134
//Internally used clock shares
iworldLocalDate :: Shared Date
iworldLocalTime :: Shared Time
iworldUTCDate   :: Shared Date
iworldUTCTime   :: Shared Time
135

136 137
//Update the clock shares
updateClocks    :: !*IWorld -> *IWorld
138

139 140
getResponseExpiry	:: !InstanceNo					!*IWorld -> (!Maybe Int, !*IWorld) 

141
/*
142 143 144
addUIUpdates    :: !InstanceNo ![UIUpdate]  !*IWorld -> *IWorld
popUIUpdates    :: ![InstanceNo]            !*IWorld -> (![(!InstanceNo,![UIUpdate])],!*IWorld)
clearUIUpdates  :: !InstanceNo              !*IWorld -> *IWorld
145
*/
146

147
instance FileSystem IWorld