mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-04-03 18:18:31 -04:00
Web API: /sdrangel/logging implementation (1)
This commit is contained in:
parent
02e0945368
commit
4999b04379
@ -21,4 +21,5 @@
|
||||
QString WebAPIAdapterInterface::instanceSummaryURL = "/sdrangel";
|
||||
QString WebAPIAdapterInterface::instanceDevicesURL = "/sdrangel/devices";
|
||||
QString WebAPIAdapterInterface::instanceChannelsURL = "/sdrangel/channels";
|
||||
QString WebAPIAdapterInterface::instanceLoggingURL = "/sdrangel/logging";
|
||||
|
||||
|
@ -26,6 +26,7 @@ namespace Swagger
|
||||
class SWGInstanceSummaryResponse;
|
||||
class SWGInstanceDevicesResponse;
|
||||
class SWGInstanceChannelsResponse;
|
||||
class SWGLoggingInfo;
|
||||
class SWGErrorResponse;
|
||||
}
|
||||
|
||||
@ -63,9 +64,28 @@ public:
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/logging (GET) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceLoggingGet(
|
||||
Swagger::SWGLoggingInfo& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
/**
|
||||
* Handler of /sdrangel/logging (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels
|
||||
* returns the Http status code (default 501: not implemented)
|
||||
*/
|
||||
virtual int instanceLoggingPut(
|
||||
Swagger::SWGLoggingInfo& response __attribute__((unused)),
|
||||
Swagger::SWGErrorResponse& error __attribute__((unused)))
|
||||
{ return 501; }
|
||||
|
||||
static QString instanceSummaryURL;
|
||||
static QString instanceDevicesURL;
|
||||
static QString instanceChannelsURL;
|
||||
static QString instanceLoggingURL;
|
||||
};
|
||||
|
||||
|
||||
|
@ -125,6 +125,52 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
else if (path == WebAPIAdapterInterface::instanceLoggingURL)
|
||||
{
|
||||
Swagger::SWGLoggingInfo normalResponse;
|
||||
Swagger::SWGErrorResponse errorResponse;
|
||||
|
||||
if (request.getMethod() == "GET")
|
||||
{
|
||||
int status = m_adapter->instanceLoggingGet(normalResponse, errorResponse);
|
||||
|
||||
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);
|
||||
|
||||
if (status == 200) {
|
||||
response.write(normalResponse.asJson().toUtf8());
|
||||
} else {
|
||||
response.write(errorResponse.asJson().toUtf8());
|
||||
}
|
||||
|
||||
response.setStatus(status);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
response.write("Invalid input format");
|
||||
response.setStatus(400,"Invalid input format");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.write("Invalid HTTP method");
|
||||
response.setStatus(405,"Invalid HTTP method");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// QDirIterator it(":", QDirIterator::Subdirectories);
|
||||
|
@ -196,3 +196,97 @@ int WebAPIAdapterGUI::instanceChannels(
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instanceLoggingGet(
|
||||
Swagger::SWGLoggingInfo& response,
|
||||
Swagger::SWGErrorResponse& error)
|
||||
{
|
||||
response.setDumpToFile(m_mainWindow.m_logger->getUseFileLogger());
|
||||
|
||||
if (response.getDumpToFile()) {
|
||||
m_mainWindow.m_logger->getLogFileName(*response.getFileName());
|
||||
m_mainWindow.m_logger->getFileMinMessageLevelStr(*response.getFileLevel());
|
||||
}
|
||||
|
||||
m_mainWindow.m_logger->getConsoleMinMessageLevelStr(*response.getConsoleLevel());
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::instanceLoggingPut(
|
||||
Swagger::SWGLoggingInfo& response,
|
||||
Swagger::SWGErrorResponse& error)
|
||||
{
|
||||
// response input is the query actually
|
||||
bool dumpToFile = response.getDumpToFile();
|
||||
QString* consoleLevel = response.getConsoleLevel();
|
||||
QString* fileLevel = response.getFileLevel();
|
||||
QString* fileName = response.getFileName();
|
||||
|
||||
// perform actions
|
||||
if (consoleLevel) {
|
||||
m_mainWindow.m_settings.setConsoleMinLogLevel(getMsgTypeFromString(*consoleLevel));
|
||||
}
|
||||
|
||||
if (fileLevel) {
|
||||
m_mainWindow.m_settings.setFileMinLogLevel(getMsgTypeFromString(*fileLevel));
|
||||
}
|
||||
|
||||
m_mainWindow.m_settings.setUseLogFile(dumpToFile);
|
||||
|
||||
if (fileName) {
|
||||
m_mainWindow.m_settings.setLogFileName(*fileLevel);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
getMsgTypeString(m_mainWindow.m_settings.getConsoleMinLogLevel(), *response.getConsoleLevel());
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
|
||||
{
|
||||
if (msgTypeString == "debug") {
|
||||
return QtDebugMsg;
|
||||
} else if (msgTypeString == "info") {
|
||||
return QtInfoMsg;
|
||||
} else if (msgTypeString == "warning") {
|
||||
return QtWarningMsg;
|
||||
} else if (msgTypeString == "error") {
|
||||
return QtCriticalMsg;
|
||||
} else {
|
||||
return QtDebugMsg;
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIAdapterGUI::getMsgTypeString(const QtMsgType& msgType, QString& levelStr)
|
||||
{
|
||||
switch (msgType)
|
||||
{
|
||||
case QtDebugMsg:
|
||||
levelStr = "debug";
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
levelStr = "info";
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
levelStr = "warning";
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
case QtFatalMsg:
|
||||
levelStr = "error";
|
||||
break;
|
||||
default:
|
||||
levelStr = "debug";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_
|
||||
#define SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "webapi/webapiadapterinterface.h"
|
||||
|
||||
class MainWindow;
|
||||
@ -43,8 +45,19 @@ public:
|
||||
Swagger::SWGInstanceChannelsResponse& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instanceLoggingGet(
|
||||
Swagger::SWGLoggingInfo& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
virtual int instanceLoggingPut(
|
||||
Swagger::SWGLoggingInfo& response,
|
||||
Swagger::SWGErrorResponse& error);
|
||||
|
||||
private:
|
||||
MainWindow& m_mainWindow;
|
||||
|
||||
static QtMsgType getMsgTypeFromString(const QString& msgTypeString);
|
||||
static void getMsgTypeString(const QtMsgType& msgType, QString& level);
|
||||
};
|
||||
|
||||
#endif /* SDRGUI_WEBAPI_WEBAPIADAPTERGUI_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user