Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Point_Registry.h"
00004
00005 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
00006
00007 #include "ace/Monitor_Base.h"
00008
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 namespace ACE
00012 {
00013 namespace Monitor_Control
00014 {
00015 Monitor_Point_Registry*
00016 Monitor_Point_Registry::instance (void)
00017 {
00018 return
00019 ACE_Singleton<Monitor_Point_Registry, ACE_SYNCH_MUTEX>::instance ();
00020 }
00021
00022 Monitor_Point_Registry::Monitor_Point_Registry (void)
00023 : constraint_id_ (0)
00024 {
00025 }
00026
00027 bool
00028 Monitor_Point_Registry::add (Monitor_Base* type)
00029 {
00030 if (type == 0)
00031 {
00032 ACE_ERROR_RETURN ((LM_ERROR,
00033 "registry add: null type\n"),
00034 false);
00035 }
00036
00037 int status = 0;
00038
00039 {
00040 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
00041
00042 type->add_ref ();
00043
00044 status = this->map_.bind (type->name (), type);
00045
00046
00047
00048 }
00049
00050 if (status == -1)
00051 {
00052 ACE_ERROR_RETURN ((LM_ERROR,
00053 "registry add: map bind failed\n"),
00054 false);
00055 }
00056
00057 return (status == 0);
00058 }
00059
00060 bool
00061 Monitor_Point_Registry::remove (const char* name)
00062 {
00063 if (name == 0)
00064 {
00065 ACE_ERROR_RETURN ((LM_ERROR,
00066 "registry remove: null name\n"),
00067 false);
00068 }
00069
00070 int status = 0;
00071 Map::data_type mp = 0;
00072
00073 {
00074 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
00075
00076 ACE_CString name_str (name, 0, false);
00077 status = this->map_.unbind (name_str, mp);
00078
00079
00080
00081 }
00082
00083 if (status == -1)
00084 {
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 }
00096 else
00097 {
00098 mp->remove_ref ();
00099 }
00100
00101 return (status == 0);
00102 }
00103
00104 Monitor_Control_Types::NameList
00105 Monitor_Point_Registry::names (void)
00106 {
00107 Monitor_Control_Types::NameList name_holder_;
00108
00109 {
00110 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
00111
00112 for (Map::CONST_ITERATOR i (this->map_); !i.done (); i.advance ())
00113 {
00114 name_holder_.push_back (i->key ());
00115 }
00116 }
00117
00118 return name_holder_;
00119 }
00120
00121 Monitor_Base*
00122 Monitor_Point_Registry::get (const ACE_CString& name) const
00123 {
00124 Map::data_type mp = 0;
00125
00126 {
00127 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
00128
00129 this->map_.find (name, mp);
00130 }
00131
00132 if (mp != 0)
00133 {
00134 mp->add_ref ();
00135 }
00136
00137 return mp;
00138 }
00139
00140 long
00141 Monitor_Point_Registry::constraint_id (void)
00142 {
00143 long retval = 0;
00144
00145 {
00146 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, -1);
00147
00148 retval = this->constraint_id_++;
00149 }
00150
00151 return retval;
00152 }
00153
00154 void
00155 Monitor_Point_Registry::cleanup (void)
00156 {
00157 for (Map::ITERATOR i = this->map_.begin ();
00158 i != this->map_.end ();
00159 i.advance ())
00160 {
00161 Map::ENTRY* entry = 0;
00162 i.next (entry);
00163 entry->int_id_->remove_ref ();
00164 }
00165 }
00166 }
00167 }
00168
00169 ACE_END_VERSIONED_NAMESPACE_DECL
00170
00171 #endif
00172