mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-30 20:40:20 -04:00 
			
		
		
		
	Web API: /sdrangel/audio (GET) implementation (1)
This commit is contained in:
		
							parent
							
								
									6c31320812
								
							
						
					
					
						commit
						dad604dcf8
					
				| @ -696,12 +696,16 @@ margin-bottom: 20px; | ||||
|     // Script section to load models into a JS Var | ||||
|     var defs = {} | ||||
|             defs.AudioDevices = { | ||||
|   "required" : [ "nbInputDevices", "nbOutputDevices" ], | ||||
|   "required" : [ "inputDeviceSelectedIndex", "nbInputDevices", "nbOutputDevices", "outputDeviceSelectedIndex" ], | ||||
|   "properties" : { | ||||
|     "nbInputDevices" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Number of input audio devices" | ||||
|     }, | ||||
|     "inputDeviceSelectedIndex" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of selected input audio devices (-1 if default)" | ||||
|     }, | ||||
|     "inputDevices" : { | ||||
|       "type" : "array", | ||||
|       "description" : "Names of input devices", | ||||
| @ -713,6 +717,10 @@ margin-bottom: 20px; | ||||
|       "type" : "integer", | ||||
|       "description" : "Number of output audio devices" | ||||
|     }, | ||||
|     "outputDeviceSelectedIndex" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of selected output audio devices (-1 if default)" | ||||
|     }, | ||||
|     "outputDevices" : { | ||||
|       "type" : "array", | ||||
|       "description" : "Names of output devices", | ||||
| @ -726,12 +734,12 @@ margin-bottom: 20px; | ||||
|             defs.AudioDevicesSelect = { | ||||
|   "properties" : { | ||||
|     "input" : { | ||||
|       "type" : "string", | ||||
|       "description" : "Name of the audio input device" | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of the audio input device (-1 for default)" | ||||
|     }, | ||||
|     "output" : { | ||||
|       "type" : "string", | ||||
|       "description" : "Name of the audio output device" | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of the audio output device (-1 for default)" | ||||
|     } | ||||
|   }, | ||||
|   "description" : "Audio devices selected" | ||||
| @ -7356,7 +7364,7 @@ except ApiException as e: | ||||
|           </div> | ||||
|           <div id="generator"> | ||||
|             <div class="content"> | ||||
|               Generated 2017-11-24T00:55:01.257+01:00 | ||||
|               Generated 2017-11-24T08:42:52.359+01:00 | ||||
|             </div> | ||||
|           </div> | ||||
|       </div> | ||||
|  | ||||
| @ -22,4 +22,4 @@ QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel"; | ||||
| QString WebAPIAdapterInterface::instanceDevicesURL = "/sdrangel/devices"; | ||||
| QString WebAPIAdapterInterface::instanceChannelsURL = "/sdrangel/channels"; | ||||
| QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging"; | ||||
| 
 | ||||
| QString WebAPIAdapterInterface::instanceAudioURL = "/sdrangel/audio"; | ||||
|  | ||||
| @ -27,6 +27,7 @@ namespace Swagger | ||||
|     class SWGInstanceDevicesResponse; | ||||
|     class SWGInstanceChannelsResponse; | ||||
|     class SWGLoggingInfo; | ||||
|     class SWGAudioDevices; | ||||
|     class SWGErrorResponse; | ||||
| } | ||||
| 
 | ||||
| @ -82,10 +83,20 @@ public: | ||||
|             Swagger::SWGErrorResponse& error __attribute__((unused))) | ||||
|     { return 501; } | ||||
| 
 | ||||
|     /**
 | ||||
|      * Handler of /sdrangel/audio (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels | ||||
|      * returns the Http status code (default 501: not implemented) | ||||
|      */ | ||||
|     virtual int instanceAudioGet( | ||||
|             Swagger::SWGAudioDevices& response __attribute__((unused)), | ||||
|             Swagger::SWGErrorResponse& error __attribute__((unused))) | ||||
|     { return 501; } | ||||
| 
 | ||||
|     static QString instanceSummaryURL; | ||||
|     static QString instanceDevicesURL; | ||||
|     static QString instanceChannelsURL; | ||||
|     static QString instanceLoggingURL; | ||||
|     static QString instanceAudioURL; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -25,6 +25,8 @@ | ||||
| #include "SWGInstanceSummaryResponse.h" | ||||
| #include "SWGInstanceDevicesResponse.h" | ||||
| #include "SWGInstanceChannelsResponse.h" | ||||
| #include "SWGAudioDevices.h" | ||||
| #include "SWGAudioDevicesSelect.h" | ||||
| #include "SWGErrorResponse.h" | ||||
| 
 | ||||
| WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : | ||||
| @ -185,6 +187,33 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http | ||||
|                 response.write("Invalid HTTP method"); | ||||
|             } | ||||
|         } | ||||
|         else if (path == WebAPIAdapterInterface::instanceAudioURL) | ||||
|         { | ||||
|             Swagger::SWGErrorResponse errorResponse; | ||||
| 
 | ||||
|             if (request.getMethod() == "GET") | ||||
|             { | ||||
|                 Swagger::SWGAudioDevices normalResponse; | ||||
| 
 | ||||
|                 int status = m_adapter->instanceAudioGet(normalResponse, errorResponse); | ||||
|                 response.setStatus(status); | ||||
| 
 | ||||
|                 if (status == 200) { | ||||
|                     response.write(normalResponse.asJson().toUtf8()); | ||||
|                 } else { | ||||
|                     response.write(errorResponse.asJson().toUtf8()); | ||||
|                 } | ||||
|             } | ||||
|             else if (request.getMethod() == "PATCH") | ||||
|             { | ||||
|                 Swagger::SWGAudioDevicesSelect normalResponse; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 response.setStatus(405,"Invalid HTTP method"); | ||||
|                 response.write("Invalid HTTP method"); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
| //            QDirIterator it(":", QDirIterator::Subdirectories);
 | ||||
|  | ||||
| @ -36,6 +36,7 @@ | ||||
| #include "SWGInstanceDevicesResponse.h" | ||||
| #include "SWGInstanceChannelsResponse.h" | ||||
| #include "SWGDeviceListItem.h" | ||||
| #include "SWGAudioDevices.h" | ||||
| #include "SWGErrorResponse.h" | ||||
| 
 | ||||
| #include "webapiadaptergui.h" | ||||
| @ -249,6 +250,38 @@ int WebAPIAdapterGUI::instanceLoggingPut( | ||||
|     return 200; | ||||
| } | ||||
| 
 | ||||
| int WebAPIAdapterGUI::instanceAudioGet( | ||||
|             Swagger::SWGAudioDevices& response, | ||||
|             Swagger::SWGErrorResponse& error __attribute__((unused))) | ||||
| { | ||||
|     const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices(); | ||||
|     const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices(); | ||||
|     int nbInputDevices = audioInputDevices.size(); | ||||
|     int nbOutputDevices = audioOutputDevices.size(); | ||||
| 
 | ||||
|     response.init(); | ||||
|     response.setNbInputDevices(nbInputDevices); | ||||
|     response.setInputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex()); | ||||
|     response.setNbOutputDevices(nbOutputDevices); | ||||
|     response.setOutputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex()); | ||||
|     QList<QString*> *inputDeviceNames = response.getInputDevices(); | ||||
|     QList<QString*> *outputDeviceNames = response.getOutputDevices(); | ||||
| 
 | ||||
|     for (int i = 0; i < nbInputDevices; i++) | ||||
|     { | ||||
|         inputDeviceNames->append(new QString()); | ||||
|         *inputDeviceNames->back() = audioInputDevices[i].deviceName(); | ||||
|     } | ||||
| 
 | ||||
|     for (int i = 0; i < nbOutputDevices; i++) | ||||
|     { | ||||
|         outputDeviceNames->append(new QString()); | ||||
|         *outputDeviceNames->back() = audioOutputDevices[i].deviceName(); | ||||
|     } | ||||
| 
 | ||||
|     return 200; | ||||
| } | ||||
| 
 | ||||
| QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString) | ||||
| { | ||||
|     if (msgTypeString == "debug") { | ||||
|  | ||||
| @ -53,6 +53,10 @@ public: | ||||
|             Swagger::SWGLoggingInfo& response, | ||||
|             Swagger::SWGErrorResponse& error); | ||||
| 
 | ||||
|     virtual int instanceAudioGet( | ||||
|             Swagger::SWGAudioDevices& response, | ||||
|             Swagger::SWGErrorResponse& error); | ||||
| 
 | ||||
| private: | ||||
|     MainWindow& m_mainWindow; | ||||
| 
 | ||||
|  | ||||
| @ -634,11 +634,16 @@ definitions: | ||||
|     description: "List of audio devices available in the system" | ||||
|     required: | ||||
|       - nbInputDevices | ||||
|       - inputDeviceSelectedIndex | ||||
|       - nbOutputDevices | ||||
|       - outputDeviceSelectedIndex | ||||
|     properties: | ||||
|       nbInputDevices: | ||||
|         description: "Number of input audio devices" | ||||
|         type: integer | ||||
|       inputDeviceSelectedIndex: | ||||
|         description: "Index of selected input audio devices (-1 if default)" | ||||
|         type: integer | ||||
|       inputDevices: | ||||
|         description: "Names of input devices" | ||||
|         type: array | ||||
| @ -647,6 +652,9 @@ definitions: | ||||
|       nbOutputDevices: | ||||
|         description: "Number of output audio devices" | ||||
|         type: integer | ||||
|       outputDeviceSelectedIndex: | ||||
|         description: "Index of selected output audio devices (-1 if default)" | ||||
|         type: integer | ||||
|       outputDevices: | ||||
|         description: "Names of output devices" | ||||
|         type: array | ||||
| @ -656,11 +664,11 @@ definitions: | ||||
|     description: "Audio devices selected" | ||||
|     properties: | ||||
|       input: | ||||
|         description: "Name of the audio input device" | ||||
|         type: string | ||||
|         description: "Index of the audio input device (-1 for default)" | ||||
|         type: integer | ||||
|       output: | ||||
|         description: "Name of the audio output device" | ||||
|         type: string | ||||
|         description: "Index of the audio output device (-1 for default)" | ||||
|         type: integer | ||||
|   LocationInformation: | ||||
|     description: "Instance geolocation information" | ||||
|     required: | ||||
|  | ||||
| @ -696,12 +696,16 @@ margin-bottom: 20px; | ||||
|     // Script section to load models into a JS Var | ||||
|     var defs = {} | ||||
|             defs.AudioDevices = { | ||||
|   "required" : [ "nbInputDevices", "nbOutputDevices" ], | ||||
|   "required" : [ "inputDeviceSelectedIndex", "nbInputDevices", "nbOutputDevices", "outputDeviceSelectedIndex" ], | ||||
|   "properties" : { | ||||
|     "nbInputDevices" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Number of input audio devices" | ||||
|     }, | ||||
|     "inputDeviceSelectedIndex" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of selected input audio devices (-1 if default)" | ||||
|     }, | ||||
|     "inputDevices" : { | ||||
|       "type" : "array", | ||||
|       "description" : "Names of input devices", | ||||
| @ -713,6 +717,10 @@ margin-bottom: 20px; | ||||
|       "type" : "integer", | ||||
|       "description" : "Number of output audio devices" | ||||
|     }, | ||||
|     "outputDeviceSelectedIndex" : { | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of selected output audio devices (-1 if default)" | ||||
|     }, | ||||
|     "outputDevices" : { | ||||
|       "type" : "array", | ||||
|       "description" : "Names of output devices", | ||||
| @ -726,12 +734,12 @@ margin-bottom: 20px; | ||||
|             defs.AudioDevicesSelect = { | ||||
|   "properties" : { | ||||
|     "input" : { | ||||
|       "type" : "string", | ||||
|       "description" : "Name of the audio input device" | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of the audio input device (-1 for default)" | ||||
|     }, | ||||
|     "output" : { | ||||
|       "type" : "string", | ||||
|       "description" : "Name of the audio output device" | ||||
|       "type" : "integer", | ||||
|       "description" : "Index of the audio output device (-1 for default)" | ||||
|     } | ||||
|   }, | ||||
|   "description" : "Audio devices selected" | ||||
| @ -7356,7 +7364,7 @@ except ApiException as e: | ||||
|           </div> | ||||
|           <div id="generator"> | ||||
|             <div class="content"> | ||||
|               Generated 2017-11-24T00:55:01.257+01:00 | ||||
|               Generated 2017-11-24T08:42:52.359+01:00 | ||||
|             </div> | ||||
|           </div> | ||||
|       </div> | ||||
|  | ||||
| @ -38,8 +38,10 @@ SWGAudioDevices::~SWGAudioDevices() { | ||||
| void | ||||
| SWGAudioDevices::init() { | ||||
|     nb_input_devices = 0; | ||||
|     input_device_selected_index = 0; | ||||
|     input_devices = new QList<QString*>(); | ||||
|     nb_output_devices = 0; | ||||
|     output_device_selected_index = 0; | ||||
|     output_devices = new QList<QString*>(); | ||||
| } | ||||
| 
 | ||||
| @ -47,6 +49,7 @@ void | ||||
| SWGAudioDevices::cleanup() { | ||||
|      | ||||
| 
 | ||||
| 
 | ||||
|     if(input_devices != nullptr) { | ||||
|         QList<QString*>* arr = input_devices; | ||||
|         foreach(QString* o, *arr) { | ||||
| @ -56,6 +59,7 @@ SWGAudioDevices::cleanup() { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     if(output_devices != nullptr) { | ||||
|         QList<QString*>* arr = output_devices; | ||||
|         foreach(QString* o, *arr) { | ||||
| @ -77,10 +81,12 @@ SWGAudioDevices::fromJson(QString &json) { | ||||
| void | ||||
| SWGAudioDevices::fromJsonObject(QJsonObject &pJson) { | ||||
|     ::Swagger::setValue(&nb_input_devices, pJson["nbInputDevices"], "qint32", ""); | ||||
|     ::Swagger::setValue(&input_device_selected_index, pJson["inputDeviceSelectedIndex"], "qint32", ""); | ||||
|      | ||||
|     ::Swagger::setValue(&input_devices, pJson["inputDevices"], "QList", "QString"); | ||||
|      | ||||
|     ::Swagger::setValue(&nb_output_devices, pJson["nbOutputDevices"], "qint32", ""); | ||||
|     ::Swagger::setValue(&output_device_selected_index, pJson["outputDeviceSelectedIndex"], "qint32", ""); | ||||
|      | ||||
|     ::Swagger::setValue(&output_devices, pJson["outputDevices"], "QList", "QString"); | ||||
|      | ||||
| @ -102,12 +108,16 @@ SWGAudioDevices::asJsonObject() { | ||||
|      | ||||
|     obj->insert("nbInputDevices", QJsonValue(nb_input_devices)); | ||||
| 
 | ||||
|     obj->insert("inputDeviceSelectedIndex", QJsonValue(input_device_selected_index)); | ||||
| 
 | ||||
|     QJsonArray input_devicesJsonArray; | ||||
|     toJsonArray((QList<void*>*)input_devices, &input_devicesJsonArray, "input_devices", "QString"); | ||||
|     obj->insert("inputDevices", input_devicesJsonArray); | ||||
| 
 | ||||
|     obj->insert("nbOutputDevices", QJsonValue(nb_output_devices)); | ||||
| 
 | ||||
|     obj->insert("outputDeviceSelectedIndex", QJsonValue(output_device_selected_index)); | ||||
| 
 | ||||
|     QJsonArray output_devicesJsonArray; | ||||
|     toJsonArray((QList<void*>*)output_devices, &output_devicesJsonArray, "output_devices", "QString"); | ||||
|     obj->insert("outputDevices", output_devicesJsonArray); | ||||
| @ -124,6 +134,15 @@ SWGAudioDevices::setNbInputDevices(qint32 nb_input_devices) { | ||||
|     this->nb_input_devices = nb_input_devices; | ||||
| } | ||||
| 
 | ||||
| qint32 | ||||
| SWGAudioDevices::getInputDeviceSelectedIndex() { | ||||
|     return input_device_selected_index; | ||||
| } | ||||
| void | ||||
| SWGAudioDevices::setInputDeviceSelectedIndex(qint32 input_device_selected_index) { | ||||
|     this->input_device_selected_index = input_device_selected_index; | ||||
| } | ||||
| 
 | ||||
| QList<QString*>* | ||||
| SWGAudioDevices::getInputDevices() { | ||||
|     return input_devices; | ||||
| @ -142,6 +161,15 @@ SWGAudioDevices::setNbOutputDevices(qint32 nb_output_devices) { | ||||
|     this->nb_output_devices = nb_output_devices; | ||||
| } | ||||
| 
 | ||||
| qint32 | ||||
| SWGAudioDevices::getOutputDeviceSelectedIndex() { | ||||
|     return output_device_selected_index; | ||||
| } | ||||
| void | ||||
| SWGAudioDevices::setOutputDeviceSelectedIndex(qint32 output_device_selected_index) { | ||||
|     this->output_device_selected_index = output_device_selected_index; | ||||
| } | ||||
| 
 | ||||
| QList<QString*>* | ||||
| SWGAudioDevices::getOutputDevices() { | ||||
|     return output_devices; | ||||
|  | ||||
| @ -46,20 +46,28 @@ public: | ||||
|     qint32 getNbInputDevices(); | ||||
|     void setNbInputDevices(qint32 nb_input_devices); | ||||
| 
 | ||||
|     qint32 getInputDeviceSelectedIndex(); | ||||
|     void setInputDeviceSelectedIndex(qint32 input_device_selected_index); | ||||
| 
 | ||||
|     QList<QString*>* getInputDevices(); | ||||
|     void setInputDevices(QList<QString*>* input_devices); | ||||
| 
 | ||||
|     qint32 getNbOutputDevices(); | ||||
|     void setNbOutputDevices(qint32 nb_output_devices); | ||||
| 
 | ||||
|     qint32 getOutputDeviceSelectedIndex(); | ||||
|     void setOutputDeviceSelectedIndex(qint32 output_device_selected_index); | ||||
| 
 | ||||
|     QList<QString*>* getOutputDevices(); | ||||
|     void setOutputDevices(QList<QString*>* output_devices); | ||||
| 
 | ||||
| 
 | ||||
| private: | ||||
|     qint32 nb_input_devices; | ||||
|     qint32 input_device_selected_index; | ||||
|     QList<QString*>* input_devices; | ||||
|     qint32 nb_output_devices; | ||||
|     qint32 output_device_selected_index; | ||||
|     QList<QString*>* output_devices; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -37,20 +37,14 @@ SWGAudioDevicesSelect::~SWGAudioDevicesSelect() { | ||||
| 
 | ||||
| void | ||||
| SWGAudioDevicesSelect::init() { | ||||
|     input = new QString(""); | ||||
|     output = new QString(""); | ||||
|     input = 0; | ||||
|     output = 0; | ||||
| } | ||||
| 
 | ||||
| void | ||||
| SWGAudioDevicesSelect::cleanup() { | ||||
|      | ||||
|     if(input != nullptr) { | ||||
|         delete input; | ||||
|     } | ||||
| 
 | ||||
|     if(output != nullptr) { | ||||
|         delete output; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| SWGAudioDevicesSelect* | ||||
| @ -64,8 +58,8 @@ SWGAudioDevicesSelect::fromJson(QString &json) { | ||||
| 
 | ||||
| void | ||||
| SWGAudioDevicesSelect::fromJsonObject(QJsonObject &pJson) { | ||||
|     ::Swagger::setValue(&input, pJson["input"], "QString", "QString"); | ||||
|     ::Swagger::setValue(&output, pJson["output"], "QString", "QString"); | ||||
|     ::Swagger::setValue(&input, pJson["input"], "qint32", ""); | ||||
|     ::Swagger::setValue(&output, pJson["output"], "qint32", ""); | ||||
| } | ||||
| 
 | ||||
| QString | ||||
| @ -82,28 +76,28 @@ QJsonObject* | ||||
| SWGAudioDevicesSelect::asJsonObject() { | ||||
|     QJsonObject* obj = new QJsonObject(); | ||||
|      | ||||
|     toJsonValue(QString("input"), input, obj, QString("QString")); | ||||
|     obj->insert("input", QJsonValue(input)); | ||||
| 
 | ||||
|     toJsonValue(QString("output"), output, obj, QString("QString")); | ||||
|     obj->insert("output", QJsonValue(output)); | ||||
| 
 | ||||
|     return obj; | ||||
| } | ||||
| 
 | ||||
| QString* | ||||
| qint32 | ||||
| SWGAudioDevicesSelect::getInput() { | ||||
|     return input; | ||||
| } | ||||
| void | ||||
| SWGAudioDevicesSelect::setInput(QString* input) { | ||||
| SWGAudioDevicesSelect::setInput(qint32 input) { | ||||
|     this->input = input; | ||||
| } | ||||
| 
 | ||||
| QString* | ||||
| qint32 | ||||
| SWGAudioDevicesSelect::getOutput() { | ||||
|     return output; | ||||
| } | ||||
| void | ||||
| SWGAudioDevicesSelect::setOutput(QString* output) { | ||||
| SWGAudioDevicesSelect::setOutput(qint32 output) { | ||||
|     this->output = output; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -22,7 +22,6 @@ | ||||
| #include <QJsonObject> | ||||
| 
 | ||||
| 
 | ||||
| #include <QString> | ||||
| 
 | ||||
| #include "SWGObject.h" | ||||
| 
 | ||||
| @ -42,16 +41,16 @@ public: | ||||
|     void fromJsonObject(QJsonObject &json); | ||||
|     SWGAudioDevicesSelect* fromJson(QString &jsonString); | ||||
| 
 | ||||
|     QString* getInput(); | ||||
|     void setInput(QString* input); | ||||
|     qint32 getInput(); | ||||
|     void setInput(qint32 input); | ||||
| 
 | ||||
|     QString* getOutput(); | ||||
|     void setOutput(QString* output); | ||||
|     qint32 getOutput(); | ||||
|     void setOutput(qint32 output); | ||||
| 
 | ||||
| 
 | ||||
| private: | ||||
|     QString* input; | ||||
|     QString* output; | ||||
|     qint32 input; | ||||
|     qint32 output; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user