Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

TAO_IMR_Op_Add Class Reference

Add Operation. More...

#include <tao_imr_i.h>

Inheritance diagram for TAO_IMR_Op_Add:

Inheritance graph
[legend]
Collaboration diagram for TAO_IMR_Op_Add:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_IMR_Op_Add (void)
 ~TAO_IMR_Op_Add (void)
virtual int parse (int argc, ACE_TCHAR **argv)
 Parse arguments. More...

virtual int run (void)
 Do the work. More...


Protected Methods

void setenv (ACE_TCHAR *opt)
 Sets one of the environment variables. More...

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


Protected Attributes

ACE_CString server_name_
 POA server name. More...

ACE_CString command_line_
 Command line. More...

ImplementationRepository::EnvironmentList environment_vars_
 Environment Variables. More...

ACE_CString working_dir_
 Working directory. More...

ImplementationRepository::ActivationMode activation_
 Activation mode (0 = NORMAL, 1 = MANUAL, 2 = PER_CLIENT, 3 = AUTO_START). More...

ACE_CString location_
 Hostname where the activator is running. More...


Detailed Description

Add Operation.

Add is used to register information about a server with the IMR.

Definition at line 144 of file tao_imr_i.h.


Constructor & Destructor Documentation

TAO_IMR_Op_Add::TAO_IMR_Op_Add void   
 

Definition at line 208 of file tao_imr_i.cpp.

References NORMAL.

00209   : activation_ (ImplementationRepository::NORMAL)
00210 {
00211   // Nothing
00212 }

TAO_IMR_Op_Add::~TAO_IMR_Op_Add void   
 

Definition at line 265 of file tao_imr_i.cpp.

00266 {
00267   // Nothing
00268 }


Member Function Documentation

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

Parse arguments.

Implements TAO_IMR_Op.

Definition at line 354 of file tao_imr_i.cpp.

References ACE_ERROR_RETURN, ACE_TCHAR, activation_, command_line_, LM_ERROR, location_, ACE_Get_Opt::opt_arg, ACE_Get_Opt::optarg, print_usage, server_name_, setenv, ACE_OS_String::strcasecmp, and working_dir_.

00355 {
00356   // Check for enough arguments (we need at least one for the server name)
00357   if (argc < 1)
00358     {
00359       this->print_usage ();
00360       return -1;
00361     }
00362 
00363  // Skip both the program name and the "add" command
00364   ACE_Get_Opt get_opts (argc, argv, "hc:w:a:e:l:");
00365 
00366   this->server_name_ = argv[0];
00367   int c;
00368 
00369   while ((c = get_opts ()) != -1)
00370     switch (c)
00371       {
00372       case 'c':  // Command line arguments
00373         this->command_line_ = get_opts.opt_arg ();
00374         break;
00375       case 'e':  // set environment variables
00376         this->setenv( get_opts.opt_arg () ) ;
00377         break;
00378       case 'w':  // Working Directory
00379         this->working_dir_ = get_opts.opt_arg ();
00380         break;
00381       case 'a':  // Activation Mode
00382         if (ACE_OS::strcasecmp (get_opts.opt_arg (), "NORMAL") == 0)
00383           this->activation_ = ImplementationRepository::NORMAL;
00384         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "MANUAL") == 0)
00385           this->activation_ = ImplementationRepository::MANUAL;
00386         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "PER_CLIENT") == 0)
00387           this->activation_ = ImplementationRepository::PER_CLIENT;
00388         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "AUTO_START") == 0)
00389           this->activation_ = ImplementationRepository::AUTO_START;
00390         else
00391           ACE_ERROR_RETURN ((LM_ERROR,
00392                              "Unknown Activation Mode <%s>!\n",
00393                              get_opts.opt_arg ()),
00394                             -1);
00395         break;
00396       case 'l': /// Location (hostname) of the activator
00397         this->location_ = get_opts.optarg;
00398         break;
00399       case 'h':  // display help
00400       default:
00401         this->print_usage ();
00402         return -1;
00403       }
00404 
00405   // Success
00406   return 0;
00407 }

void TAO_IMR_Op_Add::print_usage void    [protected]
 

Prints a message about the usage.

Definition at line 1126 of file tao_imr_i.cpp.

References ACE_ERROR, and LM_ERROR.

Referenced by parse.

01127 {
01128   ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] add <name> [command-arguments]\n"
01129                         "  where [options] are ORB options\n"
01130                         "  where <name> is the POA name used by the server object\n"
01131                         "  where [command-arguments] can be\n"
01132                         "    -h            Displays this\n"
01133                         "    -c command    Startup command\n"
01134                         "    -w dir        Working directory\n"
01135                         "    -a mode       Set activate mode (NORMAL|MANUAL|PER_CLIENT|AUTO_START)"));
01136 }

int TAO_IMR_Op_Add::run void    [virtual]
 

Do the work.

Implements TAO_IMR_Op.

Definition at line 686 of file tao_imr_i.cpp.

References ACE_ANY_EXCEPTION, 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, ImplementationRepository::StartupOptions::activation, activation_, ALREADY_REGISTERED, ImplementationRepository::StartupOptions::command_line, ImplementationRepository::StartupOptions::environment, environment_vars_, ACE_OS::gethostbyname, ACE_OS::hostname, TAO_IMR_Op::imr_locator_, LM_DEBUG, LM_ERROR, ImplementationRepository::StartupOptions::location, NO_PERMISSION, NORMAL, ACE_OS_String::strcmp, CORBA::string_dup, UNKNOWN, and ImplementationRepository::StartupOptions::working_directory.

00687 {
00688   ImplementationRepository::StartupOptions startup_options;
00689 
00690   startup_options.command_line =
00691     CORBA::string_dup (this->command_line_.c_str ());
00692   startup_options.environment =
00693     this->environment_vars_;
00694   startup_options.working_directory =
00695     CORBA::string_dup (this->working_dir_.c_str ());
00696   startup_options.activation = this->activation_;
00697 
00698   if (ACE_OS::strcmp (this->location_.c_str (), "") != 0)
00699     {
00700       // If the location is specified, use it
00701       startup_options.location = CORBA::string_dup (this->location_.c_str ());
00702     }
00703   else
00704     {
00705       // else use the hostname on which tao_imr is run
00706       char hostname[BUFSIZ];
00707       ACE_OS::hostname (hostname, BUFSIZ);
00708 
00709       struct hostent *hinfo = ACE_OS::gethostbyname (hostname);
00710 
00711       startup_options.location = CORBA::string_dup (hinfo->h_name);
00712     }
00713 
00714   ACE_DECLARE_NEW_CORBA_ENV;
00715   ACE_TRY
00716     {
00717       this->imr_locator_->register_server (
00718             this->server_name_.c_str (), startup_options ACE_ENV_ARG_PARAMETER);
00719       ACE_TRY_CHECK;
00720 
00721       ACE_DEBUG ((LM_DEBUG,
00722                   "Successfully registered server <%s>\n",
00723                   this->server_name_.c_str ()));
00724     }
00725   ACE_CATCH (ImplementationRepository::AlreadyRegistered, ex)
00726     {
00727       ACE_ERROR ((LM_ERROR,
00728                   "Server <%s> already registered!\n",
00729                   this->server_name_.c_str ()));
00730       return ALREADY_REGISTERED;
00731     }
00732   ACE_CATCH (CORBA::NO_PERMISSION, ex)
00733     {
00734       ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
00735       return NO_PERMISSION;
00736     }
00737   ACE_CATCHANY
00738     {
00739       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Adding server");
00740       return UNKNOWN;
00741     }
00742   ACE_ENDTRY;
00743 
00744   // Success
00745   return NORMAL;
00746 }

void TAO_IMR_Op_Add::setenv ACE_TCHAR   opt [protected]
 

Sets one of the environment variables.

Definition at line 338 of file tao_imr_i.cpp.

References ACE_CString, ACE_TCHAR, environment_vars_, and CORBA::string_dup.

Referenced by parse.

00339 {
00340    CORBA::ULong length = this->environment_vars_.length ();
00341 
00342    // Increase the length of the sequence
00343    this->environment_vars_.length (length + 1);
00344    ACE_CString tokens (opt);
00345    int index = tokens.find ("=");
00346    // Insert at position length since that is our new element
00347    this->environment_vars_ [length].name =
00348          CORBA::string_dup (tokens.substr (0, index).c_str ());
00349    this->environment_vars_ [length].value =
00350          CORBA::string_dup (tokens.substr (index + 1).c_str ());
00351 }


Member Data Documentation

ImplementationRepository::ActivationMode TAO_IMR_Op_Add::activation_ [protected]
 

Activation mode (0 = NORMAL, 1 = MANUAL, 2 = PER_CLIENT, 3 = AUTO_START).

Definition at line 173 of file tao_imr_i.h.

Referenced by parse, and run.

ACE_CString TAO_IMR_Op_Add::command_line_ [protected]
 

Command line.

Definition at line 164 of file tao_imr_i.h.

Referenced by parse.

ImplementationRepository::EnvironmentList TAO_IMR_Op_Add::environment_vars_ [protected]
 

Environment Variables.

Definition at line 167 of file tao_imr_i.h.

Referenced by run, and setenv.

ACE_CString TAO_IMR_Op_Add::location_ [protected]
 

Hostname where the activator is running.

Definition at line 176 of file tao_imr_i.h.

Referenced by parse.

ACE_CString TAO_IMR_Op_Add::server_name_ [protected]
 

POA server name.

Definition at line 161 of file tao_imr_i.h.

Referenced by parse.

ACE_CString TAO_IMR_Op_Add::working_dir_ [protected]
 

Working directory.

Definition at line 170 of file tao_imr_i.h.

Referenced by parse.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 20:04:31 2003 for TAO_Implementation_Repository by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002