From ffaa5f192926b503aac1f141420e279b4b1d3bc9 Mon Sep 17 00:00:00 2001 From: parsons Date: Thu, 1 May 2003 02:35:22 +0000 Subject: ChangeLogTag: Wed Apr 30 21:33:08 2003 Jeff Parsons --- TAO/ChangeLog_ref | 41 ++++ TAO/tao/ORB.cpp | 64 +++-- TAO/tao/TAO.dsp | 36 --- TAO/tao/ValueBase.cpp | 352 --------------------------- TAO/tao/ValueBase.h | 265 -------------------- TAO/tao/ValueBase.i | 345 -------------------------- TAO/tao/ValueFactory.cpp | 23 -- TAO/tao/ValueFactory.h | 120 --------- TAO/tao/ValueFactory.i | 139 ----------- TAO/tao/ValueFactory_Map.cpp | 130 ---------- TAO/tao/ValueFactory_Map.h | 87 ------- TAO/tao/ValueFactory_Map.i | 1 - TAO/tao/Valuetype/AbstractBase.cpp | 4 +- TAO/tao/Valuetype/TAO_Valuetype.dsp | 36 +++ TAO/tao/Valuetype/ValueBase.cpp | 352 +++++++++++++++++++++++++++ TAO/tao/Valuetype/ValueBase.h | 270 ++++++++++++++++++++ TAO/tao/Valuetype/ValueBase.inl | 349 ++++++++++++++++++++++++++ TAO/tao/Valuetype/ValueFactory.cpp | 23 ++ TAO/tao/Valuetype/ValueFactory.h | 121 +++++++++ TAO/tao/Valuetype/ValueFactory.inl | 139 +++++++++++ TAO/tao/Valuetype/ValueFactory_Map.cpp | 130 ++++++++++ TAO/tao/Valuetype/ValueFactory_Map.h | 90 +++++++ TAO/tao/Valuetype/ValueFactory_Map.inl | 1 + TAO/tao/Valuetype/Valuetype_Adapter_Impl.cpp | 32 +++ TAO/tao/Valuetype/Valuetype_Adapter_Impl.h | 14 +- TAO/tao/Valuetype_Adapter.h | 17 +- TAO/tao/append.cpp | 19 +- TAO/tao/corba.h | 2 - TAO/tao/skip.cpp | 19 +- 29 files changed, 1697 insertions(+), 1524 deletions(-) delete mode 100644 TAO/tao/ValueBase.cpp delete mode 100644 TAO/tao/ValueBase.h delete mode 100644 TAO/tao/ValueBase.i delete mode 100644 TAO/tao/ValueFactory.cpp delete mode 100644 TAO/tao/ValueFactory.h delete mode 100644 TAO/tao/ValueFactory.i delete mode 100644 TAO/tao/ValueFactory_Map.cpp delete mode 100644 TAO/tao/ValueFactory_Map.h delete mode 100644 TAO/tao/ValueFactory_Map.i create mode 100644 TAO/tao/Valuetype/ValueBase.cpp create mode 100644 TAO/tao/Valuetype/ValueBase.h create mode 100644 TAO/tao/Valuetype/ValueBase.inl create mode 100644 TAO/tao/Valuetype/ValueFactory.cpp create mode 100644 TAO/tao/Valuetype/ValueFactory.h create mode 100644 TAO/tao/Valuetype/ValueFactory.inl create mode 100644 TAO/tao/Valuetype/ValueFactory_Map.cpp create mode 100644 TAO/tao/Valuetype/ValueFactory_Map.h create mode 100644 TAO/tao/Valuetype/ValueFactory_Map.inl diff --git a/TAO/ChangeLog_ref b/TAO/ChangeLog_ref index a4be995641e..27abbd8b5ab 100644 --- a/TAO/ChangeLog_ref +++ b/TAO/ChangeLog_ref @@ -1,3 +1,44 @@ +Wed Apr 30 21:33:08 2003 Jeff Parsons + + * tao/ORB.cpp: + * tao/TAO.dsp: + * tao/Valuetype_Adapter.h: + * tao/append.cpp: + * tao/corba.h: + * tao/skip.cpp: + * tao/Valuetype/AbstractBase.cpp: + * tao/Valuetype/TAO_Valuetype.dsp + * tao/Valuetype/Valuetype_Adapter_Impl.cpp: + * tao/Valuetype/Valuetype_Adapter_Impl.h: + + Exisiting files modified toward separating + valuetype-related files into a library. + + * tao/Valuetype/ValueBase.cpp: + * tao/Valuetype/ValueBase.h: + * tao/Valuetype/ValueBase.inl: + * tao/Valuetype/ValueFactory.cpp: + * tao/Valuetype/ValueFactory.h: + * tao/Valuetype/ValueFactory.inl: + * tao/Valuetype/ValueFactory_Map.cpp: + * tao/Valuetype/ValueFactory_Map.h: + * tao/Valuetype/ValueFactory_Map.inl: + + Files moved from TAO/tao and/or renamed. + + * tao/ValueBase.cpp: + * tao/ValueBase.h: + * tao/ValueBase.i: + * tao/ValueFactory.cpp: + * tao/ValueFactory.h: + * tao/ValueFactory.i: + * tao/ValueFactory_Map.cpp: + * tao/ValueFactory_Map.h: + * tao/ValueFactory_Map.i: + + Files removed from TAO and transferred to + the TAO_Valuetype library. + Wed Apr 30 18:11:05 2003 Jeff Parsons * TAO_IDL/ast/ast_interface.cpp: diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index fc9a8bee1a6..1ab9c0f2bb1 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -29,13 +29,12 @@ ACE_RCSID (tao, #include "CodecFactory_ORBInitializer.h" #include "TypeCodeFactory_Adapter.h" +#include "Valuetype_Adapter.h" #if TAO_HAS_INTERCEPTORS == 1 # include "PICurrent_ORBInitializer.h" /* @@ This should go away! */ #endif /* TAO_HAS_INTERCEPTORS == 1 */ -#include "ValueFactory_Map.h" - #include "Object_KeyC.h" #include "ace/Dynamic_Service.h" @@ -2045,47 +2044,80 @@ CORBA::ORB::register_value_factory (const char *repository_id, // %! guard, and ACE_Null_Mutex in the map // do _add_ref here not in map->rebind - if (valuetype_factory_map_ == 0) + TAO_Valuetype_Adapter *adapter = + ACE_Dynamic_Service::instance ( + TAO_ORB_Core::valuetype_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + 0); + } + + if (this->valuetype_factory_map_ == 0) { // currently the ValueFactory_Map is a singleton and not per ORB // as in the OMG specs - valuetype_factory_map_ = TAO_VALUEFACTORY_MAP::instance (); - if (valuetype_factory_map_ == 0) - ACE_THROW_RETURN (CORBA::INTERNAL (), 0); + this->valuetype_factory_map_ = + adapter->valuefactory_map_instance (); + + if (this->valuetype_factory_map_ == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + 0); + } } - int result = valuetype_factory_map_->rebind (repository_id, factory); + int result = adapter->vf_map_rebind (this->valuetype_factory_map_, + repository_id, + factory); + if (result == -1) { // Error on bind. - ACE_THROW_RETURN (CORBA::INTERNAL (), 0); + ACE_THROW_RETURN (CORBA::INTERNAL (), + 0); } + if (result == 1) { return factory; // previous factory was found } + return 0; } void CORBA::ORB::unregister_value_factory (const char * /* repository_id */ - ACE_ENV_ARG_DECL_NOT_USED) + ACE_ENV_ARG_DECL) { - ACE_ERROR((LM_ERROR, ACE_TEXT ("(%N:%l) function not implemented\n"))); - // %! TODO + ACE_THROW ((CORBA::NO_IMPLEMENT ())); } CORBA::ValueFactory CORBA::ORB::lookup_value_factory (const char *repository_id - ACE_ENV_ARG_DECL_NOT_USED) + ACE_ENV_ARG_DECL) { // %! guard // do _add_ref here not in map->find - if (valuetype_factory_map_) + if (this->valuetype_factory_map_) { - CORBA::ValueFactory factory; - int result = valuetype_factory_map_->find (repository_id, - factory); + TAO_Valuetype_Adapter *adapter = + ACE_Dynamic_Service::instance ( + TAO_ORB_Core::valuetype_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + 0); + } + + CORBA::ValueFactory factory = 0; + int result = adapter->vf_map_find (this->valuetype_factory_map_, + repository_id, + factory); if (result == -1) { diff --git a/TAO/tao/TAO.dsp b/TAO/tao/TAO.dsp index 35b46d255d2..7365d886112 100644 --- a/TAO/tao/TAO.dsp +++ b/TAO/tao/TAO.dsp @@ -967,18 +967,6 @@ SOURCE=.\TypeCodeFactory_Adapter.cpp # End Source File # Begin Source File -SOURCE=.\ValueBase.cpp -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory.cpp -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory_Map.cpp -# End Source File -# Begin Source File - SOURCE=.\Valuetype_Adapter.cpp # End Source File # Begin Source File @@ -1848,18 +1836,6 @@ SOURCE=.\TypeCodeFactory_Adapter.h # End Source File # Begin Source File -SOURCE=.\ValueBase.h -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory.h -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory_Map.h -# End Source File -# Begin Source File - SOURCE=.\Valuetype_Adapter.h # End Source File # Begin Source File @@ -2446,18 +2422,6 @@ SOURCE=.\Transport_Descriptor_Interface.inl SOURCE=.\typecode.i # End Source File -# Begin Source File - -SOURCE=.\ValueBase.i -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory.i -# End Source File -# Begin Source File - -SOURCE=.\ValueFactory_Map.i -# End Source File # End Group # Begin Group "Resource files" diff --git a/TAO/tao/ValueBase.cpp b/TAO/tao/ValueBase.cpp deleted file mode 100644 index 045a918d1c3..00000000000 --- a/TAO/tao/ValueBase.cpp +++ /dev/null @@ -1,352 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// TAO -// -// = FILENAME -// ValueBase.cpp -// -// = AUTHOR -// Torsten Kuepper -// -// ============================================================================ - -#include "tao/CDR.h" -#include "tao/ORB.h" -#include "tao/ORB_Core.h" -#include "tao/ValueBase.h" -#include "tao/ValueFactory.h" -#include "tao/debug.h" - -#if !defined (__ACE_INLINE__) -# include "tao/ValueBase.i" -#endif /* ! __ACE_INLINE__ */ - -ACE_RCSID (tao, - ValueBase, - "$Id$") - -CORBA::ValueBase::~ValueBase (void) -{ -} - -CORBA::ValueBase* -CORBA::ValueBase::_downcast (CORBA::ValueBase *vt) -{ - return vt; // every vt is a CORBA::ValueBase :-) -} - -void -CORBA::ValueBase::_tao_any_destructor (void *x) -{ - CORBA::ValueBase_ptr tmp = ACE_static_cast (CORBA::ValueBase *, x); - CORBA::remove_ref (tmp); -} - -// OBV marshaling in principle: -// _tao_marshal () is called from the CDR operator<< () -// to marshal a valuetype. To marshal the state -// it calls (virtual) _tao_marshal_v () (IDL generated) on itself -// which 'jumps' to the most derived valuetype class. This function -// further calls (inline) _tao_marshal_state, which is generated from -// IDL too and does the marshaling of state members and base classes -// (before, if any) actually. -// Fragmentation (chunking) needs some cooperation with the CDR stream. -// It needs to keep track of the state we're in: -// (outside chunk, beginning of chunk - no data, inside chunk and -// the nesting level of valuetypes. (The chunks itself are not nested.)) - -// (see CORBA 2.3 GIOP 15.3.4) - -CORBA::Boolean -CORBA::ValueBase::_tao_marshal (TAO_OutputCDR &strm, - CORBA::ValueBase *this_, - ptr_arith_t /* formal_type_id */) -{ - CORBA::Boolean retval = 1; - // %! yet much to do ... look for +++ ! - - // 1. Is 'this' yet marshalled ? (->1a) - // If not then mark 'this' as marshalled. (->2) +++ - // Or is it null ? (write null_ref and return ok) - // 1a. Put indirection and return successfull. - - if (this_ == 0) - { - retval = strm.write_ulong (0); - // write TAO_OBV_GIOP_Flags::Null_ref - return retval; - } - - // 2. if (chunking) and we are in a chunk (look in strm), - // end the chunk by writing its length at its start. - // This is the responsibility of the CDR stream. +++ - // But if nothing is writtern in this chunk yet, - // we want to overwrite the place of the dummy blocksize-tag - // with our . - // Increase the nesting level of valuetypes. - - // 3. Build , which states if chunking is used - // and if type information ((list of) repository id(s)) - // is provided. The latter is necessary if the formal_type_id - // is unequal the 'true derived' type of this object. +++ - - CORBA::ULong value_tag = TAO_OBV_GIOP_Flags::Value_tag_base - | TAO_OBV_GIOP_Flags::Type_info_single; - - retval = strm.write_ulong (value_tag); - - if (! retval) - { - return retval; - } - - // 4. Marshal type information. - - retval = strm.write_string (this_->_tao_obv_repository_id ()); - - if (! retval) - { - return retval; - } - - // 5. if (chunking) let room for a blocksize-tag. (i.e. write ULong) - - // 6. Now marshal state members. (%! Problem when state is empty - // and chunked encoding is used.) - - retval = this_->_tao_marshal_v (strm); - - // 7. if (chunking) let strm overwrite the last blocksize tag - // with its concrete value. +++ - // 8. if (chunking) write an end tag, or (optimization) let the CDR - // care for collecting all end tags of nested values (e.g. linked - // list), so that only one end tag at all must be written. +++ - - return retval; -} - - -CORBA::Boolean -CORBA::ValueBase::_tao_unmarshal (TAO_InputCDR &strm, - CORBA::ValueBase *&new_object) -{ - // This is for the special case only that one unmarshals in order - // to assign the newly created object directly to a ValueBase pointer. - // Implementation is like a specialized one (in TC.cpp, if T.idl is source). - // basically do: - // ValueBase::_tao_unmarshal_pre () - // (Gets factory or possible a null or an existing object. - // Then the job is done. On an existing (backreferenced) object - // do a cast and a type check) - // new_object = factory->create_for_unmarshal () - // (with apropriate cast) - // new_object->_tao_unmarshal_v () - // new_object->_tao_unmarshal_post () - -// CORBA::ValueBase *base = 0; - CORBA::ValueFactory_var factory; - CORBA::Boolean retval = - CORBA::ValueBase::_tao_unmarshal_pre (strm, - factory.out (), - new_object, - 0); - - if (retval == 0) - { - return 0; - } - - if (factory.in () != 0) - { - new_object = factory->create_for_unmarshal (); - - if (new_object == 0) - { - return 0; // %! except.? - } - - retval = new_object->_tao_unmarshal_v (strm); - - if (retval == 0) - { - return 0; - } - } - - // Now base must be null or point to the unmarshaled object. - // Align the pointer to the right subobject. -// new_object = CORBA::ValueBase::_downcast (base); - return retval; -} - - -CORBA::Boolean -CORBA::ValueBase::_tao_unmarshal_pre (TAO_InputCDR &strm, - CORBA::ValueFactory &factory, - CORBA::ValueBase *&valuetype, - const char * const /* repo_id */) -{ // %! dont leak on error case ! - // %! postconditions - CORBA::Boolean retval = 1; - factory = 0; - // %! yet much to do ... look for +++ ! - - // 1. Get the (else it may be or ). - // Is object yet unmarshalled ( is set) ? (->1a) - // Is given ? Set 0 and return ok. - // 1a. Lookup the real address in memory, which should be aligned +++ - // to CORBA::ValueBase. Its possible at this point that worse - // type mismatch gets by undetected, if the CDR stream fakes. - // So the type should be checked ... +++ - - CORBA::ULong value_tag; - - if (!strm.read_ulong (value_tag)) - { - return 0; - } - - if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag)) - { - valuetype = 0; - return 1; - // ok, null reference unmarshaled - } - // 2. Now at this point it must be a (error else). - // if (chunking) check that any last chunk ends with matching - // size. If not raise marshal exception. - // Increase the nesting level of valuetypes. - - if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag)) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("!CORBA::ValueBase::_tao_unmarshal_pre ") - ACE_TEXT ("not value_tag\n"))); - return 0; - } - - // 3. if (chunking) read and record the blocksize-tag. - - // 4. Unmarshal type information and lookup factory. - // If no type information is given in the CDR encoding, as told - // from the , then use the repository id parameter - // (it _must_ be right). - - CORBA::String_var repo_id_stream; - - // It would be more efficient not to copy the string %!) - if (strm.read_string (repo_id_stream.inout ()) == 0) - { - return 0; - } - - TAO_ORB_Core *orb_core = strm.orb_core (); - - if (orb_core == 0) - { - orb_core = TAO_ORB_Core_instance (); - - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_WARNING, - "TAO (%P|%t) WARNING: extracting valuetype using " - "default ORB_Core\n")); - } - } - - factory = orb_core->orb ()->lookup_value_factory (repo_id_stream.in ()); - - if (factory == 0) // %! except.! - { - ACE_DEBUG ((LM_ERROR, - ACE_TEXT ("(%N:%l) OBV factory is null !!!\n"))); - return 0; - } - - return retval; -} - -CORBA::Boolean -CORBA::ValueBase::_tao_unmarshal_post (TAO_InputCDR &) -{ - CORBA::Boolean retval = 1; - - // (... called from T::_tao_unmarshal) - // 7. if (chunking) check the last blocksize tag for correct value. +++ - // And if we're gonna to truncate, skip all the state of the more - // derived classes. (But it might need to be accessed again, - // if there are embedded objects which are referenced later - // in this CDR encoding stream.) - - // 8. if (chunking) there must be some end tag. Let the CDR stream deal - // with this (and decrease the nesting level of valuetypes). - // Also the CDR stream must check for eventually outstanding end tags - // at the end of the stream which have to cause a marshal - // exception there. - - return retval; -} - - -// member functions for CORBA::DefaultValueRefCountBase ============ - -// destructor -CORBA::DefaultValueRefCountBase::~DefaultValueRefCountBase (void) -{ -} - -void -CORBA::DefaultValueRefCountBase::_add_ref (void) -{ - this->_tao_add_ref (); -} - -void -CORBA::DefaultValueRefCountBase::_remove_ref (void) -{ - this->_tao_remove_ref (); -} - -CORBA::ULong -CORBA::DefaultValueRefCountBase::_refcount_value (void) -{ - return this->_tao_refcount_value (); -} - -// =========================================================== - -// some constants - -const CORBA::ULong TAO_OBV_GIOP_Flags::Value_tag_base = 0x7fffff00L; -const CORBA::ULong TAO_OBV_GIOP_Flags::Value_tag_sigbits = 0xffffff00L; -const CORBA::ULong TAO_OBV_GIOP_Flags::Codebase_url = 1; -const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_sigbits = 0x00000006L; -const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_none = 0; -const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_single = 2; -const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_list = 6; - -// =========================================================== - -CORBA::Boolean -operator<< (TAO_OutputCDR &strm, - const CORBA::ValueBase *_tao_valuetype) -{ - return CORBA::ValueBase::_tao_marshal ( - strm, - ACE_const_cast (CORBA::ValueBase *, - _tao_valuetype), - (ptr_arith_t) &CORBA::ValueBase::_downcast - ); -} - -CORBA::Boolean -operator>> (TAO_InputCDR &strm, - CORBA::ValueBase *&_tao_valuetype) -{ - return CORBA::ValueBase::_tao_unmarshal (strm, - _tao_valuetype); -} - diff --git a/TAO/tao/ValueBase.h b/TAO/tao/ValueBase.h deleted file mode 100644 index 0758baa01a7..00000000000 --- a/TAO/tao/ValueBase.h +++ /dev/null @@ -1,265 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file ValueBase.h - * - * $Id$ - * - * @author Torsten Kuepper - */ -//============================================================================= - - -#ifndef TAO_VALUEBASE_H -#define TAO_VALUEBASE_H - -#include "ace/pre.h" - -#include "tao/orbconf.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/corbafwd.h" - -#include "ace/Basic_Types.h" /* for ptr_arith_t */ -#include "ace/Synch_T.h" - - -namespace CORBA -{ - class ValueBase; - - TAO_NAMESPACE_INLINE_FUNCTION void add_ref (ValueBase *); - TAO_NAMESPACE_INLINE_FUNCTION void remove_ref (ValueBase *); - - class ValueBase_var; - - /** - * @class ValueBase - * - * @brief Abstract baseclass for Valuetypes - * - * @see CORBA 2.3 - Section 20.17.5 - */ - class TAO_Export ValueBase - { - public: - typedef ValueBase* _ptr_type; - typedef ValueBase_var _var_type; - - // reference counting - /// %! virtual CORBA::ValueBase* _copy_value (void) = 0; - virtual void _add_ref (void) = 0; - virtual void _remove_ref (void) = 0; - virtual CORBA::ULong _refcount_value (void) = 0; - - // dynamic casting - static CORBA::ValueBase* _downcast (CORBA::ValueBase *); - - /// Used in the implementation of CORBA::Any - static void _tao_any_destructor (void *); - - /// TAO extension - virtual const char* _tao_obv_repository_id (void) const = 0; - - // TAO internal -------------------------- - - /// Marshal a valuetype (see operator<< in tao_idl generated file - /// how it is called) - static CORBA::Boolean _tao_marshal (TAO_OutputCDR &strm, - ValueBase *_this, - ptr_arith_t formal_type_id = 0); - - /// Unmarshal a valuetype, if formal type is a pointer to - /// ValueBase - static CORBA::Boolean _tao_unmarshal (TAO_InputCDR &strm, - ValueBase *&new_object); - - // static CORBA::Boolean - // T::_tao_unmarshal (TAO_InputCDR &, ValueBase *&_this) - // is typespecific for valuetype T and generated from tao_idl - // Use this for unmarshaling. - - /// Both used internally and are called from T::_tao_unmarshal () - static CORBA::Boolean _tao_unmarshal_pre (TAO_InputCDR &strm, - ValueFactory &, - ValueBase *&, - const char * const repo_id); - CORBA::Boolean _tao_unmarshal_post (TAO_InputCDR &strm); - - public: // otherwise these cannot be called from a static function - - virtual void *_tao_obv_narrow (ptr_arith_t) = 0; - - /// during marshal jump to the most derived part - virtual CORBA::Boolean _tao_marshal_v (TAO_OutputCDR &) = 0; - - /// called after obtaining the fresh object from create_for_unmarshal () - virtual CORBA::Boolean _tao_unmarshal_v (TAO_InputCDR &) = 0; - - protected: - ValueBase (void); - ValueBase (const ValueBase&); - virtual ~ValueBase (void); - - private: - ValueBase & operator= (const ValueBase &); - -#ifdef SUN_CC_HAS_PVFC_BUG - // Need ugly fix for sun cc "pure virtual function called" bug. - private: - unsigned long tao_sun_cc_pvfc_bug_fix_; - -#endif /* SUN_CC_HAS_PVFC_BUG */ - - }; // ValueBase - - /** - * @class ValueBase_var - * - * @brief _var class for ValueBase - */ - class TAO_Export ValueBase_var - { - public: - ValueBase_var (void); - ValueBase_var (CORBA::ValueBase *); - ValueBase_var (const ValueBase_var &); - ~ValueBase_var (void); - - ValueBase_var &operator= (CORBA::ValueBase *); - ValueBase_var &operator= (const ValueBase_var &); - CORBA::ValueBase *operator-> (void) const; - - operator const CORBA::ValueBase *() const; - operator CORBA::ValueBase *&(); - - /// in, inout, out, _retn - CORBA::ValueBase *in (void) const; - CORBA::ValueBase *&inout (void); - CORBA::ValueBase *&out (void); - CORBA::ValueBase *_retn (void); - CORBA::ValueBase *ptr (void) const; - - static CORBA::ValueBase * tao_duplicate (CORBA::ValueBase *); - static void tao_release (CORBA::ValueBase *); - static CORBA::ValueBase * tao_nil (void); - static CORBA::ValueBase * tao_narrow (CORBA::ValueBase * - ACE_ENV_ARG_DECL_NOT_USED); - static CORBA::ValueBase * tao_upcast (void *); - - private: - CORBA::ValueBase *ptr_; - }; - - /** - * @class ValueBase_out - * - * @brief _out class for CORBA::ValueBase - * - * _out class for CORBA::ValueBase - */ - class TAO_Export ValueBase_out - { - public: - ValueBase_out (CORBA::ValueBase *&); - ValueBase_out (ValueBase_var &); - ValueBase_out (const ValueBase_out &); - ValueBase_out &operator= (const ValueBase_out &); - ValueBase_out &operator= (const ValueBase_var &); - ValueBase_out &operator= (CORBA::ValueBase *); - operator CORBA::ValueBase *&(); - CORBA::ValueBase *&ptr (void); - CORBA::ValueBase *operator-> (void); - - private: - CORBA::ValueBase *&ptr_; - }; - - /** - * @class DefaultValueRefCountBase - * - * @brief Default mix-in for reference count of a valuetype. - * - * Default mix-in for reference count of a valuetype. - */ - class TAO_Export DefaultValueRefCountBase - : public virtual ValueBase - { - public: - virtual void _add_ref (void); - virtual void _remove_ref (void); - virtual CORBA::ULong _refcount_value (void); - - /// The _tao variants are inline for fast access from T_var - /// (if valuetype T is compiled with optimization for that.) %! (todo) - void _tao_add_ref (void); - void _tao_remove_ref (void); - CORBA::ULong _tao_refcount_value (void); - - protected: - DefaultValueRefCountBase (void); - DefaultValueRefCountBase (const DefaultValueRefCountBase&); - virtual ~DefaultValueRefCountBase (); - - private: - void operator= (const DefaultValueRefCountBase &); - - private: // data - CORBA::ULong _tao_reference_count_; - TAO_SYNCH_MUTEX _tao_reference_count_lock_; - }; // DefaultValueRefCountBase - - // which lock has the lowest memory overhead ? - // %! todo refcountbase w/o locking (now memory overhead) - // $! todo: debug aids for refcounts - -} // End CORBA namespace - -/** - * @class TAO_OBV_GIOP_Flags - * - * @brief TAO_OBV_GIOP_Flags - * - * @see CORBA 2.3 -- Section 15.3.4 - */ -class TAO_Export TAO_OBV_GIOP_Flags -{ -public: - static const CORBA::ULong Value_tag_base; - static const CORBA::ULong Value_tag_sigbits; - static const CORBA::ULong Codebase_url; - static const CORBA::ULong Type_info_sigbits; - static const CORBA::ULong Type_info_none; - static const CORBA::ULong Type_info_single; - static const CORBA::ULong Type_info_list; - - static CORBA::Boolean is_null_ref (CORBA::ULong); - static CORBA::Boolean is_value_tag (CORBA::ULong); - static CORBA::Boolean has_codebase_url (CORBA::ULong); - static CORBA::Boolean has_no_type_info (CORBA::ULong); - static CORBA::Boolean has_single_type_info (CORBA::ULong); - static CORBA::Boolean has_list_type_info (CORBA::ULong); - static CORBA::Boolean is_chunked (CORBA::ULong); - static CORBA::Boolean is_indirection_tag (CORBA::ULong); - static CORBA::Boolean is_indirection (CORBA::ULong); - static CORBA::Boolean is_block_size (CORBA::ULong); - static CORBA::Boolean is_end_tag (CORBA::ULong); -}; - -TAO_Export CORBA::Boolean -operator<< (TAO_OutputCDR&, const CORBA::ValueBase *); - -TAO_Export CORBA::Boolean -operator>> (TAO_InputCDR&, CORBA::ValueBase *&); - -#if defined (__ACE_INLINE__) -# include "tao/ValueBase.i" -#endif /* __ACE_INLINE__*/ - -#include "ace/post.h" - -#endif /* TAO_VALUEBASE_H */ diff --git a/TAO/tao/ValueBase.i b/TAO/tao/ValueBase.i deleted file mode 100644 index 5520bcc80bb..00000000000 --- a/TAO/tao/ValueBase.i +++ /dev/null @@ -1,345 +0,0 @@ -// This may not look like C++, but it's really -*- C++ -*- -// -// $Id$ - -// static operations in namespace CORBA ======================== - -ACE_INLINE void -CORBA::add_ref (CORBA::ValueBase *val) -{ - if (val) - val->_add_ref (); -} - -ACE_INLINE void -CORBA::remove_ref (CORBA::ValueBase *val) -{ - if (val) - val->_remove_ref (); -} - -// =========================================================== - -// constructor -ACE_INLINE -CORBA::ValueBase::ValueBase (void) -{ -} - -// ************************************************************* -// Inline operations for class CORBA::ValueBase_var -// ************************************************************* - -ACE_INLINE -CORBA::ValueBase_var::ValueBase_var (void) - : ptr_ (0) -{ -} - -ACE_INLINE -CORBA::ValueBase_var::ValueBase_var (CORBA::ValueBase *p) - : ptr_ (p) -{ -} - -ACE_INLINE -CORBA::ValueBase_var::~ValueBase_var (void) -{ - CORBA::remove_ref (this->ptr_); -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::ptr (void) const -{ - return this->ptr_; -} - -ACE_INLINE -CORBA::ValueBase_var::ValueBase_var (const CORBA::ValueBase_var &p) - : ptr_ (p.ptr_) -{ - p.ptr_->_add_ref (); -} - -ACE_INLINE CORBA::ValueBase_var & -CORBA::ValueBase_var::operator= (CORBA::ValueBase *p) -{ - CORBA::remove_ref (this->ptr_); - this->ptr_ = p; - return *this; -} - -ACE_INLINE CORBA::ValueBase_var & -CORBA::ValueBase_var::operator= (const CORBA::ValueBase_var &p) -{ - if (this != &p) - { - CORBA::remove_ref (this->ptr_); - p.ptr_->_add_ref (); - this->ptr_ = p.ptr_; - } - - return *this; -} - -ACE_INLINE -CORBA::ValueBase_var::operator const CORBA::ValueBase *() const // cast -{ - return this->ptr_; -} - -ACE_INLINE -CORBA::ValueBase_var::operator CORBA::ValueBase *&() // cast -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::operator-> (void) const -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::in (void) const -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase *& -CORBA::ValueBase_var::inout (void) -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase *& -CORBA::ValueBase_var::out (void) -{ - CORBA::remove_ref (this->ptr_); - this->ptr_ = 0; - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::_retn (void) -{ - // Yield ownership of valuebase. - CORBA::ValueBase *val = this->ptr_; - this->ptr_ = 0; - return val; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::tao_duplicate (CORBA::ValueBase *p) -{ - p->_add_ref (); - return p; -} - -ACE_INLINE void -CORBA::ValueBase_var::tao_release (CORBA::ValueBase *p) -{ - p->_remove_ref (); -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::tao_nil (void) -{ - return 0; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::tao_narrow ( - CORBA::ValueBase *p - ACE_ENV_ARG_DECL_NOT_USED - ) -{ - p->_add_ref (); - return CORBA::ValueBase::_downcast (p); -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_var::tao_upcast (void *src) -{ - CORBA::ValueBase **tmp = - ACE_static_cast (CORBA::ValueBase **, src); - return *tmp; -} - -// ************************************************************* -// Inline operations for class CORBA::ValueBase_out -// ************************************************************* - -ACE_INLINE -CORBA::ValueBase_out::ValueBase_out (CORBA::ValueBase *&p) - : ptr_ (p) -{ - this->ptr_ = 0; -} - -ACE_INLINE -CORBA::ValueBase_out::ValueBase_out (CORBA::ValueBase_var &p) - : ptr_ (p.out ()) -{ - this->ptr_->_remove_ref (); - this->ptr_ = 0; -} - -ACE_INLINE -CORBA::ValueBase_out::ValueBase_out (const CORBA::ValueBase_out &p) - : ptr_ (p.ptr_) -{ -} - -ACE_INLINE CORBA::ValueBase_out & -CORBA::ValueBase_out::operator= (const CORBA::ValueBase_out &p) -{ - this->ptr_ = p.ptr_; - return *this; -} - -ACE_INLINE CORBA::ValueBase_out & -CORBA::ValueBase_out::operator= (const CORBA::ValueBase_var &p) -{ - p.ptr ()->_add_ref (); - this->ptr_ = p.ptr (); - return *this; -} - -ACE_INLINE CORBA::ValueBase_out & -CORBA::ValueBase_out::operator= (CORBA::ValueBase *p) -{ - this->ptr_ = p; - return *this; -} - -ACE_INLINE -CORBA::ValueBase_out::operator CORBA::ValueBase *&() // cast -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase *& -CORBA::ValueBase_out::ptr (void) // ptr -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueBase * -CORBA::ValueBase_out::operator-> (void) -{ - return this->ptr_; -} - -// =========================================================== - -// constructor -ACE_INLINE -CORBA::DefaultValueRefCountBase::DefaultValueRefCountBase (void) - : _tao_reference_count_ (1) -{ -} - - -ACE_INLINE void -CORBA::DefaultValueRefCountBase::_tao_add_ref (void) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); - ++_tao_reference_count_; -} - -ACE_INLINE void -CORBA::DefaultValueRefCountBase::_tao_remove_ref (void) -{ - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); - -- this->_tao_reference_count_; - if (this->_tao_reference_count_ != 0) - return; - } - // The guard has been already given up, but this is no problem - // cause we have held the last reference, and this one we don't give - // away anymore, we do: - delete this; -} - -ACE_INLINE CORBA::ULong -CORBA::DefaultValueRefCountBase::_tao_refcount_value (void) -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, - guard, - this->_tao_reference_count_lock_, - 0); - return _tao_reference_count_; -} - -// =========================================================== - -// Detection of flags in the CDR Stream - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_null_ref (CORBA::ULong tag) -{ - return (tag == 0); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_value_tag (CORBA::ULong tag) -{ - return ((tag & Value_tag_sigbits) == 0x7FFFFF00L); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags:: has_codebase_url(CORBA::ULong tag) -{ - return (CORBA::Boolean) (tag & Codebase_url); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::has_no_type_info (CORBA::ULong tag) -{ - return ((tag & Type_info_sigbits) == Type_info_none); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::has_single_type_info (CORBA::ULong tag) -{ - return ((tag & Type_info_sigbits) == Type_info_single); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::has_list_type_info (CORBA::ULong tag) -{ - return ((tag & Type_info_sigbits) == Type_info_list); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags:: is_chunked (CORBA::ULong tag) -{ - return (CORBA::Boolean) (tag & 8); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_indirection_tag (CORBA::ULong tag) -{ - return (tag == 0xFFFFFFFFL); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_indirection (CORBA::ULong value) -{ - return (0x80000000L < value && value <= (0xFFFFFFFFL - 4)); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_block_size (CORBA::ULong value) -{ - return ( 0 < value && value < 0x7fffff00L); -} - -ACE_INLINE CORBA::Boolean -TAO_OBV_GIOP_Flags::is_end_tag (CORBA::ULong tag) -{ - return (0x80000000L < tag && tag <= 0xFFFFFFFFL); -} - diff --git a/TAO/tao/ValueFactory.cpp b/TAO/tao/ValueFactory.cpp deleted file mode 100644 index 6cf497f3750..00000000000 --- a/TAO/tao/ValueFactory.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "tao/ValueFactory.h" - -#if !defined (__ACE_INLINE__) -# include "tao/ValueFactory.i" -#endif /* ! __ACE_INLINE__ */ - - -ACE_RCSID (tao, - ValueFactory, - "$Id$") - - -CORBA::ValueFactoryBase::~ValueFactoryBase (void) -{ -} - -// No-op. This should never be called, but it can't be pure virtual. -CORBA::AbstractBase * -CORBA::ValueFactoryBase::create_for_unmarshal_abstract (void) -{ - return 0; -} - diff --git a/TAO/tao/ValueFactory.h b/TAO/tao/ValueFactory.h deleted file mode 100644 index 9d682aa227b..00000000000 --- a/TAO/tao/ValueFactory.h +++ /dev/null @@ -1,120 +0,0 @@ -// This may look like C, but it's really -*- C++ -*- - -//============================================================================= -/** - * @file ValueFactory.h - * - * $Id$ - * - * @author Torsten Kuepper - */ -//============================================================================= - - -#ifndef TAO_VALUEFACTORY_H -#define TAO_VALUEFACTORY_H -#include "ace/pre.h" - -#include "tao/corbafwd.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Synch_T.h" - -namespace CORBA -{ - class TAO_Export ValueFactoryBase - { - public: - ValueFactoryBase (); - virtual ~ValueFactoryBase (); - - // non-virtual is non-standard - void _add_ref (void); - void _remove_ref (void); - - // private: %! - /// In a derived class T use return type TAO_OBV_CREATE_RETURN_TYPE (T) - /// (see at definition below) - virtual CORBA::ValueBase * create_for_unmarshal (void) = 0; - - // Not pure virtual because this will be overridden only by valuetypes - // that support an abstract interface. - virtual CORBA::AbstractBase * create_for_unmarshal_abstract (void); - - private: - CORBA::ULong _tao_reference_count_; - TAO_SYNCH_MUTEX _tao_reference_count_lock_; - }; // CORBA_ValueFactoryBase - - /** - * @class ValueFactoryBase_var - * - * @brief _var class for ValueFactoryBase - */ - class TAO_Export ValueFactoryBase_var - { - public: - ValueFactoryBase_var (void); - ValueFactoryBase_var (CORBA::ValueFactoryBase *); - ValueFactoryBase_var (const ValueFactoryBase_var &); - ~ValueFactoryBase_var (void); - - ValueFactoryBase_var &operator= (CORBA::ValueFactoryBase *); - ValueFactoryBase_var &operator= (const ValueFactoryBase_var &); - CORBA::ValueFactoryBase *operator-> (void) const; - - /// in, inout, out, _retn - CORBA::ValueFactoryBase *in (void) const; - CORBA::ValueFactoryBase *&inout (void); - CORBA::ValueFactoryBase *&out (void); - CORBA::ValueFactoryBase *_retn (void); - CORBA::ValueFactoryBase *ptr (void) const; - - private: - CORBA::ValueFactoryBase *ptr_; - }; - -} // End CORBA namespace - -// Use this macro for writing code that is independend from -// the compiler support of covariant return types of pointers to -// virtual inherited classes. -// (e.g. in egcs-2.90.29 980515 (egcs-1.0.3 release) its not yet implemented) -// (But it is TAO specific and at the moment the covariant case is not -// elaborated --- its just a suggestion.) - -#ifdef TAO_HAS_OBV_COVARIANT_RETURN -# define TAO_OBV_CREATE_RETURN_TYPE(TYPE) TYPE * -#else /* TAO_HAS_OBV_COVARIANT_RETURN */ -# define TAO_OBV_CREATE_RETURN_TYPE(TYPE) CORBA::ValueBase * -#endif /* TAO_HAS_OBV_COVARIANT_RETURN */ - -// (The obtaining of the repository id is currently not yet like the OMG way. %!) -// -// Macro for on the fly registration of a factory (with type Factory). -// The repository id is taken from the static repository id of the -// valuetype via tao_repository_id () of the specialized factory. -// It forgets the pre-registered factory (if any) and the reference -// to the newly created one. (A new reference could be obtained with -// orb->lookup_value_factory (char * repo_id) .) - -#define TAO_OBV_REGISTER_FACTORY(FACTORY, VALUETYPE) \ - { CORBA::ValueFactory factory = new FACTORY; \ - CORBA::ValueFactory prev_factory = \ - TAO_ORB_Core_instance ()->orb ()->register_value_factory (\ - VALUETYPE::_tao_obv_static_repository_id (),\ - factory); \ - if (prev_factory) prev_factory->_remove_ref (); \ - factory->_remove_ref (); } - - -#if defined (__ACE_INLINE__) -# include "tao/ValueFactory.i" -#endif /* __ACE_INLINE__) */ - -#include "ace/post.h" - -#endif /* TAO_VALUEFACTORY_H */ diff --git a/TAO/tao/ValueFactory.i b/TAO/tao/ValueFactory.i deleted file mode 100644 index bbb6ad561fe..00000000000 --- a/TAO/tao/ValueFactory.i +++ /dev/null @@ -1,139 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - -ACE_INLINE -CORBA::ValueFactoryBase::ValueFactoryBase (void) - : _tao_reference_count_ (1) -{ -} - -ACE_INLINE void -CORBA::ValueFactoryBase::_add_ref (void) -{ - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); - ++_tao_reference_count_; -} - -ACE_INLINE void -CORBA::ValueFactoryBase::_remove_ref (void) -{ - { - ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); - -- this->_tao_reference_count_; - if (this->_tao_reference_count_ != 0) - return; - } - delete this; -} - -// ************************************************************* -// Inline operations for class CORBA::ValueFactoryBase_var -// ************************************************************* - -ACE_INLINE -CORBA::ValueFactoryBase_var::ValueFactoryBase_var (void) - : ptr_ (0) -{ -} - -ACE_INLINE -CORBA::ValueFactoryBase_var::ValueFactoryBase_var ( - CORBA::ValueFactoryBase *p - ) - : ptr_ (p) -{ -} - -ACE_INLINE -CORBA::ValueFactoryBase_var::~ValueFactoryBase_var (void) -{ - if (this->ptr_ != 0) - { - this->ptr_->_remove_ref (); - } -} - -ACE_INLINE CORBA::ValueFactoryBase * -CORBA::ValueFactoryBase_var::ptr (void) const -{ - return this->ptr_; -} - -ACE_INLINE -CORBA::ValueFactoryBase_var::ValueFactoryBase_var ( - const CORBA::ValueFactoryBase_var &p - ) - : ptr_ (p.ptr_) -{ - p.ptr_->_add_ref (); -} - -ACE_INLINE CORBA::ValueFactoryBase_var & -CORBA::ValueFactoryBase_var::operator= (CORBA::ValueFactoryBase *p) -{ - if (this->ptr_ != 0) - { - this->ptr_->_remove_ref (); - } - - this->ptr_ = p; - return *this; -} - -ACE_INLINE CORBA::ValueFactoryBase_var & -CORBA::ValueFactoryBase_var::operator= (const CORBA::ValueFactoryBase_var &p) -{ - if (this != &p) - { - if (this->ptr_ != 0) - { - this->ptr_->_remove_ref (); - } - - p.ptr_->_add_ref (); - this->ptr_ = p.ptr_; - } - - return *this; -} - -ACE_INLINE CORBA::ValueFactoryBase * -CORBA::ValueFactoryBase_var::operator-> (void) const -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueFactoryBase * -CORBA::ValueFactoryBase_var::in (void) const -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueFactoryBase *& -CORBA::ValueFactoryBase_var::inout (void) -{ - return this->ptr_; -} - -ACE_INLINE CORBA::ValueFactoryBase *& -CORBA::ValueFactoryBase_var::out (void) -{ - if (this->ptr_ != 0) - { - this->ptr_->_remove_ref (); - } - - this->ptr_ = 0; - return this->ptr_; -} - -ACE_INLINE CORBA::ValueFactoryBase * -CORBA::ValueFactoryBase_var::_retn (void) -{ - // Yield ownership of valuebase. - CORBA::ValueFactoryBase *val = this->ptr_; - this->ptr_ = 0; - return val; -} - diff --git a/TAO/tao/ValueFactory_Map.cpp b/TAO/tao/ValueFactory_Map.cpp deleted file mode 100644 index d43b139f1c2..00000000000 --- a/TAO/tao/ValueFactory_Map.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "tao/ValueFactory_Map.h" -#include "tao/ValueFactory.h" - -#if !defined (__ACE_INLINE__) -# include "tao/ValueFactory_Map.i" -#endif /* ! __ACE_INLINE__ */ - - -ACE_RCSID (tao, - ValueFactory_Map, - "$Id$") - - -TAO_ValueFactory_Map::TAO_ValueFactory_Map (void) - : map_ (TAO_DEFAULT_VALUE_FACTORY_TABLE_SIZE) -{ -} - -TAO_ValueFactory_Map::~TAO_ValueFactory_Map (void) -{ - // Initialize an iterator. We need to go thru each entry and free - // up storage allocated to hold the external ids and invoke - // _remove_ref () on the internal ids. - FACTORY_MAP_MANAGER::ITERATOR iterator (this->map_); - - for (FACTORY_MAP_MANAGER::ENTRY *entry = 0; - iterator.next (entry) != 0; - iterator.advance ()) - { - // We had allocated memory and stored the string. So we free the - // memory. - CORBA::string_free ((char *) entry->ext_id_); - entry->ext_id_ = 0; - entry->int_id_->_remove_ref (); - entry->int_id_ = 0; - } -} - -// %! Thread issues - -int -TAO_ValueFactory_Map::rebind (const char *repo_id, - CORBA::ValueFactory &factory) -{ -// ACE_READ_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, map_->mutex(),-1); -// --- but must be recursive - const char *prev_repo_id; - CORBA::ValueFactory prev_factory; - int ret = 0; - ret = this->map_.rebind (CORBA::string_dup (repo_id), - factory, - prev_repo_id, - prev_factory); - - if (ret > -1) // ok, no error - { - factory->_add_ref (); // The map owns one reference. - - if (ret == 1) // there was a previous factory - { - factory = prev_factory; - CORBA::string_free (ACE_const_cast(char*,prev_repo_id)); - } - } - - return ret; -} - -int -TAO_ValueFactory_Map::unbind (const char *repo_id, - CORBA::ValueFactory &factory) -{ - FACTORY_MAP_MANAGER::ENTRY *prev_entry; - int ret = 0; - ret = this->map_.find (repo_id, - prev_entry); - if (ret == 0) // there was a matching factory - { - // set factory to the previous factory, - factory = prev_entry->int_id_; - char *temp = ACE_const_cast (char *, prev_entry->ext_id_); - ret = this->map_.unbind (prev_entry); - - if (ret == 0) - { - CORBA::string_free (temp); - } - } - - return ret; -} - -// %! perhaps inline -int -TAO_ValueFactory_Map::find (const char *repo_id, - CORBA::ValueFactory &factory) -{ - int ret = 0; - ret = this->map_.find (repo_id, - factory); - // %! this must be guarded to be atomic !!!!!!!!!!!!!!!!!! - if (ret > -1) - { - factory->_add_ref (); // The caller gets one reference as gift. - } - - return ret; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; -template class ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; -template class ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; -template class ACE_Hash_Map_Manager_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; -template class ACE_Hash_Map_Entry; -template class TAO_Singleton; - -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Hash_Map_Manager_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Hash_Map_Entry -#pragma instantiate TAO_Singleton - -#elif defined (__GNUC__) && (defined (_AIX) || defined (__hpux) || defined (VXWORKS)) -template TAO_Singleton * TAO_Singleton::singleton_; - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - diff --git a/TAO/tao/ValueFactory_Map.h b/TAO/tao/ValueFactory_Map.h deleted file mode 100644 index 78ea7c3e915..00000000000 --- a/TAO/tao/ValueFactory_Map.h +++ /dev/null @@ -1,87 +0,0 @@ -// This may look like C, but it's really -*- C++ -*- - -//============================================================================= -/** - * @file ValueFactory_Map.h - * - * $Id$ - * - * @author Torsten Kuepper - */ -//============================================================================= - - -#ifndef TAO_VALUEFACTORY_MAP_H -#define TAO_VALUEFACTORY_MAP_H -#include "ace/pre.h" - -#include "ace/Hash_Map_Manager_T.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "tao/TAO_Singleton.h" -#include "ace/Synch.h" -#include "tao/corbafwd.h" - -class TAO_ValueFactory_Map -{ -public: - - TAO_ValueFactory_Map (void); - ~TAO_ValueFactory_Map (void); - - /** - * Associate the factory (int_id) with the repo_id (ext_id). - * Invokes _add_ref () on the factory. - * If previous factory had been bind with this repo_id, this one is - * returned in factory (and the caller holds a reference). - * Returns -1 on failure, 0 on success and 1 if a previous factory - * is found (and returned in factory). - */ - int rebind (const char *repo_id, CORBA::ValueFactory &factory); - - /// Removes entry for repo_id from the map and sets factory to - /// the tied one. - int unbind (const char *repo_id, CORBA::ValueFactory &factory); - - /** - * Lookup a matching factory for repo_id. - * Invokes _add_ref () on the factory if found. - * Returns -1 on failure and 0 on success. - */ - int find (const char *repo_id, CORBA::ValueFactory &factory); - - void dump (void); - -private: - - /// The hash table data structure. - typedef ACE_Hash_Map_Manager_Ex, - ACE_Equal_To, - TAO_SYNCH_RW_MUTEX> - FACTORY_MAP_MANAGER; - FACTORY_MAP_MANAGER map_; -}; /* TAO_ValueFactory_Map */ - - -// currently the ValueFactory_Map is a singleton and not per ORB -// as in the OMG specs -typedef TAO_Singleton - TAO_VALUEFACTORY_MAP; - -TAO_SINGLETON_DECLARE (TAO_Singleton, - TAO_ValueFactory_Map, - TAO_SYNCH_MUTEX) - - -#if defined (__ACE_INLINE__) -# include "tao/ValueFactory_Map.i" -#endif /* __ACE_INLINE__) */ - -#include "ace/post.h" - -#endif /* TAO_VALUEFACTORY_MAP_H */ diff --git a/TAO/tao/ValueFactory_Map.i b/TAO/tao/ValueFactory_Map.i deleted file mode 100644 index cfa1da318d3..00000000000 --- a/TAO/tao/ValueFactory_Map.i +++ /dev/null @@ -1 +0,0 @@ -// $Id$ diff --git a/TAO/tao/Valuetype/AbstractBase.cpp b/TAO/tao/Valuetype/AbstractBase.cpp index 9e9f29946be..e732bf846e4 100644 --- a/TAO/tao/Valuetype/AbstractBase.cpp +++ b/TAO/tao/Valuetype/AbstractBase.cpp @@ -1,10 +1,10 @@ // "$Id$" #include "AbstractBase.h" -#include "tao/ValueBase.h" +#include "ValueBase.h" +#include "ValueFactory.h" #include "tao/Stub.h" #include "tao/Profile.h" -#include "tao/ValueFactory.h" #include "tao/debug.h" #if !defined (__ACE_INLINE__) diff --git a/TAO/tao/Valuetype/TAO_Valuetype.dsp b/TAO/tao/Valuetype/TAO_Valuetype.dsp index c70aaca1785..d2535c472c7 100644 --- a/TAO/tao/Valuetype/TAO_Valuetype.dsp +++ b/TAO/tao/Valuetype/TAO_Valuetype.dsp @@ -98,6 +98,18 @@ SOURCE=.\AbstractBase.cpp # End Source File # Begin Source File +SOURCE=.\ValueBase.cpp +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory.cpp +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory_Map.cpp +# End Source File +# Begin Source File + SOURCE=.\Valuetype_Adapter_Impl.cpp # End Source File # End Group @@ -110,6 +122,18 @@ SOURCE=.\AbstractBase.h # End Source File # Begin Source File +SOURCE=.\ValueBase.h +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory.h +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory_Map.h +# End Source File +# Begin Source File + SOURCE=.\Valuetype_Adapter_Impl.h # End Source File # Begin Source File @@ -124,6 +148,18 @@ SOURCE=.\valuetype_export.h SOURCE=.\AbstractBase.inl # End Source File +# Begin Source File + +SOURCE=.\ValueBase.inl +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory.inl +# End Source File +# Begin Source File + +SOURCE=.\ValueFactory_Map.inl +# End Source File # End Group # Begin Group "Reosurce Files" diff --git a/TAO/tao/Valuetype/ValueBase.cpp b/TAO/tao/Valuetype/ValueBase.cpp new file mode 100644 index 00000000000..09149f7476a --- /dev/null +++ b/TAO/tao/Valuetype/ValueBase.cpp @@ -0,0 +1,352 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO +// +// = FILENAME +// ValueBase.cpp +// +// = AUTHOR +// Torsten Kuepper +// +// ============================================================================ + +#include "ValueBase.h" +#include "tao/CDR.h" +#include "tao/ORB.h" +#include "tao/ORB_Core.h" +#include "ValueFactory.h" +#include "tao/debug.h" + +#if !defined (__ACE_INLINE__) +# include "ValueBase.inl" +#endif /* ! __ACE_INLINE__ */ + +ACE_RCSID (tao, + ValueBase, + "$Id$") + +CORBA::ValueBase::~ValueBase (void) +{ +} + +CORBA::ValueBase* +CORBA::ValueBase::_downcast (CORBA::ValueBase *vt) +{ + return vt; // every vt is a CORBA::ValueBase :-) +} + +void +CORBA::ValueBase::_tao_any_destructor (void *x) +{ + CORBA::ValueBase_ptr tmp = ACE_static_cast (CORBA::ValueBase *, x); + CORBA::remove_ref (tmp); +} + +// OBV marshaling in principle: +// _tao_marshal () is called from the CDR operator<< () +// to marshal a valuetype. To marshal the state +// it calls (virtual) _tao_marshal_v () (IDL generated) on itself +// which 'jumps' to the most derived valuetype class. This function +// further calls (inline) _tao_marshal_state, which is generated from +// IDL too and does the marshaling of state members and base classes +// (before, if any) actually. +// Fragmentation (chunking) needs some cooperation with the CDR stream. +// It needs to keep track of the state we're in: +// (outside chunk, beginning of chunk - no data, inside chunk and +// the nesting level of valuetypes. (The chunks itself are not nested.)) + +// (see CORBA 2.3 GIOP 15.3.4) + +CORBA::Boolean +CORBA::ValueBase::_tao_marshal (TAO_OutputCDR &strm, + CORBA::ValueBase *this_, + ptr_arith_t /* formal_type_id */) +{ + CORBA::Boolean retval = 1; + // %! yet much to do ... look for +++ ! + + // 1. Is 'this' yet marshalled ? (->1a) + // If not then mark 'this' as marshalled. (->2) +++ + // Or is it null ? (write null_ref and return ok) + // 1a. Put indirection and return successfull. + + if (this_ == 0) + { + retval = strm.write_ulong (0); + // write TAO_OBV_GIOP_Flags::Null_ref + return retval; + } + + // 2. if (chunking) and we are in a chunk (look in strm), + // end the chunk by writing its length at its start. + // This is the responsibility of the CDR stream. +++ + // But if nothing is writtern in this chunk yet, + // we want to overwrite the place of the dummy blocksize-tag + // with our . + // Increase the nesting level of valuetypes. + + // 3. Build , which states if chunking is used + // and if type information ((list of) repository id(s)) + // is provided. The latter is necessary if the formal_type_id + // is unequal the 'true derived' type of this object. +++ + + CORBA::ULong value_tag = TAO_OBV_GIOP_Flags::Value_tag_base + | TAO_OBV_GIOP_Flags::Type_info_single; + + retval = strm.write_ulong (value_tag); + + if (! retval) + { + return retval; + } + + // 4. Marshal type information. + + retval = strm.write_string (this_->_tao_obv_repository_id ()); + + if (! retval) + { + return retval; + } + + // 5. if (chunking) let room for a blocksize-tag. (i.e. write ULong) + + // 6. Now marshal state members. (%! Problem when state is empty + // and chunked encoding is used.) + + retval = this_->_tao_marshal_v (strm); + + // 7. if (chunking) let strm overwrite the last blocksize tag + // with its concrete value. +++ + // 8. if (chunking) write an end tag, or (optimization) let the CDR + // care for collecting all end tags of nested values (e.g. linked + // list), so that only one end tag at all must be written. +++ + + return retval; +} + + +CORBA::Boolean +CORBA::ValueBase::_tao_unmarshal (TAO_InputCDR &strm, + CORBA::ValueBase *&new_object) +{ + // This is for the special case only that one unmarshals in order + // to assign the newly created object directly to a ValueBase pointer. + // Implementation is like a specialized one (in TC.cpp, if T.idl is source). + // basically do: + // ValueBase::_tao_unmarshal_pre () + // (Gets factory or possible a null or an existing object. + // Then the job is done. On an existing (backreferenced) object + // do a cast and a type check) + // new_object = factory->create_for_unmarshal () + // (with apropriate cast) + // new_object->_tao_unmarshal_v () + // new_object->_tao_unmarshal_post () + +// CORBA::ValueBase *base = 0; + CORBA::ValueFactory_var factory; + CORBA::Boolean retval = + CORBA::ValueBase::_tao_unmarshal_pre (strm, + factory.out (), + new_object, + 0); + + if (retval == 0) + { + return 0; + } + + if (factory.in () != 0) + { + new_object = factory->create_for_unmarshal (); + + if (new_object == 0) + { + return 0; // %! except.? + } + + retval = new_object->_tao_unmarshal_v (strm); + + if (retval == 0) + { + return 0; + } + } + + // Now base must be null or point to the unmarshaled object. + // Align the pointer to the right subobject. +// new_object = CORBA::ValueBase::_downcast (base); + return retval; +} + + +CORBA::Boolean +CORBA::ValueBase::_tao_unmarshal_pre (TAO_InputCDR &strm, + CORBA::ValueFactory &factory, + CORBA::ValueBase *&valuetype, + const char * const /* repo_id */) +{ // %! dont leak on error case ! + // %! postconditions + CORBA::Boolean retval = 1; + factory = 0; + // %! yet much to do ... look for +++ ! + + // 1. Get the (else it may be or ). + // Is object yet unmarshalled ( is set) ? (->1a) + // Is given ? Set 0 and return ok. + // 1a. Lookup the real address in memory, which should be aligned +++ + // to CORBA::ValueBase. Its possible at this point that worse + // type mismatch gets by undetected, if the CDR stream fakes. + // So the type should be checked ... +++ + + CORBA::ULong value_tag; + + if (!strm.read_ulong (value_tag)) + { + return 0; + } + + if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag)) + { + valuetype = 0; + return 1; + // ok, null reference unmarshaled + } + // 2. Now at this point it must be a (error else). + // if (chunking) check that any last chunk ends with matching + // size. If not raise marshal exception. + // Increase the nesting level of valuetypes. + + if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag)) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("!CORBA::ValueBase::_tao_unmarshal_pre ") + ACE_TEXT ("not value_tag\n"))); + return 0; + } + + // 3. if (chunking) read and record the blocksize-tag. + + // 4. Unmarshal type information and lookup factory. + // If no type information is given in the CDR encoding, as told + // from the , then use the repository id parameter + // (it _must_ be right). + + CORBA::String_var repo_id_stream; + + // It would be more efficient not to copy the string %!) + if (strm.read_string (repo_id_stream.inout ()) == 0) + { + return 0; + } + + TAO_ORB_Core *orb_core = strm.orb_core (); + + if (orb_core == 0) + { + orb_core = TAO_ORB_Core_instance (); + + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_WARNING, + "TAO (%P|%t) WARNING: extracting valuetype using " + "default ORB_Core\n")); + } + } + + factory = orb_core->orb ()->lookup_value_factory (repo_id_stream.in ()); + + if (factory == 0) // %! except.! + { + ACE_DEBUG ((LM_ERROR, + ACE_TEXT ("(%N:%l) OBV factory is null !!!\n"))); + return 0; + } + + return retval; +} + +CORBA::Boolean +CORBA::ValueBase::_tao_unmarshal_post (TAO_InputCDR &) +{ + CORBA::Boolean retval = 1; + + // (... called from T::_tao_unmarshal) + // 7. if (chunking) check the last blocksize tag for correct value. +++ + // And if we're gonna to truncate, skip all the state of the more + // derived classes. (But it might need to be accessed again, + // if there are embedded objects which are referenced later + // in this CDR encoding stream.) + + // 8. if (chunking) there must be some end tag. Let the CDR stream deal + // with this (and decrease the nesting level of valuetypes). + // Also the CDR stream must check for eventually outstanding end tags + // at the end of the stream which have to cause a marshal + // exception there. + + return retval; +} + + +// member functions for CORBA::DefaultValueRefCountBase ============ + +// destructor +CORBA::DefaultValueRefCountBase::~DefaultValueRefCountBase (void) +{ +} + +void +CORBA::DefaultValueRefCountBase::_add_ref (void) +{ + this->_tao_add_ref (); +} + +void +CORBA::DefaultValueRefCountBase::_remove_ref (void) +{ + this->_tao_remove_ref (); +} + +CORBA::ULong +CORBA::DefaultValueRefCountBase::_refcount_value (void) +{ + return this->_tao_refcount_value (); +} + +// =========================================================== + +// some constants + +const CORBA::ULong TAO_OBV_GIOP_Flags::Value_tag_base = 0x7fffff00L; +const CORBA::ULong TAO_OBV_GIOP_Flags::Value_tag_sigbits = 0xffffff00L; +const CORBA::ULong TAO_OBV_GIOP_Flags::Codebase_url = 1; +const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_sigbits = 0x00000006L; +const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_none = 0; +const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_single = 2; +const CORBA::ULong TAO_OBV_GIOP_Flags::Type_info_list = 6; + +// =========================================================== + +CORBA::Boolean +operator<< (TAO_OutputCDR &strm, + const CORBA::ValueBase *_tao_valuetype) +{ + return CORBA::ValueBase::_tao_marshal ( + strm, + ACE_const_cast (CORBA::ValueBase *, + _tao_valuetype), + (ptr_arith_t) &CORBA::ValueBase::_downcast + ); +} + +CORBA::Boolean +operator>> (TAO_InputCDR &strm, + CORBA::ValueBase *&_tao_valuetype) +{ + return CORBA::ValueBase::_tao_unmarshal (strm, + _tao_valuetype); +} + diff --git a/TAO/tao/Valuetype/ValueBase.h b/TAO/tao/Valuetype/ValueBase.h new file mode 100644 index 00000000000..aff9fb396f4 --- /dev/null +++ b/TAO/tao/Valuetype/ValueBase.h @@ -0,0 +1,270 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file ValueBase.h + * + * $Id$ + * + * @author Torsten Kuepper + */ +//============================================================================= + + +#ifndef TAO_VALUEBASE_H +#define TAO_VALUEBASE_H + +#include "ace/pre.h" + +#include "valuetype_export.h" +#include "tao/orbconf.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/corbafwd.h" + +#include "ace/Basic_Types.h" /* for ptr_arith_t */ +#include "ace/Synch_T.h" + +#if defined (TAO_EXPORT_MACRO) +#undef TAO_EXPORT_MACRO +#endif +#define TAO_EXPORT_MACRO TAO_Valuetype_Export + +namespace CORBA +{ + class ValueBase; + + TAO_NAMESPACE_INLINE_FUNCTION void add_ref (ValueBase *); + TAO_NAMESPACE_INLINE_FUNCTION void remove_ref (ValueBase *); + + class ValueBase_var; + + /** + * @class ValueBase + * + * @brief Abstract baseclass for Valuetypes + * + * @see CORBA 2.3 - Section 20.17.5 + */ + class TAO_Valuetype_Export ValueBase + { + public: + typedef ValueBase* _ptr_type; + typedef ValueBase_var _var_type; + + // reference counting + /// %! virtual CORBA::ValueBase* _copy_value (void) = 0; + virtual void _add_ref (void) = 0; + virtual void _remove_ref (void) = 0; + virtual CORBA::ULong _refcount_value (void) = 0; + + // dynamic casting + static CORBA::ValueBase* _downcast (CORBA::ValueBase *); + + /// Used in the implementation of CORBA::Any + static void _tao_any_destructor (void *); + + /// TAO extension + virtual const char* _tao_obv_repository_id (void) const = 0; + + // TAO internal -------------------------- + + /// Marshal a valuetype (see operator<< in tao_idl generated file + /// how it is called) + static CORBA::Boolean _tao_marshal (TAO_OutputCDR &strm, + ValueBase *_this, + ptr_arith_t formal_type_id = 0); + + /// Unmarshal a valuetype, if formal type is a pointer to + /// ValueBase + static CORBA::Boolean _tao_unmarshal (TAO_InputCDR &strm, + ValueBase *&new_object); + + // static CORBA::Boolean + // T::_tao_unmarshal (TAO_InputCDR &, ValueBase *&_this) + // is typespecific for valuetype T and generated from tao_idl + // Use this for unmarshaling. + + /// Both used internally and are called from T::_tao_unmarshal () + static CORBA::Boolean _tao_unmarshal_pre (TAO_InputCDR &strm, + ValueFactory &, + ValueBase *&, + const char * const repo_id); + CORBA::Boolean _tao_unmarshal_post (TAO_InputCDR &strm); + + public: // otherwise these cannot be called from a static function + + virtual void *_tao_obv_narrow (ptr_arith_t) = 0; + + /// during marshal jump to the most derived part + virtual CORBA::Boolean _tao_marshal_v (TAO_OutputCDR &) = 0; + + /// called after obtaining the fresh object from create_for_unmarshal () + virtual CORBA::Boolean _tao_unmarshal_v (TAO_InputCDR &) = 0; + + protected: + ValueBase (void); + ValueBase (const ValueBase&); + virtual ~ValueBase (void); + + private: + ValueBase & operator= (const ValueBase &); + +#ifdef SUN_CC_HAS_PVFC_BUG + // Need ugly fix for sun cc "pure virtual function called" bug. + private: + unsigned long tao_sun_cc_pvfc_bug_fix_; + +#endif /* SUN_CC_HAS_PVFC_BUG */ + + }; // ValueBase + + /** + * @class ValueBase_var + * + * @brief _var class for ValueBase + */ + class TAO_Valuetype_Export ValueBase_var + { + public: + ValueBase_var (void); + ValueBase_var (CORBA::ValueBase *); + ValueBase_var (const ValueBase_var &); + ~ValueBase_var (void); + + ValueBase_var &operator= (CORBA::ValueBase *); + ValueBase_var &operator= (const ValueBase_var &); + CORBA::ValueBase *operator-> (void) const; + + operator const CORBA::ValueBase *() const; + operator CORBA::ValueBase *&(); + + /// in, inout, out, _retn + CORBA::ValueBase *in (void) const; + CORBA::ValueBase *&inout (void); + CORBA::ValueBase *&out (void); + CORBA::ValueBase *_retn (void); + CORBA::ValueBase *ptr (void) const; + + static CORBA::ValueBase * tao_duplicate (CORBA::ValueBase *); + static void tao_release (CORBA::ValueBase *); + static CORBA::ValueBase * tao_nil (void); + static CORBA::ValueBase * tao_narrow (CORBA::ValueBase * + ACE_ENV_ARG_DECL_NOT_USED); + static CORBA::ValueBase * tao_upcast (void *); + + private: + CORBA::ValueBase *ptr_; + }; + + /** + * @class ValueBase_out + * + * @brief _out class for CORBA::ValueBase + * + * _out class for CORBA::ValueBase + */ + class TAO_Valuetype_Export ValueBase_out + { + public: + ValueBase_out (CORBA::ValueBase *&); + ValueBase_out (ValueBase_var &); + ValueBase_out (const ValueBase_out &); + ValueBase_out &operator= (const ValueBase_out &); + ValueBase_out &operator= (const ValueBase_var &); + ValueBase_out &operator= (CORBA::ValueBase *); + operator CORBA::ValueBase *&(); + CORBA::ValueBase *&ptr (void); + CORBA::ValueBase *operator-> (void); + + private: + CORBA::ValueBase *&ptr_; + }; + + /** + * @class DefaultValueRefCountBase + * + * @brief Default mix-in for reference count of a valuetype. + * + * Default mix-in for reference count of a valuetype. + */ + class TAO_Valuetype_Export DefaultValueRefCountBase + : public virtual ValueBase + { + public: + virtual void _add_ref (void); + virtual void _remove_ref (void); + virtual CORBA::ULong _refcount_value (void); + + /// The _tao variants are inline for fast access from T_var + /// (if valuetype T is compiled with optimization for that.) %! (todo) + void _tao_add_ref (void); + void _tao_remove_ref (void); + CORBA::ULong _tao_refcount_value (void); + + protected: + DefaultValueRefCountBase (void); + DefaultValueRefCountBase (const DefaultValueRefCountBase&); + virtual ~DefaultValueRefCountBase (); + + private: + void operator= (const DefaultValueRefCountBase &); + + private: // data + CORBA::ULong _tao_reference_count_; + TAO_SYNCH_MUTEX _tao_reference_count_lock_; + }; // DefaultValueRefCountBase + + // which lock has the lowest memory overhead ? + // %! todo refcountbase w/o locking (now memory overhead) + // $! todo: debug aids for refcounts + +} // End CORBA namespace + +/** + * @class TAO_OBV_GIOP_Flags + * + * @brief TAO_OBV_GIOP_Flags + * + * @see CORBA 2.3 -- Section 15.3.4 + */ +class TAO_Valuetype_Export TAO_OBV_GIOP_Flags +{ +public: + static const CORBA::ULong Value_tag_base; + static const CORBA::ULong Value_tag_sigbits; + static const CORBA::ULong Codebase_url; + static const CORBA::ULong Type_info_sigbits; + static const CORBA::ULong Type_info_none; + static const CORBA::ULong Type_info_single; + static const CORBA::ULong Type_info_list; + + static CORBA::Boolean is_null_ref (CORBA::ULong); + static CORBA::Boolean is_value_tag (CORBA::ULong); + static CORBA::Boolean has_codebase_url (CORBA::ULong); + static CORBA::Boolean has_no_type_info (CORBA::ULong); + static CORBA::Boolean has_single_type_info (CORBA::ULong); + static CORBA::Boolean has_list_type_info (CORBA::ULong); + static CORBA::Boolean is_chunked (CORBA::ULong); + static CORBA::Boolean is_indirection_tag (CORBA::ULong); + static CORBA::Boolean is_indirection (CORBA::ULong); + static CORBA::Boolean is_block_size (CORBA::ULong); + static CORBA::Boolean is_end_tag (CORBA::ULong); +}; + +TAO_Valuetype_Export CORBA::Boolean +operator<< (TAO_OutputCDR&, const CORBA::ValueBase *); + +TAO_Valuetype_Export CORBA::Boolean +operator>> (TAO_InputCDR&, CORBA::ValueBase *&); + +#if defined (__ACE_INLINE__) +# include "ValueBase.inl" +#endif /* __ACE_INLINE__*/ + +#include "ace/post.h" + +#endif /* TAO_VALUEBASE_H */ diff --git a/TAO/tao/Valuetype/ValueBase.inl b/TAO/tao/Valuetype/ValueBase.inl new file mode 100644 index 00000000000..856382644e2 --- /dev/null +++ b/TAO/tao/Valuetype/ValueBase.inl @@ -0,0 +1,349 @@ +// This may not look like C++, but it's really -*- C++ -*- +// +// $Id$ + +// static operations in namespace CORBA ======================== + +ACE_INLINE void +CORBA::add_ref (CORBA::ValueBase *val) +{ + if (val) + { + val->_add_ref (); + } +} + +ACE_INLINE void +CORBA::remove_ref (CORBA::ValueBase *val) +{ + if (val) + { + val->_remove_ref (); + } +} + +// =========================================================== + +// constructor +ACE_INLINE +CORBA::ValueBase::ValueBase (void) +{ +} + +// ************************************************************* +// Inline operations for class CORBA::ValueBase_var +// ************************************************************* + +ACE_INLINE +CORBA::ValueBase_var::ValueBase_var (void) + : ptr_ (0) +{ +} + +ACE_INLINE +CORBA::ValueBase_var::ValueBase_var (CORBA::ValueBase *p) + : ptr_ (p) +{ +} + +ACE_INLINE +CORBA::ValueBase_var::~ValueBase_var (void) +{ + CORBA::remove_ref (this->ptr_); +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::ptr (void) const +{ + return this->ptr_; +} + +ACE_INLINE +CORBA::ValueBase_var::ValueBase_var (const CORBA::ValueBase_var &p) + : ptr_ (p.ptr_) +{ + p.ptr_->_add_ref (); +} + +ACE_INLINE CORBA::ValueBase_var & +CORBA::ValueBase_var::operator= (CORBA::ValueBase *p) +{ + CORBA::remove_ref (this->ptr_); + this->ptr_ = p; + return *this; +} + +ACE_INLINE CORBA::ValueBase_var & +CORBA::ValueBase_var::operator= (const CORBA::ValueBase_var &p) +{ + if (this != &p) + { + CORBA::remove_ref (this->ptr_); + p.ptr_->_add_ref (); + this->ptr_ = p.ptr_; + } + + return *this; +} + +ACE_INLINE +CORBA::ValueBase_var::operator const CORBA::ValueBase *() const // cast +{ + return this->ptr_; +} + +ACE_INLINE +CORBA::ValueBase_var::operator CORBA::ValueBase *&() // cast +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::operator-> (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::in (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase *& +CORBA::ValueBase_var::inout (void) +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase *& +CORBA::ValueBase_var::out (void) +{ + CORBA::remove_ref (this->ptr_); + this->ptr_ = 0; + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::_retn (void) +{ + // Yield ownership of valuebase. + CORBA::ValueBase *val = this->ptr_; + this->ptr_ = 0; + return val; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::tao_duplicate (CORBA::ValueBase *p) +{ + p->_add_ref (); + return p; +} + +ACE_INLINE void +CORBA::ValueBase_var::tao_release (CORBA::ValueBase *p) +{ + p->_remove_ref (); +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::tao_nil (void) +{ + return 0; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::tao_narrow ( + CORBA::ValueBase *p + ACE_ENV_ARG_DECL_NOT_USED + ) +{ + p->_add_ref (); + return CORBA::ValueBase::_downcast (p); +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_var::tao_upcast (void *src) +{ + CORBA::ValueBase **tmp = + ACE_static_cast (CORBA::ValueBase **, src); + return *tmp; +} + +// ************************************************************* +// Inline operations for class CORBA::ValueBase_out +// ************************************************************* + +ACE_INLINE +CORBA::ValueBase_out::ValueBase_out (CORBA::ValueBase *&p) + : ptr_ (p) +{ + this->ptr_ = 0; +} + +ACE_INLINE +CORBA::ValueBase_out::ValueBase_out (CORBA::ValueBase_var &p) + : ptr_ (p.out ()) +{ + this->ptr_->_remove_ref (); + this->ptr_ = 0; +} + +ACE_INLINE +CORBA::ValueBase_out::ValueBase_out (const CORBA::ValueBase_out &p) + : ptr_ (p.ptr_) +{ +} + +ACE_INLINE CORBA::ValueBase_out & +CORBA::ValueBase_out::operator= (const CORBA::ValueBase_out &p) +{ + this->ptr_ = p.ptr_; + return *this; +} + +ACE_INLINE CORBA::ValueBase_out & +CORBA::ValueBase_out::operator= (const CORBA::ValueBase_var &p) +{ + p.ptr ()->_add_ref (); + this->ptr_ = p.ptr (); + return *this; +} + +ACE_INLINE CORBA::ValueBase_out & +CORBA::ValueBase_out::operator= (CORBA::ValueBase *p) +{ + this->ptr_ = p; + return *this; +} + +ACE_INLINE +CORBA::ValueBase_out::operator CORBA::ValueBase *&() // cast +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase *& +CORBA::ValueBase_out::ptr (void) // ptr +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueBase * +CORBA::ValueBase_out::operator-> (void) +{ + return this->ptr_; +} + +// =========================================================== + +// constructor +ACE_INLINE +CORBA::DefaultValueRefCountBase::DefaultValueRefCountBase (void) + : _tao_reference_count_ (1) +{ +} + + +ACE_INLINE void +CORBA::DefaultValueRefCountBase::_tao_add_ref (void) +{ + ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); + ++_tao_reference_count_; +} + +ACE_INLINE void +CORBA::DefaultValueRefCountBase::_tao_remove_ref (void) +{ + { + ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); + -- this->_tao_reference_count_; + if (this->_tao_reference_count_ != 0) + return; + } + // The guard has been already given up, but this is no problem + // cause we have held the last reference, and this one we don't give + // away anymore, we do: + delete this; +} + +ACE_INLINE CORBA::ULong +CORBA::DefaultValueRefCountBase::_tao_refcount_value (void) +{ + ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, + guard, + this->_tao_reference_count_lock_, + 0); + return _tao_reference_count_; +} + +// =========================================================== + +// Detection of flags in the CDR Stream + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_null_ref (CORBA::ULong tag) +{ + return (tag == 0); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_value_tag (CORBA::ULong tag) +{ + return ((tag & Value_tag_sigbits) == 0x7FFFFF00L); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags:: has_codebase_url (CORBA::ULong tag) +{ + return (CORBA::Boolean) (tag & Codebase_url); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::has_no_type_info (CORBA::ULong tag) +{ + return ((tag & Type_info_sigbits) == Type_info_none); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::has_single_type_info (CORBA::ULong tag) +{ + return ((tag & Type_info_sigbits) == Type_info_single); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::has_list_type_info (CORBA::ULong tag) +{ + return ((tag & Type_info_sigbits) == Type_info_list); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags:: is_chunked (CORBA::ULong tag) +{ + return (CORBA::Boolean) (tag & 8); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_indirection_tag (CORBA::ULong tag) +{ + return (tag == 0xFFFFFFFFL); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_indirection (CORBA::ULong value) +{ + return (0x80000000L < value && value <= (0xFFFFFFFFL - 4)); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_block_size (CORBA::ULong value) +{ + return ( 0 < value && value < 0x7fffff00L); +} + +ACE_INLINE CORBA::Boolean +TAO_OBV_GIOP_Flags::is_end_tag (CORBA::ULong tag) +{ + return (0x80000000L < tag && tag <= 0xFFFFFFFFL); +} + diff --git a/TAO/tao/Valuetype/ValueFactory.cpp b/TAO/tao/Valuetype/ValueFactory.cpp new file mode 100644 index 00000000000..f0c1e682fad --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory.cpp @@ -0,0 +1,23 @@ +#include "ValueFactory.h" + +#if !defined (__ACE_INLINE__) +# include "ValueFactory.inl" +#endif /* ! __ACE_INLINE__ */ + + +ACE_RCSID (tao, + ValueFactory, + "$Id$") + + +CORBA::ValueFactoryBase::~ValueFactoryBase (void) +{ +} + +// No-op. This should never be called, but it can't be pure virtual. +CORBA::AbstractBase * +CORBA::ValueFactoryBase::create_for_unmarshal_abstract (void) +{ + return 0; +} + diff --git a/TAO/tao/Valuetype/ValueFactory.h b/TAO/tao/Valuetype/ValueFactory.h new file mode 100644 index 00000000000..10292c05f68 --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory.h @@ -0,0 +1,121 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file ValueFactory.h + * + * $Id$ + * + * @author Torsten Kuepper + */ +//============================================================================= + + +#ifndef TAO_VALUEFACTORY_H +#define TAO_VALUEFACTORY_H +#include "ace/pre.h" + +#include "valuetype_export.h" +#include "tao/corbafwd.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Synch_T.h" + +namespace CORBA +{ + class TAO_Valuetype_Export ValueFactoryBase + { + public: + ValueFactoryBase (void); + virtual ~ValueFactoryBase (void); + + // non-virtual is non-standard + void _add_ref (void); + void _remove_ref (void); + + // private: %! + /// In a derived class T use return type TAO_OBV_CREATE_RETURN_TYPE (T) + /// (see at definition below) + virtual CORBA::ValueBase * create_for_unmarshal (void) = 0; + + // Not pure virtual because this will be overridden only by valuetypes + // that support an abstract interface. + virtual CORBA::AbstractBase * create_for_unmarshal_abstract (void); + + private: + CORBA::ULong _tao_reference_count_; + TAO_SYNCH_MUTEX _tao_reference_count_lock_; + }; + + /** + * @class ValueFactoryBase_var + * + * @brief _var class for ValueFactoryBase + */ + class TAO_Valuetype_Export ValueFactoryBase_var + { + public: + ValueFactoryBase_var (void); + ValueFactoryBase_var (CORBA::ValueFactoryBase *); + ValueFactoryBase_var (const ValueFactoryBase_var &); + ~ValueFactoryBase_var (void); + + ValueFactoryBase_var &operator= (CORBA::ValueFactoryBase *); + ValueFactoryBase_var &operator= (const ValueFactoryBase_var &); + CORBA::ValueFactoryBase *operator-> (void) const; + + /// in, inout, out, _retn + CORBA::ValueFactoryBase *in (void) const; + CORBA::ValueFactoryBase *&inout (void); + CORBA::ValueFactoryBase *&out (void); + CORBA::ValueFactoryBase *_retn (void); + CORBA::ValueFactoryBase *ptr (void) const; + + private: + CORBA::ValueFactoryBase *ptr_; + }; + +} // End CORBA namespace + +// Use this macro for writing code that is independend from +// the compiler support of covariant return types of pointers to +// virtual inherited classes. +// (e.g. in egcs-2.90.29 980515 (egcs-1.0.3 release) its not yet implemented) +// (But it is TAO specific and at the moment the covariant case is not +// elaborated --- its just a suggestion.) + +#ifdef TAO_HAS_OBV_COVARIANT_RETURN +# define TAO_OBV_CREATE_RETURN_TYPE(TYPE) TYPE * +#else /* TAO_HAS_OBV_COVARIANT_RETURN */ +# define TAO_OBV_CREATE_RETURN_TYPE(TYPE) CORBA::ValueBase * +#endif /* TAO_HAS_OBV_COVARIANT_RETURN */ + +// (The obtaining of the repository id is currently not yet like the OMG way. %!) +// +// Macro for on the fly registration of a factory (with type Factory). +// The repository id is taken from the static repository id of the +// valuetype via tao_repository_id () of the specialized factory. +// It forgets the pre-registered factory (if any) and the reference +// to the newly created one. (A new reference could be obtained with +// orb->lookup_value_factory (char * repo_id) .) + +#define TAO_OBV_REGISTER_FACTORY(FACTORY, VALUETYPE) \ + { CORBA::ValueFactory factory = new FACTORY; \ + CORBA::ValueFactory prev_factory = \ + TAO_ORB_Core_instance ()->orb ()->register_value_factory (\ + VALUETYPE::_tao_obv_static_repository_id (),\ + factory); \ + if (prev_factory) prev_factory->_remove_ref (); \ + factory->_remove_ref (); } + + +#if defined (__ACE_INLINE__) +# include "ValueFactory.inl" +#endif /* __ACE_INLINE__) */ + +#include "ace/post.h" + +#endif /* TAO_VALUEFACTORY_H */ diff --git a/TAO/tao/Valuetype/ValueFactory.inl b/TAO/tao/Valuetype/ValueFactory.inl new file mode 100644 index 00000000000..bbb6ad561fe --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory.inl @@ -0,0 +1,139 @@ +// -*- C++ -*- +// +// $Id$ + +ACE_INLINE +CORBA::ValueFactoryBase::ValueFactoryBase (void) + : _tao_reference_count_ (1) +{ +} + +ACE_INLINE void +CORBA::ValueFactoryBase::_add_ref (void) +{ + ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); + ++_tao_reference_count_; +} + +ACE_INLINE void +CORBA::ValueFactoryBase::_remove_ref (void) +{ + { + ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->_tao_reference_count_lock_); + -- this->_tao_reference_count_; + if (this->_tao_reference_count_ != 0) + return; + } + delete this; +} + +// ************************************************************* +// Inline operations for class CORBA::ValueFactoryBase_var +// ************************************************************* + +ACE_INLINE +CORBA::ValueFactoryBase_var::ValueFactoryBase_var (void) + : ptr_ (0) +{ +} + +ACE_INLINE +CORBA::ValueFactoryBase_var::ValueFactoryBase_var ( + CORBA::ValueFactoryBase *p + ) + : ptr_ (p) +{ +} + +ACE_INLINE +CORBA::ValueFactoryBase_var::~ValueFactoryBase_var (void) +{ + if (this->ptr_ != 0) + { + this->ptr_->_remove_ref (); + } +} + +ACE_INLINE CORBA::ValueFactoryBase * +CORBA::ValueFactoryBase_var::ptr (void) const +{ + return this->ptr_; +} + +ACE_INLINE +CORBA::ValueFactoryBase_var::ValueFactoryBase_var ( + const CORBA::ValueFactoryBase_var &p + ) + : ptr_ (p.ptr_) +{ + p.ptr_->_add_ref (); +} + +ACE_INLINE CORBA::ValueFactoryBase_var & +CORBA::ValueFactoryBase_var::operator= (CORBA::ValueFactoryBase *p) +{ + if (this->ptr_ != 0) + { + this->ptr_->_remove_ref (); + } + + this->ptr_ = p; + return *this; +} + +ACE_INLINE CORBA::ValueFactoryBase_var & +CORBA::ValueFactoryBase_var::operator= (const CORBA::ValueFactoryBase_var &p) +{ + if (this != &p) + { + if (this->ptr_ != 0) + { + this->ptr_->_remove_ref (); + } + + p.ptr_->_add_ref (); + this->ptr_ = p.ptr_; + } + + return *this; +} + +ACE_INLINE CORBA::ValueFactoryBase * +CORBA::ValueFactoryBase_var::operator-> (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueFactoryBase * +CORBA::ValueFactoryBase_var::in (void) const +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueFactoryBase *& +CORBA::ValueFactoryBase_var::inout (void) +{ + return this->ptr_; +} + +ACE_INLINE CORBA::ValueFactoryBase *& +CORBA::ValueFactoryBase_var::out (void) +{ + if (this->ptr_ != 0) + { + this->ptr_->_remove_ref (); + } + + this->ptr_ = 0; + return this->ptr_; +} + +ACE_INLINE CORBA::ValueFactoryBase * +CORBA::ValueFactoryBase_var::_retn (void) +{ + // Yield ownership of valuebase. + CORBA::ValueFactoryBase *val = this->ptr_; + this->ptr_ = 0; + return val; +} + diff --git a/TAO/tao/Valuetype/ValueFactory_Map.cpp b/TAO/tao/Valuetype/ValueFactory_Map.cpp new file mode 100644 index 00000000000..068e8c9c50e --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory_Map.cpp @@ -0,0 +1,130 @@ +#include "ValueFactory_Map.h" +#include "ValueFactory.h" + +#if !defined (__ACE_INLINE__) +# include "ValueFactory_Map.inl" +#endif /* ! __ACE_INLINE__ */ + + +ACE_RCSID (tao, + ValueFactory_Map, + "$Id$") + + +TAO_ValueFactory_Map::TAO_ValueFactory_Map (void) + : map_ (TAO_DEFAULT_VALUE_FACTORY_TABLE_SIZE) +{ +} + +TAO_ValueFactory_Map::~TAO_ValueFactory_Map (void) +{ + // Initialize an iterator. We need to go thru each entry and free + // up storage allocated to hold the external ids and invoke + // _remove_ref () on the internal ids. + FACTORY_MAP_MANAGER::ITERATOR iterator (this->map_); + + for (FACTORY_MAP_MANAGER::ENTRY *entry = 0; + iterator.next (entry) != 0; + iterator.advance ()) + { + // We had allocated memory and stored the string. So we free the + // memory. + CORBA::string_free ((char *) entry->ext_id_); + entry->ext_id_ = 0; + entry->int_id_->_remove_ref (); + entry->int_id_ = 0; + } +} + +// %! Thread issues + +int +TAO_ValueFactory_Map::rebind (const char *repo_id, + CORBA::ValueFactory &factory) +{ +// ACE_READ_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, map_->mutex(),-1); +// --- but must be recursive + const char *prev_repo_id; + CORBA::ValueFactory prev_factory; + int ret = 0; + ret = this->map_.rebind (CORBA::string_dup (repo_id), + factory, + prev_repo_id, + prev_factory); + + if (ret > -1) // ok, no error + { + factory->_add_ref (); // The map owns one reference. + + if (ret == 1) // there was a previous factory + { + factory = prev_factory; + CORBA::string_free (ACE_const_cast(char*,prev_repo_id)); + } + } + + return ret; +} + +int +TAO_ValueFactory_Map::unbind (const char *repo_id, + CORBA::ValueFactory &factory) +{ + FACTORY_MAP_MANAGER::ENTRY *prev_entry; + int ret = 0; + ret = this->map_.find (repo_id, + prev_entry); + if (ret == 0) // there was a matching factory + { + // set factory to the previous factory, + factory = prev_entry->int_id_; + char *temp = ACE_const_cast (char *, prev_entry->ext_id_); + ret = this->map_.unbind (prev_entry); + + if (ret == 0) + { + CORBA::string_free (temp); + } + } + + return ret; +} + +// %! perhaps inline +int +TAO_ValueFactory_Map::find (const char *repo_id, + CORBA::ValueFactory &factory) +{ + int ret = 0; + ret = this->map_.find (repo_id, + factory); + // %! this must be guarded to be atomic !!!!!!!!!!!!!!!!!! + if (ret > -1) + { + factory->_add_ref (); // The caller gets one reference as gift. + } + + return ret; +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; +template class ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; +template class ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; +template class ACE_Hash_Map_Manager_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX>; +template class ACE_Hash_Map_Entry; +template class TAO_Singleton; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Hash_Map_Manager_Ex, ACE_Equal_To, TAO_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Hash_Map_Entry +#pragma instantiate TAO_Singleton + +#elif defined (__GNUC__) && (defined (_AIX) || defined (__hpux) || defined (VXWORKS)) +template TAO_Singleton * TAO_Singleton::singleton_; + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + diff --git a/TAO/tao/Valuetype/ValueFactory_Map.h b/TAO/tao/Valuetype/ValueFactory_Map.h new file mode 100644 index 00000000000..c2b81528567 --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory_Map.h @@ -0,0 +1,90 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file ValueFactory_Map.h + * + * $Id$ + * + * @author Torsten Kuepper + */ +//============================================================================= + + +#ifndef TAO_VALUEFACTORY_MAP_H +#define TAO_VALUEFACTORY_MAP_H +#include "ace/pre.h" + +#include "tao/corbafwd.h" +#include "tao/TAO_Singleton.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Hash_Map_Manager_T.h" +#include "ace/Synch.h" + +class TAO_ValueFactory_Map +{ +public: + + TAO_ValueFactory_Map (void); + ~TAO_ValueFactory_Map (void); + + /** + * Associate the factory (int_id) with the repo_id (ext_id). + * Invokes _add_ref () on the factory. + * If previous factory had been bind with this repo_id, this one is + * returned in factory (and the caller holds a reference). + * Returns -1 on failure, 0 on success and 1 if a previous factory + * is found (and returned in factory). + */ + int rebind (const char *repo_id, + CORBA::ValueFactory &factory); + + /// Removes entry for repo_id from the map and sets factory to + /// the tied one. + int unbind (const char *repo_id, + CORBA::ValueFactory &factory); + + /** + * Lookup a matching factory for repo_id. + * Invokes _add_ref () on the factory if found. + * Returns -1 on failure and 0 on success. + */ + int find (const char *repo_id, + CORBA::ValueFactory &factory); + + void dump (void); + +private: + + /// The hash table data structure. + typedef ACE_Hash_Map_Manager_Ex, + ACE_Equal_To, + TAO_SYNCH_RW_MUTEX> + FACTORY_MAP_MANAGER; + FACTORY_MAP_MANAGER map_; +}; /* TAO_ValueFactory_Map */ + + +// Currently the ValueFactory_Map is a singleton and not per ORB +// as in the OMG spec. +typedef TAO_Singleton + TAO_VALUEFACTORY_MAP; + +TAO_VALUETYPE_SINGLETON_DECLARE (TAO_Singleton, + TAO_ValueFactory_Map, + TAO_SYNCH_MUTEX) + + +#if defined (__ACE_INLINE__) +# include "ValueFactory_Map.inl" +#endif /* __ACE_INLINE__) */ + +#include "ace/post.h" + +#endif /* TAO_VALUEFACTORY_MAP_H */ diff --git a/TAO/tao/Valuetype/ValueFactory_Map.inl b/TAO/tao/Valuetype/ValueFactory_Map.inl new file mode 100644 index 00000000000..cfa1da318d3 --- /dev/null +++ b/TAO/tao/Valuetype/ValueFactory_Map.inl @@ -0,0 +1 @@ +// $Id$ diff --git a/TAO/tao/Valuetype/Valuetype_Adapter_Impl.cpp b/TAO/tao/Valuetype/Valuetype_Adapter_Impl.cpp index eea8bb2a77d..5990001b91b 100644 --- a/TAO/tao/Valuetype/Valuetype_Adapter_Impl.cpp +++ b/TAO/tao/Valuetype/Valuetype_Adapter_Impl.cpp @@ -2,6 +2,8 @@ #include "Valuetype_Adapter_Impl.h" #include "AbstractBase.h" +#include "ValueBase.h" +#include "ValueFactory_Map.h" #include "tao/ORB_Core.h" ACE_RCSID (Valuetype, @@ -19,6 +21,36 @@ TAO_Valuetype_Adapter_Impl::abstractbase_to_object ( { return p->_to_object (); } + +CORBA::ULong +TAO_Valuetype_Adapter_Impl::type_info_single (void) const +{ + return TAO_OBV_GIOP_Flags::Type_info_single; +} + +TAO_ValueFactory_Map * +TAO_Valuetype_Adapter_Impl::valuefactory_map_instance (void) +{ + return TAO_VALUEFACTORY_MAP::instance (); +} + +int +TAO_Valuetype_Adapter_Impl::vf_map_rebind (TAO_ValueFactory_Map *map, + const char *repo_id, + CORBA::ValueFactory &factory) +{ + return map->rebind (repo_id, + factory); +} + +int +TAO_Valuetype_Adapter_Impl::vf_map_find (TAO_ValueFactory_Map *map, + const char *repo_id, + CORBA::ValueFactory &factory) +{ + return map->find (repo_id, + factory); +} // ********************************************************************* diff --git a/TAO/tao/Valuetype/Valuetype_Adapter_Impl.h b/TAO/tao/Valuetype/Valuetype_Adapter_Impl.h index c46489e4da7..8a7ca834c1c 100644 --- a/TAO/tao/Valuetype/Valuetype_Adapter_Impl.h +++ b/TAO/tao/Valuetype/Valuetype_Adapter_Impl.h @@ -39,8 +39,20 @@ public: virtual ~TAO_Valuetype_Adapter_Impl (void); virtual CORBA::Object_ptr abstractbase_to_object ( - CORBA::AbstractBase_ptr p + CORBA::AbstractBase_ptr ); + + virtual CORBA::ULong type_info_single (void) const; + + virtual TAO_ValueFactory_Map *valuefactory_map_instance (void); + + virtual int vf_map_rebind (TAO_ValueFactory_Map *, + const char *, + CORBA::ValueFactory &); + + virtual int vf_map_find (TAO_ValueFactory_Map *, + const char *, + CORBA::ValueFactory &); // Used to force the initialization of the ORB code. static int Initializer (void); diff --git a/TAO/tao/Valuetype_Adapter.h b/TAO/tao/Valuetype_Adapter.h index 80b7ea5b21f..9c9c4b8f5a6 100644 --- a/TAO/tao/Valuetype_Adapter.h +++ b/TAO/tao/Valuetype_Adapter.h @@ -16,12 +16,15 @@ #include "ace/pre.h" #include "ace/Service_Object.h" -#include "tao/corbafwd.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "tao/corbafwd.h" + +class TAO_ValueFactory_Map; + /** * @class TAO_Valuetype_Adapter * @@ -39,6 +42,18 @@ public: virtual CORBA::Object_ptr abstractbase_to_object ( CORBA::AbstractBase_ptr p ) = 0; + + virtual CORBA::ULong type_info_single (void) const = 0; + + virtual TAO_ValueFactory_Map * valuefactory_map_instance (void) = 0; + + virtual int vf_map_rebind (TAO_ValueFactory_Map *, + const char *, + CORBA::ValueFactory &) = 0; + + virtual int vf_map_find (TAO_ValueFactory_Map *, + const char *, + CORBA::ValueFactory &) = 0; }; #include "ace/post.h" diff --git a/TAO/tao/append.cpp b/TAO/tao/append.cpp index 8bec4e4467b..e380ddeb30f 100644 --- a/TAO/tao/append.cpp +++ b/TAO/tao/append.cpp @@ -23,8 +23,11 @@ #include "tao/CDR.h" #include "tao/Environment.h" #include "tao/Any.h" -#include "tao/ValueBase.h" #include "tao/debug.h" +#include "tao/Valuetype_Adapter.h" +#include "tao/ORB_Core.h" + +#include "ace/Dynamic_Service.h" ACE_RCSID (tao, append, @@ -1190,12 +1193,23 @@ TAO_Marshal_Value::append (CORBA::TypeCode_ptr tc, return CORBA::TypeCode::TRAVERSE_STOP; } + TAO_Valuetype_Adapter *adapter = + ACE_Dynamic_Service::instance ( + TAO_ORB_Core::valuetype_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::TRAVERSE_STOP); + } + if (value_tag == 0) // Null value type pointer. { //We are done. return retval; } - else if (value_tag & TAO_OBV_GIOP_Flags::Type_info_single) + else if (value_tag & adapter->type_info_single ()) { // Append repository id which is of type string. dest->append_string (*src); @@ -1210,6 +1224,7 @@ TAO_Marshal_Value::append (CORBA::TypeCode_ptr tc, // Handle our base valuetype if any. param = tc->concrete_base_type (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + if (param->kind () != CORBA::tk_null) { retval = this->append (param.in (), diff --git a/TAO/tao/corba.h b/TAO/tao/corba.h index 0070c100439..0de306566b4 100644 --- a/TAO/tao/corba.h +++ b/TAO/tao/corba.h @@ -51,8 +51,6 @@ #include "tao/CurrentC.h" #include "tao/BoundsC.h" -#include "tao/ValueBase.h" -#include "tao/ValueFactory.h" #include "tao/PolicyC.h" #include "tao/ServicesC.h" #include "tao/DomainC.h" diff --git a/TAO/tao/skip.cpp b/TAO/tao/skip.cpp index d66e3a71bfd..b62e2b7c114 100644 --- a/TAO/tao/skip.cpp +++ b/TAO/tao/skip.cpp @@ -23,8 +23,11 @@ #include "tao/CDR.h" #include "tao/Any.h" #include "tao/Environment.h" -#include "tao/ValueBase.h" #include "tao/debug.h" +#include "tao/Valuetype_Adapter.h" +#include "tao/ORB_Core.h" + +#include "ace/Dynamic_Service.h" ACE_RCSID (tao, @@ -948,12 +951,23 @@ TAO_Marshal_Value::skip (CORBA::TypeCode_ptr tc, return CORBA::TypeCode::TRAVERSE_STOP; } + TAO_Valuetype_Adapter *adapter = + ACE_Dynamic_Service::instance ( + TAO_ORB_Core::valuetype_adapter_name () + ); + + if (adapter == 0) + { + ACE_THROW_RETURN (CORBA::INTERNAL (), + CORBA::TypeCode::TRAVERSE_STOP); + } + if (value_tag == 0) // Null value type pointer. { //We are done. return retval; } - else if (value_tag & TAO_OBV_GIOP_Flags::Type_info_single) + else if (value_tag & adapter->type_info_single ()) { // Skip a single repository id which is of type string. stream->skip_string (); @@ -968,6 +982,7 @@ TAO_Marshal_Value::skip (CORBA::TypeCode_ptr tc, // Handle our base valuetype if any. param = tc->concrete_base_type (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (CORBA::TypeCode::TRAVERSE_STOP); + if (param->kind () != CORBA::tk_null) { retval = this->skip (param.in (), stream ACE_ENV_ARG_PARAMETER); -- cgit v1.2.1