Diffstat (limited to 'noncore/settings/networksettings2/opietooth2/OTGateway.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/opietooth2/OTGateway.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp index 2d13ce9..6531cf6 100644 --- a/noncore/settings/networksettings2/opietooth2/OTGateway.cpp +++ b/noncore/settings/networksettings2/opietooth2/OTGateway.cpp | |||
@@ -75,199 +75,199 @@ OTGateway::OTGateway( void ) : QObject( 0, "OTGateway" ), | |||
75 | readLinkKeys(); | 75 | readLinkKeys(); |
76 | } | 76 | } |
77 | 77 | ||
78 | // close bluetooth system | 78 | // close bluetooth system |
79 | OTGateway::~OTGateway( void ) { | 79 | OTGateway::~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 | ||
96 | void OTGateway::setRefreshTimer( int T ) { | 96 | void 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 | ||
106 | OTDevice * OTGateway::getOTDevice( ) { | 106 | OTDevice * 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 |
126 | void OTGateway::SLOT_SetEnabled( bool Mode ) { | 126 | void 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 | ||
134 | void OTGateway::SLOT_Enable() { | 134 | void OTGateway::SLOT_Enable() { |
135 | getOTDevice()->attach(); | 135 | getOTDevice()->attach(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void OTGateway::SLOT_Disable() { | 138 | void OTGateway::SLOT_Disable() { |
139 | getOTDevice()->detach(); | 139 | getOTDevice()->detach(); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool OTGateway::needsEnabling() { | 142 | bool OTGateway::needsEnabling() { |
143 | return getOTDevice()->needsAttach(); | 143 | return getOTDevice()->needsAttach(); |
144 | } | 144 | } |
145 | 145 | ||
146 | bool OTGateway::isEnabled() { | 146 | bool OTGateway::isEnabled() { |
147 | if( getOTDevice()->deviceNr() >= 0 && | 147 | if( getOTDevice()->deviceNr() >= 0 && |
148 | driver( getOTDevice()->deviceNr() )->isUp() ) | 148 | driver( getOTDevice()->deviceNr() )->isUp() ) |
149 | return TRUE; | 149 | return TRUE; |
150 | 150 | ||
151 | // else check system | 151 | // else check system |
152 | return getOTDevice()->isAttached(); | 152 | return getOTDevice()->isAttached(); |
153 | } | 153 | } |
154 | 154 | ||
155 | void OTGateway::SLOT_ShowError( const QString & S ) { | 155 | void OTGateway::SLOT_ShowError( const QString & S ) { |
156 | 156 | ||
157 | owarn << S << oendl; | 157 | owarn << S << oendl; |
158 | 158 | ||
159 | if( ErrorConnectCount > 0 ) { | 159 | if( ErrorConnectCount > 0 ) { |
160 | // pass error | 160 | // pass error |
161 | emit error( QString( "<p>" ) + S + "</p>" ); | 161 | emit error( QString( "<p>" ) + S + "</p>" ); |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | 164 | ||
165 | QMessageBox::warning( 0, | 165 | QMessageBox::warning( 0, |
166 | tr("OTGateway error"), | 166 | tr("OTGateway error"), |
167 | S ); | 167 | S ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void OTGateway::connectNotify( const char * S ) { | 170 | void OTGateway::connectNotify( const char * S ) { |
171 | if( strcmp( S, "error(const QString&)" ) == 0 ) { | 171 | if( S && strcmp( S, "error(const QString&)" ) == 0 ) { |
172 | ErrorConnectCount ++; | 172 | ErrorConnectCount ++; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | void OTGateway::disconnectNotify( const char * S ) { | 176 | void OTGateway::disconnectNotify( const char * S ) { |
177 | if( strcmp( S, "error(const QString&)" ) == 0 ) { | 177 | if( S && strcmp( S, "error(const QString&)" ) == 0 ) { |
178 | ErrorConnectCount --; | 178 | ErrorConnectCount --; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | void OTGateway::timerEvent( QTimerEvent * ) { | 182 | void OTGateway::timerEvent( QTimerEvent * ) { |
183 | 183 | ||
184 | OTDriver * D; | 184 | OTDriver * D; |
185 | unsigned int oldc = AllDrivers.count(); | 185 | unsigned int oldc = AllDrivers.count(); |
186 | bool old; | 186 | bool old; |
187 | 187 | ||
188 | AllDrivers.update(); | 188 | AllDrivers.update(); |
189 | 189 | ||
190 | if( oldc != AllDrivers.count() ) { | 190 | if( oldc != AllDrivers.count() ) { |
191 | updateDrivers(); | 191 | updateDrivers(); |
192 | } else { | 192 | } else { |
193 | for( unsigned int i = 0; | 193 | for( unsigned int i = 0; |
194 | i < AllDrivers.count(); | 194 | i < AllDrivers.count(); |
195 | i ++ ) { | 195 | i ++ ) { |
196 | D = AllDrivers[i]; | 196 | D = AllDrivers[i]; |
197 | old = D->isUp(); | 197 | old = D->isUp(); |
198 | if( D->currentState() >= 0 ) { | 198 | if( D->currentState() >= 0 ) { |
199 | if( old != D->isUp() ) { | 199 | if( old != D->isUp() ) { |
200 | emit stateChange( D, D->isUp() ); | 200 | emit stateChange( D, D->isUp() ); |
201 | } | 201 | } |
202 | } else { | 202 | } else { |
203 | // if one driver is unable to provide info | 203 | // if one driver is unable to provide info |
204 | // we refresh all devices | 204 | // we refresh all devices |
205 | updateDrivers(); | 205 | updateDrivers(); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | void OTGateway::SLOT_Enabled( int id, bool Up ) { | 212 | void OTGateway::SLOT_Enabled( int id, bool Up ) { |
213 | owarn << "device " << id << " state " << Up << oendl; | 213 | owarn << "device " << id << " state " << Up << oendl; |
214 | if( Up ) { | 214 | if( Up ) { |
215 | // device is up -> detect it | 215 | // device is up -> detect it |
216 | updateDrivers(); | 216 | updateDrivers(); |
217 | if( (unsigned)id >= AllDrivers.count() ) { | 217 | if( (unsigned)id >= AllDrivers.count() ) { |
218 | // to make sure that the driver really IS detected | 218 | // to make sure that the driver really IS detected |
219 | AllDrivers[id]->bringUp(); | 219 | AllDrivers[id]->bringUp(); |
220 | } | 220 | } |
221 | } // if DOWN device already down | 221 | } // if DOWN device already down |
222 | emit deviceEnabled( Up ); | 222 | emit deviceEnabled( Up ); |
223 | } | 223 | } |
224 | 224 | ||
225 | void OTGateway::updateDrivers( void ) { | 225 | void OTGateway::updateDrivers( void ) { |
226 | OTDriver * D; | 226 | OTDriver * D; |
227 | 227 | ||
228 | AllDrivers.update(); | 228 | AllDrivers.update(); |
229 | 229 | ||
230 | owarn << "updated drivers. now " << AllDrivers.count() << oendl; | 230 | owarn << "updated drivers. now " << AllDrivers.count() << oendl; |
231 | 231 | ||
232 | // connect signals for each driver | 232 | // connect signals for each driver |
233 | for( unsigned int i = 0; | 233 | for( unsigned int i = 0; |
234 | i < AllDrivers.count(); | 234 | i < AllDrivers.count(); |
235 | i ++ ) { | 235 | i ++ ) { |
236 | D = AllDrivers[i]; | 236 | D = AllDrivers[i]; |
237 | 237 | ||
238 | connect( D, | 238 | connect( D, |
239 | SIGNAL( error( const QString & ) ), | 239 | SIGNAL( error( const QString & ) ), |
240 | this, | 240 | this, |
241 | SLOT( SLOT_ShowError( const QString & ) ) | 241 | SLOT( SLOT_ShowError( const QString & ) ) |
242 | ); | 242 | ); |
243 | 243 | ||
244 | connect( D, | 244 | connect( D, |
245 | SIGNAL( stateChange( OTDriver *, bool ) ), | 245 | SIGNAL( stateChange( OTDriver *, bool ) ), |
246 | this, | 246 | this, |
247 | SIGNAL( stateChange( OTDriver *, bool ) ) | 247 | SIGNAL( stateChange( OTDriver *, bool ) ) |
248 | ); | 248 | ); |
249 | 249 | ||
250 | connect( D, | 250 | connect( D, |
251 | SIGNAL( driverDisappeared( OTDriver * ) ), | 251 | SIGNAL( driverDisappeared( OTDriver * ) ), |
252 | this, | 252 | this, |
253 | SLOT( SLOT_DriverDisappeared( OTDriver * ) ) | 253 | SLOT( SLOT_DriverDisappeared( OTDriver * ) ) |
254 | ); | 254 | ); |
255 | } | 255 | } |
256 | 256 | ||
257 | // verify main device too | 257 | // verify main device too |
258 | if( TheOTDevice ) | 258 | if( TheOTDevice ) |
259 | TheOTDevice->checkAttach(); | 259 | TheOTDevice->checkAttach(); |
260 | 260 | ||
261 | // set to default scanning hardware | 261 | // set to default scanning hardware |
262 | setScanWith( 0 ); | 262 | setScanWith( 0 ); |
263 | 263 | ||
264 | emit driverListChanged(); | 264 | emit driverListChanged(); |
265 | } | 265 | } |
266 | 266 | ||
267 | void OTGateway::SLOT_DriverDisappeared( OTDriver * D ) { | 267 | void OTGateway::SLOT_DriverDisappeared( OTDriver * D ) { |
268 | owarn << "Driver " << D->devname() << " when offline" << oendl; | 268 | owarn << "Driver " << D->devname() << " when offline" << oendl; |
269 | updateDrivers(); | 269 | updateDrivers(); |
270 | } | 270 | } |
271 | 271 | ||
272 | void OTGateway::scanNeighbourhood( OTDriver * D ) { | 272 | void OTGateway::scanNeighbourhood( OTDriver * D ) { |
273 | 273 | ||