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

📄 service_type_repository.cpp

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

#include "Service_Type_Repository.h"

#include "ace/Lock_Adapter_T.h"


ACE_RCSID (Trader,
           Service_Type_Repository,
           "Service_Type_Repository.cpp,v 1.49 2003/08/18 16:13:59 ossama Exp")


TAO_Service_Type_Repository::
TAO_Service_Type_Repository (ACE_Lock* lock)
  : lock_ (lock)
{
  this->incarnation_.low = 0;
  this->incarnation_.high = 0;

  // If a lock wasn't provided, let's assume the user doesn't want any
  // kind of lock at all.
  if (this->lock_ == 0)
    ACE_NEW (this->lock_,
             ACE_Lock_Adapter<ACE_Null_Mutex>);
}

TAO_Service_Type_Repository::~TAO_Service_Type_Repository (void)
{
  {
    // Make sure not to throw exceptions in destructors...
    ACE_WRITE_GUARD (ACE_Lock, ace_mon, *this->lock_);

    for (Service_Type_Map_Iterator service_map_iterator (this->type_map_);
         service_map_iterator.done () == 0;
         service_map_iterator++)
      {
        Type_Info *type_info = (*service_map_iterator).int_id_;
        delete type_info;
      }
  }

  delete this->lock_;
}

CosTradingRepos::ServiceTypeRepository::IncarnationNumber
TAO_Service_Type_Repository::incarnation (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
      ACE_THROW_SPEC ((CORBA::SystemException))
{
  CosTradingRepos::ServiceTypeRepository::IncarnationNumber inc_num;

  if (this->lock_->acquire_read () == -1)
    {
      inc_num = this->incarnation_;
      this->lock_->release ();
    }
  else
    {
      inc_num.high = 0;
      inc_num.low = 0;
    }

  return inc_num;
}


CosTradingRepos::ServiceTypeRepository::IncarnationNumber
TAO_Service_Type_Repository::
add_type (const char *name,
          const char *if_name,
          const CosTradingRepos::ServiceTypeRepository::PropStructSeq &props,
          const CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq &super_types
          ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosTrading::IllegalServiceType,
                   CosTradingRepos::ServiceTypeRepository::ServiceTypeExists,
                   CosTradingRepos::ServiceTypeRepository::InterfaceTypeMismatch,
                   CosTrading::IllegalPropertyName,
                   CosTrading::DuplicatePropertyName,
                   CosTradingRepos::ServiceTypeRepository::ValueTypeRedefinition,
                   CosTrading::UnknownServiceType,
                   CosTradingRepos::ServiceTypeRepository::DuplicateServiceTypeName))
{
  Prop_Map prop_map;
  Service_Type_Map super_map;
  CosTradingRepos::ServiceTypeRepository::IncarnationNumber inc_num;

  inc_num.low = 0;
  inc_num.high = 0;

  // With exceptions enabled, inc_num isn't used.
  ACE_UNUSED_ARG (inc_num);

  ACE_WRITE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_, CORBA::INTERNAL ());
  ACE_CHECK_RETURN (inc_num);

  // Make sure Type name is valid.
  if (TAO_Trader_Base::is_valid_identifier_name (name) == 0)
    ACE_THROW_RETURN (CosTrading::IllegalServiceType (name),
                      this->incarnation_);

  // Check if the service type already exists.
  TAO_String_Hash_Key type_name (name);
  if (this->type_map_.find (type_name) == 0)
    ACE_THROW_RETURN (CosTradingRepos::ServiceTypeRepository::ServiceTypeExists (),
                      this->incarnation_);

  // Make sure all property names are valid and appear only once.
  this->validate_properties (prop_map,
                             props
                             ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (this->incarnation_);

  // Check that all super_types exist, and none are duplicated.
  this->validate_supertypes (super_map,
                             super_types
                             ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (this->incarnation_);

  // NOTE: I don't really know a way to do this without an Interface
  // Repository, since the Interface Repository IDs don't contain
  // information about supertypes.
  //
  // make sure interface name is legal.
  //  this->validate_interface (if_name, super_types ACE_ENV_ARG_PARAMETER);
  //  ACE_CHECK_RETURN (this->incarnation);
  //
  // Instead, we do this:
  //
  if (if_name == 0)
    ACE_THROW_RETURN (CosTradingRepos::ServiceTypeRepository::InterfaceTypeMismatch (),
                      this->incarnation_);

  // Collect and make sure that properties of all supertypes and this
  // type are compatible.  We can use prop_map and super_types_map for
  // the job.
  this->validate_inheritance (prop_map,
                              super_types
                              ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (this->incarnation_);

  // We can now use prop_map to construct a sequence of all properties
  // the this type.
  this->update_type_map (name,
                         if_name,
                         props,
                         super_types,
                         prop_map,
                         super_map);

  CosTradingRepos::ServiceTypeRepository::IncarnationNumber return_value =
    this->incarnation_;

  // Increment incarnation number.
  this->incarnation_.low++;

  // If we wrapped around in lows...
  if (this->incarnation_.low == 0)
    this->incarnation_.high++;

  return return_value;
}

void
TAO_Service_Type_Repository::remove_type (const char *name
                                          ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosTrading::IllegalServiceType,
                   CosTrading::UnknownServiceType,
                   CosTradingRepos::ServiceTypeRepository::HasSubTypes))
{
  if (TAO_Trader_Base::is_valid_identifier_name (name) == 0)
    ACE_THROW (CosTrading::IllegalServiceType (name));

  ACE_WRITE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_, CORBA::INTERNAL ());
  ACE_CHECK;

  // Check if the type exists.
  Service_Type_Map::ENTRY* type_entry = 0; ;
  if (this->type_map_.find (name,
                            type_entry) == -1)
    ACE_THROW (CosTrading::UnknownServiceType (name));

  // Check if it has any subtypes.
  Type_Info *type_info = type_entry->int_id_;
  if (type_info->has_subtypes_)
    ACE_THROW (CosTradingRepos::ServiceTypeRepository::HasSubTypes (name, ""));

  // Remove the type from the map.
  this->type_map_.unbind (type_entry);
  delete type_info;
}

CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq *
TAO_Service_Type_Repository::
list_types (const CosTradingRepos::ServiceTypeRepository::SpecifiedServiceTypes &which_types
            ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_READ_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_, CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  CORBA::ULong i = 0;
  CORBA::ULong length = ACE_static_cast (CORBA::ULong,
                                         this->type_map_.current_size ());
  CosTrading::ServiceTypeName *types =
    CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq::allocbuf (length);

  if (types == 0)
    return 0;

  int all = which_types._d () == CosTradingRepos::ServiceTypeRepository::all;

  CosTradingRepos::ServiceTypeRepository::IncarnationNumber num =
    which_types.incarnation ();

  for (Service_Type_Map_Iterator itr (this->type_map_);
       itr.done () == 0;
       itr++)
    {
      Type_Info* type_info = (*itr).int_id_;
      const char* type_name = (*itr).ext_id_.in ();

      if (all
          || num < type_info->type_struct_.incarnation)
        types[i++] = CORBA::string_dup (type_name);
    }

  CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq *tmp = 0;

  ACE_NEW_RETURN (tmp,
                  CosTradingRepos::ServiceTypeRepository::
                  ServiceTypeNameSeq (length,
                                      i,
                                      types,
                                      1),
                  0);
  return tmp;
}

CosTradingRepos::ServiceTypeRepository::TypeStruct *
TAO_Service_Type_Repository::
describe_type (const char * name
               ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosTrading::IllegalServiceType,
                   CosTrading::UnknownServiceType))
{
  if (TAO_Trader_Base::is_valid_identifier_name (name) == 0)
    ACE_THROW_RETURN
      (CosTrading::IllegalServiceType (name),
       (CosTradingRepos::ServiceTypeRepository::TypeStruct *) 0);

  ACE_READ_GUARD_THROW_EX
    (ACE_Lock,
     ace_mon,
     *this->lock_,
     CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  // Make sure the type exists.
  TAO_String_Hash_Key type_name (name);
  Service_Type_Map::ENTRY *type_entry = 0;
  if (this->type_map_.find (type_name,
                            type_entry) == -1)
    ACE_THROW_RETURN (CosTrading::UnknownServiceType (name),
                      (CosTradingRepos::ServiceTypeRepository::TypeStruct *) 0);

  // Return appropriate information about the type.
  CosTradingRepos::ServiceTypeRepository::TypeStruct *descr = 0;
  ACE_NEW_RETURN (descr,
                  CosTradingRepos::ServiceTypeRepository::TypeStruct,
                  0);
  CosTradingRepos::ServiceTypeRepository::TypeStruct &s =
    type_entry->int_id_->type_struct_;

  descr->if_name = s.if_name;
  descr->masked = s.masked;
  descr->incarnation = s.incarnation;
  descr->super_types = s.super_types;
  descr->props = s.props;
  /*
  CORBA::ULong length = s.props.length ();
  CosTradingRepos::ServiceTypeRepository::PropStruct* pstructs =
    s.props.get_buffer (0);
  descr->props.replace (length, length, pstructs, 0);
  */
  return descr;
}

CosTradingRepos::ServiceTypeRepository::TypeStruct *
TAO_Service_Type_Repository::
fully_describe_type (const char *name
                     ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosTrading::IllegalServiceType,
                   CosTrading::UnknownServiceType))
{
  if (TAO_Trader_Base::is_valid_identifier_name (name) == 0)
    ACE_THROW_RETURN (CosTrading::IllegalServiceType (name),
                      0);

  ACE_READ_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_, CORBA::INTERNAL ());
  ACE_CHECK_RETURN (0);

  // Make sure the type exists.
  TAO_String_Hash_Key type_name (name);
  Service_Type_Map::ENTRY *type_entry = 0;
  if (this->type_map_.find (type_name,
                            type_entry) == -1)
    ACE_THROW_RETURN (CosTrading::UnknownServiceType (name),
                      0);

  // Return appropriate information about the type.
  CosTradingRepos::ServiceTypeRepository::TypeStruct *descr = 0;
  ACE_NEW_RETURN (descr,
                  CosTradingRepos::ServiceTypeRepository::TypeStruct,
                  0);
  CosTradingRepos::ServiceTypeRepository::TypeStruct &s =
    type_entry->int_id_->type_struct_;

  // Aggregate the Properties of this type and all its supertypes.
  // Compute the transitive closure of all supertypes.
  this->fully_describe_type_i (s,
                               descr->props,
                               descr->super_types);

  // We do the explicit copy, since otherwise we'd have excessive
  // properties copying.
  descr->if_name = s.if_name;
  descr->masked = s.masked;
  descr->incarnation = s.incarnation;

  return descr;
}

void
TAO_Service_Type_Repository::
mask_type (const char *name
           ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosTrading::IllegalServiceType,
                   CosTrading::UnknownServiceType,
                   CosTradingRepos::ServiceTypeRepository::AlreadyMasked))
{
  if (TAO_Trader_Base::is_valid_identifier_name (name) == 0)
    ACE_THROW (CosTrading::IllegalServiceType (name));

  ACE_WRITE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_, CORBA::INTERNAL ());

  // Make sure the type exists.
  TAO_String_Hash_Key type_name (name);
  Service_Type_Map::ENTRY *type_entry = 0;
  if (this->type_map_.find (type_name,
                            type_entry) != -1)
    ACE_THROW (CosTrading::UnknownServiceType (name));

  // Make sure the type is unmasked.
  CORBA::Boolean &mask =
    type_entry->int_id_->type_struct_.masked;

  if (mask == 1)
    ACE_THROW (CosTradingRepos::ServiceTypeRepository::AlreadyMasked (name));

⌨️ 快捷键说明

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