Skip to content
Snippets Groups Projects
Commit 15edbdc0 authored by akiraohgaki's avatar akiraohgaki
Browse files

Set handlers

parent db68a4c1
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,6 @@
#include <QDebug>
#include "handlers/confighandler.h"
//#include "handlers/systemhandler.h"
//#include "handlers/ocshandler.h"
//#include "handlers/itemhandler.h"
#include "websockets/websocketserver.h"
int main(int argc, char *argv[])
......@@ -18,7 +15,7 @@ int main(int argc, char *argv[])
// Init
QCoreApplication app(argc, argv);
ConfigHandler *configHandler = new ConfigHandler(&app);
ConfigHandler *configHandler = new ConfigHandler();
QJsonObject appConfigApplication = configHandler->getAppConfigApplication();
app.setApplicationName(appConfigApplication["name"].toString());
......@@ -48,7 +45,7 @@ int main(int argc, char *argv[])
int port = clParser.value(clOptionPort).toInt();
// Setup websocket server
WebSocketServer *wsServer = new WebSocketServer(appConfigApplication["id"].toString(), port, &app);
WebSocketServer *wsServer = new WebSocketServer(configHandler, appConfigApplication["id"].toString(), port, &app);
QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QCoreApplication::quit);
if (wsServer->start()) {
......
......@@ -6,12 +6,22 @@
#include "qtlib_json.h"
WebSocketServer::WebSocketServer(const QString &serverName, quint16 serverPort, QObject *parent)
: QObject(parent), serverName_(serverName), serverPort_(serverPort)
#include "handlers/confighandler.h"
#include "handlers/systemhandler.h"
#include "handlers/ocshandler.h"
#include "handlers/itemhandler.h"
WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &serverName, quint16 serverPort, QObject *parent)
: QObject(parent), configHandler_(configHandler), serverName_(serverName), serverPort_(serverPort)
{
wsServer_ = new QWebSocketServer(serverName_, QWebSocketServer::NonSecureMode, this);
connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection);
connect(wsServer_, &QWebSocketServer::closed, this, &WebSocketServer::stopped);
configHandler_->setParent(this);
systemHandler_ = new SystemHandler(this);
ocsHandler_ = new OcsHandler(configHandler_, this);
itemHandler_ = new ItemHandler(configHandler_, this);
}
WebSocketServer::~WebSocketServer()
......
......@@ -7,24 +7,30 @@
class QWebSocketServer;
class QWebSocket;
class ConfigHandler;
class SystemHandler;
class OcsHandler;
class ItemHandler;
class WebSocketServer : public QObject
{
Q_OBJECT
public:
explicit WebSocketServer(const QString &serverName, quint16 serverPort = 0, QObject *parent = 0);
explicit WebSocketServer(ConfigHandler *configHandler, const QString &serverName = "WebSocketServer", quint16 serverPort = 0, QObject *parent = 0);
~WebSocketServer();
signals:
void started();
void stopped();
public slots:
bool start();
void stop();
bool isError();
QString errorString();
QUrl serverUrl();
signals:
void started();
void stopped();
private slots:
void wsNewConnection();
void wsDisconnected();
......@@ -38,4 +44,9 @@ private:
quint16 serverPort_;
QWebSocketServer *wsServer_;
QList<QWebSocket *> wsClients_;
ConfigHandler *configHandler_;
SystemHandler *systemHandler_;
OcsHandler *ocsHandler_;
ItemHandler *itemHandler_;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment