summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/odevice.cpp119
-rw-r--r--libopie/odevice.h1
2 files changed, 55 insertions, 65 deletions
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index bf64676..6572fb6 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -20,2 +20,10 @@
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h>
22#include <fcntl.h>
23#include <sys/ioctl.h>
24#include <signal.h>
25#include <sys/time.h>
26#include <linux/soundcard.h>
27
28#include <qapplication.h>
21 29
@@ -25,2 +33,4 @@
25#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h>
35
26 36
@@ -51,4 +61,2 @@ protected:
51public: 61public:
52 virtual bool suspend ( );
53
54 virtual void alarmSound ( ); 62 virtual void alarmSound ( );
@@ -57,6 +65,3 @@ public:
57 virtual OLedState led ( uint which ) const; 65 virtual OLedState led ( uint which ) const;
58 virtual bool setLed ( uint which, OLedState st ); 66 virtual bool setLed ( uint which, OLedState st );
59
60private:
61 static void tstp_sighandler ( int );
62}; 67};
@@ -122,12 +127,50 @@ ODevice::~ODevice ( )
122 127
128//#include <linux/apm_bios.h>
129
130//#define APM_IOC_SUSPEND _IO('A',2)
131
132#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 ))
133
134
135void ODevice::tstp_sighandler ( int )
136{
137}
138
139
123bool ODevice::suspend ( ) 140bool ODevice::suspend ( )
124{ 141{
125 int rc = ::system ( "apm --suspend" ); 142 if ( d-> m_model == OMODEL_Unknown ) // better don't suspend in qvfb / on unkown devices
126
127 if (( rc == 127 ) || ( rc == -1 ))
128 return false; 143 return false;
129 else 144
130 return true; 145 int fd;
146 bool res = false;
147
148 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
149 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
150 struct timeval tvs, tvn;
151
152 ::signal ( SIGTSTP, tstp_sighandler );// we don't want to be stopped
153 ::gettimeofday ( &tvs, 0 );
154
155 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); // tell the kernel to "start" suspending
156 ::close ( fd );
157
158 if ( res ) {
159 ::kill ( -::getpid ( ), SIGTSTP ); // stop everthing in out process group
160
161 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
162 ::usleep ( 200 * 1000 );
163 ::gettimeofday ( &tvn, 0 );
164 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
165
166 ::kill ( -::getpid ( ), SIGCONT ); // continue everything in our process group
167 }
168
169 ::signal ( SIGTSTP, SIG_DFL );
170 }
171
172 return res;
131} 173}
132 174
175
133QString ODevice::vendorString ( ) 176QString ODevice::vendorString ( )
@@ -267,11 +310,2 @@ void ODeviceIPAQ::init ( )
267 310
268#include <unistd.h>
269#include <fcntl.h>
270#include <sys/ioctl.h>
271#include <signal.h>
272#include <sys/time.h>
273#include <linux/soundcard.h>
274#include <qapplication.h>
275#include <qpe/config.h>
276
277//#include <linux/h3600_ts.h> // including kernel headers is evil ... 311//#include <linux/h3600_ts.h> // including kernel headers is evil ...
@@ -291,47 +325,2 @@ typedef struct h3600_ts_led {
291 325
292//#include <linux/apm_bios.h>
293
294//#define APM_IOC_SUSPEND _IO('A',2)
295
296#define APM_IOC_SUSPEND (( 0<<30 ) | ( 'A'<<8 ) | ( 2 ) | ( 0<<16 ))
297
298
299void ODeviceIPAQ::tstp_sighandler ( int )
300{
301}
302
303
304bool ODeviceIPAQ::suspend ( )
305{
306 int fd;
307 bool res = false;
308
309 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
310 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
311 struct timeval tvs, tvn;
312
313 ::signal ( SIGTSTP, tstp_sighandler );
314 ::gettimeofday ( &tvs, 0 );
315
316 res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 );
317 ::close ( fd );
318
319 if ( res ) {
320 ::kill ( -::getpid ( ), SIGTSTP );
321
322 do {
323 ::usleep ( 200 * 1000 );
324 ::gettimeofday ( &tvn, 0 );
325 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
326
327 ::kill ( -::getpid ( ), SIGCONT );
328 }
329
330 ::signal ( SIGTSTP, SIG_DFL );
331 }
332
333 return res;
334}
335
336
337void ODeviceIPAQ::alarmSound ( ) 326void ODeviceIPAQ::alarmSound ( )
diff --git a/libopie/odevice.h b/libopie/odevice.h
index eeae357..cda504a 100644
--- a/libopie/odevice.h
+++ b/libopie/odevice.h
@@ -105,2 +105,3 @@ private:
105 105
106 static void tstp_sighandler ( int );
106}; 107};