Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Monitor / Monitor_Impl.cpp
blobe47bfe6bbcb04909aa21aeb6cf595bf1e2df8091
1 #include "tao/Monitor/Monitor_Impl.h"
3 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
5 #include "ace/Monitor_Point_Registry.h"
6 #include "ace/Monitor_Control_Action.h"
7 #include "ace/Monitor_Control/Monitor_Control.h"
9 class TAO_Control_Action : public Control_Action
11 public:
12 TAO_Control_Action (::Monitor::Subscriber_ptr sub)
13 : sub_ (::Monitor::Subscriber::_duplicate (sub))
17 virtual void execute (const char* /* command */)
19 try
21 // @todo, really want to send the value to the subscriber.
22 ::Monitor::DataList d;
23 sub_->push (d);
25 catch (const ::CORBA::Exception&)
30 private:
31 ::Monitor::Subscriber_var sub_;
34 Monitor_Impl::Monitor_Impl (CORBA::ORB_ptr orb)
35 : orb_ (CORBA::ORB::_duplicate (orb))
39 ::Monitor::NameList *
40 Monitor_Impl::get_statistic_names (const char * filter)
42 Monitor_Control_Types::NameList mc_names =
43 Monitor_Point_Registry::instance ()->names ();
45 ::Monitor::NameList *namelist = 0;
46 ACE_NEW_THROW_EX (namelist,
47 ::Monitor::NameList (static_cast<CORBA::ULong> (mc_names.size ())),
48 CORBA::NO_MEMORY ());
50 CORBA::ULong index = 0;
52 for (Monitor_Control_Types::NameList::Iterator i (mc_names);
53 !i.done ();
54 i.advance (), ++index)
56 ACE_CString *item = 0;
57 i.next (item);
59 if (ACE::wild_match (item->c_str (), filter, false))
61 CORBA::ULong const length = namelist->length ();
62 namelist->length (length + 1);
63 (*namelist)[length] = CORBA::string_dup (item->c_str ());
67 return namelist;
70 ::Monitor::DataList *
71 Monitor_Impl::get_statistics (const ::Monitor::NameList & names)
73 ::Monitor::DataList *datalist = 0;
74 ACE_NEW_THROW_EX (datalist,
75 ::Monitor::DataList (names.length ()),
76 CORBA::NO_MEMORY ());
78 /// Get an instance of the MC service singleton.
79 MC_ADMINMANAGER* mgr =
80 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
83 for (CORBA::ULong index = 0; index < names.length (); ++index)
85 /// Call on the administrator class to look up the desired monitors.
86 ACE::Monitor_Control::Monitor_Base *monitor =
87 mgr->admin ().monitor_point (names[index]);
89 if (monitor != 0)
91 Monitor_Control_Types::Data d (monitor->type ());
92 CORBA::ULong const length = datalist->length();
93 datalist->length (length + 1);
94 ::Monitor::Data data;
95 TAO_Monitor::get_monitor_data (monitor, data, false);
96 (*datalist)[length] = data;
98 monitor->remove_ref ();
102 return datalist;
105 ::Monitor::DataList *
106 Monitor_Impl::get_and_clear_statistics (const ::Monitor::NameList & names)
108 ::Monitor::DataList *datalist = 0;
109 ACE_NEW_THROW_EX (datalist,
110 ::Monitor::DataList (names.length ()),
111 CORBA::NO_MEMORY ());
113 /// Get an instance of the MC service singleton.
114 MC_ADMINMANAGER* mgr =
115 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
117 for (CORBA::ULong index = 0; index < names.length (); ++index)
119 /// Call on the administrator class to look up the desired monitors.
120 ACE::Monitor_Control::Monitor_Base *monitor =
121 mgr->admin ().monitor_point (names[index]);
123 if (monitor != 0)
125 CORBA::ULong const length = datalist->length();
126 datalist->length (length + 1);
127 ::Monitor::Data data;
128 TAO_Monitor::get_monitor_data (monitor, data, true);
129 (*datalist)[length] = data;
131 monitor->remove_ref ();
135 return datalist;
138 void
139 TAO_Monitor::get_monitor_data (
140 ACE::Monitor_Control::Monitor_Base *monitor,
141 Monitor::Data& data,
142 bool clear)
144 // If it's not a counter, we need to make sure that we have
145 // the most up-to-date information. A counter will always have
146 // the correct value.
147 if (monitor->type () != Monitor_Control_Types::MC_COUNTER)
149 monitor->update ();
152 // Populate the data structure based on the type of statistic
153 if (monitor->type () == Monitor_Control_Types::MC_LIST)
155 Monitor_Control_Types::NameList slist (monitor->get_list ());
156 CORBA::ULong size = static_cast<CORBA::ULong> (slist.size ());
157 Monitor::NameList list (size);
158 list.length (size);
160 for (CORBA::ULong i = 0; i < size; ++i)
162 list[i] = CORBA::string_dup (slist[i].c_str ());
165 data.data_union._d (::Monitor::DATA_TEXT);
166 data.data_union.list (list);
168 else
170 Monitor::Numeric num;
171 num.count = static_cast<CORBA::ULong> (monitor->count ());
172 num.minimum = monitor->minimum_sample ();
173 num.maximum = monitor->maximum_sample ();
174 num.last = monitor->last_sample ();
175 num.dlist.length (1);
176 num.dlist[0].value = monitor->last_sample ();
177 Monitor_Control_Types::Data d (monitor->type ());
178 if (clear)
180 monitor->retrieve_and_clear (d);
182 else
184 monitor->retrieve (d);
186 ACE_UINT64 usecs;
187 d.timestamp_.to_usec (usecs);
189 if (monitor->type() == Monitor_Control_Types::MC_COUNTER)
191 num.average = 0;
192 num.sum_of_squares = 0;
194 else
196 num.average = monitor->average ();
197 num.sum_of_squares = monitor->sum_of_squares ();
200 data.data_union._d (::Monitor::DATA_NUMERIC);
201 data.data_union.num (num);
202 data.data_union.num ().dlist[0].value = d.value_;
203 data.data_union.num ().dlist[0].timestamp = usecs;
208 ::Monitor::NameList *
209 Monitor_Impl::clear_statistics (const ::Monitor::NameList & names)
211 ::Monitor::NameList *namelist = 0;
212 ACE_NEW_THROW_EX (namelist,
213 ::Monitor::NameList (names.length ()),
214 CORBA::NO_MEMORY ());
215 namelist->length (0UL);
217 /// Get an instance of the MC service singleton.
218 MC_ADMINMANAGER* mgr =
219 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
221 for (CORBA::ULong index = 0; index < names.length (); ++index)
223 /// Call on the administrator class to look up the desired monitors.
224 ACE::Monitor_Control::Monitor_Base *monitor =
225 mgr->admin ().monitor_point (names[index]);
227 if (monitor != 0) {
228 CORBA::ULong const length = namelist->length ();
229 namelist->length (length + 1);
230 (*namelist)[length] = CORBA::string_dup (names[index].in ());
231 monitor->clear ();
233 monitor->remove_ref ();
237 return namelist;
240 ::Monitor::ConstraintStructList *
241 Monitor_Impl::register_constraint (
242 const ::Monitor::NameList & names,
243 const char * cs,
244 ::Monitor::Subscriber_ptr sub)
246 ::Monitor::ConstraintStructList *constraintlist = 0;
247 ACE_NEW_THROW_EX (constraintlist,
248 ::Monitor::ConstraintStructList (names.length ()),
249 CORBA::NO_MEMORY ());
250 constraintlist->length (0UL);
252 MC_ADMINMANAGER* mgr =
253 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
255 for (CORBA::ULong index = 0; index < names.length (); ++index)
257 /// Call on the administrator class to look up the desired monitors.
258 ACE::Monitor_Control::Monitor_Base *monitor =
259 mgr->admin ().monitor_point (names[index]);
261 if (monitor != 0)
263 TAO_Control_Action* ca = new TAO_Control_Action (sub);
264 long id = monitor->add_constraint (cs, ca);
265 CORBA::ULong const length = constraintlist->length ();
266 constraintlist->length (length + 1);
267 (*constraintlist)[length].id = id;
268 (*constraintlist)[length].itemname =
269 CORBA::string_dup (names[index].in ());
271 monitor->remove_ref ();
275 return constraintlist;
278 void
279 Monitor_Impl::unregister_constraints (
280 const ::Monitor::ConstraintStructList & constraint)
282 MC_ADMINMANAGER* mgr =
283 ACE_Dynamic_Service<MC_ADMINMANAGER>::instance ("MC_ADMINMANAGER");
285 for (CORBA::ULong index = 0; index < constraint.length (); ++index)
287 /// Call on the administrator class to look up the desired monitors.
288 ACE::Monitor_Control::Monitor_Base *monitor =
289 mgr->admin ().monitor_point (constraint[index].itemname.in ());
291 if (monitor != 0)
293 ACE::Monitor_Control::Control_Action *action =
294 monitor->remove_constraint (constraint[index].id);
296 if (action != 0)
298 action->remove_ref ();
301 monitor->remove_ref ();
306 #endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */