Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-and-itasks
Tonic
Commits
1ad3262b
Commit
1ad3262b
authored
Oct 29, 2015
by
Jurriën Stutterheim
Browse files
Initial import: Tonic.Server
parents
Changes
2
Show whitespace changes
Inline
Side-by-side
Tonic/Server.dcl
0 → 100644
View file @
1ad3262b
definition
module
Tonic
.
Server
import
iTasks
::
ComputationId
:==
[
Int
]
::
NodeId
:==
[
Int
]
::
ModuleName
:==
String
::
FunctionName
:==
String
::
TonicMessage
=
{
computationId
::
ComputationId
// Abstraction from TaskId
,
nodeId
::
NodeId
,
moduleName
::
ModuleName
,
functionName
::
FunctionName
}
derive
class
iTask
TonicMessage
Tonic/Server.icl
0 → 100644
View file @
1ad3262b
implementation
module
Tonic
.
Server
import
iTasks
from
Text
import
class
Text
,
instance
Text
String
import
qualified
Text
as
T
derive
class
iTask
TonicMessage
debugMsg
str
=
{
TonicMessage
|
computationId
=
[]
,
nodeId
=
[]
,
moduleName
=
"DEBUG"
,
functionName
=
str
}
tonicServerShare
::
Shared
[
TonicMessage
]
tonicServerShare
=
sharedStore
"tonicServerShare"
[]
acceptAndViewTonicTraces
::
Task
[
TonicMessage
]
acceptAndViewTonicTraces
=
acceptTonicTraces
tonicServerShare
||-
viewSharedInformation
"Logged traces"
[]
tonicServerShare
acceptTonicTraces
::
!(
RWShared
()
[
TonicMessage
]
[
TonicMessage
])
->
Task
[
String
]
acceptTonicTraces
tonicShare
=
tcplisten
9000
True
tonicShare
{
ConnectionHandlers
|
onConnect
=
onConnect
,
whileConnected
=
whileConnected
,
onDisconnect
=
onDisconnect
}
where
onConnect
::
String
[
TonicMessage
]
->
(
MaybeErrorString
String
,
Maybe
[
TonicMessage
],
[
String
],
Bool
)
onConnect
host
olderMessages
=
(
Ok
""
,
Just
[
debugMsg
(
"Connection from "
+++
host
)
:
olderMessages
],
[
"Welcome!"
],
False
)
whileConnected
::
(
Maybe
String
)
String
[
TonicMessage
]
->
(
MaybeErrorString
String
,
Maybe
[
TonicMessage
],
[
String
],
Bool
)
whileConnected
(
Just
newData
)
oldData
olderMessages
#
collectedData
=
oldData
+++
'T'
.
trim
newData
#
(
messages
,
leftover
)
=
partitionMessages
(
'T'
.
split
"TONIC_EOL"
collectedData
)
#
mbTMsgs
=
case
[
msg
\\
Just
msg
<-
map
(
fromJSON
o
fromString
)
messages
]
of
[]
->
Nothing
xs
->
Just
(
xs
++
olderMessages
)
=
(
Ok
leftover
,
mbTMsgs
,
[],
False
)
where
partitionMessages
::
[
String
]
->
([
String
],
String
)
partitionMessages
[]
=
([],
""
)
partitionMessages
[
x
]
=
([],
x
)
partitionMessages
[
x
:
y
:
xs
]
#
(
msgs
,
leftover
)
=
partitionMessages
[
y
:
xs
]
=
([
x
:
msgs
],
leftover
)
whileConnected
Nothing
oldData
olderMessages
=
(
Ok
oldData
,
Nothing
,
[],
False
)
onDisconnect
::
String
[
TonicMessage
]
->
(
MaybeErrorString
String
,
Maybe
[
TonicMessage
])
onDisconnect
_
lines
=
(
Ok
""
,
Just
[
debugMsg
"Disconnect"
:
lines
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment