author | sandman <sandman> | 2002-08-04 02:25:54 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-08-04 02:25:54 (UTC) |
commit | 8fd0780faa16abbcf7db9220af1bc333ae484ec8 (patch) (unidiff) | |
tree | ffacd596daa0ab07890f185510275667649d55db | |
parent | 549df674d7af9fe1347751e6a63d6ed8249d2503 (diff) | |
download | opie-8fd0780faa16abbcf7db9220af1bc333ae484ec8.zip opie-8fd0780faa16abbcf7db9220af1bc333ae484ec8.tar.gz opie-8fd0780faa16abbcf7db9220af1bc333ae484ec8.tar.bz2 |
1) Fixes for suspend/resume (improved it for iPAQ, shouldn't have changed
anything for Z) -- It seems that this also fixes the 70% CPU load
problem (needs more testing/feedback though)
2) the launcher now creates a /var/run/opie.pid file containing its pid
3) the launcher catches SIGTERM and kills all its child processes
-rw-r--r-- | core/launcher/desktop.cpp | 58 | ||||
-rw-r--r-- | core/launcher/main.cpp | 42 | ||||
-rw-r--r-- | libopie/odevice.cpp | 62 | ||||
-rw-r--r-- | libopie/odevice.h | 4 |
4 files changed, 135 insertions, 31 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 | |||
@@ -591,56 +591,66 @@ static void blankScreen() | |||
591 | QGfx* g = qt_screen->screenGfx(); | 591 | QGfx* g = qt_screen->screenGfx(); |
592 | g->fillRect(0,0,qt_screen->width(),qt_screen->height()); | 592 | g->fillRect(0,0,qt_screen->width(),qt_screen->height()); |
593 | delete g; | 593 | delete g; |
594 | */ | 594 | */ |
595 | blanked = TRUE; | 595 | blanked = TRUE; |
596 | } | 596 | } |
597 | 597 | ||
598 | static void darkScreen() | 598 | static void darkScreen() |
599 | { | 599 | { |
600 | extern void qpe_setBacklight(int); | 600 | extern void qpe_setBacklight(int); |
601 | qpe_setBacklight(0); // force off | 601 | qpe_setBacklight(0); // force off |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
605 | void Desktop::togglePower() | 605 | void Desktop::togglePower() |
606 | { | 606 | { |
607 | bool wasloggedin = loggedin; | 607 | static bool excllock = false; |
608 | loggedin=0; | 608 | |
609 | suspendTime = QDateTime::currentDateTime(); | 609 | if ( excllock ) |
610 | darkScreen(); | 610 | return; |
611 | if ( wasloggedin ) | 611 | |
612 | blankScreen(); | 612 | excllock = true; |
613 | 613 | ||
614 | system("apm --suspend"); | 614 | bool wasloggedin = loggedin; |
615 | 615 | loggedin=0; | |
616 | 616 | suspendTime = QDateTime::currentDateTime(); | |
617 | 617 | darkScreen(); | |
618 | QWSServer::screenSaverActivate( FALSE ); | 618 | if ( wasloggedin ) |
619 | { | 619 | blankScreen(); |
620 | QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep | 620 | |
621 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 621 | ODevice::inst ( )-> suspend ( ); |
622 | e << -3; // Force on | 622 | |
623 | } | 623 | QWSServer::screenSaverActivate( FALSE ); |
624 | if ( wasloggedin ) { | 624 | |
625 | login(TRUE); | 625 | { |
626 | } | 626 | QCopEnvelope("QPE/Card", "mtabChanged()" ); // might have changed while asleep |
627 | sleep(1); | 627 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
628 | execAutoStart(); | 628 | e << -3; // Force on |
629 | //qcopBridge->closeOpenConnections(); | 629 | } |
630 | //qDebug("called togglePower()!!!!!!"); | 630 | |
631 | if ( wasloggedin ) | ||
632 | login(TRUE); | ||
633 | |||
634 | execAutoStart(); | ||
635 | //qcopBridge->closeOpenConnections(); | ||
636 | //qDebug("called togglePower()!!!!!!"); | ||
637 | |||
638 | qApp-> processEvents ( ); | ||
639 | |||
640 | excllock = false; | ||
631 | } | 641 | } |
632 | 642 | ||
633 | void Desktop::toggleLight() | 643 | void Desktop::toggleLight() |
634 | { | 644 | { |
635 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 645 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
636 | e << -2; // toggle | 646 | e << -2; // toggle |
637 | } | 647 | } |
638 | 648 | ||
639 | void Desktop::toggleSymbolInput() | 649 | void Desktop::toggleSymbolInput() |
640 | { | 650 | { |
641 | tb->toggleSymbolInput(); | 651 | tb->toggleSymbolInput(); |
642 | } | 652 | } |
643 | 653 | ||
644 | void Desktop::toggleNumLockState() | 654 | void Desktop::toggleNumLockState() |
645 | { | 655 | { |
646 | tb->toggleNumLockState(); | 656 | tb->toggleNumLockState(); |
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 | |||
@@ -320,35 +320,65 @@ int initApplication( int argc, char ** argv ) | |||
320 | // Make sure calibration widget starts on top. | 320 | // Make sure calibration widget starts on top. |
321 | Calibrate *cal = new Calibrate; | 321 | Calibrate *cal = new Calibrate; |
322 | cal->exec(); | 322 | cal->exec(); |
323 | delete cal; | 323 | delete cal; |
324 | } | 324 | } |
325 | #endif | 325 | #endif |
326 | 326 | ||
327 | d->show(); | 327 | d->show(); |
328 | 328 | ||
329 | int rv = a.exec(); | 329 | int rv = a.exec(); |
330 | 330 | ||
331 | delete d; | 331 | delete d; |
332 | 332 | ||
333 | return rv; | 333 | return rv; |
334 | } | 334 | } |
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 ) |
337 | { | 360 | { |
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 |
341 | 372 | ||
342 | int retVal = initApplication( argc, argv ); | 373 | int retVal = initApplication ( argc, argv ); |
343 | 374 | ||
344 | #ifndef SINGLE_APP | 375 | #ifndef SINGLE_APP |
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 |
351 | 381 | ||
352 | return retVal; | 382 | return retVal; |
353 | } | 383 | } |
354 | 384 | ||
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp index bc8014a..057c344 100644 --- a/libopie/odevice.cpp +++ b/libopie/odevice.cpp | |||
@@ -4,67 +4,74 @@ | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <stdlib.h> | ||
21 | |||
20 | #include <qfile.h> | 22 | #include <qfile.h> |
21 | #include <qtextstream.h> | 23 | #include <qtextstream.h> |
22 | #include <qpe/sound.h> | 24 | #include <qpe/sound.h> |
23 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
24 | 26 | ||
25 | 27 | ||
26 | #include "odevice.h" | 28 | #include "odevice.h" |
27 | 29 | ||
28 | 30 | ||
29 | class ODeviceData { | 31 | class ODeviceData { |
30 | public: | 32 | public: |
31 | QString m_vendorstr; | 33 | QString m_vendorstr; |
32 | OVendor m_vendor; | 34 | OVendor m_vendor; |
33 | 35 | ||
34 | QString m_modelstr; | 36 | QString m_modelstr; |
35 | OModel m_model; | 37 | OModel m_model; |
36 | 38 | ||
37 | QString m_systemstr; | 39 | QString m_systemstr; |
38 | OSystem m_system; | 40 | OSystem m_system; |
39 | 41 | ||
40 | QString m_sysverstr; | 42 | QString m_sysverstr; |
41 | 43 | ||
42 | OLedState m_leds [4]; // just for convenience ... | 44 | OLedState m_leds [4]; // just for convenience ... |
43 | }; | 45 | }; |
44 | 46 | ||
45 | class ODeviceIPAQ : public ODevice { | 47 | class ODeviceIPAQ : public ODevice { |
46 | protected: | 48 | protected: |
47 | virtual void init ( ); | 49 | virtual void init ( ); |
48 | 50 | ||
49 | public: | 51 | public: |
52 | virtual bool suspend ( ); | ||
53 | |||
50 | virtual void alarmSound ( ); | 54 | virtual void alarmSound ( ); |
51 | 55 | ||
52 | virtual uint hasLeds ( ) const; | 56 | virtual uint hasLeds ( ) const; |
53 | virtual OLedState led ( uint which ) const; | 57 | virtual OLedState led ( uint which ) const; |
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 | }; |
56 | 63 | ||
57 | class ODeviceZaurus : public ODevice { | 64 | class ODeviceZaurus : public ODevice { |
58 | protected: | 65 | protected: |
59 | virtual void init ( ); | 66 | virtual void init ( ); |
60 | 67 | ||
61 | public: | 68 | public: |
62 | virtual void alarmSound ( ); | 69 | virtual void alarmSound ( ); |
63 | virtual void keySound ( ); | 70 | virtual void keySound ( ); |
64 | virtual void touchSound ( ); | 71 | virtual void touchSound ( ); |
65 | 72 | ||
66 | virtual uint hasLeds ( ) const; | 73 | virtual uint hasLeds ( ) const; |
67 | virtual OLedState led ( uint which ) const; | 74 | virtual OLedState led ( uint which ) const; |
68 | virtual bool setLed ( uint which, OLedState st ); | 75 | virtual bool setLed ( uint which, OLedState st ); |
69 | 76 | ||
70 | protected: | 77 | protected: |
@@ -100,32 +107,42 @@ ODevice::ODevice ( ) | |||
100 | d-> m_vendorstr = "Unkown"; | 107 | d-> m_vendorstr = "Unkown"; |
101 | d-> m_vendor = OVENDOR_Unknown; | 108 | d-> m_vendor = OVENDOR_Unknown; |
102 | d-> m_systemstr = "Unkown"; | 109 | d-> m_systemstr = "Unkown"; |
103 | d-> m_system = OSYSTEM_Unknown; | 110 | d-> m_system = OSYSTEM_Unknown; |
104 | d-> m_sysverstr = "0.0"; | 111 | d-> m_sysverstr = "0.0"; |
105 | } | 112 | } |
106 | 113 | ||
107 | void ODevice::init ( ) | 114 | void ODevice::init ( ) |
108 | { | 115 | { |
109 | } | 116 | } |
110 | 117 | ||
111 | ODevice::~ODevice ( ) | 118 | ODevice::~ODevice ( ) |
112 | { | 119 | { |
113 | delete d; | 120 | delete d; |
114 | } | 121 | } |
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 ( ) |
117 | { | 134 | { |
118 | return d-> m_vendorstr; | 135 | return d-> m_vendorstr; |
119 | } | 136 | } |
120 | 137 | ||
121 | OVendor ODevice::vendor ( ) | 138 | OVendor ODevice::vendor ( ) |
122 | { | 139 | { |
123 | return d-> m_vendor; | 140 | return d-> m_vendor; |
124 | } | 141 | } |
125 | 142 | ||
126 | QString ODevice::modelString ( ) | 143 | QString ODevice::modelString ( ) |
127 | { | 144 | { |
128 | return d-> m_modelstr; | 145 | return d-> m_modelstr; |
129 | } | 146 | } |
130 | 147 | ||
131 | OModel ODevice::model ( ) | 148 | OModel ODevice::model ( ) |
@@ -238,51 +255,96 @@ void ODeviceIPAQ::init ( ) | |||
238 | if ( f. open ( IO_ReadOnly )) { | 255 | if ( f. open ( IO_ReadOnly )) { |
239 | d-> m_systemstr = "Familiar"; | 256 | d-> m_systemstr = "Familiar"; |
240 | d-> m_system = OSYSTEM_Familiar; | 257 | d-> m_system = OSYSTEM_Familiar; |
241 | 258 | ||
242 | QTextStream ts ( &f ); | 259 | QTextStream ts ( &f ); |
243 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); | 260 | d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); |
244 | 261 | ||
245 | f. close ( ); | 262 | f. close ( ); |
246 | } | 263 | } |
247 | 264 | ||
248 | d-> m_leds [0] = OLED_Off; | 265 | d-> m_leds [0] = OLED_Off; |
249 | } | 266 | } |
250 | 267 | ||
251 | #include <unistd.h> | 268 | #include <unistd.h> |
252 | #include <fcntl.h> | 269 | #include <fcntl.h> |
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> |
255 | #include <qapplication.h> | 274 | #include <qapplication.h> |
256 | #include <qpe/config.h> | 275 | #include <qpe/config.h> |
257 | 276 | ||
258 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... | 277 | //#include <linux/h3600_ts.h> // including kernel headers is evil ... |
259 | 278 | ||
260 | typedef struct h3600_ts_led { | 279 | typedef struct h3600_ts_led { |
261 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ | 280 | unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ |
262 | unsigned char TotalTime; /* Units of 5 seconds */ | 281 | unsigned char TotalTime; /* Units of 5 seconds */ |
263 | unsigned char OnTime; /* units of 100m/s */ | 282 | unsigned char OnTime; /* units of 100m/s */ |
264 | unsigned char OffTime; /* units of 100m/s */ | 283 | unsigned char OffTime; /* units of 100m/s */ |
265 | } LED_IN; | 284 | } LED_IN; |
266 | 285 | ||
267 | 286 | ||
268 | // #define IOC_H3600_TS_MAGIC 'f' | 287 | // #define IOC_H3600_TS_MAGIC 'f' |
269 | // #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) | 288 | // #define LED_ON _IOW(IOC_H3600_TS_MAGIC, 5, struct h3600_ts_led) |
270 | #define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( | 289 | #define LED_ON (( 1<<30 ) | ( 'f'<<8 ) | ( 5 ) | ( sizeof(struct h3600_ts_led)<<16 )) // _IOW only defined in kernel headers :( |
271 | 290 | ||
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 ( ) |
274 | { | 336 | { |
275 | #if defined( QT_QWS_IPAQ ) // IPAQ | 337 | #if defined( QT_QWS_IPAQ ) // IPAQ |
276 | #ifndef QT_NO_SOUND | 338 | #ifndef QT_NO_SOUND |
277 | static Sound snd ( "alarm" ); | 339 | static Sound snd ( "alarm" ); |
278 | int fd; | 340 | int fd; |
279 | int vol; | 341 | int vol; |
280 | bool vol_reset = false; | 342 | bool vol_reset = false; |
281 | 343 | ||
282 | if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || | 344 | if ((( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) || |
283 | (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { | 345 | (( fd = ::open ( "/dev/mixer", O_RDWR )) >= 0 )) { |
284 | 346 | ||
285 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { | 347 | if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { |
286 | Config cfg ( "qpe" ); | 348 | Config cfg ( "qpe" ); |
287 | cfg. setGroup ( "Volume" ); | 349 | cfg. setGroup ( "Volume" ); |
288 | 350 | ||
diff --git a/libopie/odevice.h b/libopie/odevice.h index b54e576..eeae357 100644 --- a/libopie/odevice.h +++ b/libopie/odevice.h | |||
@@ -52,33 +52,35 @@ enum OSystem { | |||
52 | }; | 52 | }; |
53 | 53 | ||
54 | enum OLedState { | 54 | enum OLedState { |
55 | OLED_Off, | 55 | OLED_Off, |
56 | OLED_On, | 56 | OLED_On, |
57 | OLED_BlinkSlow, | 57 | OLED_BlinkSlow, |
58 | OLED_BlinkFast | 58 | OLED_BlinkFast |
59 | }; | 59 | }; |
60 | 60 | ||
61 | 61 | ||
62 | class ODevice | 62 | class ODevice |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | 65 | ||
66 | public: | 66 | public: |
67 | static ODevice *inst ( ); | 67 | static ODevice *inst ( ); |
68 | 68 | ||
69 | // system | ||
70 | virtual bool suspend ( ); | ||
69 | 71 | ||
70 | // information | 72 | // information |
71 | 73 | ||
72 | QString modelString ( ); | 74 | QString modelString ( ); |
73 | OModel model ( ); | 75 | OModel model ( ); |
74 | 76 | ||
75 | QString vendorString ( ); | 77 | QString vendorString ( ); |
76 | OVendor vendor ( ); | 78 | OVendor vendor ( ); |
77 | 79 | ||
78 | QString systemString ( ); | 80 | QString systemString ( ); |
79 | OSystem system ( ); | 81 | OSystem system ( ); |
80 | 82 | ||
81 | QString systemVersionString ( ); | 83 | QString systemVersionString ( ); |
82 | 84 | ||
83 | // input / output | 85 | // input / output |
84 | 86 | ||