Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

odevice_abstractmobiledevice.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) 2004, 2005 Holger Hans Peter Freyther <freyther@handhelds.org>
00004               =.             Copyright (C) 2004, 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
00005             .=l.             Copyright (C) 2002, 2003 Robert Griebl <sandman@handhelds.org>
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; version 2 of the License.
00012      ._= =}       :
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include "odevice_abstractmobiledevice.h"
00031 
00032 /* QT */
00033 #include <qcopchannel_qws.h>
00034 
00035 /* STD */
00036 #include <sys/time.h>
00037 #include <sys/ioctl.h>
00038 #include <time.h>
00039 #include <fcntl.h>
00040 #include <unistd.h>
00041 #include <stdlib.h>
00042 
00043 namespace Opie {
00044 namespace Core {
00045 OAbstractMobileDevice::OAbstractMobileDevice()
00046     : m_timeOut( 1500 )
00047 {}
00048 
00056 void OAbstractMobileDevice::setAPMTimeOut( int time ) {
00057     m_timeOut = time;
00058 }
00059 
00060 
00061 bool OAbstractMobileDevice::suspend() {
00062     if ( !isQWS( ) ) // only qwsserver is allowed to suspend
00063         return false;
00064 
00065     bool res = false;
00066     QCopChannel::send( "QPE/System", "aboutToSuspend()" );
00067 
00068     struct timeval tvs, tvn;
00069     ::gettimeofday ( &tvs, 0 );
00070 
00071     ::sync(); // flush fs caches
00072     res = ( ::system ( "apm --suspend" ) == 0 );
00073 
00074     // This is needed because some apm implementations are asynchronous and we
00075     // can not be sure when exactly the device is really suspended
00076     // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
00077 
00078     if ( res ) {
00079         do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
00080             ::usleep ( 200 * 1000 );
00081             ::gettimeofday ( &tvn, 0 );
00082         } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut );
00083     }
00084 
00085     QCopChannel::send( "QPE/System", "returnFromSuspend()" );
00086 
00087     return res;
00088 }
00089 
00090 //#include <linux/fb.h> better not rely on kernel headers in userspace ...
00091 
00092 // _IO and friends are only defined in kernel headers ...
00093 #define OD_IOC(dir,type,number,size)    (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
00094 #define OD_IO(type,number)              OD_IOC(0,type,number,0)
00095 
00096 #define FBIOBLANK             OD_IO( 'F', 0x11 ) // 0x4611
00097 
00098 /* VESA Blanking Levels */
00099 #define VESA_NO_BLANKING      0
00100 #define VESA_VSYNC_SUSPEND    1
00101 #define VESA_HSYNC_SUSPEND    2
00102 #define VESA_POWERDOWN        3
00103 
00104 bool OAbstractMobileDevice::setDisplayStatus ( bool on ) {
00105     bool res = false;
00106     int fd;
00107 
00108 #ifdef QT_QWS_DEVFS
00109     if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) {
00110 #else
00111     if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
00112 #endif
00113         res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
00114         ::close ( fd );
00115     }
00116 
00117     return res;
00118 }
00119 }
00120 }

Generated on Sat Nov 5 16:16:05 2005 for OPIE by  doxygen 1.4.2