make libguh-core a proper lib
This commit is contained in:
parent
4beb296439
commit
4b3518661f
23
guh.pro
23
guh.pro
@ -2,26 +2,11 @@ include(guh.pri)
|
||||
|
||||
TEMPLATE=subdirs
|
||||
|
||||
SUBDIRS += libguh server plugins
|
||||
SUBDIRS += libguh libguh-core server plugins
|
||||
|
||||
!disabletesting {
|
||||
message("Building guh tests enabled")
|
||||
SUBDIRS += tests
|
||||
DEFINES += TESTING_ENABLED
|
||||
} else {
|
||||
message("Building guh tests disabled")
|
||||
}
|
||||
|
||||
# Bluetooth LE support
|
||||
contains(DEFINES, BLUETOOTH_LE) {
|
||||
message("Bluetooth LE available (Qt $${QT_VERSION}).")
|
||||
} else {
|
||||
message("Bluetooth LE not available (Qt $${QT_VERSION}).")
|
||||
}
|
||||
|
||||
server.depends = libguh plugins
|
||||
server.depends = libguh libguh-core plugins
|
||||
plugins.depends = libguh
|
||||
tests.depends = libguh
|
||||
tests.depends = libguh libguh-core
|
||||
|
||||
doc.depends = libguh server
|
||||
# Note: some how extraimages in qdocconf did not the trick
|
||||
@ -32,7 +17,7 @@ doc.commands += cd $$top_srcdir/doc; qdoc config.qdocconf; cp -r images/* html/i
|
||||
licensecheck.commands = $$top_srcdir/tests/auto/checklicenseheaders.sh $$top_srcdir
|
||||
|
||||
test.depends = licensecheck
|
||||
test.commands = LD_LIBRARY_PATH=$$top_builddir/libguh:$$top_builddir/tests/libguh-core make check
|
||||
test.commands = LD_LIBRARY_PATH=$$top_builddir/libguh-core:$$top_builddir/libguh make check
|
||||
|
||||
QMAKE_EXTRA_TARGETS += licensecheck doc test
|
||||
|
||||
|
||||
@ -46,7 +46,6 @@ GuhConfiguration::GuhConfiguration(QObject *parent) :
|
||||
|
||||
GuhSettings settings(GuhSettings::SettingsRoleGlobal);
|
||||
|
||||
#ifndef TESTING_ENABLED
|
||||
// TcpServer
|
||||
bool createDefaults = !settings.childGroups().contains("TcpServer");
|
||||
if (settings.childGroups().contains("TcpServer")) {
|
||||
@ -143,34 +142,6 @@ GuhConfiguration::GuhConfiguration(QObject *parent) :
|
||||
m_webSocketServerConfigs[config.id] = config;
|
||||
storeServerConfig("WebSocketServer", config);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
ServerConfiguration tcpConfig;
|
||||
tcpConfig.id = "default";
|
||||
tcpConfig.address = QHostAddress("127.0.0.1");
|
||||
tcpConfig.port = 2222;
|
||||
tcpConfig.sslEnabled = true;
|
||||
tcpConfig.authenticationEnabled = true;
|
||||
m_tcpServerConfigs[tcpConfig.id] = tcpConfig;
|
||||
|
||||
WebServerConfiguration wsConfig;
|
||||
wsConfig.id = "default";
|
||||
wsConfig.address = QHostAddress("127.0.0.1");
|
||||
wsConfig.port = 3333;
|
||||
wsConfig.sslEnabled = true;
|
||||
wsConfig.authenticationEnabled = true;
|
||||
wsConfig.publicFolder = qApp->applicationDirPath();
|
||||
m_webServerConfigs[wsConfig.id] = wsConfig;
|
||||
|
||||
ServerConfiguration wssConfig;
|
||||
wssConfig.id = "default";
|
||||
wssConfig.address = QHostAddress("127.0.0.1");
|
||||
wssConfig.port = 4444;
|
||||
wssConfig.sslEnabled = true;
|
||||
wssConfig.authenticationEnabled = true;
|
||||
m_webSocketServerConfigs[wssConfig.id] = wssConfig;
|
||||
#endif
|
||||
}
|
||||
|
||||
QUuid GuhConfiguration::serverUuid() const
|
||||
122
libguh-core/libguh-core.pro
Normal file
122
libguh-core/libguh-core.pro
Normal file
@ -0,0 +1,122 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = guh-core
|
||||
|
||||
include(../guh.pri)
|
||||
|
||||
QT += sql
|
||||
INCLUDEPATH += $$top_srcdir/libguh jsonrpc
|
||||
LIBS += -L$$top_builddir/libguh/ -lguh -lssl -lcrypto
|
||||
|
||||
target.path = /usr/lib/$$system('dpkg-architecture -q DEB_HOST_MULTIARCH')
|
||||
INSTALLS += target
|
||||
|
||||
# icons for the webserver
|
||||
RESOURCES += $$top_srcdir/icons.qrc
|
||||
|
||||
HEADERS += $$top_srcdir/libguh-core/guhcore.h \
|
||||
$$top_srcdir/libguh-core/tcpserver.h \
|
||||
$$top_srcdir/libguh-core/mocktcpserver.h \
|
||||
$$top_srcdir/libguh-core/ruleengine.h \
|
||||
$$top_srcdir/libguh-core/rule.h \
|
||||
$$top_srcdir/libguh-core/stateevaluator.h \
|
||||
$$top_srcdir/libguh-core/webserver.h \
|
||||
$$top_srcdir/libguh-core/transportinterface.h \
|
||||
$$top_srcdir/libguh-core/servermanager.h \
|
||||
$$top_srcdir/libguh-core/httprequest.h \
|
||||
$$top_srcdir/libguh-core/websocketserver.h \
|
||||
$$top_srcdir/libguh-core/httpreply.h \
|
||||
$$top_srcdir/libguh-core/guhconfiguration.h \
|
||||
$$top_srcdir/libguh-core/bluetoothserver.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsonrpcserver.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsonhandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/devicehandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsontypes.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/ruleshandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/actionhandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/eventhandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/statehandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/logginghandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/configurationhandler.h \
|
||||
$$top_srcdir/libguh-core/jsonrpc/networkmanagerhandler.h \
|
||||
$$top_srcdir/libguh-core/logging/logging.h \
|
||||
$$top_srcdir/libguh-core/logging/logengine.h \
|
||||
$$top_srcdir/libguh-core/logging/logfilter.h \
|
||||
$$top_srcdir/libguh-core/logging/logentry.h \
|
||||
$$top_srcdir/libguh-core/rest/restserver.h \
|
||||
$$top_srcdir/libguh-core/rest/restresource.h \
|
||||
$$top_srcdir/libguh-core/rest/devicesresource.h \
|
||||
$$top_srcdir/libguh-core/rest/deviceclassesresource.h \
|
||||
$$top_srcdir/libguh-core/rest/vendorsresource.h \
|
||||
$$top_srcdir/libguh-core/rest/logsresource.h \
|
||||
$$top_srcdir/libguh-core/rest/pluginsresource.h \
|
||||
$$top_srcdir/libguh-core/rest/rulesresource.h \
|
||||
$$top_srcdir/libguh-core/time/timedescriptor.h \
|
||||
$$top_srcdir/libguh-core/time/calendaritem.h \
|
||||
$$top_srcdir/libguh-core/time/repeatingoption.h \
|
||||
$$top_srcdir/libguh-core/time/timeeventitem.h \
|
||||
$$top_srcdir/libguh-core/time/timemanager.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/dbus-interfaces.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkmanager.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkdevice.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirelessaccesspoint.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirelessnetworkdevice.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/networksettings.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkconnection.h \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirednetworkdevice.h \
|
||||
$$top_srcdir/libguh-core/usermanager.h \
|
||||
$$top_srcdir/libguh-core/tokeninfo.h \
|
||||
$$PWD/certificategenerator.h
|
||||
|
||||
|
||||
SOURCES += $$top_srcdir/libguh-core/guhcore.cpp \
|
||||
$$top_srcdir/libguh-core/tcpserver.cpp \
|
||||
$$top_srcdir/libguh-core/mocktcpserver.cpp \
|
||||
$$top_srcdir/libguh-core/ruleengine.cpp \
|
||||
$$top_srcdir/libguh-core/rule.cpp \
|
||||
$$top_srcdir/libguh-core/stateevaluator.cpp \
|
||||
$$top_srcdir/libguh-core/webserver.cpp \
|
||||
$$top_srcdir/libguh-core/transportinterface.cpp \
|
||||
$$top_srcdir/libguh-core/servermanager.cpp \
|
||||
$$top_srcdir/libguh-core/httprequest.cpp \
|
||||
$$top_srcdir/libguh-core/websocketserver.cpp \
|
||||
$$top_srcdir/libguh-core/httpreply.cpp \
|
||||
$$top_srcdir/libguh-core/guhconfiguration.cpp \
|
||||
$$top_srcdir/libguh-core/bluetoothserver.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsonrpcserver.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsonhandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/devicehandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/jsontypes.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/ruleshandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/actionhandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/eventhandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/statehandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/logginghandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/configurationhandler.cpp \
|
||||
$$top_srcdir/libguh-core/jsonrpc/networkmanagerhandler.cpp \
|
||||
$$top_srcdir/libguh-core/logging/logengine.cpp \
|
||||
$$top_srcdir/libguh-core/logging/logfilter.cpp \
|
||||
$$top_srcdir/libguh-core/logging/logentry.cpp \
|
||||
$$top_srcdir/libguh-core/rest/restserver.cpp \
|
||||
$$top_srcdir/libguh-core/rest/restresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/devicesresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/deviceclassesresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/vendorsresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/logsresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/pluginsresource.cpp \
|
||||
$$top_srcdir/libguh-core/rest/rulesresource.cpp \
|
||||
$$top_srcdir/libguh-core/time/timedescriptor.cpp \
|
||||
$$top_srcdir/libguh-core/time/calendaritem.cpp \
|
||||
$$top_srcdir/libguh-core/time/repeatingoption.cpp \
|
||||
$$top_srcdir/libguh-core/time/timeeventitem.cpp \
|
||||
$$top_srcdir/libguh-core/time/timemanager.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkmanager.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkdevice.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirelessaccesspoint.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirelessnetworkdevice.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/networksettings.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/networkconnection.cpp \
|
||||
$$top_srcdir/libguh-core/networkmanager/wirednetworkdevice.cpp \
|
||||
$$top_srcdir/libguh-core/usermanager.cpp \
|
||||
$$top_srcdir/libguh-core/tokeninfo.cpp \
|
||||
$$PWD/certificategenerator.cpp
|
||||
|
||||
@ -92,18 +92,15 @@ ServerManager::ServerManager(GuhConfiguration* configuration, QObject *parent) :
|
||||
|
||||
|
||||
// Transports
|
||||
#ifdef TESTING_ENABLED
|
||||
MockTcpServer *tcpServer = new MockTcpServer(this);
|
||||
m_jsonServer->registerTransportInterface(tcpServer, true);
|
||||
tcpServer->startServer();
|
||||
#else
|
||||
foreach (const ServerConfiguration &config, configuration->tcpServerConfigurations()) {
|
||||
TcpServer *tcpServer = new TcpServer(config, m_sslConfiguration, this);
|
||||
m_jsonServer->registerTransportInterface(tcpServer, config.authenticationEnabled);
|
||||
m_tcpServers.insert(config.id, tcpServer);
|
||||
tcpServer->startServer();
|
||||
}
|
||||
#endif
|
||||
|
||||
foreach (const ServerConfiguration &config, configuration->webSocketServerConfigurations()) {
|
||||
WebSocketServer *webSocketServer = new WebSocketServer(config, m_sslConfiguration, this);
|
||||
@ -149,9 +146,13 @@ BluetoothServer *ServerManager::bluetoothServer() const
|
||||
return m_bluetoothServer;
|
||||
}
|
||||
|
||||
MockTcpServer *ServerManager::mockTcpServer() const
|
||||
{
|
||||
return m_mockTcpServer;
|
||||
}
|
||||
|
||||
void ServerManager::tcpServerConfigurationChanged(const QString &id)
|
||||
{
|
||||
#ifndef TESTING_ENABLED
|
||||
ServerConfiguration config = GuhCore::instance()->configuration()->tcpServerConfigurations().value(id);
|
||||
TcpServer *server = m_tcpServers.value(id);
|
||||
if (server) {
|
||||
@ -165,14 +166,10 @@ void ServerManager::tcpServerConfigurationChanged(const QString &id)
|
||||
}
|
||||
m_jsonServer->registerTransportInterface(server, config.authenticationEnabled);
|
||||
server->startServer();
|
||||
#else
|
||||
qWarning() << "Configure called for" << id << "but disabled in testing";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ServerManager::tcpServerConfigurationRemoved(const QString &id)
|
||||
{
|
||||
#ifndef TESTING_ENABLED
|
||||
if (!m_tcpServers.contains(id)) {
|
||||
qWarning(dcConnection) << "Received a TCP Server config removed event but don't have a TCP Server instance for it.";
|
||||
return;
|
||||
@ -181,9 +178,6 @@ void ServerManager::tcpServerConfigurationRemoved(const QString &id)
|
||||
m_jsonServer->unregisterTransportInterface(server);
|
||||
server->stopServer();
|
||||
server->deleteLater();
|
||||
#else
|
||||
qWarning() << "Delete configuration called for" << id << "but disabled in testing";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ServerManager::webSocketServerConfigurationChanged(const QString &id)
|
||||
@ -28,12 +28,8 @@
|
||||
#include "rest/restserver.h"
|
||||
#include "websocketserver.h"
|
||||
#include "bluetoothserver.h"
|
||||
|
||||
#ifndef TESTING_ENABLED
|
||||
#include "tcpserver.h"
|
||||
#else
|
||||
#include "mocktcpserver.h"
|
||||
#endif
|
||||
|
||||
class QSslConfiguration;
|
||||
class QSslCertificate;
|
||||
@ -56,11 +52,8 @@ public:
|
||||
WebSocketServer* webSocketServer() const;
|
||||
BluetoothServer* bluetoothServer() const;
|
||||
|
||||
#ifdef TESTING_ENABLED
|
||||
MockTcpServer *tcpServer() const;
|
||||
#else
|
||||
TcpServer *tcpServer() const;
|
||||
#endif
|
||||
MockTcpServer *mockTcpServer() const;
|
||||
|
||||
private slots:
|
||||
void tcpServerConfigurationChanged(const QString &id);
|
||||
@ -76,11 +69,10 @@ private:
|
||||
RestServer *m_restServer;
|
||||
|
||||
BluetoothServer *m_bluetoothServer;
|
||||
#ifndef TESTING_ENABLED
|
||||
QHash<QString, TcpServer*> m_tcpServers;
|
||||
#endif
|
||||
QHash<QString, WebSocketServer*> m_webSocketServers;
|
||||
QHash<QString, WebServer*> m_webServers;
|
||||
MockTcpServer *m_mockTcpServer;
|
||||
|
||||
// Encrytption and stuff
|
||||
QSslConfiguration m_sslConfiguration;
|
||||
@ -50,10 +50,8 @@ TcpServer::TcpServer(const ServerConfiguration &configuration, const QSslConfigu
|
||||
m_server(NULL),
|
||||
m_sslConfig(sslConfiguration)
|
||||
{
|
||||
#ifndef TESTING_ENABLED
|
||||
m_avahiService = new QtAvahiService(this);
|
||||
connect(m_avahiService, &QtAvahiService::serviceStateChanged, this, &TcpServer::onAvahiServiceStateChanged);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*! Destructor of this \l{TcpServer}. */
|
||||
@ -152,7 +150,6 @@ bool TcpServer::startServer()
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef TESTING_ENABLED
|
||||
// Note: reversed order
|
||||
QHash<QString, QString> txt;
|
||||
txt.insert("jsonrpcVersion", JSON_PROTOCOL_VERSION);
|
||||
@ -161,7 +158,6 @@ bool TcpServer::startServer()
|
||||
txt.insert("uuid", GuhCore::instance()->configuration()->serverUuid().toString());
|
||||
txt.insert("name", GuhCore::instance()->configuration()->serverName());
|
||||
m_avahiService->registerService("guhIO", configuration().port, "_jsonrpc._tcp", txt);
|
||||
#endif
|
||||
|
||||
qCDebug(dcConnection) << "Started Tcp server on" << m_server->serverAddress().toString() << m_server->serverPort();
|
||||
connect(m_server, SIGNAL(clientConnected(QSslSocket *)), SLOT(onClientConnected(QSslSocket *)));
|
||||
@ -176,10 +172,8 @@ bool TcpServer::startServer()
|
||||
*/
|
||||
bool TcpServer::stopServer()
|
||||
{
|
||||
#ifndef TESTING_ENABLED
|
||||
if (m_avahiService)
|
||||
m_avahiService->resetService();
|
||||
#endif
|
||||
|
||||
if (!m_server)
|
||||
return true;
|
||||
@ -107,20 +107,20 @@ QList<QByteArray> TimeManager::availableTimeZones() const
|
||||
return QTimeZone::availableTimeZoneIds();
|
||||
}
|
||||
|
||||
#ifdef TESTING_ENABLED
|
||||
void TimeManager::stopTimer()
|
||||
{
|
||||
qWarning(dcTimeManager()) << "TimeManager timer stopped. You should only see this in tests.";
|
||||
// Stop clock (used for testing)
|
||||
m_guhTimer->stop();
|
||||
}
|
||||
|
||||
void TimeManager::setTime(const QDateTime &dateTime)
|
||||
{
|
||||
qWarning(dcTimeManager()) << "TimeManager time changed. You should only see this in tests.";
|
||||
// This method will only be called for testing to set the guhIO intern time
|
||||
emit tick();
|
||||
emit dateTimeChanged(dateTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
void TimeManager::guhTimeout()
|
||||
{
|
||||
@ -43,10 +43,8 @@ public:
|
||||
|
||||
QList<QByteArray> availableTimeZones() const;
|
||||
|
||||
#ifdef TESTING_ENABLED
|
||||
void stopTimer();
|
||||
void setTime(const QDateTime &dateTime);
|
||||
#endif
|
||||
|
||||
private:
|
||||
QTimeZone m_timeZone;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user