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);
478 IceUtil::Time
interval = current - reference;
484 SystemObserver::updateCounter(SystemObserverCounterMap::iterator& iterCounter)
487 setDataField(iterCounter->second.counterName,
"value", iterCounter->second.value);
The ChannelRef class is a reference to a channel on an Observer.
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are within a reference range.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
Checks if the relevant data fields have been updated since the installation of this condition.
Checks if the relevant data fields contain valid values.
void offerChannel(std::string channelName, std::string description)
Offer a channel.
virtual void postWorkerJobs()
void removeChannel(std::string channelName)
Remove a channel.
void offerDataField(std::string channelName, std::string datafieldName, VariantTypeId type, std::string description)
Offer a datafield without default value.
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
void addWorkerJob(const std::string &name, std::function< void(void)> &&f) const
void offerDataFieldWithDefault(std::string channelName, std::string datafieldName, const Variant &defaultValue, std::string description)
Offer a datafield with default value.
std::recursive_mutex channelsMutex
void setDataField(const std::string &channelName, const std::string &datafieldName, const Variant &value, bool triggerFilterUpdate=true)
set datafield with datafieldName and in channel channelName
void resetTimer_async(const AMD_SystemObserverInterface_resetTimerPtr &amd, const ChannelRefBasePtr &timer, const Ice::Current &c=Ice::emptyCurrent) override
resetTimer sets the start time of timer to Time.Now() and start the timer
void removeCounter_async(const AMD_SystemObserverInterface_removeCounterPtr &amd, const ChannelRefBasePtr &counter, const Ice::Current &c=Ice::emptyCurrent) override
void decrementCounter_async(const AMD_SystemObserverInterface_decrementCounterPtr &amd, const ChannelRefBasePtr &counter, const Ice::Current &c=Ice::emptyCurrent) override
void postWorkerJobs() override
void startTimer_async(const AMD_SystemObserverInterface_startTimerPtr &amd, const std::string &timerBaseName, const Ice::Current &c=Ice::emptyCurrent) override
Creates a new timer with name timerBaseName and starts it.
void incrementCounter_async(const AMD_SystemObserverInterface_incrementCounterPtr &amd, const ChannelRefBasePtr &counter, const Ice::Current &c=Ice::emptyCurrent) override
void removeTimer_async(const AMD_SystemObserverInterface_removeTimerPtr &amd, const ChannelRefBasePtr &timer, const Ice::Current &c=Ice::emptyCurrent) override
removeTimer stops timer and removes it from the SystemObserver.
void setCounter_async(const AMD_SystemObserverInterface_setCounterPtr &amd, const ChannelRefBasePtr &counter, int counterValue, const Ice::Current &c=Ice::emptyCurrent) override
void pauseTimer_async(const AMD_SystemObserverInterface_pauseTimerPtr &amd, const ChannelRefBasePtr &timer, const Ice::Current &c=Ice::emptyCurrent) override
pauseTimer pauses the advance of time in timer.
void onInitObserver() override
Framework hook.
void unpauseTimer_async(const AMD_SystemObserverInterface_unpauseTimerPtr &amd, const ChannelRefBasePtr &timer, const Ice::Current &c=Ice::emptyCurrent) override
unpauseTimer resumes the advancing in time of timer.
void startCounter_async(const AMD_SystemObserverInterface_startCounterPtr &amd, int initialValue, const std::string &counterBaseName, const Ice::Current &c=Ice::emptyCurrent) override
Creates a new counter and starts it.
void resetCounter_async(const AMD_SystemObserverInterface_resetCounterPtr &amd, const ChannelRefBasePtr &counter, const Ice::Current &c=Ice::emptyCurrent) override
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
#define ARMARX_FATAL
The logging level for unexpected behaviour, that will lead to a seriously malfunctioning program and ...
This file offers overloads of toIce() and fromIce() functions for STL container types.
Interval< T > interval(T lo, T hi)