⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tao_imr_i.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// tao_imr_i.cpp,v 1.34 2003/11/10 17:45:16 michel_j Exp

#include "tao_imr_i.h"

#include "tao/Stub.h"
#include "tao/Profile.h"

#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_netdb.h"
#include "ace/OS_NS_strings.h"

// How many servers should we get at once?
const size_t IR_LIST_CHUNK = 10;

TAO_IMR_i::TAO_IMR_i (void)
  : imr_locator_ (ImplementationRepository::Locator::_nil ()),
    op_ (0)
{
  // Nothing
}

TAO_IMR_i::~TAO_IMR_i (void)
{
  delete this->op_;
}

int
TAO_IMR_i::run ()
{
  if (this->op_ == 0)
  {
    ACE_ERROR ((LM_ERROR, "Unknown operation"));
    return TAO_IMR_Op::UNKNOWN;
  }

  return this->op_->run ();
}

int
TAO_IMR_i::init (int argc, char **argv)
{
  this->argc_ = argc;
  this->argv_ = argv;

  const char *exception_message = "Null Message";

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Retrieve the ORB.
      this->orb_ = CORBA::ORB_init (this->argc_,
                                    this->argv_,
                                    "internet"
                                    ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Parse command line and verify parameters.
      if (this->parse_args () == -1)
        return -1;

      // Get the ImplRepo object
      CORBA::Object_var imr_locator =
        orb_->resolve_initial_references ("ImplRepoService"
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (imr_locator.in ()))
        {
          ACE_ERROR ((LM_ERROR,
                      "Unable to resolve the ImR Locator.\n"));
          ACE_OS::exit (-1);
        }

      exception_message = "While narrowing ImR Locator";

      this->imr_locator_ =
        ImplementationRepository::Locator::_narrow
            (imr_locator.in()
             ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      this->op_->set_imr_locator (this->imr_locator_.in ());
    }
  ACE_CATCHANY
    {
      ACE_ERROR ((LM_ERROR, "TAO_IMR_i::init - %s\n", exception_message));
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception");
      return -1;
    }
  ACE_ENDTRY;

  return 0;
}


// Go through and figure out which operation we should do.

int
TAO_IMR_i::parse_args (void)
{
  // Make sure one command was given
  if (this->argc_ < 2)
  {
    this->print_usage ();
    return -1;
  }

  this->op_ = TAO_IMR_Op::make_op (this->argv_[1]);

  // Check for unrecognized operation

  if (this->op_ == 0)
  {
    ACE_ERROR ((LM_ERROR, "ERROR: Unrecognized command: <%s>\n", this->argv_[1]));
    this->print_usage ();
    return -1;
  }

  // Adjust argc and argv so only the command specific args are passed
  return this->op_->parse (this->argc_ - 1, this->argv_ + 1);
}


// Print out information about all operations.

void
TAO_IMR_i::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] command [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where command is one of the following:\n"
                        "    activate  Activates a server through the IR\n"
                        "    add       Add an entry to the IR\n"
                        "    autostart Activates all AUTO_START servers\n"
                        "    ior       Creates a simplified IOR\n"
                        "    list      List the entries in the IR\n"
                        "    remove    Remove an entry from the IR\n"
                        "    shutdown  Shuts down a server through the IR\n"
                        "    update    Update an entry in the IR\n"
                        "  where [command-arguments] depend on the command\n"));
}


// Factory for operations

TAO_IMR_Op *
TAO_IMR_Op::make_op (const ACE_TCHAR *op_name)
{
  if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("activate")) == 0)
    return new TAO_IMR_Op_Activate ();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("add")) == 0)
    return new TAO_IMR_Op_Add ();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("autostart")) == 0)
    return new TAO_IMR_Op_Autostart();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("ior")) == 0)
    return new TAO_IMR_Op_IOR();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("list")) == 0)
    return new TAO_IMR_Op_List ();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("remove")) == 0)
    return new TAO_IMR_Op_Remove ();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("shutdown")) == 0)
    return new TAO_IMR_Op_Shutdown ();
  else if (ACE_OS::strcasecmp (op_name, ACE_TEXT ("update")) == 0)
    return new TAO_IMR_Op_Update ();

  return 0;
}


TAO_IMR_Op::~TAO_IMR_Op ()
{
  // Nothing
}

void
TAO_IMR_Op::set_imr_locator (ImplementationRepository::Locator_ptr imr_locator)
{
  this->imr_locator_ = imr_locator;
}

void
TAO_IMR_Op::display_server_information (const ImplementationRepository::ServerInformation &info)
{
  // Figure out what the activation string is.
  const char *act = "UNKNOWN STARTUP";
  if (info.startup.activation == ImplementationRepository::NORMAL)
    act = "NORMAL";
  else if (info.startup.activation == ImplementationRepository::MANUAL)
    act = "MANUAL";
  else if (info.startup.activation == ImplementationRepository::PER_CLIENT)
    act = "PER_CLIENT";
  else if (info.startup.activation == ImplementationRepository::AUTO_START)
    act = "AUTO_START";

  // Print out information
  ACE_DEBUG ((LM_DEBUG, "Server <%s>\n", info.server.in ()));
  ACE_DEBUG ((LM_DEBUG,
              "  Activator: %s\n"
              "  Command Line: %s\n"
              "  Working Directory: %s\n"
              "  Activation Mode: %s\n",
              info.startup.activator.in (),
              info.startup.command_line.in (),
              info.startup.working_directory.in (),
              act));
  for (CORBA::ULong i = 0; i < info.startup.environment.length (); ++i)
    ACE_DEBUG ((LM_DEBUG, "Environment Variable: %s=%s \n",
                info.startup.environment[i].name.in (),
                info.startup.environment[i].value.in ()));

  // @@ add logical server once implemented


  if (info.startup.activation == ImplementationRepository::PER_CLIENT)
    ACE_DEBUG ((LM_DEBUG, "  No running info available for PER_CLIENT mode\n"));
  else if (ACE_OS::strlen (info.location.in()) > 0)
    ACE_DEBUG ((LM_DEBUG,
                "  Running at endpoint: %s\n",
                info.location.in ()));
  else   // I am assuming that a blank location means currently not running.
    ACE_DEBUG ((LM_DEBUG,
                "  Not currently running\n"));
}


TAO_IMR_Op_Add::TAO_IMR_Op_Add (void)
  : activation_ (ImplementationRepository::NORMAL)
{
  // Nothing
}

TAO_IMR_Op_List::TAO_IMR_Op_List (void)
: verbose_server_information_ (0)
{
  // Nothing
}

TAO_IMR_Op_Update::TAO_IMR_Op_Update (void)
: set_command_line_ (0),
  set_working_dir_ (0),
  set_activation_ (0)
{
  // Nothing
}

void
TAO_IMR_Op_Activate::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Activates a server\n"
                        "\n"
                        "Usage: tao_imr [options] activate <name> [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where <name> is the POA name used by the server object\n"
                        "  where [command-arguments] can be\n"
                        "    -l            Activator name.\n"
                        "    -h            Displays this\n"));
}

int
TAO_IMR_Op_Activate::parse (int argc, ACE_TCHAR **argv)
{
  // Check for enough arguments (we need at least one for the server name)
  if (argc < 2)
    {
      this->print_usage ();
      return -1;
    }

  // Skip both the program name and the "activate" command
  ACE_Get_Opt get_opts (argc, argv, "l:h");

  this->server_name_ = argv[1];
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'l':
        this->activator_ = get_opts.optarg;
        break;
      case 'h':  // display help
      default:
        this->print_usage ();
        return -1;
      }

  // Success
  return 0;
}

void
TAO_IMR_Op_Add::setenv (ACE_TCHAR *opt)
{
   CORBA::ULong length = this->environment_vars_.length ();

   // Increase the length of the sequence
   this->environment_vars_.length (length + 1);
   ACE_CString tokens (opt);
   int index = tokens.find ("=");
   // Insert at position length since that is our new element
   this->environment_vars_ [length].name =
         CORBA::string_dup (tokens.substr (0, index).c_str ());
   this->environment_vars_ [length].value =
         CORBA::string_dup (tokens.substr (index + 1).c_str ());
}

void
TAO_IMR_Op_Add::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] add <name> [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where <name> is the POA name used by the server object\n"
                        "  where [command-arguments] can be\n"
                        "    -l            Activator name. Defaults to local hostname.\n"
                        "    -h            Displays this\n"
                        "    -c command    Startup command\n"
                        "    -w dir        Working directory\n"
                        "    -e vars       Set environment variables\n"
                        "    -a mode       Set activate mode (NORMAL|MANUAL|PER_CLIENT|AUTO_START)\n"));
}

int
TAO_IMR_Op_Add::parse (int argc, ACE_TCHAR **argv)
{
  // Check for enough arguments (we need at least one for the server name)
  if (argc < 2)
    {
      this->print_usage ();
      return -1;
    }

 // Skip both the program name and the "add" command
  ACE_Get_Opt get_opts (argc, argv, "hc:w:a:e:l:");

  this->server_name_ = argv[1];
  if (this->server_name_.length() == 0)
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Server name > must be at least one character long!\n"),-1);
  }
    
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'c':  // Command line arguments
        this->command_line_ = get_opts.opt_arg ();
        break;
      case 'e':  // set environment variables
        this->setenv( get_opts.opt_arg () ) ;
        break;
      case 'w':  // Working Directory
        this->working_dir_ = get_opts.opt_arg ();
        break;
      case 'a':  // Activation Mode
        if (ACE_OS::strcasecmp (get_opts.opt_arg (), "NORMAL") == 0)
          this->activation_ = ImplementationRepository::NORMAL;
        else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "MANUAL") == 0)
          this->activation_ = ImplementationRepository::MANUAL;
        else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "PER_CLIENT") == 0)
          this->activation_ = ImplementationRepository::PER_CLIENT;
        else if (ACE_OS::strcasecmp (get_opts.opt_arg (), "AUTO_START") == 0)
          this->activation_ = ImplementationRepository::AUTO_START;
        else
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Unknown Activation Mode <%s>!\n",
                             get_opts.opt_arg ()),
                            -1);
        break;
      case 'l': /// hostname of the activator
        this->activator_ = get_opts.optarg;
        break;
      case 'h':  // display help
      default:
        this->print_usage ();
        return -1;
      }

  // Success
  return 0;
}

void
TAO_IMR_Op_Autostart::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Usage: tao_imr [options] autostart [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where [command-arguments] can be\n"
                        "    -h            Displays this\n"));
}

int
TAO_IMR_Op_Autostart::parse (int argc, ACE_TCHAR **argv)
{
  // Skip the "autostart" command
  ACE_Get_Opt get_opts (argc, argv, "h");

  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'h':  // display help
      default:
        this->print_usage ();
        return -1;
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -