summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.cpp1
-rw-r--r--noncore/settings/networksettings2/opietooth2/OTGateway.h2
2 files changed, 2 insertions, 1 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
index e8137dd..1b61a2e 100644
--- a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp
@@ -52,192 +52,193 @@ OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ),
52 AllPeers.setAutoDelete( TRUE ); 52 AllPeers.setAutoDelete( TRUE );
53 53
54 if ( ( HciCtl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) { 54 if ( ( HciCtl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
55 SLOT_ShowError( tr( "error opening hci socket" ) ); 55 SLOT_ShowError( tr( "error opening hci socket" ) );
56 return; 56 return;
57 } 57 }
58 58
59 // load all known devices 59 // load all known devices
60 updateDrivers(); 60 updateDrivers();
61 61
62 // load all peers we have ever seen 62 // load all peers we have ever seen
63 loadKnownPeers(); 63 loadKnownPeers();
64 64
65 // iterate over drivers and find active connections 65 // iterate over drivers and find active connections
66 // adding/updating peers 66 // adding/updating peers
67 loadActiveConnections(); 67 loadActiveConnections();
68 68
69 // check every 4 seconds the state of BT 69 // check every 4 seconds the state of BT
70 timerEvent(0); 70 timerEvent(0);
71 RefreshTimer = -1; 71 RefreshTimer = -1;
72 setRefreshTimer( 4000 ); 72 setRefreshTimer( 4000 );
73 73
74 // load known link keys 74 // load known link keys
75 readLinkKeys(); 75 readLinkKeys();
76} 76}
77 77
78// close bluetooth system 78// close bluetooth system
79OTGateway::~OTGateway( void ) { 79OTGateway::~OTGateway( void ) {
80 80
81 if( AllPeersModified ) { 81 if( AllPeersModified ) {
82 saveKnownPeers(); 82 saveKnownPeers();
83 } 83 }
84 84
85 if( Scanning ) 85 if( Scanning )
86 delete Scanning; 86 delete Scanning;
87 87
88 if( TheOTDevice ) 88 if( TheOTDevice )
89 delete TheOTDevice; 89 delete TheOTDevice;
90 90
91 if( HciCtl >= 0 ) { 91 if( HciCtl >= 0 ) {
92 ::close( HciCtl ); 92 ::close( HciCtl );
93 } 93 }
94} 94}
95 95
96void OTGateway::setRefreshTimer( int T ) { 96void OTGateway::setRefreshTimer( int T ) {
97 if( RefreshTimer != -1 ) { 97 if( RefreshTimer != -1 ) {
98 killTimer( RefreshTimer ); 98 killTimer( RefreshTimer );
99 } 99 }
100 100
101 if( T == 0 ) 101 if( T == 0 )
102 T = 4000; 102 T = 4000;
103 RefreshTimer = startTimer( T ); 103 RefreshTimer = startTimer( T );
104} 104}
105 105
106OTDevice * OTGateway::getOTDevice( ) { 106OTDevice * OTGateway::getOTDevice( ) {
107 if( TheOTDevice == 0 ) { 107 if( TheOTDevice == 0 ) {
108 // load bluetooth device and check state 108 // load bluetooth device and check state
109 TheOTDevice = new OTDevice( this ); 109 TheOTDevice = new OTDevice( this );
110 connect( TheOTDevice, 110 connect( TheOTDevice,
111 SIGNAL( isEnabled( int, bool ) ), 111 SIGNAL( isEnabled( int, bool ) ),
112 this, 112 this,
113 SLOT( SLOT_Enabled( int, bool ) ) ); 113 SLOT( SLOT_Enabled( int, bool ) ) );
114 114
115 connect( TheOTDevice, 115 connect( TheOTDevice,
116 SIGNAL( error( const QString & ) ), 116 SIGNAL( error( const QString & ) ),
117 this, 117 this,
118 SLOT( SLOT_ShowError( const QString & ) ) ); 118 SLOT( SLOT_ShowError( const QString & ) ) );
119 } 119 }
120 120
121 return TheOTDevice; 121 return TheOTDevice;
122} 122}
123 123
124// start bluetooth (if stopped) 124// start bluetooth (if stopped)
125// return TRUE if started 125// return TRUE if started
126void OTGateway::SLOT_SetEnabled( bool Mode ) { 126void OTGateway::SLOT_SetEnabled( bool Mode ) {
127 if( Mode ) { 127 if( Mode ) {
128 SLOT_Enable(); 128 SLOT_Enable();
129 return; 129 return;
130 } 130 }
131 SLOT_Disable(); 131 SLOT_Disable();
132} 132}
133 133
134void OTGateway::SLOT_Enable() { 134void OTGateway::SLOT_Enable() {
135 getOTDevice()->attach(); 135 getOTDevice()->attach();
136} 136}
137 137
138void OTGateway::SLOT_Disable() { 138void OTGateway::SLOT_Disable() {
139 getOTDevice()->detach(); 139 getOTDevice()->detach();
140} 140}
141 141
142bool OTGateway::needsEnabling() { 142bool OTGateway::needsEnabling() {
143 return getOTDevice()->needsAttach(); 143 return getOTDevice()->needsAttach();
144} 144}
145 145
146bool OTGateway::isEnabled() { 146bool OTGateway::isEnabled() {
147 if( getOTDevice()->deviceNr() >= 0 && 147 if( getOTDevice()->deviceNr() >= 0 &&
148 AllDrivers.count() != 0 &&
148 driver( getOTDevice()->deviceNr() )->isUp() ) 149 driver( getOTDevice()->deviceNr() )->isUp() )
149 return TRUE; 150 return TRUE;
150 151
151 // else check system 152 // else check system
152 return getOTDevice()->isAttached(); 153 return getOTDevice()->isAttached();
153} 154}
154 155
155void OTGateway::SLOT_ShowError( const QString & S ) { 156void OTGateway::SLOT_ShowError( const QString & S ) {
156 157
157 odebug << S << oendl; 158 odebug << S << oendl;
158 159
159 if( ErrorConnectCount > 0 ) { 160 if( ErrorConnectCount > 0 ) {
160 // pass error 161 // pass error
161 emit error( QString( "<p>" ) + S + "</p>" ); 162 emit error( QString( "<p>" ) + S + "</p>" );
162 return; 163 return;
163 } 164 }
164 165
165 QMessageBox::warning( 0, 166 QMessageBox::warning( 0,
166 tr("OTGateway error"), 167 tr("OTGateway error"),
167 S ); 168 S );
168} 169}
169 170
170void OTGateway::connectNotify( const char * S ) { 171void OTGateway::connectNotify( const char * S ) {
171 if( S && strcmp( S, "error(const QString&)" ) == 0 ) { 172 if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
172 ErrorConnectCount ++; 173 ErrorConnectCount ++;
173 } 174 }
174} 175}
175 176
176void OTGateway::disconnectNotify( const char * S ) { 177void OTGateway::disconnectNotify( const char * S ) {
177 if( S && strcmp( S, "error(const QString&)" ) == 0 ) { 178 if( S && strcmp( S, "error(const QString&)" ) == 0 ) {
178 ErrorConnectCount --; 179 ErrorConnectCount --;
179 } 180 }
180} 181}
181 182
182void OTGateway::timerEvent( QTimerEvent * ) { 183void OTGateway::timerEvent( QTimerEvent * ) {
183 184
184 OTDriver * D; 185 OTDriver * D;
185 unsigned int oldc = AllDrivers.count(); 186 unsigned int oldc = AllDrivers.count();
186 bool old; 187 bool old;
187 188
188 AllDrivers.update(); 189 AllDrivers.update();
189 190
190 if( oldc != AllDrivers.count() ) { 191 if( oldc != AllDrivers.count() ) {
191 updateDrivers(); 192 updateDrivers();
192 } else { 193 } else {
193 for( unsigned int i = 0; 194 for( unsigned int i = 0;
194 i < AllDrivers.count(); 195 i < AllDrivers.count();
195 i ++ ) { 196 i ++ ) {
196 D = AllDrivers[i]; 197 D = AllDrivers[i];
197 old = D->isUp(); 198 old = D->isUp();
198 if( D->currentState() >= 0 ) { 199 if( D->currentState() >= 0 ) {
199 if( old != D->isUp() ) { 200 if( old != D->isUp() ) {
200 emit stateChange( D, D->isUp() ); 201 emit stateChange( D, D->isUp() );
201 } 202 }
202 } else { 203 } else {
203 // if one driver is unable to provide info 204 // if one driver is unable to provide info
204 // we refresh all devices 205 // we refresh all devices
205 updateDrivers(); 206 updateDrivers();
206 return; 207 return;
207 } 208 }
208 } 209 }
209 } 210 }
210} 211}
211 212
212void OTGateway::SLOT_Enabled( int id, bool Up ) { 213void OTGateway::SLOT_Enabled( int id, bool Up ) {
213 odebug << "device " << id << " state " << Up << oendl; 214 odebug << "device " << id << " state " << Up << oendl;
214 if( Up ) { 215 if( Up ) {
215 // device is up -> detect it 216 // device is up -> detect it
216 updateDrivers(); 217 updateDrivers();
217 if( (unsigned)id >= AllDrivers.count() ) { 218 if( (unsigned)id >= AllDrivers.count() ) {
218 // to make sure that the driver really IS detected 219 // to make sure that the driver really IS detected
219 AllDrivers[id]->bringUp(); 220 AllDrivers[id]->bringUp();
220 } 221 }
221 } // if DOWN device already down 222 } // if DOWN device already down
222 emit deviceEnabled( Up ); 223 emit deviceEnabled( Up );
223} 224}
224 225
225void OTGateway::updateDrivers( void ) { 226void OTGateway::updateDrivers( void ) {
226 OTDriver * D; 227 OTDriver * D;
227 228
228 AllDrivers.update(); 229 AllDrivers.update();
229 230
230 odebug << "updated drivers. now " << AllDrivers.count() << oendl; 231 odebug << "updated drivers. now " << AllDrivers.count() << oendl;
231 232
232 // connect signals for each driver 233 // connect signals for each driver
233 for( unsigned int i = 0; 234 for( unsigned int i = 0;
234 i < AllDrivers.count(); 235 i < AllDrivers.count();
235 i ++ ) { 236 i ++ ) {
236 D = AllDrivers[i]; 237 D = AllDrivers[i];
237 238
238 connect( D, 239 connect( D,
239 SIGNAL( error( const QString & ) ), 240 SIGNAL( error( const QString & ) ),
240 this, 241 this,
241 SLOT( SLOT_ShowError( const QString & ) ) 242 SLOT( SLOT_ShowError( const QString & ) )
242 ); 243 );
243 244
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.h b/noncore/settings/networksettings2/opietooth2/OTGateway.h
index d97ef35..11c6b30 100644
--- a/noncore/settings/networksettings2/opietooth2/OTGateway.h
+++ b/noncore/settings/networksettings2/opietooth2/OTGateway.h
@@ -1,188 +1,188 @@
1#ifndef OTGATEWAY_H 1#ifndef OTGATEWAY_H
2#define OTGATEWAY_H 2#define OTGATEWAY_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvector.h> 5#include <qvector.h>
6#include <qmap.h> 6#include <qmap.h>
7 7
8#include <OTDriverList.h> 8#include <OTDriverList.h>
9#include <OTInquiry.h> 9#include <OTInquiry.h>
10 10
11class QPixmap; 11class QPixmap;
12 12
13namespace Opietooth2 { 13namespace Opietooth2 {
14 14
15class OTDriverList; 15class OTDriverList;
16class OTDriver; 16class OTDriver;
17class OTDevice; 17class OTDevice;
18class OTPeer; 18class OTPeer;
19class OTInquiry; 19class OTInquiry;
20class OTPANConnection; 20class OTPANConnection;
21class OTLinkKey; 21class OTLinkKey;
22 22
23typedef QVector<OTPeer> PeerVector; 23typedef QVector<OTPeer> PeerVector;
24typedef QVector<OTPANConnection> PANConnectionVector; 24typedef QVector<OTPANConnection> PANConnectionVector;
25typedef QArray<OTLinkKey> LinkKeyArray; 25typedef QArray<OTLinkKey> LinkKeyArray;
26 26
27class OTLinkKey { 27class OTLinkKey {
28 28
29public : 29public :
30 30
31 OTLinkKey( const OTDeviceAddress & F, 31 OTLinkKey( const OTDeviceAddress & F,
32 const OTDeviceAddress & T ) { 32 const OTDeviceAddress & T ) {
33 From = F; 33 From = F;
34 To = T; 34 To = T;
35 } 35 }
36 36
37 const OTDeviceAddress & to() 37 const OTDeviceAddress & to()
38 { return To; } 38 { return To; }
39 const OTDeviceAddress & from() 39 const OTDeviceAddress & from()
40 { return From; } 40 { return From; }
41 41
42 OTDeviceAddress From; 42 OTDeviceAddress From;
43 OTDeviceAddress To; 43 OTDeviceAddress To;
44}; 44};
45 45
46class OTPANConnection { 46class OTPANConnection {
47 47
48public : 48public :
49 49
50 OTPANConnection( const QString & Dev, const QString & CT ) { 50 OTPANConnection( const QString & Dev, const QString & CT ) {
51 Device = Dev; 51 Device = Dev;
52 ConnectedTo = CT; 52 ConnectedTo = CT;
53 } 53 }
54 54
55 QString Device; 55 QString Device;
56 QString ConnectedTo; 56 QString ConnectedTo;
57}; 57};
58 58
59 59
60class OTGateway : public QObject { 60class OTGateway : public QObject {
61 61
62 Q_OBJECT 62 Q_OBJECT
63 63
64public : 64public :
65 65
66 // single instance 66 // single instance
67 static OTGateway * getOTGateway( void ); 67 static OTGateway * getOTGateway( void );
68 static void releaseOTGateway( void ); 68 static void releaseOTGateway( void );
69 // convert device type as class to name for that class 69 // convert device type as class to name for that class
70 static const char * deviceTypeToName( int Cls ); 70 static const char * deviceTypeToName( int Cls );
71 71
72 // open bluetooth system 72 // open bluetooth system
73 OTGateway( void ); 73 OTGateway( void );
74 // close bluetooth system 74 // close bluetooth system
75 ~OTGateway( void ); 75 ~OTGateway( void );
76 76
77 // get access to system device 77 // get access to system device
78 OTDevice * getOTDevice(); 78 OTDevice * getOTDevice();
79 79
80 // return true if this device needs enabling of bluetooth 80 // return true if this device needs enabling of bluetooth
81 bool needsEnabling(); 81 bool needsEnabling();
82 // return true if system is running 82 // return true if system is running
83 bool isEnabled(); 83 bool isEnabled();
84 void setRefreshTimer( int MilleSecs ); 84 void setRefreshTimer( int MilleSecs );
85 // return socket to HCI raw layer 85 // return socket to HCI raw layer
86 inline int getSocket() 86 inline int getSocket()
87 { return HciCtl; } 87 { return HciCtl; }
88 88
89 OTDriverList & getDriverList() 89 OTDriverList & getDriverList()
90 { return AllDrivers; } 90 { return AllDrivers; }
91 OTDriver * driver( int nr ) 91 OTDriver * driver( int nr )
92 { return AllDrivers[nr]; } 92 { return AllDrivers.count() == 0 ? 0 : AllDrivers[nr]; }
93 void updateDrivers(); 93 void updateDrivers();
94 94
95 PANConnectionVector getPANConnections(); 95 PANConnectionVector getPANConnections();
96 96
97 // scan neighbourhood using device 97 // scan neighbourhood using device
98 void scanNeighbourhood( OTDriver * D = 0 ); 98 void scanNeighbourhood( OTDriver * D = 0 );
99 void stopScanOfNeighbourhood(void ); 99 void stopScanOfNeighbourhood(void );
100 void setScanWith( OTDriver * D = 0 ) 100 void setScanWith( OTDriver * D = 0 )
101 { ScanWith = (D) ? D : 101 { ScanWith = (D) ? D :
102 (AllDrivers.count() ) ? AllDrivers[0] : 0; } 102 (AllDrivers.count() ) ? AllDrivers[0] : 0; }
103 OTDriver * scanWith( void ) 103 OTDriver * scanWith( void )
104 { return ScanWith; } 104 { return ScanWith; }
105 105
106 // get list of all detected peers 106 // get list of all detected peers
107 inline const PeerVector & peers( void ) 107 inline const PeerVector & peers( void )
108 { return AllPeers; } 108 { return AllPeers; }
109 // ping peer to see if it is up 109 // ping peer to see if it is up
110 bool isPeerUp( const OTDeviceAddress & PAddr, 110 bool isPeerUp( const OTDeviceAddress & PAddr,
111 int timeoutInSec = 1, 111 int timeoutInSec = 1,
112 int timeoutInUSec = 0, 112 int timeoutInUSec = 0,
113 int retry = 1 ); 113 int retry = 1 );
114 OTPeer * findPeer( const OTDeviceAddress & Addr ); 114 OTPeer * findPeer( const OTDeviceAddress & Addr );
115 void removePeer( OTPeer * P ); 115 void removePeer( OTPeer * P );
116 void addPeer( OTPeer * P ); 116 void addPeer( OTPeer * P );
117 117
118 OTDriver * findDriver( const OTDeviceAddress & Addr ); 118 OTDriver * findDriver( const OTDeviceAddress & Addr );
119 119
120 inline const LinkKeyArray & getLinkKeys() const 120 inline const LinkKeyArray & getLinkKeys() const
121 { return AllKeys; } 121 { return AllKeys; }
122 bool removeLinkKey( unsigned int index ); 122 bool removeLinkKey( unsigned int index );
123 123
124 // return device number if we are connected over any device 124 // return device number if we are connected over any device
125 // to the channel 125 // to the channel
126 // else returns -1 126 // else returns -1
127 int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel ); 127 int connectedToRFCommChannel( const OTDeviceAddress & Addr, int channel );
128 int getFreeRFCommDevice( void ); 128 int getFreeRFCommDevice( void );
129 // return 0 if properly released 129 // return 0 if properly released
130 int releaseRFCommDevice( int DevNr ); 130 int releaseRFCommDevice( int DevNr );
131 131
132public slots : 132public slots :
133 133
134 // start bluetooth system 134 // start bluetooth system
135 void SLOT_SetEnabled( bool ); 135 void SLOT_SetEnabled( bool );
136 void SLOT_Enable(); 136 void SLOT_Enable();
137 void SLOT_Disable(); 137 void SLOT_Disable();
138 138
139 // show error 139 // show error
140 void SLOT_ShowError( const QString & ); 140 void SLOT_ShowError( const QString & );
141 141
142 void SLOT_Enabled( int, bool ); 142 void SLOT_Enabled( int, bool );
143 void SLOT_DriverDisappeared( OTDriver * ); 143 void SLOT_DriverDisappeared( OTDriver * );
144 void SLOT_PeerDetected( OTPeer *, bool ); 144 void SLOT_PeerDetected( OTPeer *, bool );
145 void SLOT_FinishedDetecting(); 145 void SLOT_FinishedDetecting();
146 146
147signals : 147signals :
148 148
149 // any error 149 // any error
150 void error( const QString & ); 150 void error( const QString & );
151 151
152 // signal state of bluetooth driver 152 // signal state of bluetooth driver
153 void stateChange( OTDriver * D, bool State ); 153 void stateChange( OTDriver * D, bool State );
154 154
155 // sent when list of drivers changees 155 // sent when list of drivers changees
156 void driverListChanged(); 156 void driverListChanged();
157 157
158 // sent when bluetooth on device is enabled 158 // sent when bluetooth on device is enabled
159 void deviceEnabled( bool ); 159 void deviceEnabled( bool );
160 160
161 // sent when a (new if bool = TRUE) peer is detected 161 // sent when a (new if bool = TRUE) peer is detected
162 void detectedPeer( OTPeer *, bool ); 162 void detectedPeer( OTPeer *, bool );
163 163
164 // end of detection process 164 // end of detection process
165 void finishedDetecting(); 165 void finishedDetecting();
166 166
167protected : 167protected :
168 168
169 void connectNotify( const char * Signal ); 169 void connectNotify( const char * Signal );
170 void disconnectNotify( const char * Signal ); 170 void disconnectNotify( const char * Signal );
171 171
172 void timerEvent( QTimerEvent * ); 172 void timerEvent( QTimerEvent * );
173 173
174private : 174private :
175 175
176 void loadActiveConnections( void ); 176 void loadActiveConnections( void );
177 void loadKnownPeers( void ); 177 void loadKnownPeers( void );
178 void saveKnownPeers( void ); 178 void saveKnownPeers( void );
179 bool isConnectedTo( int devid, 179 bool isConnectedTo( int devid,
180 const OTDeviceAddress & Address ); 180 const OTDeviceAddress & Address );
181 181
182 void readLinkKeys(); 182 void readLinkKeys();
183 183
184 static OTGateway * SingleGateway; 184 static OTGateway * SingleGateway;
185 static int UseCount; 185 static int UseCount;
186 186
187 OTDriver * ScanWith; 187 OTDriver * ScanWith;
188 OTDriverList AllDrivers; 188 OTDriverList AllDrivers;