1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

Web API: /sdrangel/logging implementation (2)

This commit is contained in:
f4exb 2017-11-24 00:47:42 +01:00
parent 4999b04379
commit 7a2f60fe5d
13 changed files with 173 additions and 96 deletions

View File

@ -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() {
<h3> Status: 400 - Invallid data </h3>
<ul class="nav nav-tabs nav-tabs-examples" >
<li class="active">
<a data-toggle="tab" href="#responses-instanceLoggingPut-400-schema">Schema</a>
</li>
</ul>
<div class="tab-content" style='margin-bottom: 10px;'>
<div class="tab-pane active" id="responses-instanceLoggingPut-400-schema">
<div id='responses-instanceLoggingPut-400-schema-400' style="padding: 30px; border-left: 1px solid #eee; border-right: 1px solid #eee; border-bottom: 1px solid #eee;">
<script>
$(document).ready(function() {
var schemaWrapper = {
"description" : "Invallid data",
"schema" : {
"$ref" : "#/definitions/ErrorResponse"
}
};
var schema = schemaWrapper.schema;
if (schema.$ref != null) {
schema = defsParser.$refs.get(schema.$ref);
} else {
schemaWrapper.definitions = Object.assign({}, defs);
$RefParser.dereference(schemaWrapper).catch(function(err) {
console.log(err);
});
}
//console.log(JSON.stringify(schema));
var view = new JSONSchemaView(schema, 3);
$('#responses-instanceLoggingPut-400-schema-data').val(stringify(schema));
var result = $('#responses-instanceLoggingPut-400-schema-400');
result.empty();
result.append(view.render());
});
</script>
</div>
<input id='responses-instanceLoggingPut-400-schema-data' type='hidden' value=''></input>
</div>
</div>
<h3> Status: 500 - Error </h3>
@ -7322,7 +7356,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-11-23T00:55:26.644+01:00
Generated 2017-11-24T00:44:01.796+01:00
</div>
</div>
</div>

View File

@ -17,6 +17,8 @@
///////////////////////////////////////////////////////////////////////////////////
//#include <QDirIterator>
#include <QJsonDocument>
#include <QJsonArray>
#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

View File

@ -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;
}

View File

@ -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

View File

@ -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() {
<h3> Status: 400 - Invallid data </h3>
<ul class="nav nav-tabs nav-tabs-examples" >
<li class="active">
<a data-toggle="tab" href="#responses-instanceLoggingPut-400-schema">Schema</a>
</li>
</ul>
<div class="tab-content" style='margin-bottom: 10px;'>
<div class="tab-pane active" id="responses-instanceLoggingPut-400-schema">
<div id='responses-instanceLoggingPut-400-schema-400' style="padding: 30px; border-left: 1px solid #eee; border-right: 1px solid #eee; border-bottom: 1px solid #eee;">
<script>
$(document).ready(function() {
var schemaWrapper = {
"description" : "Invallid data",
"schema" : {
"$ref" : "#/definitions/ErrorResponse"
}
};
var schema = schemaWrapper.schema;
if (schema.$ref != null) {
schema = defsParser.$refs.get(schema.$ref);
} else {
schemaWrapper.definitions = Object.assign({}, defs);
$RefParser.dereference(schemaWrapper).catch(function(err) {
console.log(err);
});
}
//console.log(JSON.stringify(schema));
var view = new JSONSchemaView(schema, 3);
$('#responses-instanceLoggingPut-400-schema-data').val(stringify(schema));
var result = $('#responses-instanceLoggingPut-400-schema-400');
result.empty();
result.append(view.render());
});
</script>
</div>
<input id='responses-instanceLoggingPut-400-schema-data' type='hidden' value=''></input>
</div>
</div>
<h3> Status: 500 - Error </h3>
@ -7322,7 +7356,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-11-23T00:55:26.644+01:00
Generated 2017-11-24T00:44:01.796+01:00
</div>
</div>
</div>

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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;