27 #include <IceUtil/Time.h>
69 std::unique_lock lock(timersMutex);
70 SystemObserverTimerMap::iterator iter = timers.begin();
72 while (iter != timers.end())
77 updateTimer(iter->second);
80 setDataField(iter->second.timerName,
"elapsedMs",
int(iter->second.elapsedMs));
83 catch (armarx::LocalException& e)
87 catch (armarx::UserException& e)
100 const std::string& timerBaseName,
101 const Ice::Current&
c)
104 [
this, amd, timerBaseName]
106 std::stringstream temp;
107 temp << ++maxTimerId <<
"_" << timerBaseName;
108 std::string timerName = temp.str();
110 std::unique_lock lock(timersMutex);
112 if (timers.find(timerName) != timers.end())
114 std::string reason =
"Timer " + timerName +
" already exists";
115 amd->ice_exception(InvalidTimerException(reason.c_str()));
123 std::pair<std::string, SystemObserverTimer> entry;
124 entry.first = timerName;
125 entry.second = timer;
127 timers.insert(entry);
136 "Elapsed milliseconds of Timer " + timerName);
140 amd->ice_response(
new ChannelRef(
this, timerName));
146 const ChannelRefBasePtr& timer,
147 const Ice::Current&
c)
152 std::unique_lock lock(timersMutex);
153 std::string timerName =
154 ChannelRefPtr::dynamicCast(timer)->getChannelName();
156 SystemObserverTimerMap::iterator iter = timers.find(timerName);
158 if (iter != timers.end())
160 resetTimer(iter->second);
164 std::string reason =
"Timer " + timerName +
" unknown";
165 amd->ice_exception(InvalidTimerException(reason.c_str()));
173 const ChannelRefBasePtr& timer,
174 const Ice::Current&
c)
179 std::unique_lock lock(timersMutex);
180 std::string timerName =
181 ChannelRefPtr::dynamicCast(timer)->getChannelName();
183 SystemObserverTimerMap::iterator iter = timers.find(timerName);
185 if (iter != timers.end())
187 iter->second.paused =
true;
191 std::string reason =
"Timer " + timerName +
" unknown";
192 amd->ice_exception(InvalidTimerException(reason.c_str()));
200 const ChannelRefBasePtr& timer,
201 const Ice::Current&
c)
206 std::unique_lock lock(timersMutex);
207 std::string timerName =
208 ChannelRefPtr::dynamicCast(timer)->getChannelName();
210 SystemObserverTimerMap::iterator iter = timers.find(timerName);
212 if (iter != timers.end())
214 iter->second.paused =
false;
215 iter->second.startTimeMs += getElapsedTimeMs(iter->second.startTimeMs +
216 iter->second.elapsedMs);
220 std::string reason =
"Timer " + timerName +
" unknown";
221 amd->ice_exception(InvalidTimerException(reason.c_str()));
229 const ChannelRefBasePtr& timer,
230 const Ice::Current&
c)
235 std::unique_lock lock(timersMutex);
236 std::string timerName =
237 ChannelRefPtr::dynamicCast(timer)->getChannelName();
239 SystemObserverTimerMap::iterator iter = timers.find(timerName);
241 if (iter != timers.end())
256 const std::string& counterBaseName,
257 const Ice::Current&
c)
260 [
this, amd, initialValue, counterBaseName]
262 std::stringstream temp;
263 temp << ++maxCounterId <<
"_" << counterBaseName;
264 std::string counterName = temp.str();
266 std::unique_lock lock(countersMutex);
268 if (counters.find(counterName) != counters.end())
270 std::string reason =
"Counter " + counterName +
" already exists";
271 amd->ice_exception(InvalidCounterException(reason.c_str()));
278 counter.
value = initialValue;
280 std::pair<std::string, SystemObserverCounter> entry;
281 entry.first = counterName;
282 entry.second = counter;
285 SystemObserverCounterMap::iterator iter;
286 iter = (counters.insert(entry)).first;
294 "Current value of counter " + counterName);
299 amd->ice_response(
new ChannelRef(
this, counterName));
305 const AMD_SystemObserverInterface_incrementCounterPtr& amd,
306 const ChannelRefBasePtr& counter,
307 const Ice::Current&
c)
312 std::unique_lock lock(countersMutex);
313 std::string counterName =
314 ChannelRefPtr::dynamicCast(counter)->getChannelName();
316 SystemObserverCounterMap::iterator iter = counters.find(counterName);
318 if (iter != counters.end())
320 iter->second.value++;
324 std::string reason =
"Counter " + counterName +
" unknown";
325 amd->ice_exception(InvalidCounterException(reason.c_str()));
329 amd->ice_response(iter->second.value);
335 const AMD_SystemObserverInterface_decrementCounterPtr& amd,
336 const ChannelRefBasePtr& counter,
337 const Ice::Current&
c)
342 std::unique_lock lock(countersMutex);
343 std::string counterName =
344 ChannelRefPtr::dynamicCast(counter)->getChannelName();
346 SystemObserverCounterMap::iterator iter = counters.find(counterName);
348 if (iter != counters.end())
350 iter->second.value--;
354 std::string reason =
"Counter " + counterName +
" unknown";
355 amd->ice_exception(InvalidCounterException(reason.c_str()));
359 amd->ice_response(iter->second.value);
365 const ChannelRefBasePtr& counter,
366 const Ice::Current&
c)
371 std::unique_lock lock(countersMutex);
372 std::string counterName =
373 ChannelRefPtr::dynamicCast(counter)->getChannelName();
375 SystemObserverCounterMap::iterator iter = counters.find(counterName);
377 if (iter != counters.end())
379 iter->second.value = 0;
383 std::string reason =
"Counter " + counterName +
" unknown";
384 amd->ice_exception(InvalidCounterException(reason.c_str()));
394 const ChannelRefBasePtr& counter,
396 const Ice::Current&
c)
399 [
this, amd, counter, counterValue]
401 std::unique_lock lock(countersMutex);
402 std::string counterName =
403 ChannelRefPtr::dynamicCast(counter)->getChannelName();
405 SystemObserverCounterMap::iterator iter = counters.find(counterName);
407 if (iter != counters.end())
409 iter->second.value = counterValue;
413 std::string reason =
"Counter " + counterName +
" unknown";
414 amd->ice_exception(InvalidCounterException(reason.c_str()));
424 const ChannelRefBasePtr& counter,
425 const Ice::Current&
c)
430 std::unique_lock lock(countersMutex);
431 std::string counterName =
432 ChannelRefPtr::dynamicCast(counter)->getChannelName();
434 SystemObserverCounterMap::iterator iter = counters.find(counterName);
436 if (iter != counters.end())
439 counters.erase(iter);
457 SystemObserver::updateTimer(SystemObserverTimer& timer)
461 timer.elapsedMs = getElapsedTimeMs(timer.startTimeMs);
466 SystemObserver::getCurrentTimeMs()
470 return current.toMilliSeconds();
474 SystemObserver::getElapsedTimeMs(
int referenceTimeMs)
477 IceUtil::Time reference = IceUtil::Time::milliSeconds(referenceTimeMs);
484 SystemObserver::updateCounter(SystemObserverCounterMap::iterator& iterCounter)
487 setDataField(iterCounter->second.counterName,
"value", iterCounter->second.value);