Salome HOME
updated copyright message
[tools/yacsgen.git] / module_generator / hxx_tmpl.py
1 # Copyright (C) 2009-2023  EDF
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 module_generator.compat import Template,set
24
25 cxxCompo="""
26 // this cxx file was generated by yacsgen
27 #include "${component}_i.hxx"
28 #include "${component}.hxx"
29 using namespace std;
30 #include <string>
31 #include <vector>
32 #include "SenderFactory.hxx"
33 #include "MultiCommException.hxx"
34 #include "ReceiverFactory.hxx"
35 #include "SALOME_Matrix_i.hxx"
36 #include "MatrixClient.hxx"
37 #include "Utils_CorbaException.hxx"
38
39 //DEFS
40 ${servicesdef}
41 //ENDDEF
42
43 //=============================================================================
44 /*!
45  *  standard constructor
46  */
47 //=============================================================================
48 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
49         PortableServer::POA_ptr poa,
50         PortableServer::ObjectId * contId, 
51         const char *instanceName, 
52         const char *interfaceName) :
53   Engines_Component_i(orb, poa, contId, instanceName, interfaceName),${inheritedconstructor}cppCompo_(new ${component})
54 {
55   MESSAGE("activate object");
56   _thisObj = this ;
57   _id = _poa->activate_object(_thisObj);
58 }
59
60 ${component}_i::~${component}_i()
61 {
62 }
63
64 ${servicesimpl}
65
66 char* ${component}_i::ComponentDataType()
67 {
68       return CORBA::string_dup("${component}");
69 }
70
71 Engines::EngineComponent_ptr ${component}_i::GetComponentInstance()
72 {
73       return ${component}_Gen::_this();
74 }
75
76 extern "C"
77 {
78   PortableServer::ObjectId * ${component}Engine_factory(
79                                CORBA::ORB_ptr orb,
80                                PortableServer::POA_ptr poa, 
81                                PortableServer::ObjectId * contId,
82                                const char *instanceName, 
83                                const char *interfaceName)
84   {
85     MESSAGE("PortableServer::ObjectId * ${component}Engine_factory()");
86     SCRUTE(interfaceName);
87     ${component}_i * my${component} 
88       = new ${component}_i(orb, poa, contId, instanceName, interfaceName);
89     return my${component}->getId() ;
90   }
91 }
92 """
93 cxxCompo=Template(cxxCompo)
94
95 hxxCompo="""
96 //this file was generated by yacsgen
97 #ifndef __${component}_hxx2salome__
98 #define __${component}_hxx2salome__
99
100 #include <SALOMEconfig.h>
101 #include CORBA_SERVER_HEADER(${module})
102 #include "SALOME_Component_i.hxx"
103 #include "SALOMEMultiComm.hxx"
104 #include <memory>  // for std::auto_ptr
105 //COMPODEFS
106 ${compodefs}
107 //ENDDEF
108
109 class ${component};  // forward declaration
110
111 class ${component}_i: ${inheritedclass}
112   public POA_${module}_ORB::${component}_Gen,
113   public Engines_Component_i
114 {
115
116 public:
117     ${component}_i(CORBA::ORB_ptr orb,
118             PortableServer::POA_ptr poa,
119             PortableServer::ObjectId * contId, 
120             const char *instanceName, 
121             const char *interfaceName);
122     virtual ~${component}_i();
123
124 ${servicesdef}
125
126 // (re)defined methods of Driver
127     virtual Engines::EngineComponent_ptr GetComponentInstance();
128     char* ComponentDataType();
129
130 private:
131     std::auto_ptr<${component}> cppCompo_;
132
133 };
134
135
136 extern "C"
137     PortableServer::ObjectId * ${component}Engine_factory(
138             CORBA::ORB_ptr orb,
139             PortableServer::POA_ptr poa,
140             PortableServer::ObjectId * contId,
141             const char *instanceName,
142             const char *interfaceName);
143
144
145 #endif
146 """
147 hxxCompo=Template(hxxCompo)
148
149 cxxService="""
150 ${ret} ${component}_i::${service}(${parameters}) throw (SALOME::SALOME_Exception)
151 {
152     beginService("${component}_i::${service}");
153     BEGIN_OF("${component}_i::${service}");
154     try
155     {
156 ${body}
157     }
158     catch (std::exception& ex)
159     {
160         THROW_SALOME_CORBA_EXCEPTION( ex.what(), SALOME::INTERNAL_ERROR );
161     }
162 }
163 """
164 cxxService=Template(cxxService)
165
166
167 #, SALOME_MED::MED_Gen_Driver, SALOME::MultiCommClass
168 interfaceidlhxx="""
169   interface ${component}_Gen: ${inherited}
170   {
171 ${services}
172   };
173 """
174 interfaceidlhxx=Template(interfaceidlhxx)
175
176
177
178 # Makefile
179
180 # CMakeLists.txt in src/<component>
181 # template parameters:
182 #   module : module name
183 #   component : component name
184 #   componentlib : name of the target library
185 #   includes : additional headers, separated by spaces or \n. can be empty
186 #   libs : additional libraries
187 #   find_libs : find_library commands
188 #   target_properties : additional properties of the target
189 cmake_src_compo_hxx = """
190 # --- options ---
191 # additional include directories
192 INCLUDE_DIRECTORIES(
193   $${KERNEL_INCLUDE_DIRS}
194   $${OMNIORB_INCLUDE_DIR}
195   $${PROJECT_BINARY_DIR}
196   $${PROJECT_BINARY_DIR}/idl
197   ${includes}
198 )
199
200 # --- definitions ---
201 ADD_DEFINITIONS(
202   $${OMNIORB_DEFINITIONS}
203 )
204
205 # find additional libraries
206 ${find_libs}
207
208 # libraries to link to
209 SET(_link_LIBRARIES
210   $${OMNIORB_LIBRARIES}
211   $${KERNEL_SalomeIDLKernel}
212   $${KERNEL_OpUtil}
213   $${KERNEL_SalomeContainer}
214   $${KERNEL_SalomeDSCContainer}
215   $${KERNEL_SalomeDSCSuperv}
216   $${KERNEL_SalomeDatastream}
217   $${KERNEL_SalomeDSCSupervBasic}
218   $${KERNEL_CalciumC}
219   SalomeIDL${module}
220   ${libs}
221 )
222
223 # --- headers ---
224
225 # header files / no moc processing
226
227 SET(${module}_HEADERS
228   ${component}_i.hxx
229 )
230
231 # --- sources ---
232
233 # sources / static
234 SET(${module}_SOURCES
235   ${component}_i.cxx
236 )
237
238 # --- rules ---
239
240 ADD_LIBRARY(${componentlib} $${${module}_SOURCES})
241 TARGET_LINK_LIBRARIES(${componentlib} $${_link_LIBRARIES} )
242 ${target_properties}
243
244 INSTALL(TARGETS ${componentlib} EXPORT $${PROJECT_NAME}TargetGroup DESTINATION $${SALOME_INSTALL_LIBS})
245
246 INSTALL(FILES $${${module}_HEADERS} DESTINATION $${SALOME_INSTALL_HEADERS})
247 """
248 cmake_src_compo_hxx = Template(cmake_src_compo_hxx)