+# FIXME: add license like in C files
+
require 'simgrid_ruby'
-include MSG
require 'thread'
-$DEBUG = false # This is a Global Variable Useful for Debugging
+$DEBUG = false # This is a Global Variable Useful for MSG::debugging
###########################################################################
# Class Semaphore
end
def acquire
+ MSG::debug("Acquire "+self.to_s)
Thread.critical = true
if (@counter -= 1) < 0
@waiting_list.push(Thread.current)
end
def release
+ MSG::debug("Release "+self.to_s)
Thread.critical = true
begin
if (@counter += 1) <= 0
- t = @waiting_list.shift
- t.wakeup if t
+ t = @waiting_list.shift
+ t.wakeup if t
+ MSG::debug("Wakeup "+t.to_s)
+ else
+ MSG::debug("Nobody to wakeup")
end
rescue ThreadError
retry
########################################################################
# Class Process
########################################################################
-class MsgProcess < Thread
+class MSG::Process < Thread
@@nextProcessId = 0
# Attributes
- attr_reader :bind, :id, :pargs # Read only
- attr_accessor :name, :properties # R/W
+ attr_reader :bind, :id, :name, :pargs ,:properties# Read only
-# Initialize : Used from ApplicationHandler to fill it in
- def initialize(*args)
+ def initialize(*args)
+ super(){
+
+ raise "Bad Number Of arguments to create a Ruby Process (name,args,prop) " if args.size < 3
+
@schedBegin = Semaphore.new(0)
@schedEnd = Semaphore.new(0)
- @properties = Hash.new()
+ #@properties = Hash.new() FIXME: get this from the C (yep that makes 4 args to this function)
@id = @@nextProcessId++
-
- argc = args.size
-
- if argc == 0 # Default initializer
- super() {
- @id = 0
- @bind = 0
- @name = ""
- @pargs = Array.new()
- start()
- debug "Initializer without any argument"
- }
-
- # 2 arguments: (HostName,Name) Or (Host , Name)
- elsif argc == 2
- super(){
- debug "Initilize with 2 args"
- type = args[0].type()
- if ( type.to_s == "String")
- host = Host.getByName(args[0])
- elsif ( type.to_s == "MSG::Host")
- host = args[0]
- else
- raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
- end
- if $DEBUG
- puts host
- end
- raise "Process name cannot be null" if args[1].empty?
- @name = args[1]
- if $DEBUG
- puts @name
- end
- @pargs = Array.new() # No Args[] Passed in Arguments
- start()
- createProcess(self,host)
+ @name = args[0]
+ @pargs = args[1]
+ @properties = args[2]
+ start()
}
-
- # 3 arguments: (hostName,Name,args[]) or (Host,Name,args[])
- elsif argc == 3
- super(){
- debug "Initilize with 3 args"
- type = args[0].type()
- if ( type.to_s == "String")
- host = Host.getByName(args[0])
- elsif ( type.to_s == "MSG::Host")
- host = args[0]
- else
- raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
- end
- if $DEBUG
- puts host
- end
-
- raise "Process name cannot be null" if args[1].empty?
- @name = args[1]
- type = args[2].type()
- raise "Third argument should be an Array" if type != "Array"
- @pargs = args[3]
- createProcess(self,host)
-
- }
- else
- raise "Bad number of argument: Expecting either 1, 2 or 3, but got "+argc.to_s
- end
end
-
+
# main
def main(args)
# To be overriden by childs
def start()
@schedBegin.acquire
# execute the main code of the process
- debug("Begin execution")
+ MSG::debug("Begin execution")
main(@pargs)
- processExit(self) # Exit the Native Process
+# processExit(self) # Exit the Native Process
@schedEnd.release
end
- def processList()
- Thread.list.each {|t| p t}
- end
-
- #Get Own ID
- def getID()
- return @id
- end
-
- #Get a Process ID
- def processID(process)
- return process.id
- end
-
- #Get Own Name
- def getName()
- return @name
- end
-
- #Get a Process Name
- def processName(process)
- return process.name
- end
+
- #Get Bind
+ # Get Bind
def getBind()
return @bind
end
- #Get Binds
+ # Set Binds
def setBind(bind)
@bind = bind
end
@schedEnd.acquire
end
- #C Simualator Process Equivalent Management
- # After Binding Ruby Process to C Process
-
-# pause
def pause()
processSuspend(self)
end
-# restart
def restart()
processResume(self)
end
-# isSuspended
def isSuspended()
processIsSuspended(self)
end
-# getHost
def getHost()
processGetHost(self)
end
-# The Rest of Methods !!! To be Continued ...
+# The Rest of Methods !!! To be Continued ... FIXME: what's missing?
end
-#########################################################################
-# Class ApplicationHandler
-#########################################################################
-class ApplicationHandler
- def initialize()
- @hostName = nil
- @function = nil
+############################################
+# Task Extend from the native Class RbTask
+############################################
+class MSG::Task < MSG::RbTask
+
+ def initialize(*args)
+ super()
end
- def onBeginProcess(hostName,function)
- @args = Array.new
- @properties = Hash.new
+ def name
+ super(self)
+ end
+
+ def compSize
+ super(self)
+ end
+
+ def send(mailbox)
+ super(mailbox)
+ end
+
+ def receive(mailbox)
+ super(mailbox)
+ end
+
+ def source
+ super(self)
+ end
+
+ def sender
+ super(self)
+ end
+
+ def listen(t_alias)
+ super(t_alias)
+ end
+
+ def execute
+ super(self)
+ end
- @hostName = hostName
- @function = function
-
- debug("onBeginProcess("+hostName+","+function+")")
+ def listenFromHost(t_alias,host)
+ super(t_alias,host)
end
+
+end
+
+############################################
+# Host Extend from the native Class RbHost
+############################################
+class MSG::Host < MSG::RbHost
- def onProperty(id,value)
- @properties[id] = value
+ def getByName(name)
+ super(name)
end
- def onProcessArg(arg)
- @args.push(arg)
+ def name
+ super(self)
end
-
- def onEndProcess()
- process = rubyNewInstance(@function)
- size = @args.size
- for i in 0..size-1
- process.pargs.push(@args[i])
- end
- process.name = @function
- host = Host.getByName(@hostName)
- processCreate(process,host)
- process.properties = @properties
+
+ def speed
+ super(self)
+ end
+
+ def getData
+ super(self)
+ end
+
+ def setData(data)
+ super(self,data)
end
+
+ def isAvail
+ super(self)
+ end
+
+ def number
+ super()
+ end
+
end
-
+
#########################
# Main chunck
#########################