Public Member Functions | Protected Member Functions | Protected Attributes

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 (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_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 76 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 71 of file Endpoint_Strategy.cpp.

  : process_options_ (process_options),
    pid_ (-1)
{
  ACE_OS::hostname (this->host_,
                    sizeof this->host_);
}

TAO_AV_Endpoint_Process_Strategy::~TAO_AV_Endpoint_Process_Strategy ( void   )  [virtual]

Destructor.

Definition at line 80 of file Endpoint_Strategy.cpp.

{
}


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

{
  ACE_Process process;

  // Create a new process to contain this endpoint
  this->pid_ = process.spawn (*this->process_options_);

  // Process creation failed
  if (this->pid_ == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) ACE_Process:: spawn failed: %p\n",
                       "spawn"),
                      -1);

  // Create a unique semaphore name, using my hostname, and pid.
  ACE_TCHAR sem_str [BUFSIZ];

  // create a unique semaphore name
  ACE_OS::sprintf (sem_str,
                   ACE_TEXT("%s:%s:%ld"),
                   "TAO_AV_Process_Semaphore",
                   this->host_,
                   static_cast<long int> (this->pid_));

  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) semaphore is %s\n",
              sem_str));
  // Create the semaphore
  ACE_Process_Semaphore semaphore (0, // 0 means that the
                                   // semaphore is locked initially
                                   sem_str);

  // wait until the child finishes booting
  while (1)
    {
      if (semaphore.acquire () == -1)
        {
          // See if my child process is still alive -- if not, return an error
          if (ACE_OS::kill (this->pid_,
                            0) == -1)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "(%P|%t) Process_Strategy: Process being waited on died unexpectedly.\n"),
                              -1);
          // if we were not interrupted due to a EINTR, break
          if (errno != EINTR)
            break;
        }
      else
        break;
    }

  // The job of the semaphore is done, remove it.
  if (semaphore.remove () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) semaphore remove failed: %p\n",
                       "remove"),
                      -1);

  try
    {
      // Get ourselves a Naming service
      this->bind_to_naming_service ();

      // Get the stream endpoint created by the child from the naming service
      this->get_stream_endpoint ();

      // Get the Vdev created by the child from the naming service
      this->get_vdev ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "TAO_AV_Endpoint_Process_Strategy::activate");
      return -1;
    }
  return 0;
}

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.

{
  try
    {
      if (CORBA::is_nil (this->naming_context_.in ()) == 0)
        return 0;

      CORBA::Object_var naming_obj =
        TAO_ORB_Core_instance ()->orb ()->resolve_initial_references ("NameService");

      if (CORBA::is_nil (naming_obj.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to resolve the Name Service.\n"),
                          -1);
      this->naming_context_ =
        CosNaming::NamingContext::_narrow (naming_obj.in ());
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "TAO_AV_Endpoint_Process_Strategy::bind_to_naming_service");
      return -1;
    }
  return 0;
}

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.

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.

{
  try
    {
      char vdev_name [BUFSIZ];
      ACE_OS::sprintf (vdev_name,
                       "%s:%s:%ld",
                       "VDev",
                       this->host_,
                       (long) this->pid_);

      if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)%s\n",vdev_name));

      // Create the name
      CosNaming::Name VDev_Name (1);
      VDev_Name.length (1);
      VDev_Name [0].id = CORBA::string_dup (vdev_name);

      // Get the CORBA::Object
      CORBA::Object_var vdev =
        this->naming_context_->resolve (VDev_Name);

      // Narrow it
      this->vdev_ =
        AVStreams::VDev::_narrow (vdev.in ());

      // Check if valid
      if (CORBA::is_nil (this->vdev_.in() ))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " could not resolve Stream_Endpoint_B in Naming service <%s>\n"),
                          -1);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "TAO_AV_Endpoint_Process_Strategy::get_vdev");
      return -1;
    }
  return 0;
}


Member Data Documentation

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.

My child's process id.

Definition at line 117 of file Endpoint_Strategy.h.

Name and arguments for the process to be created.

Definition at line 111 of file Endpoint_Strategy.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines