1 # Copyright (C) 2009-2015 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from string import Template
23 from compat import Template,set
26 #include "${component}.hxx"
30 #include <Calcium.hxx>
31 #include <CalciumException.hxx>
34 #include <SALOME_NamingService.hxx>
35 #include <Utils_SALOME_Exception.hxx>
39 #define BUILD_EXE ${exe}
41 typedef void (*sighandler_t)(int);
42 sighandler_t setsig(int sig, sighandler_t handler)
44 struct sigaction context, ocontext;
45 context.sa_handler = handler;
46 sigemptyset(&context.sa_mask);
48 if (sigaction(sig, &context, &ocontext) == -1)
50 return ocontext.sa_handler;
53 static void AttachDebugger()
60 size = backtrace (array, size);
61 strings = backtrace_symbols (array, size);
62 for (i = 0; i < size; i++)
63 _what=_what+strings[i]+ '\\n';
66 std::cerr << pthread_self() << std::endl;
67 std::cerr << _what << std::endl;
69 if(getenv ("DEBUGGER"))
71 std::stringstream exec;
73 exec << "$$DEBUGGER " << "${exe_path} " << getpid() << "&";
75 exec << "$$DEBUGGER SALOME_Container " << getpid() << "&";
77 std::cerr << exec.str() << std::endl;
78 system(exec.str().c_str());
83 static void THandler(int theSigId)
85 std::cerr << "SIGSEGV: " << std::endl;
87 //to exit or not to exit
91 static void terminateHandler(void)
93 std::cerr << "Terminate: not managed exception !" << std::endl;
95 throw SALOME_Exception("Terminate: not managed exception !");
98 static void unexpectedHandler(void)
100 std::cerr << "Unexpected: unexpected exception !" << std::endl;
102 throw SALOME_Exception("Unexpected: unexpected exception !");
108 #define F_FUNC(lname,uname) __stdcall uname
109 #define F_CALL(lname,uname) uname
110 #define STR_PSTR(str) char *str, int _(Len,str)
111 #define STR_PLEN(str)
112 #define STR_PTR(str) str
113 #define STR_LEN(str) _(Len,str)
114 #define STR_CPTR(str) str,strlen(str)
115 #define STR_CLEN(str)
117 #define F_FUNC(lname,uname) _(lname,_) /* Fortran function name */
118 #define F_CALL(lname,uname) _(lname,_) /* Fortran function call */
119 #define STR_PSTR(str) char *str /* fortran string arg pointer */
120 #define STR_PLEN(str) , int _(Len,str) /* fortran string arg length */
121 #define STR_PTR(str) str /* fortran string pointer */
122 #define STR_LEN(str) _(Len,str) /* fortran string length */
123 #define STR_CPTR(str) str /* fortran string calling arg pointer */
124 #define STR_CLEN(str) , strlen(str) /* fortran string calling arg length */
133 extern "C" void cp_exit(int err);
135 extern "C" void F_FUNC(cpexit,CPEXIT)(int *err)
145 //! Constructor for component "${component}" instance
149 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
150 PortableServer::POA_ptr poa,
151 PortableServer::ObjectId * contId,
152 const char *instanceName,
153 const char *interfaceName)
154 : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
157 setsig(SIGSEGV,&THandler);
158 set_terminate(&terminateHandler);
159 set_unexpected(&unexpectedHandler);
162 _id = _poa->activate_object(_thisObj);
165 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
166 PortableServer::POA_ptr poa,
167 Engines::Container_ptr container,
168 const char *instanceName,
169 const char *interfaceName)
170 : Superv_Component_i(orb, poa, container, instanceName, interfaceName)
173 setsig(SIGSEGV,&THandler);
174 set_terminate(&terminateHandler);
175 set_unexpected(&unexpectedHandler);
178 _id = _poa->activate_object(_thisObj);
181 //! Destructor for component "${component}" instance
182 ${component}_i::~${component}_i()
186 void ${component}_i::destroy()
190 if(!CORBA::is_nil(_orb))
193 Engines_Component_i::destroy();
197 //! Register datastream ports for a component service given its name
199 * \param service_name : service name
200 * \\return true if port registering succeeded, false if not
203 ${component}_i::init_service(const char * service_name) {
204 CORBA::Boolean rtn = false;
205 string s_name(service_name);
214 PortableServer::ObjectId * ${component}Engine_factory( CORBA::ORB_ptr orb,
215 PortableServer::POA_ptr poa,
216 PortableServer::ObjectId * contId,
217 const char *instanceName,
218 const char *interfaceName)
220 MESSAGE("PortableServer::ObjectId * ${component}Engine_factory()");
221 ${component}_i * myEngine = new ${component}_i(orb, poa, contId, instanceName, interfaceName);
222 return myEngine->getId() ;
228 CORBA::ORB_var orb = CORBA::ORB_init( argc , &argv ) ;
229 PortableServer::POAManager_var pman;
230 CORBA::Object_var obj;
233 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
234 obj = orb->resolve_initial_references("RootPOA");
235 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
236 PortableServer::POAManager_var pman = poa->the_POAManager();
237 std::string containerName(getenv("SALOME_CONTAINERNAME"));
238 std::string instanceName(getenv("SALOME_INSTANCE"));
239 obj=orb->string_to_object(getenv("SALOME_CONTAINER"));
240 Engines::Container_var container = Engines::Container::_narrow(obj);
241 ${component}_i * myEngine = new ${component}_i(orb, poa, container, instanceName.c_str(), "${component}");
243 obj=myEngine->POA_${module}_ORB::${component}::_this();
244 Engines::EngineComponent_var component = Engines::EngineComponent::_narrow(obj);
245 string component_registerName = containerName + "/" + instanceName;
246 salomens->Register(component,component_registerName.c_str());
250 catch(CORBA::Exception&)
252 std::cerr << "Caught CORBA::Exception."<< std::endl;
254 catch(std::exception& exc)
256 std::cerr << "Caught std::exception - "<<exc.what() << std::endl;
260 std::cerr << "Caught unknown exception." << std::endl;
264 void F_FUNC(yacsinit,YACSINIT)()
270 cxxCompo=Template(cxxCompo)
273 #ifndef _${component}_HXX_
274 #define _${component}_HXX_
276 #include <SALOME_Component.hh>
277 #include "Superv_Component_i.hxx"
278 #include "${module}.hh"
284 class ${component}_i: public virtual POA_${module}_ORB::${component},
285 ${inheritedclass} public virtual Superv_Component_i
288 ${component}_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa,
289 PortableServer::ObjectId * contId,
290 const char *instanceName, const char *interfaceName);
291 ${component}_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa,
292 Engines::Container_ptr container,
293 const char *instanceName, const char *interfaceName);
294 virtual ~${component}_i();
296 CORBA::Boolean init_service(const char * service_name);
302 PortableServer::ObjectId * ${component}Engine_factory( CORBA::ORB_ptr orb,
303 PortableServer::POA_ptr poa,
304 PortableServer::ObjectId * contId,
305 const char *instanceName,
306 const char *interfaceName);
312 hxxCompo=Template(hxxCompo)
315 void ${component}_i::${service}(${parameters})
317 beginService("${component}_i::${service}");
318 Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
319 //char nom_instance[INSTANCE_LEN];
320 //int info = cp_cd(component,nom_instance);
326 //cp_fin(component,CP_ARRET);
328 catch ( const CalciumException & ex)
330 std::cerr << ex.what() << std::endl;
331 //cp_fin(component,CP_ARRET);
332 SALOME::ExceptionStruct es;
333 es.text=CORBA::string_dup(ex.what());
334 es.type=SALOME::INTERNAL_ERROR;
335 throw SALOME::SALOME_Exception(es);
337 catch ( const SALOME_Exception & ex)
339 //cp_fin(component,CP_ARRET);
340 SALOME::ExceptionStruct es;
341 es.text=CORBA::string_dup(ex.what());
342 es.type=SALOME::INTERNAL_ERROR;
343 throw SALOME::SALOME_Exception(es);
345 catch ( const SALOME::SALOME_Exception & ex)
347 //cp_fin(component,CP_ARRET);
350 catch ( const std::exception& ex)
352 //std::cerr << typeid(ex).name() << std::endl;
353 SALOME::ExceptionStruct es;
354 es.text=CORBA::string_dup(ex.what());
355 es.type=SALOME::INTERNAL_ERROR;
356 throw SALOME::SALOME_Exception(es);
360 std::cerr << "unknown exception" << std::endl;
364 //cp_fin(component,CP_ARRET);
365 SALOME::ExceptionStruct es;
366 es.text=CORBA::string_dup(" unknown exception");
367 es.type=SALOME::INTERNAL_ERROR;
368 throw SALOME::SALOME_Exception(es);
370 endService("${component}_i::${service}");
374 cxxService=Template(cxxService)
377 if (s_name == "${service}")
381 //initialization CALCIUM ports IN
383 //initialization CALCIUM ports OUT
386 catch(const PortAlreadyDefined& ex)
388 std::cerr << "${component}: " << ex.what() << std::endl;
389 //Ports already created : we use them
393 std::cerr << "${component}: unknown exception" << std::endl;
398 initService=Template(initService)
402 export SALOME_CONTAINER=$$1
403 export SALOME_CONTAINERNAME=$$2
404 export SALOME_INSTANCE=$$3
408 exeCPP=Template(exeCPP)
412 # CMakeLists.txt in src/<component>
413 # template parameters:
414 # module : module name
415 # component : component name
416 # componentlib : name of the target library
417 # includes : additional headers, separated by spaces or \n. can be empty
418 # sources : additional sources, separated by spaces or \n. can be empty
419 # libs : additional libraries
420 # find_libs : find_library commands
421 # target_properties : set_target_properties commands
422 cmake_src_compo_cpp = """
424 # additional include directories
426 $${KERNEL_INCLUDE_DIRS}
427 $${OMNIORB_INCLUDE_DIR}
428 $${PROJECT_BINARY_DIR}
429 $${PROJECT_BINARY_DIR}/idl
433 # --- definitions ---
435 $${OMNIORB_DEFINITIONS}
438 # find additional libraries
441 # libraries to link to
443 $${OMNIORB_LIBRARIES}
444 $${KERNEL_SalomeIDLKernel}
446 $${KERNEL_SalomeContainer}
453 # header files / no moc processing
455 SET(${module}_HEADERS
462 SET(${module}_SOURCES
469 ADD_LIBRARY(${componentlib} $${${module}_SOURCES})
470 TARGET_LINK_LIBRARIES(${componentlib} $${_link_LIBRARIES} )
472 INSTALL(TARGETS ${componentlib} EXPORT $${PROJECT_NAME}TargetGroup DESTINATION $${SALOME_INSTALL_LIBS})
474 INSTALL(FILES $${${module}_HEADERS} DESTINATION $${SALOME_INSTALL_HEADERS})
476 cmake_src_compo_cpp = Template(cmake_src_compo_cpp)