From 64c42bdfb264bf9ef0065056f5406476827e748a Mon Sep 17 00:00:00 2001 From: prascle Date: Fri, 28 Sep 2007 14:41:30 +0000 Subject: [PATCH] merge from branch BR_For40_DSC tag mergeto_BR_Dev_For_4_0_28sep2007 --- bin/addToKillList.py | 16 +- bin/killSalomeWithPort.py | 6 +- bin/nameserver.py | 102 +- bin/orbmodule.py | 11 +- bin/runNS.py | 102 +- bin/runSalome.py | 72 +- bin/server.py | 60 +- bin/setenv.py | 10 +- bin/virtual_salome.py | 22 + configure.ac | 5 +- doc/salome/tui/KERNEL/doxyuser.in | 16 +- doc/salome/tui/Makefile.am | 2 +- idl/DSC_Engines.idl | 13 +- idl/DSC_Engines.xml | 3 + idl/Makefile.am | 30 +- idl/SALOME_Component.idl | 338 +++++- idl/SALOME_Component.xml | 19 +- idl/SALOME_Exception.xml | 31 + salome_adm/unix/config_files/Makefile.am | 1 + salome_adm/unix/config_files/check_htmlgen.m4 | 2 +- salome_adm/unix/config_files/check_mpi.m4 | 11 + salome_adm/unix/config_files/check_openmpi.m4 | 56 + salome_adm/unix/config_files/production.m4 | 79 +- src/Container/Component_i.cxx | 168 ++- src/Container/Container_i.cxx | 321 ++--- src/Container/Makefile.am | 25 +- src/Container/SALOME_Component_i.hxx | 28 + src/Container/SALOME_Container.cxx | 56 + src/Container/SALOME_ContainerManager.cxx | 7 +- src/Container/SALOME_Container_i.hxx | 3 +- src/Container/Salome_file_i.cxx | 1062 +++++++++++++++++ src/Container/Salome_file_i.hxx | 106 ++ src/Container/TestSalome_file.cxx | 154 +++ src/DSC/DSC_Basic/DSC_Basic.hxx | 3 +- src/DSC/DSC_Python/Makefile.am | 79 ++ src/DSC/DSC_Python/calcium.i | 241 ++++ src/DSC/DSC_Python/dsccalcium.py | 53 + .../Basic/data_short_port_provides.cxx | 51 +- .../Basic/data_short_port_provides.hxx | 8 + .../DSC_User/Datastream/AdjacentFunctor.hxx | 10 + src/DSC/DSC_User/Datastream/Calcium/Calcium.c | 3 +- .../DSC_User/Datastream/Calcium/Calcium.cxx | 114 ++ .../DSC_User/Datastream/Calcium/Calcium.hxx | 17 + .../Calcium/CalciumCouplingPolicy.hxx | 47 +- .../Datastream/Calcium/CalciumInterface.hxx | 103 +- .../Calcium/CalciumTypes2CorbaTypes.cxx | 4 + .../Datastream/Calcium/Copy2CorbaSpace.hxx | 8 + .../Datastream/Calcium/Copy2UserSpace.hxx | 4 + .../Calcium/CorbaTypes2CalciumTypes.cxx | 4 + .../DSC_User/Datastream/Calcium/Makefile.am | 14 +- src/DSC/DSC_User/Datastream/Calcium/calcium.h | 1 - .../DSC_User/Datastream/Calcium/calciumf.c | 120 ++ src/DSC/DSC_User/Datastream/Calcium/fortoc.h | 20 + .../Datastream/CorbaTypeManipulator.hxx | 4 + src/DSC/DSC_User/Datastream/GenericPort.hxx | 85 +- .../DSC_User/Datastream/GenericUsesPort.hxx | 4 + src/DSC/DSC_User/Makefile.am | 2 +- src/DSC/DSC_User/Superv_Component_i.cxx | 8 + src/DSC/DSC_User/Superv_Component_i.hxx | 6 + src/DSC/Makefile.am | 2 +- src/DSC/ParallelDSC/ParallelDSC_i.cxx | 3 +- src/DSC/ParallelDSC/ParallelDSC_i.hxx | 2 - src/HDFPersist/HDFascii.cc | 221 +++- src/HDFPersist/HDFascii.hxx | 4 +- src/HDFPersist/HDFcontainerObject.cc | 4 +- src/HDFPersist/HDFcontainerObject.hxx | 6 +- src/HDFPersist/HDFdataset.cc | 4 +- src/HDFPersist/HDFdataset.hxx | 8 +- src/HDFPersist/HDFexport.hxx | 39 + src/HDFPersist/HDFfile.hxx | 4 +- src/HDFPersist/HDFgroup.cc | 2 +- src/HDFPersist/HDFgroup.hxx | 6 +- src/HDFPersist/HDFinternalObject.cc | 2 +- src/HDFPersist/HDFinternalObject.hxx | 6 +- src/HDFPersist/HDFobject.cc | 4 +- src/HDFPersist/HDFobject.hxx | 6 +- src/HDFPersist/Makefile.am | 11 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 5 +- src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py | 5 +- .../Test/TestLifeCycleCORBA_SWIG.py | 5 +- src/NamingService/Test/TestNamingService.py | 5 +- src/ParallelContainer/Makefile.am | 24 +- .../Parallel_Salome_file_i.cxx | 358 ++++++ .../Parallel_Salome_file_i.hxx | 74 ++ .../SALOME_ParallelComponent_i.cxx | 399 ++++++- .../SALOME_ParallelComponent_i.hxx | 55 +- .../SALOME_ParallelContainerNodeDummy.cxx | 52 +- .../SALOME_ParallelContainerNodeMpi.cxx | 70 +- .../SALOME_ParallelContainer_i.cxx | 33 +- .../SALOME_ParallelContainer_i.hxx | 3 + src/Registry/SALOME_Registry.hxx | 3 +- .../SALOME_ResourcesManager.cxx | 7 +- src/SALOMEDS/Test/TestSALOMEDS.py | 5 +- .../Test/TestSALOMELocalTrace.py | 5 +- src/UnitTests/UnitTests.py | 5 +- 95 files changed, 4828 insertions(+), 569 deletions(-) create mode 100644 idl/SALOME_Exception.xml create mode 100644 salome_adm/unix/config_files/check_openmpi.m4 create mode 100644 src/Container/Salome_file_i.cxx create mode 100644 src/Container/Salome_file_i.hxx create mode 100644 src/Container/TestSalome_file.cxx create mode 100644 src/DSC/DSC_Python/Makefile.am create mode 100644 src/DSC/DSC_Python/calcium.i create mode 100644 src/DSC/DSC_Python/dsccalcium.py create mode 100644 src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx create mode 100644 src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx create mode 100644 src/DSC/DSC_User/Datastream/Calcium/calciumf.c create mode 100644 src/DSC/DSC_User/Datastream/Calcium/fortoc.h create mode 100644 src/HDFPersist/HDFexport.hxx create mode 100644 src/ParallelContainer/Parallel_Salome_file_i.cxx create mode 100644 src/ParallelContainer/Parallel_Salome_file_i.hxx diff --git a/bin/addToKillList.py b/bin/addToKillList.py index f29cccef7..537dfaf3d 100755 --- a/bin/addToKillList.py +++ b/bin/addToKillList.py @@ -64,8 +64,8 @@ def addToKillList(command_pid, command): if verbose(): print process_id for pid, cmd in process_id.items(): #print "see process %s : %s"% (pid, cmd[0]) - if pid == command_pid: - already_in=1 + if pid == command_pid: + already_in=1 pass pass pass @@ -73,14 +73,14 @@ def addToKillList(command_pid, command): command=(command.split(" "))[0] if already_in == 0: try: - process_ids.append({command_pid: [command]}) - fpid=open(filedict,'w') + process_ids.append({command_pid: [command]}) + fpid=open(filedict,'w') pickle.dump(process_ids, fpid) - fpid.close() + fpid.close() except: - print "addToKillList: can not add command %s to the kill list"% filedict - pass - pass + print "addToKillList: can not add command %s to the kill list"% filedict + pass + pass pass def killList(): diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index 86d112af8..79c168279 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -102,10 +102,10 @@ def killMyPort(port): if pidfield != "egrep" : if sys.platform == "win32": import win32pm - print 'stop process '+pidfield+' : omniNames' + print 'stop process '+pidfield+' : omniNames' win32pm.killpid(int(pidfield),0) else: - if verbose(): print 'stop process '+pidfield+' : omniNames' + if verbose(): print 'stop process '+pidfield+' : omniNames' os.system('kill -9 '+pidfield) pidfield = field except: @@ -138,7 +138,7 @@ def killMyPort(port): while pid != "" and len(a.split(" ")) < 2: a = commands.getoutput("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid") pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"") - print pid + print pid pass diff --git a/bin/nameserver.py b/bin/nameserver.py index aacb59ed9..dd03c51a3 100755 --- a/bin/nameserver.py +++ b/bin/nameserver.py @@ -22,68 +22,67 @@ class NamingServer(Server): os.environ["BaseDir"]=os.environ["HOME"] else: os.environ["BaseDir"]="/tmp" - - try: - os.mkdir(os.environ["BaseDir"] + "/logs") + + try: + os.mkdir(os.environ["BaseDir"] + "/logs") os.chmod(os.environ["BaseDir"] + "/logs", 0777) - except: - #print "Can't create " + os.environ["BaseDir"] + "/logs" - pass - - upath = os.environ["BaseDir"] + "/logs/"; - if sys.platform == "win32": - upath += os.environ["Username"]; - else: - upath += os.environ["USER"]; - - try: - os.mkdir(upath) - except: - #print "Can't create " + upath - pass - - #os.system("touch " + upath + "/dummy") - for fname in os.listdir(upath): - try: - os.remove(upath + "/" + fname) - except: - pass - #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log") - - print "Name Service... " - #hname=os.environ["HOST"] #commands.getoutput("hostname") + except: + #print "Can't create " + os.environ["BaseDir"] + "/logs" + pass + + upath = os.environ["BaseDir"] + "/logs/"; if sys.platform == "win32": - hname=getShortHostName(); + upath += os.environ["Username"]; else: - hname = socket.gethostname(); - - print "hname=",hname - - f=open(os.environ["OMNIORB_CONFIG"]) - ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) - print "ss = ", ss - f.close() + upath += os.environ["USER"]; + + try: + os.mkdir(upath) + except: + #print "Can't create " + upath + pass + + #os.system("touch " + upath + "/dummy") + for fname in os.listdir(upath): + try: + os.remove(upath + "/" + fname) + except: + pass + #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log") + + print "Name Service... ", + #hname=os.environ["HOST"] #commands.getoutput("hostname") + if sys.platform == "win32": + hname=getShortHostName(); + else: + hname = socket.gethostname(); + #print "hname=",hname + + f=open(os.environ["OMNIORB_CONFIG"]) + ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) + print "ss = ", ss, + f.close() sl=ss[0] ll = sl.split(':') aPort = ll[-1] #aPort=(ss.join().split(':'))[2]; - #aPort=re.findall("\d+", ss[0])[0] - - #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/" - #print "sed command = ", aSedCommand - #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"]) - print "port=", aPort - if sys.platform == "win32": - #print "start omniNames -start " + aPort + " -logdir " + upath + #aPort=re.findall("\d+", ss[0])[0] + + #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/" + #print "sed command = ", aSedCommand + #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"]) + #print "port=", aPort + if sys.platform == "win32": + #print "start omniNames -start " + aPort + " -logdir " + upath self.CMD=['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"'] - #os.system("start omniNames -start " + aPort + " -logdir " + upath) - else: + #os.system("start omniNames -start " + aPort + " -logdir " + upath) + else: #self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &'] self.CMD=['omniNames','-start' , aPort, '-logdir' , upath ] - #os.system("omniNames -start " + aPort + " -logdir " + upath + " &") + #os.system("omniNames -start " + aPort + " -logdir " + upath + " &") - print "ok" - print "to list contexts and objects bound int the context with the specified name : showNS " + print "... ok" + print "to list contexts and objects bound into the context with the specified name : showNS " def initArgs(self): @@ -95,7 +94,6 @@ class NamingServer(Server): self.CMD=['xterm', '-e']+ env_ld_library_path + ['python'] self.initNSArgs() - # In LifeCycleCORBA, FactoryServer is started with rsh on the requested # computer if this Container does not exist. Default is localhost. # Others Containers are started with start_impl method of FactoryServer Container. diff --git a/bin/orbmodule.py b/bin/orbmodule.py index 86c89201e..f629aa847 100755 --- a/bin/orbmodule.py +++ b/bin/orbmodule.py @@ -35,14 +35,11 @@ class client: # Initialise the ORB self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # Initialise the Naming Service - print "Obtain a reference to the root naming context" - print args self.initNS(args) # -------------------------------------------------------------------------- def initNS(self,args): - print "Obtain a reference to the root naming context" # Obtain a reference to the root naming context obj = self.orb.resolve_initial_references("NameService") try: @@ -50,7 +47,7 @@ class client: return except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE): self.rootContext = None - print "Lancement du Naming Service", + print "Launch Naming Service++", # On lance le Naming Server (doit etre dans le PATH) NamingServer(args).run() @@ -151,9 +148,9 @@ class client: print "Searching %s in Naming Service " % theName, while(1): try: - aPid, aStatus = os.waitpid(thePID,os.WNOHANG) - except Exception, exc: - raise "Impossible de trouver %s" % theName + os.kill(thePID,0) + except: + raise "Process %d for %s not found" % (thePID,theName) aCount += 1 anObj = self.Resolve(theName) if anObj: diff --git a/bin/runNS.py b/bin/runNS.py index 5af2c5af5..444760369 100755 --- a/bin/runNS.py +++ b/bin/runNS.py @@ -6,11 +6,11 @@ import os, commands, sys, re, string, socket from Utils_Identity import getShortHostName if sys.platform == "win32": - # temporarily using home directory for Namning Service logs - # to be replaced with TEMP later... - os.environ["BaseDir"]=os.environ["HOME"] + # temporarily using home directory for Namning Service logs + # to be replaced with TEMP later... + os.environ["BaseDir"]=os.environ["HOME"] else: - os.environ["BaseDir"]="/tmp" + os.environ["BaseDir"]="/tmp" os.environ["Username"]=os.environ["USER"] @@ -21,50 +21,50 @@ os.environ["Username"]=os.environ["USER"] # clear log files def startOmni(): - try: - os.mkdir(os.environ["BaseDir"] + "/logs") - os.chmod(os.environ["BaseDir"] + "/logs", 0777) - except: - #print "Can't create " + os.environ["BaseDir"] + "/logs" - pass - - upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"] - - try: - os.mkdir(upath) - except: - #print "Can't create " + upath - pass - - #os.system("touch " + upath + "/dummy") - for fname in os.listdir(upath): - try: - os.remove(upath + "/" + fname) - except: - pass - #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log") - - print "Name Service... " - #hname=os.environ["HOST"] #commands.getoutput("hostname") - if sys.platform == "win32": + try: + os.mkdir(os.environ["BaseDir"] + "/logs") + os.chmod(os.environ["BaseDir"] + "/logs", 0777) + except: + #print "Can't create " + os.environ["BaseDir"] + "/logs" + pass + + upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"] + + try: + os.mkdir(upath) + except: + #print "Can't create " + upath + pass + + #os.system("touch " + upath + "/dummy") + for fname in os.listdir(upath): + try: + os.remove(upath + "/" + fname) + except: + pass + #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log") + + print "Name Service... " + #hname=os.environ["HOST"] #commands.getoutput("hostname") + if sys.platform == "win32": hname=getShortHostName() - else: - hname=socket.gethostname() - - print "hname=",hname - - f=open(os.environ["OMNIORB_CONFIG"]) - ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) - print "ss = ", ss - f.close() - aPort=re.findall("\d+", ss[0])[0] - - #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/" - #print "sed command = ", aSedCommand - #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"]) - global process_id - print "port=", aPort - if sys.platform == "win32": + else: + hname=socket.gethostname() + + print "hname=",hname + + f=open(os.environ["OMNIORB_CONFIG"]) + ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) + print "ss = ", ss + f.close() + aPort=re.findall("\d+", ss[0])[0] + + #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/" + #print "sed command = ", aSedCommand + #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"]) + global process_id + print "port=", aPort + if sys.platform == "win32": #import win32pm #command = ['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"'] #os.system("start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\"" ) @@ -72,11 +72,11 @@ def startOmni(): #print command pid = win32pm.spawnpid( string.join(command, " "), -nc ) process_id[pid]=command - else: - os.system("omniNames -start " + aPort + " -logdir " + upath + " &") + else: + os.system("omniNames -start " + aPort + " -logdir " + upath + " &") - print "ok" - print "to list contexts and objects bound int the context with the specified name : showNS " + print "ok" + print "to list contexts and objects bound into the context with the specified name : showNS " # In LifeCycleCORBA, FactoryServer is started with rsh on the requested # computer if this Container does not exist. Default is localhost. diff --git a/bin/runSalome.py b/bin/runSalome.py index 62afcfb21..4cfcf1502 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -88,10 +88,10 @@ class InterpServer(Server): global process_id command = self.CMD print "INTERPSERVER::command = ", command - if sys.platform == "win32": + if sys.platform == "win32": import win32pm pid = win32pm.spawnpid( string.join(command, " "),'-nc' ) - else: + else: pid = os.spawnvp(os.P_NOWAIT, command[0], command) process_id[pid]=self.CMD self.PID = pid @@ -102,9 +102,9 @@ class CatalogServer(Server): def __init__(self,args): self.args=args self.initArgs() - #if sys.platform == "win32": - # self.SCMD1=[os.environ["KERNEL_ROOT_DIR"] + "/win32/" + os.environ["BIN_ENV"] + "/" + 'SALOME_ModuleCatalog_Server' + ".exe",'-common'] - #else: + #if sys.platform == "win32": + # self.SCMD1=[os.environ["KERNEL_ROOT_DIR"] + "/win32/" + os.environ["BIN_ENV"] + "/" + 'SALOME_ModuleCatalog_Server' + ".exe",'-common'] + #else: self.SCMD1=['SALOME_ModuleCatalog_Server','-common'] self.SCMD2=[] home_dir=os.getenv('HOME') @@ -182,9 +182,9 @@ class ContainerPYServer(Server): def __init__(self,args): self.args=args self.initArgs() - if sys.platform == "win32": + if sys.platform == "win32": self.CMD=[os.environ["PYTHONBIN"], '\"'+os.environ["KERNEL_ROOT_DIR"] + '/bin/salome/SALOME_ContainerPy.py'+'\"','FactoryServerPy'] - else: + else: self.CMD=['SALOME_ContainerPy.py','FactoryServerPy'] # --- @@ -193,9 +193,9 @@ class ContainerSUPERVServer(Server): def __init__(self,args): self.args=args self.initArgs() -# if sys.platform == "win32": + # if sys.platform == "win32": # self.CMD=[os.environ["KERNEL_ROOT_DIR"] + "/win32/" + os.environ["BIN_ENV"] + "/" + 'SALOME_Container' + ".exe",'SuperVisionContainer'] -# else: +# else: self.CMD=['SALOME_Container','SuperVisionContainer'] # --- @@ -215,11 +215,10 @@ class SessionServer(Server): def __init__(self,args): self.args = args.copy() # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge) - self.args['xterm']=0 + #self.args['xterm']=0 # self.initArgs() self.SCMD1=['SALOME_Session_Server'] - self.SCMD2=[] if 'registry' in self.args['embedded']: self.SCMD1+=['--with','Registry', @@ -706,39 +705,39 @@ def searchFreePort(args, save_config=1): limit=limit+10 while 1: import os - import re - from os import getpid + import re + from os import getpid from os import system - if sys.platform == "win32": - tmp_file = os.getenv('TEMP'); + if sys.platform == "win32": + tmp_file = os.getenv('TEMP'); else: tmp_file = '/tmp/' - tmp_file += 'hostname_%s'%(getpid()) + tmp_file += 'hostname_%s'%(getpid()) # status = os.system("netstat -ltn | grep -E :%s > /dev/null 2>&1"%(NSPORT)) - system( "netstat -a -n > %s" % tmp_file ); + system( "netstat -a -n > %s" % tmp_file ); - f = open( tmp_file, 'r' ); - lines = f.readlines(); - f.close(); + f = open( tmp_file, 'r' ); + lines = f.readlines(); + f.close(); - pattern = "tcp.*:([0-9]+).*:.*listen"; - regObj = re.compile( pattern, re.IGNORECASE ); + pattern = "tcp.*:([0-9]+).*:.*listen"; + regObj = re.compile( pattern, re.IGNORECASE ); status = 1; - for item in lines: - m = regObj.search( item ) - if m: - try: - p = int( m.group(1) ) - if p == NSPORT: - status = 0; - break; - except: - pass - pass + for item in lines: + m = regObj.search( item ) + if m: + try: + p = int( m.group(1) ) + if p == NSPORT: + status = 0; + break; + except: + pass + pass if status == 1: print "%s - OK"%(NSPORT) @@ -749,8 +748,7 @@ def searchFreePort(args, save_config=1): myhost = myhost[:-1] f.close() -# system('rm -f %s'%(tmp_file)) - os.remove( tmp_file ); + os.remove( tmp_file ); # home = os.environ['HOME'] @@ -776,10 +774,10 @@ def searchFreePort(args, save_config=1): if save_config: from os import system if sys.platform == "win32": - import shutil + import shutil shutil.copyfile( os.environ['OMNIORB_CONFIG'], "%s/.omniORB_last.cfg"%( home ) ) else: - system('ln -s -f %s %s/.omniORB_last.cfg'%(os.environ['OMNIORB_CONFIG'], home)) + system('ln -s -f %s %s/.omniORB_last.cfg'%(os.environ['OMNIORB_CONFIG'], home)) pass # break diff --git a/bin/server.py b/bin/server.py index 88e74720e..5bd61799d 100755 --- a/bin/server.py +++ b/bin/server.py @@ -14,7 +14,7 @@ class Server: def initArgs(self): self.PID=None self.CMD=[] - self.ARGS=[] + self.ARGS=[] if self.args['xterm']: self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold'] @@ -32,15 +32,65 @@ class Server: + os.getenv("LD_LIBRARY_PATH")] myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path command = myargs + self.CMD - print "command = ", command - if sys.platform == "win32": + #print "command = ", command + if sys.platform == "win32": import win32pm #cmd_str = "\"" + string.join(command, " ") + "\"" #print cmd_str #pid = win32pm.spawnpid( cmd_str ) pid = win32pm.spawnpid( string.join(command, " "), '-nc' ) #pid = win32pm.spawnpid( string.join(command, " ") ) - else: - pid = os.spawnvp(os.P_NOWAIT, command[0], command) + else: + #pid = os.spawnvp(os.P_NOWAIT, command[0], command) + pid=self.daemonize(command) process_id[pid]=self.CMD self.PID = pid + return pid + + def daemonize(self,args): + # to daemonize a process need to do the UNIX double-fork magic + # see Stevens, "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177) + # and UNIX Programming FAQ 1.7 How do I get my program to act like a daemon? + # http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 + #open a pipe + c2pread, c2pwrite = os.pipe() + #do first fork + pid=os.fork() + if pid > 0: + #first parent + os.close(c2pwrite) + #receive real pid from child + data=os.read(c2pread,24) #read 24 bytes + os.waitpid(pid,0) #remove zombie + os.close(c2pread) + # return : first parent + return int(data) + + #first child + # decouple from parent environment + os.setsid() + os.close(c2pread) + + # do second fork : second child not a session leader + try: + pid = os.fork() + if pid > 0: + #send real pid to parent + os.write(c2pwrite,"%d" % pid) + os.close(c2pwrite) + # exit from second parent + os._exit(0) + except OSError, e: + print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) + os.write(c2pwrite,"-1") + os.close(c2pwrite) + sys.exit(1) + + #I am a daemon + os.close(0) #close stdin + os.open("/dev/null", os.O_RDWR) # redirect standard input (0) to /dev/null + try: + os.execvp(args[0], args) + except OSError, e: + print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror) + os._exit(127) diff --git a/bin/setenv.py b/bin/setenv.py index 35ac2ad4c..0b1fc0e20 100755 --- a/bin/setenv.py +++ b/bin/setenv.py @@ -37,9 +37,9 @@ salome_subdir = "salome" def add_path(directory, variable_name): """Function helper to add environment variables""" if sys.platform == "win32": - splitsym = ";" + splitsym = ";" else: - splitsym = ":" + splitsym = ":" if not os.environ.has_key(variable_name): os.environ[variable_name] = "" pass @@ -240,9 +240,9 @@ def set_env(args, modules_list, modules_root_dir): "PYTHONPATH") - if sys.platform == "win32": - add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), - "PATH") + if sys.platform == "win32": + add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), + "PATH") else: add_path(os.path.join(plugin_root,get_lib_dir(),salome_subdir), "LD_LIBRARY_PATH") diff --git a/bin/virtual_salome.py b/bin/virtual_salome.py index d9c9fa5cf..4f6a4724a 100644 --- a/bin/virtual_salome.py +++ b/bin/virtual_salome.py @@ -114,6 +114,8 @@ def link_module(options): module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui') module_doc_dir=os.path.join(module_dir,'doc','salome') module_sharedoc_dir=os.path.join(module_dir,'share','doc','salome') + module_sharedoc_gui_dir=os.path.join(module_dir,'share','doc','salome','gui') + module_sharedoc_tui_dir=os.path.join(module_dir,'share','doc','salome','tui') bin_dir=os.path.join(home_dir,'bin','salome') lib_dir=os.path.join(home_dir,'lib','salome') @@ -125,6 +127,8 @@ def link_module(options): doc_tui_dir=os.path.join(home_dir,'doc','salome','tui') doc_dir=os.path.join(home_dir,'doc','salome') sharedoc_dir=os.path.join(home_dir,'share','doc','salome') + sharedoc_gui_dir=os.path.join(home_dir,'share','doc','salome','gui') + sharedoc_tui_dir=os.path.join(home_dir,'share','doc','salome','tui') verbose = options.verbose @@ -181,10 +185,28 @@ def link_module(options): if os.path.exists(module_sharedoc_dir): mkdir(sharedoc_dir) for fn in os.listdir(module_sharedoc_dir): + if fn == 'gui':continue + if fn == 'tui':continue symlink(os.path.join(module_sharedoc_dir, fn), os.path.join(sharedoc_dir, fn)) pass pass + #directory share/doc/salome/gui : create it and link content + if os.path.exists(module_sharedoc_gui_dir): + mkdir(sharedoc_gui_dir) + for fn in os.listdir(module_sharedoc_gui_dir): + symlink(os.path.join(module_sharedoc_gui_dir, fn), os.path.join(sharedoc_gui_dir, fn)) + pass + pass + + #directory share/doc/salome/tui : create it and link content + if os.path.exists(module_sharedoc_tui_dir): + mkdir(sharedoc_tui_dir) + for fn in os.listdir(module_sharedoc_tui_dir): + symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn)) + pass + pass + #directory share/salome/resources : create it and link content if os.path.exists(module_share_dir): mkdir(share_dir) diff --git a/configure.ac b/configure.ac index 8480a5e5f..334762482 100644 --- a/configure.ac +++ b/configure.ac @@ -104,8 +104,8 @@ echo Configuring production echo --------------------------------------------- echo # production.m4 -AC_ENABLE_DEBUG(yes) -AC_DISABLE_PRODUCTION +AC_ENABLE_DEBUG(no) +AC_ENABLE_PRODUCTION(no) echo echo --------------------------------------------- @@ -566,6 +566,7 @@ AC_OUTPUT([ \ ./src/DSC/DSC_User/Datastream/Palm/Makefile \ ./src/DSC/DSC_User/Datastream/Calcium/Makefile \ ./src/DSC/ParallelDSC/Makefile \ + ./src/DSC/DSC_Python/Makefile \ ./src/GenericObj/Makefile \ ./src/HDFPersist/Makefile \ ./src/KERNEL_PY/Makefile \ diff --git a/doc/salome/tui/KERNEL/doxyuser.in b/doc/salome/tui/KERNEL/doxyuser.in index 854a69cc4..4b407f61b 100644 --- a/doc/salome/tui/KERNEL/doxyuser.in +++ b/doc/salome/tui/KERNEL/doxyuser.in @@ -58,8 +58,8 @@ GENERATE_BUGLIST = NO GENERATE_DEPRECATEDLIST= NO ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 25 -SHOW_USED_FILES = NO -SHOW_DIRECTORIES = NO +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = YES FILE_VERSION_FILTER = #--------------------------------------------------------------------------- @@ -96,15 +96,15 @@ EXAMPLE_RECURSIVE = NO IMAGE_PATH = sources/ INPUT_FILTER = FILTER_PATTERNS = -FILTER_SOURCE_FILES = YES +FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO +SOURCE_BROWSER = YES +INLINE_SOURCES = YES STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = NO +REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES USE_HTAGS = NO VERBATIM_HEADERS = YES @@ -124,7 +124,7 @@ HTML_OUTPUT = KERNEL HTML_FILE_EXTENSION = .html HTML_HEADER = sources/myheader.html HTML_FOOTER = sources/footer.html -HTML_STYLESHEET = sources/doxygen.css +HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO CHM_FILE = @@ -134,7 +134,7 @@ BINARY_TOC = YES TOC_EXPAND = YES DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO +GENERATE_TREEVIEW = YES TREEVIEW_WIDTH = 250 #--------------------------------------------------------------------------- diff --git a/doc/salome/tui/Makefile.am b/doc/salome/tui/Makefile.am index 993af3090..07b894756 100644 --- a/doc/salome/tui/Makefile.am +++ b/doc/salome/tui/Makefile.am @@ -49,9 +49,9 @@ usr_docs: $(DOXYGEN) ./doxyuser1; \ cd ..; $(INSTALL) -d $(docdir)/tui/KERNEL; - cp -fr KERNEL $(docdir)/tui cp -fr $(srcdir)/KERNEL/sources/static/*.* $(docdir)/tui/KERNEL; cp -fr $(srcdir)/KERNEL/sources/ $(docdir)/tui/KERNEL; + cp -fr KERNEL $(docdir)/tui cp -fr $(srcdir)/KERNEL/HTML/ $(docdir)/tui/KERNEL; cp -f $(srcdir)/pythfilter.py $(docdir)/tui/KERNEL; cp -fr $(srcdir)/KERNEL/exemple/ $(docdir)/tui/KERNEL; diff --git a/idl/DSC_Engines.idl b/idl/DSC_Engines.idl index 9ace69068..83b558a59 100644 --- a/idl/DSC_Engines.idl +++ b/idl/DSC_Engines.idl @@ -370,7 +370,7 @@ module Engines { This interface defines the operations needed to add a paco++ port into a parallel DSC component. */ - interface Parallel_DSC : Engines::DSC { + interface Parallel_DSC : Engines::Superv_Component, Engines::Parallel_Component { /*! This operation gives the proxy node of a paco++ port to all the nodes. @@ -385,17 +385,8 @@ module Engines { void set_paco_proxy(in Object ref, in string provides_port_name, in Ports::PortProperties port_prop); - - /*! - The SUPERV module call this method before starting the service. Thus the service - can add is dynamics ports before is started. - - \param service_name service's name. - \return true if the service is correctly initialised. - */ - boolean init_service(in string service_name); - }; + }; }; #endif diff --git a/idl/DSC_Engines.xml b/idl/DSC_Engines.xml index 5db294c08..a4d5603b6 100644 --- a/idl/DSC_Engines.xml +++ b/idl/DSC_Engines.xml @@ -46,6 +46,9 @@ set_paco_proxy distributed + + + Superv_Component init_service distributed diff --git a/idl/Makefile.am b/idl/Makefile.am index 8ddeafd24..70837010e 100644 --- a/idl/Makefile.am +++ b/idl/Makefile.am @@ -119,22 +119,33 @@ IDL_SOURCES += $(DYNIDL_SOURCES) salomeinclude_DATA= $(STATIDL_SOURCES:%SK.cc=%.hh) if WITH_PACO_PARALLEL -PAR = SALOME_ComponentPaCO.h SALOME_ComponentPaCO.cc \ +PAR = SALOME_ExceptionPaCO.h SALOME_ExceptionPaCO.cc \ + SALOME_ComponentPaCO.h SALOME_ComponentPaCO.cc \ SALOME_PortsPaCO.h SALOME_PortsPaCO.cc \ DSC_EnginesPaCO.h DSC_EnginesPaCO.cc PAR_LIB = libSalomeParallelIDLKernel.la -IDL_PACO = SALOME_ComponentPaCO.idl SALOME_PortsPaCO.idl DSC_EnginesPaCO.idl +IDL_PACO = SALOME_ExceptionPaCO.idl SALOME_ComponentPaCO.idl SALOME_PortsPaCO.idl DSC_EnginesPaCO.idl GEN_PACO = SALOME_ComponentPaCO_Engines_Container_server.cc \ SALOME_ComponentPaCO_Engines_Container_client.cc \ SALOME_ComponentPaCO_Engines_Component_server.cc \ SALOME_ComponentPaCO_Engines_Component_client.cc \ + SALOME_ComponentPaCO_Engines_Parallel_Component_server.cc \ + SALOME_ComponentPaCO_Engines_Parallel_Component_client.cc \ + SALOME_ComponentPaCO_Engines_fileTransfer_server.cc \ + SALOME_ComponentPaCO_Engines_fileTransfer_client.cc \ + SALOME_ComponentPaCO_Engines_Salome_file_server.cc \ + SALOME_ComponentPaCO_Engines_Salome_file_client.cc \ + SALOME_ComponentPaCO_Engines_Parallel_Salome_file_server.cc \ + SALOME_ComponentPaCO_Engines_Parallel_Salome_file_client.cc \ SALOME_PortsPaCO_Ports_Port_server.cc \ SALOME_PortsPaCO_Ports_Port_client.cc \ DSC_EnginesPaCO_Engines_DSC_server.cc \ DSC_EnginesPaCO_Engines_DSC_client.cc \ + DSC_EnginesPaCO_Engines_Superv_Component_server.cc \ + DSC_EnginesPaCO_Engines_Superv_Component_client.cc \ DSC_EnginesPaCO_Engines_Parallel_DSC_server.cc \ DSC_EnginesPaCO_Engines_Parallel_DSC_client.cc @@ -142,7 +153,17 @@ INCLUDES_PACO = SALOME_ComponentPaCO_Engines_Container_server.h \ SALOME_ComponentPaCO_Engines_Container_client.h \ SALOME_ComponentPaCO_Engines_Component_server.h \ SALOME_ComponentPaCO_Engines_Component_client.h \ + SALOME_ComponentPaCO_Engines_Parallel_Component_server.h \ + SALOME_ComponentPaCO_Engines_Parallel_Component_client.h \ + SALOME_ComponentPaCO_Engines_fileTransfer_server.h \ + SALOME_ComponentPaCO_Engines_fileTransfer_client.h \ + SALOME_ComponentPaCO_Engines_Salome_file_server.h \ + SALOME_ComponentPaCO_Engines_Salome_file_client.h \ + SALOME_ComponentPaCO_Engines_Parallel_Salome_file_server.h \ + SALOME_ComponentPaCO_Engines_Parallel_Salome_file_client.h \ + SALOME_ExceptionPaCO.h \ SALOME_ComponentPaCO.h \ + SALOME_Exception.h \ SALOME_Component.h \ SALOME_PortsPaCO_Ports_Port_server.h \ SALOME_PortsPaCO_Ports_Port_client.h \ @@ -150,12 +171,14 @@ INCLUDES_PACO = SALOME_ComponentPaCO_Engines_Container_server.h \ SALOME_Ports.h \ DSC_EnginesPaCO_Engines_DSC_server.h \ DSC_EnginesPaCO_Engines_DSC_client.h \ + DSC_EnginesPaCO_Engines_Superv_Component_server.h \ + DSC_EnginesPaCO_Engines_Superv_Component_client.h \ DSC_EnginesPaCO_Engines_Parallel_DSC_server.h \ DSC_EnginesPaCO_Engines_Parallel_DSC_client.h \ DSC_EnginesPaCO.h \ DSC_Engines.h -XML = SALOME_Component.xml DSC_Engines.xml SALOME_Ports.xml +XML = SALOME_Exception.xml SALOME_Component.xml DSC_Engines.xml SALOME_Ports.xml endif idldir = $(prefix)/idl/salome @@ -164,6 +187,7 @@ nodist_salomeinclude_HEADERS = ${INCLUDES_PACO} BUILT_SOURCES = $(IDL_SOURCES) $(PAR) +SALOME_ExceptionPaCO.h SALOME_ExceptionPaCO.cc : SALOME_Exception.idl SALOME_Exception.xml SALOME_ComponentPaCO.h SALOME_ComponentPaCO.cc : SALOME_Component.idl SALOME_Component.xml SALOME_PortsPaCO.h SALOME_PortsPaCO.cc : SALOME_Ports.idl SALOME_Ports.xml DSC_EnginesPaCO.h DSC_EnginesPaCO.cc : DSC_Engines.idl DSC_Engines.xml diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index d750af377..08aea29fc 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -26,6 +26,8 @@ #ifndef _SALOME_COMPONENT_IDL_ #define _SALOME_COMPONENT_IDL_ +#include "SALOME_Exception.idl" + /*! \brief This is a package of interfaces used for connecting new components to %SALOME application. It also contains a set of interfaces used for management of %MED @@ -53,6 +55,7 @@ module Engines interface Component ; interface fileRef ; interface fileTransfer ; + interface Salome_file; /*! \brief Interface of the %Container. This interface defines the process of loading and registration @@ -159,6 +162,16 @@ module Engines */ fileRef createFileRef(in string origFileName); + /*! + returns a Salome_file object if origFileName exists and is readable + else returns null object. + + \param origFileName name of the file to be managed (can contain the path). + + \return Salome_file CORBA reference. + */ + Salome_file createSalome_file(in string origFileName); + /*! returns a fileTransfer object used to copy files from the container machine to the clients machines. Only one fileTransfer instance is @@ -168,8 +181,6 @@ module Engines }; - - /*! \brief Interface of the %component. This interface is used for interaction between the %container and the %component and between the components inside the container. @@ -275,10 +286,104 @@ module Engines */ TMPFile DumpPython(in Object theStudy, in boolean isPublished, - out boolean isValidScript); + out boolean isValidScript); + + + /*! + Returns a CORBA Ref of a input Salome_file managed by a service. + + \param service_name service's name. + \param file_name name of the requested file. + + \return CORBA Ref of the requested file. + + \exception contains informations of what if the component cannot + sends the file's reference. + */ + Engines::Salome_file getInputFileToService(in string service_name, + in string Salome_file_name) raises(SALOME::SALOME_Exception); + + /*! + This method is used before the activation of the service. It calls + recvFiles() on all the input Salome_file files of the service. + + Before each recvFiles(), it uses the callback method named configureSalome_file. + This method allows the user to configure the files managed by the Salome_file. + + By default, there is no files managed when a Salome_file is created, + but the supervisor set some files managed by the Salome_file from the information contained + into the schema file. + + \param service_name service's name. + + \exception contains informations about files that are not in a good state. + */ + void checkInputFilesToService(in string service_name) raises(SALOME::SALOME_Exception); + + /*! + This method adds a input Salome_file to a service of the component. + + \param service_name service's name. + \param Salome_file_name name of the Salome_file + + \return a reference of the Salome_file + + \exception raises an exception if there is already + a Salome_file with this name for the service. + */ + Engines::Salome_file setInputFileToService(in string service_name, + in string Salome_file_name) raises(SALOME::SALOME_Exception); + + /*! + Returns a CORBA Ref of a output Salome_file managed by a service. + + \param service_name service's name. + \param file_name name of the requested file. + + \return CORBA Ref of the requested file. + + \exception contains informations of what if the component cannot + sends the file's reference. + */ + Engines::Salome_file getOutputFileToService(in string service_name, + in string Salome_file_name) raises(SALOME::SALOME_Exception); + + /*! + This method is used at the end of the service. It calls + recvFiles() on all the output Salome_file files of the service. + + Before each recvFiles(), it uses the callback method named configureSalome_file. + This method allows the user to configure the files managed by the Salome_file. + + By default, there is no files managed when a Salome_file is created, + but the supervisor set some files managed by the Salome_file from the information contained + into the schema file. + + \param service_name service's name. + + \exception contains informations about files that are not in a good state. + */ + void checkOutputFilesToService(in string service_name) raises(SALOME::SALOME_Exception); + /*! + This method adds an output Salome_file to a service of the component. + + \param service_name service's name. + \param Salome_file_name name of the Salome_file + + \return a reference of the Salome_file + + \exception raises an exception if there is already + a Salome_file with this name for the service. + */ + Engines::Salome_file setOutputFileToService(in string service_name, + in string Salome_file_name) raises(SALOME::SALOME_Exception); } ; + interface Parallel_Component : Engines::Component { + void send_parallel_proxy_object(in Object proxy_ref); + }; + /*! A block of binary data used for file transfer. The maximum size of the block is defined on server side. @@ -314,7 +419,187 @@ module Engines fileBlock getBlock(in long fileId); }; - /*! \brief Interface of fileTransfer. + /*! + This is a file managed by a Salome_file. It contains file's name, path and status. + The status is : "present" or "notpresent". + */ + struct file { + string file_name; + string path; + string type; + string source_file_name; + string status; + long node; + Engines::Container container; + }; + + /*! + A sequence of Engines::file. + */ + typedef sequence files; + + + /*! + It is the state of a Salome_file. It contains the Salome_file's name, the name + of the hdf5 file where it can be saved, the number of files managed and the information + if all the files are received. + */ + struct SfState { + string name; + string hdf5_file_name; + long number_of_files; + boolean files_ok; + }; + + /*! \brief Interface of a Salome_file managed + This file is independent of a Salome module. It can managed one or more + real files. It's useful for parallel files. Currently Salome_file cannot manage + two files that have the same name but not the same path. + */ + interface Salome_file : Engines::fileTransfer + { + /*! + Load a Salome_file from a hdf5 file. + + \param hdf5_file name (with path) of the hdf5_file. + + \exception contains informations of errors if the loading doesn't succeed. + */ + void load(in string hdf5_file) raises (SALOME::SALOME_Exception); + + /*! + Save a Salome_file into a hdf5_file. + + \param hdf5_file name (with path) of the hdf5_file. + + \exception contains informations of errors if the save doesn't succeed. + + */ + void save(in string hdf5_file) raises (SALOME::SALOME_Exception); + + /*! + Save a Salome_file into a hdf5_file. All files that are managed + are saved into the hdf5_file + + \param hdf5_file name (with path) of the hdf5_file. + + \exception contains informations of errors if the save doesn't succeed. + + */ + void save_all(in string hdf5_file) raises (SALOME::SALOME_Exception); + +/**************/ + + /*! + Add a Local file to the Salome_file. + + \param file_name name of the file with the path. + + \exception raised if the file is already added into the Salome_file. + */ + void setLocalFile(in string comp_file_name) raises (SALOME::SALOME_Exception); + + /*! + Add a Distributed file to the Salome_file. + + \param comp_file_name name of the file with the path. + + \exception raised if the file is already added into the Salome_file. + */ + void setDistributedFile(in string comp_file_name) raises (SALOME::SALOME_Exception); + + /*! + Connect a Salome_file with another Salome_file. + It works only if the Salome_file managed only one file + + \param source_Salome_file Salome_file that managed the distributed version of the file. + + \exception raised if there is more or less than one file. + */ + void connect(in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception); + + /*! + Connect the managed file file_name to a Salome_file. + + \param file_name name of the file without the path. + \param source_Salome_file Salome_file that managed the distributed version of the file. + + \exception raised if the file doesn't exist. + */ + void connectDistributedFile(in string file_name, + in Engines::Salome_file source_Salome_file) raises (SALOME::SALOME_Exception); + + /*! + Connect the file_name with a Distributed file_name. + + \param file_name name of the file without the path. + \param source_file_name It's the name of the file managed by the distributed source Salome_file. + + \exception raised if the file doesn't exist. + */ + void setDistributedSourceFile(in string file_name, + in string source_file_name) raises (SALOME::SALOME_Exception); + +/**************/ + + /*! + Get all the distributed files managed by the Salome_file and + check all the local files. + + \exception raised if some of the files are not ok. + */ + void recvFiles() raises (SALOME::SALOME_Exception) ; + +/**************/ + + /*! + Remove a file of the Salome_file. + + \param file_name name of the file. + + \exception raised if the file doesn't exist. + */ + void removeFile(in string file_name) raises (SALOME::SALOME_Exception); + + /*! + Remove all the files of the Salome_file. + */ + void removeFiles(); + +/**************/ + + /*! + Get the list of the files managed by the Salome_file. + The list can be empty. + */ + Engines::files getFilesInfos(); + + /*! + Get a file managed by the Salome_file. + + \param file_name the name of the file. + + \return CORBA file reference. + + \exception raised if the file doesn't exist. + */ + Engines::file getFileInfos(in string file_name) raises (SALOME::SALOME_Exception); + + /*! + Return the state of the Salome_file. + */ + Engines::SfState getSalome_fileState(); + + + /*! + Set the container where files are. + + \param container container CORBA's reference. + */ + void setContainer(in Engines::Container container); + }; + + /*! \brief Interface of fileRef. The fileTransfer and fileRef interfaces provide a file transfer service between different computers. @@ -344,6 +629,49 @@ module Engines string getRef(in string machine); }; -} ; + /*! \brief Interface of a Parallel_Salome_file + This interface is used by parallel components and containers. + It adds methods to enable to choose on which node of the parallel component the file has to + be received. + */ + interface Parallel_Salome_file : Engines::Salome_file { + + /*! + Set a number of node for the file. Default is the node 0. + + \param file_name name of the file. + \param node_nbr node number where the file is. + + \exception raised if the file doesn't exist. + */ + void setFileNode(in string file_name, in long node_nbr) raises (SALOME::SALOME_Exception); + + /*! + Get the number of the node that actually managed the file. + + \param file_name name of managed file. + + \return node number of the file + + \exception raised if the file doesn't exist. + */ + long getFileNode(in string file_name) raises (SALOME::SALOME_Exception); + + /*! + This method update the state of file for the Parallel_Salome_file. + + \param new_file the new state of file. + */ + Engines::Container updateFile(in Engines::file new_file); + + /*! + This method is used by the parallel implementation of recvFiles. + + \exception raised if the file cannot be ok. + */ + void recvFiles_node() raises (SALOME::SALOME_Exception); + + }; +}; #endif diff --git a/idl/SALOME_Component.xml b/idl/SALOME_Component.xml index 22b783fc2..2b65d9058 100644 --- a/idl/SALOME_Component.xml +++ b/idl/SALOME_Component.xml @@ -47,9 +47,26 @@ Component - ping + setInputFileToService + distributed + + + setOutputFileToService distributed + + Parallel_Component + + send_parallel_proxy_object + distributed + + + + Salome_file + + + Parallel_Salome_file + diff --git a/idl/SALOME_Exception.xml b/idl/SALOME_Exception.xml new file mode 100644 index 000000000..33d565323 --- /dev/null +++ b/idl/SALOME_Exception.xml @@ -0,0 +1,31 @@ + + + + + + diff --git a/salome_adm/unix/config_files/Makefile.am b/salome_adm/unix/config_files/Makefile.am index f812d9293..2cd5f15ce 100644 --- a/salome_adm/unix/config_files/Makefile.am +++ b/salome_adm/unix/config_files/Makefile.am @@ -68,6 +68,7 @@ check_htmlgen.m4 \ check_lam.m4 \ check_lsf.m4 \ check_mpi.m4 \ +check_openmpi.m4 \ check_mpich.m4 \ check_omniorb.m4 \ check_opengl.m4 \ diff --git a/salome_adm/unix/config_files/check_htmlgen.m4 b/salome_adm/unix/config_files/check_htmlgen.m4 index 8e42b102e..ec51ec269 100644 --- a/salome_adm/unix/config_files/check_htmlgen.m4 +++ b/salome_adm/unix/config_files/check_htmlgen.m4 @@ -41,7 +41,7 @@ then DOXYGEN_WITH_PYTHON=yes DOXYGEN_WITH_STL=yes ;; - [1-9].[5-9]*) + [[1-9]].[[5-9]]*) DOXYGEN_WITH_PYTHON=yes DOXYGEN_WITH_STL=yes ;; diff --git a/salome_adm/unix/config_files/check_mpi.m4 b/salome_adm/unix/config_files/check_mpi.m4 index 57b796b72..69c0ed854 100644 --- a/salome_adm/unix/config_files/check_mpi.m4 +++ b/salome_adm/unix/config_files/check_mpi.m4 @@ -96,6 +96,17 @@ dnl fi + if test "$WITHLAM" = no; then +dnl +dnl --------------------------------------------- +dnl testing OPENMPI +dnl --------------------------------------------- +dnl + + CHECK_OPENMPI + + fi + fi if test x$WITHMPI2 = xyes; then diff --git a/salome_adm/unix/config_files/check_openmpi.m4 b/salome_adm/unix/config_files/check_openmpi.m4 new file mode 100644 index 000000000..24673dde6 --- /dev/null +++ b/salome_adm/unix/config_files/check_openmpi.m4 @@ -0,0 +1,56 @@ +dnl Copyright (C) 2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +dnl +dnl +dnl + +AC_DEFUN([CHECK_OPENMPI],[ +AC_ARG_WITH(openmpi, + AC_HELP_STRING([--with-openmpi],[root directory path of openmpi installation]), + WITHOPENMPI="yes",WITHOPENMPI="no") + +MPI_INCLUDES="" +MPI_LIBS="" +mpi_ok=no + +if test "$WITHOPENMPI" = yes; then + + OPENMPI_HOME=$withval + + if test "$OPENMPI_HOME"; then + MPI_INCLUDES=`$OPENMPI_HOME/bin/mpicxx --showme:compile` + MPI_LIBS=`$OPENMPI_HOME/bin/mpicxx --showme:link` + fi + + CPPFLAGS_old="$CPPFLAGS" + CPPFLAGS="$MPI_INCLUDES $CPPFLAGS" + AC_CHECK_HEADER(mpi.h,WITHOPENMPI="yes",WITHOPENMPI="no") + CPPFLAGS="$CPPFLAGS_old" + + AC_MSG_CHECKING(for openmpi) + if test "$WITHOPENMPI" = "yes";then + mpi_ok=yes + AC_MSG_RESULT(yes) + else + mpi_ok=no + AC_MSG_RESULT(no) + fi +fi +])dnl + diff --git a/salome_adm/unix/config_files/production.m4 b/salome_adm/unix/config_files/production.m4 index e4a61870b..1d2b1b0a5 100644 --- a/salome_adm/unix/config_files/production.m4 +++ b/salome_adm/unix/config_files/production.m4 @@ -28,30 +28,20 @@ dnl version $Id$ dnl author Patrick GOLDBRONN dnl -# AC_ENABLE_PRODUCTION -AC_DEFUN([AC_ENABLE_PRODUCTION], [dnl -define([AC_ENABLE_PRODUCTION_DEFAULT], ifelse($1, no, no, yes))dnl -AC_ARG_ENABLE(production, -changequote(<<, >>)dnl -<< --enable-production[=PKGS] build without debug information [default=>>AC_ENABLE_PRODUCTION_DEFAULT], -changequote([, ])dnl -[p=${PACKAGE-default} -case "$enableval" in -yes) enable_production=yes ;; -no) enable_production=no ;; -*) - enable_production=no - # Look at the argument we got. We use all the common list separators. - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," - for pkg in $enableval; do - if test "X$pkg" = "X$p"; then - enable_production=yes - fi - done - IFS="$ac_save_ifs" - ;; -esac], -enable_production=AC_ENABLE_PRODUCTION_DEFAULT)dnl +dnl AC_ENABLE_PRODUCTION +dnl +dnl This macro enables production build : optimized + no debugging information (-g) +dnl default = not enabled +dnl +AC_DEFUN([AC_ENABLE_PRODUCTION], +[define([AC_ENABLE_PRODUCTION_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([production], + [AC_HELP_STRING([--enable-production], + [compile in optimized mode @<:@default=]AC_ENABLE_PRODUCTION_DEFAULT[@:>@])], + [ + enable_production=$enableval + ], + [enable_production=]AC_ENABLE_PRODUCTION_DEFAULT) AC_CXX_OPTION(-Wno-deprecated,CXXFLAGS) AC_CXX_OPTION(-Wparentheses,CXXFLAGS) @@ -65,36 +55,29 @@ if test "X$enable_production" = "Xyes"; then CFLAGS="$CFLAGS -O" AC_CXX_OPTION(-Wuninitialized,CXXFLAGS) CXXFLAGS="$CXXFLAGS -O " +else + CFLAGS="$CFLAGS -O -g" + CXXFLAGS="$CXXFLAGS -O -g" fi ]) # AC_DISABLE_PRODUCTION - set the default flag to --disable-production AC_DEFUN([AC_DISABLE_PRODUCTION], [AC_ENABLE_PRODUCTION(no)]) -# AC_ENABLE_DEBUG -AC_DEFUN([AC_ENABLE_DEBUG], [dnl -define([AC_ENABLE_DEBUG_DEFAULT], ifelse($1, no, no, yes))dnl -AC_ARG_ENABLE(debug, -changequote(<<, >>)dnl -<< --enable-debug[=PKGS] build without debug information [default=>>AC_ENABLE_DEBUG_DEFAULT], -changequote([, ])dnl -[p=${PACKAGE-default} -case "$enableval" in -yes) enable_debug=yes ;; -no) enable_debug=no ;; -*) - enable_debug=no - # Look at the argument we got. We use all the common list separators. - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," - for pkg in $enableval; do - if test "X$pkg" = "X$p"; then - enable_debug=yes - fi - done - IFS="$ac_save_ifs" - ;; -esac], -enable_debug=AC_ENABLE_DEBUG_DEFAULT)dnl +dnl AC_ENABLE_DEBUG +dnl +dnl This macro enables debugging build : debug + trace +dnl default = not enabled +dnl +AC_DEFUN([AC_ENABLE_DEBUG], + [define([AC_ENABLE_DEBUG_DEFAULT], ifelse($1, no, no, yes))dnl + AC_ARG_ENABLE([debug], + [AC_HELP_STRING([--enable-debug], + [build with debug and trace information @<:@default=]AC_ENABLE_DEBUG_DEFAULT[@:>@])], + [ + enable_debug=$enableval + ], + [enable_debug=]AC_ENABLE_DEBUG_DEFAULT) if test "X$enable_debug" = "Xyes"; then CFLAGS="$CFLAGS -g -D_DEBUG_ " diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 0efb11a82..af8380f8c 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -646,7 +646,8 @@ void Engines_Component_i::beginService(const char *serviceName) (*it).second >>= value; // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC. #if defined __GNUC__ - int ret = setenv(cle.c_str(), value, overwrite); +// int ret = setenv(cle.c_str(), value, overwrite); + setenv(cle.c_str(), value, overwrite); #else //CCRT porting : setenv not defined in stdlib.h std::string s(cle); @@ -654,7 +655,8 @@ void Engines_Component_i::beginService(const char *serviceName) s+=value; // char* cast because 1st arg of linux putenv function // is not a const char* ! - int ret=putenv((char *)s.c_str()); +// int ret=putenv((char *)s.c_str()); + putenv((char *)s.c_str()); //End of CCRT porting #endif MESSAGE("--- setenv: "<find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +Engines::Salome_file_ptr +Engines_Component_i::setInputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Input_Service_file_map.find(service_name); + if (_Service_file_map_it == _Input_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Input_Service_file_map[service_name] = _map; + } + _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + Salome_file_i * Sfile = new Salome_file_i(); + Engines::Container_ptr container = this->GetContainerRef(); + Sfile->setContainer(Engines::Container::_duplicate(container)); + (*_map)[Salome_file_name] = Sfile; + } + + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + return Sfile->_this(); +} + +void +Engines_Component_i::checkInputFilesToService(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Service_file_map_it = _Input_Service_file_map.find(service_name); + if (_Service_file_map_it != _Input_Service_file_map.end()) { + _t_Salome_file_map * _map = _Input_Service_file_map[service_name]; + _t_Salome_file_map::iterator begin = _map->begin(); + _t_Salome_file_map::iterator end = _map->end(); + + for(;begin!=end;begin++) { + Salome_file_i * file = begin->second; + std::string file_port_name = begin->first; + configureSalome_file(service_name, file_port_name, file); + file->recvFiles(); + } + } +} + +Engines::Salome_file_ptr +Engines_Component_i::getOutputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we throw an exception. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + + return Sfile->_this(); +} + +Engines::Salome_file_ptr +Engines_Component_i::setOutputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Output_Service_file_map[service_name] = _map; + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + Salome_file_i * Sfile = new Salome_file_i(); + Engines::Container_ptr container = this->GetContainerRef(); + Sfile->setContainer(Engines::Container::_duplicate(container)); + (*_map)[Salome_file_name] = Sfile; + } + + Salome_file_i * Sfile = (*_map)[Salome_file_name]; + return Sfile->_this(); +} + +void +Engines_Component_i::checkOutputFilesToService(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it != _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + _t_Salome_file_map::iterator begin = _map->begin(); + _t_Salome_file_map::iterator end = _map->end(); + + for(;begin!=end;begin++) { + Salome_file_i * file = begin->second; + std::string file_port_name = begin->first; + configureSalome_file(service_name, file_port_name, file); + file->recvFiles(); + } + } + +} + +//============================================================================= +/*! + * C++ method: used to configure the Salome_file into the runtime. + * \param service_name name of the service that use this Salome_file + * \param file_port_name name of the Salome_file + * \param file Salome_file C++ object + */ +//============================================================================= +void +Engines_Component_i::configureSalome_file(std::string service_name, + std::string file_port_name, + Salome_file_i * file) +{ + // By default this method does nothing +} + diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 412b79b50..0c4928a9b 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -44,6 +44,7 @@ int SIGUSR1 = 1000; #include //#ifndef WNT #include CORBA_SERVER_HEADER(SALOME_Component) +#include CORBA_SERVER_HEADER(SALOME_Exception) //#else //#include //#endif @@ -52,6 +53,7 @@ int SIGUSR1 = 1000; #include "SALOME_Component_i.hxx" #include "SALOME_FileRef_i.hxx" #include "SALOME_FileTransfer_i.hxx" +#include "Salome_file_i.hxx" #include "SALOME_NamingService.hxx" #include "OpUtil.hxx" @@ -101,12 +103,12 @@ Engines_Container_i::Engines_Container_i () : //============================================================================= Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, - PortableServer::POA_var poa, - char *containerName , + PortableServer::POA_var poa, + char *containerName , int argc , char* argv[], - bool activAndRegist, - bool isServantAloneInProcess - ) : + bool activAndRegist, + bool isServantAloneInProcess + ) : _numInstance(0),_isServantAloneInProcess(isServantAloneInProcess) { _pid = (long)getpid(); @@ -120,11 +122,11 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, string hostname = GetHostname(); #ifndef WNT MESSAGE(hostname << " " << getpid() << - " Engines_Container_i starting argc " << + " Engines_Container_i starting argc " << _argc << " Thread " << pthread_self() ) ; #else MESSAGE(hostname << " " << _getpid() << - " Engines_Container_i starting argc " << _argc<< " Thread " << pthread_self().p ) ; + " Engines_Container_i starting argc " << _argc<< " Thread " << pthread_self().p ) ; #endif int i = 0 ; @@ -162,14 +164,14 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, _NS->init_orb( CORBA::ORB::_duplicate(_orb) ) ; CORBA::Object_var obj=_poa->id_to_reference(*_id); Engines::Container_var pCont - = Engines::Container::_narrow(obj); + = Engines::Container::_narrow(obj); _containerName = _NS->BuildContainerNameForNS(containerName, - hostname.c_str()); + hostname.c_str()); SCRUTE(_containerName); _NS->Register(pCont, _containerName.c_str()); MESSAGE("Engines_Container_i::Engines_Container_i : Container name " - << _containerName); + << _containerName); // Python: // import SALOME_Container @@ -183,37 +185,28 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, SCRUTE(myCommand); if (!_isSupervContainer) - { + { #ifdef WNT -// //Py_ACQUIRE_NEW_THREAD; -// PyEval_AcquireLock(); -// /* It should not be possible for more than one thread state -// to be used for a thread.*/ -// PyThreadState *myTstate = PyGILState_GetThisThreadState(); -// // if no thread state defined -// if ( !myTstate ) -// myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); -// PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); - - PyEval_AcquireLock(); - PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); - PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); + + PyEval_AcquireLock(); + PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); + PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); #else - Py_ACQUIRE_NEW_THREAD; + Py_ACQUIRE_NEW_THREAD; #endif #ifdef WNT - // mpv: this is temporary solution: there is a unregular crash if not - //Sleep(2000); - // + // mpv: this is temporary solution: there is a unregular crash if not + //Sleep(2000); + // // first element is the path to Registry.dll, but it's wrong - PyRun_SimpleString("import sys\n"); - PyRun_SimpleString("sys.path = sys.path[1:]\n"); + PyRun_SimpleString("import sys\n"); + PyRun_SimpleString("sys.path = sys.path[1:]\n"); #endif - PyRun_SimpleString("import SALOME_Container\n"); - PyRun_SimpleString((char*)myCommand.c_str()); - Py_RELEASE_NEW_THREAD; - } + PyRun_SimpleString("import SALOME_Container\n"); + PyRun_SimpleString((char*)myCommand.c_str()); + Py_RELEASE_NEW_THREAD; + } fileTransfer_i* aFileTransfer = new fileTransfer_i(); _fileTransfer = Engines::fileTransfer::_narrow(aFileTransfer->_this()); @@ -389,20 +382,20 @@ Engines_Container_i::load_component_Library(const char* componentName) PyObject *globals = PyModule_GetDict(mainmod); PyObject *pyCont = PyDict_GetItemString(globals, "pyCont"); PyObject *result = PyObject_CallMethod(pyCont, - "import_component", - "s",componentName); + "import_component", + "s",componentName); int ret= PyInt_AsLong(result); SCRUTE(ret); Py_RELEASE_NEW_THREAD; if (ret) // import possible: Python component - { - _numInstanceMutex.lock() ; // lock to be alone (stl container write) - _library_map[aCompName] = (void *)pyCont; // any non O value OK - _numInstanceMutex.unlock() ; - MESSAGE("import Python: "<string_to_object(iors.c_str()); - iobject = Engines::Component::_narrow( obj ) ; + CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); + iobject = Engines::Component::_narrow( obj ) ; } return iobject._retn(); } @@ -488,8 +481,8 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, else { iobject = createInstance(genericRegisterName, - handle, - studyId); + handle, + studyId); return iobject._retn(); } } @@ -507,7 +500,7 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName, Engines::Component_ptr Engines_Container_i::find_component_instance( const char* registeredName, - CORBA::Long studyId) + CORBA::Long studyId) { Engines::Component_var anEngine = Engines::Component::_nil(); map::iterator itm =_listInstances_map.begin(); @@ -516,13 +509,13 @@ Engines_Container_i::find_component_instance( const char* registeredName, string instance = (*itm).first; SCRUTE(instance); if (instance.find(registeredName) == 0) - { - anEngine = (*itm).second; - if (studyId == anEngine->getStudyId()) - { - return anEngine._retn(); - } - } + { + anEngine = (*itm).second; + if (studyId == anEngine->getStudyId()) + { + return anEngine._retn(); + } + } itm++; } return anEngine._retn(); @@ -544,7 +537,7 @@ Engines_Container_i::find_component_instance( const char* registeredName, Engines::Component_ptr Engines_Container_i::load_impl( const char* genericRegisterName, - const char* componentName ) + const char* componentName ) { string impl_name = string ("lib") + genericRegisterName +string("Engine.so"); Engines::Component_var iobject = Engines::Component::_nil() ; @@ -590,12 +583,12 @@ void Engines_Container_i::finalize_removal() void *handle = (*ith).second; string impl_name= (*ith).first; if (handle) - { - SCRUTE(handle); - SCRUTE(impl_name); -// dlclose(handle); // SALOME unstable after ... -// _library_map.erase(impl_name); - } + { + SCRUTE(handle); + SCRUTE(impl_name); +// dlclose(handle); // SALOME unstable after ... +// _library_map.erase(impl_name); + } } _toRemove_map.clear(); _numInstanceMutex.unlock(); @@ -677,6 +670,36 @@ Engines_Container_i::getFileTransfer() } +Engines::Salome_file_ptr +Engines_Container_i::createSalome_file(const char* origFileName) +{ + string origName(origFileName); + if (CORBA::is_nil(_Salome_file_map[origName])) + { + Salome_file_i* aSalome_file = new Salome_file_i(); + aSalome_file->setContainer(Engines::Container::_duplicate(this->_this())); + try + { + aSalome_file->setLocalFile(origFileName); + aSalome_file->recvFiles(); + } + catch (const SALOME::SALOME_Exception& e) + { + return Engines::Salome_file::_nil(); + } + + Engines::Salome_file_var theSalome_file = Engines::Salome_file::_nil(); + theSalome_file = Engines::Salome_file::_narrow(aSalome_file->_this()); + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _Salome_file_map[origName] = theSalome_file; + _numInstanceMutex.unlock() ; + } + + Engines::Salome_file_ptr theSalome_file = + Engines::Salome_file::_duplicate(_Salome_file_map[origName]); + ASSERT(!CORBA::is_nil(theSalome_file)); + return theSalome_file; +} //============================================================================= /*! * C++ method: Finds an already existing servant instance of a component, or @@ -702,7 +725,7 @@ Engines_Container_i::getFileTransfer() Engines::Component_ptr Engines_Container_i::find_or_create_instance(string genericRegisterName, - string componentLibraryName) + string componentLibraryName) { string aGenRegisterName = genericRegisterName; string impl_name = componentLibraryName; @@ -717,44 +740,44 @@ Engines_Container_i::find_or_create_instance(string genericRegisterName, // --- find a registered instance in naming service, or create string component_registerBase = - _containerName + "/" + aGenRegisterName; + _containerName + "/" + aGenRegisterName; Engines::Component_var iobject = Engines::Component::_nil() ; try - { - CORBA::Object_var obj = - _NS->ResolveFirst( component_registerBase.c_str()); - if ( CORBA::is_nil( obj ) ) - { - iobject = createInstance(genericRegisterName, - handle, - 0); // force multiStudy instance here ! - } - else - { - iobject = Engines::Component::_narrow( obj ) ; - Engines_Component_i *servant = - dynamic_cast - (_poa->reference_to_servant(iobject)); - ASSERT(servant) - int studyId = servant->getStudyId(); - ASSERT (studyId >= 0); - if (studyId == 0) // multiStudy instance, OK - { - // No ReBind ! - MESSAGE(component_registerBase.c_str()<<" already bound"); - } - else // monoStudy instance: NOK - { - iobject = Engines::Component::_nil(); - INFOS("load_impl & find_component_instance methods " - << "NOT SUITABLE for mono study components"); - } - } - } + { + CORBA::Object_var obj = + _NS->ResolveFirst( component_registerBase.c_str()); + if ( CORBA::is_nil( obj ) ) + { + iobject = createInstance(genericRegisterName, + handle, + 0); // force multiStudy instance here ! + } + else + { + iobject = Engines::Component::_narrow( obj ) ; + Engines_Component_i *servant = + dynamic_cast + (_poa->reference_to_servant(iobject)); + ASSERT(servant) + int studyId = servant->getStudyId(); + ASSERT (studyId >= 0); + if (studyId == 0) // multiStudy instance, OK + { + // No ReBind ! + MESSAGE(component_registerBase.c_str()<<" already bound"); + } + else // monoStudy instance: NOK + { + iobject = Engines::Component::_nil(); + INFOS("load_impl & find_component_instance methods " + << "NOT SUITABLE for mono study components"); + } + } + } catch (...) - { - INFOS( "Container_i::load_impl catched" ) ; - } + { + INFOS( "Container_i::load_impl catched" ) ; + } return iobject._retn(); } } @@ -782,8 +805,8 @@ Engines_Container_i::find_or_create_instance(string genericRegisterName, Engines::Component_ptr Engines_Container_i::createInstance(string genericRegisterName, - void *handle, - int studyId) + void *handle, + int studyId) { // --- find the factory @@ -828,15 +851,15 @@ Engines_Container_i::createInstance(string genericRegisterName, sprintf( aNumI , "%d" , numInstance ) ; string instanceName = aGenRegisterName + "_inst_" + aNumI ; string component_registerName = - _containerName + "/" + instanceName; + _containerName + "/" + instanceName; // --- Instanciate required CORBA object PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(), - aGenRegisterName.c_str() ) ; + aGenRegisterName.c_str() ) ; if (id == NULL) - return iobject._retn(); + return iobject._retn(); // --- get reference & servant from id @@ -844,7 +867,7 @@ Engines_Container_i::createInstance(string genericRegisterName, iobject = Engines::Component::_narrow( obj ) ; Engines_Component_i *servant = - dynamic_cast(_poa->reference_to_servant(iobject)); + dynamic_cast(_poa->reference_to_servant(iobject)); ASSERT(servant); //SCRUTE(servant->pd_refCount); servant->_remove_ref(); // compensate previous id_to_reference @@ -890,7 +913,7 @@ void Engines_Container_i::decInstanceCnt(string genericRegisterName) if (_cntInstances_map[aGenRegisterName] == 0) { string impl_name = - Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str()); + Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str()); SCRUTE(impl_name); void* handle = _library_map[impl_name]; ASSERT(handle); @@ -971,8 +994,8 @@ void CallCancelThread() ; #ifndef WNT void SigIntHandler(int what , - siginfo_t * siginfo , - void * toto ) + siginfo_t * siginfo , + void * toto ) { //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers) // use of streams (and so on) should never be used because : @@ -995,25 +1018,25 @@ void SigIntHandler(int what , { ActSigIntHandler() ; if ( siginfo->si_signo == SIGUSR1 ) - { - SetCpuUsed() ; - } + { + SetCpuUsed() ; + } else if ( siginfo->si_signo == SIGUSR2 ) - { - CallCancelThread() ; - } + { + CallCancelThread() ; + } else - { - _Sleeping = true ; - // MESSAGE("SigIntHandler BEGIN sleeping.") ; - int count = 0 ; - while( _Sleeping ) - { - sleep( 1 ) ; - count += 1 ; - } - // MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; - } + { + _Sleeping = true ; + // MESSAGE("SigIntHandler BEGIN sleeping.") ; + int count = 0 ; + while( _Sleeping ) + { + sleep( 1 ) ; + count += 1 ; + } + // MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; + } return ; } } @@ -1035,21 +1058,21 @@ void SigIntHandler( int what ) { ActSigIntHandler() ; if ( what == SIGUSR1 ) - { - SetCpuUsed() ; - } + { + SetCpuUsed() ; + } else - { - _Sleeping = true ; - MESSAGE("SigIntHandler BEGIN sleeping.") ; - int count = 0 ; - while( _Sleeping ) - { - Sleep( 1000 ) ; - count += 1 ; - } - MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; - } + { + _Sleeping = true ; + MESSAGE("SigIntHandler BEGIN sleeping.") ; + int count = 0 ; + while( _Sleeping ) + { + Sleep( 1000 ) ; + count += 1 ; + } + MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ; + } return ; } } diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 4e7c0d619..4c8b65729 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -42,7 +42,8 @@ salomeinclude_HEADERS = \ SALOME_FileRef_i.hxx \ SALOME_ContainerManager.hxx \ Container_init_python.hxx \ - SALOME_Container.hxx + SALOME_Container.hxx \ + Salome_file_i.hxx # Scripts to be installed dist_salomescript_DATA =\ @@ -63,7 +64,6 @@ dist_salomescript_SCRIPTS=\ COMMON_CPPFLAGS=\ @PYTHON_INCLUDES@ \ @MPI_INCLUDES@ \ - @CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \ @QT_MT_INCLUDES@ \ -I$(srcdir)/../Basics \ -I$(srcdir)/../SALOMELocalTrace \ @@ -72,6 +72,7 @@ COMMON_CPPFLAGS=\ -I$(srcdir)/../Registry \ -I$(srcdir)/../Notification \ -I$(srcdir)/../ResourcesManager \ + -I$(srcdir)/../HDFPersist \ -I$(top_builddir)/salome_adm/unix \ -I$(top_builddir)/idl \ @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @@ -85,6 +86,7 @@ COMMON_LIBS =\ ../Utils/libOpUtil.la \ ../SALOMELocalTrace/libSALOMELocalTrace.la \ ../Basics/libSALOMEBasics.la \ + ../HDFPersist/libSalomeHDFPersist.la \ $(top_builddir)/idl/libSalomeIDLKernel.la\ @MPI_LIBS@ \ @CORBA_LIBS@ @@ -103,7 +105,8 @@ libSalomeContainer_la_SOURCES=\ SALOME_FileTransfer_i.cxx \ SALOME_FileRef_i.cxx \ Container_init_python.cxx \ - SALOME_ContainerManager.cxx + SALOME_ContainerManager.cxx \ + Salome_file_i.cxx libSalomeContainer_la_CPPFLAGS =\ $(COMMON_CPPFLAGS) @@ -127,6 +130,8 @@ endif # =============================================================== # bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer +noinst_PROGRAMS = TestSalome_file + SALOME_Container_SOURCES =\ SALOME_Container.cxx \ SALOME_Container_SignalsHandler.cxx @@ -139,6 +144,9 @@ SALOME_Container_LDADD =\ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la +SALOME_Container_LDFLAGS =\ +-Xlinker -export-dynamic + SALOME_ContainerManagerServer_SOURCES =\ SALOME_ContainerManagerServer.cxx @@ -149,3 +157,14 @@ SALOME_ContainerManagerServer_LDADD =\ libSalomeContainer.la \ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la + +TestSalome_file_SOURCES =\ + TestSalome_file.cxx + +TestSalome_file_CPPFLAGS =\ + $(COMMON_CPPFLAGS) + +TestSalome_file_LDADD =\ + libSalomeContainer.la \ + $(COMMON_LIBS) \ + ../Basics/libSALOMEBasics.la diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 3bd3f85d0..de8a42e0e 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -43,6 +43,7 @@ #include #include CORBA_SERVER_HEADER(SALOME_Component) #include "NOTIFICATION.hxx" +#include "Salome_file_i.hxx" class RegistryConnexion; class Engines_Container_i; @@ -95,7 +96,19 @@ public: CORBA::Boolean isPublished, CORBA::Boolean& isValidScript); + // CORBA operations for Salome_file + virtual Engines::Salome_file_ptr getInputFileToService(const char* service_name, + const char* Salome_file_name); + virtual Engines::Salome_file_ptr getOutputFileToService(const char* service_name, + const char* Salome_file_name); + virtual void checkInputFilesToService(const char* service_name); + virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, + const char* Salome_file_name); + + virtual void checkOutputFilesToService(const char* service_name); + virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, + const char* Salome_file_name); // --- local C++ methods PortableServer::ObjectId * getId(); @@ -116,6 +129,11 @@ public: long CpuUsed() ; void CancelThread() ; + virtual void configureSalome_file(std::string service_name, + std::string file_port_name, + Salome_file_i * file); + + protected: int _studyId; // -1: not initialised; 0: multiStudy; >0: study static bool _isMultiStudy; @@ -133,6 +151,16 @@ protected: NOTIFICATION_Supplier* _notifSupplier; std::map_fieldsDict; + // Map Salome_file_name to Salome_file* + typedef std::map _t_Salome_file_map; + // Map Service_name to _Salome_file_map + typedef std::map _t_Service_file_map; + + _t_Service_file_map _Input_Service_file_map; + _t_Service_file_map _Output_Service_file_map; + _t_Service_file_map::iterator _Service_file_map_it; + _t_Salome_file_map::iterator _Salome_file_map_it; + std::string _serviceName ; std::string _graphName ; std::string _nodeName ; diff --git a/src/Container/SALOME_Container.cxx b/src/Container/SALOME_Container.cxx index ab3e599a7..9a8cf992b 100644 --- a/src/Container/SALOME_Container.cxx +++ b/src/Container/SALOME_Container.cxx @@ -62,12 +62,68 @@ using namespace std; extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB); +#include +#include +#include +#include + +typedef void (*sighandler_t)(int); +sighandler_t setsig(int sig, sighandler_t handler) +{ + struct sigaction context, ocontext; + context.sa_handler = handler; + sigemptyset(&context.sa_mask); + context.sa_flags = 0; + if (sigaction(sig, &context, &ocontext) == -1) + return SIG_ERR; + return ocontext.sa_handler; +} + +void AttachDebugger() +{ + if(getenv ("DEBUGGER")) + { + std::stringstream exec; + exec << "$DEBUGGER SALOME_Container " << getpid() << "&"; + std::cerr << exec.str() << std::endl; + system(exec.str().c_str()); + while(1); + } +} + +void Handler(int theSigId) +{ + std::cerr << "SIGSEGV: " << std::endl; + AttachDebugger(); + //to exit or not to exit + exit(1); +} + +void terminateHandler(void) +{ + std::cerr << "Terminate: not managed exception !" << std::endl; + AttachDebugger(); +} + +void unexpectedHandler(void) +{ + std::cerr << "Unexpected: unexpected exception !" << std::endl; + AttachDebugger(); +} + int main(int argc, char* argv[]) { #ifdef HAVE_MPI2 MPI_Init(&argc,&argv); #endif + if(getenv ("DEBUGGER")) + { + setsig(SIGSEGV,&Handler); + set_terminate(&terminateHandler); + set_unexpected(&unexpectedHandler); + } + // Initialise the ORB. //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 7642e5ae8..296e3e0d2 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -185,6 +185,11 @@ StartContainer(const Engines::MachineParameters& params, const Engines::MachineList& possibleComputers, Engines::ResPolicy policy) { +#ifdef WITH_PACO_PARALLEL + std::string parallelLib(params.parallelLib); + if (parallelLib != "") + return FindOrStartParallelContainer(params, possibleComputers); +#endif long id; string containerNameInNS; char idc[3*sizeof(long)]; @@ -326,7 +331,7 @@ FindOrStartParallelContainer(const Engines::MachineParameters& params_const, INFOS("[FindOrStartParallelContainer] Starting a parallel container"); // Step 2.1 : Choose a computer - string theMachine = _ResManager->FindBest(possibleComputers); + string theMachine = _ResManager->FindFirst(possibleComputers); if(theMachine == "") { INFOS("[FindOrStartParallelContainer] !!!!!!!!!!!!!!!!!!!!!!!!!!"); INFOS("[FindOrStartParallelContainer] No possible computer found"); diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index fe32eba83..03c27e0d5 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -92,7 +92,7 @@ public: Engines::fileRef_ptr createFileRef(const char* origFileName); Engines::fileTransfer_ptr getFileTransfer(); - + virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName); // --- local C++ methods Engines::Component_ptr @@ -131,6 +131,7 @@ protected: int _numInstance ; std::map _listInstances_map; std::map _fileRef_map; + std::map _Salome_file_map; Engines::fileTransfer_var _fileTransfer; int _argc ; diff --git a/src/Container/Salome_file_i.cxx b/src/Container/Salome_file_i.cxx new file mode 100644 index 000000000..8f10ad2cf --- /dev/null +++ b/src/Container/Salome_file_i.cxx @@ -0,0 +1,1062 @@ +// Copyright (C) 2007 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : Salome_file_i.cxx +// Author : André RIBES, EDF +// Module : SALOME +// $Header: + +#include "Salome_file_i.hxx" +#include "utilities.h" +#include +#include +#include "HDFOI.hxx" +#include + +//============================================================================= +/*! + * Default constructor, + */ +//============================================================================= + +Salome_file_i::Salome_file_i() +{ + _fileId = 0; + _path_max = 1 + pathconf("/", _PC_PATH_MAX); + _state.name = CORBA::string_dup(""); + _state.hdf5_file_name = CORBA::string_dup(""); + _state.number_of_files = 0; + _state.files_ok = true; + _container = Engines::Container::_nil(); + _default_source_Salome_file = Engines::Salome_file::_nil(); +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +Salome_file_i::~Salome_file_i() +{ +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::load + */ +//============================================================================= +void +Salome_file_i::load(const char* hdf5_file) { + _state.hdf5_file_name = CORBA::string_dup(hdf5_file); + try + { + HDFfile *hdf_file; + HDFgroup *hdf_group; + HDFdataset *hdf_dataset; + int size; + int fd; + char * value; + char * buffer; + + hdf_file = new HDFfile((char*) hdf5_file); + hdf_file->OpenOnDisk(HDF_RDONLY); + + hdf_group = new HDFgroup("CONFIG",hdf_file); + hdf_group->OpenOnDisk(); + hdf_dataset = new HDFdataset("MODE",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string mode(value); + delete value; + + hdf_group = new HDFgroup("GROUP_FILES",hdf_file); + hdf_group->OpenOnDisk(); + hdf_dataset = new HDFdataset("LIST_OF_FILES",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string list_of_files(value); + delete value; + + std::istringstream iss(list_of_files); + std::string file_name; + while (std::getline(iss, file_name, ' ')) + { + std::string dataset_group_name("DATASET"); + dataset_group_name += file_name; + + hdf_group = new HDFgroup(dataset_group_name.c_str(), hdf_file); + hdf_group->OpenOnDisk(); + + hdf_dataset = new HDFdataset("NAME",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string name(value); + + hdf_dataset = new HDFdataset("PATH",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string path(value); + + hdf_dataset = new HDFdataset("TYPE",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string type(value); + + hdf_dataset = new HDFdataset("SOURCE_FILE_NAME",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string source_file_name(value); + + hdf_dataset = new HDFdataset("STATUS",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + value = new char[size]; + hdf_dataset->ReadFromDisk(value); + hdf_dataset->CloseOnDisk(); + std::string status(value); + + if (mode == "all") { + + // Changing path, is now current directory + char CurrentPath[_path_max]; + getcwd(CurrentPath, _path_max); + path = CurrentPath; + + std::string group_name("GROUP"); + group_name += file_name; + hdf_group = new HDFgroup(group_name.c_str(),hdf_file); + hdf_group->OpenOnDisk(); + hdf_dataset = new HDFdataset("FILE DATASET",hdf_group); + hdf_dataset->OpenOnDisk(); + size = hdf_dataset->GetSize(); + buffer = new char[size]; + + if ( (fd = ::open(file_name.c_str(),O_RDWR|O_CREAT,00666)) <0) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "open failed"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + }; + hdf_dataset->ReadFromDisk(buffer); + if ( write(fd,buffer,size) <0) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "write failed"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + }; + // Close the target file + ::close(fd); + + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + + _fileManaged[file_name] = infos; + + // Update Salome_file state + _state.number_of_files++; + _state.files_ok = true; + } + else { + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + // Infos for parallel extensions... + infos.node = 0; + infos.container = Engines::Container::_duplicate(_container); + + _fileManaged[file_name] = infos; + + // Update Salome_file state + _state.number_of_files++; + if (status != "ok") + _state.files_ok = false; + } + } + } + catch (HDFexception) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "!!!! HDFexception"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::save + */ +//============================================================================= +void +Salome_file_i::save(const char* hdf5_file) { + _state.hdf5_file_name = CORBA::string_dup(hdf5_file); + try + { + HDFfile *hdf_file; + HDFgroup *hdf_group; + HDFdataset *hdf_dataset; + hdf_size size[1]; + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + + hdf_file = new HDFfile((char*) _state.hdf5_file_name.in()); + hdf_file->CreateOnDisk(); + + // Save mode information + hdf_group = new HDFgroup("CONFIG", hdf_file); + hdf_group->CreateOnDisk(); + std::string mode("infos"); + size[0] = strlen(mode.c_str()) + 1; + hdf_dataset = new HDFdataset("MODE", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) mode.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + + // List of files that are managed + std::string list_of_files; + for(;begin!=end;begin++) + { + Engines::file file_infos = begin->second; + std::string file_name(file_infos.file_name.in()); + + list_of_files = list_of_files + file_name + std::string(" "); + } + hdf_group = new HDFgroup("GROUP_FILES", hdf_file); + hdf_group->CreateOnDisk(); + size[0] = strlen(list_of_files.c_str()) + 1; + hdf_dataset = new HDFdataset("LIST_OF_FILES", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) list_of_files.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + + // Insert Files into the hdf5_file + begin = _fileManaged.begin(); + for(;begin!=end;begin++) + { + Engines::file file_infos = begin->second; + std::string file_name(file_infos.file_name.in()); + std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append(_fileManaged[file_name].file_name.in()); + std::string dataset_group_name("DATASET"); + dataset_group_name += std::string(_fileManaged[file_name].file_name.in()); + + hdf_group = new HDFgroup((char *) dataset_group_name.c_str(), hdf_file); + hdf_group->CreateOnDisk(); + size[0] = strlen(file_infos.file_name.in()) + 1; + hdf_dataset = new HDFdataset("NAME", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.file_name.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.path.in()) + 1; + hdf_dataset = new HDFdataset("PATH", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.path.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.type.in()) + 1; + hdf_dataset = new HDFdataset("TYPE", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.type.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.source_file_name.in()) + 1; + hdf_dataset = new HDFdataset("SOURCE_FILE_NAME", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.source_file_name.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.status.in()) + 1; + hdf_dataset = new HDFdataset("STATUS", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.status.in()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + } + + hdf_file->CloseOnDisk(); + + // delete hdf_dataset; + // delete hdf_group; ----> SEGFAULT !!! + // delete hdf_file; ----> SEGFAULT !!! + } + catch (HDFexception) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "!!!! HDFexception"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::save_all + */ +//============================================================================= +void +Salome_file_i::save_all(const char* hdf5_file) { + + _state.hdf5_file_name = CORBA::string_dup(hdf5_file); + // Test Salome_file status + if (_state.files_ok == false) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "File Not Ok !"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + + // For each file we create two groups + // First group contains file's informations + // Second group contains the file + // At the end we create a group and a dataset containing the names + // of all the files. + try + { + HDFfile *hdf_file; + HDFgroup *hdf_group; + HDFdataset *hdf_dataset; + hdf_size size[1]; + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + + hdf_file = new HDFfile((char*) _state.hdf5_file_name.in()); + hdf_file->CreateOnDisk(); + + // Save mode information + hdf_group = new HDFgroup("CONFIG", hdf_file); + hdf_group->CreateOnDisk(); + std::string mode("all"); + size[0] = strlen(mode.c_str()) + 1; + hdf_dataset = new HDFdataset("MODE", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) mode.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + + + // List of files that will be inserted + std::string list_of_files; + for(;begin!=end;begin++) + { + Engines::file file_infos = begin->second; + std::string file_name(file_infos.file_name.in()); + + list_of_files = list_of_files + file_name + std::string(" "); + } + hdf_group = new HDFgroup("GROUP_FILES", hdf_file); + hdf_group->CreateOnDisk(); + size[0] = strlen(list_of_files.c_str()) + 1; + hdf_dataset = new HDFdataset("LIST_OF_FILES", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) list_of_files.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + + // Insert Files into the hdf5_file + begin = _fileManaged.begin(); + for(;begin!=end;begin++) + { + Engines::file file_infos = begin->second; + std::string file_name(file_infos.file_name.in()); + std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append(_fileManaged[file_name].file_name.in()); + std::string group_name("GROUP"); + group_name += std::string(_fileManaged[file_name].file_name.in()); + std::string dataset_group_name("DATASET"); + dataset_group_name += std::string(_fileManaged[file_name].file_name.in()); + + hdf_group = new HDFgroup((char *) group_name.c_str(), hdf_file); + hdf_group->CreateOnDisk(); + HDFConvert::FromAscii(comp_file_name.c_str(), *hdf_group, "FILE DATASET"); + hdf_group->CloseOnDisk(); + + hdf_group = new HDFgroup((char *) dataset_group_name.c_str(), hdf_file); + hdf_group->CreateOnDisk(); + size[0] = strlen(file_infos.file_name.in()) + 1; + hdf_dataset = new HDFdataset("NAME", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.file_name.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.path.in()) + 1; + hdf_dataset = new HDFdataset("PATH", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.path.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.type.in()) + 1; + hdf_dataset = new HDFdataset("TYPE", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.type.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.source_file_name.in()) + 1; + hdf_dataset = new HDFdataset("SOURCE_FILE_NAME", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.source_file_name.in()); + hdf_dataset->CloseOnDisk(); + size[0] = strlen(file_infos.status.in()) + 1; + hdf_dataset = new HDFdataset("STATUS", hdf_group, HDF_STRING, size, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void *) file_infos.status.in()); + hdf_dataset->CloseOnDisk(); + hdf_group->CloseOnDisk(); + + } + + hdf_file->CloseOnDisk(); + + // delete hdf_dataset; + // delete hdf_group; ----> SEGFAULT !!! + // delete hdf_file; ----> SEGFAULT !!! + } + catch (HDFexception) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "!!!! HDFexception"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setLocalFile + */ +//============================================================================= +void +Salome_file_i::setLocalFile(const char* comp_file_name) +{ + std::string file_name(""); + std::string path(""); + std::string type("local"); + std::string source_file_name(""); + std::string status("not_ok"); + + std::string cp_file_name(comp_file_name); + std::size_t index = cp_file_name.rfind("/"); + if (index != -1) + { + file_name = cp_file_name.substr(index+1); + path = cp_file_name.substr(0,index+1); + } + else + { + file_name = comp_file_name; + char CurrentPath[_path_max]; + getcwd(CurrentPath, _path_max); + path = CurrentPath; + } + + // Test if this file is already added + _t_fileManaged::iterator it = _fileManaged.find(file_name); + if (it != _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file already added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + + // Test if the file is ok + if(fopen(comp_file_name,"rb") != NULL) + status = "ok"; + + // Adding file with is informations + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + // Infos for parallel extensions... + infos.node = 0; + infos.container = Engines::Container::_duplicate(_container); + + _fileManaged[file_name] = infos; + + // Update Salome_file state + _state.number_of_files++; + if (status != "ok") + _state.files_ok = false; +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setDistributedFile + */ +//============================================================================= +void +Salome_file_i::setDistributedFile(const char* comp_file_name) +{ + std::string file_name(""); + std::string path(""); + std::string type("distributed"); + std::string source_file_name(""); + std::string status("not_ok"); + + std::string cp_file_name(comp_file_name); + std::size_t index = cp_file_name.rfind("/"); + if (index != -1) + { + file_name = cp_file_name.substr(index+1); + path = cp_file_name.substr(0,index+1); + } + else + { + file_name = comp_file_name; + char CurrentPath[_path_max]; + getcwd(CurrentPath, _path_max); + path = CurrentPath; + } + + // Test if this file is already added + _t_fileManaged::iterator it = _fileManaged.find(file_name); + if (it != _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file already added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + + // Adding file with his informations + Engines::file infos; + infos.file_name = CORBA::string_dup(file_name.c_str()); + infos.path = CORBA::string_dup(path.c_str()); + infos.type = CORBA::string_dup(type.c_str()); + infos.source_file_name = CORBA::string_dup(source_file_name.c_str()); + infos.status = CORBA::string_dup(status.c_str()); + // Infos for parallel extensions... + infos.node = 0; + infos.container = Engines::Container::_duplicate(_container); + + _fileManaged[file_name] = infos; + + if(!CORBA::is_nil(_default_source_Salome_file)) + { + _fileDistributedSource[file_name] = + Engines::Salome_file::_duplicate(_default_source_Salome_file); + } + + // Update Salome_file state + _state.number_of_files++; + _state.files_ok = false; +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::connect + */ +//============================================================================= +void +Salome_file_i::connect(Engines::Salome_file_ptr source_Salome_file) +{ + if(CORBA::is_nil(_default_source_Salome_file)) + { + _default_source_Salome_file = Engines::Salome_file::_duplicate(source_Salome_file); + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) { + // Get the name of the file + std::string file_name = begin->first; + _t_fileDistributedSource::iterator it = _fileDistributedSource.find(file_name); + if (it == _fileDistributedSource.end()) + { + _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); + } + } + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "already connected to a default Salome_file"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + // We can connect this Salome_file if there is only one file managed + // by the Salome_file + //std::string fname; + //if (_fileManaged.size() == 1) + //{ + // only one file managed + // _t_fileManaged::iterator it = _fileManaged.begin(); + // fname = it->first; + // _fileDistributedSource[fname] = Engines::Salome_file::_duplicate(source_Salome_file); + //} + //else + //{ + // SALOME::ExceptionStruct es; + // es.type = SALOME::INTERNAL_ERROR; + // std::string text = "cannot connect"; + // es.text = CORBA::string_dup(text.c_str()); + // throw SALOME::SALOME_Exception(es); + //} +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::connectDistributedFile + */ +//============================================================================= +void +Salome_file_i::connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file) +{ + // Test if this file is added + _t_fileManaged::iterator it = _fileManaged.find(file_name); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file is not added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + else + { + _fileDistributedSource[file_name] = Engines::Salome_file::_duplicate(source_Salome_file); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::setDistributedSourceFile + */ +//============================================================================= +void +Salome_file_i::setDistributedSourceFile(const char* file_name, + const char * source_file_name) +{ + std::string fname(file_name); + + // Test if this file is added + _t_fileManaged::iterator it = _fileManaged.find(fname); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "file is not added"; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + else + { + _fileManaged[fname].source_file_name = CORBA::string_dup(source_file_name); + } +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::recvFiles + */ +//============================================================================= +void +Salome_file_i::recvFiles() { + + std::string files_not_ok(""); + + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) + { + bool result = true; + Engines::file file_infos = begin->second; + // Test if the file is local or distributed + if (std::string(file_infos.type.in()) == "local") + { + if (std::string(file_infos.status.in()) == "not_ok") + result = checkLocalFile(file_infos.file_name.in()); + } + else + { + if (std::string(file_infos.status.in()) == "not_ok") + result = getDistributedFile(file_infos.file_name.in()); + } + // if the result is false + // we add this file to files_not_ok + if (!result) + { + files_not_ok.append(" "); + files_not_ok.append(file_infos.file_name.in()); + } + } + + if (files_not_ok != "") + { + std::cerr << "tutu" << std::endl; + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "files not ready : " + files_not_ok; + es.text = CORBA::string_dup(text.c_str()); + std::cerr << "titi" << std::endl; + throw SALOME::SALOME_Exception(es); + } + else + { + // We change the state of the Salome_file + _state.files_ok = true; + } +} + +//============================================================================= +/*! + * local C++ method : This method is used by revFiles to check if a local + * managed file is ok. + * \param fileName name of the file + */ +//============================================================================= +bool +Salome_file_i::checkLocalFile(std::string file_name) +{ + bool result = true; + + std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append("/"); + comp_file_name.append(_fileManaged[file_name].file_name.in()); + if(fopen(comp_file_name.c_str(),"rb") == NULL) + { + INFOS("file " << comp_file_name << " cannot be open for reading"); + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + result = false; + } + + if (result) + { + _fileManaged[file_name].status = CORBA::string_dup("ok"); + } + return result; +} + +//============================================================================= +/*! + * local C++ method : this method is used by recvFiles to get a + * distributed file from is distributed source. + * If there is no source_file_name for the file, it tries to get + * the file from the source. In this case, the source distributed file has to managed + * only one file to be able to the send the file. + * + * \param fileName name of the file + */ +//============================================================================= +bool +Salome_file_i::getDistributedFile(std::string file_name) +{ + bool result = true; + const char * source_file_name = _fileManaged[file_name].source_file_name.in(); + int fileId; + FILE* fp; + std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append("/"); + comp_file_name.append(_fileManaged[file_name].file_name.in()); + + // Test if the process can write on disk + if ((fp = fopen(comp_file_name.c_str(),"wb")) == NULL) + { + INFOS("file " << comp_file_name << " cannot be open for writing"); + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + result = false; + return result; + } + + try + { + fileId = _fileDistributedSource[file_name]->open(source_file_name); + } + catch (...) + { + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + fclose(fp); + result = false; + return result; + } + + if (fileId > 0) + { + Engines::fileBlock* aBlock; + int toFollow = 1; + int ctr=0; + MESSAGE("begin of transfer of " << comp_file_name); + while (toFollow) + { + ctr++; + aBlock = _fileDistributedSource[file_name]->getBlock(fileId); + toFollow = aBlock->length(); + CORBA::Octet *buf = aBlock->get_buffer(); + int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); + ASSERT(nbWri == toFollow); + } + fclose(fp); + MESSAGE("end of transfer of " << comp_file_name); + _fileDistributedSource[file_name]->close(fileId); + } + else + { + INFOS("open reference file for copy impossible"); + result = false; + fclose(fp); + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + return result; + } + + _fileManaged[file_name].status = CORBA::string_dup("ok"); + return result; +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::removeFile + */ +//============================================================================= +void +Salome_file_i::removeFile(const char* file_name) +{ + MESSAGE("Salome_file_i::removeFile : NOT YET IMPLEMENTED"); +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::removeFiles + */ +//============================================================================= +void +Salome_file_i::removeFiles() { + MESSAGE("Salome_file_i::removeFiles : NOT YET IMPLEMENTED"); +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::getFilesInfos + */ +//============================================================================= +Engines::files* +Salome_file_i::getFilesInfos() { + + Engines::files * infos = new Engines::files(); + infos->length(_fileManaged.size()); + + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + int i = 0; + for(;begin!=end;begin++) { + (*infos)[i] = *(new Engines::file(begin->second)); + i++; + } + return infos; +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::getFileInfos + */ +//============================================================================= +Engines::file* +Salome_file_i::getFileInfos(const char* file_name) { + + std::string fname(file_name); + + // Test if this file is managed + _t_fileManaged::iterator it = _fileManaged.find(fname); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "file is not managed"; + throw SALOME::SALOME_Exception(es); + } + + Engines::file * infos = new Engines::file(_fileManaged[fname]); + return infos; +} + +//============================================================================= +/*! + * CORBA method + * \see Engines::Salome_file::getSalome_fileState + */ +//============================================================================= +Engines::SfState* +Salome_file_i::getSalome_fileState() +{ + return new Engines::SfState(_state); +} + +//============================================================================= +/*! + * CORBA method: try to open the file given. If the file is readable, return + * a positive integer else return 0; + * \param fileName file name to be transfered + * \return fileId = positive integer > 0 if open OK. + */ +//============================================================================= + +CORBA::Long +Salome_file_i::open(const char* file_name) +{ + int aKey = 0; + + std::string fname(file_name); + if (fname == "") { + // We enter in the simple case where the user + // has not used setDistributedSourceFile. + // In this case we try to see if the Salome_file + if (_fileManaged.size() == 1) + { + // only one file managed + _t_fileManaged::iterator it = _fileManaged.begin(); + fname = it->first; + } + else + { + // we can't choose the file so : + return aKey; + } + } + + _t_fileManaged::iterator it = _fileManaged.find(fname); + if (it == _fileManaged.end()) + { + return aKey; + } + + std::string comp_file_name(_fileManaged[fname].path.in()); + comp_file_name.append("/"); + comp_file_name.append(fname); + MESSAGE("Salome_file_i::open " << comp_file_name); + FILE* fp; + if ((fp = fopen(comp_file_name.c_str(),"rb")) == NULL) + { + INFOS("file " << comp_file_name << " is not readable"); + return aKey; + } + + aKey = ++_fileId; + _fileAccess[aKey] = fp; + return aKey; +} + +//============================================================================= +/*! + * CORBA method: close the file associated to the fileId given at open. + * \param fileId got in return from open method + */ +//============================================================================= + +void +Salome_file_i::close(CORBA::Long fileId) +{ + MESSAGE("Salome_file_i::close"); + FILE* fp; + if (!(fp = _fileAccess[fileId]) ) + { + INFOS(" no FILE structure associated to fileId " << fileId); + } + else fclose(fp); +} + +//============================================================================= +/*! + * CORBA method: get a block of data from the file associated to the fileId + * given at open. + * \param fileId got in return from open method + * \return an octet sequence. Last one is empty. + */ +//============================================================================= + +#define FILEBLOCK_SIZE 256*1024 + +Engines::fileBlock* +Salome_file_i::getBlock(CORBA::Long fileId) +{ + Engines::fileBlock* aBlock = new Engines::fileBlock; + + FILE* fp; + if (! (fp = _fileAccess[fileId]) ) + { + INFOS(" no FILE structure associated to fileId " <replace(nbRed, nbRed, buf, 1); // 1 means give ownership + return aBlock; +} + +void +Salome_file_i::setContainer(Engines::Container_ptr container) +{ + _container = Engines::Container::_duplicate(container); + + // Update All the files + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) { + begin->second.container = Engines::Container::_duplicate(container); + } +} + diff --git a/src/Container/Salome_file_i.hxx b/src/Container/Salome_file_i.hxx new file mode 100644 index 000000000..16b09034e --- /dev/null +++ b/src/Container/Salome_file_i.hxx @@ -0,0 +1,106 @@ +// Copyright (C) 2007 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : Salome_file_i.hxx +// Author : André RIBES, EDF +// Module : SALOME +// $Header: + +#ifndef _SALOME_FILE_I_HXX_ +#define _SALOME_FILE_I_HXX_ + +#include + +#include CORBA_SERVER_HEADER(SALOME_Component) +#include CORBA_SERVER_HEADER(SALOME_Exception) + +#include +#include +#include + +class CONTAINER_EXPORT Salome_file_i: + public virtual POA_Engines::Salome_file +{ + public: + Salome_file_i(); + virtual ~Salome_file_i(); + + // Import and export methods + virtual void load(const char* hdf5_file); + virtual void save(const char* hdf5_file); + virtual void save_all(const char* hdf5_file); + + // Adding files + virtual void setLocalFile(const char* comp_file_name); + virtual void setDistributedFile(const char* comp_file_name); + + // Configure DistributedFile + virtual void connect(Engines::Salome_file_ptr source_Salome_file); + virtual void connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file); + virtual void setDistributedSourceFile(const char* file_name, + const char * source_file_name); + + // Recv and check files + virtual void recvFiles(); + + // Removing or deleting files + virtual void removeFile(const char* file_name); + virtual void removeFiles(); + + // Informations methods: + virtual void setContainer(Engines::Container_ptr container); + virtual Engines::files* getFilesInfos(); + virtual Engines::file* getFileInfos(const char* file_name); + virtual Engines::SfState* getSalome_fileState(); + + // ---------------- fileTransfert Methods ----------------------- + virtual CORBA::Long open(const char* file_name); + virtual void close(CORBA::Long fileId); + virtual Engines::fileBlock* getBlock(CORBA::Long fileId); + + protected: + // ---------------- local C++ methods --------------------------- + virtual bool checkLocalFile(std::string file_name); + virtual bool getDistributedFile(std::string file_name); + + protected: + + // Contains a relation between a file ID (int) with + // a fd descriptor (FILE*) open on the file. + typedef std::map _t_fileAccess; + + // Contains the informations of the files managed by the Salome_file. + typedef std::map _t_fileManaged; + + // Contains the CORBA reference for each distributed file managed. + typedef std::map _t_fileDistributedSource; + + int _fileId; + long _path_max; + _t_fileAccess _fileAccess; + _t_fileManaged _fileManaged; + _t_fileDistributedSource _fileDistributedSource; + Engines::SfState _state; + Engines::Container_ptr _container; + Engines::Salome_file_ptr _default_source_Salome_file; +}; + +#endif diff --git a/src/Container/TestSalome_file.cxx b/src/Container/TestSalome_file.cxx new file mode 100644 index 000000000..76d3b031f --- /dev/null +++ b/src/Container/TestSalome_file.cxx @@ -0,0 +1,154 @@ +#include "Salome_file_i.hxx" +#include +#include +#include +#include "HDFascii.hxx" + +using namespace std; + +void print_infos(Engines::file * infos) +{ + cerr << "-------------------------------------------------------------------" << endl; + cerr << "file_name = " << infos->file_name << endl; + cerr << "path = " << infos->path << endl; + cerr << "type = " << infos->type << endl; + cerr << "source_file_name = " << infos->source_file_name << endl; + cerr << "status = " << infos->status << endl; +} + +void print_state(Engines::SfState * state) +{ + cerr << "-------------------------------------------------------------------" << endl; + cerr << "name = " << state->name << endl; + cerr << "hdf5_file_name = " << state->hdf5_file_name << endl; + cerr << "number_of_files = " << state->number_of_files << endl; + cerr << "files_ok = " << state->files_ok << endl; +} + + +int main (int argc, char * argv[]) +{ + system("rm toto cat test.hdf test2.hdf"); + + Salome_file_i file; + Salome_file_i file2; + Salome_file_i file3; + Salome_file_i file4; + Salome_file_i file5; + Engines::file * infos; + Engines::SfState * state; + Engines::files * all_infos; + PortableServer::POA_var root_poa; + PortableServer::POAManager_var pman; + CORBA::Object_var obj; + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of setLocalFile()" << endl; + file.setLocalFile("/tmp/toto"); + infos = file.getFileInfos("toto"); + print_infos(infos); + + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of getFilesInfos()" << endl; + all_infos = file.getFilesInfos(); + for (int i = 0; i < all_infos->length(); i++) + { + print_infos(&((*all_infos)[i])); + } + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of getSalome_fileState()" << endl; + state = file.getSalome_fileState(); + print_state(state); + + // We start CORBA ... + CORBA::ORB_ptr orb = CORBA::ORB_init(argc , argv); + obj = orb->resolve_initial_references("RootPOA"); + root_poa = PortableServer::POA::_narrow(obj); + pman = root_poa->the_POAManager(); + pman->activate(); + + file2.setLocalFile("/tmp/toto_distributed_source"); + Engines::Salome_file_ptr file2_ref = file2._this(); + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of setDistributedFile()" << endl; + file.setDistributedFile("/tmp/toto_distributed"); + file.connectDistributedFile("toto_distributed", file2_ref); +// file.setDistributedSourceFile("toto_distributed", "toto_distributed_source"); + infos = file.getFileInfos("toto_distributed"); + print_infos(infos); + + // We create the files ... + std::ostringstream oss; + oss << "/tmp/toto"; + std::ofstream f(oss.str().c_str()); + if (f) + f << "blablabla" << std::endl; + + std::ostringstream oss2; + oss2 << "/tmp/toto_distributed_source"; + std::ofstream f2(oss2.str().c_str()); + if (f2) + f2 << "bliblibli" << std::endl; + + try + { + file.recvFiles(); + } + catch (SALOME::SALOME_Exception & e) + { + cerr << "Exception : " << e.details.text << endl; + } + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of getFilesInfos()" << endl; + all_infos = file.getFilesInfos(); + for (int i = 0; i < all_infos->length(); i++) + { + print_infos(&((*all_infos)[i])); + } + + cerr << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + cerr << "Test of getSalome_fileState()" << endl; + state = file.getSalome_fileState(); + print_state(state); + + orb->destroy(); + + file3.setLocalFile("/tmp/toto"); + file3.setLocalFile("/bin/cat"); + state = file3.getSalome_fileState(); + print_state(state); + file3.save_all("test.hdf"); + file3.setLocalFile("/bin/tutu"); + file3.save("test2.hdf"); + + file4.load("test.hdf"); + all_infos = file4.getFilesInfos(); + for (int i = 0; i < all_infos->length(); i++) + { + print_infos(&((*all_infos)[i])); + } + state = file4.getSalome_fileState(); + print_state(state); + file5.load("test2.hdf"); + all_infos = file5.getFilesInfos(); + for (int i = 0; i < all_infos->length(); i++) + { + print_infos(&((*all_infos)[i])); + } + state = file5.getSalome_fileState(); + print_state(state); + + // Test of ConvertFromHDFToASCII + // and ConvertFromASCIIToHDF + cerr << "Test of ConvertFromASCIIToHDF" << endl; + HDFascii::ConvertFromASCIIToHDF("/tmp/toto"); // RETURN NULL ! + cerr << "Test of ConvertFromHDFToASCII" << endl; + cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", false) << endl; + cerr << HDFascii::ConvertFromHDFToASCII("test2.hdf", true) << endl; + + cerr << "End of tests" << endl; +} diff --git a/src/DSC/DSC_Basic/DSC_Basic.hxx b/src/DSC/DSC_Basic/DSC_Basic.hxx index 0c94e55e6..0efc1a2e2 100755 --- a/src/DSC/DSC_Basic/DSC_Basic.hxx +++ b/src/DSC/DSC_Basic/DSC_Basic.hxx @@ -44,4 +44,5 @@ #define DSC_BASIC_EXPORT #endif -#endif \ No newline at end of file +#endif + diff --git a/src/DSC/DSC_Python/Makefile.am b/src/DSC/DSC_Python/Makefile.am new file mode 100644 index 000000000..48ed93f93 --- /dev/null +++ b/src/DSC/DSC_Python/Makefile.am @@ -0,0 +1,79 @@ +# Copyright (C) 2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : Makefile.am +# Author : André RIBES (EDF), Eric Fayolle (EDF) +# Module : KERNEL +# + +include $(top_srcdir)/salome_adm/unix/make_common_starter.am + +# =============================================================== +# Local definitions +# =============================================================== +# + +# This local variable defines the list of CPPFLAGS common to all target in this package. +COMMON_CPPFLAGS= -I$(top_srcdir)/src/DSC/DSC_User \ + -I$(top_srcdir)/src/DSC/DSC_User/Datastream \ + -I$(top_srcdir)/src/DSC/DSC_User/Datastream/Palm \ + -I$(top_srcdir)/src/DSC/DSC_User/Datastream/Calcium \ + -I$(top_srcdir)/src/DSC/DSC_User/Basic \ + -I$(top_srcdir)/src/DSC/DSC_Basic \ + -I$(top_srcdir)/src/SALOMELocalTrace \ + -I$(top_srcdir)/src/Basics \ + -I$(top_srcdir)/src/Utils \ + -I$(top_srcdir)/src/Container \ + -I$(top_srcdir)/src/Notification \ + -I$(top_builddir)/salome_adm/unix \ + -I$(top_builddir)/idl \ + @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @BOOST_CPPFLAGS@ + +# This local variable defines the list of dependant libraries common to all target in this package. +COMMON_LIBS = @CORBA_LIBS@ + +# +# =============================================================== +# Libraries targets +# =============================================================== +# + +AM_CFLAGS = -fexceptions +pkgpython_PYTHON = calcium.py dsccalcium.py +pkgpyexec_LTLIBRARIES = _calcium.la +SWIG_FLAGS= -python -c++ -noexcept +SWIG_SRC=calcium.i +_calcium_la_SOURCES = calcium_wrap.cpp +_calcium_la_LDFLAGS = -module +_calcium_la_LIBADD = ../DSC_User/Datastream/Calcium/libCalciumC.la \ + ../DSC_User/Datastream/libSalomeDatastream.la \ + ../DSC_User/Basic/libSalomeDSCSupervBasic.la \ + ../DSC_User/libSalomeDSCSuperv.la \ + ../DSC_Basic/libSalomeDSCContainer.la \ + ../../Container/libSalomeContainer.la + +_calcium_la_CXXFLAGS = $(PYTHON_INCLUDES) $(COMMON_CPPFLAGS) + +calcium_wrap.cpp calcium.py:calcium.i + $(SWIG) $(SWIG_FLAGS) -o calcium_wrap.cpp $< + +CLEANFILES = calcium_wrap.cpp + diff --git a/src/DSC/DSC_Python/calcium.i b/src/DSC/DSC_Python/calcium.i new file mode 100644 index 000000000..f7700dd20 --- /dev/null +++ b/src/DSC/DSC_Python/calcium.i @@ -0,0 +1,241 @@ +%define DOCSTRING +"CALCIUM python wrapping : Superv_Component class +" +%enddef + +%module(docstring=DOCSTRING) calcium + +%feature("autodoc", "0"); + +%{ +//C++ Includes +#include +#include +#include +#include + +//--- from omniORBpy.h (not present on Debian Sarge packages) + +struct omniORBpyAPI { + + PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj, + CORBA::Boolean hold_lock); + // Convert a C++ object reference to a Python object reference. + // If is true, caller holds the Python interpreter lock. + + CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj, + CORBA::Boolean hold_lock); + // Convert a Python object reference to a C++ object reference. + // Raises BAD_PARAM if the Python object is not an object reference. + // If is true, caller holds the Python interpreter lock. + + + omniORBpyAPI(); + // Constructor for the singleton. Sets up the function pointers. +}; + + omniORBpyAPI* api; + +%} + +%init +%{ + // init section + + PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy"); + if (!omnipy) + { + PyErr_SetString(PyExc_ImportError, + (char*)"Cannot import _omnipy"); + return; + } + PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API"); + api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi); + Py_DECREF(pyapi); +%} + +%include "carrays.i" +%include "cpointer.i" + +/* Wrap a class interface around an "int *" */ +%pointer_class(int, intp); +/* Wrap a class interface around an "float *" */ +%pointer_class(float, floatp); +/* Wrap a class interface around an "double *" */ +%pointer_class(double, doublep); + +%array_class(int, intArray); +%array_class(float, floatArray); +%array_class(double, doubleArray); + +%typemap(python,in) CORBA::Boolean +{ + $1=(CORBA::Boolean)PyInt_AsLong($input); +} + +%typemap(python,in) CORBA::ORB_ptr +{ + try { + CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1); + $1 = CORBA::ORB::_narrow(obj); + } + catch (...) { + PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr"); + } +} +%typemap(python,in) PortableServer::POA_ptr +{ + try { + CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1); + $1 = PortableServer::POA::_narrow(obj); + } + catch (...) { + PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr"); + } +} + +%typemap(python,in) Engines::Container_ptr +{ + try { + CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1); + $1 = Engines::Container::_narrow(obj); + } + catch (...) { + PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr"); + } +} +%typemap(python,in) Ports::Port_ptr +{ + try { + CORBA::Object_ptr obj = api->pyObjRefToCxxObjRef($input,1); + $1 = Ports::Port::_narrow(obj); + } + catch (...) { + PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr"); + } +} + +%typemap(python,out) Ports::Port_ptr , Ports::PortProperties_ptr +{ + $result = api->cxxObjRefToPyObjRef($1, 1); +} + +/* + * Exception section + */ +// a general exception handler +%exception { + try { + $action + } catch(Engines::DSC::PortNotDefined& _e) { + PyErr_SetString(PyExc_ValueError,"Port not defined"); + return NULL; + } catch(Engines::DSC::PortNotConnected& _e) { + PyErr_SetString(PyExc_ValueError,"Port not connected"); + return NULL; + } catch(Engines::DSC::BadPortType& _e) { + PyErr_SetString(PyExc_ValueError,"Bad port type"); + return NULL; + } catch(...) { + PyErr_SetString(PyExc_ValueError,"Unknown exception"); + return NULL; + } +} + +/* + * End of Exception section + */ +namespace Engines +{ +class DSC +{ + public: + enum Message { AddingConnection, RemovingConnection, ApplicationError }; +}; +} + +class PySupervCompo:public Superv_Component_i +{ + public: + + PySupervCompo(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + Engines::Container_ptr contai, + const char *instanceName, + const char *interfaceName); + + virtual ~PySupervCompo(); + CORBA::Boolean init_service(const char * service_name){return true;}; + virtual provides_port * create_provides_data_port(const char* port_fab_type) + throw (BadFabType); + virtual uses_port * create_uses_data_port(const char* port_fab_type) + throw (BadFabType); + virtual void add_port(const char * port_fab_type, + const char * port_type, + const char * port_name) + throw (PortAlreadyDefined, BadFabType, BadType, BadProperty); + template < typename SpecificPortType > + SpecificPortType * add_port(const char * port_fab_type, + const char * port_type, + const char * port_name) + throw (PortAlreadyDefined, BadFabType, BadType, BadCast, BadProperty); + virtual void add_port(provides_port * port, + const char* provides_port_name) + throw (PortAlreadyDefined, NilPort, BadProperty); + virtual void add_port(uses_port * port, + const char* uses_port_name) + throw (PortAlreadyDefined, NilPort, BadProperty); + template + SpecificPortType * get_port( const char * port_name) + throw (PortNotDefined, PortNotConnected, BadCast, UnexpectedState); + virtual Ports::Port_ptr get_provides_port(const char* provides_port_name, + const CORBA::Boolean connection_error) + throw (Engines::DSC::PortNotDefined, + Engines::DSC::PortNotConnected, + Engines::DSC::BadPortType); + virtual void connect_uses_port(const char* uses_port_name, + Ports::Port_ptr provides_port_ref) + throw (Engines::DSC::PortNotDefined, + Engines::DSC::BadPortType, + Engines::DSC::NilPort); + virtual void connect_provides_port(const char* provides_port_name) + throw (Engines::DSC::PortNotDefined); + virtual void disconnect_provides_port(const char* provides_port_name, + const Engines::DSC::Message message) + throw (Engines::DSC::PortNotDefined, + Engines::DSC::PortNotConnected); + + virtual void disconnect_uses_port(const char* uses_port_name, + Ports::Port_ptr provides_port_ref, + const Engines::DSC::Message message) + throw (Engines::DSC::PortNotDefined, + Engines::DSC::PortNotConnected, + Engines::DSC::BadPortReference); + + virtual Ports::PortProperties_ptr get_port_properties(const char* port_name); + + %extend + { + //To get the address of the component + long ptr() + { + return (long)self; + } + } +}; + +extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend); + +#define CP_TEMPS 40 +#define CP_ITERATION 41 +#define CP_SEQUENTIEL 42 +#define CP_CONT 20 +#define CP_ARRET 21 + +int cp_een(void *component,int dep,float t,int n,char *nom,int nval,int *val); +int cp_edb(void *component,int dep,double t,int n,char *nom,int nval,double *val); + +int cp_len(void *component,int dep,float *INOUT,float *INPUT,int *INOUT,char *nom,int nmax,int *OUTPUT,int *val); +int cp_ldb(void *component,int dep,double *INOUT,double *INPUT,int *INOUT,char *nom,int nmax,int *OUTPUT,double *val); +int cp_fin(void *component,int cp_end); + diff --git a/src/DSC/DSC_Python/dsccalcium.py b/src/DSC/DSC_Python/dsccalcium.py new file mode 100644 index 000000000..c96fdc16c --- /dev/null +++ b/src/DSC/DSC_Python/dsccalcium.py @@ -0,0 +1,53 @@ +import calcium +import SALOME_ComponentPy +import SALOME_DriverPy +import Engines + +class PyDSCComponent(SALOME_ComponentPy.SALOME_ComponentPy_i, + SALOME_DriverPy.SALOME_DriverPy_i): + """ + A Python SALOME component is implemented by a Python class that has + the name of the component and is located in a python module that has the + name of the component. + + This class is a base class for Python DSC components. + + You must derive it and implement init_service and those methods + that are services of the component. + """ + def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ): + SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, + contID, containerName, instanceName, interfaceName, 0) + SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName) + # create the DSC proxy + self.proxy=calcium.PySupervCompo(orb,poa,contID,instanceName,interfaceName ) + # Store a reference on naming service in _naming_service attribute + self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb ) + + def init_service(self,service): + return True + + enums={Engines.DSC.RemovingConnection:calcium.DSC.RemovingConnection, + Engines.DSC.AddingConnection:calcium.DSC.AddingConnection, + Engines.DSC.ApplicationError:calcium.DSC.ApplicationError, + } + def get_provides_port(self,name,error): + return self.proxy.get_provides_port(name,error) + + def connect_uses_port(self,name,port): + self.proxy.connect_uses_port(name,port) + + def connect_provides_port(self,name): + self.proxy.connect_provides_port(name) + + def disconnect_provides_port(self,name,message): + self.proxy.disconnect_provides_port(name,message._v) + #self.proxy.disconnect_provides_port(name,self.enums[message]) + + def disconnect_uses_port(self,name,port,message): + self.proxy.disconnect_uses_port(name,port,message._v) + #self.proxy.disconnect_uses_port(name,port,self.enums[message]) + + def get_port_properties(self,name): + return self.proxy.get_port_properties(name) + diff --git a/src/DSC/DSC_User/Basic/data_short_port_provides.cxx b/src/DSC/DSC_User/Basic/data_short_port_provides.cxx index 08723ec70..5b204d41f 100644 --- a/src/DSC/DSC_User/Basic/data_short_port_provides.cxx +++ b/src/DSC/DSC_User/Basic/data_short_port_provides.cxx @@ -27,18 +27,65 @@ data_short_port_provides::data_short_port_provides() { _val = 0; + short_termine = false; + short_mutex = new pthread_mutex_t(); + pthread_mutex_init(short_mutex, NULL); + short_condition = new pthread_cond_t(); + pthread_cond_init(short_condition, NULL); + short_termine_cp = true; + short_mutex_cp = new pthread_mutex_t(); + pthread_mutex_init(short_mutex_cp, NULL); + short_condition_cp = new pthread_cond_t(); + pthread_cond_init(short_condition_cp, NULL); } -data_short_port_provides::~data_short_port_provides() {} +data_short_port_provides::~data_short_port_provides() { + pthread_mutex_destroy(short_mutex); + delete short_mutex; + pthread_cond_destroy(short_condition); + delete short_condition; + pthread_mutex_destroy(short_mutex_cp); + delete short_mutex_cp; + pthread_cond_destroy(short_condition_cp); + delete short_condition_cp; +} void data_short_port_provides::put(CORBA::Short data) { + // On attend que le get soit fait + pthread_mutex_lock(short_mutex_cp); + while (short_termine_cp == false) + { + pthread_cond_wait(short_condition_cp, short_mutex_cp); + } + short_termine_cp = false; + pthread_mutex_unlock(short_mutex_cp); + + pthread_mutex_lock(short_mutex); _val = data; + short_termine = true; + pthread_cond_signal(short_condition); + pthread_mutex_unlock(short_mutex); } CORBA::Short data_short_port_provides::get() { - return _val; + CORBA::Short result; + pthread_mutex_lock(short_mutex); + while (short_termine == false) + { + pthread_cond_wait(short_condition, short_mutex); + } + result = _val; + short_termine = false; + pthread_mutex_unlock(short_mutex); + + // On indique que l'on a copie la valeur + pthread_mutex_lock(short_mutex_cp); + short_termine_cp = true; + pthread_cond_signal(short_condition_cp); + pthread_mutex_unlock(short_mutex_cp); + return result; } Ports::Port_ptr diff --git a/src/DSC/DSC_User/Basic/data_short_port_provides.hxx b/src/DSC/DSC_User/Basic/data_short_port_provides.hxx index 2c5adca40..df33f6551 100644 --- a/src/DSC/DSC_User/Basic/data_short_port_provides.hxx +++ b/src/DSC/DSC_User/Basic/data_short_port_provides.hxx @@ -29,6 +29,7 @@ #include #include "SALOME_Ports.hh" #include "provides_port.hxx" +#include /*! \class data_short_port_provides * \brief This class a port that sends a CORBA short with @@ -65,6 +66,13 @@ class data_short_port_provides : private : CORBA::Short _val; + pthread_mutex_t * short_mutex; + pthread_cond_t * short_condition; + bool short_termine; + pthread_mutex_t * short_mutex_cp; + pthread_cond_t * short_condition_cp; + bool short_termine_cp; + }; #endif diff --git a/src/DSC/DSC_User/Datastream/AdjacentFunctor.hxx b/src/DSC/DSC_User/Datastream/AdjacentFunctor.hxx index 76888edad..214ccc097 100644 --- a/src/DSC/DSC_User/Datastream/AdjacentFunctor.hxx +++ b/src/DSC/DSC_User/Datastream/AdjacentFunctor.hxx @@ -51,23 +51,31 @@ template < typename T > struct AdjacentFunctor { // Suppose que les valeurs passées en paramètres sont triées par ordre croissant bool operator()(const T &v1) { +#ifdef _DEBUG_ std::cout << "AdjacentFunctor: " << _minValue << _maxValue << std::endl; std::cout << "AdjacentFunctor: " << _min << _max << std::endl; +#endif if ( v1 <= _minValue && v1 >= _maxValue) { _equal= true; +#ifdef _DEBUG_ std::cout << "AdjacentFunctor: _equal : " << v1 << std::endl; +#endif return true; } if ( v1 < _minValue ) { _min=v1;_minFound=true; +#ifdef _DEBUG_ std::cout << "AdjacentFunctor: _minFound : " <<_min << std::endl; +#endif } else if ( v1 > _maxValue ) { _max=v1;_maxFound=true; +#ifdef _DEBUG_ std::cout << "AdjacentFunctor: _maxFound : " <<_max << std::endl; +#endif } @@ -94,7 +102,9 @@ template < typename T > struct AdjacentFunctor { bool isEqual() const { return _equal;} bool isBounded() const { return _minFound && _maxFound;} bool getBounds(TNoConst & min, TNoConst & max) const { +#ifdef _DEBUG_ std::cout << "_minFound : " <<_minFound << ", _maxFound " << _maxFound << std::endl; +#endif if (_minFound && _maxFound ) { min=_min; max=_max; return true; } return false; } diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.c b/src/DSC/DSC_User/Datastream/Calcium/Calcium.c index a9732b254..de497f752 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/Calcium.c +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.c @@ -27,6 +27,7 @@ #include "calcium.h" #include #include +#include // Interface C de SalomeCalcium @@ -150,7 +151,6 @@ InfoType cp_fin (void * component, int code) { fflush(stderr); \ fprintf(stderr,"Beginning of CPExx: %s %d %f\n",nomvar,i,t); \ if ( (data == NULL) || (nbelem < 1) ) return CPNTNULL; \ - printf("cp_name : Valeur de nomvar %s\n",nomvar); \ \ InfoType info = ecp_ecriture_##_typeName (component, mode, &t, i, \ nomvar, nbelem, \ @@ -170,3 +170,4 @@ CALCIUM_ECR_INTERFACE_C_(ere,float,float,float,); CALCIUM_ECR_INTERFACE_C_(edb,double,double,double,); CALCIUM_ECR_INTERFACE_C_(elo,float,bool,bool,); CALCIUM_ECR_INTERFACE_C_(ecp,float,float,cplx,); + diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx new file mode 100644 index 000000000..c17ddb80a --- /dev/null +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.cxx @@ -0,0 +1,114 @@ +#include "Calcium.hxx" +#include +#include +#include +#include +#include + +//#define _DEBUG_ + +PySupervCompo::PySupervCompo( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + Engines::Container_ptr contain, + const char *instanceName, + const char *interfaceName, + bool notif) : + Superv_Component_i(orb, poa,poa->reference_to_id(contain), instanceName, interfaceName) +{ +} + +PySupervCompo::~PySupervCompo() +{ +} + + +extern "C" +{ + void cp_exit(int err) + { + throw CalciumException(err,LOC("Abort coupling")); + } + + void setDependency(provides_port * port,char* type,CalciumTypes::DependencyType depend) + { + if(std::string(type)=="CALCIUM_real") + { + dynamic_cast(port)->setDependencyType(depend); + } + else if(std::string(type)=="CALCIUM_double") + { + dynamic_cast(port)->setDependencyType(depend); + } + else if(std::string(type)=="CALCIUM_integer") + { + dynamic_cast(port)->setDependencyType(depend); + } + else + { + std::cerr << "unknown type:" << std::endl; + } + } + + void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend) + { +#ifdef _DEBUG_ + std::cerr << "create_calcium_port: " << name << " " << type << " " << mode << " " << depend << std::endl; +#endif + + if(std::string(mode) == "IN") + { + provides_port * port ; + //provides port + try + { + port = compo->create_provides_data_port(type); + compo->add_port(port, name); + if(std::string(depend) == "I") + setDependency(port,type,CalciumTypes::ITERATION_DEPENDENCY); + else if(std::string(depend) == "T") + setDependency(port,type,CalciumTypes::TIME_DEPENDENCY); + else + { + std::cerr << "create_calcium_port:unknown dependency: " << depend << std::endl; + } + } + catch(const Superv_Component_i::PortAlreadyDefined& ex) + { + //Port already defined : we use the old one + delete port; + std::cerr << "create_calcium_port: " << ex.what() << std::endl; + } + catch ( ... ) + { + std::cerr << "create_calcium_port: unknown exception" << std::endl; + } + } + else if(std::string(mode) == "OUT") + { + uses_port * uport ; + try + { + uport = compo->create_uses_data_port(type); + compo->add_port(uport, name); + } + catch(const Superv_Component_i::PortAlreadyDefined& ex) + { + //Port already defined : we use the old one + delete uport; + std::cerr << "create_calcium_port: " << ex.what() << std::endl; + } + catch ( ... ) + { + std::cerr << "create_calcium_port: unknown exception" << std::endl; + } + } + else + { + //Unknown mode + std::cerr << "create_calcium_port:Unknown mode: " << mode << std::endl; + } + } + +} + + diff --git a/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx b/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx new file mode 100644 index 000000000..a014eeefe --- /dev/null +++ b/src/DSC/DSC_User/Datastream/Calcium/Calcium.hxx @@ -0,0 +1,17 @@ +#include "Superv_Component_i.hxx" + +class PySupervCompo:public Superv_Component_i +{ + public: + PySupervCompo(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + Engines::Container_ptr contain, + const char *instanceName, + const char *interfaceName, + bool notif = false); + virtual ~PySupervCompo(); + CORBA::Boolean init_service(const char * service_name){return true;}; +}; + + +extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend); diff --git a/src/DSC/DSC_User/Datastream/Calcium/CalciumCouplingPolicy.hxx b/src/DSC/DSC_User/Datastream/Calcium/CalciumCouplingPolicy.hxx index e64db491f..a6c301ee6 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/CalciumCouplingPolicy.hxx +++ b/src/DSC/DSC_User/Datastream/Calcium/CalciumCouplingPolicy.hxx @@ -178,35 +178,51 @@ struct CalciumCouplingPolicy::BoundedDataIdProcessor{ MapIterator it2=it1; ++it2; size_t dataSize1 = DataManipulator::size(it1->second); +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Taille de donnée dataId1 : " << dataSize1 << std::endl; +#endif // Gérer dans calcium la limite de la taille du buffer donnée par // l'utilisateur. size_t dataSize2 = DataManipulator::size(it2->second); +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Taille de donnée dataId2 : " << dataSize2 << std::endl; +#endif size_t dataSize = std::min< size_t >( dataSize1, dataSize2 ); DataId dataId2 = it2->first; DataId dataId1 = it1->first; TimeType t2 = dataId2.first; TimeType t1 = dataId1.first; +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t1 : " << t1 << std::endl; std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t2 : " << t2 << std::endl; +#endif TimeType t = dataId.first; +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de t : " << t << std::endl; +#endif TimeType timeDiff = t2-t1; +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de timeDiff : " << timeDiff << std::endl; +#endif TimeType coeff = (t2-t)/timeDiff; +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Valeur de coeff : " << coeff << std::endl; +#endif InnerType const * const InIt1 = DataManipulator::getPointer(it1->second); +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données à t1 : " << std::endl; std::copy(InIt1,InIt1+dataSize1,std::ostream_iterator(std::cout," ")); std::cout << std::endl; +#endif InnerType const * const InIt2 = DataManipulator::getPointer(it2->second); +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données à t2 : " << std::endl; std::copy(InIt2,InIt2+dataSize2,std::ostream_iterator(std::cout," ")); std::cout << std::endl; +#endif Type dataOut = DataManipulator::create(dataSize); InnerType * const OutIt = DataManipulator::getPointer(dataOut); @@ -225,9 +241,11 @@ struct CalciumCouplingPolicy::BoundedDataIdProcessor{ // } } +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::BoundedDataIdProcessor : Données calculées à t : " << std::endl; std::copy(OutIt,OutIt+dataSize,std::ostream_iterator(std::cout," ")); std::cout << std::endl; +#endif data = dataOut; } @@ -248,8 +266,10 @@ bool CalciumCouplingPolicy::isDataIdConveniant( AssocContainer & storedDatas, co AdjacentFunctor< key_type > af(expectedDataId); if ( _dependencyType == CalciumTypes::TIME_DEPENDENCY ) { +#ifdef _DEBUG_ std::cout << "-------- time expected : " << expectedDataId.first << std::endl; std::cout << "-------- time expected corrected : " << expectedDataId.first*(1.0-_deltaT) << std::endl; +#endif af.setMaxValue(key_type(expectedDataId.first*(1.0-_deltaT),0)); } isBounded = false; @@ -273,7 +293,9 @@ bool CalciumCouplingPolicy::isDataIdConveniant( AssocContainer & storedDatas, co typename AssocContainer::iterator current = prev; while ( (current != storedDatas.end()) && !af(current->first) ) { +#ifdef _DEBUG_ std::cout << "------- stored time : " << current->first << std::endl; +#endif // if ( af(current->first) ) break; prev = current++; } @@ -290,7 +312,9 @@ bool CalciumCouplingPolicy::isDataIdConveniant( AssocContainer & storedDatas, co else wDataIt1 = storedDatas.end(); +#ifdef _DEBUG_ std::cout << "-------- isDataIdConvenient : isEqual : " << isEqual << " , isBounded " << isBounded << std::endl; +#endif return isEqual || isBounded; } @@ -318,7 +342,9 @@ struct CalciumCouplingPolicy::EraseDataIdProcessor { typedef typename Container::value_type value_type; typedef typename Container::iterator iterator; +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::eraseDataId, storedDatasSize : " << storedDatas.size() << std::endl; +#endif if ( _couplingPolicy._storageLevel == CalciumTypes::UNLIMITED_STORAGE_LEVEL ) return; @@ -327,8 +353,9 @@ struct CalciumCouplingPolicy::EraseDataIdProcessor { if (s > 0 ) { size_t dist=distance(storedDatas.begin(),wDataIt1); for (int i=0; i= expectedDataId iterator it1 = storedDatas.lower_bound(expectedDataId); +#ifdef _DEBUG_ std::cout << "-------- CalciumCouplingPolicy::DisconnectProcessor MARK5 " << std::endl; for (iterator it=storedDatas.begin();it!=storedDatas.end();++it) std::cout <<" "<<(*it).first ; std::cout < +//#define _DEBUG_ // Déplacer cette information dans CorbaTypeManipulator // Gérer en même temps la recopie profonde. @@ -85,9 +86,11 @@ public : // calcium_uses_port* myCalciumUsesPort= // dynamic_cast(myUsesPort); +#ifdef _DEBUG_ std::cerr << "-------- CalciumInterface(ecp_fin) MARK 1 -|"<< *it <<"|----"<< // typeid(myUsesPort).name() <<"-------------" << typeid(myCalciumUsesPort).name() <<"-------------" << std::endl; +#endif // if ( !myCalciumUsesPort ) // throw Superv_Component_i::BadCast(LOC(OSS()<<"Impossible de convertir le port " @@ -96,10 +99,14 @@ public : myCalciumUsesPort->disconnect(provideLastGivenValue); } catch ( const Superv_Component_i::BadCast & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif throw (CalciumException(CalciumTypes::CPTPVR,ex)); } catch ( const DSC_Exception & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif // Exception venant de SupervComponent : // PortNotDefined(CPNMVR), PortNotConnected(CPLIEN) // ou du port uses : Dsc_Exception @@ -171,26 +178,38 @@ public : CorbaDataType corbaData; long ilong; +#ifdef _DEBUG_ std::cerr << "-------- CalciumInterface(ecp_lecture) MARK 1 ------------------" << std::endl; +#endif if (nomVar.empty()) throw CalciumException(CalciumTypes::CPNMVR, LOC("Le nom de la variable est ")); PortType * port; +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 2 ------------------" << std::endl; +#endif try { port = component.Superv_Component_i::get_port< PortType > (nomVar.c_str()); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 3 ------------------" << std::endl; +#endif } catch ( const Superv_Component_i::PortNotDefined & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif throw (CalciumException(CalciumTypes::CPNMVR,ex)); } catch ( const Superv_Component_i::PortNotConnected & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl;; +#endif throw (CalciumException(CalciumTypes::CPLIEN,ex)); // VERIFIER LES CAS DES CODES : CPINARRET, CPSTOPSEQ, CPCTVR, CPLIEN } catch ( const Superv_Component_i::BadCast & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif throw (CalciumException(CalciumTypes::CPTPVR,ex)); } @@ -211,20 +230,30 @@ public : if ( dependencyType == CalciumTypes::TIME_DEPENDENCY ) { corbaData = port->get(ti,tf, 0); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 5 ------------------" << std::endl; +#endif } else if ( dependencyType == CalciumTypes::ITERATION_DEPENDENCY ) { corbaData = port->get(0, i); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 6 ------------------" << std::endl; +#endif } else { // Lecture en séquence +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 7 ------------------" << std::endl; +#endif corbaData = port->next(ti,i); } +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 8 ------------------" << std::endl; +#endif size_t corbaDataSize = DataManipulator::size(corbaData); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) corbaDataSize : " << corbaDataSize << std::endl; +#endif // Vérifie si l'utilisateur demande du 0 copie if ( data == NULL ) { @@ -234,10 +263,14 @@ public : nRead = corbaDataSize; // Si les types T et InnerType sont différents, il faudra effectuer tout de même une recopie if (!IsSameType::value) data = new T1[nRead]; +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 9 ------------------" << std::endl; +#endif // On essaye de faire du 0 copy si les types T et InnerType sont les mêmes Copy2UserSpace< IsSameType::value >::apply(data,corbaData,nRead); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 10 ------------------" << std::endl; +#endif // Attention : Seul CalciumCouplingPolicy via eraseDataId doit décider de supprimer ou non // la donnée corba associée à un DataId ! Ne pas effectuer la desallocation suivante : // old : Dans les deux cas la structure CORBA n'est plus utile @@ -247,18 +280,24 @@ public : // DataManipulator::delete_data(corbaData); } else { nRead = std::min < size_t > (corbaDataSize,bufferLength); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 11 ------------------" << std::endl; +#endif Copy2UserSpace::apply(data,corbaData,nRead); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture) MARK 12 ------------------" << std::endl; +#endif // Attention : Seul CalciumCouplingPolicy via eraseDataId doit décider de supprimer ou non // la donnée corba associée à un DataId ! Ne pas effectuer la desallocation suivante : // DataManipulator::delete_data(corbaData); } +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecp_lecture), Valeur de data : " << std::endl; std::copy(data,data+nRead,std::ostream_iterator(std::cout," ")); std::cout << "Ptr :" << data << std::endl; std::cout << "-------- CalciumInterface(ecp_lecture) MARK 13 ------------------" << std::endl; +#endif return; @@ -297,24 +336,36 @@ public : typedef typename DataManipulator::Type CorbaDataType; // Attention != T1 typedef typename DataManipulator::InnerType InnerType; +#ifdef _DEBUG_ std::cerr << "-------- CalciumInterface(ecriture) MARK 1 ------------------" << std::endl; +#endif if ( nomVar.empty() ) throw CalciumException(CalciumTypes::CPNMVR, LOC("Le nom de la variable est ")); PortType * port; +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 2 ------------------" << std::endl; +#endif try { port = component.Superv_Component_i::get_port< PortType > (nomVar.c_str()); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 3 ------------------" << std::endl; +#endif } catch ( const Superv_Component_i::PortNotDefined & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif throw (CalciumException(CalciumTypes::CPNMVR,ex)); } catch ( const Superv_Component_i::PortNotConnected & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl;; +#endif throw (CalciumException(CalciumTypes::CPLIEN,ex)); // VERIFIER LES CAS DES CODES : CPINARRET, CPSTOPSEQ, CPCTVR, CPLIEN } catch ( const Superv_Component_i::BadCast & ex) { +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif throw (CalciumException(CalciumTypes::CPTPVR,ex)); } @@ -357,7 +408,9 @@ public : LOC(OSS()<<"Le buffer a envoyer est de taille nulle ")); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 7 ------------------" << std::endl; +#endif CorbaDataType corbaData; @@ -388,23 +441,31 @@ public : port->put(*corbaData,t, -1); //Le -1 peut être traité par le cst DataIdContainer et transformé en 0 //Etre obligé de mettre une étoile ds (*corbadata) va poser des pb pour les types <> seq +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 5 ------------------" << std::endl; +#endif } else if ( dependencyType == CalciumTypes::ITERATION_DEPENDENCY ) { port->put(*corbaData,-1, i); +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 6 ------------------" << std::endl; +#endif } +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture), Valeur de corbaData : " << std::endl; for (int i = 0; i < corbaData->length(); ++i) cout << "-------- CalciumInterface(ecriture), corbaData[" << i << "] = " << (*corbaData)[i] << endl; +#endif // if ( !IsSameType::value ) delete corbaData; // Supprime l'objet CORBA avec eventuellement les données qu'il contient (case de la recopie) delete corbaData; +#ifdef _DEBUG_ std::cout << "-------- CalciumInterface(ecriture) MARK 7 ------------------" << std::endl; +#endif return; } @@ -436,12 +497,20 @@ ecp_fin_ (void * component, int code) { CalciumInterface::ecp_fin( *_component, provideLastGivenValue); } catch ( const CalciumException & ex) { //tester l'arrêt par exception +#ifdef _DEBUG_ std::cerr << ex.what() << std::endl; +#endif return ex.getInfo(); } return CalciumTypes::CPOK; }; +#ifdef _DEBUG_ +#define DEBTRACE(msg) {std::cerr<(dependencyType); \ \ if ( IsSameType< _name , cplx >::value ) _bufferLength*=2; \ - std::cout << "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" << std::endl; \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" ) \ try { \ CalciumInterface::ecp_lecture< _type, _name >( *_component, \ _dependencyType, \ @@ -466,22 +535,24 @@ ecp_fin_ (void * component, int code) { nomvar, \ _bufferLength, _nRead, *data); \ } catch ( const CalciumException & ex) { \ - std::cout << "-------- CalciumInterface(lecture Inter Part) MARK 1b ------------------" << std::endl; \ - std::cerr << ex.what() << std::endl; \ - std::cout << "-------- CalciumInterface(lecture Inter Part) MARK 1ter ------------------" << std::endl; \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1b ------------------" ) \ + DEBTRACE( ex.what() ) \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1ter ------------------" ) \ return ex.getInfo(); \ } \ if ( IsSameType< _name , cplx >::value ) { *nRead=_nRead/2; \ - std::cout << "-------- CalciumInterface(lecture Inter Part) IsSameType cplx -------------" << std::endl; \ - std::cout << "-------- CalciumInterface(lecture Inter Part) _nRead : " << _nRead << std::endl; \ - std::cout << "-------- CalciumInterface(lecture Inter Part) *nRead : " << *nRead << std::endl; \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) IsSameType cplx -------------" ) \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) _nRead : " << _nRead ) \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part) *nRead : " << *nRead ) \ } else *nRead = _nRead; \ if (_dependencyType == CalciumTypes::CP_SEQUENTIEL ) \ *ti=(CalTimeType< _type _qual >::TimeType)(_ti); \ - std::cout << "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data << std::endl; \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) \ + /* \ for (int i=0; i<_nRead;++i) \ printf("-------- CalciumInterface(lecture Inter Part), Valeur de data (typage entier) data[%d] : %d \n",i,(*data)[i]); \ - std::cout << "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data << std::endl; \ + */ \ + DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) \ return CalciumTypes::CPOK; \ }; \ extern "C" void ecp_lecture_##_name##_free ( _type _qual * data) { \ @@ -497,11 +568,11 @@ ecp_fin_ (void * component, int code) { double _t=*t; \ size_t _bufferLength=bufferLength; \ if ( IsSameType< _name , cplx >::value ) _bufferLength=_bufferLength*2; \ - std::cout << "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" << std::endl; \ + DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" ) \ try { \ - printf("-------- CalciumInterface(ecriture Inter Part), cp_name : Nom de la var. de type %s : %s\n",#_type,nomvar); \ + /*printf("-------- CalciumInterface(ecriture Inter Part), cp_name : Nom de la var. de type %s : %s\n",#_type,nomvar);*/ \ std::string essai(nomvar); \ - std::cout << "----------->-" << nomvar << std::endl; \ + DEBTRACE( "----------->-" << nomvar ) \ CalciumInterface::ecp_ecriture< _type, _name >( *_component, \ static_cast(dependencyType), \ _t,i,nomvar,_bufferLength,*data); \ @@ -509,11 +580,13 @@ ecp_fin_ (void * component, int code) { std::cerr << ex.what() << std::endl; \ return ex.getInfo(); \ } \ - std::cout << "-------- CalciumInterface(ecriture Inter Part), Valeur de data : " << std::endl; \ - std::cout << "-------- CalciumInterface(ecriture Inter Part), Ptr(1) :" << data << std::endl; \ + DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data : " ) \ + DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Ptr(1) :" << data ) \ + /* \ for (int i=0; i<_bufferLength;++i) \ printf("-------- CalciumInterface(ecriture Inter Part), Valeur de data (typage entier) data[%d] : %d \n",i,data[i]); \ - std::cout << "-------- CalciumInterface(ecriture Inter Part), Ptr(2) :" << data << std::endl; \ + */ \ + DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Ptr(2) :" << data ) \ return CalciumTypes::CPOK; \ }; \ diff --git a/src/DSC/DSC_User/Datastream/Calcium/CalciumTypes2CorbaTypes.cxx b/src/DSC/DSC_User/Datastream/Calcium/CalciumTypes2CorbaTypes.cxx index 0425a6baf..5cf6d10c5 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/CalciumTypes2CorbaTypes.cxx +++ b/src/DSC/DSC_User/Datastream/Calcium/CalciumTypes2CorbaTypes.cxx @@ -48,12 +48,14 @@ table[CalciumTypes::ITERATION_DEPENDENCY ] = Ports::Calcium_Ports::ITERATION_DEP table[CalciumTypes::UNDEFINED_DEPENDENCY ] = Ports::Calcium_Ports::UNDEFINED_DEPENDENCY ; +#ifdef _DEBUG_ std::cout << "CORBA_DEPENDENCY_TYPE() : table["<& ) *this ; +#ifdef _DEBUG_ std::cout << "CORBA_DEPENDENCY_TYPE() : ::operator["< MARK 1 ------------------" << std::endl; +#endif // Crée le type corba à partir du data sans lui en donner la propriété corbaData = DataManipulator::create(nRead,&data,false); +#ifdef _DEBUG_ std::cerr << "-------- Copy2CorbaSpace MARK 2 --(dataPtr : " << DataManipulator::getPointer(corbaData,false)<<")----------------" << std::endl; +#endif } }; @@ -68,11 +72,14 @@ Copy2CorbaSpace { corbaData = DataManipulator::create(nRead); InnerType * dataPtr = DataManipulator::getPointer(corbaData,false); +#ifdef _DEBUG_ std::cerr << "-------- Copy2CorbaSpace MARK 1 --(dataPtr : " << dataPtr<<")----------------" << std::endl; +#endif std::copy(&data,&data+nRead,dataPtr); +#ifdef _DEBUG_ std::cerr << "-------- Copy2CorbaSpace MARK 2 --(nRead: "< MARK 3 : " ; @@ -82,6 +89,7 @@ Copy2CorbaSpace { for (int i=0; i{ // Recopie des données dans le buffer allouée la méthode appelante // dans le cas d'une demande utilisateur 0 copie mais sur // des types utilisateurs et CORBA incompatibles. +#ifdef _DEBUG_ std::cerr << "-------- Copy2UserSpace MARK 1 --(dataPtr : " < MARK 2 --(nRead: "< MARK 3 --(data : " <(std::cout," ")); std::cout << std::endl; +#endif } }; diff --git a/src/DSC/DSC_User/Datastream/Calcium/CorbaTypes2CalciumTypes.cxx b/src/DSC/DSC_User/Datastream/Calcium/CorbaTypes2CalciumTypes.cxx index 1789bcf63..7c827dbb5 100644 --- a/src/DSC/DSC_User/Datastream/Calcium/CorbaTypes2CalciumTypes.cxx +++ b/src/DSC/DSC_User/Datastream/Calcium/CorbaTypes2CalciumTypes.cxx @@ -48,12 +48,14 @@ table[Ports::Calcium_Ports::ITERATION_DEPENDENCY ] = CalciumTypes::ITERATION_DEP table[Ports::Calcium_Ports::UNDEFINED_DEPENDENCY ] = CalciumTypes::UNDEFINED_DEPENDENCY ; +#ifdef _DEBUG_ std::cout << "DEPENDENCY_TYPE() : table["< &table = (map&)*this ; +#ifdef _DEBUG_ std::cout << "DEPENDENCY_TYPE() : ::operator["< +#include +#include +#include +#include + +static void* COMPO=0; + +#ifdef __cplusplus +extern "C" { +#endif + +static void fstrtocstr(char *cstr, char *fstr,int fstr_len) +{ + int i,iend; + for (iend = fstr_len-1; iend >= 0; iend--) + if (fstr[iend] != ' ') break; + for (i = 0; i <= iend; i++) + cstr[i] = fstr[i]; + cstr[i] = '\0'; +} + +static void cstrtofstr(char *cstr, char *fstr,int fstr_len) +{ + int i, len; + len = strlen(cstr); + if (len > fstr_len) len = fstr_len; + for (i = 0; i < len; i++) + fstr[i] = cstr[i]; + while (i < fstr_len) + fstr[i++] = ' '; +} + +static char * fstr1(char *nom,int nnom) +{ + char * cnom=(char*)malloc((nnom+1)*sizeof(char)); + fstrtocstr(cnom,nom,nnom); + return cnom; +} + +static char * free_str1(char *nom) +{ + free(nom); +} + +void F_FUNC(cpcd,CPCD)(long *compo,STR_PSTR(nom),int *info STR_PLEN(nom)) +{ + /* nom is OUT argument */ + cp_cd((void *)*compo,STR_PTR(nom)); + /* replace in place ??? */ + cstrtofstr(STR_PTR(nom),STR_PTR(nom),STR_LEN(nom)); +} + +void F_FUNC(cplen,CPLEN)(long *compo,int *dep,float *ti,float *tf,int *iter,STR_PSTR(nom), + int *max,int *n, int *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPLEN: %s %f %f\n",cnom,*ti,*tf); + *err=cp_len((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); + fprintf(stderr,"End of CPLEN: %s \n",cnom); + free_str1(cnom); +} + +void F_FUNC(cpldb,CPLDB)(long *compo,int *dep,double *ti,double *tf,int *iter,STR_PSTR(nom), + int *max,int *n, double *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPLDB: %s %f %f \n",cnom, *ti,*tf); + *err=cp_ldb((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); + fprintf(stderr,"End of CPLDB: %s %f %f \n",cnom,*ti,*tf); + free_str1(cnom); +} + +void F_FUNC(cplre,CPLRE)(long *compo,int *dep,float *ti,float *tf,int *iter,STR_PSTR(nom), + int *max,int *n, float *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPLRE: %s %f %f \n",cnom, *ti,*tf); + *err=cp_lre((void *)*compo,*dep,ti,tf,iter,cnom,*max,n,tab); + fprintf(stderr,"End of CPLRE: %s %f %f \n",cnom,*ti,*tf); + free_str1(cnom); +} + +void F_FUNC(cpedb,CPEDB)(long *compo,int *dep,double *ti,int *iter,STR_PSTR(nom),int *n, double *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPEDB: %s %f \n",cnom, *ti); + *err=cp_edb((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); + fprintf(stderr,"End of CPEDB: %s %f \n",cnom, *ti); + free_str1(cnom); +} + +void F_FUNC(cpere,CPERE)(long *compo,int *dep,float *ti,int *iter,STR_PSTR(nom),int *n, float *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPERE: %s %f \n",cnom, *ti); + *err=cp_ere((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); + fprintf(stderr,"End of CPERE: %s %f \n",cnom, *ti); + free_str1(cnom); +} + +void F_FUNC(cpeen,CPEEN)(long *compo,int *dep,float *ti,int *iter,STR_PSTR(nom),int *n, int *tab,int *err STR_PLEN(nom)) +{ + char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom)); + fprintf(stderr,"CPEEN: %s %f %d\n",cnom, *ti,*iter); + *err=cp_een((void *)*compo,*dep,*ti,*iter,cnom,*n,tab); + fprintf(stderr,"End of CPEEN: %s %f \n",cnom,*ti); + free_str1(cnom); +} + +void F_FUNC(cpfin,CPFIN)(long *compo,int *dep,int *err) +{ + fprintf(stderr,"CPFIN: \n"); + *err=cp_fin((void *)*compo,*dep); +} + +#ifdef __cplusplus +} +#endif + diff --git a/src/DSC/DSC_User/Datastream/Calcium/fortoc.h b/src/DSC/DSC_User/Datastream/Calcium/fortoc.h new file mode 100644 index 000000000..67b45336d --- /dev/null +++ b/src/DSC/DSC_User/Datastream/Calcium/fortoc.h @@ -0,0 +1,20 @@ + +#ifndef FORTRAN_H +#define FORTRAN_H + +/* Operateur de concatenation */ +#define _(A,B) A##B + +#ifdef __linux +#define F_FUNC(lname,uname) _(lname,_) /* Fortran function name */ +#define F_CALL(lname,uname) _(lname,_) /* Fortran function call */ +#define STR_PSTR(str) char *str /* fortran string arg pointer */ +#define STR_PLEN(str) , int _(Len,str) /* fortran string arg length */ +#define STR_PTR(str) str /* fortran string pointer */ +#define STR_LEN(str) _(Len,str) /* fortran string length */ + + +#endif + +#endif + diff --git a/src/DSC/DSC_User/Datastream/CorbaTypeManipulator.hxx b/src/DSC/DSC_User/Datastream/CorbaTypeManipulator.hxx index 21fe061ee..a60cf98b3 100644 --- a/src/DSC/DSC_User/Datastream/CorbaTypeManipulator.hxx +++ b/src/DSC/DSC_User/Datastream/CorbaTypeManipulator.hxx @@ -214,9 +214,13 @@ public: // ATTENTION TESTER p184 si le pointeur est null // ATTENTION TESTER Si le flag release si la sequence contient des chaines // ou des object refs +#ifdef _DEBUG_ std::cout << "----seq_u_manipulation::get_data(..)-- MARK 1 ------------------" << std::endl; +#endif InnerType * p_data = const_cast(data).get_buffer(true); +#ifdef _DEBUG_ std::cout << "----seq_u_manipulation::get_data(..)-- MARK 2 ------"<< p_data <<"------------" << std::endl; +#endif // Crée une nouvelle sequence propriétaire des données du buffer (pas de recopie) // Les données seront automatiquement désallouées par appel interne à la méthode freebuf diff --git a/src/DSC/DSC_User/Datastream/GenericPort.hxx b/src/DSC/DSC_User/Datastream/GenericPort.hxx index cc9a7e7eb..6148b8f8f 100644 --- a/src/DSC/DSC_User/Datastream/GenericPort.hxx +++ b/src/DSC/DSC_User/Datastream/GenericPort.hxx @@ -120,11 +120,15 @@ GenericPort::close (PortableServer::POA_var po template < typename DataManipulator, typename COUPLING_POLICY> void GenericPort::wakeupWaiting() { +#ifdef _DEBUG_ std::cout << "-------- wakeupWaiting ------------------" << std::endl; +#endif storedDatas_mutex.lock(); if (waitingForAnyDataId || waitingForConvenientDataId) { +#ifdef _DEBUG_ std::cout << "-------- wakeupWaiting:signal --------" << std::endl; std::cout << std::flush; +#endif cond_instance.signal(); } storedDatas_mutex.unlock(); @@ -144,9 +148,11 @@ void GenericPort::put(CorbaInDataType dataPara fflush(stdout); fflush(stderr); try { +#ifdef _DEBUG_ // Affichage des donnees pour DEBUGging cerr << "parametres emis: " << time << ", " << tag << endl; DataManipulator::dump(dataParam); +#endif // L'intérêt des paramètres time et tag pour ce port est décidé dans la politique de couplage // Il est possible de filtrer en prenant en compte uniquement un paramètre time/tag ou les deux @@ -165,9 +171,13 @@ void GenericPort::put(CorbaInDataType dataPara bool expectedDataReceived = false; +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 1 ------------------" << std::endl; +#endif if ( dataIds.empty() ) return; +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 1bis ------------------" << std::endl; +#endif // Recupere les donnees venant de l'ORB et relâche les structures CORBA // qui n'auraient plus cours en sortie de méthode put @@ -176,22 +186,30 @@ void GenericPort::put(CorbaInDataType dataPara int nbOfIter = 0; +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 2 ------ "<< (dataIdIt == dataIds.end()) << "------------" << std::endl; std::cout << "-------- Put : MARK 2bis "<< (*dataIdIt) <<"------------------" << std::endl; +#endif storedDatas_mutex.lock(); for (;dataIdIt != dataIds.end();++dataIdIt) { +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 3 ------------------" << std::endl; +#endif // Duplique l'instance de donnée pour les autres dataIds if (nbOfIter > 0) data = DataManipulator::clone(data); +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 3bis -----"<< dataIdIt.operator*() <<"------------" << std::endl; +#endif DataId currentDataId=*dataIdIt; +#ifdef _DEBUG_ std::cerr << "processing dataId : "<< currentDataId << std::endl; std::cout << "-------- Put : MARK 4 ------------------" << std::endl; +#endif // Ajoute l'instance de la donnee a sa place dans la table de données // ou remplace une instance précédente si elle existe @@ -201,18 +219,24 @@ void GenericPort::put(CorbaInDataType dataPara // <=> premier emplacement où l'on pourrait insérer notre DataId // <=> en général équivaux à (*wDataIt).first >= currentDataId typename DataTable::iterator wDataIt = storedDatas.lower_bound(currentDataId); +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 5 ------------------" << std::endl; +#endif // On n'a pas trouvé de dataId supérieur au notre ou // on a trouvé une clé > à cet Id if (wDataIt == storedDatas.end() || storedDatas.key_comp()(currentDataId,(*wDataIt).first) ) { +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 6 ------------------" << std::endl; +#endif // Ajoute la donnee dans la table wDataIt = storedDatas.insert(wDataIt, make_pair (currentDataId, data)); } else { // Si on n'est pas en fin de liste et qu'il n'y a pas de relation d'ordre strict // entre notre dataId et le DataId pointé c'est qu'ils sont identiques +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 7 ------------------" << std::endl; +#endif // Les données sont remplacées par les nouvelles valeurs // lorsque que le dataId existe déjà DataType old_data = (*wDataIt).second; @@ -221,15 +245,19 @@ void GenericPort::put(CorbaInDataType dataPara DataManipulator::delete_data (old_data); } +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 8 ------------------" << std::endl; +#endif // Compte le nombre de dataIds à traiter ++nbOfIter; +#ifdef _DEBUG_ std::cout << "-------- Put : waitingForConvenientDataId : " << waitingForConvenientDataId <<"---" << std::endl; std::cout << "-------- Put : waitingForAnyDataId : " << waitingForAnyDataId <<"---" << std::endl; std::cout << "-------- Put : currentDataId : " << currentDataId <<"---" << std::endl; std::cout << "-------- Put : expectedDataId : " << expectedDataId <<"---" << std::endl; std::cout << "-------- Put : MARK 9 ------------------" << std::endl; +#endif // A simplifier mais : // - pas possible de mettre des arguments optionnels à cause @@ -248,14 +276,18 @@ void GenericPort::put(CorbaInDataType dataPara ( waitingForConvenientDataId && isDataIdConveniant(storedDatas, expectedDataId, dummy1, dummy2, dummy3) ) ) { +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 10 ------------------" << std::endl; +#endif //Doit pouvoir réveiller le get ici (a vérifier) expectedDataReceived = true; } } if (expectedDataReceived) { +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 11 ------------------" << std::endl; +#endif // si waitingForAnyDataId était positionné, c'est forcément lui qui a activer // expectedDataReceived à true if (waitingForAnyDataId) @@ -271,16 +303,22 @@ void GenericPort::put(CorbaInDataType dataPara // Pb2 : également si deux attentes de DataIds même différents car on n'en stocke qu'un ! // Conclusion : Pour l'instant on ne gère pas un service multithreadé qui effectue // des lectures simultanées sur le même port ! +#ifdef _DEBUG_ std::cout << "-------- Put : new datas available ------------------" << std::endl; +#endif fflush(stdout);fflush(stderr); cond_instance.signal(); } +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 12 ------------------" << std::endl; +#endif // Deverouille l'acces a la table : On peut remonter l'appel au dessus de expected... storedDatas_mutex.unlock(); +#ifdef _DEBUG_ std::cout << "-------- Put : MARK 13 ------------------" << std::endl; +#endif fflush(stdout); fflush(stderr); @@ -288,7 +326,6 @@ void GenericPort::put(CorbaInDataType dataPara catch ( const SALOME_Exception & ex ) { // On évite de laisser un mutex storedDatas_mutex.unlock(); - std::cerr << ex; THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); } @@ -318,9 +355,13 @@ GenericPort::get(TimeType time, bool isEqual, isBounded; typedef typename DataManipulator::InnerType InnerType; +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 1 ------------------" << std::endl; +#endif expectedDataId = DataId(time,tag); +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 2 ------------------" << std::endl; +#endif typename DataTable::iterator wDataIt1; @@ -336,18 +377,23 @@ GenericPort::get(TimeType time, // - l'itérateur wDataIt1 est tel que wDataIt1->first < wdataId < (wDataIt1+1)->first // Méthode provenant de la COUPLING_POLICY isDataIdConveniant(storedDatas,expectedDataId,isEqual,isBounded,wDataIt1); +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 3 ------------------" << std::endl; +#endif // L'ordre des différents tests est important if ( isEqual ) { +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 4 ------------------" << std::endl; +#endif // La propriété de la données N'EST PAS transmise à l'utilisateur en mode CALCIUM. // Si l'utilisateur supprime la donnée, storedDataIds devient incohérent // C'est EraseDataId qui choisi ou non de supprimer la donnée // Du coup interaction potentielle entre le 0 copy et gestion de l'historique dataToTransmit = (*wDataIt1).second; +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 5 ------------------" << std::endl; std::cout << "-------- Get : Données trouvées à t : " << std::endl; typename DataManipulator::InnerType const * const InIt1 = DataManipulator::getPointer(dataToTransmit); @@ -355,17 +401,22 @@ GenericPort::get(TimeType time, std::copy(InIt1, InIt1 + N, std::ostream_iterator< InnerType > (std::cout," ")); std::cout << std::endl; +#endif // Décide de la suppression de certaines instances de données // La donnée contenu dans la structure CORBA et son dataId sont désallouées // Méthode provenant de la COUPLING_POLICY typename COUPLING_POLICY::template EraseDataIdProcessor processEraseDataId(*this); processEraseDataId.apply(storedDatas,wDataIt1); +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 6 ------------------" << std::endl; +#endif break; } +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 7 ------------------" << std::endl; +#endif //if ( isBounded() && COUPLING_POLICY::template needToProcessBoundedDataId() ) { // Le DataId demandé n'est pas trouvé mais est encadré ET la politique de couplage @@ -379,7 +430,9 @@ GenericPort::get(TimeType time, // l'interpolation. // Les données calciulées sont donc stockées dans storedDatas. // La propriété des données N'EST PAS transférée à l'utilisateur en mode CALCIUM. +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 8 ------------------" << std::endl; +#endif typename COUPLING_POLICY::template BoundedDataIdProcessor processBoundedDataId(*this); //si static BDIP::apply(dataToTransmit,expectedDataId,wDataIt1); @@ -392,6 +445,7 @@ GenericPort::get(TimeType time, // A déplacer en paramètre de la méthode précédente ? storedDatas[expectedDataId]=dataToTransmit; +#ifdef _DEBUG_ std::cout << "-------- Get : Données calculées à t : " << std::endl; typename DataManipulator::InnerType const * const InIt1 = DataManipulator::getPointer(dataToTransmit); size_t N = DataManipulator::size(dataToTransmit); @@ -400,6 +454,7 @@ GenericPort::get(TimeType time, std::ostream_iterator< InnerType > (std::cout," ")); std::cout << std::endl; std::cout << "-------- Get : MARK 9 ------------------" << std::endl; +#endif typename COUPLING_POLICY::template EraseDataIdProcessor processEraseDataId(*this); processEraseDataId.apply(storedDatas,wDataIt1); @@ -414,17 +469,23 @@ GenericPort::get(TimeType time, // Réception bloquante sur le dataId demandé // Si l'instance de donnée n'est pas trouvee +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 10 ------------------" << std::endl; +#endif //Positionné à faux dans la méthode put waitingForConvenientDataId = true; +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 11 ------------------" << std::endl; // Ici on attend que la méthode put recoive la donnée std::cout << "-------- Get : waiting datas ------------------" << std::endl; +#endif fflush(stdout);fflush(stderr); cond_instance.wait(); +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 12 ------------------" << std::endl; +#endif } } catch (...) { @@ -435,7 +496,9 @@ GenericPort::get(TimeType time, // Deverouille l'acces a la table storedDatas_mutex.unlock(); +#ifdef _DEBUG_ std::cout << "-------- Get : MARK 13 ------------------" << std::endl; +#endif // La propriété de la données N'EST PAS transmise à l'utilisateur en mode CALCIUM // Si l'utilisateur supprime la donnée, storedDataIds devient incohérent @@ -472,7 +535,9 @@ GenericPort::next(TimeType &t, try { storedDatas_mutex.lock();// Gérer les Exceptions ds le corps de la méthode +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 1 ---lastDataIdSet ("<::next(TimeType &t, waitingForAnyDataId = false; break; } +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 2 ------------------" << std::endl; +#endif //Positionné à faux dans la méthode put waitingForAnyDataId = true; +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 3 ------------------" << std::endl; // Ici on attend que la méthode put recoive la donnée std::cout << "-------- Next : waiting datas ------------------" << std::endl; +#endif fflush(stdout);fflush(stderr); cond_instance.wait(); if (lastDataIdSet) { +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 4 ------------------" << std::endl; +#endif wDataIt1 = storedDatas.upper_bound(lastDataId); } else { +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 5 ------------------" << std::endl; +#endif lastDataIdSet = true; wDataIt1 = storedDatas.begin(); } } +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 6 ------------------" << std::endl; +#endif t = getTime( (*wDataIt1).first ); tag = getTag ( (*wDataIt1).first ); dataToTransmit = (*wDataIt1).second; +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 7 ------------------" << std::endl; +#endif lastDataId = (*wDataIt1).first; typename COUPLING_POLICY::template EraseDataIdProcessor processEraseDataId(*this); processEraseDataId.apply(storedDatas, wDataIt1); +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 8 ------------------" << std::endl; +#endif } catch (...) { +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 8bis ------------------" << std::endl; +#endif waitingForAnyDataId = false; storedDatas_mutex.unlock(); throw; } storedDatas_mutex.unlock(); +#ifdef _DEBUG_ std::cout << "-------- Next : MARK 9 ------------------" << std::endl; +#endif // La propriété de la données N'EST PAS transmise à l'utilisateur en mode CALCIUM // Si l'utilisateur supprime la donnée, storedDataIds devient incohérent diff --git a/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx b/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx index 43357dc2e..8d186c509 100644 --- a/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx +++ b/src/DSC/DSC_User/Datastream/GenericUsesPort.hxx @@ -123,11 +123,13 @@ GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put CorbaPortTypePtr port = CorbaPortType::_narrow((*_my_ports)[i]); //if (i) { PB1 copyOfData = DataManipulator::clone(data); +#ifdef _DEBUG_ std::cout << "-------- GenericUsesPort::put : Copie de data(" //<< DataManipulator::getPointer(data) <<") vers copyOfData (" <put(*copyOfData,time,tag); // catcher les exceptions @@ -154,7 +156,9 @@ GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort { if (_my_ports) delete _my_ports; +#ifdef _DEBUG_ std::cerr << "GenericUsesPort::uses_port_changed" << endl; +#endif _my_ports = new Engines::DSC::uses_port(*new_uses_port); } diff --git a/src/DSC/DSC_User/Makefile.am b/src/DSC/DSC_User/Makefile.am index ec9ce2fbc..37d753254 100644 --- a/src/DSC/DSC_User/Makefile.am +++ b/src/DSC/DSC_User/Makefile.am @@ -23,7 +23,6 @@ # Author : André RIBES (EDF) # Module : KERNEL -SUBDIRS = Basic Datastream include $(top_srcdir)/salome_adm/unix/make_common_starter.am @@ -93,3 +92,4 @@ test_DSC_Exception_CXXFLAGS = $(COMMON_CPPFLAGS) test_DSC_Exception_LDADD = $(top_builddir)/src/Utils/libOpUtil.la +SUBDIRS = Basic Datastream diff --git a/src/DSC/DSC_User/Superv_Component_i.cxx b/src/DSC/DSC_User/Superv_Component_i.cxx index 2892ddabf..187657c2c 100644 --- a/src/DSC/DSC_User/Superv_Component_i.cxx +++ b/src/DSC/DSC_User/Superv_Component_i.cxx @@ -43,7 +43,9 @@ Superv_Component_i::Superv_Component_i(CORBA::ORB_ptr orb, bool notif) : Engines_DSC_i(orb, poa, contId, instanceName, interfaceName) { +#ifdef _DEBUG_ std::cout << "--Superv_Component_i : MARK 1 ---- " << instanceName << "----" << std::endl; +#endif _my_basic_factory = new basic_port_factory(); _my_palm_factory = new palm_port_factory(); _my_calcium_factory = new calcium_port_factory(); @@ -105,7 +107,9 @@ throw (BadFabType) search_result = the_type.find("CALCIUM_"); if (search_result == 0) { +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::create_uses_data_port : MARK 1 ---- " << the_type.substr(search_result+8, the_type.length()) << "----" << std::endl; +#endif rtn_proxy = _my_calcium_factory->create_data_proxy(the_type.substr(search_result+8, the_type.length())); } @@ -132,9 +136,13 @@ Superv_Component_i::add_port(const char * port_fab_type, add_port(port, port_name); } else if (s_port_type == "uses") { +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::add_port : MARK 1 ---- " << std::endl; +#endif uses_port * port = create_uses_data_port(port_fab_type); +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::add_port : MARK 2 ---- " << std::endl; +#endif add_port(port, port_name); } else diff --git a/src/DSC/DSC_User/Superv_Component_i.hxx b/src/DSC/DSC_User/Superv_Component_i.hxx index 1ee77c610..8b46949ba 100644 --- a/src/DSC/DSC_User/Superv_Component_i.hxx +++ b/src/DSC/DSC_User/Superv_Component_i.hxx @@ -273,7 +273,9 @@ Superv_Component_i::add_port(const char * port_fab_type, assert(port_name); SpecificPortType * retPort; +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::add_port : Mark 0 ---- " << port_name << "----" << std::endl; +#endif std::string s_port_type(port_type); if (s_port_type == "provides") { @@ -287,10 +289,14 @@ Superv_Component_i::add_port(const char * port_fab_type, else if (s_port_type == "uses") { uses_port * port = create_uses_data_port(port_fab_type); add_port(port, port_name); +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::add_port : Mark 1 ---- " << port << "----" << std::endl; std::cout << "---- Superv_Component_i::add_port : Mark 1 ---- get_repository_id()" << port->get_repository_id() << std::endl; +#endif retPort = dynamic_cast(port); +#ifdef _DEBUG_ std::cout << "---- Superv_Component_i::add_port : Mark 2 ---- " << retPort << "----" << std::endl; +#endif if ( retPort == NULL ) { delete port; throw BadCast( LOC("La conversion vers le type de port demandé n'est pas possible " )); } diff --git a/src/DSC/Makefile.am b/src/DSC/Makefile.am index fb949237f..edc4849c7 100644 --- a/src/DSC/Makefile.am +++ b/src/DSC/Makefile.am @@ -27,4 +27,4 @@ if WITH_PACO_PARALLEL SUBDIR_PAR = ParallelDSC endif -SUBDIRS = DSC_Basic DSC_User $(SUBDIR_PAR) +SUBDIRS = DSC_Basic DSC_User $(SUBDIR_PAR) DSC_Python diff --git a/src/DSC/ParallelDSC/ParallelDSC_i.cxx b/src/DSC/ParallelDSC/ParallelDSC_i.cxx index eba3c8e55..c4f15adb5 100644 --- a/src/DSC/ParallelDSC/ParallelDSC_i.cxx +++ b/src/DSC/ParallelDSC/ParallelDSC_i.cxx @@ -34,8 +34,9 @@ Engines_ParallelDSC_i::Engines_ParallelDSC_i(CORBA::ORB_ptr orb, char * ior, Engines_Parallel_Component_i(orb, ior, poa, contId, instanceName, interfaceName, notif), Engines::Parallel_DSC_serv(orb, ior), Engines::DSC_serv(orb, ior), -// Engines::Superv_Component_serv(orb, ior), + Engines::Superv_Component_serv(orb, ior), Engines::Component_serv(orb, ior), + Engines::Parallel_Component_serv(orb, ior), InterfaceParallel_impl(orb,ior) { } diff --git a/src/DSC/ParallelDSC/ParallelDSC_i.hxx b/src/DSC/ParallelDSC/ParallelDSC_i.hxx index 0524de5ea..ed900566f 100644 --- a/src/DSC/ParallelDSC/ParallelDSC_i.hxx +++ b/src/DSC/ParallelDSC/ParallelDSC_i.hxx @@ -49,8 +49,6 @@ public: virtual ~Engines_ParallelDSC_i(); - //virtual CORBA::Boolean init_service(const char* service_name) {return true;} - /*! * \see Engines::DSC::add_provides_port */ diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index 4d3d58f39..1408f71be 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -26,16 +26,20 @@ #include "HDFOI.hxx" -#include -#include -#include -#include -#include +//#include +//#include +//#include +//#include +//#include #include #include #include #include +#include +#include +#include +#include #ifdef WNT #include @@ -57,6 +61,9 @@ char* makeName(char* name); char* restoreName(char* name); void write_float64(FILE* fp, hdf_float64* value); void read_float64(FILE* fp, hdf_float64* value); +bool directoryExists(const char* dir); +bool createDirectory(const char* dir); +bool is_readable( const std::string & file ); #define MAX_STRING_SIZE 65535 #define MAX_ID_SIZE 20 @@ -104,13 +111,15 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, bool isReplace, const char* theExtension) { - TCollection_AsciiString aPath((char*)thePath); + //TCollection_AsciiString aPath((char*)thePath); + std::string aPath((char*)thePath); if(!isReplace) { if(theExtension == NULL) aPath += ".asc"; else aPath += (char*)theExtension; } - TCollection_AsciiString aFileName(aPath); + //TCollection_AsciiString aFileName(aPath); + std::string aFileName(aPath); if(isReplace) aFileName=aPath+".ascii_tmp"; HDFfile *hdf_file = new HDFfile((char*)thePath); @@ -119,7 +128,8 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, char name[HDF_NAME_MAX_LEN+1]; int nbsons = hdf_file->nInternalObjects(), nbAttr = hdf_file->nAttributes(); - FILE* fp = fopen(aFileName.ToCString(), "w"); + //FILE* fp = fopen(aFileName.ToCString(), "w"); + FILE* fp = fopen(aFileName.c_str(), "w"); fprintf(fp, "%s\n", ASCIIHDF_ID); fprintf(fp, "%i\n", nbsons+nbAttr); @@ -131,7 +141,8 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, hdf_attribute = 0; } - for (Standard_Integer i=0; iInternalObjectIndentify(i,name); if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue; @@ -156,17 +167,24 @@ char* HDFascii::ConvertFromHDFToASCII(const char* thePath, delete hdf_file; if(isReplace) { - OSD_Path anOSDPath(aFileName); - OSD_File anOSDFile(anOSDPath); - if(anOSDFile.Exists()) - anOSDFile.Move(aPath); - else +// OSD_Path anOSDPath(aFileName); +// OSD_File anOSDFile(anOSDPath); +// if(anOSDFile.Exists()) +// anOSDFile.Move(aPath); +// else +// return NULL; + if(access (aFileName.c_str() , F_OK ) == 0) { + rename(aFileName.c_str(), aPath.c_str()); + } + else return NULL; } - int length = strlen(aPath.ToCString()); + //int length = strlen(aPath.ToCString()); + int length = strlen(aPath.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aPath.ToCString()) ; + //strcpy(new_str , aPath.ToCString()) ; + strcpy(new_str , aPath.c_str()) ; return new_str; } @@ -180,7 +198,10 @@ void SaveGroupInASCIIfile(HDFgroup *hdf_group, FILE* fp, int ident) { hdf_group->OpenOnDisk(); - TCollection_AsciiString anIdent(ident, '\t'); + //TCollection_AsciiString anIdent(ident, '\t'); + std::ostringstream oss; + oss << ident; + std::string anIdent(oss.str()); int nbsons = hdf_group->nInternalObjects(), nbAttr = hdf_group->nAttributes(); /*fprintf(fp, "%s%s\n", anIdent.ToCString(), GROUP_ID);*/ @@ -241,8 +262,14 @@ void SaveDatasetInASCIIfile(HDFdataset *hdf_dataset, FILE* fp, int ident) hdf_byte_order order = hdf_dataset->GetOrder(); int nbAttr = hdf_dataset->nAttributes(); - TCollection_AsciiString anIdent(ident, '\t'); - TCollection_AsciiString anIdentChild(ident+1, '\t'); +// TCollection_AsciiString anIdent(ident, '\t'); +// TCollection_AsciiString anIdentChild(ident+1, '\t'); + std::ostringstream oss; + std::ostringstream oss2; + oss << ident; + oss2 << ident+1; + std::string anIdent(oss.str()); + std::string anIdentChild(oss2.str()); char* name = makeName(hdf_dataset->GetName()); @@ -341,8 +368,14 @@ void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident) hdf_type type = hdf_attribute->GetType(); - TCollection_AsciiString anIdent(ident, '\t'); - TCollection_AsciiString anIdentChild(ident+1, '\t'); + //TCollection_AsciiString anIdent(ident, '\t'); + //TCollection_AsciiString anIdentChild(ident+1, '\t'); + std::ostringstream oss; + std::ostringstream oss2; + oss << ident; + oss2 << ident+1; + std::string anIdent(oss.str()); + std::string anIdentChild(oss2.str()); char* name = makeName(hdf_attribute->GetName()); int size = hdf_attribute->GetSize(); @@ -397,11 +430,15 @@ void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident) char* HDFascii::ConvertFromASCIIToHDF(const char* thePath) { // Get a temporary directory to store a file - TCollection_AsciiString aTmpDir = GetTmpDir(), aFileName("hdf_from_ascii.hdf"); + //TCollection_AsciiString aTmpDir = GetTmpDir(), aFileName("hdf_from_ascii.hdf"); + std::string aTmpDir = GetTmpDir(); + std::string aFileName("hdf_from_ascii.hdf"); // Build a full file name of temporary file - TCollection_AsciiString aFullName = aTmpDir + aFileName; + //TCollection_AsciiString aFullName = aTmpDir + aFileName; + std::string aFullName = aTmpDir + aFileName; - HDFfile *hdf_file = new HDFfile(aFullName.ToCString()); + //HDFfile *hdf_file = new HDFfile(aFullName.ToCString()); + HDFfile *hdf_file = new HDFfile((char *) aFullName.c_str()); hdf_file->CreateOnDisk(); FILE *fp = fopen(thePath, "r"); @@ -450,9 +487,15 @@ char* HDFascii::ConvertFromASCIIToHDF(const char* thePath) hdf_file->CloseOnDisk(); delete hdf_file; - int length = strlen(aTmpDir.ToCString()); + //int length = strlen(aTmpDir.ToCString()); + int length = strlen(aTmpDir.c_str()); + cerr << "length : " << length << endl; char *new_str = new char[ 1+length ]; - strcpy(new_str , aTmpDir.ToCString()) ; + //strcpy(new_str , aTmpDir.ToCString()) ; + strcpy(new_str , aTmpDir.c_str()) ; + + cerr << "test ::: " << aTmpDir << endl; + cerr << "test ::: " << new_str << endl; return new_str; } @@ -677,83 +720,115 @@ char* GetTmpDir() { //Find a temporary directory to store a file - TCollection_AsciiString aTmpDir; + //TCollection_AsciiString aTmpDir; + std::string aTmpDir; #ifdef WNT char *aTmp; aTmp = getenv("TMP"); - if(aTmp != NULL) - aTmpDir = TCollection_AsciiString(aTmp); - else - aTmpDir = TCollection_AsciiString("C:\\"); + if(aTmp != NULL) { +// aTmpDir = TCollection_AsciiString(aTmp); + aTmpDir = std::string(aTmp); + } + else { +// aTmpDir = TCollection_AsciiString("C:\\"); + aTmpDir = std::string("C:\\"); + } #else - aTmpDir = TCollection_AsciiString("/tmp/"); + //aTmpDir = TCollection_AsciiString("/tmp/"); + aTmpDir = std::string("/tmp/"); #endif srand((unsigned int)time(NULL)); int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory - TCollection_AsciiString aSubDir(aRND); - if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); +// TCollection_AsciiString aSubDir(aRND); +// if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); + std::ostringstream oss; + oss << aRND; + std::string aSubDir(oss.str()); + if(aSubDir.length() <= 1) aSubDir = std::string("123409876"); aTmpDir += aSubDir; //Get RND sub directory #ifdef WIN32 - if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +// if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; + if(aTmpDir[aTmpDir.length()-1] != '\\') aTmpDir+='\\'; #else - if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +// if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; + if(aTmpDir[aTmpDir.length()-1] != '/') aTmpDir+='/'; #endif - OSD_Path aPath(aTmpDir); - OSD_Directory aDir(aPath); +// OSD_Path aPath(aTmpDir); +// OSD_Directory aDir(aPath); + std::string aDir(aTmpDir); - for(aRND = 0; aDir.Exists(); aRND++) { - aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name - aPath = OSD_Path(aTmpDir); - aDir = OSD_Directory(aPath); - } + //std::cerr << "temp dir .... : " << aTmpDir << std::endl; - OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); - aDir.Build(aProtection); + for(aRND = 0; directoryExists(aDir.c_str()); aRND++) { + //aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name + aTmpDir.insert((aTmpDir.length() - 1), oss.str()); //Build a unique directory name + std::cerr << "Tempory directory exist, changing name ..." << std::endl; + std::cerr << "temp dir .... : " << aTmpDir << std::endl; + aDir = std::string(aTmpDir); +// aPath = OSD_Path(aTmpDir); +// aDir = OSD_Directory(aPath); + } - int length = strlen(aTmpDir.ToCString()); + //OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); + //aDir.Build(aProtection); + createDirectory(aDir.c_str()); + //int length = strlen(aTmpDir.ToCString()); + int length = strlen(aTmpDir.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aTmpDir.ToCString()); - + //strcpy(new_str , aTmpDir.ToCString()); + strcpy(new_str , aTmpDir.c_str()); return new_str; } char* makeName(char* name) { - TCollection_AsciiString aName(name), aNewName; - Standard_Integer i, length = aName.Length(); + //TCollection_AsciiString aName(name), aNewName; + std::string aName(name), aNewName; + //Standard_Integer i, length = aName.Length(); + int i, length = aName.length(); char replace = (char)19; for(i=1; i<=length; i++) { - if(aName.Value(i) == ' ') aNewName+=replace; - else aNewName += aName.Value(i); + //if(aName.Value(i) == ' ') aNewName+=replace; + //else aNewName += aName.Value(i); + if(aName[i] == ' ') aNewName+=replace; + else aNewName += aName[i]; } - length = strlen(aNewName.ToCString()); + //length = strlen(aNewName.ToCString()); + length = strlen(aNewName.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aNewName.ToCString()) ; + //strcpy(new_str , aNewName.ToCString()) ; + strcpy(new_str , aNewName.c_str()) ; return new_str; } char* restoreName(char* name) { - TCollection_AsciiString aName(name), aNewName; - Standard_Integer i, length = aName.Length(); + //TCollection_AsciiString aName(name), aNewName; + std::string aName(name), aNewName; + //Standard_Integer i, length = aName.Length(); + int i, length = aName.length(); char replace = (char)19; for(i=1; i<=length; i++) { - if(aName.Value(i) == replace) aNewName+=' '; - else aNewName += aName.Value(i); + //if(aName.Value(i) == replace) aNewName+=' '; + //else aNewName += aName.Value(i); + if(aName[i] == replace) aNewName+=' '; + else aNewName += aName[i]; } - length = strlen(aNewName.ToCString()); + //length = strlen(aNewName.ToCString()); + length = strlen(aNewName.c_str()); char *new_str = new char[ 1+length ]; - strcpy(new_str , aNewName.ToCString()) ; + //strcpy(new_str , aNewName.ToCString()) ; + strcpy(new_str , aNewName.c_str()) ; return new_str; } @@ -775,3 +850,29 @@ void read_float64(FILE* fp, hdf_float64* value) array[i] = (unsigned char)tmp; } } + +bool directoryExists(const char* dir) +{ + DIR* dhandle = opendir(dir); + + if (dhandle != NULL) + { + closedir(dhandle); + return true; + } + else + { + return false; + } +} + +bool createDirectory(const char* dir) +{ + return mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0; +} + +bool is_readable( const std::string & file ) +{ + std::ifstream fichier( file.c_str() ); + return !fichier.fail(); +} diff --git a/src/HDFPersist/HDFascii.hxx b/src/HDFPersist/HDFascii.hxx index 5cbe219bd..999b17352 100644 --- a/src/HDFPersist/HDFascii.hxx +++ b/src/HDFPersist/HDFascii.hxx @@ -28,10 +28,10 @@ #ifndef __HDFascii_H__ #define __HDFascii_H__ -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFascii +class HDF_EXPORT HDFascii { public: diff --git a/src/HDFPersist/HDFcontainerObject.cc b/src/HDFPersist/HDFcontainerObject.cc index 70ecf2e13..6f8d1c353 100644 --- a/src/HDFPersist/HDFcontainerObject.cc +++ b/src/HDFPersist/HDFcontainerObject.cc @@ -30,10 +30,10 @@ extern "C" } #include "HDFcontainerObject.hxx" #include "HDFexception.hxx" -#include "utilities.h" +//#include "utilities.h" using namespace std; -HDFcontainerObject::HDFcontainerObject(char *name) +HDFcontainerObject::HDFcontainerObject(const char *name) : HDFinternalObject(name) { _nsons = 0; diff --git a/src/HDFPersist/HDFcontainerObject.hxx b/src/HDFPersist/HDFcontainerObject.hxx index fef43ed21..dfc237b26 100644 --- a/src/HDFPersist/HDFcontainerObject.hxx +++ b/src/HDFPersist/HDFcontainerObject.hxx @@ -33,16 +33,16 @@ extern "C" } #include "HDFobject.hxx" #include "HDFinternalObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFcontainerObject : public HDFinternalObject +class HDF_EXPORT HDFcontainerObject : public HDFinternalObject { private : HDFinternalObject *_firstson; HDFinternalObject *_lastson; int _nsons; public : - HDFcontainerObject(char *name); + HDFcontainerObject(const char *name); virtual ~HDFcontainerObject(); virtual int nInternalObjects(); diff --git a/src/HDFPersist/HDFdataset.cc b/src/HDFPersist/HDFdataset.cc index de5d07afa..4a0b7b160 100644 --- a/src/HDFPersist/HDFdataset.cc +++ b/src/HDFPersist/HDFdataset.cc @@ -43,7 +43,7 @@ herr_t dataset_attr(hid_t loc_id, const char *attr_name, void *operator_data) return 1; } -HDFdataset::HDFdataset(char *name, HDFcontainerObject *father,hdf_type type, +HDFdataset::HDFdataset(const char *name, HDFcontainerObject *father,hdf_type type, hdf_size dim[], int dimsize, hdf_byte_order order) : HDFinternalObject(name) { @@ -66,7 +66,7 @@ HDFdataset::HDFdataset(char *name, HDFcontainerObject *father,hdf_type type, } -HDFdataset::HDFdataset(char *name,HDFcontainerObject *father) +HDFdataset::HDFdataset(const char *name,HDFcontainerObject *father) : HDFinternalObject(name) { _father = father; diff --git a/src/HDFPersist/HDFdataset.hxx b/src/HDFPersist/HDFdataset.hxx index 3eff4f0df..1e2a62401 100644 --- a/src/HDFPersist/HDFdataset.hxx +++ b/src/HDFPersist/HDFdataset.hxx @@ -33,9 +33,9 @@ extern "C" } #include "HDFinternalObject.hxx" #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFdataset : public HDFinternalObject +class HDF_EXPORT HDFdataset : public HDFinternalObject { private : HDFcontainerObject *_father; @@ -48,10 +48,10 @@ private : char* _attribute; public: - HDFdataset(char *name, HDFcontainerObject *father,hdf_type type, + HDFdataset(const char *name, HDFcontainerObject *father,hdf_type type, hdf_size dim[],int dimsize, hdf_byte_order order = H5T_ORDER_NONE); - HDFdataset(char *name,HDFcontainerObject *father); + HDFdataset(const char *name,HDFcontainerObject *father); virtual ~HDFdataset(); void CreateOnDisk(); diff --git a/src/HDFPersist/HDFexport.hxx b/src/HDFPersist/HDFexport.hxx new file mode 100644 index 000000000..21b64d34e --- /dev/null +++ b/src/HDFPersist/HDFexport.hxx @@ -0,0 +1,39 @@ +// Copyright (C) 2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : HDFexport.hxx +// Author : Andre Ribes - EDF R&D +// Module : SALOME + +#ifndef _HDF_export_HXX_ +#define _HDF_export_HXX_ + +#ifdef WNT + #if defined WIN32 + #define HDF_EXPORT __declspec( dllimport ) + #else + #define HDF_EXPORT + #endif +#else + #define HDF_EXPORT +#endif + +#endif diff --git a/src/HDFPersist/HDFfile.hxx b/src/HDFPersist/HDFfile.hxx index 431dc001e..51c9aa7f1 100644 --- a/src/HDFPersist/HDFfile.hxx +++ b/src/HDFPersist/HDFfile.hxx @@ -32,9 +32,9 @@ extern "C" #include "HDFtypes.h" } #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFfile : public HDFcontainerObject +class HDF_EXPORT HDFfile : public HDFcontainerObject { private : hdf_access_mode _access_mode; diff --git a/src/HDFPersist/HDFgroup.cc b/src/HDFPersist/HDFgroup.cc index 467525320..2b0f2fb19 100644 --- a/src/HDFPersist/HDFgroup.cc +++ b/src/HDFPersist/HDFgroup.cc @@ -40,7 +40,7 @@ herr_t group_attr(hid_t loc_id, const char *attr_name, void *operator_data) return 1; } -HDFgroup::HDFgroup(char *name, HDFcontainerObject *father) +HDFgroup::HDFgroup(const char *name, HDFcontainerObject *father) : HDFcontainerObject(name) { _father = father; diff --git a/src/HDFPersist/HDFgroup.hxx b/src/HDFPersist/HDFgroup.hxx index 2641650e1..8c0d02b88 100644 --- a/src/HDFPersist/HDFgroup.hxx +++ b/src/HDFPersist/HDFgroup.hxx @@ -32,9 +32,9 @@ extern "C" #include "HDFtypes.h" } #include "HDFcontainerObject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFgroup : public HDFcontainerObject +class HDF_EXPORT HDFgroup : public HDFcontainerObject { private : HDFcontainerObject *_father; @@ -42,7 +42,7 @@ private : hdf_idt _mid; char* _attribute; public : - HDFgroup(char *name, HDFcontainerObject *father); + HDFgroup(const char *name, HDFcontainerObject *father); void CreateOnDisk(); void OpenOnDisk(); diff --git a/src/HDFPersist/HDFinternalObject.cc b/src/HDFPersist/HDFinternalObject.cc index a3cdc1f7f..716e6da49 100644 --- a/src/HDFPersist/HDFinternalObject.cc +++ b/src/HDFPersist/HDFinternalObject.cc @@ -33,7 +33,7 @@ extern "C" using namespace std; #endif -HDFinternalObject::HDFinternalObject(char *name) +HDFinternalObject::HDFinternalObject(const char *name) : HDFobject(name) { _previousbrother = NULL; diff --git a/src/HDFPersist/HDFinternalObject.hxx b/src/HDFPersist/HDFinternalObject.hxx index fa05249de..ee4c32e51 100644 --- a/src/HDFPersist/HDFinternalObject.hxx +++ b/src/HDFPersist/HDFinternalObject.hxx @@ -32,15 +32,15 @@ extern "C" #include "HDFtypes.h" } #include "HDFobject.hxx" -#include +#include "HDFexport.hxx" -class Standard_EXPORT HDFinternalObject : public HDFobject +class HDF_EXPORT HDFinternalObject : public HDFobject { private : HDFinternalObject *_previousbrother; HDFinternalObject *_nextbrother; public : - HDFinternalObject(char *name); + HDFinternalObject(const char *name); HDFinternalObject *GetPreviousBrother(); HDFinternalObject *GetNextBrother(); diff --git a/src/HDFPersist/HDFobject.cc b/src/HDFPersist/HDFobject.cc index 42bb19b0b..5adb8aafe 100644 --- a/src/HDFPersist/HDFobject.cc +++ b/src/HDFPersist/HDFobject.cc @@ -30,10 +30,10 @@ extern "C" #include "hdfi.h" #include } -#include "utilities.h" +//#include "utilities.h" using namespace std; -HDFobject::HDFobject(char *name) +HDFobject::HDFobject(const char *name) { // MESSAGE("-------- constructor " << name << " " << this); HDFerrorModeLock(); diff --git a/src/HDFPersist/HDFobject.hxx b/src/HDFPersist/HDFobject.hxx index a011003c1..3c829822a 100644 --- a/src/HDFPersist/HDFobject.hxx +++ b/src/HDFPersist/HDFobject.hxx @@ -31,14 +31,14 @@ extern "C" { #include "HDFtypes.h" } -#include +#include -class Standard_EXPORT HDFobject { +class HDF_EXPORT HDFobject { protected : char *_name; hdf_idt _id; public : - HDFobject(char *name); + HDFobject(const char *name); virtual ~HDFobject(); hdf_idt GetId(); diff --git a/src/HDFPersist/Makefile.am b/src/HDFPersist/Makefile.am index 92cb42c97..5e1925c9c 100644 --- a/src/HDFPersist/Makefile.am +++ b/src/HDFPersist/Makefile.am @@ -42,7 +42,8 @@ salomeinclude_HEADERS = \ HDFtypes.h \ HDFconvert.hxx \ hdfi.h \ - HDFascii.hxx + HDFascii.hxx \ + HDFexport.hxx # Libraries targets lib_LTLIBRARIES = libSalomeHDFPersist.la @@ -88,11 +89,13 @@ libSalomeHDFPersist_la_SOURCES =\ HDFascii.cc libSalomeHDFPersist_la_LDFLAGS = -no-undefined -version-info=0:0:0 -libSalomeHDFPersist_la_CPPFLAGS = @CAS_CPPFLAGS@ @HDF5_INCLUDES@ -DPCLINUX \ + +#libSalomeHDFPersist_la_CPPFLAGS = @CAS_CPPFLAGS@ @HDF5_INCLUDES@ -DPCLINUX \ +libSalomeHDFPersist_la_CPPFLAGS = @HDF5_INCLUDES@ -DPCLINUX \ -I$(srcdir)/../SALOMELocalTrace \ -I$(srcdir)/../Basics -libSalomeHDFPersist_la_LIBADD = @CAS_KERNEL@ @HDF5_LIBS@ - +#libSalomeHDFPersist_la_LIBADD = @CAS_KERNEL@ @HDF5_LIBS@ +libSalomeHDFPersist_la_LIBADD = @HDF5_LIBS@ EXTRA_DIST = \ test1.c \ diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 10047091c..d4541abac 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -277,7 +277,7 @@ bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName) SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ; ASSERT(! CORBA::is_nil(Catalog)); - SALOME_ModuleCatalog::Acomponent_ptr compoInfo = + SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(componentName); if (CORBA::is_nil (compoInfo)) { @@ -340,6 +340,9 @@ void SALOME_LifeCycleCORBA::preSet( Engines::MachineParameters& params) params.nb_proc_per_node = 0; params.nb_node = 0; params.isMPI = false; + + params.parallelLib = ""; + params.nb_component_nodes = 0; } //============================================================================= diff --git a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py index 3e3b974b3..9bfb82f71 100644 --- a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py +++ b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py @@ -19,14 +19,15 @@ import sys, os,signal,string,commands import runSalome +import setenv import orbmodule import TestKiller import addToKillList # get SALOME environment : -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # set environment for trace in logger # (with file, servers may be killed before the write to the file...) diff --git a/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py index 2157e8d38..8a4d7856e 100644 --- a/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py +++ b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py @@ -28,14 +28,15 @@ import sys, os,signal,string,commands import runSalome +import setenv import orbmodule import TestKiller import addToKillList # get SALOME environment : -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # set environment for trace in logger # (with file, servers may be killed before the write to the file...) diff --git a/src/NamingService/Test/TestNamingService.py b/src/NamingService/Test/TestNamingService.py index 2bc32efe9..f41e7689d 100644 --- a/src/NamingService/Test/TestNamingService.py +++ b/src/NamingService/Test/TestNamingService.py @@ -18,13 +18,14 @@ # import sys, os,signal,string,commands import runSalome +import setenv import orbmodule import TestKiller # get SALOME environment : -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # set environment for trace in logger # (with file, servers may be killed before the write to the file...) diff --git a/src/ParallelContainer/Makefile.am b/src/ParallelContainer/Makefile.am index 0e04b8a16..1734d4f10 100644 --- a/src/ParallelContainer/Makefile.am +++ b/src/ParallelContainer/Makefile.am @@ -33,7 +33,8 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am # # header files salomeinclude_HEADERS = SALOME_ParallelComponent_i.hxx \ - SALOME_ParallelContainer_i.hxx + SALOME_ParallelContainer_i.hxx \ + Parallel_Salome_file_i.hxx # # =============================================================== @@ -49,6 +50,7 @@ COMMON_CPPFLAGS= -I$(top_srcdir)/src/Container \ -I$(top_srcdir)/src/NamingService \ -I$(top_srcdir)/src/Registry \ -I$(top_srcdir)/src/Utils \ + -I$(srcdir)/../HDFPersist \ -I$(top_builddir)/salome_adm/unix \ -I$(top_builddir)/idl \ -I$(top_srcdir)/src/SALOMETraceCollector \ @@ -58,7 +60,9 @@ COMMON_CPPFLAGS= -I$(top_srcdir)/src/Container \ # This local variable defines the list of dependant libraries common to all target in this package. COMMON_LIBS = $(top_builddir)/src/Container/libSalomeContainer.la \ + $(top_builddir)/src/HDFPersist/libSalomeHDFPersist.la \ $(top_builddir)/idl/libSalomeParallelIDLKernel.la \ + $(top_builddir)/idl/libSalomeIDLKernel.la \ @CORBA_LIBS@ \ @PACO_LIBS@ @@ -70,7 +74,9 @@ COMMON_LIBS = $(top_builddir)/src/Container/libSalomeContainer.la \ lib_LTLIBRARIES = libSalomeParallelContainer.la libSalomeParallelContainer_la_SOURCES = SALOME_ParallelComponent_i.cxx \ - SALOME_ParallelContainer_i.cxx + SALOME_ParallelContainer_i.cxx \ + $(top_srcdir)/src/Container/Salome_file_i.cxx \ + Parallel_Salome_file_i.cxx libSalomeParallelContainer_la_CXXFLAGS = $(COMMON_CPPFLAGS) @@ -96,22 +102,28 @@ bin_PROGRAMS = SALOME_ParallelContainerProxyDummy \ SALOME_ParallelContainerProxyDummy_SOURCES = SALOME_ParallelContainerProxyDummy.cxx SALOME_ParallelContainerProxyDummy_CXXFLAGS = $(COMMON_CPPFLAGS) SALOME_ParallelContainerProxyDummy_LDADD = libSalomeParallelContainer.la \ - -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_omnithread + -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_omnithread \ + $(COMMON_LIBS) SALOME_ParallelContainerNodeDummy_SOURCES = SALOME_ParallelContainerNodeDummy.cxx SALOME_ParallelContainerNodeDummy_CXXFLAGS = $(COMMON_CPPFLAGS) SALOME_ParallelContainerNodeDummy_LDADD = libSalomeParallelContainer.la \ - -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_omnithread + -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_omnithread \ + $(COMMON_LIBS) SALOME_ParallelContainerProxyMpi_SOURCES = SALOME_ParallelContainerProxyMpi.cxx SALOME_ParallelContainerProxyMpi_CXXFLAGS = $(COMMON_CPPFLAGS) @MPI_INCLUDES@ SALOME_ParallelContainerProxyMpi_LDADD = libSalomeParallelContainer.la \ -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_mpi -lPaCO_omnithread \ - @MPI_LIBS@ + @MPI_LIBS@ \ + $(COMMON_LIBS) + SALOME_ParallelContainerNodeMpi_SOURCES = SALOME_ParallelContainerNodeMpi.cxx SALOME_ParallelContainerNodeMpi_CXXFLAGS = $(COMMON_CPPFLAGS) @MPI_INCLUDES@ SALOME_ParallelContainerNodeMpi_LDADD = libSalomeParallelContainer.la \ -L@PACOPATH@/lib -lPaCO_dummy -lPaCO_mpi -lPaCO_omnithread \ - @MPI_LIBS@ + @MPI_LIBS@\ + $(COMMON_LIBS) + diff --git a/src/ParallelContainer/Parallel_Salome_file_i.cxx b/src/ParallelContainer/Parallel_Salome_file_i.cxx new file mode 100644 index 000000000..ac06b5005 --- /dev/null +++ b/src/ParallelContainer/Parallel_Salome_file_i.cxx @@ -0,0 +1,358 @@ +// Copyright (C) 2007 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : Parallel_Salome_file_i.cxx +// Author : André RIBES, EDF +// Module : SALOME +// $Header: + +#include "Parallel_Salome_file_i.hxx" +#include "utilities.h" + +Parallel_Salome_file_i::Parallel_Salome_file_i(CORBA::ORB_ptr orb, const char * ior) : + InterfaceParallel_impl(orb,ior), + Engines::Salome_file_serv(orb,ior), + Engines::fileTransfer_serv(orb,ior), + Engines::Parallel_Salome_file_serv(orb,ior) +{ + CORBA::Object_ptr obj = _orb->string_to_object(ior); + proxy = Engines::Parallel_Salome_file::_narrow(obj); + parallel_file = NULL; +} + +Parallel_Salome_file_i::~Parallel_Salome_file_i() {} + +void +Parallel_Salome_file_i::load(const char* hdf5_file) { + MESSAGE("Parallel_Salome_file_i::load : NOT YET IMPLEMENTED"); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Parallel_Salome_file_i::load : NOT YET IMPLEMENTED"; + throw SALOME::SALOME_Exception(es); +} + +void +Parallel_Salome_file_i::save(const char* hdf5_file) { + MESSAGE("Parallel_Salome_file_i::save : NOT YET IMPLEMENTED"); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Parallel_Salome_file_i::save : NOT YET IMPLEMENTED"; + throw SALOME::SALOME_Exception(es); +} + +void +Parallel_Salome_file_i::save_all(const char* hdf5_file) { + MESSAGE("Parallel_Salome_file_i::save_all : NOT YET IMPLEMENTED"); + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Parallel_Salome_file_i::save_all : NOT YET IMPLEMENTED"; + throw SALOME::SALOME_Exception(es); +} + +void +Parallel_Salome_file_i::connect(Engines::Salome_file_ptr source_Salome_file) { + // only one file managed case + Salome_file_i::connect(source_Salome_file); + + // Test if the file is managed in an another node + // If yes, node is updated + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) { + std::string file_name = begin->first; + if (_fileManaged[file_name].node > 0 && getMyRank() == 0) { + if (parallel_file == NULL) + parallel_file = Engines::PaCO_Parallel_Salome_file::PaCO_narrow(proxy, _orb); + parallel_file->connect(source_Salome_file, _fileManaged[file_name].node); + } + } +} + +void +Parallel_Salome_file_i::connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file) { + Salome_file_i::connectDistributedFile(file_name, source_Salome_file); + + // Test if the file is managed in an another node + // If yes, node is updated + std::string fname(file_name); + if (_fileManaged[fname].node > 0 && getMyRank() == 0) { + if (parallel_file == NULL) + parallel_file = Engines::PaCO_Parallel_Salome_file::PaCO_narrow(proxy, _orb); + parallel_file->connectDistributedFile(file_name, source_Salome_file, _fileManaged[fname].node); + } +} + +void +Parallel_Salome_file_i::setDistributedSourceFile(const char* file_name, + const char * source_file_name) { + Salome_file_i::setDistributedSourceFile(file_name, source_file_name); + // Test if the file is managed in an another node + // If yes, node is updated + std::string fname(file_name); + if (_fileManaged[fname].node > 0 && getMyRank() == 0) { + if (parallel_file == NULL) + parallel_file = Engines::PaCO_Parallel_Salome_file::PaCO_narrow(proxy, _orb); + parallel_file->setDistributedSourceFile(file_name, source_file_name, _fileManaged[fname].node); + } +} + +void +Parallel_Salome_file_i::recvFiles() { + if (parallel_file == NULL) + parallel_file = Engines::PaCO_Parallel_Salome_file::PaCO_narrow(proxy, _orb); + + std::string files_not_ok(""); + int total = getTotalNode(); + for (int i =0; irecvFiles_node(i); + } + catch (SALOME::SALOME_Exception & ex) { + files_not_ok = files_not_ok + std::string(ex.details.text.in()); + } + } + + if (files_not_ok != "") + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = "files not ready : " + files_not_ok; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } + else + { + // We change the state of the Salome_file + _state.files_ok = true; + } +} + +void +Parallel_Salome_file_i::recvFiles_node() { + + std::string files_not_ok(""); + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) + { + bool result = true; + Engines::file file_infos = begin->second; + if (file_infos.node == getMyRank()) { + // Test if the file is local or distributed + if (std::string(file_infos.type.in()) == "local") + { + if (std::string(file_infos.status.in()) == "not_ok") + result = checkLocalFile(file_infos.file_name.in()); + } + else + { + if (std::string(file_infos.status.in()) == "not_ok") { + // 2 cases : + // Source file is a Salome_file + // Source file is a Parallel_Salome_file + PaCO::ParallelKernel_var interface_manager = + PaCO::ParallelKernel::_narrow(_fileDistributedSource[file_infos.file_name.in()]); + if (CORBA::is_nil(interface_manager)) + result = getDistributedFile(file_infos.file_name.in()); + else + result = getParallelDistributedFile(file_infos.file_name.in()); + } + } + // if the result is false + // we add this file to files_not_ok + if (!result) + { + files_not_ok.append(" "); + files_not_ok.append(file_infos.file_name.in()); + } + } + } + if (files_not_ok != "") + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + std::string text = files_not_ok; + es.text = CORBA::string_dup(text.c_str()); + throw SALOME::SALOME_Exception(es); + } +} + +bool +Parallel_Salome_file_i::getParallelDistributedFile(std::string file_name) { + + bool result = true; + const char * source_file_name = _fileManaged[file_name].source_file_name.in(); + int fileId; + FILE* fp; + std::string comp_file_name(_fileManaged[file_name].path.in()); + comp_file_name.append("/"); + comp_file_name.append(_fileManaged[file_name].file_name.in()); + + // Test if the process can write on disk + if ((fp = fopen(comp_file_name.c_str(),"wb")) == NULL) + { + INFOS("file " << comp_file_name << " cannot be open for writing"); + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + result = false; + return result; + } + + Engines::PaCO_Parallel_Salome_file * parallel_source_file = + Engines::PaCO_Parallel_Salome_file::PaCO_narrow(_fileDistributedSource[file_name], _orb); + + int node = parallel_source_file->getFileNode(source_file_name); + + try + { + fileId = parallel_source_file->open(source_file_name, node); + } + catch (...) + { + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + fclose(fp); + result = false; + return result; + } + + if (fileId > 0) + { + Engines::fileBlock* aBlock; + int toFollow = 1; + int ctr=0; + MESSAGE("begin of transfer of " << comp_file_name); + while (toFollow) + { + ctr++; + aBlock = parallel_source_file->getBlock(fileId, node); + toFollow = aBlock->length(); + CORBA::Octet *buf = aBlock->get_buffer(); + int nbWri = fwrite(buf, sizeof(CORBA::Octet), toFollow, fp); + ASSERT(nbWri == toFollow); + } + fclose(fp); + MESSAGE("end of transfer of " << comp_file_name); + parallel_source_file->close(fileId, node); + } + else + { + INFOS("open reference file for copy impossible"); + result = false; + fclose(fp); + _fileManaged[file_name].status = CORBA::string_dup("not_ok"); + return result; + } + + _fileManaged[file_name].status = CORBA::string_dup("ok"); + return result; +} + +void +Parallel_Salome_file_i::setContainer(Engines::Container_ptr container) { + _container = Engines::Container::_duplicate(container); + + // Update All the files managed by the node + _t_fileManaged::iterator begin = _fileManaged.begin(); + _t_fileManaged::iterator end = _fileManaged.end(); + for(;begin!=end;begin++) { + begin->second.container = Engines::Container::_duplicate(container); + } +} + +void +Parallel_Salome_file_i::setFileNode(const char* file_name, CORBA::Long node) { + + // Test if this file is managed + std::string fname(file_name); + _t_fileManaged::iterator it = _fileManaged.find(fname); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "file is not managed"; + throw SALOME::SALOME_Exception(es); + } + + // Update file infos into this node (node 0) + // and into the node that actually managed it + _fileManaged[fname].node = node; + + if (node > 0) { + if (parallel_file == NULL) + parallel_file = Engines::PaCO_Parallel_Salome_file::PaCO_narrow(proxy, _orb); + + Engines::Container_ptr cont = parallel_file->updateFile(_fileManaged[fname], node); + parallel_file->connectDistributedFile(fname.c_str(), + _fileDistributedSource[fname], + node); + + // Update file infos with the new reference of the container + _fileManaged[fname].container = Engines::Container::_duplicate(cont); + } +} + +Engines::Container_ptr +Parallel_Salome_file_i::updateFile(const Engines::file& file) { + // Copy file + Engines::file new_file_infos(file); + + // Adding it to node list + new_file_infos.container = Engines::Container::_duplicate(_container); + std::string fname(new_file_infos.file_name.in()); + _fileManaged[fname] = new_file_infos; + + // Return the new reference of the container associated to the file + return Engines::Container::_duplicate(_container); +} + +CORBA::Long +Parallel_Salome_file_i::getFileNode(const char* file_name) { + + // Test if this file is managed + std::string fname(file_name); + if (fname == "") { + // We enter in the simple case where the user + // has not used setDistributedSourceFile. + // In this case we try to see if the Salome_file + if (_fileManaged.size() == 1) + { + // only one file managed + _t_fileManaged::iterator it = _fileManaged.begin(); + fname = it->first; + } + else + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "Error : there is more than one file that is managed"; + throw SALOME::SALOME_Exception(es); + } + } + _t_fileManaged::iterator it = _fileManaged.find(fname); + if (it == _fileManaged.end()) + { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "file is not managed"; + throw SALOME::SALOME_Exception(es); + } + + return _fileManaged[fname].node; +} diff --git a/src/ParallelContainer/Parallel_Salome_file_i.hxx b/src/ParallelContainer/Parallel_Salome_file_i.hxx new file mode 100644 index 000000000..c3814a5c4 --- /dev/null +++ b/src/ParallelContainer/Parallel_Salome_file_i.hxx @@ -0,0 +1,74 @@ +// Copyright (C) 2007 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : Parallel_Salome_file_i.hxx +// Author : André RIBES, EDF +// Module : SALOME +// $Header: + +#ifndef _PARALLEL_SALOME_FILE_I_HXX_ +#define _PARALLEL_SALOME_FILE_I_HXX_ + +#include +#include +#include +#include + +#include "SALOME_ComponentPaCO_Engines_Parallel_Salome_file_server.h" +#include "Salome_file_i.hxx" + +class CONTAINER_EXPORT Parallel_Salome_file_i: + public virtual Salome_file_i, + public virtual Engines::Parallel_Salome_file_serv +{ + public: + Parallel_Salome_file_i(CORBA::ORB_ptr orb, const char * ior); + virtual ~Parallel_Salome_file_i(); + + virtual void setFileNode(const char* file_name, CORBA::Long node); + virtual CORBA::Long getFileNode(const char* file_name); + virtual Engines::Container_ptr updateFile(const Engines::file& file); + + // New implementation for these methods + // For the parallel cases + virtual void load(const char* hdf5_file); + virtual void save(const char* hdf5_file); + virtual void save_all(const char* hdf5_file); + virtual void connect(Engines::Salome_file_ptr source_Salome_file); + virtual void connectDistributedFile(const char * file_name, + Engines::Salome_file_ptr source_Salome_file); + virtual void setDistributedSourceFile(const char* file_name, + const char * source_file_name); + virtual void recvFiles(); + virtual void recvFiles_node(); + virtual void setContainer(Engines::Container_ptr container); + //virtual void removeFile(const char* file_name); + //virtual void removeFiles(); + + // Local C++ methods + virtual bool getParallelDistributedFile(std::string file_name); + + private : + Engines::Parallel_Salome_file_var proxy; + Engines::PaCO_Parallel_Salome_file * parallel_file; +}; + +#endif + diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index ddcd47d80..db60ae5e4 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -43,6 +43,7 @@ int SIGUSR11 = 1000; #endif +#include using namespace std; @@ -59,7 +60,7 @@ bool Engines_Parallel_Component_i::_isMultiInstance = false; //============================================================================= Engines_Parallel_Component_i::Engines_Parallel_Component_i(CORBA::ORB_ptr orb, char * ior) : - InterfaceParallel_impl(orb,ior), Engines::Component_serv(orb,ior) + InterfaceParallel_impl(orb,ior), Engines::Component_serv(orb,ior), Engines::Parallel_Component_serv(orb,ior) { //ASSERT(0); INFOS("Default Constructor..."); @@ -84,7 +85,9 @@ Engines_Parallel_Component_i::Engines_Parallel_Component_i(CORBA::ORB_ptr orb, c const char *instanceName, const char *interfaceName, bool notif) : - InterfaceParallel_impl(orb,ior), Engines::Component_serv(orb,ior), + InterfaceParallel_impl(orb,ior), + Engines::Component_serv(orb,ior), + Engines::Parallel_Component_serv(orb,ior), _instanceName(instanceName), _interfaceName(interfaceName), _myConnexionToRegistry(0), @@ -106,7 +109,11 @@ Engines_Parallel_Component_i::Engines_Parallel_Component_i(CORBA::ORB_ptr orb, c _instanceName.c_str()); _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif); - //SCRUTE(pd_refCount); + + deploy_mutex = new pthread_mutex_t(); + pthread_mutex_init(deploy_mutex, NULL); + _proxy = NULL; + //SCRUTE(pd_refCount); } //============================================================================= @@ -121,6 +128,11 @@ Engines_Parallel_Component_i::~Engines_Parallel_Component_i() { MESSAGE("Component destructor"); Engines_Parallel_Container_i::decInstanceCnt(_interfaceName); + pthread_mutex_destroy(deploy_mutex); + delete deploy_mutex; + + if (_proxy) + delete _proxy; } //============================================================================= @@ -567,7 +579,8 @@ void Engines_Parallel_Component_i::beginService(const char *serviceName) (*it).second >>= value; // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC. #if defined __GNUC__ - int ret = setenv(cle.c_str(), value, overwrite); + //int ret = setenv(cle.c_str(), value, overwrite); + setenv(cle.c_str(), value, overwrite); #else //CCRT porting : setenv not defined in stdlib.h std::string s(cle); @@ -575,7 +588,8 @@ void Engines_Parallel_Component_i::beginService(const char *serviceName) s+=value; // char* cast because 1st arg of linux putenv function // is not a const char* ! - int ret=putenv((char *)s.c_str()); + //int ret=putenv((char *)s.c_str()); + putenv((char *)s.c_str()); //End of CCRT porting #endif MESSAGE("--- setenv: "<find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + + // We create a new PaCO++ object. + // He has the same configuration than + // his component + + // Firstly, we have to create the proxy object + // of the Salome_file and transmit his + // reference to the other nodes. + if (getMyRank() == 0) { + Engines::Parallel_Salome_file_proxy_impl * proxy = + new Engines::Parallel_Salome_file_proxy_impl(CORBA::ORB::_duplicate(_orb)); + PaCO_operation * proxy_global_ptr = proxy->getContext("global_paco_context"); + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = getContext("global_paco_context"); + //compo_global_ptr->init_context(proxy_global_ptr); + proxy_global_ptr->init_context(compo_global_ptr); + + paco_fabrique_manager* pfm = paco_getFabriqueManager(); + pfm->register_com("dummy", new paco_dummy_fabrique()); + proxy_global_ptr->setComFab(NULL); + proxy_global_ptr->setLibCom("dummy",NULL); + + proxy_global_ptr->setTypeClient(true); + PaCO::PacoTopology_t client_topo; + client_topo.total = 1; + proxy_global_ptr->setClientTopo(client_topo); + PaCO::PacoTopology_t serveur_topo; + serveur_topo.total = getTotalNode(); + proxy->setTopo(serveur_topo); + + // We register the CORBA objet into the POA + CORBA::Object_ptr proxy_ref = proxy->_this(); + + // We send the reference to all the nodes... + CORBA::Object_ptr comp_proxy = _orb->string_to_object(_ior.c_str()); + Engines::Parallel_Component_var component_proxy = Engines::Parallel_Component::_narrow(comp_proxy); + component_proxy->send_parallel_proxy_object(proxy_ref); + + // Adding proxy into the map + (*_proxy_map)[Salome_file_name] = proxy; + } + else { + this->wait_parallel_object_proxy(); + } + + proxy_ior = this->get_parallel_proxy_object(); + (*_IOR_proxy_map)[Salome_file_name] = proxy_ior; + + // We register each node of the parallel Salome_file object + // into the proxy. + for (int i = 0; i < getTotalNode(); i++) { + if (i == getMyRank()) { + Parallel_Salome_file_i * servant = + new Parallel_Salome_file_i(CORBA::ORB::_duplicate(_orb), proxy_ior.c_str()); + PaCO_operation * servant_global_ptr = servant->getContext("global_paco_context"); + + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); +// compo_global_ptr->init_context(servant_global_ptr); + servant_global_ptr->init_context(compo_global_ptr); + + // We register the CORBA objet into the POA + servant->POA_PaCO::InterfaceParallel::_this(); + + // Register the servant + servant->deploy(getMyRank()); + + // Adding servant to the map + (*_map)[Salome_file_name] = servant; + } + + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); + compo_global_ptr->my_com->paco_barrier(); + } + + // Parallel_Salome_file is created and deployed + delete _proxy; + _proxy = NULL; + } + pthread_mutex_unlock(deploy_mutex); + proxy_ior = (*_IOR_proxy_map)[Salome_file_name]; + CORBA::Object_ptr proxy_ref = _orb->string_to_object(proxy_ior.c_str()); + return Engines::Salome_file::_narrow(proxy_ref); +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::setOutputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we add it. + _Service_file_map_it = _Output_Service_file_map.find(service_name); + if (_Service_file_map_it == _Output_Service_file_map.end()) { + _t_Salome_file_map * _map = new _t_Salome_file_map(); + _Output_Service_file_map[service_name] = _map; + _t_Proxy_Salome_file_map * _proxy_map = new _t_Proxy_Salome_file_map(); + _Proxy_Output_Service_file_map[service_name] = _proxy_map; + _t_IOR_Proxy_Salome_file_map * _IOR_proxy_map = new _t_IOR_Proxy_Salome_file_map(); + _IOR_Proxy_Output_Service_file_map[service_name] = _IOR_proxy_map; + } + _t_Salome_file_map * _map = _Output_Service_file_map[service_name]; + _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Output_Service_file_map[service_name]; + _t_IOR_Proxy_Salome_file_map * _IOR_proxy_map = _IOR_Proxy_Output_Service_file_map[service_name]; + + pthread_mutex_lock(deploy_mutex); + std::string proxy_ior; + + // Try to find the Salome_file ... + _Salome_file_map_it = _map->find(Salome_file_name); + if (_Salome_file_map_it == _map->end()) { + + // We create a new PaCO++ object. + // He has the same configuration than + // his component + + // Firstly, we have to create the proxy object + // of the Salome_file and transmit his + // reference to the other nodes. + if (getMyRank() == 0) { + Engines::Parallel_Salome_file_proxy_impl * proxy = + new Engines::Parallel_Salome_file_proxy_impl(CORBA::ORB::_duplicate(_orb)); + PaCO_operation * proxy_global_ptr = proxy->getContext("global_paco_context"); + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = getContext("global_paco_context"); + //compo_global_ptr->init_context(proxy_global_ptr); + proxy_global_ptr->init_context(compo_global_ptr); + + paco_fabrique_manager* pfm = paco_getFabriqueManager(); + pfm->register_com("dummy", new paco_dummy_fabrique()); + proxy_global_ptr->setComFab(NULL); + proxy_global_ptr->setLibCom("dummy",NULL); + + proxy_global_ptr->setTypeClient(true); + PaCO::PacoTopology_t client_topo; + client_topo.total = 1; + proxy_global_ptr->setClientTopo(client_topo); + PaCO::PacoTopology_t serveur_topo; + serveur_topo.total = getTotalNode(); + proxy->setTopo(serveur_topo); + + // We register the CORBA objet into the POA + CORBA::Object_ptr proxy_ref = proxy->_this(); + + // We send the reference to all the nodes... + CORBA::Object_ptr comp_proxy = _orb->string_to_object(_ior.c_str()); + Engines::Parallel_Component_var component_proxy = Engines::Parallel_Component::_narrow(comp_proxy); + component_proxy->send_parallel_proxy_object(proxy_ref); + + // Adding proxy into the map + (*_proxy_map)[Salome_file_name] = proxy; + } + else { + this->wait_parallel_object_proxy(); + } + + proxy_ior = this->get_parallel_proxy_object(); + (*_IOR_proxy_map)[Salome_file_name] = proxy_ior; + + // We register each node of the parallel Salome_file object + // into the proxy. + for (int i = 0; i < getTotalNode(); i++) { + if (i == getMyRank()) { + Parallel_Salome_file_i * servant = + new Parallel_Salome_file_i(CORBA::ORB::_duplicate(_orb), proxy_ior.c_str()); + PaCO_operation * servant_global_ptr = servant->getContext("global_paco_context"); + + // We initialize the object with the context of the Parallel component + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); +// compo_global_ptr->init_context(servant_global_ptr); + servant_global_ptr->init_context(compo_global_ptr); + + // We register the CORBA objet into the POA + servant->POA_PaCO::InterfaceParallel::_this(); + + // Register the servant + servant->deploy(getMyRank()); + + // Adding servant to the map + (*_map)[Salome_file_name] = servant; + } + + PaCO_operation * compo_global_ptr = this->getContext("global_paco_context"); + compo_global_ptr->my_com->paco_barrier(); + } + + // Parallel_Salome_file is created and deployed + delete _proxy; + _proxy = NULL; + } + pthread_mutex_unlock(deploy_mutex); + proxy_ior = (*_IOR_proxy_map)[Salome_file_name]; + CORBA::Object_ptr proxy_ref = _orb->string_to_object(proxy_ior.c_str()); + return Engines::Salome_file::_narrow(proxy_ref); +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::getInputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we throw an exception. + _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it == _Proxy_Input_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); + } + _t_Proxy_Salome_file_map * _map = _Proxy_Input_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Proxy_Salome_file_map_it = _map->find(Salome_file_name); + if (_Proxy_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + + // Client get the proxy object + Engines::Parallel_Salome_file_proxy_impl * Sfile = (*_map)[Salome_file_name]; + return Sfile->_this(); +} + +Engines::Salome_file_ptr +Engines_Parallel_Component_i::getOutputFileToService(const char* service_name, + const char* Salome_file_name) +{ + // Try to find the service, if it doesn't exist, we throw an exception. + _Proxy_Service_file_map_it = _Proxy_Output_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it == _Proxy_Output_Service_file_map.end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have salome files"; + throw SALOME::SALOME_Exception(es); + } + _t_Proxy_Salome_file_map * _map = _Proxy_Output_Service_file_map[service_name]; + + // Try to find the Salome_file ... + _Proxy_Salome_file_map_it = _map->find(Salome_file_name); + if (_Proxy_Salome_file_map_it == _map->end()) { + SALOME::ExceptionStruct es; + es.type = SALOME::INTERNAL_ERROR; + es.text = "service doesn't have this Salome_file"; + throw SALOME::SALOME_Exception(es); + } + + // Client get the proxy object + Engines::Parallel_Salome_file_proxy_impl * Sfile = (*_map)[Salome_file_name]; + return Sfile->_this(); +} + + +void +Engines_Parallel_Component_i::checkInputFilesToService(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Proxy_Service_file_map_it = _Proxy_Input_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it != _Proxy_Input_Service_file_map.end()) { + _t_Proxy_Salome_file_map * _proxy_map = _Proxy_Input_Service_file_map[service_name]; + _t_Proxy_Salome_file_map::iterator begin = _proxy_map->begin(); + _t_Proxy_Salome_file_map::iterator end = _proxy_map->end(); + + for(;begin!=end;begin++) { + Engines::Parallel_Salome_file_proxy_impl * file = begin->second; + std::string file_port_name = begin->first; + configureSalome_file(service_name, file_port_name, file); + file->recvFiles(); + } + } +} + +void +Engines_Parallel_Component_i::checkOutputFilesToService(const char* service_name) +{ + // Try to find the service, if it doesn't exist, nothing to do. + _Proxy_Service_file_map_it = _Proxy_Output_Service_file_map.find(service_name); + if (_Proxy_Service_file_map_it != _Proxy_Output_Service_file_map.end()) { + _t_Proxy_Salome_file_map * _map = _Proxy_Output_Service_file_map[service_name]; + _t_Proxy_Salome_file_map::iterator begin = _map->begin(); + _t_Proxy_Salome_file_map::iterator end = _map->end(); + + for(;begin!=end;begin++) { + Engines::Parallel_Salome_file_proxy_impl * file = begin->second; + std::string file_port_name = begin->first; + configureSalome_file(service_name, file_port_name, file); + file->recvFiles(); + } + } + +} + +//============================================================================= +/*! + * C++ method: Used by the Parallel Component to deploy a Parallel Salome_file + */ +//============================================================================= +void +Engines_Parallel_Component_i::send_parallel_proxy_object(CORBA::Object_ptr proxy_ref) { + _proxy = _orb->object_to_string(proxy_ref); +} + +//============================================================================= +/*! + * C++ method: Used by the Parallel Component to deploy a Parallel Salome_file + */ +//============================================================================= +void +Engines_Parallel_Component_i::wait_parallel_object_proxy() { + char * proxy = NULL; + proxy = get_parallel_proxy_object(); + while(proxy == NULL) + { + sleep(1); + proxy = get_parallel_proxy_object(); + } +} + +//============================================================================= +/*! + * C++ method: Used by the Parallel Component to deploy a Parallel Salome_file + */ +//============================================================================= +char * +Engines_Parallel_Component_i::get_parallel_proxy_object() { + return _proxy; +} + + +//============================================================================= +/*! + * C++ method: used to configure the Salome_file into the runtime. + * \param service_name name of the service that use this Salome_file + * \param file_port_name name of the Salome_file + * \param file Parallel Salome_file C++ object + */ +//============================================================================= +void +Engines_Parallel_Component_i::configureSalome_file(std::string service_name, + std::string file_port_name, + Engines::Parallel_Salome_file_proxy_impl * file) +{ + // By default this method does nothing +} + diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx index 07c3bb104..edadf93ce 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx @@ -37,10 +37,11 @@ #include #include -#include "SALOME_ComponentPaCO_Engines_Component_server.h" +#include "SALOME_ComponentPaCO_Engines_Parallel_Component_server.h" #include "NOTIFICATION.hxx" #include "RegistryConnexion.hxx" +#include "Parallel_Salome_file_i.hxx" class Engines_Parallel_Container_i; @@ -59,7 +60,7 @@ class Engines_Parallel_Container_i; #endif class CONTAINER_EXPORT Engines_Parallel_Component_i: - public virtual Engines::Component_serv, + public virtual Engines::Parallel_Component_serv, public virtual PortableServer::RefCountServantBase { public: @@ -98,6 +99,21 @@ public: CORBA::Boolean isPublished, CORBA::Boolean& isValidScript); + // CORBA operations for Salome_file + virtual Engines::Salome_file_ptr getInputFileToService(const char* service_name, + const char* Salome_file_name); + virtual Engines::Salome_file_ptr getOutputFileToService(const char* service_name, + const char* Salome_file_name); + + virtual void checkInputFilesToService(const char* service_name); + virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, + const char* Salome_file_name); + + virtual void checkOutputFilesToService(const char* service_name); + virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, + const char* Salome_file_name); + + void send_parallel_proxy_object(CORBA::Object_ptr proxy_ref); // --- local C++ methods @@ -118,6 +134,13 @@ public: void SetCurCpu() ; long CpuUsed() ; + void wait_parallel_object_proxy(); + char * get_parallel_proxy_object(); + + virtual void configureSalome_file(std::string service_name, + std::string file_port_name, + Engines::Parallel_Salome_file_proxy_impl * file); + protected: int _studyId; // -1: not initialised; 0: multiStudy; >0: study static bool _isMultiStudy; @@ -135,10 +158,38 @@ protected: NOTIFICATION_Supplier* _notifSupplier; std::map_fieldsDict; + // Map Salome_file_name to Parallel_Salome_file* + typedef std::map _t_Salome_file_map; + typedef std::map _t_Proxy_Salome_file_map; + typedef std::map _t_IOR_Proxy_Salome_file_map; + + // Map Service_name to _Salome_file_map + typedef std::map _t_Service_file_map; + typedef std::map _t_Proxy_Service_file_map; + typedef std::map _t_IOR_Proxy_Service_file_map; + + _t_Service_file_map _Input_Service_file_map; + _t_Service_file_map _Output_Service_file_map; + _t_Service_file_map::iterator _Service_file_map_it; + _t_Salome_file_map::iterator _Salome_file_map_it; + + _t_Proxy_Service_file_map _Proxy_Input_Service_file_map; + _t_Proxy_Service_file_map _Proxy_Output_Service_file_map; + _t_Proxy_Service_file_map::iterator _Proxy_Service_file_map_it; + _t_Proxy_Salome_file_map::iterator _Proxy_Salome_file_map_it; + + _t_IOR_Proxy_Service_file_map _IOR_Proxy_Input_Service_file_map; + _t_IOR_Proxy_Service_file_map _IOR_Proxy_Output_Service_file_map; + _t_IOR_Proxy_Service_file_map::iterator _IOR_Proxy_Service_file_map_it; + _t_IOR_Proxy_Salome_file_map::iterator _IOR_Proxy_Salome_file_map_it; + std::string _serviceName ; std::string _graphName ; std::string _nodeName ; + pthread_mutex_t * deploy_mutex; + char * _proxy; + private: #ifndef WNT pthread_t _ThreadId ; diff --git a/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx b/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx index f08a384c7..4f5d0d274 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerNodeDummy.cxx @@ -63,13 +63,63 @@ void handler(int t) { } #endif +typedef void (*sighandler_t)(int); +sighandler_t setsig(int sig, sighandler_t handler) +{ + struct sigaction context, ocontext; + context.sa_handler = handler; + sigemptyset(&context.sa_mask); + context.sa_flags = 0; + if (sigaction(sig, &context, &ocontext) == -1) + return SIG_ERR; + return ocontext.sa_handler; +} + +void AttachDebugger() +{ + if(getenv ("DEBUGGER")) + { + std::stringstream exec; + exec << "$DEBUGGER SALOME_ParallelContainerNodeDummy " << getpid() << "&"; + std::cerr << exec.str() << std::endl; + system(exec.str().c_str()); + while(1); + } +} + +void Handler(int theSigId) +{ + std::cerr << "SIGSEGV: " << std::endl; + AttachDebugger(); + //to exit or not to exit + exit(1); +} + +void terminateHandler(void) +{ + std::cerr << "Terminate: not managed exception !" << std::endl; + AttachDebugger(); +} + +void unexpectedHandler(void) +{ + std::cerr << "Unexpected: unexpected exception !" << std::endl; + AttachDebugger(); +} + int main(int argc, char* argv[]) { INFOS("Launching a parallel container node"); #ifdef _DEBUG_ - signal(SIGSEGV, handler); +// signal(SIGSEGV, handler); #endif + if(getenv ("DEBUGGER")) + { + setsig(SIGSEGV,&Handler); + set_terminate(&terminateHandler); + set_unexpected(&unexpectedHandler); + } // Initialise the ORB. ORB_INIT &init = *SINGLETON_::Instance(); diff --git a/src/ParallelContainer/SALOME_ParallelContainerNodeMpi.cxx b/src/ParallelContainer/SALOME_ParallelContainerNodeMpi.cxx index ce7b79f0f..4852bcafb 100644 --- a/src/ParallelContainer/SALOME_ParallelContainerNodeMpi.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainerNodeMpi.cxx @@ -53,9 +53,18 @@ using namespace std; -#ifdef DEBUG_PARALLEL +#ifdef _DEBUG_ #include +void test(int sigval) { + cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + cerr << "SIGSEGV in :" << getpid() << endl; + cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; + while (1) {} +} + void handler(int t) { cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl; @@ -66,19 +75,72 @@ void handler(int t) { } #endif +typedef void (*sighandler_t)(int); +sighandler_t setsig(int sig, sighandler_t handler) +{ + struct sigaction context, ocontext; + context.sa_handler = handler; + sigemptyset(&context.sa_mask); + context.sa_flags = 0; + if (sigaction(sig, &context, &ocontext) == -1) + return SIG_ERR; + return ocontext.sa_handler; +} + +void AttachDebugger() +{ + if(getenv ("DEBUGGER")) + { + std::stringstream exec; + exec << "$DEBUGGER SALOME_ParallelContainerNodeMpi " << getpid() << "&"; + std::cerr << exec.str() << std::endl; + system(exec.str().c_str()); + while(1); + } +} + +void Handler(int theSigId) +{ + std::cerr << "SIGSEGV: " << std::endl; + AttachDebugger(); + //to exit or not to exit + exit(1); +} + +void terminateHandler(void) +{ + std::cerr << "Terminate: not managed exception !" << std::endl; + AttachDebugger(); +} + +void unexpectedHandler(void) +{ + std::cerr << "Unexpected: unexpected exception !" << std::endl; + AttachDebugger(); +} + int main(int argc, char* argv[]) { INFOS("Launching a parallel Mpi container node"); -#ifdef DEBUG_PARALLEL - signal(SIGSEGV, handler); +#ifdef _DEBUG_ +// struct sigaction action; +// action.sa_handler = &test; +// sigaction(SIGSEGV, &action, NULL); #endif // MPI Init int provided; MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided); -#ifdef DEBUG_PARALLEL + if(getenv ("DEBUGGER")) + { + std::cerr << "Unexpected: unexpected exception !" << std::endl; + setsig(SIGSEGV,&Handler); + set_terminate(&terminateHandler); + set_unexpected(&unexpectedHandler); + } +#ifdef _DEBUG_ cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << endl; cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << endl; cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << endl; diff --git a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx index f9f22e483..9fbf89e85 100644 --- a/src/ParallelContainer/SALOME_ParallelContainer_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelContainer_i.cxx @@ -20,7 +20,7 @@ // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // File : SALOME_ParallelContainer_i.cxx -// Author : André RIBES, EDF +// Author : Andr� RIBES, EDF // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA #include @@ -704,7 +704,7 @@ Engines_Parallel_Container_i::createParallelInstance(string genericRegisterName, // in the nameing service. _numInstanceMutex.lock() ; // lock on the instance number _numInstance++ ; - int numInstance = _numInstance ; +// int numInstance = _numInstance ; _numInstanceMutex.unlock() ; } cerr << "Node " << getMyRank() << " entering in paco_barrier()" << endl; @@ -991,4 +991,33 @@ Engines_Parallel_Container_i::getFileTransfer() } +Engines::Salome_file_ptr +Engines_Parallel_Container_i::createSalome_file(const char* origFileName) +{ + string origName(origFileName); + if (CORBA::is_nil(_Salome_file_map[origName])) + { + Salome_file_i* aSalome_file = new Salome_file_i(); + try + { + aSalome_file->setLocalFile(origFileName); + aSalome_file->recvFiles(); + } + catch (const SALOME::SALOME_Exception& e) + { + return Engines::Salome_file::_nil(); + } + + Engines::Salome_file_var theSalome_file = Engines::Salome_file::_nil(); + theSalome_file = Engines::Salome_file::_narrow(aSalome_file->_this()); + _numInstanceMutex.lock() ; // lock to be alone (stl container write) + _Salome_file_map[origName] = theSalome_file; + _numInstanceMutex.unlock() ; + } + + Engines::Salome_file_ptr theSalome_file = + Engines::Salome_file::_duplicate(_Salome_file_map[origName]); + ASSERT(!CORBA::is_nil(theSalome_file)); + return theSalome_file; +} diff --git a/src/ParallelContainer/SALOME_ParallelContainer_i.hxx b/src/ParallelContainer/SALOME_ParallelContainer_i.hxx index 254d60740..962bc9a1d 100644 --- a/src/ParallelContainer/SALOME_ParallelContainer_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelContainer_i.hxx @@ -129,6 +129,8 @@ public: Engines::fileRef_ptr createFileRef(const char* origFileName); Engines::fileTransfer_ptr getFileTransfer(); + + virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName); protected: static std::map _cntInstances_map; @@ -147,6 +149,7 @@ protected: int _numInstance ; std::map _listInstances_map; std::map _fileRef_map; + std::map _Salome_file_map; Engines::fileTransfer_var _fileTransfer; int _argc ; diff --git a/src/Registry/SALOME_Registry.hxx b/src/Registry/SALOME_Registry.hxx index 899bc5586..4ca01a2c7 100755 --- a/src/Registry/SALOME_Registry.hxx +++ b/src/Registry/SALOME_Registry.hxx @@ -44,4 +44,5 @@ #define REGISTRY_EXPORT #endif -#endif \ No newline at end of file +#endif + diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 3552c1128..01bf2756b 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -993,7 +993,9 @@ SALOME_ResourcesManager::BuildCommandToLaunchLocalParallelContainer(const std::s if (par < 0) { // Nodes case + command = "mpiexec -np " + string(buffer) + " "; +// command += "gdb --args "; command += real_exe_name; command += " " + _NS->ContainerName(rtn); command += " " + parallelLib; @@ -1029,9 +1031,8 @@ SALOME_ResourcesManager::BuildCommandToLaunchLocalParallelContainer(const std::s if (log == "xterm") { command = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH; " - + command + " \" &"; - //command = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH; " - // + command + "; cat \" &"; + + command + " \" &"; +// + command + "; echo $LD_LIBRARY_PATH; cat \" &"; } return command; diff --git a/src/SALOMEDS/Test/TestSALOMEDS.py b/src/SALOMEDS/Test/TestSALOMEDS.py index d2c162635..01891488e 100644 --- a/src/SALOMEDS/Test/TestSALOMEDS.py +++ b/src/SALOMEDS/Test/TestSALOMEDS.py @@ -19,13 +19,14 @@ import sys, os,signal,string,commands import runSalome +import setenv import orbmodule import TestKiller # get SALOME environment : -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # launch CORBA naming server diff --git a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py index 2c6ea82a1..dadd6002a 100644 --- a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py +++ b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.py @@ -19,12 +19,13 @@ import sys, os,signal,string,commands import runSalome +import setenv # get SALOME environment : # here we need KERNEL_ROOT_DIR, PATH, LD_LIBRARY_PATH -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # execute Unit Test diff --git a/src/UnitTests/UnitTests.py b/src/UnitTests/UnitTests.py index 238807a6b..04fc42f44 100644 --- a/src/UnitTests/UnitTests.py +++ b/src/UnitTests/UnitTests.py @@ -19,13 +19,14 @@ import sys, os,signal,string,commands import runSalome +import setenv import orbmodule import TestKiller # get SALOME environment : -args, modules_list, modules_root_dir = runSalome.get_config() -runSalome.set_env(args, modules_list, modules_root_dir) +args, modules_list, modules_root_dir = setenv.get_config() +setenv.set_env(args, modules_list, modules_root_dir) # set environment for trace in logger # (with file, servers may be killed before the write to the file...) -- 2.39.2