97 lines
1.4 KiB
C++
Executable File
97 lines
1.4 KiB
C++
Executable File
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include "tcpserver_export.h"
|
|
|
|
class WorkerInstance;
|
|
class CommandInterface;
|
|
|
|
|
|
|
|
class TCPSERVER_EXPORT TcpServer : public QTcpServer
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
typedef QVector<CommandInterface*(*)(unsigned short) > CommandInterfaceList;
|
|
public:
|
|
|
|
|
|
virtual ~TcpServer();
|
|
|
|
|
|
static TcpServer *instance(unsigned short port);
|
|
|
|
|
|
|
|
bool listen(const QHostAddress &address = QHostAddress::Any);
|
|
|
|
|
|
|
|
void setUseWorkerThreads(bool bEnable);
|
|
|
|
|
|
|
|
bool useWorkerThreads() const;
|
|
|
|
|
|
|
|
QVector<WorkerInstance *> workers() const;
|
|
|
|
|
|
|
|
unsigned short getListenPort() const;
|
|
|
|
|
|
|
|
static bool registerCommand(unsigned short port, CommandInterface * (*factory)(unsigned short));
|
|
|
|
|
|
|
|
static bool unregisterCommand(unsigned short port, CommandInterface * (*factory)(unsigned short));
|
|
|
|
|
|
|
|
static CommandInterfaceList registeredCommands(unsigned short port);
|
|
|
|
|
|
|
|
void setUserData(void *userData);
|
|
|
|
|
|
|
|
void *userData() const;
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
|
void aboutToQuit(unsigned short port);
|
|
|
|
public Q_SLOTS:
|
|
|
|
|
|
void shutdownRequest();
|
|
|
|
|
|
void workerFinished();
|
|
|
|
protected:
|
|
void incomingConnection(qintptr socketDescriptor);
|
|
|
|
private:
|
|
class Private;
|
|
|
|
|
|
Private *const d;
|
|
|
|
explicit TcpServer(unsigned short port);
|
|
|
|
|
|
|
|
bool listen(const QHostAddress &address, quint16 port);
|
|
};
|