blob: a47cefb9e382df52ba7c21ca3899c07ead54fb52 (
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#ifndef OTGATEWAY_H
#define OTGATEWAY_H
#include <qobject.h>
#include <qvector.h>
#include <qmap.h>
#include <OTDriverList.h>
#include <OTInquiry.h>
class QPixmap;
namespace Opietooth2 {
class OTDriverList;
class OTDriver;
class OTDevice;
class OTPeer;
class OTInquiry;
class OTPANConnection;
class OTLinkKey;
typedef QVector<OTPeer> PeerVector;
typedef QVector<OTPANConnection> PANConnectionVector;
typedef QArray<OTLinkKey> LinkKeyArray;
class OTLinkKey {
public :
OTLinkKey( const OTDeviceAddress & F,
const OTDeviceAddress & T ) {
From = F;
To = T;
}
const OTDeviceAddress & to()
{ return To; }
const OTDeviceAddress & from()
{ return From; }
OTDeviceAddress From;
OTDeviceAddress To;
};
class OTPANConnection {
public :
OTPANConnection( const QString & Dev, const QString & CT ) {
Device = Dev;
ConnectedTo = CT;
}
QString Device;
QString ConnectedTo;
};
class OTGateway : public QObject {
Q_OBJECT
public :
// single instance
static OTGateway * getOTGateway( void );
static void releaseOTGateway( void );
// convert device type as class to name for that class
static const char * deviceTypeToName( int Cls );
// open bluetooth system
OTGateway( void );
// close bluetooth system
~OTGateway( void );
// get access to system device
OTDevice * getOTDevice();
// return true if this device needs enabling of bluetooth
bool needsEnabling();
// return true if system is running
bool isEnabled();
void setRefreshTimer( int MilleSecs );
// return socket to HCI raw layer
inline int getSocket()
{ return HciCtl; }
OTDriverList & getDriverList()
{ return AllDrivers; }
OTDriver * driver( int nr )
{ return AllDrivers[nr]; }
void updateDrivers();
PANConnectionVector getPANConnections();
// scan neighbourhood using device
void scanNeighbourhood( OTDriver * D = 0 );
void stopScanOfNeighbourhood(void );
void setScanWith( OTDriver * D = 0 )
{ ScanWith = (D) ? D :
(AllDrivers.count() ) ? AllDrivers[0] : 0; }
OTDriver * scanWith( void )
{ return ScanWith; }
// get list of all detected peers
inline const PeerVector & peers( void )
{ return AllPeers; }
// ping peer to see if it is up
bool isPeerUp( const OTDeviceAddress & PAddr,
int timeoutInSec = 1,
int timeoutInUSec = 0,
int retry = 1 );
OTPeer * findPeer( const OTDeviceAddress & Addr );
void removePeer( OTPeer * P );
void addPeer( OTPeer * P );
OTDriver * findDriver( const OTDeviceAddress & Addr );
inline const LinkKeyArray & getLinkKeys() const
{ return AllKeys; }
bool removeLinkKey( unsigned int index );
// return device number if we are connected over any device
// to the channel
// else returns -1
int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel );
int getFreeRFCommDevice( void );
// return 0 if properly released
int releaseRFCommDevice( int DevNr );
public slots :
// start bluetooth system
void SLOT_SetEnabled( bool );
void SLOT_Enable();
void SLOT_Disable();
// show error
void SLOT_ShowError( const QString & );
void SLOT_Enabled( int, bool );
void SLOT_DriverDisappeared( OTDriver * );
void SLOT_PeerDetected( OTPeer *, bool );
void SLOT_FinishedDetecting();
signals :
// any error
void error( const QString & );
// signal state of bluetooth driver
void stateChange( OTDriver * D, bool State );
// sent when list of drivers changees
void driverListChanged();
// sent when bluetooth on device is enabled
void deviceEnabled( bool );
// sent when a (new if bool = TRUE) peer is detected
void detectedPeer( OTPeer *, bool );
// end of detection process
void finishedDetecting();
protected :
void connectNotify( const char * Signal );
void disconnectNotify( const char * Signal );
void timerEvent( QTimerEvent * );
private :
void loadActiveConnections( void );
void loadKnownPeers( void );
void saveKnownPeers( void );
bool isConnectedTo( int devid,
const OTDeviceAddress & Address );
void readLinkKeys();
static OTGateway * SingleGateway;
static int UseCount;
OTDriver * ScanWith;
OTDriverList AllDrivers;
OTDevice * TheOTDevice;
int HciCtl;
int ErrorConnectCount;
int RefreshTimer;
OTInquiry * Scanning;
bool AllPeersModified;
PeerVector AllPeers;
LinkKeyArray AllKeys;
};
};
#endif
|