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 @@ ...@@ -8,9 +8,6 @@
#include <QDebug> #include <QDebug>
#include "handlers/confighandler.h" #include "handlers/confighandler.h"
//#include "handlers/systemhandler.h"
//#include "handlers/ocshandler.h"
//#include "handlers/itemhandler.h"
#include "websockets/websocketserver.h" #include "websockets/websocketserver.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -18,7 +15,7 @@ int main(int argc, char *argv[]) ...@@ -18,7 +15,7 @@ int main(int argc, char *argv[])
// Init // Init
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
ConfigHandler *configHandler = new ConfigHandler(&app); ConfigHandler *configHandler = new ConfigHandler();
QJsonObject appConfigApplication = configHandler->getAppConfigApplication(); QJsonObject appConfigApplication = configHandler->getAppConfigApplication();
app.setApplicationName(appConfigApplication["name"].toString()); app.setApplicationName(appConfigApplication["name"].toString());
...@@ -48,7 +45,7 @@ int main(int argc, char *argv[]) ...@@ -48,7 +45,7 @@ int main(int argc, char *argv[])
int port = clParser.value(clOptionPort).toInt(); int port = clParser.value(clOptionPort).toInt();
// Setup websocket server // 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); QObject::connect(wsServer, &WebSocketServer::stopped, &app, &QCoreApplication::quit);
if (wsServer->start()) { if (wsServer->start()) {
......
...@@ -6,12 +6,22 @@ ...@@ -6,12 +6,22 @@
#include "qtlib_json.h" #include "qtlib_json.h"
WebSocketServer::WebSocketServer(const QString &serverName, quint16 serverPort, QObject *parent) #include "handlers/confighandler.h"
: QObject(parent), serverName_(serverName), serverPort_(serverPort) #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); wsServer_ = new QWebSocketServer(serverName_, QWebSocketServer::NonSecureMode, this);
connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection); connect(wsServer_, &QWebSocketServer::newConnection, this, &WebSocketServer::wsNewConnection);
connect(wsServer_, &QWebSocketServer::closed, this, &WebSocketServer::stopped); 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() WebSocketServer::~WebSocketServer()
......
...@@ -7,24 +7,30 @@ ...@@ -7,24 +7,30 @@
class QWebSocketServer; class QWebSocketServer;
class QWebSocket; class QWebSocket;
class ConfigHandler;
class SystemHandler;
class OcsHandler;
class ItemHandler;
class WebSocketServer : public QObject class WebSocketServer : public QObject
{ {
Q_OBJECT Q_OBJECT
public: 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(); ~WebSocketServer();
signals:
void started();
void stopped();
public slots:
bool start(); bool start();
void stop(); void stop();
bool isError(); bool isError();
QString errorString(); QString errorString();
QUrl serverUrl(); QUrl serverUrl();
signals:
void started();
void stopped();
private slots: private slots:
void wsNewConnection(); void wsNewConnection();
void wsDisconnected(); void wsDisconnected();
...@@ -38,4 +44,9 @@ private: ...@@ -38,4 +44,9 @@ private:
quint16 serverPort_; quint16 serverPort_;
QWebSocketServer *wsServer_; QWebSocketServer *wsServer_;
QList<QWebSocket *> wsClients_; 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