use Windows, Math, Strings, Editor, System, Structures
type DataRecord is DoubleLinked.Record with
word32[,] Content
int Nr
end
design Universe is
cell Window = create MenuWindow("Memory allocation")
system <- Io.SetStdOut( Window )
cell Earth = create Planet( "Earth", Window )
end
design Planet(ansi Name, cell Window ) is
keep Name, Window
cell Timer
type SatRecord is record
cell Cell
ansi Name
word Orbit
end
SatRecord SatList[] = [ [null, "TelStar", 7300],
[null, "Hubble", 17100] ]
constructor is
system <- Service.Get("Timer")
for each Sat in SatList do
Sat.Cell = create Satellite( Sat.Orbit, Sat.Name, self , Window)
end
end
on Service.Provider(ansi ServiceName, cell Timer) do
keep Timer
Timer <- Subscribe.Interval( 500w, "Interval.Collect")
Timer <- Subscribe.Interval( 3900w, "Interval.Transmit" )
end
on Service.NoProvider(ansi Name) do
Window <- print("\nNo provider for this service : [Name]")
end
interface Interval is
for each Sat in SatList do
Sat.Cell <- CollectData
end
end
on Transmit( word ms ) do
for each Sat in SatList do
Sat.Cell <- TransmitData
end
end
interface end
on Transmission(ansi Satellite, ansi TextMessage, word32[,] Content) do
Window <- print("\n[Name] received [TextMessage] from [Satellite]")
end
end
design Satellite( word Orbit, ansi Name, cell Planet, cell Window) is
keep Orbit, Name, Planet, Window
use template DoubleLinked.List for DataListType, DataRecord
DataListType DataList
int Counter = 0
bool Visible = true
VirtualMachineManagerClass VMMgr = VMMgr.Get()
constructor is
Window <- print("\n\t[Name] is in orbit")
system <- Service.Get("Timer")
end
on Service.Provider( ansi ServiceName , cell Timer) do
Timer <- Subscribe.Interval( Orbit / 2 , "ToggleVisible")
Timer <- Subscribe.Interval( 5000w, "MemoryStatus" )
end
on ToggleVisible(word when) => Visible = not Visible
on CollectData do
not Visible ? yield
var NewData := DataList.New()
not NewData ? yield
sel NewData.Content[400,600]
NewData.Nr = Counter +~ 1
Window <- print("\n\t[Name] collects data [NewData.Nr]")
DataList.Push(NewData)
end
on TransmitData do
DataRecord.ptr Data
not Visible ? yield
while Data := DataList.Pop() do
Planet <- Transmission("[Name]","Data [Data.Nr]", Data.Content)
delete Data.Content
delete Data
end
end
on MemoryStatus( word time ) do
CellMemoryUsage Usage = [0,0 ]
Usage = VMMgr.GetCellMemoryUsage( self )
Window <- print("\n*** [ time / 1000 ] *** Memory Status [Name]: [Usage.NrOfItems] items - [Usage.BytesAllocated] bytes.")
end
end