2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 def readORBConfigFile(filename):
26 """ Extract information (host, port) from ORB configuration file. """
27 with open(filename) as f:
28 contents = f.readlines()
31 host, port = None, None
33 m = re.match("(ORB)?InitRef = NameService=corbaname::([\D\d]+):(\d*)", line)
42 # IMPORTANT NOTE: do not add any print call (cf. note at the bottom of the file)
43 def writeORBConfigFile(path, host, port, kwargs={}):
45 from salome_utils import generateFileName
46 omniorb_config = generateFileName(path, prefix="omniORB",
53 os.environ['OMNIORB_CONFIG'] = omniorb_config
54 os.environ['NSPORT'] = "%s"%(port)
55 os.environ['NSHOST'] = "%s"%(host)
57 from omniORB import CORBA
58 prefix = "" if CORBA.ORB_ID == "omniORB4" else "ORB"
60 from subprocess import check_output
61 ips = check_output(['hostname', '--all-ip-addresses'])
62 # get ip address on default interface (for instance eth0) to limit listening on this interface (cyber security request)
63 ipDefault = ips.split()[0].decode()
65 GIOP_MaxMsgSize = 2097152000 # 2 GBytes
68 orbdata.append("%sInitRef = NameService=corbaname::%s:%s"%(prefix,host,port))
69 orbdata.append("%sgiopMaxMsgSize = %s # 2 GBytes"%(prefix,GIOP_MaxMsgSize))
70 orbdata.append("%straceLevel = 0 # critical errors only"%(prefix))
71 orbdata.append("%smaxGIOPConnectionPerServer = 500 # to allow containers parallel launch"%(prefix))
72 orbdata.append("%snativeCharCodeSet = UTF-8"%(prefix))
73 orbdata.append("%sendPoint = giop:tcp:127.0.0.1:%s"%(prefix,''))
74 orbdata.append("%sendPoint = giop:tcp:%s:%s"%(prefix, ipDefault,''))
77 with open(omniorb_config, "w") as f:
78 f.write("\n".join(orbdata))
80 return [ omniorb_config, GIOP_MaxMsgSize ]
82 # -----------------------------------------------------------------------------
84 if __name__ == "__main__":
97 alist = str(a).split("=", 1)
103 [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs)
105 # :TRICKY: print values so they can be read from caller bash script
106 # Example of bash script:
107 # RETURN_VALUES=$(python ORBConfigFile.py path host port)
108 # RETURN_VALUE_1=$(echo ${RETURN_VALUES} | cut -d' ' -f1)
109 # RETURN_VALUE_2=$(echo ${RETURN_VALUES} | cut -d' ' -f2)
111 # IMPORTANT NOTE: this print call MUST BE the first one!!
112 print(filename, msgSize)