3 # Copyright (C) 2009-2015 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # Author : Andre RIBES (EDF R&D)
25 Module that defines PACOComponent for SALOME PaCO++ components implemented in C++
28 from gener import Component, Invalid
29 from paco_tmpl import compoMakefile, hxxCompo, cxxService
30 from paco_tmpl import initService, cxxCompo, paco_sources
31 from paco_tmpl import cxxFactoryDummy, cxxFactoryMpi, cxx_des_parallel_stream
32 from paco_tmpl import hxxparallel_instream, hxxparallel_outstream, hxxinit_ok
33 from paco_tmpl import hxxparallel_instream_init, hxxparallel_outstream_init, cxxService_connect
34 from paco_tmpl import cxx_cons_service, cxx_cons_parallel_outstream, cxx_cons_parallel_instream
36 class PACOComponent(Component):
38 def __init__(self, name, parallel_lib, services=None, libs="", rlibs="", includes="",
39 kind="lib", exe_path=None, sources=None):
40 self.exe_path = exe_path
41 self.parallel_lib = parallel_lib
42 Component.__init__(self, name, services, impl="PACO", libs=libs,
43 rlibs=rlibs, includes=includes, kind=kind,
46 """ validate component definition parameters"""
47 Component.validate(self)
49 if self.kind not in kinds:
50 raise Invalid("kind must be one of %s for component %s" % (kinds,self.name))
51 parallel_libs = ("dummy", "mpi")
52 if self.parallel_lib not in parallel_libs:
53 raise Invalid("parallel_lib must be one of %s" % parallel_libs)
55 def makeCompo(self, gen):
56 """generate files for PaCO++ component
58 return a dict where key is the file name and value is the content of the file
60 cxxfile = "%s.cxx" % self.name
61 hxxfile = "%s.hxx" % self.name
62 if self.kind == "lib":
63 sources = " ".join(map(os.path.basename, self.sources))
65 sources += paco_sources.substitute(module=gen.module.name,
67 return {"Makefile.am":compoMakefile.substitute(module=gen.module.name,
72 includes=self.includes),
73 cxxfile:self.makecxx(gen),
74 hxxfile:self.makehxx(gen)}
76 def makehxx(self, gen):
77 """return a string that is the content of .hxx file
80 parallel_instream = ""
81 parallel_outstream = ""
83 parallelstreamports = ""
84 for serv in self.services:
85 service = " void %s(" % serv.name
86 service = service+gen.makeArgs(serv)+");"
87 services.append(service)
88 services_init_ok += hxxinit_ok.substitute(service_name=serv.name)
90 # Ajout des ports parallel DataStream
91 for name, type in serv.parallel_instream:
92 parallel_instream += hxxparallel_instream.substitute(name=name,
94 for name, type in serv.parallel_outstream:
95 parallel_outstream += hxxparallel_outstream.substitute(name=name,
97 servicesdef = "\n".join(services)
98 parallelstreamports += parallel_instream
99 parallelstreamports += parallel_outstream
100 return hxxCompo.substitute(component=self.name,
101 module=gen.module.name,
102 servicesdef=servicesdef,
103 services_init_ok=services_init_ok,
104 parallelstreamports=parallelstreamports,
105 parallel_lib=self.parallel_lib)
107 def makecxx(self, gen):
108 """return a string that is the content of .cxx file
115 for serv in self.services:
116 defs.append(serv.defs)
119 cons_services += cxx_cons_service.substitute(service_name=serv.name)
120 for name, type in serv.parallel_instream:
121 cons_services += cxx_cons_parallel_instream.substitute(name=name)
122 for name, type in serv.parallel_outstream:
123 cons_services += cxx_cons_parallel_outstream.substitute(name=name)
126 # On détruit uniquement les ports uses
127 # Les ports provides sont détruit lors de la destruction du poa
128 for name, type in serv.parallel_outstream:
129 des_services += cxx_des_parallel_stream.substitute(name=name)
132 init_parallel_datastream_ports=""
133 for name, type in serv.parallel_instream:
134 init_parallel_datastream_ports += hxxparallel_instream_init.substitute(name=name,
136 for name, type in serv.parallel_outstream:
137 init_parallel_datastream_ports += hxxparallel_outstream_init.substitute(name=name,
139 init = initService.substitute(service_name=serv.name,
140 init_parallel_datastream_ports=init_parallel_datastream_ports)
144 connect_parallel_streamport = ""
145 for name, type in serv.parallel_outstream:
146 connect_parallel_streamport += cxxService_connect.substitute(name=name)
148 service = cxxService.substitute(component=self.name, service=serv.name,
149 parameters=gen.makeArgs(serv),
151 connect_parallel_streamport=connect_parallel_streamport)
152 services.append(service)
154 cxxfile = cxxCompo.substitute(component=self.name, module=gen.module.name,
155 servicesdef="\n".join(defs),
156 servicesimpl="\n".join(services),
157 initservice='\n'.join(inits),
158 cons_services=cons_services,
159 des_services=des_services)
161 if self.parallel_lib == "dummy":
162 cxxfile += cxxFactoryDummy.substitute(component=self.name, module=gen.module.name)
163 elif self.parallel_lib == "mpi":
164 cxxfile += cxxFactoryMpi.substitute(component=self.name, module=gen.module.name)