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

GPRSrun.cpp

Go to the documentation of this file.
00001 #include <sys/types.h>
00002 #include <signal.h>
00003 #include <errno.h>
00004 #include <qdir.h>
00005 #include <system.h>
00006 #include <resources.h>
00007 #include <netnode.h>
00008 #include "GPRSrun.h"
00009 
00010 State_t GPRSRun::detectState( void ) { 
00011 
00012       // is pppd still running ?
00013       // is rfcomm still active
00014       NetworkSetup * NC = networkSetup();
00015       InterfaceInfo * I = NC->assignedInterface();
00016 
00017       QDir D("/var/run");
00018 
00019       if( I ) {
00020         // has some pppx attached
00021         return ( I->IsUp ) ? IsUp : Available;
00022       }
00023 
00024       // check ppp itself and figure out interface
00025 
00026       odebug << "Check for ppp " << NC->name() << oendl;
00027       if( D.exists( QString("ppp-")+removeSpaces(NC->name())+".pid") ) {
00028         // get pid and check if pppd is still running
00029         QFile F( D.path()+"/ppp-"+removeSpaces(NC->name())+".pid");
00030 
00031         odebug << "PPP PID " << F.name() << oendl;
00032         if( F.open( IO_ReadOnly ) ) {
00033           QTextStream TS(&F);
00034           QString X = TS.readLine();
00035           PPPPid = X.toULong();
00036           int rv;
00037 
00038           rv = ::kill( PPPPid, 0 );
00039           if( rv == 0 ||
00040               ( rv < 0 && errno == EPERM )
00041             ) {
00042             // pppd is still up
00043             X = TS.readLine();
00044             I = NSResources->system().findInterface(X);
00045 
00046             odebug << "ppp running : IFace " << X << " = " << (long)I << oendl;
00047 
00048             if( I ) {
00049               NC->assignInterface( I );
00050               return (I->IsUp) ? IsUp : Available;
00051             }
00052 
00053             return Available;
00054 
00055           } else {
00056             // pppd is down
00057             PPPPid = 0;
00058           } 
00059         } // else pppd is down
00060       }
00061       NC->assignInterface( 0 );
00062       return Unknown;
00063 }
00064 
00065 QString GPRSRun::setMyState( NetworkSetup * NC, Action_t A , bool ) { 
00066 
00067     if( A == Up ) {
00068       // start ppp on deviceFile
00069       QStringList SL;
00070       SL << "pon"
00071          << removeSpaces( NC->name() )
00072          << NC->device()->deviceFile();
00073 
00074       if( ! NSResources->system().execAsUser( SL ) ) {
00075         return QString("Cannot start pppd for %1").arg(NC->name());
00076       }
00077     } else if ( A == Down ) {
00078       if( PPPPid == 0 ) {
00079         detectState();
00080       }
00081       if( PPPPid ) {
00082         QStringList SL;
00083 
00084         SL << "poff"
00085            << removeSpaces( NC->name() );
00086 
00087         if( ! NSResources->system().execAsUser( SL ) ) {
00088           return QString("Cannot terminate pppd for %1").arg(NC->name());
00089         }
00090         NC->assignInterface( 0 );
00091         odebug << "ppp stopped " << oendl;
00092         PPPPid = 0;
00093       }
00094     }
00095 
00096     return QString();
00097 }
00098 
00099 bool GPRSRun::handlesInterface( const QString & S ) {
00100     return Pat.match( S ) >= 0;
00101 }
00102 
00103 bool GPRSRun::handlesInterface( InterfaceInfo * I ) {
00104     return handlesInterface( I->Name );
00105 }

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