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

📄 repository_i.cpp

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

  char *name = TAO_IFR_Service_Utils::int_to_string (count++);
  this->config_->set_integer_value (this->sequences_key_,
                                    "count",
                                    count);

  // Make new database entry.
  ACE_Configuration_Section_Key new_key;
  this->config_->open_section (this->sequences_key_,
                               name,
                               1,
                               new_key);

  // Set the bound attribute.
  this->config_->set_integer_value (new_key,
                                    "bound",
                                    bound);

  // Set the def_kind attribute.
  this->config_->set_integer_value (new_key,
                                    "def_kind",
                                    CORBA::dk_Sequence);

  // Set the "name" for destroy to use.
  this->config_->set_string_value (new_key,
                                   "name",
                                   name);

  char *element_path =
    TAO_IFR_Service_Utils::reference_to_path (element_type);

  // To get key to element type.
  this->config_->set_string_value (new_key,
                                   "element_path",
                                   element_path);

  // Create the object reference.
  ACE_TString obj_id ("sequences\\");
  obj_id += name;

  CORBA::Object_var obj =
    TAO_IFR_Service_Utils::create_objref (CORBA::dk_Sequence,
                                          obj_id.c_str (),
                                          this->repo_
                                          ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::SequenceDef::_nil ());

  return CORBA::SequenceDef::_narrow (obj.in ()
                                     ACE_ENV_ARG_PARAMETER);
}

CORBA::ArrayDef_ptr
TAO_Repository_i::create_array (CORBA::ULong length,
                                CORBA::IDLType_ptr element_type
                                ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  TAO_IFR_WRITE_GUARD_RETURN (CORBA::ArrayDef::_nil ());

  return this->create_array_i (length,
                               element_type
                               ACE_ENV_ARG_PARAMETER);
}

CORBA::ArrayDef_ptr
TAO_Repository_i::create_array_i (CORBA::ULong length,
                                  CORBA::IDLType_ptr element_type
                                  ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  u_int count = 0;
  this->config_->get_integer_value (this->arrays_key_,
                                    "count",
                                    count);

  char *name = TAO_IFR_Service_Utils::int_to_string (count++);
  this->config_->set_integer_value (this->arrays_key_,
                                    "count",
                                    count);

  // Make new database entry.
  ACE_Configuration_Section_Key new_key;
  this->config_->open_section (this->arrays_key_,
                               name,
                               1,
                               new_key);

  // Set the length attribute.
  this->config_->set_integer_value (new_key,
                                    "length",
                                    length);

  // Set the def_kind attribute.
  this->config_->set_integer_value (new_key,
                                    "def_kind",
                                    CORBA::dk_Array);

  // Set the "name" for destroy to use.
  this->config_->set_string_value (new_key,
                                   "name",
                                   name);

  char *element_path =
    TAO_IFR_Service_Utils::reference_to_path (element_type);

  // To get key to element type.
  this->config_->set_string_value (new_key,
                                   "element_path",
                                   element_path);

  // Create the object reference.
  ACE_TString obj_id ("arrays\\");
  obj_id += name;

  CORBA::Object_var obj =
    TAO_IFR_Service_Utils::create_objref (CORBA::dk_Array,
                                          obj_id.c_str (),
                                          this->repo_
                                          ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::ArrayDef::_nil ());

  return CORBA::ArrayDef::_narrow (obj.in ()
                                  ACE_ENV_ARG_PARAMETER);
}

CORBA::FixedDef_ptr
TAO_Repository_i::create_fixed (CORBA::UShort digits,
                                CORBA::Short scale
                                ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  TAO_IFR_WRITE_GUARD_RETURN (CORBA::FixedDef::_nil ());

  return this->create_fixed_i (digits,
                               scale
                               ACE_ENV_ARG_PARAMETER);
}

CORBA::FixedDef_ptr
TAO_Repository_i::create_fixed_i (CORBA::UShort /* digits */,
                                  CORBA::Short /* scale */
                                  ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), CORBA::FixedDef::_nil ());
}

int
TAO_Repository_i::repo_init (CORBA::Repository_ptr repo_ref,
                             PortableServer::POA_ptr repo_poa
                             ACE_ENV_ARG_DECL)
{
  this->repo_objref_ = repo_ref;
  this->repo_poa_ = repo_poa;

  // Create the appropriate lock.
  if (OPTIONS::instance ()->enable_locking ())
    {
      ACE_NEW_THROW_EX (this->lock_,
                        ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (),
                        CORBA::NO_MEMORY ());
    }
  else
    {
      ACE_NEW_THROW_EX (this->lock_,
                        ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
                        CORBA::NO_MEMORY ());
    }
  ACE_CHECK_RETURN (-1);

  // Resolve and narrow the TypeCodeFactory.
  CORBA::Object_var object =
    this->orb_->resolve_initial_references ("TypeCodeFactory"
                                            ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (!CORBA::is_nil (object.in ()))
    {
      this->tc_factory_ =
        CORBA::TypeCodeFactory::_narrow (object.in ()
                                         ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (-1);

      if (CORBA::is_nil (this->tc_factory_.in ()))
        ACE_ERROR_RETURN ((
            LM_ERROR,
            ACE_TEXT ("Repository: TypeCodeFactory narrow failed\n")
          ),
          -1
        );
    }
  else
    {
      ACE_ERROR_RETURN ((
          LM_ERROR,
          ACE_TEXT ("Repository: TypeCodeFactory resolve failed\n")
        ),
        -1
      );
    }

  // Resolve and narrow the POACurrent object.
  object =
    this->orb_->resolve_initial_references ("POACurrent"
                                            ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (!CORBA::is_nil (object.in ()))
    {
      this->poa_current_ =
        PortableServer::Current::_narrow (object.in ()
                                          ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (-1);

      if (CORBA::is_nil (this->poa_current_.in ()))
        ACE_ERROR_RETURN ((
            LM_ERROR,
            ACE_TEXT ("Repository: POACurrent narrow failed\n")
          ),
          -1
        );
    }
  else
    {
      ACE_ERROR_RETURN ((
          LM_ERROR,
          ACE_TEXT ("Repository: POACurrent resolve failed\n")
        ),
        -1
      );
    }

  if (this->create_sections () != 0)
    {
      return -1;
    }

  int status = this->create_servants_and_poas (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (status != 0)
    {
      return -1;
    }

  return 0;
}

int
TAO_Repository_i::create_sections (void)
{
  this->config_->open_section (config_->root_section (),
                               "root",
                               1, // Will create if IFR is not persistent.
                               this->root_key_);

  this->config_->open_section (this->root_key_,
                               "repo_ids",
                               1, // Will create if IFR is not persistent.
                               this->repo_ids_key_);

  int status =
    this->config_->open_section (this->root_key_,
                                 "pkinds",
                                 0, // Don't create
                                 this->pkinds_key_);

  if (status != 0)
    // IFR is non-persistent or is being run for the first time.
    // Must add entries for primitive kinds.
    {
      this->config_->open_section (this->root_key_,
                                   "pkinds",
                                   1, // It doesn't exist so create it.
                                   this->pkinds_key_);

      u_int num_pkinds = this->num_pkinds ();

      for (u_int i = 0; i < num_pkinds; ++i)
        {
          ACE_Configuration_Section_Key key;
          CORBA::PrimitiveKind pkind = ACE_static_cast (CORBA::PrimitiveKind,
                                                        i);

          this->config_->open_section (this->pkinds_key_,
                                       this->pkind_to_string (pkind),
                                       1,
                                       key);

          this->config_->set_integer_value (key,
                                            "def_kind",
                                            CORBA::dk_Primitive);

          this->config_->set_integer_value (key,
                                            "pkind",
                                            i);

        }
    }

  this->config_->open_section (this->root_key_,
                               "strings",
                               1,
                               this->strings_key_);

  this->config_->open_section (this->root_key_,
                               "wstrings",
                               1,
                               this->wstrings_key_);

  this->config_->open_section (this->root_key_,
                               "fixeds",
                               1,
                               this->fixeds_key_);

  this->config_->open_section (this->root_key_,
                               "arrays",
                               1,
                               this->arrays_key_);

  this->config_->open_section (this->root_key_,
                               "sequences",
                               1,
                               this->sequences_key_);

  u_int count = 0;

  // If repository is not persistent, we need to set all
  // the "count" fields to 0. We test just one for existence.
  status =
    this->config_->get_integer_value (this->strings_key_,
                                      "count",
                                      count);

  if (status == -1) // Field "count" does not exist.
    {
      this->config_->set_integer_value (this->strings_key_,
                                        "count",
                                        0);

      this->config_->set_integer_value (this->wstrings_key_,
                                        "count",
                                        0);

      this->config_->set_integer_value (this->fixeds_key_,
                                        "count",
                                        0);

      this->config_->set_integer_value (this->arrays_key_,
                                        "count",
                                        0);

      this->config_->set_integer_value (this->sequences_key_,
                                        "count",
                                        0);
    }

  // The following are done because we are also a Container.
  this->repo_ = this;
  this->section_key_ = this->root_key_;

  this->config_->set_string_value (this->section_key_,
                                   "absolute_name",
                                   "");

  this->config_->set_string_value (this->section_key_,
                                   "id",
                                   ""); // required by spec

  this->config_->set_string_value (this->section_key_,
                                   "name",
                                   "");

  this->config_->set_integer_value (this->section_key_,
                                    "def_kind",
                                    CORBA::dk_Repository);

  return 0;
}

⌨️ 快捷键说明

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