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

📄 cospropertyservice_i.cpp

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

      // Make the NamesIterator out of this TAO_PropertySet.
      TAO_PropertyNamesIterator *names_iterator;
      ACE_NEW (names_iterator, TAO_PropertyNamesIterator (*property_set));

      // Init the out parameter.

      // Get the Interface ptr.
      CosPropertyService::PropertyNamesIterator_ptr iterator_ptr =
        names_iterator->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      // POA stuff todo here, since we have <destroy> method in the
      // <NamesIterator> interface.
      // Give ownership of this servant to the POA.
      names_iterator->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      // Init the out parameter.
      rest = iterator_ptr;
    }
}

// Returns the value of a property in the PropertySet.


CORBA::Any *
TAO_PropertySet::get_property_value (const char *property_name
                                     ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosPropertyService::PropertyNotFound,
                   CosPropertyService::InvalidPropertyName))
{
  // Check the name's validity.
  if (property_name == 0)
    ACE_THROW_RETURN (CosPropertyService::InvalidPropertyName(),
                      0);

  // Get the value out of the hash table.

  CosProperty_Hash_Key hash_key (property_name);
  CosProperty_Hash_Value hash_value;

  if (this->hash_table_.find (hash_key, hash_value) != 0)
    ACE_THROW_RETURN (CosPropertyService::PropertyNotFound(),
                      0);

  // Return the any value got.
  CORBA::Any *any_ptr =0;
  ACE_NEW_RETURN (any_ptr,
                  CORBA::Any (hash_value.pvalue_),
                  0);
  return any_ptr;
}

// Returns the values of the properties listed in property_names. When
// the boolean return value is true, the Properties parameter contains
// valid values for all requested property names. If false, then all
// properties with a value of type tk_void may have failed due to
// <PropertyNotFound> or <InvalidPropertyName>.


CORBA::Boolean
TAO_PropertySet::get_properties (const CosPropertyService::PropertyNames &property_names,
                                 CosPropertyService::Properties_out nproperties
                                 ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Allocate memory for the out parameter.
  ACE_NEW_RETURN (nproperties,
                  CosPropertyService::Properties,
                  0);

  // Validate the length.
  CORBA::ULong n = property_names.length ();
  if (n == 0)
    return 0;

  // Set the length for the out parameter.
  nproperties->length (n);

  // Get values for all the names.

  CORBA::Any_ptr any_ptr = 0;
  CORBA::Boolean ret_val = 1;

  for (CORBA::ULong i = 0; i < n; i++)
    {
      any_ptr = get_property_value (property_names [i]
                                    ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);

      if (any_ptr != 0)
        {
          // Property is found.
          nproperties [i].property_name = property_names [i];
          nproperties [i].property_value = *any_ptr;
        }
      else
        {
          // Invalid name. Ret value is False.
          ret_val = 0;

          // Assign void type to this name in the out parameter.
          nproperties [i].property_name =
            property_names [i];

          // Make an any value with tk_void type.
          CORBA::Any any;
          any._tao_set_typecode (CORBA::_tc_void);
          nproperties [i].property_value = any;
        }
    }

  return ret_val;
}


void
TAO_PropertySet::get_all_properties (CORBA::ULong how_many,
                                     CosPropertyService::Properties_out nproperties,
                                     CosPropertyService::PropertiesIterator_out rest
                                     ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Allocate memory for the out parameter.
  ACE_NEW (nproperties,
           CosPropertyService::Properties);

  // Validate the length.
  CORBA::ULong num_of_properties =
          this->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  if (num_of_properties == 0)
    return;

  // Set the length for the nproperties if how_many > 0.
  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;

      nproperties->length (sequence_length);
    }

  // Prepare an iterator and iterate through the PropertySet. Retrive
  // the values.

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

  for (CORBA::ULong i = 0;
       i < sequence_length;
       i++, iterator.advance ())
    if (iterator.next (entry_ptr) != 0)
      {
        nproperties[i].property_name =
          CORBA::string_dup (entry_ptr->ext_id_.pname_.in ());
        nproperties[i].property_value =
          entry_ptr->int_id_.pvalue_;
      }

  // If there are more properties, put them in the <PropertiesIterator>.
  // Make a new <TAO_PropertySet> and use that to create an Properties
  // iterator.  put that in a iterator and assign that to the out
  // paramerter.

  if (num_of_properties > how_many)
    {
      TAO_PropertySet *prop_set;

      ACE_NEW (prop_set, TAO_PropertySet);

      for (CORBA::ULong i = sequence_length;
           i < num_of_properties;
           i++, iterator.advance ())
        {
          if (iterator.next (entry_ptr) != 0
              && prop_set->hash_table_.bind (entry_ptr->ext_id_,
                                             entry_ptr->int_id_) < 0)
            ACE_DEBUG ((LM_DEBUG,
                        "Error:TAO_PropertySet::get_all_properties\n"));
        }

      // Make the iterator out of the new TAO_Propset.
      TAO_PropertiesIterator *iterator = 0;
      ACE_NEW (iterator,
               TAO_PropertiesIterator (*prop_set));

      // Init the out parameter.

      // Get the interface ptr.
      CosPropertyService::PropertiesIterator_ptr iterator_ptr =
        iterator->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      // POA stuff todo here, since we have <destroy> method in the
      // <NamesIterator> interface.
      // Give ownership of this servant to the POA.
      iterator->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      // Init the out parameter.
      rest = iterator_ptr;
    }
}

// Deletes the specified property if it exists from a PropertySet.


void
TAO_PropertySet::delete_property (const char *property_name
                                  ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosPropertyService::PropertyNotFound,
                   CosPropertyService::InvalidPropertyName,
                   CosPropertyService::FixedProperty))
{
  // Check the name's validity.
  if (property_name == 0)
    ACE_THROW (CosPropertyService::InvalidPropertyName());

  // Get the entry from the Hash Table.

  CosProperty_Hash_Key hash_key (property_name);
  COSPROPERTY_HASH_ENTRY *entry_ptr = 0;

  if (this->hash_table_.find (hash_key,
                              entry_ptr) == -1)
    ACE_THROW (CosPropertyService::PropertyNotFound());

  // If property is fixed, then raise exception.
  if ((entry_ptr->int_id_.pmode_ == CosPropertyService::fixed_normal)
      || (entry_ptr->int_id_.pmode_ == CosPropertyService::fixed_readonly))
    ACE_THROW (CosPropertyService::FixedProperty());

  // Unbind this property.
  if (this->hash_table_.unbind (entry_ptr) != 0)
    {
      ACE_THROW (CORBA::UNKNOWN ());
    }

  return;
}

// Deletes the properties defined in the property_names
// parameter. This is a batch operation that returns the
// MultipleExceptions exception if any delete failed.


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

  // Declare multiple exceptions' object.
  CosPropertyService::MultipleExceptions *multi_ex = 0;
  ACE_NEW (multi_ex,
           CosPropertyService::MultipleExceptions);

  for (CORBA::ULong pi = 0; pi < sequence_length; pi++)
    {
      ACE_TRY
        {
          // Delete this property.
          this->delete_property (property_names[pi]
                                 ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }
      ACE_CATCH (CosPropertyService::InvalidPropertyName, ex)
        {
          // Put this exception in the multiple exception.
          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 =
            property_names[pi];
        }
      ACE_CATCH (CosPropertyService::PropertyNotFound, ex)
        {
          // Put this exception in the multiple exception.
          CORBA::ULong len = multi_ex->exceptions.length ();
          multi_ex->exceptions.length (len + 1);
          multi_ex->exceptions[len].reason =
            CosPropertyService::property_not_found;
          multi_ex->exceptions[len].failing_property_name =
            property_names[pi];
        }
      ACE_CATCH (CosPropertyService::FixedProperty, ex)
        {
          // Put this exception in the multiple exception.
          CORBA::ULong len = multi_ex->exceptions.length ();
          multi_ex->exceptions.length (len + 1);
          multi_ex->exceptions[len].reason =
            CosPropertyService::fixed_property;
          multi_ex->exceptions[len].failing_property_name =
            property_names[pi];
        }
      ACE_CATCH (CORBA::SystemException, sysex)
        {
          // We cant afford to get this. Throw this.
          ACE_RE_THROW;
        }
      ACE_ENDTRY;
      ACE_CHECK;
    }

  // Raise the multiple exceptions if there are any.
  if (multi_ex->exceptions.length () > 0)
    ACE_THROW (CosPropertyService::MultipleExceptions (*multi_ex));
}

// Delete all the properties in the current ProperySet : Delete the
// properties one by one.


CORBA::Boolean
TAO_PropertySet::delete_all_properties (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // Get all the property names in a names' sequence.
  CosPropertyService::PropertyNames *names_ptr = 0;
  CosPropertyService::PropertyNames_out names_out (names_ptr);
  CosPropertyService::PropertyNames_var names;

  CosPropertyService::PropertyNamesIterator *iter_ptr = 0;
  CosPropertyService::PropertyNamesIterator_out iter_out (iter_ptr);
  CosPropertyService::PropertyNamesIterator_var iter;

  CORBA::ULong size = this->get_number_of_properties (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  this->get_all_property_names (size,
                                names_out,
                                iter_out
                                ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  // Get the out values on to the var varibles.
  names = names_out.ptr ();
  iter = iter_out.ptr ();

  // Delete all these properties.
  this->delete_properties (names.in ()
                           ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  // All properties deleted.
  return 1;
}

// Returns TRUE if the property is defined in the PropertySet.


CORBA::Boolean
TAO_PropertySet::is_property_defined (const char *property_name
                                      ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CosPropertyService::InvalidPropertyName))
{
  CosProperty_Hash_Key hash_key (property_name);

  if (this->hash_table_.find (hash_key) == 0)
    return 1;
  else
    return 0;
}


void
TAO_PropertySet::operator= (const TAO_PropertySet &)

⌨️ 快捷键说明

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