tao_imr_i.cpp

Go to the documentation of this file.
00001 // $Id: tao_imr_i.cpp 78894 2007-07-14 14:56:10Z sowayaa $
00002 
00003 #include "tao_imr_i.h"
00004 
00005 #include "tao/PortableServer/PortableServer.h"
00006 #include "tao/PortableServer/ForwardRequestC.h"
00007 
00008 #include "tao/Stub.h"
00009 #include "tao/Profile.h"
00010 
00011 #include "ace/Get_Opt.h"
00012 #include "ace/Read_Buffer.h"
00013 #include "ace/OS_NS_strings.h"
00014 #include "ace/OS.h"
00015 
00016 TAO_IMR_i::TAO_IMR_i (void)
00017 : imr_ (ImplementationRepository::Administration::_nil ())
00018 {
00019   // Nothing
00020 }
00021 
00022 TAO_IMR_i::~TAO_IMR_i (void)
00023 {
00024 }
00025 
00026 int
00027 TAO_IMR_i::run ()
00028 {
00029   if (this->op_.get () == 0)
00030     {
00031       ACE_ERROR ((LM_ERROR, "Unknown operation"));
00032       return TAO_IMR_Op::UNKNOWN;
00033     }
00034 
00035   return this->op_->run ();
00036 }
00037 
00038 int
00039 TAO_IMR_i::init (int argc, char **argv)
00040 {
00041   this->argc_ = argc;
00042   this->argv_ = argv;
00043 
00044   const char *exception_message = "Null Message";
00045 
00046   try
00047     {
00048       // Retrieve the ORB.
00049       this->orb_ = CORBA::ORB_init (this->argc_, this->argv_, "tao_imr_i");
00050 
00051       // Parse command line and verify parameters.
00052       if (this->parse_args () == -1)
00053         return -1;
00054 
00055       // Get the ImplRepo object
00056       CORBA::Object_var obj =
00057         orb_->resolve_initial_references ("ImplRepoService");
00058 
00059       if (CORBA::is_nil (obj.in ()))
00060         {
00061           ACE_ERROR ((LM_ERROR, "Unable to resolve the ImR.\n"));
00062           return -1;
00063         }
00064 
00065       exception_message = "While narrowing ImR";
00066 
00067       this->imr_ =
00068         ImplementationRepository::Administration::_narrow (obj.in ());
00069 
00070       if (CORBA::is_nil (imr_.in ()))
00071         {
00072           ACE_ERROR ((LM_ERROR, "Unable to narrow the ImR.\n"));
00073           return -1;
00074         }
00075 
00076       this->op_->set_imr (this->imr_.in ());
00077     }
00078   catch (const CORBA::Exception& ex)
00079     {
00080       ACE_ERROR ((LM_ERROR, "TAO_IMR_i::init - %s\n", exception_message));
00081       ex._tao_print_exception ("Exception");
00082       return -1;
00083     }
00084 
00085   return 0;
00086 }
00087 
00088 
00089 // Go through and figure out which operation we should do.
00090 
00091 int
00092 TAO_IMR_i::parse_args (void)
00093 {
00094   // Make sure one command was given
00095   if (this->argc_ < 2)
00096     {
00097       ACE_ERROR((LM_ERROR, "Error: No operation specified.\n"));
00098       this->print_usage ();
00099       return -1;
00100     }
00101 
00102   this->op_.reset (TAO_IMR_Op::make_op (this->argv_[1]));
00103 
00104   // Check for unrecognized operation
00105 
00106   if (this->op_.get () == 0)
00107     {
00108       ACE_ERROR((LM_ERROR, "Error: Unknown operation '%s'.\n", this->argv_[1]));
00109       this->print_usage ();
00110       return -1;
00111     }
00112 
00113   // Adjust argc and argv so only the command specific args are passed
00114   return this->op_->parse (this->argc_ - 1, this->argv_ + 1);
00115 }
00116 
00117 
00118 // Print out information about all operations.
00119 
00120 void
00121 TAO_IMR_i::print_usage (void)
00122 {
00123   ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] command [command-arguments]\n"
00124     "  where [options] are ORB options\n"
00125     "  where command is one of the following:\n"
00126     "    start         Start a server through the ImR\n"
00127     "    add           Add an entry to the ImR\n"
00128     "    autostart Activates all AUTO_START servers\n"
00129     "    ior       Creates a simplified IOR\n"
00130     "    list          List the entries in the ImR\n"
00131     "    remove        Remove an entry from the ImR\n"
00132     "    shutdown      Shut down a server through the ImR\n"
00133     "    shutdown-repo Shut down the ImR\n"
00134     "    update        Update an entry in the ImR\n"
00135     "  where [command-arguments] depend on the command\n"));
00136 }
00137 
00138 
00139 // Factory for operations
00140 
00141 TAO_IMR_Op *
00142 TAO_IMR_Op::make_op (const ACE_TCHAR *op_name)
00143 {
00144   if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("activate")) == 0)
00145     {
00146       ACE_ERROR((LM_ERROR, "Warning: The activate option has been renamed to start.\n"));
00147       return new TAO_IMR_Op_Activate ();
00148     }
00149   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("start")) == 0)
00150     return new TAO_IMR_Op_Activate ();
00151   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("add")) == 0)
00152     return new TAO_IMR_Op_Register (true);
00153   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("autostart")) == 0)
00154     return new TAO_IMR_Op_Autostart();
00155   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("ior")) == 0)
00156     return new TAO_IMR_Op_IOR();
00157   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("list")) == 0)
00158     return new TAO_IMR_Op_List ();
00159   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("remove")) == 0)
00160     return new TAO_IMR_Op_Remove ();
00161   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("shutdown")) == 0)
00162     return new TAO_IMR_Op_Shutdown ();
00163   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("shutdown-repo")) == 0)
00164     return new TAO_IMR_Op_ShutdownRepo ();
00165   else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("update")) == 0)
00166     return new TAO_IMR_Op_Register (false);
00167 
00168   return 0;
00169 }
00170 
00171 
00172 TAO_IMR_Op::~TAO_IMR_Op ()
00173 {
00174   // Nothing
00175 }
00176 
00177 void
00178 TAO_IMR_Op::set_imr (ImplementationRepository::Administration_ptr imr)
00179 {
00180   this->imr_ = imr;
00181 }
00182 
00183 void
00184 TAO_IMR_Op::display_server_information (const ImplementationRepository::ServerInformation &info)
00185 {
00186   // Figure out what the activation string is.
00187   const char *act = "UNKNOWN STARTUP";
00188   if (info.startup.activation == ImplementationRepository::NORMAL)
00189     act = "NORMAL";
00190   else if (info.startup.activation == ImplementationRepository::MANUAL)
00191     act = "MANUAL";
00192   else if (info.startup.activation == ImplementationRepository::PER_CLIENT)
00193     act = "PER_CLIENT";
00194   else if (info.startup.activation == ImplementationRepository::AUTO_START)
00195     act = "AUTO_START";
00196 
00197   // Print out information
00198   ACE_DEBUG ((LM_DEBUG, "Server <%s>\n", info.server.in ()));
00199 
00200   const char * locked_out = "";
00201 
00202   int limit = info.startup.start_limit;
00203   if (info.startup.start_limit < 0)
00204     {
00205       limit = -limit;
00206       locked_out = "  Locked Out\n";
00207     }
00208 
00209   ACE_DEBUG ((LM_DEBUG,
00210     "  Activator: %s\n"
00211     "  Command Line: %s\n"
00212     "  Working Directory: %s\n"
00213     "  Activation Mode: %s\n"
00214     "  Number of retries: %d\n"
00215     "%s",
00216     info.startup.activator.in (),
00217     info.startup.command_line.in (),
00218     info.startup.working_directory.in (),
00219     act,
00220     limit - 1,
00221     locked_out));
00222   for (CORBA::ULong i = 0; i < info.startup.environment.length (); ++i)
00223     ACE_DEBUG ((LM_DEBUG, "Environment Variable: %s=%s \n",
00224     info.startup.environment[i].name.in (),
00225     info.startup.environment[i].value.in ()));
00226 
00227   if (info.startup.activation == ImplementationRepository::PER_CLIENT)
00228     ACE_DEBUG ((LM_DEBUG,
00229                 "  No running info available for PER_CLIENT mode\n"));
00230   else if (ACE_OS::strlen (info.partial_ior.in ()) > 0)
00231     ACE_DEBUG ((LM_DEBUG,
00232                 "  Running at endpoint: %s\n",
00233                 info.partial_ior.in ()));
00234   else   // I am assuming that a blank partial_ior means currently not running.
00235     ACE_DEBUG ((LM_DEBUG,
00236                 "  Not currently running\n"));
00237 
00238   ACE_DEBUG ((LM_DEBUG, "\n"));
00239 }
00240 
00241 TAO_IMR_Op_List::TAO_IMR_Op_List (void)
00242 : verbose_server_information_ (0)
00243 {
00244   // Nothing
00245 }
00246 
00247 TAO_IMR_Op_Register::TAO_IMR_Op_Register (bool is_add)
00248 : is_add_ (is_add)
00249 , set_command_line_ (false)
00250 , set_environment_vars_(false)
00251 , set_working_dir_ (false)
00252 , set_activation_ (false)
00253 , activation_(ImplementationRepository::NORMAL)
00254 , set_retry_count_(false)
00255 , retry_count_ (0)
00256 , set_activator_ (false)
00257 {
00258   // Nothing
00259 }
00260 
00261 void
00262 TAO_IMR_Op_Activate::print_usage (void)
00263 {
00264   ACE_ERROR ((LM_ERROR, "Starts a server using its registered Activator.\n"
00265     "\n"
00266     "Usage: tao_imr [options] start <name>\n"
00267     "  where [options] are ORB options\n"
00268     "  where <name> is the name of a registered POA.\n"
00269     "  -h Displays this\n"));
00270 }
00271 
00272 int
00273 TAO_IMR_Op_Activate::parse (int argc, ACE_TCHAR **argv)
00274 {
00275   // Check for enough arguments (we need at least one for the server name)
00276   if (argc < 2)
00277     {
00278       this->print_usage ();
00279       return -1;
00280     }
00281 
00282   // Skip both the program name and the "activate" command
00283   ACE_Get_Opt get_opts (argc, argv, "h");
00284 
00285   this->server_name_ = argv[1];
00286   int c;
00287 
00288   while ((c = get_opts ()) != -1)
00289     {
00290       switch (c)
00291       {
00292       case 'h':
00293         this->print_usage ();
00294         return -1;
00295       default:
00296         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00297         this->print_usage ();
00298         return -1;
00299       }
00300     }
00301   return 0;
00302 }
00303 
00304 void
00305 TAO_IMR_Op_Autostart::print_usage (void)
00306 {
00307   ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] autostart\n"
00308     "  where [options] are ORB options\n"
00309     "  -h Displays this\n"));
00310 }
00311 
00312 int
00313 TAO_IMR_Op_Autostart::parse (int argc, ACE_TCHAR **argv)
00314 {
00315   // Skip the "autostart" command
00316   ACE_Get_Opt get_opts (argc, argv, "h");
00317 
00318   int c;
00319 
00320   while ((c = get_opts ()) != -1)
00321     {
00322       switch (c)
00323       {
00324       case 'h':  // display help
00325         this->print_usage ();
00326         return -1;
00327       default:
00328         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00329         this->print_usage ();
00330         return -1;
00331       }
00332     }
00333   return 0;
00334 }
00335 
00336 void
00337 TAO_IMR_Op_IOR::print_usage (void)
00338 {
00339   ACE_ERROR ((LM_ERROR, "Creates an IOR for a server that is registered with the IMR and uses\n"
00340     "the InterOperable Naming Service.  Please see the documentation for\n"
00341     "more information on which server configurations work with this command.\n"
00342     "\n"
00343     "Usage: tao_imr [options] ior <object_key> [command-arguments]\n"
00344     "  where [options] are ORB options\n"
00345     "  where <object_key> matches the simple key bound in the server IORTable.\n"
00346     "  where [command-arguments] can be\n"
00347     "    -f filename   filename to output the IOR to\n"
00348     "    -h            Displays this\n"));
00349 }
00350 
00351 int
00352 TAO_IMR_Op_IOR::parse (int argc, ACE_TCHAR **argv)
00353 {
00354   // Check for enough arguments (we need at least one for the server name)
00355   if (argc < 2)
00356     {
00357       this->print_usage ();
00358       return -1;
00359     }
00360 
00361   // Skip both the program name and the "ior" command
00362   ACE_Get_Opt get_opts (argc, argv, "hf:");
00363 
00364   this->server_name_ = argv[1];
00365   if (this->server_name_.length() == 0 || this->server_name_[0] == '-')
00366     {
00367       ACE_ERROR((LM_ERROR, "ERROR : name is required.\n"));
00368       this->print_usage ();
00369       return -1;
00370     }
00371 
00372   int c;
00373 
00374   while ((c = get_opts ()) != -1)
00375     {
00376       switch (c)
00377       {
00378       case 'f':  // File name
00379         this->filename_ = get_opts.opt_arg ();
00380         break;
00381       case 'h':  // display help
00382         this->print_usage ();
00383         return -1;
00384       default:
00385         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00386         this->print_usage ();
00387         return -1;
00388       }
00389     }
00390   return 0;
00391 }
00392 
00393 void
00394 TAO_IMR_Op_List::print_usage (void)
00395 {
00396   ACE_ERROR ((LM_ERROR, "Lists all or one of the servers in the Implementation Repository\n"
00397     "\n"
00398     "Usage: tao_imr [options] list [name] [command-arguments]\n"
00399     "  where [options] are ORB options\n"
00400     "  where [name] is the optional server name to search for\n"
00401     "  where [command-arguments] can be\n"
00402     "    -v            Verbose: Displays more info for each server when\n"
00403     "                  displaying more than one server\n"
00404     "    -h            Displays this\n"));
00405 }
00406 
00407 int
00408 TAO_IMR_Op_List::parse (int argc, ACE_TCHAR **argv)
00409 {
00410   int server_flag = 0;
00411 
00412   if (argc > 1 && argv[1][0] != '-')
00413   {
00414     this->server_name_ = argv[1];
00415     server_flag = 2;
00416   }
00417 
00418   // Skip both the program name and the "list" command
00419   ACE_Get_Opt get_opts (argc, argv, "vh", server_flag);
00420 
00421   int c;
00422 
00423   while ((c = get_opts ()) != -1)
00424     {
00425       switch (c)
00426       {
00427       case 'v': // verbose server display
00428         this->verbose_server_information_ = 1;
00429         break;
00430       case 'h':  // display help
00431         this->print_usage ();
00432         return -1;
00433       default:
00434         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00435         this->print_usage ();
00436         return -1;
00437       }
00438     }
00439   return 0;
00440 }
00441 
00442 void
00443 TAO_IMR_Op_Remove::print_usage (void)
00444 {
00445   ACE_ERROR ((LM_ERROR, "Removes a server entry\n"
00446     "\n"
00447     "Usage: tao_imr [options] remove <name>\n"
00448     "  where [options] are ORB options\n"
00449     "  where <name> is the POA name used by the server object\n"
00450     "  -h Displays this\n"));
00451 }
00452 
00453 int
00454 TAO_IMR_Op_Remove::parse (int argc, ACE_TCHAR **argv)
00455 {
00456   // Check for enough arguments (we need at least one for the server name)
00457   if (argc < 2)
00458     {
00459       this->print_usage ();
00460       return -1;
00461     }
00462 
00463   // Skip both the program name and the "remove" command
00464   ACE_Get_Opt get_opts (argc, argv, "h");
00465 
00466   this->server_name_ = argv[1];
00467   int c;
00468 
00469   while ((c = get_opts ()) != -1)
00470     {
00471       switch (c)
00472       {
00473       case 'h':
00474         this->print_usage ();
00475         return -1;
00476       default:
00477         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00478         this->print_usage ();
00479         return -1;
00480       }
00481     }
00482   return 0;
00483 }
00484 
00485 void
00486 TAO_IMR_Op_Shutdown::print_usage (void)
00487 {
00488   ACE_ERROR ((LM_ERROR, "Shuts down a server\n"
00489     "\n"
00490     "Usage: tao_imr [options] shutdown <name>\n"
00491     "  where [options] are ORB options\n"
00492     "  where <name> is the name of the server object\n"
00493     "  -h Displays this\n"));
00494 }
00495 
00496 int
00497 TAO_IMR_Op_Shutdown::parse (int argc, ACE_TCHAR **argv)
00498 {
00499   // Check for enough arguments (we need at least one for the server name)
00500   if (argc < 2)
00501     {
00502       this->print_usage ();
00503       return -1;
00504     }
00505 
00506   // Skip both the program name and the "shutdown" command
00507   ACE_Get_Opt get_opts (argc, argv, "h");
00508 
00509   this->server_name_ = argv[1];
00510   int c;
00511 
00512   while ((c = get_opts ()) != -1)
00513     {
00514       switch (c)
00515       {
00516       case 'h':
00517         this->print_usage ();
00518         return -1;
00519       default:
00520         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00521         this->print_usage ();
00522         return -1;
00523       }
00524     }
00525   return 0;
00526 }
00527 
00528 TAO_IMR_Op_ShutdownRepo::TAO_IMR_Op_ShutdownRepo()
00529 : activators_(false)
00530 {
00531 }
00532 
00533 void
00534 TAO_IMR_Op_ShutdownRepo::print_usage (void)
00535 {
00536   ACE_ERROR ((LM_ERROR, "Shuts down the ImR\n"
00537     "\n"
00538     "Usage: tao_imr [options] shutdown-repo [-a]\n"
00539     "  where [options] are ORB options\n"
00540     "  Specify -a to also shutdown any registered ImR Activators.\n"
00541     "  -h Displays this\n"));
00542 }
00543 
00544 int
00545 TAO_IMR_Op_ShutdownRepo::parse (int argc, ACE_TCHAR **argv)
00546 {
00547   // Check for enough arguments (we need at least one for the server name)
00548   if (argc < 1)
00549     {
00550       this->print_usage ();
00551       return -1;
00552     }
00553 
00554   // Skip both the program name and the "shutdown-repo" command
00555   ACE_Get_Opt get_opts (argc, argv, "ha");
00556 
00557   int c;
00558 
00559   while ((c = get_opts ()) != -1)
00560     {
00561       switch (c)
00562       {
00563       case 'h':
00564         this->print_usage ();
00565         return -1;
00566       case 'a':
00567         activators_ = true;
00568         break;
00569       default:
00570         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00571         this->print_usage ();
00572         return -1;
00573       }
00574     }
00575 
00576   return 0;
00577 }
00578 
00579 void
00580 TAO_IMR_Op_Register::addenv (ACE_TCHAR *opt)
00581 {
00582   CORBA::ULong length = this->environment_vars_.length ();
00583   // Increase the length of the sequence
00584   this->environment_vars_.length (length + 1);
00585   ACE_CString tokens (opt);
00586   int index = tokens.find ("=");
00587   // Insert at position length since that is our new element
00588   this->environment_vars_ [length].name =
00589     CORBA::string_dup (tokens.substr (0, index).c_str ());
00590   this->environment_vars_ [length].value =
00591     CORBA::string_dup (tokens.substr (index + 1).c_str ());
00592 }
00593 
00594 void
00595 TAO_IMR_Op_Register::print_usage (void)
00596 {
00597   ACE_ERROR ((LM_ERROR,
00598     "Adds/Updates a server entry\n"
00599     "\n"
00600     "Usage: tao_imr [options] <add|update> <name> [command-arguments]\n"
00601     "  where [options] are ORB options\n"
00602     "  where <name> is the POA name used by the server object\n"
00603     "  where [command-arguments] can be\n"
00604     "    -h            Displays this\n"
00605     "    -l            Activator name.\n"
00606     "    -c command    Startup command\n"
00607     "    -w dir        Working directory\n"
00608     "    -e name=value Set environment variables\n"
00609     "    -a mode       Set activate mode (NORMAL|MANUAL|PER_CLIENT|AUTO_START)\n"
00610     "    -r count      Set the startup/ping retry count to count\n"));
00611 }
00612 
00613 int
00614 TAO_IMR_Op_Register::parse (int argc, ACE_TCHAR **argv)
00615 {
00616   // Check for enough arguments (we need at least one for the server name)
00617   if (argc < 2)
00618     {
00619       ACE_ERROR((LM_ERROR, "Error: Must supply at least a server name.\n"));
00620       this->print_usage ();
00621       return -1;
00622     }
00623 
00624   // Skip both the program name and the "update" command
00625   ACE_Get_Opt get_opts (argc, argv, "hc:w:a:e:r:R:l:");
00626 
00627   this->server_name_ = argv[1];
00628   int c;
00629 
00630   while ((c = get_opts ()) != -1)
00631     {
00632       switch (c)
00633       {
00634       case 'c':  // Command line arguments
00635         this->set_command_line_ = true;
00636         this->command_line_ = get_opts.opt_arg ();
00637         break;
00638       case 'e':  // set environment variables
00639         this->set_environment_vars_ = true;
00640         this->addenv( get_opts.opt_arg () );
00641         break;
00642       case 'w':  // Working Directory
00643         this->set_working_dir_ = true;
00644         this->working_dir_ = get_opts.opt_arg ();
00645         break;
00646       case 'a':  // Activation Mode
00647         this->set_activation_ = true;
00648         if (ACE_OS::strcasecmp (get_opts.opt_arg (), "NORMAL") == 0)
00649           this->activation_ = ImplementationRepository::NORMAL;
00650         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "MANUAL") == 0)
00651           this->activation_ = ImplementationRepository::MANUAL;
00652         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "PER_CLIENT") == 0)
00653           this->activation_ = ImplementationRepository::PER_CLIENT;
00654         else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "AUTO_START") == 0)
00655           this->activation_ = ImplementationRepository::AUTO_START;
00656         else
00657           ACE_ERROR_RETURN ((LM_ERROR,
00658           "Unknown Activation Mode <%s>.\n",
00659           get_opts.opt_arg ()),
00660           -1);
00661         break;
00662       case 'r':
00663       case 'R':   // startup/ping Retry Count
00664         {
00665           this->set_retry_count_ = true;
00666           int rc = ACE_OS::atoi(get_opts.optarg);
00667           if (rc > 0)
00668             this->retry_count_ = rc;
00669         }
00670         break;
00671       case 'l': /// hostname of the activator
00672         this->activator_ = get_opts.optarg;
00673         this->set_activator_ = true;
00674         break;
00675       case 'h':  // display help
00676         this->print_usage ();
00677         return -1;
00678       default:
00679         ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00680         this->print_usage ();
00681         return -1;
00682       }
00683     }
00684   return 0;
00685 }
00686 
00687 
00688 // ============================================================================
00689 // = Run methods
00690 
00691 
00692 int
00693 TAO_IMR_Op_Activate::run (void)
00694 {
00695   ACE_ASSERT(! CORBA::is_nil(imr_));
00696   try
00697     {
00698       this->imr_->activate_server (this->server_name_.c_str ());
00699       ACE_DEBUG ((LM_DEBUG,
00700         "Successfully Activated server <%s>\n",
00701         this->server_name_.c_str ()));
00702     }
00703   catch (const ImplementationRepository::CannotActivate& ex)
00704     {
00705       ACE_ERROR ((LM_ERROR, "Cannot activate server <%s>, reason: <%s>\n",
00706         this->server_name_.c_str (),
00707         ex.reason.in ()));
00708       return TAO_IMR_Op::CANNOT_ACTIVATE;
00709     }
00710   catch (const ImplementationRepository::NotFound&)
00711     {
00712       ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n", this->server_name_.c_str ()));
00713       return TAO_IMR_Op::NOT_FOUND;
00714     }
00715   catch (const PortableServer::ForwardRequest&)
00716     {
00717       throw;
00718     }
00719   catch (const CORBA::Exception& ex)
00720     {
00721       ex._tao_print_exception ("Activating Server");
00722       return TAO_IMR_Op::UNKNOWN;
00723     }
00724 
00725   return TAO_IMR_Op::NORMAL;
00726 }
00727 
00728 int
00729 TAO_IMR_Op_Autostart::run (void)
00730 {
00731   ACE_ASSERT(! CORBA::is_nil (imr_));
00732 
00733   ImplementationRepository::ServerInformationList_var server_list;
00734   ImplementationRepository::ServerInformationIterator_var server_iter;
00735 
00736   try
00737     {
00738       this->imr_->list (0,
00739         server_list,
00740         server_iter);
00741 
00742       ACE_ASSERT(CORBA::is_nil (server_iter.in ()));
00743 
00744       CORBA::ULong len = server_list->length ();
00745       for (CORBA::ULong i = 0; i < len; ++i)
00746         {
00747           try
00748             {
00749               this->imr_->activate_server (server_list[i].server.in ());
00750             }
00751           catch (const CORBA::Exception& ex)
00752             {
00753               ex._tao_print_exception (
00754                 server_list[i].server.in (
00755                   ));
00756               // Ignore exception
00757             }
00758         }
00759     }
00760   catch (const CORBA::Exception& ex)
00761     {
00762       ex._tao_print_exception ("autostart");
00763       return TAO_IMR_Op::UNKNOWN;
00764     }
00765 
00766   return TAO_IMR_Op::NORMAL;
00767 }
00768 
00769 int
00770 TAO_IMR_Op_IOR::run (void)
00771 {
00772   ACE_ASSERT (! CORBA::is_nil(imr_));
00773 
00774   // Create a corbaloc string
00775   // Todo : Most of this logic duplicates that in the POA.cpp
00776   try
00777     {
00778       if (CORBA::is_nil (this->imr_)
00779         || !this->imr_->_stubobj ()
00780         || !this->imr_->_stubobj ()->profile_in_use ())
00781       {
00782         ACE_ERROR_RETURN ((
00783           LM_ERROR,
00784           ACE_TEXT ("Invalid ImR IOR.\n")
00785           ), -1);
00786       }
00787 
00788       CORBA::String_var imr_str =
00789         this->imr_->_stubobj ()->
00790         profile_in_use ()->to_string ();
00791 
00792       // Search for "corbaloc:" alone, without the protocol.  This code
00793       // should be protocol neutral.
00794       const char corbaloc[] = "corbaloc:";
00795       char *pos = ACE_OS::strstr (imr_str.inout (), corbaloc);
00796 
00797       if (pos == 0)
00798       {
00799         ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00800       }
00801       else
00802       {
00803         pos = ACE_OS::strchr (pos + sizeof (corbaloc), ':');
00804         pos = ACE_OS::strchr (pos + 1,
00805           this->imr_->_stubobj ()->profile_in_use ()->object_key_delimiter ());
00806 
00807         if (pos)
00808         {
00809           *(pos + 1) = 0;  // Crop the string
00810         }
00811         else
00812         {
00813           ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00814         }
00815       }
00816       ACE_CString ior (imr_str.in ());
00817 
00818       // Add the key
00819       ior += this->server_name_;
00820 
00821       ACE_DEBUG ((LM_DEBUG, "%s\n", ior.c_str ()));
00822 
00823       if (this->filename_.length () > 0)
00824       {
00825         FILE *file = ACE_OS::fopen (this->filename_.c_str (), "w");
00826 
00827         if (file == 0)
00828         {
00829           ACE_ERROR_RETURN ((LM_ERROR,
00830             "Error: Unable to open %s for writing: %p\n",
00831             this->filename_.c_str ()),
00832             -1);
00833         }
00834 
00835         ACE_OS::fprintf (file, "%s", ior.c_str ());
00836         ACE_OS::fclose (file);
00837       }
00838     }
00839   catch (const CORBA::Exception& ex)
00840     {
00841       ex._tao_print_exception ("IOR");
00842       return TAO_IMR_Op::UNKNOWN;
00843     }
00844 
00845   return TAO_IMR_Op::NORMAL;
00846 }
00847 
00848 int
00849 TAO_IMR_Op_List::run (void)
00850 {
00851   ACE_ASSERT (! CORBA::is_nil(imr_));
00852 
00853   ImplementationRepository::ServerInformationList_var server_list;
00854   ImplementationRepository::ServerInformationIterator_var server_iter;
00855 
00856   try
00857     {
00858       // If there is a server name, list only that server.  Otherwise, look
00859       // at all of them.
00860       if (this->server_name_.length () == 0)
00861         {
00862           this->imr_->list (0,
00863             server_list.out(),
00864             server_iter.out());
00865 
00866           if (server_list->length() == 0)
00867           {
00868             ACE_DEBUG((LM_DEBUG, "No servers found.\n"));
00869             return TAO_IMR_Op::NORMAL;
00870           }
00871 
00872           for (CORBA::ULong i = 0; i < server_list->length (); i++)
00873             this->display_server_information (server_list[i]);
00874 
00875           ACE_ASSERT (CORBA::is_nil (server_iter.in ()));
00876         }
00877       else
00878         {
00879           ImplementationRepository::ServerInformation_var si;
00880 
00881           this->imr_->find (this->server_name_.c_str (), si);
00882 
00883           this->verbose_server_information_ = 1;
00884 
00885           this->display_server_information (si.in ());
00886         }
00887     }
00888   catch (const ImplementationRepository::NotFound&)
00889     {
00890       ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n", this->server_name_.c_str ()));
00891       return TAO_IMR_Op::NOT_FOUND;
00892     }
00893   catch (const CORBA::Exception& ex)
00894     {
00895       ex._tao_print_exception ("List");
00896       return TAO_IMR_Op::UNKNOWN;
00897     }
00898 
00899   return TAO_IMR_Op::NORMAL;
00900 }
00901 
00902 int
00903 TAO_IMR_Op_Remove::run (void)
00904 {
00905   ACE_ASSERT (! CORBA::is_nil(imr_));
00906 
00907   try
00908     {
00909       this->imr_->remove_server (this->server_name_.c_str ());
00910 
00911       ACE_DEBUG ((LM_DEBUG, "Successfully removed server <%s>\n",
00912         this->server_name_.c_str ()));
00913     }
00914   catch (const ImplementationRepository::NotFound&)
00915     {
00916       ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n",
00917         this->server_name_.c_str ()));
00918       return TAO_IMR_Op::NOT_FOUND;
00919     }
00920   catch (const CORBA::NO_PERMISSION&)
00921     {
00922       ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
00923       return TAO_IMR_Op::NO_PERMISSION;
00924     }
00925   catch (const CORBA::Exception& ex)
00926     {
00927       ex._tao_print_exception ("Removing Server");
00928       return TAO_IMR_Op::UNKNOWN;
00929     }
00930 
00931   return TAO_IMR_Op::NORMAL;
00932 }
00933 
00934 int
00935 TAO_IMR_Op_Shutdown::run (void)
00936 {
00937   ACE_ASSERT (! CORBA::is_nil(imr_));
00938 
00939   try
00940     {
00941       this->imr_->shutdown_server (this->server_name_.c_str ());
00942 
00943       ACE_DEBUG ((LM_DEBUG, "Successfully shut down server <%s>\n",
00944         this->server_name_.c_str ()));
00945     }
00946   catch (const ImplementationRepository::NotFound&)
00947     {
00948       ACE_ERROR ((LM_ERROR, "Server <%s> already shut down.\n", this->server_name_.c_str ()));
00949       return TAO_IMR_Op::NOT_FOUND;
00950     }
00951   catch (const CORBA::TIMEOUT&)
00952     {
00953       ACE_DEBUG ((LM_DEBUG, "Timeout waiting for <%s> to shutdown.\n",
00954         this->server_name_.c_str ()));
00955     }
00956   catch (const CORBA::Exception& ex)
00957     {
00958       ex._tao_print_exception ("Shutting Down Server");
00959       return TAO_IMR_Op::UNKNOWN;
00960     }
00961 
00962   return TAO_IMR_Op::NORMAL;
00963 }
00964 
00965 int
00966 TAO_IMR_Op_ShutdownRepo::run (void)
00967 {
00968   ACE_ASSERT(! CORBA::is_nil(imr_));
00969 
00970   try
00971     {
00972       bool servers = false; // not implemented yet, if ever
00973       this->imr_->shutdown (activators_, servers);
00974 
00975       ACE_DEBUG ((LM_DEBUG, "ImR shutdown initiated.\n"));
00976     }
00977   catch (const CORBA::TIMEOUT&)
00978     {
00979       ACE_DEBUG ((LM_DEBUG, "Timeout waiting for ImR shutdown.\n"));
00980     }
00981   catch (const CORBA::Exception& ex)
00982     {
00983       ex._tao_print_exception ("Shutting Down ImR");
00984       return TAO_IMR_Op::UNKNOWN;
00985     }
00986 
00987   return TAO_IMR_Op::NORMAL;
00988 }
00989 
00990 int
00991 TAO_IMR_Op_Register::run (void)
00992 {
00993   ACE_ASSERT (! CORBA::is_nil(imr_));
00994 
00995   ImplementationRepository::ServerInformation_var server_information;
00996   ImplementationRepository::StartupOptions  local;
00997   ImplementationRepository::StartupOptions* options = 0;
00998 
00999   try
01000     {
01001       this->imr_->find(this->server_name_.c_str (),
01002         server_information.out());
01003 
01004       if (server_name_ == server_information->server.in())
01005         {
01006           if (is_add_)
01007             {
01008               ACE_DEBUG((LM_DEBUG, "Server <%s> already registered.\n", this->server_name_.c_str ()));
01009               return ALREADY_REGISTERED;
01010             }
01011           options = &server_information->startup;
01012         }
01013       else // not found
01014         {
01015           if (!is_add_)
01016           {
01017             ACE_DEBUG((LM_DEBUG, "Adding Server <%s> on update command.\n", this->server_name_.c_str ()));
01018             is_add_ = true;
01019           }
01020           options = &local;
01021         }
01022 
01023       if (this->set_command_line_)
01024         options->command_line = CORBA::string_dup (this->command_line_.c_str ());
01025 
01026       if (this->set_environment_vars_)
01027         options->environment = this->environment_vars_;
01028 
01029       if (this->set_working_dir_)
01030         options->working_directory = CORBA::string_dup (this->working_dir_.c_str ());
01031 
01032       if (this->set_activation_ || is_add_)
01033         options->activation = this->activation_;
01034 
01035       if (this->set_retry_count_ || is_add_)
01036         options->start_limit = this->retry_count_ + 1;
01037 
01038       if (this->set_activator_)
01039         options->activator = CORBA::string_dup(this->activator_.c_str ());
01040       // If the command line is set, we must have an activator
01041       else if (this->set_command_line_ &&
01042               (options->activator.in () == 0 || *options->activator.in () == 0))
01043         {
01044           char host_name[MAXHOSTNAMELEN + 1];
01045           ACE_OS::hostname (host_name, MAXHOSTNAMELEN);
01046           options->activator = CORBA::string_dup (host_name);
01047           ACE_DEBUG ((LM_DEBUG, "Updating Server <%s> with default activator of <%s>.\n",
01048             this->server_name_.c_str (), options->activator.in ()));
01049         }
01050 
01051       this->imr_->add_or_update_server (this->server_name_.c_str (), *options);
01052 
01053       ACE_DEBUG((LM_DEBUG, "Successfully registered <%s>.\n", this->server_name_.c_str ()));
01054     }
01055   catch (const CORBA::NO_PERMISSION&)
01056     {
01057       ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
01058       return TAO_IMR_Op::NO_PERMISSION;
01059     }
01060   catch (const CORBA::Exception& ex)
01061     {
01062       ex._tao_print_exception ("Updating server");
01063       return TAO_IMR_Op::UNKNOWN;
01064     }
01065 
01066   return TAO_IMR_Op::NORMAL;
01067 }
01068 
01069 // ============================================================================
01070 // = Display Server Information methods
01071 
01072 void
01073 TAO_IMR_Op_List::display_server_information (const ImplementationRepository::ServerInformation &info)
01074 {
01075   if (this->verbose_server_information_)
01076     TAO_IMR_Op::display_server_information (info);
01077   else
01078     ACE_DEBUG ((LM_DEBUG, "<%s>\n", info.server.in ()));
01079 }

Generated on Sun Jan 27 15:54:51 2008 for TAO_Implementation_Repository by doxygen 1.3.6