00001
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
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 ACE_DECLARE_NEW_CORBA_ENV;
00047 ACE_TRY
00048 {
00049
00050 this->orb_ = CORBA::ORB_init (this->argc_, this->argv_, "tao_imr_i" ACE_ENV_ARG_PARAMETER);
00051 ACE_TRY_CHECK;
00052
00053
00054 if (this->parse_args () == -1)
00055 return -1;
00056
00057
00058 CORBA::Object_var obj =
00059 orb_->resolve_initial_references ("ImplRepoService" ACE_ENV_ARG_PARAMETER);
00060 ACE_TRY_CHECK;
00061
00062 if (CORBA::is_nil (obj.in ()))
00063 {
00064 ACE_ERROR ((LM_ERROR, "Unable to resolve the ImR.\n"));
00065 return -1;
00066 }
00067
00068 exception_message = "While narrowing ImR";
00069
00070 this->imr_ =
00071 ImplementationRepository::Administration::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
00072 ACE_TRY_CHECK;
00073
00074 if (CORBA::is_nil (imr_.in ()))
00075 {
00076 ACE_ERROR ((LM_ERROR, "Unable to narrow the ImR.\n"));
00077 return -1;
00078 }
00079
00080 this->op_->set_imr (this->imr_.in ());
00081 }
00082 ACE_CATCHANY
00083 {
00084 ACE_ERROR ((LM_ERROR, "TAO_IMR_i::init - %s\n", exception_message));
00085 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception");
00086 return -1;
00087 }
00088 ACE_ENDTRY;
00089
00090 return 0;
00091 }
00092
00093
00094
00095
00096 int
00097 TAO_IMR_i::parse_args (void)
00098 {
00099
00100 if (this->argc_ < 2)
00101 {
00102 ACE_ERROR((LM_ERROR, "Error: No operation specified.\n"));
00103 this->print_usage ();
00104 return -1;
00105 }
00106
00107 this->op_.reset (TAO_IMR_Op::make_op (this->argv_[1]));
00108
00109
00110
00111 if (this->op_.get () == 0)
00112 {
00113 ACE_ERROR((LM_ERROR, "Error: Unknown operation '%s'.\n", this->argv_[1]));
00114 this->print_usage ();
00115 return -1;
00116 }
00117
00118
00119 return this->op_->parse (this->argc_ - 1, this->argv_ + 1);
00120 }
00121
00122
00123
00124
00125 void
00126 TAO_IMR_i::print_usage (void)
00127 {
00128 ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] command [command-arguments]\n"
00129 " where [options] are ORB options\n"
00130 " where command is one of the following:\n"
00131 " start Start a server through the ImR\n"
00132 " add Add an entry to the ImR\n"
00133 " autostart Activates all AUTO_START servers\n"
00134 " ior Creates a simplified IOR\n"
00135 " list List the entries in the ImR\n"
00136 " remove Remove an entry from the ImR\n"
00137 " shutdown Shut down a server through the ImR\n"
00138 " shutdown-repo Shut down the ImR\n"
00139 " update Update an entry in the ImR\n"
00140 " where [command-arguments] depend on the command\n"));
00141 }
00142
00143
00144
00145
00146 TAO_IMR_Op *
00147 TAO_IMR_Op::make_op (const ACE_TCHAR *op_name)
00148 {
00149 if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("activate")) == 0)
00150 {
00151 ACE_ERROR((LM_ERROR, "Warning: The activate option has been renamed to start.\n"));
00152 return new TAO_IMR_Op_Activate ();
00153 }
00154 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("start")) == 0)
00155 return new TAO_IMR_Op_Activate ();
00156 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("add")) == 0)
00157 return new TAO_IMR_Op_Register (true);
00158 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("autostart")) == 0)
00159 return new TAO_IMR_Op_Autostart();
00160 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("ior")) == 0)
00161 return new TAO_IMR_Op_IOR();
00162 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("list")) == 0)
00163 return new TAO_IMR_Op_List ();
00164 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("remove")) == 0)
00165 return new TAO_IMR_Op_Remove ();
00166 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("shutdown")) == 0)
00167 return new TAO_IMR_Op_Shutdown ();
00168 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("shutdown-repo")) == 0)
00169 return new TAO_IMR_Op_ShutdownRepo ();
00170 else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("update")) == 0)
00171 return new TAO_IMR_Op_Register (false);
00172
00173 return 0;
00174 }
00175
00176
00177 TAO_IMR_Op::~TAO_IMR_Op ()
00178 {
00179
00180 }
00181
00182 void
00183 TAO_IMR_Op::set_imr (ImplementationRepository::Administration_ptr imr)
00184 {
00185 this->imr_ = imr;
00186 }
00187
00188 void
00189 TAO_IMR_Op::display_server_information (const ImplementationRepository::ServerInformation &info)
00190 {
00191
00192 const char *act = "UNKNOWN STARTUP";
00193 if (info.startup.activation == ImplementationRepository::NORMAL)
00194 act = "NORMAL";
00195 else if (info.startup.activation == ImplementationRepository::MANUAL)
00196 act = "MANUAL";
00197 else if (info.startup.activation == ImplementationRepository::PER_CLIENT)
00198 act = "PER_CLIENT";
00199 else if (info.startup.activation == ImplementationRepository::AUTO_START)
00200 act = "AUTO_START";
00201
00202
00203 ACE_DEBUG ((LM_DEBUG, "Server <%s>\n", info.server.in ()));
00204
00205 const char * locked_out = "";
00206
00207 int limit = info.startup.start_limit;
00208 if (info.startup.start_limit < 0)
00209 {
00210 limit = -limit;
00211 locked_out = " Locked Out\n";
00212 }
00213
00214 ACE_DEBUG ((LM_DEBUG,
00215 " Activator: %s\n"
00216 " Command Line: %s\n"
00217 " Working Directory: %s\n"
00218 " Activation Mode: %s\n"
00219 " Number of retries: %d\n"
00220 "%s",
00221 info.startup.activator.in (),
00222 info.startup.command_line.in (),
00223 info.startup.working_directory.in (),
00224 act,
00225 limit - 1,
00226 locked_out));
00227 for (CORBA::ULong i = 0; i < info.startup.environment.length (); ++i)
00228 ACE_DEBUG ((LM_DEBUG, "Environment Variable: %s=%s \n",
00229 info.startup.environment[i].name.in (),
00230 info.startup.environment[i].value.in ()));
00231
00232 if (info.startup.activation == ImplementationRepository::PER_CLIENT)
00233 ACE_DEBUG ((LM_DEBUG,
00234 " No running info available for PER_CLIENT mode\n"));
00235 else if (ACE_OS::strlen (info.partial_ior.in ()) > 0)
00236 ACE_DEBUG ((LM_DEBUG,
00237 " Running at endpoint: %s\n",
00238 info.partial_ior.in ()));
00239 else
00240 ACE_DEBUG ((LM_DEBUG,
00241 " Not currently running\n"));
00242
00243 ACE_DEBUG ((LM_DEBUG, "\n"));
00244 }
00245
00246 TAO_IMR_Op_List::TAO_IMR_Op_List (void)
00247 : verbose_server_information_ (0)
00248 {
00249
00250 }
00251
00252 TAO_IMR_Op_Register::TAO_IMR_Op_Register (bool is_add)
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
00264 }
00265
00266 void
00267 TAO_IMR_Op_Activate::print_usage (void)
00268 {
00269 ACE_ERROR ((LM_ERROR, "Starts a server using its registered Activator.\n"
00270 "\n"
00271 "Usage: tao_imr [options] start <name>\n"
00272 " where [options] are ORB options\n"
00273 " where <name> is the name of a registered POA.\n"
00274 " -h Displays this\n"));
00275 }
00276
00277 int
00278 TAO_IMR_Op_Activate::parse (int argc, ACE_TCHAR **argv)
00279 {
00280
00281 if (argc < 2)
00282 {
00283 this->print_usage ();
00284 return -1;
00285 }
00286
00287
00288 ACE_Get_Opt get_opts (argc, argv, "h");
00289
00290 this->server_name_ = argv[1];
00291 int c;
00292
00293 while ((c = get_opts ()) != -1)
00294 {
00295 switch (c)
00296 {
00297 case 'h':
00298 this->print_usage ();
00299 return -1;
00300 default:
00301 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00302 this->print_usage ();
00303 return -1;
00304 }
00305 }
00306 return 0;
00307 }
00308
00309 void
00310 TAO_IMR_Op_Autostart::print_usage (void)
00311 {
00312 ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] autostart\n"
00313 " where [options] are ORB options\n"
00314 " -h Displays this\n"));
00315 }
00316
00317 int
00318 TAO_IMR_Op_Autostart::parse (int argc, ACE_TCHAR **argv)
00319 {
00320
00321 ACE_Get_Opt get_opts (argc, argv, "h");
00322
00323 int c;
00324
00325 while ((c = get_opts ()) != -1)
00326 {
00327 switch (c)
00328 {
00329 case 'h':
00330 this->print_usage ();
00331 return -1;
00332 default:
00333 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00334 this->print_usage ();
00335 return -1;
00336 }
00337 }
00338 return 0;
00339 }
00340
00341 void
00342 TAO_IMR_Op_IOR::print_usage (void)
00343 {
00344 ACE_ERROR ((LM_ERROR, "Creates an IOR for a server that is registered with the IMR and uses\n"
00345 "the InterOperable Naming Service. Please see the documentation for\n"
00346 "more information on which server configurations work with this command.\n"
00347 "\n"
00348 "Usage: tao_imr [options] ior <object_key> [command-arguments]\n"
00349 " where [options] are ORB options\n"
00350 " where <object_key> matches the simple key bound in the server IORTable.\n"
00351 " where [command-arguments] can be\n"
00352 " -f filename filename to output the IOR to\n"
00353 " -h Displays this\n"));
00354 }
00355
00356 int
00357 TAO_IMR_Op_IOR::parse (int argc, ACE_TCHAR **argv)
00358 {
00359
00360 if (argc < 2)
00361 {
00362 this->print_usage ();
00363 return -1;
00364 }
00365
00366
00367 ACE_Get_Opt get_opts (argc, argv, "hf:");
00368
00369 this->server_name_ = argv[1];
00370 if (this->server_name_.length() == 0 || this->server_name_[0] == '-')
00371 {
00372 ACE_ERROR((LM_ERROR, "ERROR : name is required.\n"));
00373 this->print_usage ();
00374 return -1;
00375 }
00376
00377 int c;
00378
00379 while ((c = get_opts ()) != -1)
00380 {
00381 switch (c)
00382 {
00383 case 'f':
00384 this->filename_ = get_opts.opt_arg ();
00385 break;
00386 case 'h':
00387 this->print_usage ();
00388 return -1;
00389 default:
00390 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00391 this->print_usage ();
00392 return -1;
00393 }
00394 }
00395 return 0;
00396 }
00397
00398 void
00399 TAO_IMR_Op_List::print_usage (void)
00400 {
00401 ACE_ERROR ((LM_ERROR, "Lists all or one of the servers in the Implementation Repository\n"
00402 "\n"
00403 "Usage: tao_imr [options] list [name] [command-arguments]\n"
00404 " where [options] are ORB options\n"
00405 " where [name] is the optional server name to search for\n"
00406 " where [command-arguments] can be\n"
00407 " -v Verbose: Displays more info for each server when\n"
00408 " displaying more than one server\n"
00409 " -h Displays this\n"));
00410 }
00411
00412 int
00413 TAO_IMR_Op_List::parse (int argc, ACE_TCHAR **argv)
00414 {
00415 int server_flag = 0;
00416
00417 if (argc > 1 && argv[1][0] != '-')
00418 {
00419 this->server_name_ = argv[1];
00420 server_flag = 2;
00421 }
00422
00423
00424 ACE_Get_Opt get_opts (argc, argv, "vh", server_flag);
00425
00426 int c;
00427
00428 while ((c = get_opts ()) != -1)
00429 {
00430 switch (c)
00431 {
00432 case 'v':
00433 this->verbose_server_information_ = 1;
00434 break;
00435 case 'h':
00436 this->print_usage ();
00437 return -1;
00438 default:
00439 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00440 this->print_usage ();
00441 return -1;
00442 }
00443 }
00444 return 0;
00445 }
00446
00447 void
00448 TAO_IMR_Op_Remove::print_usage (void)
00449 {
00450 ACE_ERROR ((LM_ERROR, "Removes a server entry\n"
00451 "\n"
00452 "Usage: tao_imr [options] remove <name>\n"
00453 " where [options] are ORB options\n"
00454 " where <name> is the POA name used by the server object\n"
00455 " -h Displays this\n"));
00456 }
00457
00458 int
00459 TAO_IMR_Op_Remove::parse (int argc, ACE_TCHAR **argv)
00460 {
00461
00462 if (argc < 2)
00463 {
00464 this->print_usage ();
00465 return -1;
00466 }
00467
00468
00469 ACE_Get_Opt get_opts (argc, argv, "h");
00470
00471 this->server_name_ = argv[1];
00472 int c;
00473
00474 while ((c = get_opts ()) != -1)
00475 {
00476 switch (c)
00477 {
00478 case 'h':
00479 this->print_usage ();
00480 return -1;
00481 default:
00482 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00483 this->print_usage ();
00484 return -1;
00485 }
00486 }
00487 return 0;
00488 }
00489
00490 void
00491 TAO_IMR_Op_Shutdown::print_usage (void)
00492 {
00493 ACE_ERROR ((LM_ERROR, "Shuts down a server\n"
00494 "\n"
00495 "Usage: tao_imr [options] shutdown <name>\n"
00496 " where [options] are ORB options\n"
00497 " where <name> is the name of the server object\n"
00498 " -h Displays this\n"));
00499 }
00500
00501 int
00502 TAO_IMR_Op_Shutdown::parse (int argc, ACE_TCHAR **argv)
00503 {
00504
00505 if (argc < 2)
00506 {
00507 this->print_usage ();
00508 return -1;
00509 }
00510
00511
00512 ACE_Get_Opt get_opts (argc, argv, "h");
00513
00514 this->server_name_ = argv[1];
00515 int c;
00516
00517 while ((c = get_opts ()) != -1)
00518 {
00519 switch (c)
00520 {
00521 case 'h':
00522 this->print_usage ();
00523 return -1;
00524 default:
00525 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00526 this->print_usage ();
00527 return -1;
00528 }
00529 }
00530 return 0;
00531 }
00532
00533 TAO_IMR_Op_ShutdownRepo::TAO_IMR_Op_ShutdownRepo()
00534 : activators_(false)
00535 {
00536 }
00537
00538 void
00539 TAO_IMR_Op_ShutdownRepo::print_usage (void)
00540 {
00541 ACE_ERROR ((LM_ERROR, "Shuts down the ImR\n"
00542 "\n"
00543 "Usage: tao_imr [options] shutdown-repo [-a]\n"
00544 " where [options] are ORB options\n"
00545 " Specify -a to also shutdown any registered ImR Activators.\n"
00546 " -h Displays this\n"));
00547 }
00548
00549 int
00550 TAO_IMR_Op_ShutdownRepo::parse (int argc, ACE_TCHAR **argv)
00551 {
00552
00553 if (argc < 1)
00554 {
00555 this->print_usage ();
00556 return -1;
00557 }
00558
00559
00560 ACE_Get_Opt get_opts (argc, argv, "ha");
00561
00562 int c;
00563
00564 while ((c = get_opts ()) != -1)
00565 {
00566 switch (c)
00567 {
00568 case 'h':
00569 this->print_usage ();
00570 return -1;
00571 case 'a':
00572 activators_ = true;
00573 break;
00574 default:
00575 ACE_ERROR((LM_ERROR, "ERROR : Unknown option '%c'\n", (char) c));
00576 this->print_usage ();
00577 return -1;
00578 }
00579 }
00580
00581 return 0;
00582 }
00583
00584 void
00585 TAO_IMR_Op_Register::addenv (ACE_TCHAR *opt)
00586 {
00587 CORBA::ULong length = this->environment_vars_.length ();
00588
00589 this->environment_vars_.length (length + 1);
00590 ACE_CString tokens (opt);
00591 int index = tokens.find ("=");
00592
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 }
00598
00599 void
00600 TAO_IMR_Op_Register::print_usage (void)
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 }
00617
00618 int
00619 TAO_IMR_Op_Register::parse (int argc, ACE_TCHAR **argv)
00620 {
00621
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
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':
00640 this->set_command_line_ = true;
00641 this->command_line_ = get_opts.opt_arg ();
00642 break;
00643 case 'e':
00644 this->set_environment_vars_ = true;
00645 this->addenv( get_opts.opt_arg () );
00646 break;
00647 case 'w':
00648 this->set_working_dir_ = true;
00649 this->working_dir_ = get_opts.opt_arg ();
00650 break;
00651 case 'a':
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':
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':
00677 this->activator_ = get_opts.optarg;
00678 this->set_activator_ = true;
00679 break;
00680 case 'h':
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 }
00691
00692
00693
00694
00695
00696
00697 int
00698 TAO_IMR_Op_Activate::run (void)
00699 {
00700 ACE_ASSERT(! CORBA::is_nil(imr_));
00701 ACE_DECLARE_NEW_CORBA_ENV;
00702 ACE_TRY
00703 {
00704 this->imr_->activate_server (this->server_name_.c_str () ACE_ENV_ARG_PARAMETER);
00705 ACE_TRY_CHECK;
00706 ACE_DEBUG ((LM_DEBUG,
00707 "Successfully Activated server <%s>\n",
00708 this->server_name_.c_str ()));
00709 }
00710 ACE_CATCH (ImplementationRepository::CannotActivate, ex)
00711 {
00712 ACE_ERROR ((LM_ERROR, "Cannot activate server <%s>, reason: <%s>\n",
00713 this->server_name_.c_str (),
00714 ex.reason.in ()));
00715 return TAO_IMR_Op::CANNOT_ACTIVATE;
00716 }
00717 ACE_CATCH (ImplementationRepository::NotFound, ex)
00718 {
00719 ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n", this->server_name_.c_str ()));
00720 return TAO_IMR_Op::NOT_FOUND;
00721 }
00722 ACE_CATCH (PortableServer::ForwardRequest, ex)
00723 {
00724 ACE_RE_THROW;
00725 }
00726 ACE_CATCHANY
00727 {
00728 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Activating Server");
00729 return TAO_IMR_Op::UNKNOWN;
00730 }
00731 ACE_ENDTRY;
00732
00733 return TAO_IMR_Op::NORMAL;
00734 }
00735
00736 int
00737 TAO_IMR_Op_Autostart::run (void)
00738 {
00739 ACE_ASSERT(! CORBA::is_nil (imr_));
00740
00741 ImplementationRepository::ServerInformationList_var server_list;
00742 ImplementationRepository::ServerInformationIterator_var server_iter;
00743
00744 ACE_DECLARE_NEW_CORBA_ENV;
00745 ACE_TRY
00746 {
00747 this->imr_->list (0,
00748 server_list,
00749 server_iter
00750 ACE_ENV_ARG_PARAMETER);
00751 ACE_TRY_CHECK;
00752
00753 ACE_ASSERT(CORBA::is_nil (server_iter.in ()));
00754
00755 CORBA::ULong len = server_list->length ();
00756 for (CORBA::ULong i = 0; i < len; ++i)
00757 {
00758 ACE_TRY_EX (inside)
00759 {
00760 this->imr_->activate_server (server_list[i].server.in () ACE_ENV_ARG_PARAMETER);
00761 ACE_TRY_CHECK_EX (inside);
00762 }
00763 ACE_CATCHANY
00764 {
00765 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, server_list[i].server.in ());
00766
00767 }
00768 ACE_ENDTRY;
00769 }
00770 }
00771 ACE_CATCHANY
00772 {
00773 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "autostart");
00774 return TAO_IMR_Op::UNKNOWN;
00775 }
00776 ACE_ENDTRY;
00777
00778 return TAO_IMR_Op::NORMAL;
00779 }
00780
00781 int
00782 TAO_IMR_Op_IOR::run (void)
00783 {
00784 ACE_ASSERT (! CORBA::is_nil(imr_));
00785
00786
00787
00788 ACE_TRY_NEW_ENV
00789 {
00790 if (CORBA::is_nil (this->imr_)
00791 || !this->imr_->_stubobj ()
00792 || !this->imr_->_stubobj ()->profile_in_use ())
00793 {
00794 ACE_ERROR_RETURN ((
00795 LM_ERROR,
00796 ACE_TEXT ("Invalid ImR IOR.\n")
00797 ), -1);
00798 }
00799
00800 CORBA::String_var imr_str =
00801 this->imr_->_stubobj ()->
00802 profile_in_use ()->to_string (ACE_ENV_SINGLE_ARG_PARAMETER);
00803 ACE_TRY_CHECK;
00804
00805
00806
00807 const char corbaloc[] = "corbaloc:";
00808 char *pos = ACE_OS::strstr (imr_str.inout (), corbaloc);
00809
00810 if (pos == 0)
00811 {
00812 ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00813 }
00814 else
00815 {
00816 pos = ACE_OS::strchr (pos + sizeof (corbaloc), ':');
00817 pos = ACE_OS::strchr (pos + 1,
00818 this->imr_->_stubobj ()->profile_in_use ()->object_key_delimiter ());
00819
00820 if (pos)
00821 {
00822 *(pos + 1) = 0;
00823 }
00824 else
00825 {
00826 ACE_ERROR_RETURN ((LM_ERROR, "Could not parse IMR IOR.\n"), -1);
00827 }
00828 }
00829 ACE_CString ior (imr_str.in ());
00830
00831
00832 ior += this->server_name_;
00833
00834 ACE_DEBUG ((LM_DEBUG, "%s\n", ior.c_str ()));
00835
00836 if (this->filename_.length () > 0)
00837 {
00838 FILE *file = ACE_OS::fopen (this->filename_.c_str (), "w");
00839
00840 if (file == 0)
00841 {
00842 ACE_ERROR_RETURN ((LM_ERROR,
00843 "Error: Unable to open %s for writing: %p\n",
00844 this->filename_.c_str ()),
00845 -1);
00846 }
00847
00848 ACE_OS::fprintf (file, "%s", ior.c_str ());
00849 ACE_OS::fclose (file);
00850 }
00851 }
00852 ACE_CATCHANY
00853 {
00854 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "IOR");
00855 return TAO_IMR_Op::UNKNOWN;
00856 }
00857 ACE_ENDTRY;
00858
00859 return TAO_IMR_Op::NORMAL;
00860 }
00861
00862 int
00863 TAO_IMR_Op_List::run (void)
00864 {
00865 ACE_ASSERT (! CORBA::is_nil(imr_));
00866
00867 ImplementationRepository::ServerInformationList_var server_list;
00868 ImplementationRepository::ServerInformationIterator_var server_iter;
00869
00870 ACE_DECLARE_NEW_CORBA_ENV;
00871 ACE_TRY
00872 {
00873
00874
00875 if (this->server_name_.length () == 0)
00876 {
00877 this->imr_->list (0,
00878 server_list.out(),
00879 server_iter.out()
00880 ACE_ENV_ARG_PARAMETER);
00881 ACE_TRY_CHECK;
00882
00883 if (server_list->length() == 0)
00884 {
00885 ACE_DEBUG((LM_DEBUG, "No servers found.\n"));
00886 return TAO_IMR_Op::NORMAL;
00887 }
00888
00889 for (CORBA::ULong i = 0; i < server_list->length (); i++)
00890 this->display_server_information (server_list[i]);
00891
00892 ACE_ASSERT (CORBA::is_nil (server_iter.in ()));
00893 }
00894 else
00895 {
00896 ImplementationRepository::ServerInformation_var si;
00897
00898 this->imr_->find (this->server_name_.c_str (), si ACE_ENV_ARG_PARAMETER);
00899 ACE_TRY_CHECK;
00900
00901 this->verbose_server_information_ = 1;
00902
00903 this->display_server_information (si.in ());
00904 }
00905 }
00906 ACE_CATCH (ImplementationRepository::NotFound, ex)
00907 {
00908 ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n", this->server_name_.c_str ()));
00909 return TAO_IMR_Op::NOT_FOUND;
00910 }
00911 ACE_CATCHANY
00912 {
00913 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "List");
00914 return TAO_IMR_Op::UNKNOWN;
00915 }
00916 ACE_ENDTRY;
00917
00918 return TAO_IMR_Op::NORMAL;
00919 }
00920
00921 int
00922 TAO_IMR_Op_Remove::run (void)
00923 {
00924 ACE_ASSERT (! CORBA::is_nil(imr_));
00925
00926 ACE_DECLARE_NEW_CORBA_ENV;
00927 ACE_TRY
00928 {
00929 this->imr_->remove_server (this->server_name_.c_str () ACE_ENV_ARG_PARAMETER);
00930 ACE_TRY_CHECK;
00931
00932 ACE_DEBUG ((LM_DEBUG, "Successfully removed server <%s>\n",
00933 this->server_name_.c_str ()));
00934 }
00935 ACE_CATCH (ImplementationRepository::NotFound, ex)
00936 {
00937 ACE_ERROR ((LM_ERROR, "Could not find server <%s>.\n",
00938 this->server_name_.c_str ()));
00939 return TAO_IMR_Op::NOT_FOUND;
00940 }
00941 ACE_CATCH (CORBA::NO_PERMISSION, ex)
00942 {
00943 ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
00944 return TAO_IMR_Op::NO_PERMISSION;
00945 }
00946 ACE_CATCHANY
00947 {
00948 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Removing Server");
00949 return TAO_IMR_Op::UNKNOWN;
00950 }
00951 ACE_ENDTRY;
00952
00953 return TAO_IMR_Op::NORMAL;
00954 }
00955
00956 int
00957 TAO_IMR_Op_Shutdown::run (void)
00958 {
00959 ACE_ASSERT (! CORBA::is_nil(imr_));
00960
00961 ACE_DECLARE_NEW_CORBA_ENV;
00962 ACE_TRY
00963 {
00964 this->imr_->shutdown_server (this->server_name_.c_str () ACE_ENV_ARG_PARAMETER);
00965 ACE_TRY_CHECK;
00966
00967 ACE_DEBUG ((LM_DEBUG, "Successfully shut down server <%s>\n",
00968 this->server_name_.c_str ()));
00969 }
00970 ACE_CATCH (ImplementationRepository::NotFound, ex)
00971 {
00972 ACE_ERROR ((LM_ERROR, "Server <%s> already shut down.\n", this->server_name_.c_str ()));
00973 return TAO_IMR_Op::NOT_FOUND;
00974 }
00975 ACE_CATCH(CORBA::TIMEOUT, ex)
00976 {
00977 ACE_DEBUG ((LM_DEBUG, "Timeout waiting for <%s> to shutdown.\n",
00978 this->server_name_.c_str ()));
00979 }
00980 ACE_CATCHANY
00981 {
00982 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Shutting Down Server");
00983 return TAO_IMR_Op::UNKNOWN;
00984 }
00985 ACE_ENDTRY;
00986
00987 return TAO_IMR_Op::NORMAL;
00988 }
00989
00990 int
00991 TAO_IMR_Op_ShutdownRepo::run (void)
00992 {
00993 ACE_ASSERT(! CORBA::is_nil(imr_));
00994
00995 ACE_DECLARE_NEW_CORBA_ENV;
00996 ACE_TRY
00997 {
00998 bool servers = false;
00999 this->imr_->shutdown (activators_, servers ACE_ENV_ARG_PARAMETER);
01000 ACE_TRY_CHECK;
01001
01002 ACE_DEBUG ((LM_DEBUG, "ImR shutdown initiated.\n"));
01003 }
01004 ACE_CATCH(CORBA::TIMEOUT, ex)
01005 {
01006 ACE_DEBUG ((LM_DEBUG, "Timeout waiting for ImR shutdown.\n"));
01007 }
01008 ACE_CATCHANY
01009 {
01010 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Shutting Down ImR");
01011 return TAO_IMR_Op::UNKNOWN;
01012 }
01013 ACE_ENDTRY;
01014
01015 return TAO_IMR_Op::NORMAL;
01016 }
01017
01018 int
01019 TAO_IMR_Op_Register::run (void)
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
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
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 }
01100
01101
01102
01103
01104 void
01105 TAO_IMR_Op_List::display_server_information (const ImplementationRepository::ServerInformation &info)
01106 {
01107 if (this->verbose_server_information_)
01108 TAO_IMR_Op::display_server_information (info);
01109 else
01110 ACE_DEBUG ((LM_DEBUG, "<%s>\n", info.server.in ()));
01111 }