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

wlanrun.cpp

Go to the documentation of this file.
00001 
00002 #include <qfile.h>
00003 #include <qtextstream.h>
00004 #include <qstringlist.h>
00005 #include <resources.h>
00006 #include "wlanrun.h"
00007 
00008 State_t WLanRun::detectState( void ) {
00009 
00010     // unavailable : no card found
00011     // available : card found and assigned to us or free
00012     // up : card found and assigned to us and up
00013 
00014     NetworkSetup * NC = networkSetup();
00015     QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
00016     System & Sys = NSResources->system();
00017     InterfaceInfo * Run;
00018 
00019     QFile F( S );
00020 
00021     if( F.open( IO_ReadOnly ) ) {
00022       // could open file -> read interface and assign
00023       QString X;
00024       QTextStream TS(&F);
00025       X = TS.readLine();
00026       // find interface
00027       if( handlesInterface( X ) ) {
00028         for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
00029              It.current();
00030              ++It ) {
00031           Run = It.current();
00032           if( X == Run->Name ) {
00033             NC->assignInterface( Run );
00034             return (Run->IsUp) ? IsUp : Available;
00035           }
00036         }
00037       }
00038     } 
00039 
00040     if( ( Run = NC->assignedInterface() ) ) {
00041       // we already have an interface assigned -> still present ?
00042       if( ! Run->IsUp ) {
00043         // usb is still free -> keep assignment
00044         return Available;
00045       } // else interface is up but NOT us -> some other profile
00046     }
00047 
00048     // nothing (valid) assigned to us
00049     NC->assignInterface( 0 );
00050 
00051     // find possible interface
00052     for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
00053          It.current();
00054          ++It ) {
00055       Run = It.current();
00056       if( handlesInterface( *Run ) &&
00057           ( Run->CardType == ARPHRD_ETHER
00058 #ifdef ARPHRD_IEEE1394
00059             || Run->CardType == ARPHRD_IEEE1394
00060 #endif
00061           ) &&
00062           ! Run->IsUp
00063         ) {
00064         // proper type, and Not UP -> free
00065         return Off;
00066       }
00067     }
00068 
00069     return Unavailable;
00070 
00071 }
00072 
00073 QString WLanRun::setMyState( NetworkSetup * , Action_t , bool ) {
00074 
00075     // we only handle activate and deactivate
00076     return QString();
00077 }
00078 
00079 // get interface that is free or assigned to us
00080 InterfaceInfo * WLanRun::getInterface( void ) {
00081 
00082     System & S = NSResources->system();
00083     InterfaceInfo * best = 0, * Run;
00084 
00085     for( QDictIterator<InterfaceInfo> It(S.interfaces());
00086          It.current();
00087          ++It ) {
00088       Run = It.current();
00089       if( handlesInterface( *Run ) &&
00090           ( Run->CardType == ARPHRD_ETHER
00091 #ifdef ARPHRD_IEEE1394
00092             || Run->CardType == ARPHRD_IEEE1394
00093 #endif
00094           )
00095         ) {
00096         // this is a LAN card
00097         if( Run->assignedToNetworkSetup() == netNode()->networkSetup() ) {
00098           // assigned to us
00099           return Run;
00100         } else if( Run->assignedToNetworkSetup() == 0 ) {
00101           // free
00102           best = Run;
00103         }
00104       }
00105     }
00106     return best; // can be 0
00107 }
00108 
00109 bool WLanRun::handlesInterface( const QString & S ) {
00110     InterfaceInfo * II;
00111     II = NSResources->system().interface( S );
00112     if( ( II = NSResources->system().interface( S ) ) ) {
00113       return handlesInterface( *II );
00114     }
00115     return Pat.match( S ) >= 0;
00116 }
00117 
00118 bool WLanRun::handlesInterface( const InterfaceInfo & II ) {
00119     return ( Pat.match( II.Name ) < 0 );
00120 }

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