blob: 6909e8dac4d4bb36d64178c8de70ae591c63a04f (
plain)
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
71
72
73
74
75
76
77
78
79
80
|
#ifndef GATOSOCKET_H
#define GATOSOCKET_H
#include <QtCore/QObject>
#include <QtCore/QQueue>
#include <QtCore/QSocketNotifier>
#include "gatoaddress.h"
#include "gatoconnectionparameters.h"
/** This class encapsulates a message-oriented bluetooth L2CAP socket. */
class GatoSocket : public QObject
{
Q_OBJECT
Q_ENUMS(State)
public:
explicit GatoSocket(QObject *parent);
~GatoSocket();
enum State {
StateDisconnected,
StateConnecting,
StateConnected
};
enum Error {
TimeoutError,
UnknownError
};
enum SecurityLevel {
SecurityNone,
SecurityLow,
SecurityMedium,
SecurityHigh
};
State state() const;
bool connectTo(const GatoAddress &addr, unsigned short cid);
void close();
/** Dequeues a pending message from the rx queue.
* Doesn't block: if there are no pending messages, returns null QByteArray. */
QByteArray receive();
/** Adds a message to the tx queue. */
void send(const QByteArray &pkt);
SecurityLevel securityLevel() const;
bool setSecurityLevel(SecurityLevel level);
GatoConnectionParameters connectionParameters() const;
bool setConnectionParameters(const GatoConnectionParameters ¶ms);
signals:
void connected();
void disconnected();
void error(Error error);
void readyRead();
private:
bool transmit(const QByteArray &pkt);
private slots:
void readNotify();
void writeNotify();
private:
State s;
int fd;
SecurityLevel desiredSec;
GatoConnectionParameters desiredParams;
QSocketNotifier *readNotifier;
QQueue<QByteArray> readQueue;
QSocketNotifier *writeNotifier;
QQueue<QByteArray> writeQueue;
};
#endif // GATOSOCKET_H
|