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

📄 cospropertyservice_i.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                      ACE_ENV_ARG_DECL)
  : allowed_property_types_ (allowed_property_types),
    allowed_property_names_ (allowed_properties.length ())
{
  // Set the length for the sequence, just to make sure.
  this->allowed_property_names_.length (allowed_properties.length ());

  // Keep the allowed property names in the sequence..
  for (CORBA::ULong ni = 0;
       ni < allowed_properties.length ();
       ni++)
    this->allowed_property_names_[ni] =
      allowed_properties[ni].property_name;

  // Define the allowed properties in the hash table.
  ACE_TRY
    {
      this->define_properties (allowed_properties
                               ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "TAO_PropertySet-Constructor");
      ACE_RE_THROW;
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

// TAO_PropertySetDef's constructor needs this, for initializing the
// allowed properties' sequence withe just the maximum length.

TAO_PropertySet::TAO_PropertySet (const CosPropertyService::PropertyTypes allowed_property_types,
                                      const CORBA::ULong number_of_allowed_properties
                                      ACE_ENV_ARG_DECL_NOT_USED)
  : allowed_property_types_ (allowed_property_types),
    allowed_property_names_ (number_of_allowed_properties)
{
}

// PropertySetFactory needs this constructor. Store all the initial
// properies with *normal* modes.


TAO_PropertySet::TAO_PropertySet (const CosPropertyService::Properties initial_properties
                                  ACE_ENV_ARG_DECL)
{
  // Define all the initial properties in the Property Set. All take
  // *normal* modes.
  ACE_TRY
    {
      this->define_properties (initial_properties
                               ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "TAO_PropertySet-Constructor");
      ACE_RE_THROW;
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

// Destructor. All sequences will be deleted.

TAO_PropertySet::~TAO_PropertySet (void)
{
}

// Function to modify or add a property to the PropertySet:
// Adds the name and the value to the set... Doesn't check for Typecode
// overwriting, duplicate names, void names etc, yet.
// @@ Uses Normal mode as the default mode of properties, We can
// change this behavior based on the Initial set of allowed modes, if
// there is anything like that set by the client.


void
TAO_PropertySet::define_property (const char *property_name,
                                  const CORBA::Any &property_value
                                  ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosPropertyService::InvalidPropertyName,
                   CosPropertyService::ConflictingProperty,
                   CosPropertyService::UnsupportedTypeCode,
                   CosPropertyService::UnsupportedProperty,
                   CosPropertyService::ReadOnlyProperty))
{
  // Check the name's validity.
  if (property_name == 0)
    ACE_THROW (CosPropertyService::InvalidPropertyName());

  CORBA::TypeCode_var arg_tc = property_value.type ();

  // Is this type allowed?
  if (is_type_allowed (arg_tc.in ()) != 1)
    ACE_THROW (CosPropertyService::UnsupportedTypeCode());

  // Is this property allowed?
  if (is_property_allowed (property_name) != 1)
    ACE_THROW (CosPropertyService::UnsupportedProperty());

  // Try to bind the property. Use normal mode.
  CosProperty_Hash_Key hash_key (property_name);
  CosProperty_Hash_Value hash_value (property_value,
                                     CosPropertyService::normal);
  COSPROPERTY_HASH_ENTRY *entry_ptr;
  //CosProperty_Hash_Key old_key;
  //CosProperty_Hash_Value old_value;

  int ret = this->hash_table_.bind (hash_key,
                                    hash_value,
                                    entry_ptr);

  CORBA::TypeCode_var mapped_tc;

  switch (ret)
    {
    case 0:
      break;
    case 1:
      // Property already exists.

      // Is the pointer valid?
      if (entry_ptr == 0)
        ACE_THROW (CORBA::UNKNOWN ());

      mapped_tc = entry_ptr->int_id_.pvalue_.type ();

      // If type is not the same, raise exception.
      if (! mapped_tc.in ()->equal (arg_tc.in ()))
        ACE_THROW (CosPropertyService::ConflictingProperty());

      // If mode is read only, raise exception.
      if ((entry_ptr->int_id_.pmode_ == CosPropertyService::read_only) ||
          (entry_ptr->int_id_.pmode_ == CosPropertyService::fixed_readonly))
        ACE_THROW (CosPropertyService::ReadOnlyProperty());

      // Use the mode that is already there.
      hash_value.pmode_ = entry_ptr->int_id_.pmode_;

      // Everything is fine. Overwrite the value.
      if (this->hash_table_.rebind (hash_key,
                                    hash_value) != 1)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "TAO_PropertySet::Define Property failed\n"));
          ACE_THROW (CORBA::UNKNOWN ());
        }
      break;
    default:
      // Error. ret is -1.
      ACE_THROW (CORBA::UNKNOWN ());
    }

  return;
}

// Tells whether this type is allowed in this property set or no.

CORBA::Boolean
TAO_PropertySet::is_type_allowed (CORBA::TypeCode_ptr type)
{
  ACE_DECLARE_NEW_CORBA_ENV;

  // If the sequence is empty, no constraints.
  if (this->allowed_property_types_.length () == 0)
    return 1;

  // Check in the allowed_property_types sequence.
  CORBA::Boolean ret_val = 0;
  for (CORBA::ULong ti = 0;
       ti < this->allowed_property_types_.length ();
       ti++)
    {
      ACE_TRY
        {
          ret_val = this->allowed_property_types_[ti]->equal (type
                                                              ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          if (ret_val == 1)
            return 1;
        }
      ACE_CATCHANY
        {
          ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                               "TAO_PropertySet::is_type_allowed failed");
          return ret_val;
        }
      ACE_ENDTRY;
      ACE_CHECK_RETURN (0);
    }

  // Type not found.
  return ret_val;
}

// Tells whether this property is allowed in this property or no.

CORBA::Boolean
TAO_PropertySet::is_property_allowed (const char* property_name)
{
  // If  the sequence is empty, no constraints.
  if (this->allowed_property_names_.length() == 0)
    return 1;

  // Check in the allowed_property_names.
  for (CORBA::ULong ni = 0;
       ni < this->allowed_property_names_.length ();
       ni++)
    if (ACE_OS::strcmp ((const char *) this->allowed_property_names_[ni],
                        property_name) == 0)
      return 1;

  // Name not found in the sequence.
  return 0;
}

// Defining a sequence of properties
//
// Check for overwriting, duplicate names, void names etc and raise
// appropriate exceptions.


void
TAO_PropertySet::define_properties (const CosPropertyService::Properties &nproperties
                                    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosPropertyService::MultipleExceptions))
{
  // Get the length.
  CORBA::ULong sequence_length = nproperties.length ();

  // Define multiple exceptions object.
  CosPropertyService::MultipleExceptions multi_ex;

  for (CORBA::ULong pi = 0; pi < sequence_length; pi++)
    {
      ACE_TRY
        {
          // Define this property.
          this->define_property (nproperties [pi].property_name.in (),
                                 nproperties [pi].property_value
                                 ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
      ACE_CATCH (CosPropertyService::InvalidPropertyName, ex)
        {
          CORBA::ULong len = multi_ex.exceptions.length ();
          multi_ex.exceptions.length (len + 1);
          multi_ex.exceptions[len].reason =
            CosPropertyService::invalid_property_name;
          multi_ex.exceptions[len].failing_property_name =
            nproperties[pi].property_name;
        }
      ACE_CATCH (CosPropertyService::ConflictingProperty, ex)
        {
          CORBA::ULong len = multi_ex.exceptions.length ();
          multi_ex.exceptions.length (len + 1);
          multi_ex.exceptions[len].reason =
            CosPropertyService::conflicting_property;
          multi_ex.exceptions[len].failing_property_name =
            nproperties[pi].property_name;
        }
      ACE_CATCH (CosPropertyService::ReadOnlyProperty, ex)
        {
          CORBA::ULong len = multi_ex.exceptions.length ();
          multi_ex.exceptions.length (len + 1);
          multi_ex.exceptions[len].reason =
            CosPropertyService::read_only_property;
          multi_ex.exceptions[len].failing_property_name =
            nproperties[pi].property_name;
        }
      ACE_CATCH (CosPropertyService::UnsupportedTypeCode, ex)
        {
          CORBA::ULong len = multi_ex.exceptions.length ();
          multi_ex.exceptions.length (len + 1);
          multi_ex.exceptions[len].reason =
            CosPropertyService::unsupported_type_code;
          multi_ex.exceptions[len].failing_property_name =
            nproperties[pi].property_name;
        }
      ACE_CATCH (CosPropertyService::UnsupportedProperty, ex)
         {
           CORBA::ULong len = multi_ex.exceptions.length ();
           multi_ex.exceptions.length (len + 1);
           multi_ex.exceptions[len].reason =
             CosPropertyService::unsupported_property;
           multi_ex.exceptions[len].failing_property_name =
             nproperties[pi].property_name;
         }
       ACE_CATCH (CORBA::SystemException, sysex)
         {
           ACE_RE_THROW;
         }
       ACE_ENDTRY;
       ACE_CHECK;
    }

  // Raise the multi exception if needed.
  if (multi_ex.exceptions.length () > 0)
    ACE_THROW (CosPropertyService::MultipleExceptions (multi_ex));
}

// Returns the current number of properties associated with this
// PropertySet.


CORBA::ULong
TAO_PropertySet::get_number_of_properties (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  return ACE_static_cast (CORBA::ULong, this->hash_table_.current_size ());
}

//  Returns all of the property names currently defined in the
//  PropertySet. If the PropertySet contains more than <how_many>
//  property names, then the remaining property names are put into the
//  PropertyNamesIterator.


void
TAO_PropertySet::get_all_property_names (CORBA::ULong how_many,
                                             CosPropertyService::PropertyNames_out property_names,
                                             CosPropertyService::PropertyNamesIterator_out rest
                                             ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Allocating storage is a must.
  ACE_NEW (property_names,
           CosPropertyService::PropertyNames);

  CORBA::ULong num_of_properties =
    this->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  if (num_of_properties == 0)
    // Nothing to do.
    return;

  // Set the length of the property_names appropriately.
  CORBA::ULong sequence_length = 0;

  if (how_many > 0)
    {
      if (how_many >= num_of_properties)
        sequence_length = num_of_properties;
      else
        sequence_length = how_many;
      property_names->length (sequence_length);
    }

  // Iterate thru names and put them in the property_names.

  COSPROPERTY_HASH_ENTRY *entry_ptr;
  COSPROPERTY_HASH_ITERATOR iterator (this->hash_table_);

  for (CORBA::ULong ni = 0;
       ni < sequence_length;
       ni++, iterator.advance ())
    if (iterator.next (entry_ptr) != 0)
      property_names [ni] =
        CORBA::string_dup (entry_ptr->ext_id_.pname_.in ());

  // If there are some more properties, put them in the
  // iterator. How?? Make a new PropertySet and use that to create
  // propertyNames Iterator.

  if (num_of_properties > how_many)
    {
      TAO_PropertySet *property_set;

      ACE_NEW (property_set, TAO_PropertySet);

      for (CORBA::ULong i = how_many;
           i < num_of_properties;
           i++, iterator.advance ())
        if (iterator.next (entry_ptr) != 0)
          if (property_set->hash_table_.bind (entry_ptr->ext_id_,
                                              entry_ptr->int_id_) < 0)

⌨️ 快捷键说明

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