4 # * Copyright 2010 Martin Quinson, Mehdi Fekari
5 # * All right reserved.
7 # * This program is free software; you can redistribute
8 # * it and/or modify it under the terms of the license
9 # *(GNU LGPL) which comes with this package.
14 $DEBUG = false # This is a Global Variable Useful for Debugging
16 class RbProcess < Thread
19 attr_accessor :bind, :id, :proprieties, :name,
20 :pargs, :schedBegin, :schedEnd
22 # Initialize : USED in ApplicationHandler to Initialize it
27 if argc == 0 #>>> new()
36 puts "Init Default Initialzer...Nothing to do...Bye"
41 # Init with 2 arguments **********************>>>(HostName,Name) Or (Host , Name)
45 if ( type.to_s == "String")
46 host = Host.getByName(args[0])
48 if ( type.to_s == "MSG::Host")
54 raise "Process Name Cannot Be Null" if args[1].empty?
55 @name = args[1] # First Arg
59 @pargs = Array.new() # No Args[] Passed in Arguments
64 createProcess(self,host)
66 puts "Initilize with 2 args"
72 # Init with 3 arguments **********************(hostName,Name,args[]) or # (Host,Name,args[])
77 if( type.to_s == "String")
78 host =Host.getByName(args[0])
80 if ( type.to_s == "MSG::Host" )
87 raise "Process Name Cannot Be Null" if args[0].empty?
90 raise "Third Argument Should be an Array" if type != "Array"
95 createProcess(self,host)
98 puts "Initilize with 3 args"
101 # sleep #keep the thread running
106 # Init_var Called By Initialize
108 @proprieties = Hash.new()
109 # Process Synchronization Tools
110 @schedBegin = Semaphore.new(0)
111 @schedEnd = Semaphore.new(0)
116 # To Be Implemented within The Process...
117 # The Main Code of The Process to be Executed ...
121 # Start : To keep the Process Alive and waitin' via semaphore
124 @schedBegin.acquire()
125 #execute The Main Code of The Process ( Example Master ; Slave ...)
127 processExit(self) #Exite the Native Process
134 return @@nextProcessId
140 Thread.list.each {|t| p t}
155 def processID(process)
165 def processName(process)
182 @schedBegin.acquire()
186 @schedBegin.release()
190 #C Simualateur Process Equivalent Management
191 # After Binding Ruby Process to C Process
205 processIsSuspended(self)
213 # The Rest of Methods !!! To be Continued ...