summaryrefslogtreecommitdiff
authorkergoth <kergoth>2003-04-21 17:15:01 (UTC)
committer kergoth <kergoth>2003-04-21 17:15:01 (UTC)
commitb3ec819dfed40b05b2bea1b1392de774bc1f572d (patch) (unidiff)
treec0e30307ba6623f49cda10ce35e7f3323b4062f8
parenteecb4b6d3c22466f273c3498b6370b1e1c67c726 (diff)
downloadopie-b3ec819dfed40b05b2bea1b1392de774bc1f572d.zip
opie-b3ec819dfed40b05b2bea1b1392de774bc1f572d.tar.gz
opie-b3ec819dfed40b05b2bea1b1392de774bc1f572d.tar.bz2
Final fix for the suspend bug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 501b601..62e3569 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -43,34 +43,32 @@
43#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 43#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
44#endif 44#endif
45 45
46// _IO and friends are only defined in kernel headers ... 46// _IO and friends are only defined in kernel headers ...
47 47
48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 48#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
49 49
50#define OD_IO(type,number) OD_IOC(0,type,number,0) 50#define OD_IO(type,number) OD_IOC(0,type,number,0)
51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 51#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 52#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 53#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
54 54
55using namespace Opie; 55using namespace Opie;
56 56
57class ODeviceData { 57class ODeviceData {
58public: 58public:
59 bool m_qwsserver : 1;
60
61 QString m_vendorstr; 59 QString m_vendorstr;
62 OVendor m_vendor; 60 OVendor m_vendor;
63 61
64 QString m_modelstr; 62 QString m_modelstr;
65 OModel m_model; 63 OModel m_model;
66 64
67 QString m_systemstr; 65 QString m_systemstr;
68 OSystem m_system; 66 OSystem m_system;
69 67
70 QString m_sysverstr; 68 QString m_sysverstr;
71 69
72 Transformation m_rotation; 70 Transformation m_rotation;
73 ODirection m_direction; 71 ODirection m_direction;
74 72
75 QValueList <ODeviceButton> *m_buttons; 73 QValueList <ODeviceButton> *m_buttons;
76 uint m_holdtime; 74 uint m_holdtime;
@@ -226,66 +224,66 @@ struct z_button z_buttons_c700 [] = {
226 "QPE/TaskBar", "toggleMenu()", 224 "QPE/TaskBar", "toggleMenu()",
227 "QPE/TaskBar", "toggleStartMenu()" }, 225 "QPE/TaskBar", "toggleStartMenu()" },
228 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Display Rotate"), 226 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
229 "", 227 "",
230 "QPE/Rotation", "flip()", 228 "QPE/Rotation", "flip()",
231 "QPE/Rotation", "flip()" }, 229 "QPE/Rotation", "flip()" },
232}; 230};
233 231
234static QCString makeChannel ( const char *str ) 232static QCString makeChannel ( const char *str )
235{ 233{
236 if ( str && !::strchr ( str, '/' )) 234 if ( str && !::strchr ( str, '/' ))
237 return QCString ( "QPE/Application/" ) + str; 235 return QCString ( "QPE/Application/" ) + str;
238 else 236 else
239 return str; 237 return str;
240} 238}
241 239
242 240static inline bool isQWS()
243 241{
242 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
243}
244 244
245ODevice *ODevice::inst ( ) 245ODevice *ODevice::inst ( )
246{ 246{
247 static ODevice *dev = 0; 247 static ODevice *dev = 0;
248 248
249 if ( !dev ) { 249 if ( !dev ) {
250 if ( QFile::exists ( "/proc/hal/model" )) 250 if ( QFile::exists ( "/proc/hal/model" ))
251 dev = new iPAQ ( ); 251 dev = new iPAQ ( );
252 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 252 else if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
253 dev = new Zaurus ( ); 253 dev = new Zaurus ( );
254 else 254 else
255 dev = new ODevice ( ); 255 dev = new ODevice ( );
256 256
257 dev-> init ( ); 257 dev-> init ( );
258 } 258 }
259 return dev; 259 return dev;
260} 260}
261 261
262 262
263/************************************************** 263/**************************************************
264 * 264 *
265 * common 265 * common
266 * 266 *
267 **************************************************/ 267 **************************************************/
268 268
269 269
270ODevice::ODevice ( ) 270ODevice::ODevice ( )
271{ 271{
272 d = new ODeviceData; 272 d = new ODeviceData;
273 273
274 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
275
276 d-> m_modelstr = "Unknown"; 274 d-> m_modelstr = "Unknown";
277 d-> m_model = Model_Unknown; 275 d-> m_model = Model_Unknown;
278 d-> m_vendorstr = "Unknown"; 276 d-> m_vendorstr = "Unknown";
279 d-> m_vendor = Vendor_Unknown; 277 d-> m_vendor = Vendor_Unknown;
280 d-> m_systemstr = "Unknown"; 278 d-> m_systemstr = "Unknown";
281 d-> m_system = System_Unknown; 279 d-> m_system = System_Unknown;
282 d-> m_sysverstr = "0.0"; 280 d-> m_sysverstr = "0.0";
283 d-> m_rotation = Rot0; 281 d-> m_rotation = Rot0;
284 d-> m_direction = CW; 282 d-> m_direction = CW;
285 283
286 d-> m_holdtime = 1000; // 1000ms 284 d-> m_holdtime = 1000; // 1000ms
287 d-> m_buttons = 0; 285 d-> m_buttons = 0;
288} 286}
289 287
290void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 288void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
291{ 289{
@@ -293,34 +291,32 @@ void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
293 reloadButtonMapping ( ); 291 reloadButtonMapping ( );
294 } 292 }
295} 293}
296 294
297void ODevice::init ( ) 295void ODevice::init ( )
298{ 296{
299} 297}
300 298
301/** 299/**
302 * This method initialises the button mapping 300 * This method initialises the button mapping
303 */ 301 */
304void ODevice::initButtons ( ) 302void ODevice::initButtons ( )
305{ 303{
306 if ( d-> m_buttons ) 304 if ( d-> m_buttons )
307 return; 305 return;
308 306
309 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
310
311 // Simulation uses iPAQ 3660 device buttons 307 // Simulation uses iPAQ 3660 device buttons
312 308
313 qDebug ( "init Buttons" ); 309 qDebug ( "init Buttons" );
314 d-> m_buttons = new QValueList <ODeviceButton>; 310 d-> m_buttons = new QValueList <ODeviceButton>;
315 311
316 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 312 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
317 i_button *ib = ipaq_buttons + i; 313 i_button *ib = ipaq_buttons + i;
318 ODeviceButton b; 314 ODeviceButton b;
319 315
320 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 316 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
321 b. setKeycode ( ib-> code ); 317 b. setKeycode ( ib-> code );
322 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 318 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
323 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 319 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
324 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 320 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
325 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 321 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
326 d-> m_buttons-> append ( b ); 322 d-> m_buttons-> append ( b );
@@ -346,33 +342,33 @@ bool ODevice::setSoftSuspend ( bool /*soft*/ )
346 342
347#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 343#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
348 344
349/** 345/**
350 * This method will try to suspend the device 346 * This method will try to suspend the device
351 * It only works if the user is the QWS Server and the apm application 347 * It only works if the user is the QWS Server and the apm application
352 * is installed. 348 * is installed.
353 * It tries to suspend and then waits some time cause some distributions 349 * It tries to suspend and then waits some time cause some distributions
354 * do have asynchronus apm implementations. 350 * do have asynchronus apm implementations.
355 * This method will either fail and return false or it'll suspend the 351 * This method will either fail and return false or it'll suspend the
356 * device and return once the device got woken up 352 * device and return once the device got woken up
357 * 353 *
358 * @return if the device got suspended 354 * @return if the device got suspended
359 */ 355 */
360bool ODevice::suspend ( ) 356bool ODevice::suspend ( )
361{ 357{
362 if ( !d-> m_qwsserver ) // only qwsserver is allowed to suspend 358 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
363 return false; 359 return false;
364 360
365 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 361 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
366 return false; 362 return false;
367 363
368 bool res = false; 364 bool res = false;
369 365
370 struct timeval tvs, tvn; 366 struct timeval tvs, tvn;
371 ::gettimeofday ( &tvs, 0 ); 367 ::gettimeofday ( &tvs, 0 );
372 368
373 ::sync ( ); // flush fs caches 369 ::sync ( ); // flush fs caches
374 res = ( ::system ( "apm --suspend" ) == 0 ); 370 res = ( ::system ( "apm --suspend" ) == 0 );
375 371
376 // This is needed because the iPAQ apm implementation is asynchronous and we 372 // This is needed because the iPAQ apm implementation is asynchronous and we
377 // can not be sure when exactly the device is really suspended 373 // can not be sure when exactly the device is really suspended
378 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 374 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
@@ -794,35 +790,33 @@ void iPAQ::init ( )
794 790
795 791
796 792
797 793
798 794
799 m_leds [0] = m_leds [1] = Led_Off; 795 m_leds [0] = m_leds [1] = Led_Off;
800 796
801 m_power_timer = 0; 797 m_power_timer = 0;
802 798
803} 799}
804 800
805void iPAQ::initButtons ( ) 801void iPAQ::initButtons ( )
806{ 802{
807 if ( d-> m_buttons ) 803 if ( d-> m_buttons )
808 return; 804 return;
809 805
810 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 806 if ( isQWS( ) )
811
812 if ( d-> m_qwsserver )
813 QWSServer::setKeyboardFilter ( this ); 807 QWSServer::setKeyboardFilter ( this );
814 808
815 d-> m_buttons = new QValueList <ODeviceButton>; 809 d-> m_buttons = new QValueList <ODeviceButton>;
816 810
817 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 811 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
818 i_button *ib = ipaq_buttons + i; 812 i_button *ib = ipaq_buttons + i;
819 ODeviceButton b; 813 ODeviceButton b;
820 814
821 if (( ib-> model & d-> m_model ) == d-> m_model ) { 815 if (( ib-> model & d-> m_model ) == d-> m_model ) {
822 b. setKeycode ( ib-> code ); 816 b. setKeycode ( ib-> code );
823 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 817 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
824 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 818 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
825 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 819 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
826 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 820 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
827 821
828 d-> m_buttons-> append ( b ); 822 d-> m_buttons-> append ( b );
@@ -1194,34 +1188,32 @@ void Zaurus::init ( )
1194 break; 1188 break;
1195 case Model_Zaurus_SLB600: 1189 case Model_Zaurus_SLB600:
1196 case Model_Zaurus_SL5500: 1190 case Model_Zaurus_SL5500:
1197 case Model_Zaurus_SL5000: 1191 case Model_Zaurus_SL5000:
1198 default: 1192 default:
1199 d-> m_rotation = Rot270; 1193 d-> m_rotation = Rot270;
1200 break; 1194 break;
1201 } 1195 }
1202 m_leds [0] = Led_Off; 1196 m_leds [0] = Led_Off;
1203} 1197}
1204 1198
1205void Zaurus::initButtons ( ) 1199void Zaurus::initButtons ( )
1206{ 1200{
1207 if ( d-> m_buttons ) 1201 if ( d-> m_buttons )
1208 return; 1202 return;
1209 1203
1210 d-> m_qwsserver = qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
1211
1212 d-> m_buttons = new QValueList <ODeviceButton>; 1204 d-> m_buttons = new QValueList <ODeviceButton>;
1213 1205
1214 struct z_button * pz_buttons; 1206 struct z_button * pz_buttons;
1215 int buttoncount; 1207 int buttoncount;
1216 switch ( d-> m_model ) { 1208 switch ( d-> m_model ) {
1217 case Model_Zaurus_SLC700: 1209 case Model_Zaurus_SLC700:
1218 pz_buttons = z_buttons_c700; 1210 pz_buttons = z_buttons_c700;
1219 buttoncount = ARRAY_SIZE(z_buttons_c700); 1211 buttoncount = ARRAY_SIZE(z_buttons_c700);
1220 break; 1212 break;
1221 default: 1213 default:
1222 pz_buttons = z_buttons; 1214 pz_buttons = z_buttons;
1223 buttoncount = ARRAY_SIZE(z_buttons); 1215 buttoncount = ARRAY_SIZE(z_buttons);
1224 break; 1216 break;
1225 } 1217 }
1226 1218
1227 for ( int i = 0; i < buttoncount; i++ ) { 1219 for ( int i = 0; i < buttoncount; i++ ) {