|
|
|
#ifndef NETWORKPROVIDER
|
|
|
|
#define NETWORKPROVIDER
|
|
|
|
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include "provider/IProvider.h"
|
|
|
|
#include "parser/IParser.h"
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
class NetworkProvider : public QObject, 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;
|
|
|
|
void clientConnected();
|
|
|
|
void clientDisconnected();
|
|
|
|
void clientError(QString error);
|
|
|
|
|
|
|
|
//uncrustify off
|
|
|
|
private slots:
|
|
|
|
//uncrustify on
|
|
|
|
void onErrorOccured(QAbstractSocket::SocketError error);
|
|
|
|
void createNewConnection();
|
|
|
|
|
|
|
|
void onReadyRead();
|
|
|
|
void onClientDisconnected();
|
|
|
|
void onSocketError(QAbstractSocket::SocketError socketError);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _isRunning;
|
|
|
|
quint16 _port;
|
|
|
|
QHostAddress _address;
|
|
|
|
QTcpServer _server;
|
|
|
|
Parser_ptr _parser;
|
|
|
|
|
|
|
|
void initServer();
|
|
|
|
void resumeConnectedSessions();
|
|
|
|
void stopConnectedSessions();
|
|
|
|
|
|
|
|
QTimer _timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //NEWTORKPROVIDER
|