thread.hpp
Go to the documentation of this file.
1 
9 #ifndef QTCTRL_THREAD
10 #define QTCTRL_THREAD
11 
12 #include <QThread>
13 #include <QProcess>
14 
15 
21 class ROSserver : public QThread {
22  Q_OBJECT // This macro is needed to handle Qt events
23 
25  bool ROS_run; // solution 2
26 
28  std::string workspace;
29 
31  void run();
32 
33 private Q_SLOTS:
36  void threadError(QProcess::ProcessError error)
37  { Q_EMIT errorOccurred( (int)(error), workspace.c_str() ); }
38 
39 
40 public:
43  ROSserver(QObject* parent) : QThread(parent), ROS_run(true) {}
44 
48  void setWorkspace(const std::string& wrksp) {
49  static const std::string begin("$ROS_WS/src/qt_ctrl/");
50  workspace = begin + wrksp; // beginning never changes
51  }
52 
57  void sleep(const long& seconds) const { QThread::sleep(seconds); }
58 
60  void stop() {
61  ROS_run = false; // ask to the run() method to stop (sol. 2)
62  quit(); wait(); // when stopped, stop the thread
63  } // end of void stop()
64 
65 Q_SIGNALS:
69  void errorOccurred(const int error, const QString& program);
70 
71 }; // end of class ROSserveur
72 
73 #endif // QTCTRL_THREAD
void threadError(QProcess::ProcessError error)
Signals which error occured when starting the process.
Definition: thread.hpp:36
void run()
The main method of this thread.
Definition: thread.cpp:14
ROSserver(QObject *parent)
Starts a ROS server in a separate thread.
Definition: thread.hpp:43
std::string workspace
Name of the workspace selected.
Definition: thread.hpp:28
void stop()
Stops the ROS server (and the thread&#39;s execution).
Definition: thread.hpp:60
void setWorkspace(const std::string &wrksp)
Set the workspace name.
Definition: thread.hpp:48
void errorOccurred(const int error, const QString &program)
Signals the error occured when starting the process.
bool ROS_run
Should the ROS server continue to run?
Definition: thread.hpp:25
This class is used to start a ROS server.
Definition: thread.hpp:21
void sleep(const long &seconds) const
Waits for a given duration, in seconds.
Definition: thread.hpp:57


qt_ctrl
Author(s): Alexis Scheuer
autogenerated on Wed Dec 16 2020 15:51:32