#include <Endpoint_Strategy.h>
Inheritance diagram for TAO_AV_Endpoint_Process_Strategy:
Public Member Functions | |
TAO_AV_Endpoint_Process_Strategy (ACE_Process_Options *process_options) | |
virtual | ~TAO_AV_Endpoint_Process_Strategy (void) |
Destructor. | |
virtual int | activate (void) |
Protected Member Functions | |
virtual int | bind_to_naming_service (void) |
Bind to the naming service. | |
virtual int | get_stream_endpoint (void)=0 |
virtual int | get_vdev (void) |
Protected Attributes | |
CosNaming::NamingContext_var | naming_context_ |
Naming context. | |
ACE_Process_Options * | process_options_ |
Name and arguments for the process to be created. | |
char | host_ [MAXHOSTNAMELEN] |
name of this host used for resolving unique names. | |
pid_t | pid_ |
My child's process id. |
Definition at line 76 of file Endpoint_Strategy.h.
TAO_AV_Endpoint_Process_Strategy::TAO_AV_Endpoint_Process_Strategy | ( | ACE_Process_Options * | process_options | ) |
Constructor. The process_options contain the name and arguments for the process to be created
Definition at line 71 of file Endpoint_Strategy.cpp.
References ACE_OS::hostname().
00072 : process_options_ (process_options), 00073 pid_ (-1) 00074 { 00075 ACE_OS::hostname (this->host_, 00076 sizeof this->host_); 00077 }
TAO_AV_Endpoint_Process_Strategy::~TAO_AV_Endpoint_Process_Strategy | ( | void | ) | [virtual] |
int TAO_AV_Endpoint_Process_Strategy::activate | ( | void | ) | [virtual] |
creates a new child process, and waits on a semaphore until the child process has finished creating the endpoints
Definition at line 89 of file Endpoint_Strategy.cpp.
References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, ACE_ERROR_RETURN, ACE_Process_Semaphore::acquire(), bind_to_naming_service(), get_stream_endpoint(), get_vdev(), ACE_OS::kill(), LM_DEBUG, LM_ERROR, pid_, ACE_Process_Semaphore::remove(), ACE_Process::spawn(), and ACE_OS::sprintf().
00090 { 00091 ACE_Process process; 00092 00093 // Create a new process to contain this endpoint 00094 this->pid_ = process.spawn (*this->process_options_); 00095 00096 // Process creation failed 00097 if (this->pid_ == -1) 00098 ACE_ERROR_RETURN ((LM_ERROR, 00099 "(%P|%t) ACE_Process:: spawn failed: %p\n", 00100 "spawn"), 00101 -1); 00102 00103 // Create a unique semaphore name, using my hostname, and pid. 00104 char sem_str [BUFSIZ]; 00105 00106 // create a unique semaphore name 00107 ACE_OS::sprintf (sem_str, 00108 "%s:%s:%ld", 00109 "TAO_AV_Process_Semaphore", 00110 this->host_, 00111 static_cast<long int> (this->pid_)); 00112 00113 ACE_DEBUG ((LM_DEBUG, 00114 "(%P|%t) semaphore is %s\n", 00115 sem_str)); 00116 // Create the semaphore 00117 ACE_Process_Semaphore semaphore (0, // 0 means that the 00118 // semaphore is locked initially 00119 sem_str); 00120 00121 // wait until the child finishes booting 00122 while (1) 00123 { 00124 if (semaphore.acquire () == -1) 00125 { 00126 // See if my child process is still alive -- if not, return an error 00127 if (ACE_OS::kill (this->pid_, 00128 0) == -1) 00129 ACE_ERROR_RETURN ((LM_ERROR, 00130 "(%P|%t) Process_Strategy: Process being waited on died unexpectedly.\n"), 00131 -1); 00132 // if we were not interrupted due to a EINTR, break 00133 if (errno != EINTR) 00134 break; 00135 } 00136 else 00137 break; 00138 } 00139 00140 // The job of the semaphore is done, remove it. 00141 if (semaphore.remove () == -1) 00142 ACE_ERROR_RETURN ((LM_ERROR, 00143 "(%P|%t) semaphore remove failed: %p\n", 00144 "remove"), 00145 -1); 00146 00147 try 00148 { 00149 // Get ourselves a Naming service 00150 this->bind_to_naming_service (); 00151 00152 // Get the stream endpoint created by the child from the naming service 00153 this->get_stream_endpoint (); 00154 00155 // Get the Vdev created by the child from the naming service 00156 this->get_vdev (); 00157 } 00158 catch (const CORBA::Exception& ex) 00159 { 00160 ex._tao_print_exception ( 00161 "TAO_AV_Endpoint_Process_Strategy::activate"); 00162 return -1; 00163 } 00164 return 0; 00165 }
int TAO_AV_Endpoint_Process_Strategy::bind_to_naming_service | ( | void | ) | [protected, virtual] |
Bind to the naming service.
Definition at line 169 of file Endpoint_Strategy.cpp.
References CORBA::Exception::_tao_print_exception(), ACE_ERROR_RETURN, TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), LM_ERROR, naming_context_, TAO_ORB_Core::orb(), CORBA::ORB::resolve_initial_references(), and TAO_ORB_Core_instance().
Referenced by activate().
00170 { 00171 try 00172 { 00173 if (CORBA::is_nil (this->naming_context_.in ()) == 0) 00174 return 0; 00175 00176 CORBA::Object_var naming_obj = 00177 TAO_ORB_Core_instance ()->orb ()->resolve_initial_references ("NameService"); 00178 00179 if (CORBA::is_nil (naming_obj.in ())) 00180 ACE_ERROR_RETURN ((LM_ERROR, 00181 " (%P|%t) Unable to resolve the Name Service.\n"), 00182 -1); 00183 this->naming_context_ = 00184 CosNaming::NamingContext::_narrow (naming_obj.in ()); 00185 } 00186 catch (const CORBA::Exception& ex) 00187 { 00188 ex._tao_print_exception ( 00189 "TAO_AV_Endpoint_Process_Strategy::bind_to_naming_service"); 00190 return -1; 00191 } 00192 return 0; 00193 }
virtual int TAO_AV_Endpoint_Process_Strategy::get_stream_endpoint | ( | void | ) | [protected, pure virtual] |
Get the object reference for the newly created stream endpoint (which will be in the child process) Subclasses will define the functionality for this
Implemented in TAO_AV_Endpoint_Process_Strategy_A, and TAO_AV_Endpoint_Process_Strategy_B.
Referenced by activate().
int TAO_AV_Endpoint_Process_Strategy::get_vdev | ( | void | ) | [protected, virtual] |
Get the Vdev object reference for the newly created endpoint
Definition at line 197 of file Endpoint_Strategy.cpp.
References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, ACE_ERROR_RETURN, TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, naming_context_, ACE_OS::sprintf(), CORBA::string_dup(), TAO_debug_level, and TAO_AV_Endpoint_Strategy::vdev_.
Referenced by activate().
00198 { 00199 try 00200 { 00201 char vdev_name [BUFSIZ]; 00202 ACE_OS::sprintf (vdev_name, 00203 "%s:%s:%ld", 00204 "VDev", 00205 this->host_, 00206 (long) this->pid_); 00207 00208 if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)%s\n",vdev_name)); 00209 00210 // Create the name 00211 CosNaming::Name VDev_Name (1); 00212 VDev_Name.length (1); 00213 VDev_Name [0].id = CORBA::string_dup (vdev_name); 00214 00215 // Get the CORBA::Object 00216 CORBA::Object_var vdev = 00217 this->naming_context_->resolve (VDev_Name); 00218 00219 // Narrow it 00220 this->vdev_ = 00221 AVStreams::VDev::_narrow (vdev.in ()); 00222 00223 // Check if valid 00224 if (CORBA::is_nil (this->vdev_.in() )) 00225 ACE_ERROR_RETURN ((LM_ERROR, 00226 " could not resolve Stream_Endpoint_B in Naming service <%s>\n"), 00227 -1); 00228 } 00229 catch (const CORBA::Exception& ex) 00230 { 00231 ex._tao_print_exception ( 00232 "TAO_AV_Endpoint_Process_Strategy::get_vdev"); 00233 return -1; 00234 } 00235 return 0; 00236 }
char TAO_AV_Endpoint_Process_Strategy::host_[MAXHOSTNAMELEN] [protected] |
name of this host used for resolving unique names.
Definition at line 114 of file Endpoint_Strategy.h.
CosNaming::NamingContext_var TAO_AV_Endpoint_Process_Strategy::naming_context_ [protected] |
Naming context.
Definition at line 108 of file Endpoint_Strategy.h.
Referenced by bind_to_naming_service(), TAO_AV_Endpoint_Process_Strategy_B::get_stream_endpoint(), TAO_AV_Endpoint_Process_Strategy_A::get_stream_endpoint(), and get_vdev().
pid_t TAO_AV_Endpoint_Process_Strategy::pid_ [protected] |
My child's process id.
Definition at line 117 of file Endpoint_Strategy.h.
Referenced by activate().
Name and arguments for the process to be created.
Definition at line 111 of file Endpoint_Strategy.h.