diff --git a/sdrbase/resources/index.html b/sdrbase/resources/index.html index 1ee9e4225..798f8d825 100644 --- a/sdrbase/resources/index.html +++ b/sdrbase/resources/index.html @@ -779,8 +779,8 @@ margin-bottom: 20px; "description" : "Key to identify the channel plugin type as short object name" }, "tx" : { - "type" : "boolean", - "description" : "True if this is a Tx channel" + "type" : "integer", + "description" : "Not zero (true) if this is a Tx channel" }, "version" : { "type" : "string", @@ -830,8 +830,8 @@ margin-bottom: 20px; "description" : "Sequence in the enumeration of same device types" }, "tx" : { - "type" : "boolean", - "description" : "Set to true if this is a Tx device" + "type" : "integer", + "description" : "Set to not zero (true) if this is a Tx device" }, "nbStreams" : { "type" : "integer", @@ -964,7 +964,6 @@ margin-bottom: 20px; "description" : "Instance geolocation information" }; defs.LoggingInfo = { - "required" : [ "consoleLevel", "fileLevel" ], "properties" : { "consoleLevel" : { "type" : "string", @@ -975,8 +974,8 @@ margin-bottom: 20px; "description" : "Minimum level of messages written to file: debug, info, warning, error" }, "dumpToFile" : { - "type" : "boolean", - "description" : "True if messages are written to file" + "type" : "integer", + "description" : "not zero (true) if messages are written to file" }, "fileName" : { "type" : "string", @@ -1088,8 +1087,8 @@ margin-bottom: 20px; "description" : "Key to identify the type of hardware device" }, "tx" : { - "type" : "boolean", - "description" : "True if this is a Tx device" + "type" : "integer", + "description" : "Not zero (true) if this is a Tx device" }, "nbStreams" : { "type" : "integer", @@ -5099,9 +5098,44 @@ $(document).ready(function() {

Status: 400 - Invallid data

+
+
+ +
+ +

Status: 500 - Error

@@ -7322,7 +7356,7 @@ except ApiException as e:
- Generated 2017-11-23T00:55:26.644+01:00 + Generated 2017-11-24T00:44:01.796+01:00
diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 4e55a4a5a..b0d4df33d 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -17,6 +17,8 @@ /////////////////////////////////////////////////////////////////////////////////// //#include +#include +#include #include "httpdocrootsettings.h" #include "webapirequestmapper.h" @@ -43,8 +45,8 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http { if (m_adapter == 0) // format service unavailable if adapter is null { - response.write("Service not available"); response.setStatus(500,"Service not available"); + response.write("Service not available"); } else // normal processing { @@ -58,19 +60,18 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http Swagger::SWGErrorResponse errorResponse; int status = m_adapter->instanceSummary(normalResponse, errorResponse); + response.setStatus(status); if (status == 200) { response.write(normalResponse.asJson().toUtf8()); } else { response.write(errorResponse.asJson().toUtf8()); } - - response.setStatus(status); } else { - response.write("Invalid HTTP method"); response.setStatus(405,"Invalid HTTP method"); + response.write("Invalid HTTP method"); } } else if (path == WebAPIAdapterInterface::instanceDevicesURL) @@ -84,19 +85,18 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http bool tx = (txStr == "true"); int status = m_adapter->instanceDevices(tx, normalResponse, errorResponse); + response.setStatus(status); if (status == 200) { response.write(normalResponse.asJson().toUtf8()); } else { response.write(errorResponse.asJson().toUtf8()); } - - response.setStatus(status); } else { - response.write("Invalid HTTP method"); response.setStatus(405,"Invalid HTTP method"); + response.write("Invalid HTTP method"); } } else if (path == WebAPIAdapterInterface::instanceChannelsURL) @@ -110,19 +110,18 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http bool tx = (txStr == "true"); int status = m_adapter->instanceChannels(tx, normalResponse, errorResponse); + response.setStatus(status); if (status == 200) { response.write(normalResponse.asJson().toUtf8()); } else { response.write(errorResponse.asJson().toUtf8()); } - - response.setStatus(status); } else { - response.write("Invalid HTTP method"); response.setStatus(405,"Invalid HTTP method"); + response.write("Invalid HTTP method"); } } else if (path == WebAPIAdapterInterface::instanceLoggingURL) @@ -133,42 +132,57 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http if (request.getMethod() == "GET") { int status = m_adapter->instanceLoggingGet(normalResponse, errorResponse); + response.setStatus(status); if (status == 200) { response.write(normalResponse.asJson().toUtf8()); } else { response.write(errorResponse.asJson().toUtf8()); } - - response.setStatus(status); } else if (request.getMethod() == "PUT") { try { QString jsonStr = request.getBody(); - qDebug("WebAPIRequestMapper::service: /sdrangel/logging (PUT): %s", qPrintable(jsonStr)); - normalResponse.fromJson(jsonStr); - int status = m_adapter->instanceLoggingPut(normalResponse, errorResponse); + QByteArray jsonBytes(jsonStr.toStdString().c_str()); + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error); - if (status == 200) { - response.write(normalResponse.asJson().toUtf8()); - } else { + if (error.error == QJsonParseError::NoError) + { + normalResponse.fromJson(jsonStr); + int status = m_adapter->instanceLoggingPut(normalResponse, errorResponse); + response.setStatus(status); + + if (status == 200) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else + { + QString errorMsg = QString("Input JSON error: ") + error.errorString(); + errorResponse.init(); + *errorResponse.getMessage() = errorMsg; + response.setStatus(400, errorMsg.toUtf8()); response.write(errorResponse.asJson().toUtf8()); } - - response.setStatus(status); } catch (const std::exception& ex) { - response.write("Invalid input format"); - response.setStatus(400,"Invalid input format"); + QString errorMsg = QString("Error parsing request: ") + ex.what(); + errorResponse.init(); + *errorResponse.getMessage() = errorMsg; + response.setStatus(500, errorMsg.toUtf8()); + response.write(errorResponse.asJson().toUtf8()); } } else { - response.write("Invalid HTTP method"); response.setStatus(405,"Invalid HTTP method"); + response.write("Invalid HTTP method"); } } else diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 53782407d..37663444d 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -58,7 +58,7 @@ int WebAPIAdapterGUI::instanceSummary( Swagger::SWGLoggingInfo *logging = response.getLogging(); logging->init(); - logging->setDumpToFile(m_mainWindow.m_logger->getUseFileLogger()); + logging->setDumpToFile(m_mainWindow.m_logger->getUseFileLogger() ? 1 : 0); if (logging->getDumpToFile()) { m_mainWindow.m_logger->getLogFileName(*logging->getFileName()); m_mainWindow.m_logger->getFileMinMessageLevelStr(*logging->getFileLevel()); @@ -198,9 +198,9 @@ int WebAPIAdapterGUI::instanceChannels( int WebAPIAdapterGUI::instanceLoggingGet( Swagger::SWGLoggingInfo& response, - Swagger::SWGErrorResponse& error) + Swagger::SWGErrorResponse& error __attribute__((unused))) { - response.setDumpToFile(m_mainWindow.m_logger->getUseFileLogger()); + response.setDumpToFile(m_mainWindow.m_logger->getUseFileLogger() ? 1 : 0); if (response.getDumpToFile()) { m_mainWindow.m_logger->getLogFileName(*response.getFileName()); @@ -214,10 +214,10 @@ int WebAPIAdapterGUI::instanceLoggingGet( int WebAPIAdapterGUI::instanceLoggingPut( Swagger::SWGLoggingInfo& response, - Swagger::SWGErrorResponse& error) + Swagger::SWGErrorResponse& error __attribute__((unused))) { // response input is the query actually - bool dumpToFile = response.getDumpToFile(); + bool dumpToFile = (response.getDumpToFile() != 0); QString* consoleLevel = response.getConsoleLevel(); QString* fileLevel = response.getFileLevel(); QString* fileName = response.getFileName(); @@ -234,21 +234,17 @@ int WebAPIAdapterGUI::instanceLoggingPut( m_mainWindow.m_settings.setUseLogFile(dumpToFile); if (fileName) { - m_mainWindow.m_settings.setLogFileName(*fileLevel); + m_mainWindow.m_settings.setLogFileName(*fileName); } m_mainWindow.setLoggingOpions(); // build response - response.setDumpToFile(m_mainWindow.m_settings.getUseLogFile()); - - if (response.getDumpToFile()) - { - *response.getFileName() = m_mainWindow.m_settings.getLogFileName(); - getMsgTypeString(m_mainWindow.m_settings.getFileMinLogLevel(), *response.getFileLevel()); - } - + response.init(); getMsgTypeString(m_mainWindow.m_settings.getConsoleMinLogLevel(), *response.getConsoleLevel()); + response.setDumpToFile(m_mainWindow.m_settings.getUseLogFile() ? 1 : 0); + getMsgTypeString(m_mainWindow.m_settings.getFileMinLogLevel(), *response.getFileLevel()); + *response.getFileName() = m_mainWindow.m_settings.getLogFileName(); return 200; } diff --git a/swagger/sdrangel/api/swagger/swagger.yaml b/swagger/sdrangel/api/swagger/swagger.yaml index 6cacab7c3..e0698743e 100644 --- a/swagger/sdrangel/api/swagger/swagger.yaml +++ b/swagger/sdrangel/api/swagger/swagger.yaml @@ -121,6 +121,8 @@ paths: $ref: "#/definitions/LoggingInfo" "400": description: Invallid data + schema: + $ref: "#/definitions/ErrorResponse" "500": description: Error schema: @@ -462,9 +464,6 @@ definitions: type: string LoggingInfo: description: "Logging parameters setting" - required: - - consoleLevel - - fileLevel properties: consoleLevel: description: "Minimum level of messages printed to console: debug, info, warning, error" @@ -473,8 +472,8 @@ definitions: description: "Minimum level of messages written to file: debug, info, warning, error" type: string dumpToFile: - description: "True if messages are written to file" - type: boolean + description: "not zero (true) if messages are written to file" + type: integer fileName: description: "Name of the log file" type: string @@ -496,8 +495,8 @@ definitions: description: "Sequence in the enumeration of same device types" type: integer tx: - description: "Set to true if this is a Tx device" - type: boolean + description: "Set to not zero (true) if this is a Tx device" + type: integer nbStreams: description: "Number of channels or streams in the device" type: integer @@ -526,8 +525,8 @@ definitions: description: "Key to identify the channel plugin type as short object name" type: string tx: - description: "True if this is a Tx channel" - type: boolean + description: "Not zero (true) if this is a Tx channel" + type: integer version: description: "Channel plugin version number" type: string @@ -582,8 +581,8 @@ definitions: description: "Key to identify the type of hardware device" type: string tx: - description: "True if this is a Tx device" - type: boolean + description: "Not zero (true) if this is a Tx device" + type: integer nbStreams: description: "Number of channels or streams in the device" type: integer diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 1ee9e4225..798f8d825 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -779,8 +779,8 @@ margin-bottom: 20px; "description" : "Key to identify the channel plugin type as short object name" }, "tx" : { - "type" : "boolean", - "description" : "True if this is a Tx channel" + "type" : "integer", + "description" : "Not zero (true) if this is a Tx channel" }, "version" : { "type" : "string", @@ -830,8 +830,8 @@ margin-bottom: 20px; "description" : "Sequence in the enumeration of same device types" }, "tx" : { - "type" : "boolean", - "description" : "Set to true if this is a Tx device" + "type" : "integer", + "description" : "Set to not zero (true) if this is a Tx device" }, "nbStreams" : { "type" : "integer", @@ -964,7 +964,6 @@ margin-bottom: 20px; "description" : "Instance geolocation information" }; defs.LoggingInfo = { - "required" : [ "consoleLevel", "fileLevel" ], "properties" : { "consoleLevel" : { "type" : "string", @@ -975,8 +974,8 @@ margin-bottom: 20px; "description" : "Minimum level of messages written to file: debug, info, warning, error" }, "dumpToFile" : { - "type" : "boolean", - "description" : "True if messages are written to file" + "type" : "integer", + "description" : "not zero (true) if messages are written to file" }, "fileName" : { "type" : "string", @@ -1088,8 +1087,8 @@ margin-bottom: 20px; "description" : "Key to identify the type of hardware device" }, "tx" : { - "type" : "boolean", - "description" : "True if this is a Tx device" + "type" : "integer", + "description" : "Not zero (true) if this is a Tx device" }, "nbStreams" : { "type" : "integer", @@ -5099,9 +5098,44 @@ $(document).ready(function() {

Status: 400 - Invallid data

+
+
+ +
+ +

Status: 500 - Error

@@ -7322,7 +7356,7 @@ except ApiException as e:
- Generated 2017-11-23T00:55:26.644+01:00 + Generated 2017-11-24T00:44:01.796+01:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelListItem.cpp b/swagger/sdrangel/code/qt5/client/SWGChannelListItem.cpp index ac90362ea..ab66c9e91 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelListItem.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannelListItem.cpp @@ -40,7 +40,7 @@ SWGChannelListItem::init() { name = new QString(""); id_uri = new QString(""); id = new QString(""); - tx = false; + tx = 0; version = new QString(""); index = 0; } @@ -81,7 +81,7 @@ SWGChannelListItem::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); ::Swagger::setValue(&id_uri, pJson["idURI"], "QString", "QString"); ::Swagger::setValue(&id, pJson["id"], "QString", "QString"); - ::Swagger::setValue(&tx, pJson["tx"], "bool", ""); + ::Swagger::setValue(&tx, pJson["tx"], "qint32", ""); ::Swagger::setValue(&version, pJson["version"], "QString", "QString"); ::Swagger::setValue(&index, pJson["index"], "qint32", ""); } @@ -142,12 +142,12 @@ SWGChannelListItem::setId(QString* id) { this->id = id; } -bool +qint32 SWGChannelListItem::getTx() { return tx; } void -SWGChannelListItem::setTx(bool tx) { +SWGChannelListItem::setTx(qint32 tx) { this->tx = tx; } diff --git a/swagger/sdrangel/code/qt5/client/SWGChannelListItem.h b/swagger/sdrangel/code/qt5/client/SWGChannelListItem.h index e564a5eb1..d9163f168 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannelListItem.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannelListItem.h @@ -51,8 +51,8 @@ public: QString* getId(); void setId(QString* id); - bool getTx(); - void setTx(bool tx); + qint32 getTx(); + void setTx(qint32 tx); QString* getVersion(); void setVersion(QString* version); @@ -65,7 +65,7 @@ private: QString* name; QString* id_uri; QString* id; - bool tx; + qint32 tx; QString* version; qint32 index; }; diff --git a/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.cpp b/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.cpp index 11ba2ac4b..713204f55 100644 --- a/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.cpp @@ -41,7 +41,7 @@ SWGDeviceListItem::init() { hw_type = new QString(""); serial = new QString(""); sequence = 0; - tx = false; + tx = 0; nb_streams = 0; stream_index = 0; device_set_index = 0; @@ -85,7 +85,7 @@ SWGDeviceListItem::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&hw_type, pJson["hwType"], "QString", "QString"); ::Swagger::setValue(&serial, pJson["serial"], "QString", "QString"); ::Swagger::setValue(&sequence, pJson["sequence"], "qint32", ""); - ::Swagger::setValue(&tx, pJson["tx"], "bool", ""); + ::Swagger::setValue(&tx, pJson["tx"], "qint32", ""); ::Swagger::setValue(&nb_streams, pJson["nbStreams"], "qint32", ""); ::Swagger::setValue(&stream_index, pJson["streamIndex"], "qint32", ""); ::Swagger::setValue(&device_set_index, pJson["deviceSetIndex"], "qint32", ""); @@ -163,12 +163,12 @@ SWGDeviceListItem::setSequence(qint32 sequence) { this->sequence = sequence; } -bool +qint32 SWGDeviceListItem::getTx() { return tx; } void -SWGDeviceListItem::setTx(bool tx) { +SWGDeviceListItem::setTx(qint32 tx) { this->tx = tx; } diff --git a/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.h b/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.h index 4fd9ac5b5..3d4df2302 100644 --- a/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.h +++ b/swagger/sdrangel/code/qt5/client/SWGDeviceListItem.h @@ -54,8 +54,8 @@ public: qint32 getSequence(); void setSequence(qint32 sequence); - bool getTx(); - void setTx(bool tx); + qint32 getTx(); + void setTx(qint32 tx); qint32 getNbStreams(); void setNbStreams(qint32 nb_streams); @@ -75,7 +75,7 @@ private: QString* hw_type; QString* serial; qint32 sequence; - bool tx; + qint32 tx; qint32 nb_streams; qint32 stream_index; qint32 device_set_index; diff --git a/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.cpp b/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.cpp index f4b3b77c4..9cba94008 100644 --- a/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.cpp @@ -39,7 +39,7 @@ void SWGLoggingInfo::init() { console_level = new QString(""); file_level = new QString(""); - dump_to_file = false; + dump_to_file = 0; file_name = new QString(""); } @@ -73,7 +73,7 @@ void SWGLoggingInfo::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&console_level, pJson["consoleLevel"], "QString", "QString"); ::Swagger::setValue(&file_level, pJson["fileLevel"], "QString", "QString"); - ::Swagger::setValue(&dump_to_file, pJson["dumpToFile"], "bool", ""); + ::Swagger::setValue(&dump_to_file, pJson["dumpToFile"], "qint32", ""); ::Swagger::setValue(&file_name, pJson["fileName"], "QString", "QString"); } @@ -120,12 +120,12 @@ SWGLoggingInfo::setFileLevel(QString* file_level) { this->file_level = file_level; } -bool +qint32 SWGLoggingInfo::getDumpToFile() { return dump_to_file; } void -SWGLoggingInfo::setDumpToFile(bool dump_to_file) { +SWGLoggingInfo::setDumpToFile(qint32 dump_to_file) { this->dump_to_file = dump_to_file; } diff --git a/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.h b/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.h index a28d354f7..7194e3997 100644 --- a/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.h +++ b/swagger/sdrangel/code/qt5/client/SWGLoggingInfo.h @@ -48,8 +48,8 @@ public: QString* getFileLevel(); void setFileLevel(QString* file_level); - bool getDumpToFile(); - void setDumpToFile(bool dump_to_file); + qint32 getDumpToFile(); + void setDumpToFile(qint32 dump_to_file); QString* getFileName(); void setFileName(QString* file_name); @@ -58,7 +58,7 @@ public: private: QString* console_level; QString* file_level; - bool dump_to_file; + qint32 dump_to_file; QString* file_name; }; diff --git a/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.cpp b/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.cpp index b04eba307..c818fc9a8 100644 --- a/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.cpp @@ -39,7 +39,7 @@ void SWGSamplingDevice::init() { index = 0; hw_type = new QString(""); - tx = false; + tx = 0; nb_streams = 0; stream_index = 0; sequence = 0; @@ -85,7 +85,7 @@ void SWGSamplingDevice::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&index, pJson["index"], "qint32", ""); ::Swagger::setValue(&hw_type, pJson["hwType"], "QString", "QString"); - ::Swagger::setValue(&tx, pJson["tx"], "bool", ""); + ::Swagger::setValue(&tx, pJson["tx"], "qint32", ""); ::Swagger::setValue(&nb_streams, pJson["nbStreams"], "qint32", ""); ::Swagger::setValue(&stream_index, pJson["streamIndex"], "qint32", ""); ::Swagger::setValue(&sequence, pJson["sequence"], "qint32", ""); @@ -150,12 +150,12 @@ SWGSamplingDevice::setHwType(QString* hw_type) { this->hw_type = hw_type; } -bool +qint32 SWGSamplingDevice::getTx() { return tx; } void -SWGSamplingDevice::setTx(bool tx) { +SWGSamplingDevice::setTx(qint32 tx) { this->tx = tx; } diff --git a/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.h b/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.h index c033316a1..b1853fc78 100644 --- a/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.h +++ b/swagger/sdrangel/code/qt5/client/SWGSamplingDevice.h @@ -48,8 +48,8 @@ public: QString* getHwType(); void setHwType(QString* hw_type); - bool getTx(); - void setTx(bool tx); + qint32 getTx(); + void setTx(qint32 tx); qint32 getNbStreams(); void setNbStreams(qint32 nb_streams); @@ -76,7 +76,7 @@ public: private: qint32 index; QString* hw_type; - bool tx; + qint32 tx; qint32 nb_streams; qint32 stream_index; qint32 sequence;