Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Monitor_Point_Registry.cpp
blob4c3844f7ea5728639a5dd4337f76d8656a638d8a
1 // $Id: Monitor_Point_Registry.cpp 81833 2008-06-04 14:44:53Z parsons $
3 #include "ace/Monitor_Point_Registry.h"
5 #if defined (ACE_HAS_MONITOR_FRAMEWORK) && (ACE_HAS_MONITOR_FRAMEWORK == 1)
7 #include "ace/Monitor_Base.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 namespace ACE
13 namespace Monitor_Control
15 Monitor_Point_Registry*
16 Monitor_Point_Registry::instance (void)
18 return
19 ACE_Singleton<Monitor_Point_Registry, ACE_SYNCH_MUTEX>::instance ();
22 Monitor_Point_Registry::Monitor_Point_Registry (void)
23 : constraint_id_ (0)
27 bool
28 Monitor_Point_Registry::add (Monitor_Base* type)
30 if (type == 0)
32 ACE_ERROR_RETURN ((LM_ERROR,
33 "registry add: null type\n"),
34 false);
37 int status = 0;
40 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
42 type->add_ref ();
44 status = this->map_.bind (type->name (), type);
46 /// Temporary debugging code.
47 // ACE_DEBUG ((LM_DEBUG, "adding %s\n", type->name ()));
50 if (status == -1)
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "registry add: map bind failed\n"),
54 false);
57 return (status == 0);
60 bool
61 Monitor_Point_Registry::remove (const char* name)
63 if (name == 0)
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "registry remove: null name\n"),
67 false);
70 int status = 0;
71 Map::data_type mp = 0;
74 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, false);
76 ACE_CString name_str (name, 0, false);
77 status = this->map_.unbind (name_str, mp);
79 /// Temporary debugging code.
80 // ACE_DEBUG ((LM_DEBUG, "removing %s\n", name_str.c_str ()));
83 if (status == -1)
85 // (JP) There is a problem with this failing on a single ACE_Message_Queue
86 // monitor per process. I think it is the message queue associated
87 // with the default reactor, maybe because at that low level, ACE
88 // is using malloc with placement, then free, which may bypass the
89 // normal destructors. In any case, it happens only at shutdown
90 // and there seems to be no memory leak.
91 // ACE_ERROR_RETURN ((LM_ERROR,
92 // "registry remove: unbind failed for %s\n",
93 // name),
94 // false);
96 else
98 mp->remove_ref ();
101 return (status == 0);
104 Monitor_Control_Types::NameList
105 Monitor_Point_Registry::names (void)
107 Monitor_Control_Types::NameList name_holder_;
110 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
112 for (Map::CONST_ITERATOR i (this->map_); !i.done (); i.advance ())
114 name_holder_.push_back (i->key ());
118 return name_holder_;
121 Monitor_Base*
122 Monitor_Point_Registry::get (const ACE_CString& name) const
124 Map::data_type mp = 0;
127 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, 0);
129 this->map_.find (name, mp);
132 if (mp != 0)
134 mp->add_ref ();
137 return mp;
140 long
141 Monitor_Point_Registry::constraint_id (void)
143 long retval = 0;
146 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, this->mutex_, -1);
148 retval = this->constraint_id_++;
151 return retval;
154 void
155 Monitor_Point_Registry::cleanup (void)
157 for (Map::ITERATOR i = this->map_.begin ();
158 i != this->map_.end ();
159 i.advance ())
161 Map::ENTRY* entry = 0;
162 i.next (entry);
163 entry->int_id_->remove_ref ();
169 ACE_END_VERSIONED_NAMESPACE_DECL
171 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */