Activator_Options Class Reference

#include <Activator_Options.h>

List of all members.

Public Types

enum  SERVICE_COMMAND { SC_NONE, SC_INSTALL, SC_REMOVE, SC_INSTALL_NO_LOCATOR }

Public Member Functions

 Activator_Options ()
int init (int argc, char *argv[])
 Parse the command-line arguments and initialize the options.

int init_from_registry ()
 This version should only be used when run as an nt service.

bool service (void) const
 Service Mode.

bool notify_imr (void) const
unsigned int debug (void) const
 Debug level for the Implementation Repository.

const ACE_CStringior_filename (void) const
 Returns the file where the IOR should be stored.

SERVICE_COMMAND service_command (void) const
 The nt service command to run (install/remove).

int save_registry_options ()
 Save the command line arguments as registry settings. (Windows only).

const char * cmdline (void) const
const ACE_CStringname (void) const

Private Member Functions

int parse_args (int &argc, char *argv[])
 Parses and pulls out arguments for the ImR.

void print_usage (void) const
 Print the usage information.

int load_registry_options ()
 Loads options from the registry.


Private Attributes

ACE_CString cmdline_
 Our extra command line arguments.

unsigned int debug_
 Debug level.

ACE_CString ior_output_file_
 File where the IOR of the server object is stored.

bool service_
 Should we run as a service?

bool notify_imr_
SERVICE_COMMAND service_command_
 SC_NONE, SC_INSTALL, SC_REMOVE, ...

ACE_CString name_


Member Enumeration Documentation

enum Activator_Options::SERVICE_COMMAND
 

Enumeration values:
SC_NONE 
SC_INSTALL 
SC_REMOVE 
SC_INSTALL_NO_LOCATOR 

Definition at line 36 of file Activator_Options.h.

00036                        {
00037     SC_NONE,
00038     SC_INSTALL,
00039     SC_REMOVE,
00040     SC_INSTALL_NO_LOCATOR
00041   };


Constructor & Destructor Documentation

Activator_Options::Activator_Options  ) 
 

Definition at line 27 of file Activator_Options.cpp.

00028 : debug_ (1)
00029 , service_ (false)
00030 , notify_imr_ (false)
00031 , service_command_(SC_NONE)
00032 {
00033 }


Member Function Documentation

const char * Activator_Options::cmdline void   )  const
 

Definition at line 339 of file Activator_Options.cpp.

References cmdline_.

00340 {
00341   return this->cmdline_.c_str ();
00342 }

unsigned int Activator_Options::debug void   )  const
 

Debug level for the Implementation Repository.

Definition at line 321 of file Activator_Options.cpp.

00322 {
00323   return this->debug_;
00324 }

int Activator_Options::init int  argc,
char *  argv[]
 

Parse the command-line arguments and initialize the options.

Definition at line 146 of file Activator_Options.cpp.

References ACE_CString, cmdline_, and parse_args().

Referenced by ImR_Activator_Loader::init(), and main().

00147 {
00148   // Make an initial pass through and grab the arguments that we recognize.
00149   // This may also run the commands to install or remove the nt service.
00150   int result = this->parse_args (argc, argv);
00151   if (result != 0)
00152     {
00153       return result;
00154     }
00155 
00156   for (int i = 0; i < argc; ++i)
00157     {
00158       this->cmdline_ += ACE_CString (argv[i]) + ACE_CString (" ");
00159     }
00160 
00161   return 0;
00162 }

int Activator_Options::init_from_registry  ) 
 

This version should only be used when run as an nt service.

Definition at line 165 of file Activator_Options.cpp.

References load_registry_options().

Referenced by Activator_NT_Service::svc().

00166 {
00167   this->load_registry_options();
00168   return 0;
00169 }

const ACE_CString & Activator_Options::ior_filename void   )  const
 

Returns the file where the IOR should be stored.

Definition at line 327 of file Activator_Options.cpp.

References ior_output_file_.

00328 {
00329   return this->ior_output_file_;
00330 }

int Activator_Options::load_registry_options  )  [private]
 

Loads options from the registry.

Definition at line 236 of file Activator_Options.cpp.

References ACE_ASSERT, cmdline_, ior_output_file_, notify_imr_, SERVICE_REG_PATH, and SERVICE_REG_ROOT.

Referenced by init_from_registry().

00237 {
00238 #if defined (ACE_WIN32)
00239   HKEY key = 0;
00240   // Create or open the parameters key
00241   LONG err = ACE_TEXT_RegOpenKeyEx (SERVICE_REG_ROOT,
00242                              SERVICE_REG_PATH,
00243                              0,
00244                              KEY_READ,
00245                              &key
00246                              );
00247   if (err != ERROR_SUCCESS)
00248     {
00249       // If there aren't any saved parameters, then that's ok.
00250       return 0;
00251     }
00252   char tmpstr[4096];
00253   DWORD sz = sizeof (tmpstr);
00254   DWORD type = 0;
00255   err = ACE_TEXT_RegQueryValueEx (key, "ORBInitOptions", 0, &type,
00256     (LPBYTE) tmpstr, &sz);
00257   if (err == ERROR_SUCCESS)
00258     {
00259       ACE_ASSERT (type == REG_SZ);
00260       tmpstr[sz - 1] = '\0';
00261       this->cmdline_ = tmpstr;
00262     }
00263 
00264   sz = sizeof(tmpstr);
00265   err = ACE_TEXT_RegQueryValueEx (key, "IORFile", 0, &type,
00266     (LPBYTE) tmpstr, &sz);
00267   if (err == ERROR_SUCCESS)
00268     {
00269       ACE_ASSERT (type == REG_SZ);
00270       tmpstr[sz - 1] = '\0';
00271       this->ior_output_file_ = tmpstr;
00272     }
00273 
00274   sz = sizeof(debug_);
00275   err = ACE_TEXT_RegQueryValueEx (key, "DebugLevel", 0, &type,
00276     (LPBYTE) &this->debug_ , &sz);
00277   if (err == ERROR_SUCCESS)
00278     {
00279       ACE_ASSERT (type == REG_DWORD);
00280     }
00281 
00282   sz = sizeof(tmpstr);
00283   err = ACE_TEXT_RegQueryValueEx (key, "Name", 0, &type,
00284     (LPBYTE) tmpstr, &sz);
00285   if (err == ERROR_SUCCESS)
00286     {
00287       ACE_ASSERT (type == REG_SZ);
00288       tmpstr[sz - 1] = '\0';
00289       this->name_ = tmpstr;
00290     }
00291 
00292   DWORD tmpint = 0;
00293   sz = sizeof(tmpint);
00294   err = ACE_TEXT_RegQueryValueEx (key, "NotifyImR", 0, &type,
00295     (LPBYTE) &tmpint , &sz);
00296   if (err == ERROR_SUCCESS)
00297     {
00298       ACE_ASSERT (type == REG_DWORD);
00299     }
00300   this->notify_imr_ = tmpint != 0;
00301 
00302   err = ::RegCloseKey (key);
00303   ACE_ASSERT(err == ERROR_SUCCESS);
00304 #endif /* ACE_WIN32 */
00305   return 0;
00306 }

const ACE_CString & Activator_Options::name void   )  const
 

Definition at line 345 of file Activator_Options.cpp.

00346 {
00347   return this->name_;
00348 }

bool Activator_Options::notify_imr void   )  const
 

Notify the ImR when server processes die. Note : Currently this only works on Unix.

Definition at line 315 of file Activator_Options.cpp.

References notify_imr_.

00316 {
00317   return this->notify_imr_;
00318 }

int Activator_Options::parse_args int &  argc,
char *  argv[]
[private]
 

Parses and pulls out arguments for the ImR.

Definition at line 36 of file Activator_Options.cpp.

References ACE_Arg_Shifter, ACE_ERROR, ACE_TEXT, ACE_OS::atoi(), ior_output_file_, LM_ERROR, notify_imr_, print_usage(), SC_INSTALL, SC_INSTALL_NO_LOCATOR, SC_REMOVE, service_command_, and ACE_OS::strcasecmp().

Referenced by init().

00037 {
00038   ACE_Arg_Shifter shifter (argc, argv);
00039 
00040   while (shifter.is_anything_left ())
00041     {
00042       if (ACE_OS::strcasecmp (shifter.get_current (),
00043                               ACE_TEXT ("-c")) == 0)
00044         {
00045           shifter.consume_arg ();
00046 
00047           if (!shifter.is_anything_left () || shifter.get_current ()[0] == '-')
00048             {
00049               ACE_ERROR ((LM_ERROR, "Error: -c option needs a command\n"));
00050               this->print_usage ();
00051               return -1;
00052             }
00053 
00054           if (ACE_OS::strcasecmp (shifter.get_current (),
00055                                    ACE_TEXT ("install")) == 0)
00056             {
00057               this->service_command_ = SC_INSTALL;
00058             }
00059           else if (ACE_OS::strcasecmp (shifter.get_current (),
00060                                    ACE_TEXT ("remove")) == 0)
00061             {
00062               this->service_command_ = SC_REMOVE;
00063             }
00064           else if (ACE_OS::strcasecmp (shifter.get_current (),
00065                                    ACE_TEXT ("install_no_imr")) == 0)
00066             {
00067               this->service_command_ = SC_INSTALL_NO_LOCATOR;
00068             }
00069           else
00070             {
00071               ACE_ERROR((LM_ERROR, "Error: Unknown service command : %s\n", shifter.get_current()));
00072               this->print_usage ();
00073               return -1;
00074             }
00075         }
00076       else if (ACE_OS::strcasecmp (shifter.get_current (),
00077                                    ACE_TEXT ("-d")) == 0)
00078         {
00079           shifter.consume_arg ();
00080 
00081           if (!shifter.is_anything_left () || shifter.get_current ()[0] == '-')
00082             {
00083               ACE_ERROR ((LM_ERROR, "Error: -d option needs a debuglevel\n"));
00084               this->print_usage ();
00085               return -1;
00086             }
00087 
00088           this->debug_ = ACE_OS::atoi (shifter.get_current ());
00089         }
00090       else if (ACE_OS::strcasecmp (shifter.get_current (),
00091                                    ACE_TEXT ("-o")) == 0)
00092         {
00093           shifter.consume_arg ();
00094 
00095           if (!shifter.is_anything_left () || shifter.get_current ()[0] == '-')
00096             {
00097               ACE_ERROR ((LM_ERROR, "Error: -o option needs a filename\n"));
00098               this->print_usage ();
00099               return -1;
00100             }
00101           this->ior_output_file_ = shifter.get_current ();
00102         }
00103       else if (ACE_OS::strcasecmp (shifter.get_current (),
00104                                    ACE_TEXT ("-s")) == 0)
00105         {
00106           this->service_ = true;
00107         }
00108       else if ((ACE_OS::strcasecmp (shifter.get_current (),
00109                                     ACE_TEXT ("-?")) == 0)
00110                || (ACE_OS::strcasecmp (shifter.get_current (),
00111                                        ACE_TEXT ("-h")) == 0))
00112         {
00113           this->print_usage ();
00114           return 1;
00115         }
00116       else if (ACE_OS::strcasecmp (shifter.get_current (),
00117                                    ACE_TEXT ("-n")) == 0)
00118         {
00119           shifter.consume_arg ();
00120 
00121           if (!shifter.is_anything_left () || shifter.get_current ()[0] == '-')
00122             {
00123               ACE_ERROR ((LM_ERROR, "Error: -n option needs a name\n"));
00124               this->print_usage ();
00125               return -1;
00126             }
00127           this->name_ = shifter.get_current ();
00128         }
00129       else if (ACE_OS::strcasecmp (shifter.get_current (),
00130                                    ACE_TEXT ("-l")) == 0)
00131         {
00132           this->notify_imr_ = true;
00133         }
00134       else
00135         {
00136           shifter.ignore_arg ();
00137           continue;
00138         }
00139 
00140       shifter.consume_arg ();
00141     }
00142   return 0;
00143 }

void Activator_Options::print_usage void   )  const [private]
 

Print the usage information.

Definition at line 172 of file Activator_Options.cpp.

References ACE_ERROR, and LM_ERROR.

Referenced by parse_args().

00173 {
00174   ACE_ERROR ((LM_ERROR,
00175               "Usage:\n"
00176               "\n"
00177               "ImR_Activator [-c cmd] [-d 0|1|2] [-o file] [-l] [-n name]\n"
00178               "\n"
00179               "  -c command  Runs service commands \n"
00180               "              ('install' or 'remove' or 'install_no_imr')\n"
00181               "  -d level    Sets the debug level\n"
00182               "  -o file     Outputs the ImR's IOR to a file\n"
00183               "  -l          Notify the ImR when a process exits\n"
00184               "  -n name     Specify a name for the Activator\n")
00185              );
00186 }

int Activator_Options::save_registry_options  ) 
 

Save the command line arguments as registry settings. (Windows only).

Definition at line 189 of file Activator_Options.cpp.

References ACE_ASSERT, cmdline_, ior_output_file_, notify_imr_, SERVICE_REG_PATH, and SERVICE_REG_ROOT.

Referenced by run_service_command().

00190 {
00191 #if defined (ACE_WIN32)
00192   HKEY key = 0;
00193   // Create or open the parameters key
00194   LONG err = ACE_TEXT_RegCreateKeyEx (SERVICE_REG_ROOT,
00195                              SERVICE_REG_PATH,
00196                              0,
00197                              "", // class
00198                              REG_OPTION_NON_VOLATILE,
00199                              KEY_ALL_ACCESS,
00200                              NULL,
00201                              &key,
00202                              NULL
00203                              );
00204   if (err != ERROR_SUCCESS)
00205     {
00206       return -1;
00207     }
00208   err = ACE_TEXT_RegSetValueEx (key, "ORBInitOptions", 0, REG_SZ,
00209     (LPBYTE) this->cmdline_.c_str (), this->cmdline_.length () + 1);
00210   ACE_ASSERT (err == ERROR_SUCCESS);
00211 
00212   err = ACE_TEXT_RegSetValueEx (key, "IORFile", 0, REG_SZ,
00213     (LPBYTE) this->ior_output_file_.c_str (), this->ior_output_file_.length () + 1);
00214   ACE_ASSERT (err == ERROR_SUCCESS);
00215 
00216   err = ACE_TEXT_RegSetValueEx (key, "DebugLevel", 0, REG_DWORD,
00217     (LPBYTE) &this->debug_ , sizeof (this->debug_));
00218   ACE_ASSERT (err == ERROR_SUCCESS);
00219 
00220   err = ACE_TEXT_RegSetValueEx( key, "Name", 0, REG_SZ,
00221     (LPBYTE) this->name_.c_str (), this->name_.length () + 1);
00222   ACE_ASSERT (err == ERROR_SUCCESS);
00223 
00224   DWORD tmpint = this->notify_imr_;
00225   err = ACE_TEXT_RegSetValueEx (key, "NotifyImR", 0, REG_DWORD,
00226     (LPBYTE) &tmpint , sizeof (tmpint));
00227   ACE_ASSERT (err == ERROR_SUCCESS);
00228 
00229   err = ::RegCloseKey (key);
00230   ACE_ASSERT (err == ERROR_SUCCESS);
00231 #endif
00232   return 0;
00233 }

bool Activator_Options::service void   )  const
 

Service Mode.

Definition at line 309 of file Activator_Options.cpp.

Referenced by main().

00310 {
00311   return this->service_;
00312 }

Activator_Options::SERVICE_COMMAND Activator_Options::service_command void   )  const
 

The nt service command to run (install/remove).

Definition at line 333 of file Activator_Options.cpp.

References service_command_.

Referenced by run_service_command().

00334 {
00335   return this->service_command_;
00336 }


Member Data Documentation

ACE_CString Activator_Options::cmdline_ [private]
 

Our extra command line arguments.

Definition at line 86 of file Activator_Options.h.

Referenced by cmdline(), init(), load_registry_options(), and save_registry_options().

unsigned int Activator_Options::debug_ [private]
 

Debug level.

Definition at line 89 of file Activator_Options.h.

ACE_CString Activator_Options::ior_output_file_ [private]
 

File where the IOR of the server object is stored.

Definition at line 92 of file Activator_Options.h.

Referenced by ior_filename(), load_registry_options(), parse_args(), and save_registry_options().

ACE_CString Activator_Options::name_ [private]
 

Definition at line 102 of file Activator_Options.h.

bool Activator_Options::notify_imr_ [private]
 

Definition at line 97 of file Activator_Options.h.

Referenced by load_registry_options(), notify_imr(), parse_args(), and save_registry_options().

bool Activator_Options::service_ [private]
 

Should we run as a service?

Definition at line 95 of file Activator_Options.h.

SERVICE_COMMAND Activator_Options::service_command_ [private]
 

SC_NONE, SC_INSTALL, SC_REMOVE, ...

Definition at line 100 of file Activator_Options.h.

Referenced by parse_args(), and service_command().


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