-rw-r--r-- | core/launcher/desktop.cpp | 22 | ||||
-rw-r--r-- | core/launcher/main.cpp | 40 | ||||
-rw-r--r-- | libopie/odevice.cpp | 62 | ||||
-rw-r--r-- | libopie/odevice.h | 2 |
4 files changed, 115 insertions, 11 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index f90da1a..7f24259 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -606,2 +606,9 @@ void Desktop::togglePower() | |||
606 | { | 606 | { |
607 | static bool excllock = false; | ||
608 | |||
609 | if ( excllock ) | ||
610 | return; | ||
611 | |||
612 | excllock = true; | ||
613 | |||
607 | bool wasloggedin = loggedin; | 614 | bool wasloggedin = loggedin; |
@@ -613,7 +620,6 @@ void Desktop::togglePower() | |||
613 | 620 | ||
614 | system("apm --suspend"); | 621 | ODevice::inst ( )-> suspend ( ); |
615 | |||
616 | |||
617 | 622 | ||
618 | QWSServer::screenSaverActivate( FALSE ); | 623 | QWSServer::screenSaverActivate( FALSE ); |
624 | |||
619 | { | 625 | { |
@@ -623,6 +629,6 @@ void Desktop::togglePower() | |||
623 | } | 629 | } |
624 | if ( wasloggedin ) { | 630 | |
631 | if ( wasloggedin ) | ||
625 | login(TRUE); | 632 | login(TRUE); |
626 | } | 633 | |
627 | sleep(1); | ||
628 | execAutoStart(); | 634 | execAutoStart(); |
@@ -630,2 +636,6 @@ void Desktop::togglePower() | |||
630 | //qDebug("called togglePower()!!!!!!"); | 636 | //qDebug("called togglePower()!!!!!!"); |
637 | |||
638 | qApp-> processEvents ( ); | ||
639 | |||
640 | excllock = false; | ||
631 | } | 641 | } |
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp index a19da14..1e741d5 100644 --- a/core/launcher/main.cpp +++ b/core/launcher/main.cpp | |||
@@ -335,2 +335,25 @@ int initApplication( int argc, char ** argv ) | |||
335 | 335 | ||
336 | static const char *pidfile_path = "/var/run/opie.pid"; | ||
337 | |||
338 | void create_pidfile ( ) | ||
339 | { | ||
340 | FILE *f; | ||
341 | |||
342 | if (( f = ::fopen ( pidfile_path, "w" ))) { | ||
343 | ::fprintf ( f, "%d", getpid ( )); | ||
344 | ::fclose ( f ); | ||
345 | } | ||
346 | } | ||
347 | |||
348 | void remove_pidfile ( ) | ||
349 | { | ||
350 | ::unlink ( pidfile_path ); | ||
351 | } | ||
352 | |||
353 | void handle_sigterm ( int sig ) | ||
354 | { | ||
355 | if ( qApp ) | ||
356 | qApp-> quit ( ); | ||
357 | } | ||
358 | |||
336 | int main( int argc, char ** argv ) | 359 | int main( int argc, char ** argv ) |
@@ -338,3 +361,11 @@ int main( int argc, char ** argv ) | |||
338 | #ifndef SINGLE_APP | 361 | #ifndef SINGLE_APP |
339 | signal( SIGCHLD, SIG_IGN ); | 362 | ::signal( SIGCHLD, SIG_IGN ); |
363 | |||
364 | ::signal ( SIGTERM, handle_sigterm ); | ||
365 | |||
366 | ::setsid ( ); | ||
367 | ::setpgid ( 0, 0 ); | ||
368 | |||
369 | ::atexit ( remove_pidfile ); | ||
370 | create_pidfile ( ); | ||
340 | #endif | 371 | #endif |
@@ -345,6 +376,5 @@ int main( int argc, char ** argv ) | |||
345 | // Kill them. Kill them all. | 376 | // Kill them. Kill them all. |
346 | setpgid( getpid(), getppid() ); | 377 | ::kill ( 0, SIGTERM ); |
347 | killpg( getpid(), SIGTERM ); | 378 | ::sleep( 1 ); |
348 | sleep( 1 ); | 379 | ::kill ( 0, SIGKILL ); |
349 | killpg( getpid(), SIGKILL ); | ||
350 | #endif | 380 | #endif |
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index bc8014a..057c344 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -19,2 +19,4 @@ | |||
19 | 19 | ||
20 | #include <stdlib.h> | ||
21 | |||
20 | #include <qfile.h> | 22 | #include <qfile.h> |
@@ -49,2 +51,4 @@ protected: | |||
49 | public: | 51 | public: |
52 | virtual bool suspend ( ); | ||
53 | |||
50 | virtual void alarmSound ( ); | 54 | virtual void alarmSound ( ); |
@@ -54,2 +58,5 @@ public: | |||
54 | virtual bool setLed ( uint which, OLedState st ); | 58 | virtual bool setLed ( uint which, OLedState st ); |
59 | |||
60 | private: | ||
61 | static void tstp_sighandler ( int ); | ||
55 | }; | 62 | }; |
@@ -115,2 +122,12 @@ ODevice::~ODevice ( ) | |||
115 | 122 | ||
123 | bool ODevice::suspend ( ) | ||
124 | { | ||
125 | int rc = ::system ( "apm --suspend" ); | ||
126 | |||
127 | if (( rc == 127 ) || ( rc == -1 )) | ||
128 | return false; | ||
129 | else | ||
130 | return true; | ||
131 | } | ||
132 | |||
116 | QString ODevice::vendorString ( ) | 133 | QString ODevice::vendorString ( ) |
@@ -253,2 +270,4 @@ void ODeviceIPAQ::init ( ) | |||
253 | #include <sys/ioctl.h> | 270 | #include <sys/ioctl.h> |
271 | #include <signal.h> | ||
272 | #include <sys/time.h> | ||
254 | #include <linux/soundcard.h> | 273 | #include <linux/soundcard.h> |
@@ -272,2 +291,45 @@ typedef struct h3600_ts_led { | |||
272 | 291 | ||
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 | |||
299 | void ODeviceIPAQ::tstp_sighandler ( int ) | ||
300 | { | ||
301 | } | ||
302 | |||
303 | |||
304 | bool ODeviceIPAQ::suspend ( ) | ||
305 | { | ||
306 | int fd; | ||
307 | bool res = false; | ||
308 | |||
309 | if (( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) { | ||
310 | struct timeval tvs, tvn; | ||
311 | |||
312 | ::signal ( SIGTSTP, tstp_sighandler ); | ||
313 | ::gettimeofday ( &tvs, 0 ); | ||
314 | |||
315 | res = ( ::ioctl ( fd, APM_IOC_SUSPEND ) == 0 ); | ||
316 | ::close ( fd ); | ||
317 | |||
318 | if ( res ) { | ||
319 | ::kill ( -::getpid ( ), SIGTSTP ); | ||
320 | |||
321 | do { | ||
322 | ::usleep ( 200 * 1000 ); | ||
323 | ::gettimeofday ( &tvn, 0 ); | ||
324 | } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); | ||
325 | |||
326 | ::kill ( -::getpid ( ), SIGCONT ); | ||
327 | } | ||
328 | |||
329 | ::signal ( SIGTSTP, SIG_DFL ); | ||
330 | } | ||
331 | return res; | ||
332 | } | ||
333 | |||
334 | |||
273 | void ODeviceIPAQ::alarmSound ( ) | 335 | void ODeviceIPAQ::alarmSound ( ) |
diff --git a/libopie/odevice.h b/libopie/odevice.h index b54e576..eeae357 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h | |||
@@ -68,2 +68,4 @@ public: | |||
68 | 68 | ||
69 | // system | ||
70 | virtual bool suspend ( ); | ||
69 | 71 | ||