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

📄 tao_imr_i.cpp

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

  // Success
  return 0;
}

void
TAO_IMR_Op_IOR::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Creates an IOR for a server that is registered with the IMR and uses\n"
                        "the InterOperable Naming Service.  Please see the documentation for\n"
                        "more information on which server configurations work with this command.\n"
                        "\n"
                        "Usage: tao_imr [options] ior <name> [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where <name> is the POA name of the server\n"
                        "  where [command-arguments] can be\n"
                        "    -f filename   filename to output the IOR to\n"
                        "    -h            Displays this\n"));
}

int
TAO_IMR_Op_IOR::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 "ior" command
  ACE_Get_Opt get_opts (argc, argv, "hf:");

  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'f':  // File name
        this->filename_ = get_opts.opt_arg ();
        break;
      case 'h':  // display help
      default:
        this->print_usage();
        return -1;
      }

  int remaining_index = get_opts.opt_ind();
  if (get_opts.argc() - remaining_index > 1) {
    ACE_DEBUG((LM_DEBUG, "Error : Too many arguments.\n\n"));
    this->print_usage();
    return -1;
  }

  if (remaining_index < get_opts.argc()) {
    this->server_name_ = get_opts.argv()[remaining_index];
  }

  if (this->server_name_.length() == 0) 
  {
    ACE_DEBUG((LM_DEBUG, "Error : Missing server name.\n\n"));
    this->print_usage();
    return -1;
  }

  return 0;
}

void
TAO_IMR_Op_List::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Lists all or one of the servers in the Implementation Repository\n"
                        "\n"
                        "Usage: tao_imr [options] list [name] [command-arguments]\n"
                        "  where [options] are ORB options\n"
                        "  where [name] is the optional server name to search for\n"
                        "  where [command-arguments] can be\n"
                        "    -v            Verbose: Displays more info for each server when\n"
                        "                  displaying more than one server\n"
                        "    -h            Displays this\n"));
}

int
TAO_IMR_Op_List::parse (int argc, ACE_TCHAR **argv)
{
  int server_flag = 0;

  if (argc > 1 && argv[1][0] != '-')
    {
      this->server_name_ = argv[1];
      server_flag = 2; 
    }

  // Skip both the program name and the "list" command
  ACE_Get_Opt get_opts (argc, argv, "vh", server_flag);

  int c;

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

  // Success
  return 0;
}

void
TAO_IMR_Op_Remove::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Removes a server entry\n"
                        "\n"
                        "Usage: tao_imr [options] remove <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_Remove::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 "remove" 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': 
      default:
        this->print_usage ();
        return -1;
      }

  // Success
  return 0;
}

void
TAO_IMR_Op_Shutdown::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Shuts down a server\n"
                        "\n"
                        "Usage: tao_imr [options] shutdown <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_Shutdown::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 "shutdown" 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': 
      default:
        this->print_usage ();
        return -1;
      }

  // Success
  return 0;
}

void
TAO_IMR_Op_Update::setenv (ACE_TCHAR *opt)
{
   this->set_environment_vars_ = 1;
   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_Update::print_usage (void)
{
  ACE_ERROR ((LM_ERROR, "Updates a server entry\n"
                        "\n"
                        "Usage: tao_imr [options] update <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"
                        "    -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_Update::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 "update" command
  ACE_Get_Opt get_opts (argc, argv, "hc:w:a:e:l:");

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

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'c':  // Command line arguments
        this->set_command_line_ = 1;
        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->set_working_dir_ = 1;
        this->working_dir_ = get_opts.opt_arg ();
        break;
      case 'a':  // Activation Mode
        this->set_activation_ = 1;
        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':
        this->activator_ = get_opts.optarg;
        break;
      case 'h':  // display help
      default:
        this->print_usage ();
        return -1;
      }

  return 0;
}


// ============================================================================
// = Run methods


int
TAO_IMR_Op_Activate::run (void)
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      if (this->activator_.length() == 0)
        {
          this->imr_locator_->activate_server (this->server_name_.c_str ()
                                               ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
      else
        {
          this->imr_locator_->activate_server_in_activator (
                this->server_name_.c_str (),
                this->activator_.c_str ()
                ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
      ACE_DEBUG ((LM_DEBUG,
                  "Successfully Activated server <%s>\n",
                  this->server_name_.c_str ()));
    }
  ACE_CATCH (ImplementationRepository::CannotActivate, ex)
    {
      ACE_ERROR ((LM_ERROR, "Cannot activate server <%s>, reason: <%s>\n",
                            this->server_name_.c_str (),
                            ex.reason.in ()));
      return TAO_IMR_Op::CANNOT_ACTIVATE;
    }
  ACE_CATCH (ImplementationRepository::NotFound, ex)
    {
      ACE_ERROR ((LM_ERROR, "Could not find server <%s>!\n", this->server_name_.c_str ()));
      return TAO_IMR_Op::NOT_FOUND;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Activating Server");
      return TAO_IMR_Op::UNKNOWN;
    }
  ACE_ENDTRY;

  // Success
  return TAO_IMR_Op::NORMAL;
}

int
TAO_IMR_Op_Add::run (void)
{
  ImplementationRepository::StartupOptions startup_options;

  startup_options.command_line =
    CORBA::string_dup (this->command_line_.c_str ());
  startup_options.environment =
    this->environment_vars_;
  startup_options.working_directory =
    CORBA::string_dup (this->working_dir_.c_str ());
  startup_options.activation = this->activation_;

  if (this->activator_.length() != 0)
    {
      startup_options.activator = CORBA::string_dup (this->activator_.c_str ());
    }
  else
    {
      // else use the hostname on which tao_imr is run
      char host_name[MAXHOSTNAMELEN + 1];
      ACE_OS::hostname (host_name, MAXHOSTNAMELEN);
      startup_options.activator = CORBA::string_dup (host_name);
    }

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      this->imr_locator_->register_server (this->server_name_.c_str (), 
        startup_options ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG,
                  "Successfully registered server <%s>\n",
                  this->server_name_.c_str ()));
    }
  ACE_CATCH (ImplementationRepository::NotFound, ex)
    {
      ACE_ERROR ((LM_ERROR,
                  "Could not register server <%s>. Activator <%s> not found!\n",
                  this->server_name_.c_str (),
                  this->activator_.c_str()
                  ));
      return TAO_IMR_Op::ALREADY_REGISTERED;
    }
  ACE_CATCH (ImplementationRepository::AlreadyRegistered, ex)
    {
      ACE_ERROR ((LM_ERROR,
                  "Server <%s> already registered!\n",
                  this->server_name_.c_str ()));
      return TAO_IMR_Op::ALREADY_REGISTERED;
    }
  ACE_CATCH (CORBA::NO_PERMISSION, ex)
    {
      ACE_ERROR ((LM_ERROR, "No Permission: ImplRepo is in Locked mode\n"));
      return TAO_IMR_Op::NO_PERMISSION;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Adding server");
      return TAO_IMR_Op::UNKNOWN;
    }
  ACE_ENDTRY;

⌨️ 快捷键说明

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