HulaLoop
Simple cross-platform audio loopback and recording.
HulaControlError.h
Go to the documentation of this file.
1 #ifndef HL_CONTROL_ERROR_H
2 #define HL_CONTROL_ERROR_H
3 
4 #include <string>
5 
7 
8 #include <QCoreApplication>
9 #include <QMessageBox>
10 #include <QString>
11 
24 /******************************************************************************
25  *
26  * Collection of error codes and exceptions for hlcontrol
27  *
28 ******************************************************************************/
29 // Export error messages
30 #define HL_EXPORT_OPEN_FILE_CODE -18
31 #define HL_EXPORT_OPEN_FILE_MSG "Could not open file %s!"
32 
33 namespace hula
34 {
35  inline QString getTranslatedErrorMessage(int);
36 
41 
42  Q_DECLARE_TR_FUNCTIONS(Exception)
43 
44  private:
45  int errorCode;
46 
47  public:
51  ControlException(int errorCode)
52  {
53  this->errorCode = errorCode;
54  }
55 
62  const std::string getErrorMessage() const
63  {
64  return std::string(qPrintable(getTranslatedErrorMessage(errorCode)));
65  }
66 
72  int getErrorCode() const
73  {
74  return errorCode;
75  }
76  };
77 
90  inline QString getTranslatedErrorMessage(int code)
91  {
92  switch (code)
93  {
94  case HL_OS_INIT_CODE:
95  return ControlException::tr(HL_OS_INIT_MSG);
96  break;
97  case HL_PA_INIT_CODE:
98  return ControlException::tr(HL_PA_INIT_MSG);
99  break;
100  case HL_OSX_DAEMON_INIT_CODE:
101  return ControlException::tr(HL_OSX_DAEMON_INIT_MSG);
102  break;
103  case HL_OSX_DAEMON_CRASH_CODE:
104  return ControlException::tr(HL_OSX_DAEMON_CRASH_MSG);
105  break;
106  case HL_OSX_PGREP_CODE:
107  return ControlException::tr(HL_OSX_PGREP_MSG);
108  break;
109  case HL_OSX_EXEPATH_CODE:
110  return ControlException::tr(HL_OSX_EXEPATH_MSG);
111  break;
112  case HL_OSX_EXEPATH_TRIM_CODE:
113  return ControlException::tr(HL_OSX_EXEPATH_TRIM_MSG);
114  break;
115  case HL_DEVICE_NOT_FOUND_CODE:
116  return ControlException::tr(HL_DEVICE_NOT_FOUND_MSG);
117  break;
118  case HL_PA_OPEN_STREAM_CODE:
119  return ControlException::tr(HL_PA_OPEN_STREAM_MSG);
120  break;
121  case HL_PA_CLOSE_STREAM_CODE:
122  return ControlException::tr(HL_PA_CLOSE_STREAM_MSG);
123  break;
124  case HL_PA_DEVICE_READ_STREAM_CODE:
125  return ControlException::tr(HL_PA_DEVICE_READ_STREAM_MSG);
126  break;
127  case HL_PA_GET_DEVICES_CODE:
128  return ControlException::tr(HL_PA_GET_DEVICES_MSG);
129  break;
130  case HL_CHECK_PARAMS_CODE:
131  return ControlException::tr(HL_CHECK_PARAMS_MSG);
132  break;
133  case HL_LINUX_OPEN_DEVICE_CODE:
134  return ControlException::tr(HL_LINUX_OPEN_DEVICE_MSG);
135  break;
136  case HL_RB_ALLOC_BUFFER_CODE:
137  return ControlException::tr(HL_RB_ALLOC_BUFFER_MSG);
138  break;
139  case HL_RB_INIT_BUFFER_CODE:
140  return ControlException::tr(HL_RB_INIT_BUFFER_MSG);
141  break;
142  case HL_EXPORT_OPEN_FILE_CODE:
143  return ControlException::tr(HL_EXPORT_OPEN_FILE_MSG);
144  break;
145  default:
146  return QString(ControlException::tr("Unknown error code: %1").arg(code));
147  break;
148  }
149  }
150 }
151 
152 #endif // END HL_CONTROL_ERROR_H
ControlException(int errorCode)
Constructor of ControlException.
Definition: HulaControlError.h:51
const std::string getErrorMessage() const
This method returns the error message that corresponds to the error code in the locale given by the a...
Definition: HulaControlError.h:62
<hlaudio/internal/HulaAudioError.h>This file is automatically included via hlaudio.h
Wrapper around translation functions for Qt.
Definition: Controller.h:10
int getErrorCode() const
This method returns the error code.
Definition: HulaControlError.h:72
Exception class for the control module and higher.
Definition: HulaControlError.h:40
QString getTranslatedErrorMessage(int)
Retrieve the description associated with a given error code.
Definition: HulaControlError.h:90