diff options
author | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-11-27 01:24:50 +0000 |
---|---|---|
committer | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-11-27 01:24:50 +0000 |
commit | f0f5433b7acac9169d04a04b8c6beb0a827e1c13 (patch) | |
tree | 8ef492a81fa11b185ffe0f7b9abf2e2a136fad41 | |
parent | 46ed4a24ffd1e87bb6d1d1c53dcf7e22d87088e0 (diff) | |
download | ATCD-f0f5433b7acac9169d04a04b8c6beb0a827e1c13.tar.gz |
ChangeLogTag: Wed Nov 26 19:20:54 2003 Dale Wilson <wilson_d@ociweb.com>
9 files changed, 488 insertions, 45 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 58b1d362611..4a83e6604fa 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,24 @@ +Wed Nov 26 19:20:54 2003 Dale Wilson <wilson_d@ociweb.com> + + * orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h: + * orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.cpp: + Enhance Properties_Decoder to provide everything necessary + to implement the PropertyManager interface. + --the name is no longer ideal. + + * orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.h: + * orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.cpp: + New: a collection of Properties_Decoders + + * orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h: + * orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp: + Use the new, improved Properties_Decoder to implement PropertyManager + + * orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h: + * orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.cpp: + Manage object group's properties via Properties_Decoder + + Wed Nov 26 15:31:47 2003 Dale Wilson <wilson_d@ociweb.com> * orbsvcs/orbsvcs/CosEvent/CEC_TypedConsumerAdmin.cpp: diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp index 453f28c4a71..53b3d962e6e 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp @@ -534,6 +534,11 @@ TAO::FT_ReplicationManager::set_default_properties ( { this->property_manager_.set_default_properties (props ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // Alternative implementation + this->default_properties_.decode(props); + //@@ validate properties? } PortableGroup::Properties * @@ -541,9 +546,17 @@ TAO::FT_ReplicationManager::get_default_properties ( ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ( (CORBA::SystemException)) { +#if 0 return this->property_manager_.get_default_properties ( ACE_ENV_SINGLE_ARG_PARAMETER); +#else + PortableGroup::Properties_var result; + ACE_NEW_THROW_EX ( result, PortableGroup::Properties(), CORBA::NO_MEMORY()); + this->default_properties_.export_properties (*result ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (PortableGroup::Properties::_nil()); + return result._retn (); +#endif } void @@ -556,6 +569,9 @@ TAO::FT_ReplicationManager::remove_default_properties ( { this->property_manager_.remove_default_properties (props ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->default_properties_.remove (props ACE_ENV_ARG_PARAMETER); } void @@ -570,6 +586,21 @@ TAO::FT_ReplicationManager::set_type_properties ( this->property_manager_.set_type_properties (type_id, overrides ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + + TAO_PG::Properties_Decoder * typeid_properties; + if ( 0 != this->typeid_properties_map_.find (type_id, typeid_properties)) + { + ACE_NEW_THROW_EX ( + typeid_properties, + TAO_PG::Properties_Decoder (overrides, & this->default_properties_), + CORBA::NO_MEMORY()); + this->typeid_properties_map_.bind (type_id, typeid_properties); + } + typeid_properties->clear (); + typeid_properties->decode (overrides ACE_ENV_ARG_PARAMETER); + ACE_CHECK; } PortableGroup::Properties * @@ -578,9 +609,22 @@ TAO::FT_ReplicationManager::get_type_properties ( ACE_ENV_ARG_DECL) ACE_THROW_SPEC ( (CORBA::SystemException)) { +#if 0 return this->property_manager_.get_type_properties (type_id ACE_ENV_ARG_PARAMETER); +#else + PortableGroup::Properties_var result; + ACE_NEW_THROW_EX (result, PortableGroup::Properties(), CORBA::NO_MEMORY ()); + + TAO_PG::Properties_Decoder * typeid_properties; + if ( 0 != this->typeid_properties_map_.find (type_id, typeid_properties)) + { + typeid_properties->export_properties (*result ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + return result._retn (); +#endif } void @@ -595,6 +639,13 @@ TAO::FT_ReplicationManager::remove_type_properties ( this->property_manager_.remove_type_properties (type_id, props ACE_ENV_ARG_PARAMETER); + + TAO_PG::Properties_Decoder * typeid_properties; + if ( 0 != this->typeid_properties_map_.find (type_id, typeid_properties)) + { + typeid_properties->remove (props ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } } void @@ -610,6 +661,17 @@ TAO::FT_ReplicationManager::set_properties_dynamically ( this->property_manager_.set_properties_dynamically (object_group, overrides ACE_ENV_ARG_PARAMETER); + + TAO::PG_Object_Group * group = 0; + if (this->object_group_map_.find_group (object_group, group)) + { + group->set_properties_dynamically (overrides ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + else + { + ACE_THROW (PortableGroup::ObjectGroupNotFound ()); + } } PortableGroup::Properties * @@ -619,9 +681,26 @@ TAO::FT_ReplicationManager::get_properties ( ACE_THROW_SPEC ( (CORBA::SystemException, PortableGroup::ObjectGroupNotFound)) { +#if 0 return this->property_manager_.get_properties (object_group ACE_ENV_ARG_PARAMETER); +#else + PortableGroup::Properties_var result; + ACE_NEW_THROW_EX (result, PortableGroup::Properties(), CORBA::NO_MEMORY ()); + + TAO::PG_Object_Group * group = 0; + if (this->object_group_map_.find_group (object_group, group)) + { + group->get_properties (result ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + else + { + ACE_THROW (PortableGroup::ObjectGroupNotFound ()); + } + return result._retn(); +#endif } @@ -690,7 +769,7 @@ TAO::FT_ReplicationManager::create_member ( the_criteria ACE_ENV_ARG_PARAMETER); - int todo; +//@@ int todo; } @@ -893,12 +972,24 @@ TAO::FT_ReplicationManager::create_object ( // then create the corresponding // entry in our object group map + // first find the properties for this type of object group + TAO_PG::Properties_Decoder * typeid_properties; + if ( 0 != this->typeid_properties_map_.find (type_id, typeid_properties)) + { + ACE_NEW_THROW_EX ( + typeid_properties, + TAO_PG::Properties_Decoder (& this->default_properties_), + CORBA::NO_MEMORY()); + this->typeid_properties_map_.bind (type_id, typeid_properties); + } + TAO::PG_Object_Group * objectGroup = TAO::PG_Object_Group::create ( this->orb_.in (), obj.in (), type_id, - the_criteria + the_criteria, + typeid_properties ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::Object::_nil ()); @@ -942,6 +1033,6 @@ TAO::FT_ReplicationManager::delete_object ( this->generic_factory_.delete_object (factory_creation_id ACE_ENV_ARG_PARAMETER); - int todo; +//@@ int todo; ACE_CHECK; } diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h index 5bacbeb504b..3b69261425e 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h @@ -27,9 +27,12 @@ #include <orbsvcs/PortableGroup/PG_GenericFactory.h> #include <orbsvcs/PortableGroup/PG_ObjectGroupManager.h> #include <orbsvcs/PortableGroup/PG_FactoryRegistry.h> -#include <orbsvcs/PortableGroup/PG_Object_Group_Map.h> #include <orbsvcs/FT_ReplicationManager/FT_FaultConsumer.h> +// Note: the new, improved versions... +#include <orbsvcs/PortableGroup/PG_Object_Group_Map.h> +#include <orbsvcs/PortableGroup/PG_Typeid_Properties_Map.h> + namespace TAO { /** @@ -468,6 +471,10 @@ namespace TAO /// A container for our object group information TAO::PG_Object_Group_Map object_group_map_; + TAO_PG::Properties_Decoder default_properties_; + + TAO::PG_Typeid_Properties_Map typeid_properties_map_; + /// The fault notifier. FT::FaultNotifier_var fault_notifier_; diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.cpp index c0878c3568a..34405e45a09 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.cpp +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.cpp @@ -63,7 +63,8 @@ TAO::PG_Object_Group::PG_Object_Group ( CORBA::Object_ptr empty_group, const PortableGroup::TagGroupTaggedComponent & tagged_component, const char * type_id, - PortableGroup::Criteria the_criteria) + PortableGroup::Criteria the_criteria, + TAO_PG::Properties_Decoder * type_properties) : internals_() , orb_ (CORBA::ORB::_duplicate (orb)) , iorm_ (TAO_IOP::TAO_IOR_Manipulation::_duplicate(iorm)) @@ -73,7 +74,7 @@ TAO::PG_Object_Group::PG_Object_Group ( , reference_ (CORBA::Object::_duplicate(empty_group)) // MemberMap members_ self initialized , primary_location_(0) - , properties_ (the_criteria) + , properties_ (the_criteria, type_properties) , membership_style_ (0) , initial_number_members_ (0) , minimum_number_members_ (0) @@ -86,7 +87,8 @@ TAO::PG_Object_Group * TAO::PG_Object_Group::create ( CORBA::ORB_ptr orb, CORBA::Object_ptr empty_group, // empty group as created by ObjectManager const char * type_id, - PortableGroup::Criteria the_criteria + PortableGroup::Criteria the_criteria, + TAO_PG::Properties_Decoder * type_properties ACE_ENV_ARG_DECL) { //@@ Might be worthwhile making iorm_ static @@ -130,7 +132,9 @@ TAO::PG_Object_Group * TAO::PG_Object_Group::create ( empty_group, tagged_component, type_id, - the_criteria), + the_criteria, + type_properties + ), CORBA::NO_MEMORY()); return objectGroup; } @@ -148,7 +152,7 @@ TAO::PG_Object_Group::~PG_Object_Group () } } - +#if 0 // may want this again someday ///////////////////// // q&d debug function static void dump_ior (const char * base, const char * ext, unsigned long version, const char * iogr) @@ -160,7 +164,7 @@ static void dump_ior (const char * base, const char * ext, unsigned long version ACE_OS::fwrite (iogr, 1, ACE_OS::strlen(iogr), iorfile); ACE_OS::fclose (iorfile); } - +#endif // may want this again someday PortableGroup::ObjectGroup_ptr TAO::PG_Object_Group::reference()const { @@ -462,16 +466,17 @@ void TAO::PG_Object_Group::set_properties_dynamically ( PortableGroup::UnsupportedProperty)) { InternalGuard guard(this->internals_); - this->properties_ = overrides; + this->properties_.decode (overrides ACE_ENV_ARG_PARAMETER); //@@ int todo_parse_properties_for_special_value; //@@ int todo_override_rather_than_replace_question; } -void TAO::PG_Object_Group::get_properties (PortableGroup::Properties_var & result) const +void TAO::PG_Object_Group::get_properties (PortableGroup::Properties_var & result ACE_ENV_ARG_DECL) const + ACE_THROW_SPEC ((CORBA::SystemException)) { // const cast to simulate mutable InternalGuard guard(ACE_const_cast (TAO::PG_Object_Group *, this)->internals_); - (*result) = this->properties_; + this->properties_.export_properties(*result ACE_ENV_ARG_PARAMETER); } diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h index 4f72e158b4d..c4398017cd5 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Object_Group.h @@ -24,6 +24,8 @@ #pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "PG_Properties_Decoder.h" + ////////////////////////////////// // Classes declared in this header namespace TAO @@ -112,7 +114,8 @@ namespace TAO CORBA::Object_ptr empty_group, const PortableGroup::TagGroupTaggedComponent & tag_component, const char * type_id, - PortableGroup::Criteria the_criteria); + PortableGroup::Criteria the_criteria, + TAO_PG::Properties_Decoder * type_properties); public: /** @@ -122,7 +125,8 @@ namespace TAO CORBA::ORB_ptr orb, CORBA::Object_ptr empty_group, // empty group as created by ObjectManager const char * type_id, - PortableGroup::Criteria the_criteria + PortableGroup::Criteria the_criteria, + TAO_PG::Properties_Decoder * type_properties ACE_ENV_ARG_DECL); /// Destructor @@ -177,7 +181,8 @@ namespace TAO PortableGroup::InvalidProperty, PortableGroup::UnsupportedProperty)); - void get_properties (PortableGroup::Properties_var & result) const; + void get_properties (PortableGroup::Properties_var & result) const + ACE_THROW_SPEC ((CORBA::SystemException)); PortableGroup::ObjectGroupId get_object_group_id () const; @@ -304,8 +309,7 @@ namespace TAO // Miscellaneous properties passed to create_object when this group // was initially created. To be used to create new members. - PortableGroup::Properties properties_; - + TAO_PG::Properties_Decoder properties_; // Cached property information diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.cpp index faad8d41c8d..59663d60ef8 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.cpp +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.cpp @@ -15,38 +15,186 @@ ////////////////////// // Properties_Decoder + +TAO_PG::Properties_Decoder::Properties_Decoder() + : defaults_ (0) +{ +} + + TAO_PG::Properties_Decoder::Properties_Decoder (const PortableGroup::Properties & property_set) + : defaults_ (0) { - size_t count = property_set.length(); + this->decode (property_set); + // @@ do something about the no-memory exception +} + +TAO_PG::Properties_Decoder::Properties_Decoder ( + const PortableGroup::Properties & property_set, + Properties_Decoder * defaults) + : defaults_ (defaults) +{ + this->decode (property_set); + // @@ do something about the no-memory exception +} + + +TAO_PG::Properties_Decoder::Properties_Decoder ( + Properties_Decoder * defaults) + : defaults_ (defaults) +{ +} + + + +TAO_PG::Properties_Decoder::~Properties_Decoder () +{ + this->clear (); +} + +void TAO_PG::Properties_Decoder::decode (const PortableGroup::Properties & property_set ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) + +{ + size_t count = property_set.length (); for (size_t nItem = 0; nItem < count; ++nItem) { const PortableGroup::Property & property = property_set[nItem]; const CosNaming::Name & nsName = property.nam; // note assumption one level name with no kind - // TODO: fix this + // @@ TODO: fix this const CosNaming::NameComponent & nc = nsName[0]; ACE_CString name = ACE_static_cast (const char *, nc.id); - if (0 != values_.bind(name, & property.val)) + + PortableGroup::Value * value_copy; + ACE_NEW_THROW_EX (value_copy, PortableGroup::Value (property.val), CORBA::NO_MEMORY ()); + PortableGroup::Value * replaced_value; + if (0 == this->values_.rebind (name, value_copy, replaced_value)) { - ACE_ERROR ((LM_ERROR, - "%n\n%T: Property_set: bind failed.\n" - )); + if (0 != replaced_value) + { + delete replaced_value; + } + } + else + { + if (TAO_debug_level > 3) + { + ACE_ERROR ( (LM_ERROR, + "%n\n%T: Property_set: rebind failed.\n" + )); + } + // @@ should throw something here + ACE_THROW (CORBA::NO_MEMORY ()); } } } -TAO_PG::Properties_Decoder::~Properties_Decoder () +void TAO_PG::Properties_Decoder::clear () +{ + for (ValueMapIterator it = this->values_.begin (); + it != this->values_.end (); + ++it) + { + ACE_TRY_NEW_ENV + { + delete (*it).int_id_; + } + ACE_CATCHANY + { + // ignore this (we might log it?) + } + ACE_ENDTRY; + } + this->values_.unbind_all (); +} + +void TAO_PG::Properties_Decoder::remove (const PortableGroup::Properties & property_set) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + size_t count = property_set.length (); + for (size_t nItem = 0; nItem < count; ++nItem) + { + const PortableGroup::Property & property = property_set[nItem]; + const CosNaming::Name & nsName = property.nam; + // note assumption one level name with no kind + // @@ TODO: fix this + const CosNaming::NameComponent & nc = nsName[0]; + ACE_CString name = ACE_static_cast (const char *, nc.id); + + PortableGroup::Value * deleted_value; + if ( 0 == this->values_.unbind (name, deleted_value)) + { + delete deleted_value; + } + else + { + // don't worry about it. + } + } +} + + + +void TAO_PG::Properties_Decoder::export_properties(PortableGroup::Properties & property_set) const { + ValueMap merged_values; + this->merge_properties (merged_values); + + property_set.length (merged_values.current_size ()); + + size_t pos = 0; + // note AFICT ACE_Hash_Map does not support const iterators, hence the const cast. + ValueMap & mutable_values = ACE_const_cast (ValueMap &, this->values_); + for (ValueMapIterator it = mutable_values.begin (); + it != mutable_values.end (); + ++it) + { + const ACE_CString & name = (*it).ext_id_; + const PortableGroup::Value * value = (*it).int_id_; + + PortableGroup::Property & property = property_set[pos]; + CosNaming::Name & nsName = property.nam; + //@@ note assumption: single level name, no kind + nsName.length(1); + CosNaming::NameComponent & nc = nsName[0]; + nc.id = CORBA::string_dup (name.c_str ()); + PortableGroup::Value & val = property.val; + val = *value; // NOTE: Any assignment does a deep copy + ++pos; + } + ACE_ASSERT (pos == property_set.length ()); +} + +void TAO_PG::Properties_Decoder::merge_properties (ValueMap & merged_values) const +{ + if (0 != this->defaults_) + { + this->defaults_->merge_properties (merged_values); + } + // note AFICT ACE_Hash_Map does not support const iterators, hence the const cast. + ValueMap & mutable_values = ACE_const_cast (ValueMap &, this->values_); + for (ValueMapIterator it = mutable_values.begin (); + it != mutable_values.end (); + ++it) + { + merged_values.rebind ( (*it).ext_id_, (*it).int_id_); + } } + + int TAO_PG::Properties_Decoder::find ( const ACE_CString & key, const PortableGroup::Value *& pValue) const { - int found = 0; - if (0 == values_.find(key, pValue)) + int found = (0 == this->values_.find (key, pValue)); + if (! found) { - found = 1; + if (0 != this->defaults_) + { + found = this->defaults_->find (key, pValue); + } } return found; } @@ -81,17 +229,17 @@ int TAO_PG::test_encode_decode () value <<= (CORBA::Double) testDouble; encoder.add (testDoubleKey, value); - encoder.encode(property_set); + encoder.encode (property_set); } - TAO_PG::Properties_Decoder decoder(property_set); + TAO_PG::Properties_Decoder decoder (property_set); CORBA::Long longResult = 0; if (find (decoder, testLongKey, longResult) ) { if (longResult != testLong) { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: %s = %d expecting %d\n", testLongKey, (int)longResult, @@ -102,7 +250,7 @@ int TAO_PG::test_encode_decode () } else { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: Can't find value for %s\n", testLongKey )); result = 0; @@ -111,9 +259,9 @@ int TAO_PG::test_encode_decode () const char * stringResult = ""; if (find (decoder, testStringKey, stringResult)) { - if(0 != ACE_OS::strcmp(testString, stringResult)) + if (0 != ACE_OS::strcmp (testString, stringResult)) { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: %s = \"%s\" expecting \"%s\"\n", testStringKey, (int)stringResult, @@ -124,7 +272,7 @@ int TAO_PG::test_encode_decode () } else { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: Can't find value for %s\n", testStringKey )); result = 0; @@ -134,9 +282,9 @@ int TAO_PG::test_encode_decode () CORBA::Double doubleResult = 0.0; if (find (decoder, testDoubleKey, doubleResult)) { - if(doubleResult != testDouble) + if (doubleResult != testDouble) { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: %s = \"%f\" expecting \"%f\"\n", testDoubleKey, doubleResult, @@ -147,7 +295,7 @@ int TAO_PG::test_encode_decode () } else { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ( (LM_ERROR, "%n\n%T: Can't find value for %s\n", testDoubleKey )); result = 0; @@ -162,9 +310,21 @@ int TAO_PG::test_encode_decode () ACE_CString, const PortableGroup::Value *, ACE_SYNCH_NULL_MUTEX>; + + typedef class ACE_Hash_Map_Iterator< + ACE_CString, + const PortableGroup::Value *, + ACE_SYNCH_NULL_MUTEX>; + #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + # pragma instantiate ACE_Hash_Map_Manager< ACE_CString, const PortableGroup::Value *, ACE_SYNCH_NULL_MUTEX> +#pragma instantiate ACE_Hash_Map_Iterator< + ACE_CString, + const PortableGroup::Value *, + ACE_SYNCH_NULL_MUTEX> + #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h index 78dcf3d78e9..6b4c1e4af3c 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h @@ -21,32 +21,117 @@ namespace TAO_PG { + + /** + * The Properties_Decoder captures the set of properties from a PortableGroup::Properties + * structure in a more usable format (a hash map), and provides methods for + * operating on these properties. + * + * It supports "chains" of property sets to implement default value semantics. + * If a requested property is not found in this set, the default set(s) are searched. + * Thus any property found at this level overrides the defaults. + */ + class TAO_PortableGroup_Export Properties_Decoder { typedef ACE_Hash_Map_Manager< ACE_CString, const PortableGroup::Value *, ACE_SYNCH_NULL_MUTEX> ValueMap; + typedef ACE_Hash_Map_Iterator< + ACE_CString, + const PortableGroup::Value *, + ACE_SYNCH_NULL_MUTEX> ValueMapIterator; + public: + + /** + * constructor: empty set with no defaults. + */ + Properties_Decoder(); + + /** + * constructor + * @param property_set the properties to be decoded + */ Properties_Decoder (const PortableGroup::Properties & property_set); + + /** + * constructor with defaults + * @param property_set the properties to be decoded + * @param defaults a propert set decoder that supplies default values. + */ + Properties_Decoder (const PortableGroup::Properties & property_set, Properties_Decoder * defaults); + + /** + * constructor with defaults, but no properties (yet) + * (note this is not a copy constructor) + * @param defaults a propert set decoder that supplies default values. + */ + Properties_Decoder (Properties_Decoder * defaults); + + ~Properties_Decoder (); - // general purpose method + /** + * general purpose find. returns a pointer to an Any + * if templated methods were available: + * template <typename TYPE > + * int find (const ACE_CString & key, TYPE & value) const; + * instead, see global function below + * @param key the (simple) name of the property + * @param pValue an out parameter to receive a pointer to the Any containing the value + * @returns boolean true if found + */ int find (const ACE_CString & key, const PortableGroup::Value *& pValue)const; - // if templated methods were available: - // template <typename TYPE > - // int find (const ACE_CString & key, TYPE & value) const; - // instead, see global function below + + /** + * Decode additional properties + * Duplicate values replace previous values. + * @param property_set the properties to be decoded + */ + void decode (const PortableGroup::Properties & property_set) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * Clear properties + * Does not clear default properties. + */ + void clear (); + + void remove (const PortableGroup::Properties & property_set) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /** + * Export the properties to a PortableGroup::Properties + * + * This method is intended to be used to implement the PropertyManager::get_*_properties + * methods. If you want to access the properties for any purpose other than exporting + * them across a CORBA interface, it is much more efficient to use the find interface. + * + */ + void export_properties(PortableGroup::Properties & property_set) const; + + private: + /** + * populate a ValueMap with the properties known to this decoder + * including but overriding default values + */ + void merge_properties (ValueMap & merged_values) const; private: - Properties_Decoder(); Properties_Decoder(const Properties_Decoder & rhs); Properties_Decoder & operator = (const Properties_Decoder & rhs); private: ValueMap values_; - PortableGroup::Properties_var property_set_; + /** + * a parent to another property decoder that provides default values + * these can be chained indefinitely. + * @@ TODO: reference counted pointers would be a good idea here. + */ + Properties_Decoder * defaults_; }; #ifdef PG_PS_UNIT_TEST diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.cpp new file mode 100644 index 00000000000..a24a7169484 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.cpp @@ -0,0 +1,40 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file PG_Typeid_Properties_Map.cpp + * + * $Id$ + * + * This file implements classes to help manage PortableGroup::Properties + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= + +#include "PG_Typeid_Properties_Map.h" + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + + template class ACE_Hash_Map_Manager< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX>; + + template class ACE_Hash_Map_Iterator< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +# pragma instantiate ACE_Hash_Map_Manager< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX> + +# pragma instantiate ACE_Hash_Map_Iterator< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX> + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.h new file mode 100644 index 00000000000..1a9899bfd58 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Typeid_Properties_Map.h @@ -0,0 +1,30 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file PG_Typeid_Properties_Map.h + * + * $Id$ + * + * This file declares classes to help manage the PortableGroup::Properties + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= +#ifndef TAO_PG_TYPEID_PROPERTIES_MAP_H +#define TAO_PG_TYPEID_PROPERTIES_MAP_H + +#include "PG_Properties_Decoder.h" + +namespace TAO +{ + typedef ACE_Hash_Map_Manager< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX> PG_Typeid_Properties_Map; + typedef ACE_Hash_Map_Iterator< + ACE_CString, + const ::TAO_PG::Properties_Decoder *, + TAO_SYNCH_MUTEX> PG_Typeid_Properties_Map_Iterator; +} //namespace TAO_PG + +#endif // TAO_PG_TYPEID_PROPERTIES_MAP_H |