00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file ValueFactory.h 00006 * 00007 * $Id: ValueFactory.h 76995 2007-02-11 12:51:42Z johnnyw $ 00008 * 00009 * @author Torsten Kuepper <kuepper2@lfa.uni-wuppertal.de> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_VALUEFACTORY_H 00014 #define TAO_VALUEFACTORY_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/Valuetype/valuetype_export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "tao/Valuetype/Value_VarOut_T.h" 00025 00026 #include "tao/Basic_Types.h" 00027 #include "tao/orbconf.h" 00028 #include "ace/Synch_Traits.h" 00029 #include "ace/Thread_Mutex.h" 00030 #include "ace/Null_Mutex.h" 00031 #include "ace/Atomic_Op.h" 00032 00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00034 00035 namespace CORBA 00036 { 00037 class AbstractBase; 00038 typedef AbstractBase *AbstractBase_ptr; 00039 00040 class ValueBase; 00041 00042 class ValueFactoryBase; 00043 00044 extern TAO_Valuetype_Export void add_ref (ValueFactoryBase *); 00045 extern TAO_Valuetype_Export void remove_ref (ValueFactoryBase *); 00046 00047 typedef TAO_Value_Var_T<ValueFactoryBase> 00048 ValueFactoryBase_var; 00049 00050 typedef ValueFactoryBase_var ValueFactory_var; 00051 00052 class TAO_Valuetype_Export ValueFactoryBase 00053 { 00054 public: 00055 ValueFactoryBase (void); 00056 virtual ~ValueFactoryBase (void); 00057 00058 // non-virtual is non-standard 00059 void _add_ref (void); 00060 void _remove_ref (void); 00061 00062 // private: %! 00063 /// In a derived class T use return type TAO_OBV_CREATE_RETURN_TYPE (T) 00064 /// (see at definition below) 00065 virtual CORBA::ValueBase * create_for_unmarshal ( 00066 void) = 0; 00067 00068 // Not pure virtual because this will be overridden only by valuetypes 00069 // that support an abstract interface. 00070 virtual CORBA::AbstractBase_ptr create_for_unmarshal_abstract (void); 00071 00072 private: 00073 /// Reference counter. 00074 ACE_Atomic_Op<TAO_SYNCH_MUTEX, CORBA::ULong> _tao_reference_count_; 00075 }; 00076 00077 } // End CORBA namespace 00078 00079 namespace TAO 00080 { 00081 /** 00082 * @brief Specializations needed for using with Value_Var_T 00083 */ 00084 template<> 00085 struct TAO_Valuetype_Export Value_Traits<CORBA::ValueFactoryBase> 00086 { 00087 static void add_ref (CORBA::ValueFactoryBase *); 00088 static void remove_ref (CORBA::ValueFactoryBase *); 00089 00090 // For INOUT value type arguments, so they can use the same set 00091 // of arg classes as interfaces. 00092 static void release (CORBA::ValueFactoryBase *); 00093 }; 00094 } 00095 00096 TAO_END_VERSIONED_NAMESPACE_DECL 00097 00098 // Use this macro for writing code that is independent from 00099 // the compiler support of covariant return types of pointers to 00100 // virtual inherited classes. 00101 // (e.g. in egcs-2.90.29 980515 (egcs-1.0.3 release) its not yet implemented) 00102 // (But it is TAO specific and at the moment the covariant case is not 00103 // elaborated --- its just a suggestion.) 00104 00105 #ifdef TAO_HAS_OBV_COVARIANT_RETURN 00106 # define TAO_OBV_CREATE_RETURN_TYPE(TYPE) TYPE * 00107 #else /* TAO_HAS_OBV_COVARIANT_RETURN */ 00108 # define TAO_OBV_CREATE_RETURN_TYPE(TYPE) CORBA::ValueBase * 00109 #endif /* TAO_HAS_OBV_COVARIANT_RETURN */ 00110 00111 // (The obtaining of the repository id is currently not yet like the OMG way. %!) 00112 // 00113 // Macro for on the fly registration of a factory (with type Factory). 00114 // The repository id is taken from the static repository id of the 00115 // valuetype via tao_repository_id () of the specialized factory. 00116 // It forgets the pre-registered factory (if any) and the reference 00117 // to the newly created one. (A new reference could be obtained with 00118 // orb->lookup_value_factory (char * repo_id) .) 00119 00120 #define TAO_OBV_REGISTER_FACTORY(FACTORY, VALUETYPE) \ 00121 { CORBA::ValueFactory factory = new FACTORY; \ 00122 CORBA::ValueFactory prev_factory = \ 00123 TAO_ORB_Core_instance ()->orb ()->register_value_factory (\ 00124 VALUETYPE::_tao_obv_static_repository_id (),\ 00125 factory); \ 00126 if (prev_factory) prev_factory->_remove_ref (); \ 00127 factory->_remove_ref (); } 00128 00129 00130 #include /**/ "ace/post.h" 00131 00132 #endif /* TAO_VALUEFACTORY_H */