-
Notifications
You must be signed in to change notification settings - Fork 18
/
mbthreadedconnmanager.h
70 lines (49 loc) · 2.27 KB
/
mbthreadedconnmanager.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef MBTHREADEDCONNMANAGER_H
#define MBTHREADEDCONNMANAGER_H
#include <QObject>
#include <QThread>
#include <QMutex>
//#include <QWaitCondition>
class MBConnection;
class MBCommand;
class MBThreadedConnManager : public QObject
{
Q_OBJECT
public:
explicit MBThreadedConnManager(QObject *parent = 0);
~MBThreadedConnManager();
const QThread *managedThread();
public:
void registerConnection(MBConnection *conn);
void unregisterConnection(MBConnection *conn);
void mbConnectAsync(MBConnection *conn, int invokeId);
void closeAsync(MBConnection *conn, bool prioritize, int invokeId);
void readBitsAsync(MBConnection *conn, int slaveId, int addr, QVector<quint8> *result, int invokeId);
void readInputBitsAsync(MBConnection *conn, int slaveId, int addr, QVector<quint8> *result, int invokeId);
void readRegistersAsync(MBConnection *conn, int slaveId, int addr, QVector<quint16> *result, int invokeId);
void readInputRegistersAsync(MBConnection *conn, int slaveId, int addr, QVector<quint16> *result, int invokeId);
void writeBitAsync(MBConnection *conn, int slaveId, int coilAddr, int status, int invokeId);
void writeRegisterAsync(MBConnection *conn, int slaveId, int regAddr, int value, int invokeId);
void writeBitsAsync(MBConnection *conn, int slaveId, int addr, QVector<quint8> *data, int invokeId);
void writeRegistersAsync(MBConnection *conn, int slaveId, int addr, QVector<quint16> *data, int invokeId);
void reportSlaveIdAsync(MBConnection *conn, int slaveId, QVector<quint8> *dest, int invokeId);
void sendRawRequestAsync(MBConnection *conn, int slaveId, QVector<quint8> *req, int invokeId);
void waitForConfirmationAsync(MBConnection *conn, int slaveId, QVector<quint8> *resp, int invokeId);
bool cancelRequest(MBConnection *conn, int invokeId);
signals:
void commandAdded();
private slots:
void _threadFinished();
void _nextCommandAdded();
private:
void _appendCommand(MBCommand *cmd);
void _prependCommand(MBCommand *cmd);
private:
QThread _managedThread;
QMutex _mutex;
//QWaitCondition _hasSomeWorkToDo;
QList<MBCommand*> _commands;//protected by _mutex
MBCommand *_currentCommand;//protected by _mutex
int _managedConnectionsCnt;
};
#endif // MBTHREADEDCONNMANAGER_H