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

stabmon.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 
00022 #include "stabmon.h"
00023 
00024 #ifdef QWS
00025 #include <qtopia/qcopenvelope_qws.h>
00026 #endif
00027 
00028 #include <qfile.h>
00029 
00030 #include <sys/stat.h>
00031 #if defined(Q_OS_LINUX) || defined(_OS_LINUX_)
00032 #include <unistd.h>
00033 #endif
00034 #include <stdlib.h>
00035 
00036 SysFileMonitor::SysFileMonitor(QObject* parent) :
00037     QObject(parent)
00038 {
00039     startTimer(2000);
00040 }
00041 
00042 const char * stab0 = "/var/run/stab";
00043 const char * stab1 = "/var/state/pcmcia/stab";
00044 const char * stab2 = "/var/lib/pcmcia/stab";
00045 
00046 void SysFileMonitor::timerEvent(QTimerEvent*)
00047 {
00048     struct stat s;
00049 
00050     static const char * tab [] = {
00051         stab0,
00052         stab1,
00053         stab2
00054     };
00055     static const int nstab = sizeof(tab)/sizeof(const char *);
00056     static int last[nstab];
00057 
00058     bool ch = FALSE;
00059     for ( int i=0; i<nstab; i++ ) {
00060         if ( ::stat(tab[i], &s)==0 && (long)s.st_mtime != last[i] ) {
00061             last[i] = (long)s.st_mtime;
00062             ch=TRUE;
00063         }
00064         if ( ch ) {
00065 #ifndef QT_NO_COP
00066             QCopEnvelope("QPE/Card", "stabChanged()" );
00067 #endif
00068             break;
00069         }
00070     }
00071 
00072     // st_size is no use, it's 0 for /proc/mounts too. Read it all.
00073     static int mtabSize = 0;
00074     QFile f( "/proc/mounts" );
00075     if ( f.open(IO_ReadOnly) ) {
00076 #if 0
00077         // readAll does not work correctly on sequential devices (as eg. /proc files)
00078         QByteArray ba = f.readAll();
00079         if ( (int)ba.size() != mtabSize ) {
00080             mtabSize = (int)ba.size();
00081 #ifndef QT_NO_COP
00082             QCopEnvelope("QPE/Card", "mtabChanged()" );
00083 #endif
00084         }
00085 #else
00086         QString s;
00087         while( !f.atEnd() ) {
00088             QString tmp;
00089             f.readLine( tmp, 1024 );
00090             s += tmp;
00091         }
00092         if ( (int)s.length() != mtabSize ) {
00093             mtabSize = (int)s.length();
00094 #ifndef QT_NO_COP
00095             QCopEnvelope("QPE/Card", "mtabChanged()" );
00096 #endif
00097         }
00098 #endif
00099     }
00100 }
00101 

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