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
13 namespace Monitor_Control
15 Monitor_Point_Registry
*
16 Monitor_Point_Registry::instance (void)
19 ACE_Singleton
<Monitor_Point_Registry
, ACE_SYNCH_MUTEX
>::instance ();
22 Monitor_Point_Registry::Monitor_Point_Registry (void)
28 Monitor_Point_Registry::add (Monitor_Base
* type
)
32 ACE_ERROR_RETURN ((LM_ERROR
,
33 "registry add: null type\n"),
40 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX
, guard
, this->mutex_
, false);
44 status
= this->map_
.bind (type
->name (), type
);
46 /// Temporary debugging code.
47 // ACE_DEBUG ((LM_DEBUG, "adding %s\n", type->name ()));
52 ACE_ERROR_RETURN ((LM_ERROR
,
53 "registry add: map bind failed\n"),
61 Monitor_Point_Registry::remove (const char* name
)
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 "registry remove: null name\n"),
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 ()));
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",
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 ());
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
);
141 Monitor_Point_Registry::constraint_id (void)
146 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX
, guard
, this->mutex_
, -1);
148 retval
= this->constraint_id_
++;
155 Monitor_Point_Registry::cleanup (void)
157 for (Map::ITERATOR i
= this->map_
.begin ();
158 i
!= this->map_
.end ();
161 Map::ENTRY
* entry
= 0;
163 entry
->int_id_
->remove_ref ();
169 ACE_END_VERSIONED_NAMESPACE_DECL
171 #endif /* ACE_HAS_MONITOR_FRAMEWORK==1 */