Salome HOME
Merge branch 'V8_0_0_BR'
[tools/yacsgen.git] / module_generator / hxx_para_tmpl.py
1 # Copyright (C) 2009-2015  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 try:
21   from string import Template
22 except:
23   from compat import Template,set
24
25 cxxCompo="""
26 // this cxx file was generated by yacsgen
27 #include "${component}_i.hxx"
28 #include "${cxx_include_file}"
29 using namespace std;
30 #include <string>
31 #include <vector>
32 #include <pthread.h>
33 #include "SenderFactory.hxx"
34 #include "MultiCommException.hxx"
35 #include "ReceiverFactory.hxx"
36 #include "SALOME_Matrix_i.hxx"
37 #include "MatrixClient.hxx"
38 #include "Utils_CorbaException.hxx"
39 #include "MEDCouplingFieldDouble.hxx"
40
41 typedef struct
42 {
43   bool exception;
44   string msg;
45 } except_st;
46
47
48 //DEFS
49 ${servicesdef}
50 //ENDDEF
51
52 //=============================================================================
53 /*!
54  *  standard constructor
55  */
56 //=============================================================================
57 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
58         PortableServer::POA_ptr poa,
59         PortableServer::ObjectId * contId, 
60         const char *instanceName, 
61         const char *interfaceName,
62         bool regist) :
63   ParaMEDMEMComponent_i(orb,poa,contId,instanceName,interfaceName,regist),${inheritedconstructor}cppCompo_(new ${component})
64 {
65   MESSAGE("activate object");
66   _thisObj = this ;
67   _id = _poa->activate_object(_thisObj);
68 }
69
70 ${component}_i::~${component}_i()
71 {
72 }
73
74 ${servicesimpl}
75
76 ${thread_impl}
77
78 extern "C"
79 {
80   PortableServer::ObjectId * ${component}Engine_factory(
81                                CORBA::ORB_ptr orb,
82                                PortableServer::POA_ptr poa, 
83                                PortableServer::ObjectId * contId,
84                                const char *instanceName, 
85                                const char *interfaceName)
86   {
87
88    bool regist;
89    int numproc;
90    int flag;
91
92    MPI_Initialized(&flag);
93    if (!flag) {
94       int argc = 0;
95       char ** argv = NULL;
96       MPI_Init(&argc, &argv);
97    }
98
99    MPI_Comm_rank( MPI_COMM_WORLD, &numproc );
100    if( numproc == 0 )
101       regist = true;
102    else
103       regist = false;
104    ${component}_i * my${component} = new ${component}_i(orb, poa, contId, instanceName, interfaceName, regist);
105    return my${component}->getId();
106   }
107 }
108 """
109 cxxCompo=Template(cxxCompo)
110
111 hxxCompo="""
112 //this file was generated by yacsgen
113 #ifndef __${component}_hxx2salome__
114 #define __${component}_hxx2salome__
115
116 #include <SALOMEconfig.h>
117 #include "Utils_CorbaException.hxx"
118 #include CORBA_SERVER_HEADER(${module})
119 #include "Utils_CorbaException.hxx"
120 #include <memory>  // for std::auto_ptr
121
122 ${compodefs}
123
124 // thread functions declaration
125 ${thread_func_decl}
126
127 // thread structures declaration
128 ${thread_str_decl}
129
130 class ${component};  // forward declaration
131
132 class ${component}_i: ${inheritedclass}
133   public POA_${module}_ORB::${component}_Gen,
134   public ParaMEDMEM::ParaMEDMEMComponent_i
135 {
136
137 public:
138     ${component}_i(CORBA::ORB_ptr orb,
139             PortableServer::POA_ptr poa,
140             PortableServer::ObjectId * contId, 
141             const char *instanceName, 
142             const char *interfaceName,
143             bool regist);
144     virtual ~${component}_i();
145
146 ${servicesdef}
147
148 // (re)defined methods of Driver
149
150 private:
151     std::auto_ptr<${component}> cppCompo_;
152
153 };
154
155
156 extern "C"
157     PortableServer::ObjectId * ${component}Engine_factory(
158             CORBA::ORB_ptr orb,
159             PortableServer::POA_ptr poa,
160             PortableServer::ObjectId * contId,
161             const char *instanceName,
162             const char *interfaceName);
163
164
165 #endif
166 """
167 hxxCompo=Template(hxxCompo)
168
169 cxxService="""
170 ${ret} ${component}_i::${service}(${parameters}) throw (SALOME::SALOME_Exception)
171 {
172     beginService("${component}_i::${service}");
173     BEGIN_OF("${component}_i::${service}");
174     except_st *est;
175     void *ret_th;
176     pthread_t *th;
177     try
178     {
179 ${body}
180         endService("${component}_i::${service}");
181         END_OF("${component}_i::${service}");
182
183     }
184     catch (std::exception& ex)
185     {
186         THROW_SALOME_CORBA_EXCEPTION( ex.what(), SALOME::INTERNAL_ERROR );
187     }
188 }
189 """
190 cxxService=Template(cxxService)
191
192
193 #compoMakefile="""
194 #
195 #dist_lib${component}Engine_la_SOURCES = \
196 #       ${component}_i.cxx
197 #
198 #lib${component}Engine_la_CXXFLAGS = -I$$(top_builddir)/idl  $$(SALOME_INCLUDES) $$(MPI_INCLUDES) ${includes}
199 #lib${component}Engine_la_LIBADD   = ${libs} -L$$(top_builddir)/idl -lSalomeIDL${module} $${SALOME_LIBS} -lSalomeMPIContainer -lparamedmemcompo $$(FLIBS)
200 #
201 #
202 #"""
203 #
204 #compoMakefile=Template(compoMakefile)
205
206
207 # CMakeLists.txt in src/<component>
208 # template parameters:
209 #   module : module name
210 #   component : component name
211 #   componentlib : name of the target library
212 #   includes : additional headers, separated by spaces or \n. can be empty
213 #   libs : additional libraries
214 #   find_libs : find_library commands
215 #   target_properties : additional properties of the target
216 cmake_src_compo_hxxpara = """
217 # --- options ---
218 # additional include directories
219 INCLUDE_DIRECTORIES(
220   $${KERNEL_INCLUDE_DIRS}
221   $${OMNIORB_INCLUDE_DIR}
222   $${PROJECT_BINARY_DIR}
223   $${PROJECT_BINARY_DIR}/idl
224   $${MEDCOUPLING_INCLUDE_DIRS}
225   ${includes}
226 )
227
228 # --- definitions ---
229 ADD_DEFINITIONS(
230   $${OMNIORB_DEFINITIONS}
231 )
232
233 # find additional libraries
234 ${find_libs}
235
236 # libraries to link to
237 SET(_link_LIBRARIES
238   $${OMNIORB_LIBRARIES}
239   $${KERNEL_SalomeIDLKernel}
240   $${KERNEL_OpUtil}
241   $${KERNEL_SalomeContainer}
242   $${KERNEL_SalomeMPIContainer}
243   $${MED_paramedmemcompo}
244   $${MED_paramedcouplingcorba}
245   SalomeIDL${module}
246   ${libs}
247 )
248
249 # --- headers ---
250
251 # header files / no moc processing
252
253 SET(${module}_HEADERS
254   ${component}_i.hxx
255 )
256
257 # --- sources ---
258
259 # sources / static
260 SET(${module}_SOURCES
261   ${component}_i.cxx
262 )
263
264 # --- rules ---
265
266 ADD_LIBRARY(${componentlib} $${${module}_SOURCES})
267 TARGET_LINK_LIBRARIES(${componentlib} $${_link_LIBRARIES} )
268 ${target_properties}
269
270 INSTALL(TARGETS ${componentlib} EXPORT $${PROJECT_NAME}TargetGroup DESTINATION $${SALOME_INSTALL_LIBS})
271
272 INSTALL(FILES $${${module}_HEADERS} DESTINATION $${SALOME_INSTALL_HEADERS})
273 """
274 cmake_src_compo_hxxpara = Template(cmake_src_compo_hxxpara)
275
276 #, SALOME_MED::MED_Gen_Driver, SALOME::MultiCommClass
277 interfaceidlhxx="""
278   interface ${component}_Gen: ${inherited}
279   {
280 ${services}
281   };
282 """
283 interfaceidlhxx=Template(interfaceidlhxx)
284