state_monitor.cpp
Go to the documentation of this file.
00001 #include "mrta/sample_holder.h"
00002 #include "mrta/state_monitor.h"
00003 #include <ros/console.h>
00004 
00005 namespace mrta
00006 {
00007 StateMonitor::StateMonitor(QObject* parent, const ros::Duration& timeout,
00008                            size_t count_states)
00009     : QObject(parent)
00010 {
00011   for (size_t index(0); index < count_states; index++)
00012   {
00013     SampleHolder* sample_holder = new SampleHolder(this, timeout);
00014     connect(sample_holder, SIGNAL(changed()), this, SIGNAL(changed()));
00015     connect(sample_holder, SIGNAL(updated(bool)), this, SLOT(updated(bool)));
00016     sample_holders_.append(sample_holder);
00017   }
00018 }
00019 
00020 StateMonitor::~StateMonitor()
00021 {
00022   ROS_INFO_STREAM("[~StateMonitor] before");
00023   for (size_t index(0); index < sample_holders_.count(); index++)
00024   {
00025     if (sample_holders_[index])
00026     {
00027       delete sample_holders_[index];
00028       sample_holders_[index] = NULL;
00029     }
00030   }
00031   sample_holders_.clear();
00032   ROS_INFO_STREAM("[~StateMonitor] after");
00033 }
00034 
00035 SampleHolder* StateMonitor::getSampleHolder(size_t index) const
00036 {
00037   return index >= 0 && index < sample_holders_.count() ? sample_holders_[index]
00038                                                          : NULL;
00039 }
00040 
00041 void StateMonitor::setTimeout(ros::Duration timeout)
00042 {
00043   for (size_t index(0); index < sample_holders_.count(); index++)
00044   {
00045     sample_holders_[index]->setTimeout(timeout);
00046   }
00047 }
00048 
00049 void StateMonitor::update(size_t index)
00050 {
00051   if (index >= 0 && index < sample_holders_.count())
00052   {
00053     sample_holders_[index]->update();
00054   }
00055 }
00056 
00057 void StateMonitor::updated(bool up_to_date)
00058 {
00059   int index(sample_holders_.indexOf(static_cast<SampleHolder*>(sender())));
00060   if (index != -1)
00061   {
00062     emit updated(index, up_to_date);
00063     emit changed();
00064   }
00065 }
00066 }


rqt_mrta
Author(s): Adriano Henrique Rossette Leite
autogenerated on Thu Jun 6 2019 18:50:52