Salome HOME
PAL issue 2757: Traiter de manière masquée lâ\80\99exécution de la commande DEBUT...
[tools/yacsgen.git] / module_generator / hxx_para_tmpl.py
1 # Copyright (C) 2009-2013  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.
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 #, SALOME_MED::MED_Gen_Driver, SALOME::MultiCommClass
205 interfaceidlhxx="""
206   interface ${component}_Gen: ${inherited}
207   {
208 ${services}
209   };
210 """
211 interfaceidlhxx=Template(interfaceidlhxx)
212
213
214 compoMakefile=Template(compoMakefile)