00001 #ifndef _MRTA_MONITOR_H_ 00002 #define _MRTA_MONITOR_H_ 00003 00004 #include <QMap> 00005 #include <ros/duration.h> 00006 #include <ros/node_handle.h> 00007 #include "utilities/message_field_subscriber.h" 00008 00009 namespace rqt_mrta 00010 { 00011 namespace config 00012 { 00013 namespace architecture 00014 { 00015 class Topic; 00016 } 00017 } 00018 } 00019 00020 namespace mrta 00021 { 00022 class StateMonitor; 00023 class System; 00024 class Monitor : public QObject 00025 { 00026 Q_OBJECT 00027 public: 00028 typedef rqt_mrta::config::architecture::Topic Config; 00029 virtual ~Monitor(); 00030 Config* getConfig() const; 00031 QString getName() const; 00032 QString getType() const; 00033 size_t getQueueSize() const; 00034 QString getField() const; 00035 ros::Duration getTimeout() const; 00036 ros::Duration getHorizon() const; 00037 void setConfig(Config* config); 00038 void setRegistry(utilities::MessageSubscriberRegistry* registry); 00039 00040 public slots: 00041 void setName(const QString& name); 00042 void setType(const QString& type); 00043 void setQueueSize(const size_t& queue_size); 00044 void setField(const QString& field); 00045 void setTimeout(const ros::Duration& timeout); 00046 void setHorizon(const ros::Duration& horizon); 00047 00048 protected: 00049 Monitor(System* system, utilities::MessageSubscriberRegistry* registry, 00050 Config* config); 00051 void addStateMonitor(const QString& id, StateMonitor* monitor); 00052 00053 protected slots: 00054 virtual void add(const QString& id) = 0; 00055 00056 signals: 00057 void changed(); 00058 void received(const QString& id); 00059 00060 protected: 00061 virtual void update(const QString& id) = 0; 00062 void update(const QString& id, int state); 00063 System* getSystem() const; 00064 00065 private: 00066 typedef QMap<QString, StateMonitor*> StateMonitorMap; 00067 QString name_; 00068 QString type_; 00069 size_t queue_size_; 00070 QString field_; 00071 ros::Duration timeout_; 00072 ros::Duration horizon_; 00073 Config* config_; 00074 utilities::MessageSubscriberRegistry* registry_; 00075 utilities::MessageFieldSubscriber* subscriber_; 00076 StateMonitorMap monitors_; 00077 bool subscribe(); 00078 bool unsubscribe(); 00079 00080 private slots: 00081 void updateSubscriber(); 00082 void subscriberReceived(variant_topic_tools::BuiltinVariant field_value); 00083 }; 00084 } 00085 00086 #endif // _MRTA_MONITOR_H_