Go to the documentation of this file.00001 #include "tao/Valuetype/ValueFactory_Map.h"
00002 #include "tao/Valuetype/ValueFactory.h"
00003 #include "tao/CORBA_String.h"
00004
00005 ACE_RCSID (Valuetype,
00006 ValueFactory_Map,
00007 "$Id: ValueFactory_Map.cpp 78787 2007-07-05 08:02:28Z johnnyw $")
00008
00009 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 TAO_ValueFactory_Map::TAO_ValueFactory_Map (void)
00012 : map_ (TAO_DEFAULT_VALUE_FACTORY_TABLE_SIZE)
00013 {
00014 }
00015
00016 TAO_ValueFactory_Map::~TAO_ValueFactory_Map (void)
00017 {
00018
00019
00020
00021 FACTORY_MAP_MANAGER::ITERATOR iterator (this->map_);
00022
00023 for (FACTORY_MAP_MANAGER::ENTRY *entry = 0;
00024 iterator.next (entry) != 0;
00025 iterator.advance ())
00026 {
00027
00028
00029 CORBA::string_free ((char *) entry->ext_id_);
00030 entry->ext_id_ = 0;
00031 entry->int_id_->_remove_ref ();
00032 entry->int_id_ = 0;
00033 }
00034 }
00035
00036 int
00037 TAO_ValueFactory_Map::rebind (const char *repo_id,
00038 CORBA::ValueFactory &factory)
00039 {
00040 ACE_GUARD_RETURN(TAO_SYNCH_MUTEX, guard, this->mutex_, -1);
00041
00042 const char *prev_repo_id = 0;
00043 CORBA::ValueFactory prev_factory = 0;
00044 int const ret = this->map_.rebind (CORBA::string_dup (repo_id),
00045 factory,
00046 prev_repo_id,
00047 prev_factory);
00048
00049 if (ret > -1)
00050 {
00051 factory->_add_ref ();
00052
00053 if (ret == 1)
00054 {
00055 factory = prev_factory;
00056 CORBA::string_free (const_cast<char*> (prev_repo_id));
00057 }
00058 }
00059
00060 return ret;
00061 }
00062
00063 int
00064 TAO_ValueFactory_Map::unbind (const char *repo_id,
00065 CORBA::ValueFactory &factory)
00066 {
00067 ACE_GUARD_RETURN(TAO_SYNCH_MUTEX, guard, this->mutex_, -1);
00068
00069 FACTORY_MAP_MANAGER::ENTRY *prev_entry = 0;
00070 int ret = this->map_.find (repo_id, prev_entry);
00071
00072 if (ret == 0)
00073 {
00074
00075 factory = prev_entry->int_id_;
00076 char *temp = const_cast<char *> (prev_entry->ext_id_);
00077 ret = this->map_.unbind (prev_entry);
00078
00079 if (ret == 0)
00080 {
00081 CORBA::string_free (temp);
00082 }
00083 }
00084
00085 return ret;
00086 }
00087
00088
00089 int
00090 TAO_ValueFactory_Map::find (const char *repo_id,
00091 CORBA::ValueFactory &factory)
00092 {
00093 ACE_GUARD_RETURN(TAO_SYNCH_MUTEX, guard, this->mutex_, -1);
00094
00095 int const ret = this->map_.find (repo_id, factory);
00096 if (ret > -1)
00097 {
00098 factory->_add_ref ();
00099 }
00100
00101 return ret;
00102 }
00103
00104 TAO_END_VERSIONED_NAMESPACE_DECL
00105