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 if (status == -1)
00048 {
00049 ACE_ERROR_RETURN ((LM_ERROR,
00050 "registry add: map bind failed\n"),
00051 false);
00052 }
00053
00054 return (status == 0);
00055 }
00056
00057 bool
00058 Monitor_Point_Registry::remove (const char* name)
00059 {
00060 if (name == 0)
00061 {
00062 ACE_ERROR_RETURN ((LM_ERROR,
00063 "registry remove: null name\n"),
00064 false);
00065 }
00066
00067 int status = 0;
00068 Map::data_type mp = 0;
00069
00070 {
00071 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
00072
00073 ACE_CString name_str (name, 0, false);
00074 status = this->map_.unbind (name_str, mp);
00075 }
00076
00077 if (status == -1)
00078 {
00079 ACE_ERROR_RETURN ((LM_ERROR,
00080 "registry remove: unbind failed for %s\n",
00081 name),
00082 false);
00083 }
00084 else
00085 {
00086 mp->remove_ref ();
00087 }
00088
00089 return (status == 0);
00090 }
00091
00092 Monitor_Control_Types::NameList
00093 Monitor_Point_Registry::names (void)
00094 {
00095 Monitor_Control_Types::NameList name_holder_;
00096
00097 {
00098 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
00099
00100 for (Map::CONST_ITERATOR i (this->map_); !i.done (); i.advance ())
00101 {
00102 name_holder_.push_back (i->key ());
00103 }
00104 }
00105
00106 return name_holder_;
00107 }
00108
00109 Monitor_Base*
00110 Monitor_Point_Registry::get (const ACE_CString& name) const
00111 {
00112 Map::data_type mp = 0;
00113
00114 {
00115 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
00116
00117 this->map_.find (name, mp);
00118 }
00119
00120 if (mp != 0)
00121 {
00122 mp->add_ref ();
00123 }
00124
00125 return mp;
00126 }
00127
00128 long
00129 Monitor_Point_Registry::constraint_id (void)
00130 {
00131 long retval = 0;
00132
00133 {
00134 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, -1);
00135
00136 retval = this->constraint_id_++;
00137 }
00138
00139 return retval;
00140 }
00141
00142 void
00143 Monitor_Point_Registry::cleanup (void)
00144 {
00145 for (Map::ITERATOR i = this->map_.begin ();
00146 i != this->map_.end ();
00147 i.advance ())
00148 {
00149 Map::ENTRY* entry = 0;
00150 i.next (entry);
00151 entry->int_id_->remove_ref ();
00152 }
00153 }
00154 }
00155 }
00156
00157 ACE_END_VERSIONED_NAMESPACE_DECL
00158
00159 #endif
00160