2 from string import Template
4 from compat import Template,set
7 #include "${component}.hxx"
11 #include <Calcium.hxx>
14 #include <SALOME_NamingService.hxx>
15 #include <Utils_SALOME_Exception.hxx>
17 typedef void (*sighandler_t)(int);
18 sighandler_t setsig(int sig, sighandler_t handler)
20 struct sigaction context, ocontext;
21 context.sa_handler = handler;
22 sigemptyset(&context.sa_mask);
24 if (sigaction(sig, &context, &ocontext) == -1)
26 return ocontext.sa_handler;
29 static void AttachDebugger()
31 if(getenv ("DEBUGGER"))
33 std::stringstream exec;
35 exec << "$$DEBUGGER " << "${exe_path} " << getpid() << "&";
37 exec << "$$DEBUGGER SALOME_Container " << getpid() << "&";
39 std::cerr << exec.str() << std::endl;
40 system(exec.str().c_str());
45 static void THandler(int theSigId)
47 std::cerr << "SIGSEGV: " << std::endl;
49 //to exit or not to exit
53 static void terminateHandler(void)
55 std::cerr << "Terminate: not managed exception !" << std::endl;
57 throw SALOME_Exception("Terminate: not managed exception !");
60 static void unexpectedHandler(void)
62 std::cerr << "Unexpected: unexpected exception !" << std::endl;
64 throw SALOME_Exception("Unexpected: unexpected exception !");
70 #define F_FUNC(lname,uname) __stdcall uname
71 #define F_CALL(lname,uname) uname
72 #define STR_PSTR(str) char *str, int _(Len,str)
74 #define STR_PTR(str) str
75 #define STR_LEN(str) _(Len,str)
76 #define STR_CPTR(str) str,strlen(str)
79 #define F_FUNC(lname,uname) _(lname,_) /* Fortran function name */
80 #define F_CALL(lname,uname) _(lname,_) /* Fortran function call */
81 #define STR_PSTR(str) char *str /* fortran string arg pointer */
82 #define STR_PLEN(str) , int _(Len,str) /* fortran string arg length */
83 #define STR_PTR(str) str /* fortran string pointer */
84 #define STR_LEN(str) _(Len,str) /* fortran string length */
85 #define STR_CPTR(str) str /* fortran string calling arg pointer */
86 #define STR_CLEN(str) , strlen(str) /* fortran string calling arg length */
93 extern "C" void cp_exit(int err);
95 extern "C" void F_FUNC(cpexit,CPEXIT)(int err)
105 //! Constructor for component "${component}" instance
109 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
110 PortableServer::POA_ptr poa,
111 PortableServer::ObjectId * contId,
112 const char *instanceName,
113 const char *interfaceName)
114 : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
116 std::cerr << "create component" << std::endl;
118 setsig(SIGSEGV,&THandler);
119 set_terminate(&terminateHandler);
120 set_unexpected(&unexpectedHandler);
123 _id = _poa->activate_object(_thisObj);
126 ${component}_i::${component}_i(CORBA::ORB_ptr orb,
127 PortableServer::POA_ptr poa,
128 Engines::Container_ptr container,
129 const char *instanceName,
130 const char *interfaceName)
131 : Superv_Component_i(orb, poa, container, instanceName, interfaceName)
134 setsig(SIGSEGV,&THandler);
135 set_terminate(&terminateHandler);
136 set_unexpected(&unexpectedHandler);
139 _id = _poa->activate_object(_thisObj);
142 //! Destructor for component "${component}" instance
143 ${component}_i::~${component}_i()
147 void ${component}_i::destroy()
149 Engines_Component_i::destroy();
151 if(!CORBA::is_nil(_orb))
156 //! Register datastream ports for a component service given its name
158 * \param service_name : service name
159 * \\return true if port registering succeeded, false if not
162 ${component}_i::init_service(const char * service_name) {
163 CORBA::Boolean rtn = false;
164 string s_name(service_name);
173 PortableServer::ObjectId * ${component}Engine_factory( CORBA::ORB_ptr orb,
174 PortableServer::POA_ptr poa,
175 PortableServer::ObjectId * contId,
176 const char *instanceName,
177 const char *interfaceName)
179 MESSAGE("PortableServer::ObjectId * ${component}Engine_factory()");
180 ${component}_i * myEngine = new ${component}_i(orb, poa, contId, instanceName, interfaceName);
181 return myEngine->getId() ;
187 CORBA::ORB_var orb = CORBA::ORB_init( argc , &argv ) ;
188 PortableServer::POAManager_var pman;
189 CORBA::Object_var obj;
192 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
193 obj = orb->resolve_initial_references("RootPOA");
194 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
195 PortableServer::POAManager_var pman = poa->the_POAManager();
196 std::string containerName(getenv("SALOME_CONTAINERNAME"));
197 std::string instanceName(getenv("SALOME_INSTANCE"));
198 obj=orb->string_to_object(getenv("SALOME_CONTAINER"));
199 Engines::Container_var container = Engines::Container::_narrow(obj);
200 ${component}_i * myEngine = new ${component}_i(orb, poa, container, instanceName.c_str(), "${component}");
202 obj=myEngine->_this();
203 Engines::Component_var component = Engines::Component::_narrow(obj);
204 string component_registerName = containerName + "/" + instanceName;
205 salomens->Register(component,component_registerName.c_str());
209 catch(CORBA::Exception&)
211 std::cerr << "Caught CORBA::Exception."<< std::endl;
213 catch(std::exception& exc)
215 std::cerr << "Caught std::exception - "<<exc.what() << std::endl;
219 std::cerr << "Caught unknown exception." << std::endl;
223 void F_FUNC(yacsinit,YACSINIT)()
229 cxxCompo=Template(cxxCompo)
232 #ifndef _${component}_HXX_
233 #define _${component}_HXX_
235 #include "Superv_Component_i.hxx"
236 #include "${module}.hh"
238 class ${component}_i:
239 public virtual POA_${module}::${component},
240 public virtual Superv_Component_i
243 ${component}_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa,
244 PortableServer::ObjectId * contId,
245 const char *instanceName, const char *interfaceName);
246 ${component}_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa,
247 Engines::Container_ptr container,
248 const char *instanceName, const char *interfaceName);
249 virtual ~${component}_i();
251 CORBA::Boolean init_service(const char * service_name);
257 PortableServer::ObjectId * ${component}Engine_factory( CORBA::ORB_ptr orb,
258 PortableServer::POA_ptr poa,
259 PortableServer::ObjectId * contId,
260 const char *instanceName,
261 const char *interfaceName);
267 hxxCompo=Template(hxxCompo)
270 void ${component}_i::${service}(${parameters})
272 std::cerr << "${component}_i::${service}" << std::endl;
273 beginService("${component}_i::${service}");
274 Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
275 char nom_instance[INSTANCE_LEN];
276 int info = cp_cd(component,nom_instance);
282 cp_fin(component,CP_ARRET);
284 catch ( const CalciumException & ex)
286 std::cerr << ex.what() << std::endl;
287 cp_fin(component,CP_ARRET);
288 SALOME::ExceptionStruct es;
289 es.text=CORBA::string_dup(ex.what());
290 es.type=SALOME::INTERNAL_ERROR;
291 throw SALOME::SALOME_Exception(es);
293 catch ( const SALOME_Exception & ex)
295 cp_fin(component,CP_ARRET);
296 SALOME::ExceptionStruct es;
297 es.text=CORBA::string_dup(ex.what());
298 es.type=SALOME::INTERNAL_ERROR;
299 throw SALOME::SALOME_Exception(es);
301 catch ( const SALOME::SALOME_Exception & ex)
303 cp_fin(component,CP_ARRET);
308 std::cerr << "unknown exception" << std::endl;
312 cp_fin(component,CP_ARRET);
313 SALOME::ExceptionStruct es;
314 es.text=CORBA::string_dup(" unknown exception");
315 es.type=SALOME::INTERNAL_ERROR;
316 throw SALOME::SALOME_Exception(es);
318 endService("${component}_i::${service}");
319 std::cerr << "end of ${component}_i::${service}" << std::endl;
323 cxxService=Template(cxxService)
326 if (s_name == "${service}")
330 //initialization CALCIUM ports IN
332 //initialization CALCIUM ports OUT
335 catch(const PortAlreadyDefined& ex)
337 std::cerr << "${component}: " << ex.what() << std::endl;
338 //Ports already created : we use them
342 std::cerr << "${component}: unknown exception" << std::endl;
347 initService=Template(initService)
351 export SALOME_CONTAINER=$$1
352 export SALOME_CONTAINERNAME=$$2
353 export SALOME_INSTANCE=$$3
357 exeCPP=Template(exeCPP)
362 include $$(top_srcdir)/adm_local/make_common_starter.am
364 AM_CFLAGS=$$(KERNEL_INCLUDES) -fexceptions
366 lib_LTLIBRARIES = lib${component}Engine.la
367 lib${component}Engine_la_SOURCES = ${component}.cxx
368 nodist_lib${component}Engine_la_SOURCES =
369 lib${component}Engine_la_CXXFLAGS = -I$$(top_builddir)/idl $$(KERNEL_INCLUDES) ${includes}
370 lib${component}Engine_la_FFLAGS = $$(KERNEL_INCLUDES) -fexceptions ${includes}
371 lib${component}Engine_la_LIBADD = -L$$(top_builddir)/idl -l${module} $$(FLIBS) ${libs}
372 lib${component}Engine_la_LDFLAGS = ${rlibs}
373 salomeinclude_HEADERS = ${component}.hxx
375 compoMakefile=Template(compoMakefile)
378 include $$(top_srcdir)/adm_local/make_common_starter.am
380 AM_CFLAGS=$$(KERNEL_INCLUDES) -fexceptions
382 lib_LTLIBRARIES = lib${component}Exelib.la
383 lib${component}Exelib_la_SOURCES = ${component}.cxx
384 nodist_lib${component}Exelib_la_SOURCES =
385 lib${component}Exelib_la_CXXFLAGS = -I$$(top_builddir)/idl $$(KERNEL_INCLUDES) ${includes}
386 lib${component}Exelib_la_FFLAGS = $$(KERNEL_INCLUDES) -fexceptions ${includes}
387 lib${component}Exelib_la_LIBADD = -L$$(top_builddir)/idl -l${module} $$(FLIBS) ${libs}
388 lib${component}Exelib_la_LDFLAGS = ${rlibs}
389 salomeinclude_HEADERS = ${component}.hxx
390 # These files are executable scripts
391 dist_salomescript_SCRIPTS= ${component}.exe
393 compoEXEMakefile=Template(compoEXEMakefile)