TAO_AV_Endpoint_Process_Strategy Class Reference

Process-based strategy for creating endpoints. Abstract base class. More...

#include <Endpoint_Strategy.h>

Inheritance diagram for TAO_AV_Endpoint_Process_Strategy:

Inheritance graph
[legend]
Collaboration diagram for TAO_AV_Endpoint_Process_Strategy:

Collaboration graph
[legend]
List of all members.

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 (ACE_ENV_SINGLE_ARG_DECL)
 Bind to the naming service.

virtual int get_stream_endpoint (ACE_ENV_SINGLE_ARG_DECL)=0
virtual int get_vdev (ACE_ENV_SINGLE_ARG_DECL)

Protected Attributes

CosNaming::NamingContext_var naming_context_
 Naming context.

ACE_Process_Optionsprocess_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.


Detailed Description

Process-based strategy for creating endpoints. Abstract base class.

Definition at line 78 of file Endpoint_Strategy.h.


Constructor & Destructor Documentation

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 77 of file Endpoint_Strategy.cpp.

References ACE_OS::hostname().

00078   : process_options_ (process_options),
00079     pid_ (-1)
00080 {
00081   ACE_OS::hostname (this->host_,
00082                     sizeof this->host_);
00083 }

TAO_AV_Endpoint_Process_Strategy::~TAO_AV_Endpoint_Process_Strategy void   )  [virtual]
 

Destructor.

Definition at line 86 of file Endpoint_Strategy.cpp.

00087 {
00088 }


Member Function Documentation

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 95 of file Endpoint_Strategy.cpp.

References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_ERROR_RETURN, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, ACE_Process_Semaphore::acquire(), bind_to_naming_service(), get_stream_endpoint(), get_vdev(), ACE_OS::kill(), LM_DEBUG, LM_ERROR, ACE_Process_Semaphore::remove(), ACE_Process::spawn(), and ACE_OS::sprintf().

00096 {
00097   ACE_Process process;
00098 
00099   // Create a new process to contain this endpoint
00100   this->pid_ = process.spawn (*this->process_options_);
00101 
00102   // Process creation failed
00103   if (this->pid_ == -1)
00104     ACE_ERROR_RETURN ((LM_ERROR,
00105                        "(%P|%t) ACE_Process:: spawn failed: %p\n",
00106                        "spawn"),
00107                       -1);
00108 
00109   // Create a unique semaphore name, using my hostname, and pid.
00110   char sem_str [BUFSIZ];
00111 
00112   // create a unique semaphore name
00113   ACE_OS::sprintf (sem_str,
00114                    "%s:%s:%ld",
00115                    "TAO_AV_Process_Semaphore",
00116                    this->host_,
00117                    static_cast<long int> (this->pid_));
00118 
00119   ACE_DEBUG ((LM_DEBUG,
00120               "(%P|%t) semaphore is %s\n",
00121               sem_str));
00122   // Create the semaphore
00123   ACE_Process_Semaphore semaphore (0, // 0 means that the
00124                                    // semaphore is locked initially
00125                                    sem_str);
00126 
00127   // wait until the child finishes booting
00128   while (1)
00129     {
00130       if (semaphore.acquire () == -1)
00131         {
00132           // See if my child process is still alive -- if not, return an error
00133           if (ACE_OS::kill (this->pid_,
00134                             0) == -1)
00135             ACE_ERROR_RETURN ((LM_ERROR,
00136                                "(%P|%t) Process_Strategy: Process being waited on died unexpectedly.\n"),
00137                               -1);
00138           // if we were not interrupted due to a EINTR, break
00139           if (errno != EINTR)
00140             break;
00141         }
00142       else
00143         break;
00144     }
00145 
00146   // The job of the semaphore is done, remove it.
00147   if (semaphore.remove () == -1)
00148     ACE_ERROR_RETURN ((LM_ERROR,
00149                        "(%P|%t) semaphore remove failed: %p\n",
00150                        "remove"),
00151                       -1);
00152 
00153   ACE_DECLARE_NEW_CORBA_ENV;
00154   ACE_TRY
00155     {
00156       // Get ourselves a Naming service
00157       this->bind_to_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER);
00158       ACE_TRY_CHECK;
00159 
00160       // Get the stream endpoint created by the child from the naming service
00161       this->get_stream_endpoint (ACE_ENV_SINGLE_ARG_PARAMETER);
00162       ACE_TRY_CHECK;
00163 
00164       // Get the Vdev created by the child from the naming service
00165       this->get_vdev (ACE_ENV_SINGLE_ARG_PARAMETER);
00166       ACE_TRY_CHECK;
00167     }
00168   ACE_CATCHANY
00169     {
00170       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_AV_Endpoint_Process_Strategy::activate");
00171       return -1;
00172     }
00173   ACE_ENDTRY;
00174   ACE_CHECK_RETURN (-1);
00175   return 0;
00176 }

virtual int TAO_AV_Endpoint_Process_Strategy::bind_to_naming_service ACE_ENV_SINGLE_ARG_DECL   )  [protected, virtual]
 

Bind to the naming service.

Referenced by activate().

virtual int TAO_AV_Endpoint_Process_Strategy::get_stream_endpoint ACE_ENV_SINGLE_ARG_DECL   )  [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().

virtual int TAO_AV_Endpoint_Process_Strategy::get_vdev ACE_ENV_SINGLE_ARG_DECL   )  [protected, virtual]
 

Get the Vdev object reference for the newly created endpoint

Referenced by activate().


Member Data Documentation

char TAO_AV_Endpoint_Process_Strategy::host_[MAXHOSTNAMELEN] [protected]
 

name of this host used for resolving unique names.

Definition at line 116 of file Endpoint_Strategy.h.

CosNaming::NamingContext_var TAO_AV_Endpoint_Process_Strategy::naming_context_ [protected]
 

Naming context.

Definition at line 110 of file Endpoint_Strategy.h.

pid_t TAO_AV_Endpoint_Process_Strategy::pid_ [protected]
 

My child's process id.

Definition at line 119 of file Endpoint_Strategy.h.

ACE_Process_Options* TAO_AV_Endpoint_Process_Strategy::process_options_ [protected]
 

Name and arguments for the process to be created.

Definition at line 113 of file Endpoint_Strategy.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:47:00 2006 for TAO_AV by doxygen 1.3.6