summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTGateway.h
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTGateway.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.h200
1 files changed, 200 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.h b/noncore/settings/networksettings2/opietooth2/OTGateway.h
new file mode 100644
index 0000000..a47cefb
--- a/dev/null
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.h
@@ -0,0 +1,200 @@
1#ifndef OTGATEWAY_H
2#define OTGATEWAY_H
3
4#include <qobject.h>
5#include <qvector.h>
6#include <qmap.h>
7
8#include <OTDriverList.h>
9#include <OTInquiry.h>
10
11class QPixmap;
12
13namespace Opietooth2 {
14
15class OTDriverList;
16class OTDriver;
17class OTDevice;
18class OTPeer;
19class OTInquiry;
20class OTPANConnection;
21class OTLinkKey;
22
23typedef QVector<OTPeer> PeerVector;
24typedef QVector<OTPANConnection> PANConnectionVector;
25typedef QArray<OTLinkKey> LinkKeyArray;
26
27class OTLinkKey {
28
29public :
30
31 OTLinkKey( const OTDeviceAddress & F,
32 const OTDeviceAddress & T ) {
33 From = F;
34 To = T;
35 }
36
37 const OTDeviceAddress & to()
38 { return To; }
39 const OTDeviceAddress & from()
40 { return From; }
41
42 OTDeviceAddress From;
43 OTDeviceAddress To;
44};
45
46class OTPANConnection {
47
48public :
49
50 OTPANConnection( const QString & Dev, const QString & CT ) {
51 Device = Dev;
52 ConnectedTo = CT;
53 }
54
55 QString Device;
56 QString ConnectedTo;
57};
58
59
60class OTGateway : public QObject {
61
62 Q_OBJECT
63
64public :
65
66 // single instance
67 static OTGateway * getOTGateway( void );
68 static void releaseOTGateway( void );
69 // convert device type as class to name for that class
70 static const char * deviceTypeToName( int Cls );
71
72 // open bluetooth system
73 OTGateway( void );
74 // close bluetooth system
75 ~OTGateway( void );
76
77 // get access to system device
78 OTDevice * getOTDevice();
79
80 // return true if this device needs enabling of bluetooth
81 bool needsEnabling();
82 // return true if system is running
83 bool isEnabled();
84 void setRefreshTimer( int MilleSecs );
85 // return socket to HCI raw layer
86 inline int getSocket()
87 { return HciCtl; }
88
89 OTDriverList & getDriverList()
90 { return AllDrivers; }
91 OTDriver * driver( int nr )
92 { return AllDrivers[nr]; }
93 void updateDrivers();
94
95 PANConnectionVector getPANConnections();
96
97 // scan neighbourhood using device
98 void scanNeighbourhood( OTDriver * D = 0 );
99 void stopScanOfNeighbourhood(void );
100 void setScanWith( OTDriver * D = 0 )
101 { ScanWith = (D) ? D :
102 (AllDrivers.count() ) ? AllDrivers[0] : 0; }
103 OTDriver * scanWith( void )
104 { return ScanWith; }
105
106 // get list of all detected peers
107 inline const PeerVector & peers( void )
108 { return AllPeers; }
109 // ping peer to see if it is up
110 bool isPeerUp( const OTDeviceAddress & PAddr,
111 int timeoutInSec = 1,
112 int timeoutInUSec = 0,
113 int retry = 1 );
114 OTPeer * findPeer( const OTDeviceAddress & Addr );
115 void removePeer( OTPeer * P );
116 void addPeer( OTPeer * P );
117
118 OTDriver * findDriver( const OTDeviceAddress & Addr );
119
120 inline const LinkKeyArray & getLinkKeys() const
121 { return AllKeys; }
122 bool removeLinkKey( unsigned int index );
123
124 // return device number if we are connected over any device
125 // to the channel
126 // else returns -1
127 int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel );
128 int getFreeRFCommDevice( void );
129 // return 0 if properly released
130 int releaseRFCommDevice( int DevNr );
131
132public slots :
133
134 // start bluetooth system
135 void SLOT_SetEnabled( bool );
136 void SLOT_Enable();
137 void SLOT_Disable();
138
139 // show error
140 void SLOT_ShowError( const QString & );
141
142 void SLOT_Enabled( int, bool );
143 void SLOT_DriverDisappeared( OTDriver * );
144 void SLOT_PeerDetected( OTPeer *, bool );
145 void SLOT_FinishedDetecting();
146
147signals :
148
149 // any error
150 void error( const QString & );
151
152 // signal state of bluetooth driver
153 void stateChange( OTDriver * D, bool State );
154
155 // sent when list of drivers changees
156 void driverListChanged();
157
158 // sent when bluetooth on device is enabled
159 void deviceEnabled( bool );
160
161 // sent when a (new if bool = TRUE) peer is detected
162 void detectedPeer( OTPeer *, bool );
163
164 // end of detection process
165 void finishedDetecting();
166
167protected :
168
169 void connectNotify( const char * Signal );
170 void disconnectNotify( const char * Signal );
171
172 void timerEvent( QTimerEvent * );
173
174private :
175
176 void loadActiveConnections( void );
177 void loadKnownPeers( void );
178 void saveKnownPeers( void );
179 bool isConnectedTo( int devid,
180 const OTDeviceAddress & Address );
181
182 void readLinkKeys();
183
184 static OTGateway * SingleGateway;
185 static int UseCount;
186
187 OTDriver * ScanWith;
188 OTDriverList AllDrivers;
189 OTDevice * TheOTDevice;
190 int HciCtl;
191 int ErrorConnectCount;
192 int RefreshTimer;
193 OTInquiry * Scanning;
194 bool AllPeersModified;
195 PeerVector AllPeers;
196 LinkKeyArray AllKeys;
197};
198};
199
200#endif