Ali Hatami Tajik
6 months ago
6 changed files with 189 additions and 1 deletions
@ -0,0 +1,20 @@ |
|||
#ifndef IPROVIDER |
|||
#define IPROVIDER |
|||
|
|||
#include <QObject> |
|||
#include "type/Log.h" |
|||
|
|||
class IDataProvider |
|||
{ |
|||
public: |
|||
virtual ~IDataProvider() |
|||
{ |
|||
} |
|||
|
|||
signals: |
|||
virtual void provided(const Log_ptr log) = 0; |
|||
}; |
|||
|
|||
Q_DECLARE_INTERFACE(IDataProvider, "IDataProvider") //define this out of namespace scope
|
|||
|
|||
#endif //IPROVIDER
|
@ -0,0 +1,40 @@ |
|||
#ifndef NETWORKPROVIDER |
|||
#define NETWORKPROVIDER |
|||
|
|||
#include <QHostAddress> |
|||
#include <QTcpServer> |
|||
#include "provider/IProvider.h" |
|||
#include "parser/IParser.h" |
|||
|
|||
class NetworkProvider : public IDataProvider |
|||
{ |
|||
Q_OBJECT |
|||
Q_INTERFACES(IDataProvider) |
|||
|
|||
public: |
|||
NetworkProvider(QHostAddress hostAddress, quint16 port); |
|||
void setParser(Parser_ptr parser); |
|||
void pauseServer(); |
|||
void resumeServer(); |
|||
void stopServer(); |
|||
|
|||
signals: |
|||
void provided(const Log_ptr log) override; |
|||
|
|||
//uncrustify off
|
|||
private slots: |
|||
//uncrustify on
|
|||
void onErrorOccured(QAbstractSocket::SocketError error); |
|||
void createNewConnection(); |
|||
|
|||
private: |
|||
bool _isRunning; |
|||
quint16 _port; |
|||
QHostAddress _address; |
|||
QTcpServer _server; |
|||
Parser_ptr _parser; |
|||
|
|||
void initServer(); |
|||
}; |
|||
|
|||
#endif //NEWTORKPROVIDER
|
@ -0,0 +1,42 @@ |
|||
#ifndef NETWORKPROVIDER |
|||
#define NETWORKPROVIDER |
|||
|
|||
#include <QHostAddress> |
|||
#include <QTcpServer> |
|||
#include "provider/IProvider.h" |
|||
#include "parser/IParser.h" |
|||
|
|||
class NetworkProvider : public IDataProvider |
|||
{ |
|||
Q_OBJECT |
|||
Q_INTERFACES(IDataProvider) |
|||
|
|||
public: |
|||
NetworkProvider(QHostAddress hostAddress, quint16 port); |
|||
void setParser(Parser_ptr parser); |
|||
void pauseServer(); |
|||
void resumeServer(); |
|||
void stopServer(); |
|||
|
|||
signals: |
|||
void provided(const Log_ptr log) override; |
|||
|
|||
//uncrustify off |
|||
private slots: |
|||
//uncrustify on |
|||
void onErrorOccured(QAbstractSocket::SocketError error); |
|||
void createNewConnection(); |
|||
|
|||
private: |
|||
bool _isRunning; |
|||
quint16 _port; |
|||
QHostAddress _address; |
|||
QTcpServer _server; |
|||
Parser_ptr _parser; |
|||
|
|||
void initServer(); |
|||
void resumeConnectedSessions(); |
|||
void stopConnectedSessions(); |
|||
}; |
|||
|
|||
#endif //NEWTORKPROVIDER |
@ -0,0 +1,80 @@ |
|||
#include "provider/NetworkProvider.h" |
|||
|
|||
#include <QThread> |
|||
|
|||
/*************************************************************************************************/ |
|||
NetworkProvider::NetworkProvider(QHostAddress hostAddress, quint16 port) |
|||
{ |
|||
_address = hostAddress; |
|||
_port = port; |
|||
_isRunning = false; |
|||
initServer(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::setParser(Parser_ptr parser) |
|||
{ |
|||
_parser = parser; |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::pauseServer() |
|||
{ |
|||
stopConnectedSessions(); |
|||
_server.pauseAccepting(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::resumeServer() |
|||
{ |
|||
resumeConnectedSessions(); |
|||
_server.resumeAccepting(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::stopServer() |
|||
{ |
|||
stopConnectedSessions(); |
|||
_server.close(); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::onErrorOccured(QAbstractSocket::SocketError error) |
|||
{ |
|||
//Handle Error
|
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::createNewConnection() |
|||
{ |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::initServer() |
|||
{ |
|||
QThread* thread = new QThread(); |
|||
_server.moveToThread(thread); |
|||
|
|||
QObject::connect(&_server, |
|||
&QTcpServer::newConnection, |
|||
this, |
|||
&NetworkProvider::createNewConnection); |
|||
|
|||
QObject::connect(&_server, |
|||
&QTcpServer::acceptError, |
|||
this, |
|||
&NetworkProvider::onErrorOccured); |
|||
_server.listen(_address, _port); |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::resumeConnectedSessions() |
|||
{ |
|||
_isRunning = true; |
|||
} |
|||
|
|||
/*************************************************************************************************/ |
|||
void NetworkProvider::stopConnectedSessions() |
|||
{ |
|||
_isRunning = false; |
|||
} |
Loading…
Reference in new issue