SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
command.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef SDRBASE_COMMANDS_COMMAND_H_
19 #define SDRBASE_COMMANDS_COMMAND_H_
20 
21 #include <Qt>
22 #include <QByteArray>
23 #include <QString>
24 #include <QMetaType>
25 #include <QObject>
26 #include <QProcess>
27 #include <time.h>
28 
29 #include "export.h"
30 
31 class SDRBASE_API Command : public QObject
32 {
33  Q_OBJECT
34 public:
35  Command();
36  Command(const Command& command);
37  ~Command();
38  void resetToDefaults();
39 
40  QByteArray serialize() const;
41  bool deserialize(const QByteArray& data);
42 
43  void setCommand(const QString& command) { m_command = command; }
44  const QString& getCommand() const { return m_command; }
45  void setArgString(const QString& argString) { m_argString = argString; }
46  const QString& getArgString() const { return m_argString; }
47  void setGroup(const QString& group) { m_group = group; }
48  const QString& getGroup() const { return m_group; }
49  void setDescription(const QString& description) { m_description = description; }
50  const QString& getDescription() const { return m_description; }
51  void setKey(Qt::Key key) { m_key = key; }
52  Qt::Key getKey() const { return m_key; }
53  void setKeyModifiers(Qt::KeyboardModifiers keyModifiers) { m_keyModifiers = keyModifiers; }
54  Qt::KeyboardModifiers getKeyModifiers() const { return m_keyModifiers; }
55  void setAssociateKey(bool associate) { m_associateKey = associate; }
56  bool getAssociateKey() const { return m_associateKey; }
57  void setRelease(bool release) { m_release = release; }
58  bool getRelease() const { return m_release; }
59  QString getKeyLabel() const;
60 
61  void run(const QString& apiAddress, int apiPort, int deviceSetIndex);
62  void kill();
63  QProcess::ProcessState getLastProcessState() const;
64  bool getLastProcessError(QProcess::ProcessError& error) const;
65  bool getLastProcessExit(int& exitCode, QProcess::ExitStatus& exitStatus) const;
66  const QString& getLastProcessLog() const;
67  uint64_t getLastProcessStartTimestampms() const { return m_currentProcessStartTimeStampms; }
68  uint64_t getLastProcessFinishTimestampms() const { return m_currentProcessFinishTimeStampms; }
69  const QString& getLastProcessCommandLine() const { return m_currentProcessCommandLine; }
70  qint64 getLastProcessPid() const { return m_currentProcessPid; }
71 
72  static bool commandCompare(const Command *c1, Command *c2)
73  {
74  if (c1->m_group != c2->m_group)
75  {
76  return c1->m_group < c2->m_group;
77  }
78  else
79  {
80  if (c1->m_description != c2->m_description) {
81  return c1->m_description < c2->m_description;
82  }
83  else
84  {
85  if (c1->m_key != c2->m_key) {
86  return c1->m_key < c2->m_key;
87  } else {
88  return c1->m_release;
89  }
90  }
91  }
92  }
93 
94 private:
95  QString m_group;
96  QString m_description;
97  QString m_command;
98  QString m_argString;
99  Qt::Key m_key;
100  Qt::KeyboardModifiers m_keyModifiers;
102  bool m_release;
103  QProcess *m_currentProcess;
104  QProcess::ProcessState m_currentProcessState;
106  QProcess::ProcessError m_currentProcessError;
109  QProcess::ExitStatus m_currentProcessExitStatus;
110  QString m_log;
115 
116 private slots:
117  void processStateChanged(QProcess::ProcessState newState);
118  void processError(QProcess::ProcessError error);
119  void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
120 };
121 
124 
125 #endif /* SDRBASE_COMMANDS_COMMAND_H_ */
QString m_group
Definition: command.h:95
void setRelease(bool release)
Definition: command.h:57
Qt::KeyboardModifiers getKeyModifiers() const
Definition: command.h:54
QProcess::ExitStatus m_currentProcessExitStatus
Definition: command.h:109
const QString & getDescription() const
Definition: command.h:50
Qt::Key getKey() const
Definition: command.h:52
QString m_description
Definition: command.h:96
QString m_argString
Definition: command.h:98
Qt::Key m_key
Definition: command.h:99
QProcess * m_currentProcess
Definition: command.h:103
qint64 m_currentProcessPid
Definition: command.h:114
void setArgString(const QString &argString)
Definition: command.h:45
uint64_t getLastProcessFinishTimestampms() const
Definition: command.h:68
QString m_currentProcessCommandLine
Definition: command.h:113
const QString & getLastProcessCommandLine() const
Definition: command.h:69
static bool commandCompare(const Command *c1, Command *c2)
Definition: command.h:72
uint64_t m_currentProcessFinishTimeStampms
Definition: command.h:112
bool m_release
Definition: command.h:102
qint64 getLastProcessPid() const
Definition: command.h:70
bool m_isInError
Definition: command.h:105
void setKey(Qt::Key key)
Definition: command.h:51
void setDescription(const QString &description)
Definition: command.h:49
bool m_hasExited
Definition: command.h:107
QString m_command
Definition: command.h:97
uint64_t getLastProcessStartTimestampms() const
Definition: command.h:67
QProcess::ProcessState m_currentProcessState
Definition: command.h:104
Qt::KeyboardModifiers m_keyModifiers
Definition: command.h:100
Q_DECLARE_METATYPE(const Command *)
QProcess::ProcessError m_currentProcessError
Definition: command.h:106
uint64_t m_currentProcessStartTimeStampms
Definition: command.h:111
const QString & getArgString() const
Definition: command.h:46
void setCommand(const QString &command)
Definition: command.h:43
const QString & getGroup() const
Definition: command.h:48
QString m_log
Definition: command.h:110
void setAssociateKey(bool associate)
Definition: command.h:55
bool getAssociateKey() const
Definition: command.h:56
void setGroup(const QString &group)
Definition: command.h:47
const QString & getCommand() const
Definition: command.h:44
#define SDRBASE_API
Definition: export.h:40
bool m_associateKey
Definition: command.h:101
void setKeyModifiers(Qt::KeyboardModifiers keyModifiers)
Definition: command.h:53
int m_currentProcessExitCode
Definition: command.h:108
bool getRelease() const
Definition: command.h:58
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48