Go to the documentation of this file.00001
00002 #include "orbsvcs/Notify/MonitorControl/Control_Registry.h"
00003
00004 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00005
00006 TAO_Control_Registry*
00007 TAO_Control_Registry::instance (void)
00008 {
00009 return TAO_Singleton<TAO_Control_Registry, TAO_SYNCH_MUTEX>::instance ();
00010 }
00011
00012 TAO_Control_Registry::~TAO_Control_Registry (void)
00013 {
00014 ACE_WRITE_GUARD (TAO_SYNCH_RW_MUTEX, guard, this->mutex_);
00015
00016 Map::iterator itr (this->map_);
00017 Map::value_type* entry = 0;
00018
00019 while (itr.next (entry))
00020 {
00021 delete entry->item ();
00022 itr.advance ();
00023 }
00024 }
00025
00026 bool
00027 TAO_Control_Registry::add (TAO_NS_Control* type)
00028 {
00029 ACE_WRITE_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, this->mutex_, false);
00030
00031 if (type == 0)
00032 {
00033 throw Map_Error (Map_Error::MAP_ERROR_INVALID_VALUE);
00034 }
00035
00036 int status = this->map_.bind(type->name(), type);
00037
00038 if (status == -1)
00039 {
00040 throw Map_Error (Map_Error::MAP_ERROR_BIND_FAILURE);
00041 }
00042 else if (status == 0)
00043 {
00044
00045 this->name_cache_.length (0);
00046 }
00047
00048 return (status == 0);
00049 }
00050
00051 bool
00052 TAO_Control_Registry::remove (const ACE_CString& name)
00053 {
00054 ACE_WRITE_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, this->mutex_, false);
00055
00056 Map::data_type type = 0;
00057 int status = this->map_.unbind(name, type);
00058
00059 if (status != 0)
00060 {
00061 return false;
00062 }
00063
00064
00065 this->name_cache_.length (0);
00066 delete type;
00067 return true;
00068 }
00069
00070 const TAO_Control_Registry::NameList&
00071 TAO_Control_Registry::names (void)
00072 {
00073 if (this->name_cache_.length () == 0)
00074 {
00075 ACE_WRITE_GUARD_RETURN (TAO_SYNCH_RW_MUTEX,
00076 guard,
00077 this->mutex_,
00078 this->name_cache_);
00079
00080 if (this->name_cache_.length () == 0)
00081 {
00082 CORBA::ULong length = 0;
00083 Map::iterator itr (this->map_);
00084 Map::value_type* entry = 0;
00085
00086 while (itr.next (entry))
00087 {
00088 this->name_cache_.length (length + 1);
00089 this->name_cache_[length++] =
00090 CORBA::string_dup (entry->key ().c_str ());
00091 itr.advance ();
00092 }
00093 }
00094 }
00095
00096 return this->name_cache_;
00097 }
00098
00099 TAO_NS_Control*
00100 TAO_Control_Registry::get (const ACE_CString& name) const
00101 {
00102 ACE_READ_GUARD_RETURN (TAO_SYNCH_RW_MUTEX, guard, this->mutex_, 0);
00103
00104 Map::data_type type = 0;
00105 this->map_.find (name, type);
00106 return type;
00107 }
00108
00109 TAO_END_VERSIONED_NAMESPACE_DECL