-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTcpServer.h
48 lines (42 loc) · 1.93 KB
/
MyTcpServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <QReadWriteLock>
#include <QObject>
#include <QTcpServer>
#include "sqlbusiness.h"
#include "mytcpsocket.h"
class MyTcpServer : public QTcpServer
{
Q_OBJECT
public:
explicit MyTcpServer(QObject* parent = nullptr);
void incomingConnection(qintptr handle);
~MyTcpServer();
enum USERTYPE {
WHAT = -1,
ROOT = 0,
TEACHER = 1,
STUDENT = 2
};
USERTYPE getUSERTYPE() const { return m_userType; }
signals:
void clientDisconnected(qintptr handle);
protected:
QHash<QString, bool> userOnlineHash; //在线
QHash<qintptr, QThread*> socketThreadHash; //套接字对应线程
QHash<QThread*, QString> userThreadHash; //线程用户
QHash<QThread*, sqlbusiness*> threadSqlHash; //每个线程对应sql实例
protected slots:
void onlineHandle(qintptr handle);
void loginHandle(QString usertype, QString username, QString password, qintptr handle);
void infRegHandle(QString tabletype, QString registertype, QString information, qintptr handle, QString messageType);
void questionInsertHandle(QString messagetype, QString registertype, QString information, qintptr handle, QString messageType);
void qqInsertHandle(QString messagetype, QString registertype, QString information, qintptr handle, QString messageType);
void studentAnswerHandle(QString messagetype, QString registertype, QString information, qintptr handle, QString messageType);
void questionDelectHandle(QString messagetype, QString registertype, QString information, qintptr handle, QString messageType);
void questionUpdateHandle(QString tableName, QString fieldNames, QString fieldValues, qintptr handle, QString messageType);
void delectHandle(QString messagetype, QString registertype, QString information, qintptr handle, QString messageType);
void mulTableInsertHandle(QString value1, QString value2, QString value3, qintptr handle, QString messageType);
private:
USERTYPE m_userType;
QReadWriteLock dbLock;
};