TAO_IMR_Op_Register Class Reference

Register Operation. More...

#include <tao_imr_i.h>

Inheritance diagram for TAO_IMR_Op_Register:

Inheritance graph
[legend]
Collaboration diagram for TAO_IMR_Op_Register:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_IMR_Op_Register (bool is_add)
virtual int parse (int argc, ACE_TCHAR **argv)
virtual int run (void)
 Do the work.


Protected Member Functions

void addenv (ACE_TCHAR *opt)
 Sets one environment variable.

void print_usage (void)
 Prints a message about the usage.


Protected Attributes

bool is_add_
 Enables pre-registration checks.

ACE_CString server_name_
 POA server name.

bool set_command_line_
ACE_CString command_line_
bool set_environment_vars_
ImplementationRepository::EnvironmentList environment_vars_
bool set_working_dir_
ACE_CString working_dir_
bool set_activation_
ImplementationRepository::ActivationMode activation_
bool set_retry_count_
int retry_count_
bool set_activator_
ACE_CString activator_

Detailed Description

Register Operation.

Register is used to update/add information for a server with the IMR.

Definition at line 281 of file tao_imr_i.h.


Constructor & Destructor Documentation

TAO_IMR_Op_Register::TAO_IMR_Op_Register bool  is_add  ) 
 

Definition at line 252 of file tao_imr_i.cpp.

00253 : is_add_ (is_add)
00254 , set_command_line_ (false)
00255 , set_environment_vars_(false)
00256 , set_working_dir_ (false)
00257 , set_activation_ (false)
00258 , activation_(ImplementationRepository::NORMAL)
00259 , set_retry_count_(false)
00260 , retry_count_ (0)
00261 , set_activator_ (false)
00262 {
00263   // Nothing
00264 }


Member Function Documentation

void TAO_IMR_Op_Register::addenv ACE_TCHAR opt  )  [protected]
 

Sets one environment variable.

Definition at line 585 of file tao_imr_i.cpp.

References ACE_CString, environment_vars_, and CORBA::string_dup().

Referenced by parse().

00586 {
00587   CORBA::ULong length = this->environment_vars_.length ();
00588   // Increase the length of the sequence
00589   this->environment_vars_.length (length + 1);
00590   ACE_CString tokens (opt);
00591   int index = tokens.find ("=");
00592   // Insert at position length since that is our new element
00593   this->environment_vars_ [length].name =
00594     CORBA::string_dup (tokens.substr (0, index).c_str ());
00595   this->environment_vars_ [length].value =
00596     CORBA::string_dup (tokens.substr (index + 1).c_str ());
00597 }

int TAO_IMR_Op_Register::parse int  argc,
ACE_TCHAR **  argv
[virtual]
 

hostname of the activator

Implements TAO_IMR_Op.

Definition at line 619 of file tao_imr_i.cpp.

References ACE_ERROR, ACE_ERROR_RETURN, activator_, addenv(), ACE_OS::atoi(), LM_ERROR, print_usage(), retry_count_, set_activation_, set_activator_, set_command_line_, set_environment_vars_, set_retry_count_, set_working_dir_, and ACE_OS::strcasecmp().

00620 {
00621   // Check for enough arguments (we need at least one for the server name)
00622   if (argc < 2)
00623     {
00624       ACE_ERROR((LM_ERROR, "Error: Must supply at least a server name.\n"));
00625       this->print_usage ();
00626       return -1;
00627     }
00628 
00629   // Skip both the program name and the "update" command
00630   ACE_Get_Opt get_opts (argc, argv, "hc:w:a:e:r:R:l:");
00631 
00632   this->server_name_ = argv[1];
00633   int c;
00634 
00635   while ((c = get_opts ()) != -1)
00636     {
00637       switch (c)
00638       {
00639       case 'c':  // Command line arguments
00640         this->set_command_line_ = true;
00641         this->command_line_ = get_opts.opt_arg ();
00642         break;
00643       case 'e':  // set environment variables
00644         this->set_environment_vars_ = true;
00645         this->addenv( get_opts.opt_arg () );
00646         break;
00647       case 'w':  // Working Directory
00648         this->set_working_dir_ = true;
00649         this->working_dir_ = get_opts.opt_arg ();
00650         break;
00651       case 'a':  // Activation Mode
00652         this->set_activation_ = true;
00653         if (ACE_OS::strcasecmp (get_opts.opt_arg (), "NORMAL") == 0)
00654           this->activation_ = ImplementationRepository::NORMAL;
00655         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "MANUAL") == 0)
00656           this->activation_ = ImplementationRepository::MANUAL;
00657         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "PER_CLIENT") == 0)
00658           this->activation_ = ImplementationRepository::PER_CLIENT;
00659         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "AUTO_START") == 0)
00660           this->activation_ = ImplementationRepository::AUTO_START;
00661         else
00662           ACE_ERROR_RETURN ((LM_ERROR,
00663           "Unknown Activation Mode <%s>.\n",
00664           get_opts.opt_arg ()),
00665           -1);
00666         break;
00667       case 'r':
00668       case 'R':   // startup/ping Retry Count
00669         {
00670           this->set_retry_count_ = true;
00671           int rc = ACE_OS::atoi(get_opts.optarg);
00672           if (rc > 0)
00673             this->retry_count_ = rc;
00674         }
00675         break;
00676       case 'l': /// hostname of the activator
00677         this->activator_ = get_opts.optarg;
00678         this->set_activator_ = true;
00679         break;
00680       case 'h':  // display help
00681         this->print_usage ();
00682         return -1;
00683       default:
00684         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00685         this->print_usage ();
00686         return -1;
00687       }
00688     }
00689   return 0;
00690 }

void TAO_IMR_Op_Register::print_usage void   )  [protected]
 

Prints a message about the usage.

Definition at line 600 of file tao_imr_i.cpp.

References ACE_ERROR, and LM_ERROR.

Referenced by parse().

00601 {
00602   ACE_ERROR ((LM_ERROR,
00603     "Adds/Updates a server entry\n"
00604     "\n"
00605     "Usage: tao_imr [options] <add|update> <name> [command-arguments]\n"
00606     "  where [options] are ORB options\n"
00607     "  where <name> is the POA name used by the server object\n"
00608     "  where [command-arguments] can be\n"
00609     "    -h            Displays this\n"
00610     "    -l            Activator name.\n"
00611     "    -c command    Startup command\n"
00612     "    -w dir        Working directory\n"
00613     "    -e name=value Set environment variables\n"
00614     "    -a mode       Set activate mode (NORMAL|MANUAL|PER_CLIENT|AUTO_START)\n"
00615     "    -r count      Set the startup/ping retry count to count\n"));
00616 }

int TAO_IMR_Op_Register::run void   )  [virtual]
 

Do the work.

Implements TAO_IMR_Op.

Definition at line 1019 of file tao_imr_i.cpp.

References ACE_ANY_EXCEPTION, ACE_ASSERT, ACE_CATCH, ACE_CATCHANY, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, environment_vars_, ACE_OS::hostname(), is_add_, LM_DEBUG, LM_ERROR, MAXHOSTNAMELEN, retry_count_, set_activation_, set_activator_, set_command_line_, set_environment_vars_, set_retry_count_, set_working_dir_, and CORBA::string_dup().

01020 {
01021   ACE_ASSERT (! CORBA::is_nil(imr_));
01022 
01023   ImplementationRepository::ServerInformation_var server_information;
01024   ImplementationRepository::StartupOptions  local;
01025   ImplementationRepository::StartupOptions* options = NULL;
01026 
01027   ACE_DECLARE_NEW_CORBA_ENV;
01028   ACE_TRY
01029     {
01030       this->imr_->find(this->server_name_.c_str (),
01031         server_information.out() ACE_ENV_ARG_PARAMETER);
01032       ACE_TRY_CHECK;
01033 
01034       if (server_name_ == server_information->server.in())
01035         {
01036           if (is_add_)
01037             {
01038               ACE_DEBUG((LM_DEBUG, "Server <%s> already registered.\n", this->server_name_.c_str ()));
01039               return ALREADY_REGISTERED;
01040             }
01041           options = &server_information->startup;
01042         }
01043       else // not found
01044         {
01045           if (!is_add_)
01046           {
01047             ACE_DEBUG((LM_DEBUG, "Adding Server <%s> on update command.\n", this->server_name_.c_str ()));
01048             is_add_ = true;
01049           }
01050           options = &local;
01051         }
01052 
01053       if (this->set_command_line_)
01054         options->command_line = CORBA::string_dup (this->command_line_.c_str ());
01055 
01056       if (this->set_environment_vars_)
01057         options->environment = this->environment_vars_;
01058 
01059       if (this->set_working_dir_)
01060         options->working_directory = CORBA::string_dup (this->working_dir_.c_str ());
01061 
01062       if (this->set_activation_ || is_add_)
01063         options->activation = this->activation_;
01064 
01065       if (this->set_retry_count_ || is_add_)
01066         options->start_limit = this->retry_count_ + 1;
01067 
01068       if (this->set_activator_)
01069         options->activator = CORBA::string_dup(this->activator_.c_str ());
01070       // If the command line is set, we must have an activator
01071       else if (this->set_command_line_ &&
01072               (options->activator.in () == 0 || *options->activator.in () == 0))
01073         {
01074           char host_name[MAXHOSTNAMELEN + 1];
01075           ACE_OS::hostname (host_name, MAXHOSTNAMELEN);
01076           options->activator = CORBA::string_dup (host_name);
01077           ACE_DEBUG ((LM_DEBUG, "Updating Server <%s> with default activator of <%s>.\n",
01078             this->server_name_.c_str (), options->activator.in ()));
01079         }
01080 
01081       this->imr_->add_or_update_server (this->server_name_.c_str (), *options ACE_ENV_ARG_PARAMETER);
01082       ACE_TRY_CHECK;
01083 
01084       ACE_DEBUG((LM_DEBUG, "Successfully registered <%s>.\n", this->server_name_.c_str ()));
01085     }
01086   ACE_CATCH (CORBA::NO_PERMISSION, ex)
01087     {
01088       ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
01089       return TAO_IMR_Op::NO_PERMISSION;
01090     }
01091   ACE_CATCHANY
01092     {
01093       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Updating server");
01094       return TAO_IMR_Op::UNKNOWN;
01095     }
01096   ACE_ENDTRY;
01097 
01098   return TAO_IMR_Op::NORMAL;
01099 }


Member Data Documentation

ImplementationRepository::ActivationMode TAO_IMR_Op_Register::activation_ [protected]
 

Definition at line 313 of file tao_imr_i.h.

ACE_CString TAO_IMR_Op_Register::activator_ [protected]
 

Definition at line 319 of file tao_imr_i.h.

Referenced by parse().

ACE_CString TAO_IMR_Op_Register::command_line_ [protected]
 

Definition at line 304 of file tao_imr_i.h.

ImplementationRepository::EnvironmentList TAO_IMR_Op_Register::environment_vars_ [protected]
 

Definition at line 307 of file tao_imr_i.h.

Referenced by addenv(), and run().

bool TAO_IMR_Op_Register::is_add_ [protected]
 

Enables pre-registration checks.

Definition at line 292 of file tao_imr_i.h.

Referenced by run().

int TAO_IMR_Op_Register::retry_count_ [protected]
 

Definition at line 316 of file tao_imr_i.h.

Referenced by parse(), and run().

ACE_CString TAO_IMR_Op_Register::server_name_ [protected]
 

POA server name.

Definition at line 301 of file tao_imr_i.h.

bool TAO_IMR_Op_Register::set_activation_ [protected]
 

Definition at line 312 of file tao_imr_i.h.

Referenced by parse(), and run().

bool TAO_IMR_Op_Register::set_activator_ [protected]
 

Definition at line 318 of file tao_imr_i.h.

Referenced by parse(), and run().

bool TAO_IMR_Op_Register::set_command_line_ [protected]
 

Definition at line 303 of file tao_imr_i.h.

Referenced by parse(), and run().

bool TAO_IMR_Op_Register::set_environment_vars_ [protected]
 

Definition at line 306 of file tao_imr_i.h.

Referenced by parse(), and run().

bool TAO_IMR_Op_Register::set_retry_count_ [protected]
 

Definition at line 315 of file tao_imr_i.h.

Referenced by parse(), and run().

bool TAO_IMR_Op_Register::set_working_dir_ [protected]
 

Definition at line 309 of file tao_imr_i.h.

Referenced by parse(), and run().

ACE_CString TAO_IMR_Op_Register::working_dir_ [protected]
 

Definition at line 310 of file tao_imr_i.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:37:30 2006 for TAO_Implementation_Repository by doxygen 1.3.6