44 #include "TaskContextS.h" 45 #include <orbsvcs/CosNamingC.h> 47 #include <ace/SString.h> 48 #include "tao/TimeBaseC.h" 49 #include "tao/Messaging/Messaging.h" 50 #include "tao/Messaging/Messaging_RT_PolicyC.h" 52 #include <omniORB4/Naming.hh> 54 #include "TaskContextC.h" 61 #include "../../os/threads.hpp" 62 #include "../../Activity.hpp" 63 #include "../../types/GlobalsRepository.hpp" 81 servers.erase(mtaskcontext);
84 iors.erase(mtaskcontext);
86 PortableServer::ObjectId_var oid = mpoa->servant_to_id(mtask_i.in());
87 mpoa->deactivate_object(oid);
91 CORBA::Object_var rootObj = orb->resolve_initial_references(
"NameService");
92 CosNaming::NamingContext_var rootNC = CosNaming::NamingContext::_narrow(rootObj.in());
94 if (CORBA::is_nil( rootNC.in() ) ) {
95 log(
Warning) <<
"CTaskContext '"<< mregistered_name <<
"' could not find CORBA Naming Service."<<
endlog();
100 name[0].id = CORBA::string_dup(
"TaskContexts");
101 name[1].id = CORBA::string_dup( mregistered_name.c_str() );
103 rootNC->unbind(name);
104 log(
Info) <<
"Successfully removed CTaskContext '"<< mregistered_name <<
"' from CORBA Naming Service."<<
endlog();
106 catch( CosNaming::NamingContext::NotFound ) {
107 log(
Info) <<
"CTaskContext '"<< mregistered_name <<
"' task was already unbound."<<
endlog();
110 log(
Warning) <<
"CTaskContext '"<< mregistered_name <<
"' unbinding failed."<<
endlog();
114 log(
Warning) <<
"CTaskContext '"<< mregistered_name <<
"' unbinding failed from CORBA Naming Service."<<
endlog();
123 servers[mtaskcontext] =
this;
127 CORBA::Object_var poa_object =
128 orb->resolve_initial_references (
"RootPOA");
129 mpoa = PortableServer::POA::_narrow(poa_object);
130 PortableServer::POAManager_var poa_manager =
131 mpoa->the_POAManager ();
150 CORBA::String_var ior = orb->object_to_string( mtask.in() );
151 iors[mtaskcontext] = std::string( ior.in() );
154 CORBA::Object_var rootObj;
155 CosNaming::NamingContext_var rootNC;
157 rootObj = orb->resolve_initial_references(
"NameService");
158 rootNC = CosNaming::NamingContext::_narrow(rootObj);
161 if (CORBA::is_nil( rootNC ) ) {
162 std::string err(
"CTaskContext '" + mregistered_name +
"' could not find CORBA Naming Service.");
163 if (require_name_service) {
165 servers.erase(mtaskcontext);
171 #ifndef ORO_NO_EMIT_CORBA_IOR 172 log() <<
"Writing IOR to 'std::cerr' and file '" << mregistered_name <<
".ior'"<<
endlog();
175 CORBA::String_var ior = orb->object_to_string( mtask.in() );
179 std::string iorname( mregistered_name );
181 std::ofstream file_ior( iorname.c_str() );
188 log(
Info) <<
"CTaskContext '"<< mregistered_name <<
"' found CORBA Naming Service."<<
endlog();
190 CosNaming::Name name;
192 name[0].id = CORBA::string_dup(
"TaskContexts");
193 CosNaming::NamingContext_var controlNC;
195 controlNC = rootNC->bind_new_context(name);
197 catch( CosNaming::NamingContext::AlreadyBound&) {
198 log(
Debug) <<
"NamingContext 'TaskContexts' already bound to CORBA Naming Service."<<
endlog();
203 name[1].id = CORBA::string_dup( mregistered_name.c_str() );
205 rootNC->bind(name, mtask );
206 log(
Info) <<
"Successfully added CTaskContext '"<< mregistered_name <<
"' to CORBA Naming Service."<<
endlog();
208 catch( CosNaming::NamingContext::AlreadyBound&) {
209 log(
Warning) <<
"CTaskContext '"<< mregistered_name <<
"' already bound to CORBA Naming Service."<<
endlog();
210 log() <<
"Trying to rebind...";
212 rootNC->rebind(name, mtask);
217 log() <<
" done. New CTaskContext bound to Naming Service."<<
endlog();
221 log(
Info) <<
"CTaskContext '"<< mregistered_name <<
"' is not using the CORBA Naming Service."<<
endlog();
222 #ifndef ORO_NO_EMIT_CORBA_IOR 223 log() <<
"Writing IOR to 'std::cerr' and file '" << mregistered_name <<
".ior'"<<
endlog();
226 CORBA::String_var ior = orb->object_to_string( mtask.in() );
230 std::string iorname( mregistered_name );
232 std::ofstream file_ior( iorname.c_str() );
239 catch (CORBA::Exception &e) {
247 : mtaskcontext(taskc), muse_naming(use_naming), mregistered_name(alias)
249 this->initTaskContextServer(require_name_service);
254 : mtaskcontext(taskc), muse_naming(use_naming), mregistered_name(taskc->getName())
263 delete servers.begin()->second;
272 if ( !CORBA::is_nil(
orb) ) {
273 ServerMap::iterator it =
servers.find(c);
295 if ( CORBA::is_nil(
orb) ) {
302 log(
Info) <<
"Orb Shutdown...";
304 if (wait_for_completion)
306 orb->shutdown( wait_for_completion );
309 catch (CORBA::Exception &e) {
310 log(
Error) <<
"Orb Shutdown...failed! CORBA exception raised." <<
endlog();
319 if ( CORBA::is_nil(
orb) ) {
328 catch (CORBA::Exception &e) {
341 OrbRunner(
int scheduler,
int priority,
unsigned cpu_affinity)
342 :
Activity(scheduler, priority, 0.0, cpu_affinity, 0,
"OrbRunner")
371 scheduler.
refresh(global_repository->getProperty(
"OrbRunnerScheduler"));
373 priority.
refresh(global_repository->getProperty(
"OrbRunnerPriority"));
375 cpu_affinity.
refresh(global_repository->getProperty(
"OrbRunnerCpuAffinity"));
377 return ThreadOrb(scheduler, priority, cpu_affinity);
382 if ( CORBA::is_nil(
orb) ) {
398 if ( CORBA::is_nil(
orb) ) {
418 catch (CORBA::Exception &e) {
419 log(
Error) <<
"Orb Destroy : CORBA exception raised!" <<
endlog();
430 if ( CORBA::is_nil(
orb) )
434 log(
Debug) <<
"Returning existing TaskContextServer for "<< alias <<
endlog();
435 return servers.find(tc)->second;
439 log(
Info) <<
"Creating new TaskContextServer for "<< alias <<
endlog();
455 if ( CORBA::is_nil(
orb) )
456 return CTaskContext::_nil();
459 log(
Debug) <<
"Returning existing TaskContextServer for "<< alias <<
endlog();
460 return CTaskContext::_duplicate(
servers.find(tc)->second->server() );
464 if ( (it->first) == tc ) {
465 log(
Debug) <<
"Returning server of Proxy for "<< alias <<
endlog();
466 return CTaskContext::_duplicate(it->second);
470 log(
Info) <<
"Creating new TaskContextServer for "<< alias <<
endlog();
473 return CTaskContext::_duplicate( cts->
server() );
478 return CTaskContext::_nil();
490 IorMap::const_iterator it =
iors.find(tc);
491 if (it !=
iors.end())
494 return std::string(
"");
virtual bool refresh(const base::PropertyBase *other)
Service::shared_ptr provides()
static shared_ptr Instance()
virtual RTT::corba::CTaskContext_ptr activate_this()
#define CORBA_EXCEPTION_INFO(x)
boost::shared_ptr< GlobalsRepository > shared_ptr
static CTaskContext_ptr CreateServer(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
static std::string getIOR(TaskContext *tc)
TaskContextServer(TaskContext *taskcontext, bool use_naming, bool require_name_service)
static void clearServants()
void initTaskContextServer(bool require_name_service)
OrbRunner(int scheduler, int priority, unsigned cpu_affinity)
static void CleanupServer(TaskContext *tc)
const char * what() const
static base::ActivityInterface * orbrunner
static PortableServer::POA_var rootPOA
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
basic_ostreams & endl(basic_ostreams &s)
An Activity executes a RunnableInterface object in a (periodic) thread.
corba::CTaskContext_var mtask
static void deregisterServant(DataFlowInterface *obj)
static void CleanupServers()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
static void ShutdownOrb(bool wait_for_completion=true)
static void DoShutdownOrb(bool wait_for_completion=true)
static Logger::LogFunction endlog()
CTaskContext_ptr server() const
static CORBA::ORB_var orb
virtual const std::string & getName() const