Diffstat (limited to 'noncore/settings/networksettings2/usb') (more/less context) (ignore whitespace changes)
10 files changed, 56 insertions, 118 deletions
diff --git a/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control b/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control index 8b8508c..ffb3012 100644 --- a/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control +++ b/noncore/settings/networksettings2/usb/opie-networksettings2plugin-usb.control @@ -1,9 +1,9 @@ -Package: opie-networksettingsplugin2-usb +Package: opie-networksettings2plugin-usb Files: plugins/networksettings2/libusb.so* Priority: optional Section: opie/settings Maintainer: Wim Delvaux <wimpie@handhelds.org> Architecture: arm Depends: opie-networksettings2, libopiecore2, libopienet2 Description: Network settings usb plugin. Version: $QPE_VERSION$EXTRAVERSION diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index 14c479a..bd9ae2b 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -1,49 +1,57 @@ +#include <resources.h> #include "usb_NN.h" #include "usb_NNI.h" static const char * USBNeeds[] = { 0 }; +static const char * USBProvides[] = + { "device", + 0 + }; + /** * Constructor, find all of the possible interfaces */ USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) { + NSResources->addSystemFile( + "interfaces", "/etc/network/interfaces", 1 ); } /** * Delete any interfaces that we own. */ USBNetNode::~USBNetNode(){ } const QString USBNetNode::nodeDescription(){ return tr("\ <p>Configure Ethernet over USB.</p>\ <p>Use this for a computer to computer USB cable connection</p>\ " ); } ANetNodeInstance * USBNetNode::createInstance( void ) { return new AUSB( this ); } const char ** USBNetNode::needs( void ) { return USBNeeds; } -const char * USBNetNode::provides( void ) { - return "device"; +const char ** USBNetNode::provides( void ) { + return USBProvides; } QString USBNetNode::genNic( long ) { return QString( "usbf" ); } void USBNetNode::setSpecificAttribute( QString & , QString & ) { } void USBNetNode::saveSpecificAttribute( QTextStream & ) { } diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index 73da15a..b825cec 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -11,25 +11,25 @@ class USBNetNode : public ANetNode{ public: USBNetNode(); virtual ~USBNetNode(); virtual const QString pixmapName() { return "Devices/usb"; } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const char ** provides( void ); virtual QString genNic( long nr ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index 50c6e8d..600b771 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -23,39 +23,37 @@ QWidget * AUSB::edit( QWidget * parent ) { } QString AUSB::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AUSB::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -short AUSB::generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, +short AUSB::generateFileEmbedded( SystemFile & SF, long DevNr ) { QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); short rvl, rvd; rvl = 1; - if( ID == "interfaces" ) { - Log(("Generate USB for %s\n", ID.latin1() )); + if( SF.name() == "interfaces" ) { + Log(("Generate USB for %s\n", SF.name().latin1() )); // generate mapping stanza for this interface - TS << " pre-up " + SF << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl; rvl = 0; } - rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + rvd = ANetNodeInstance::generateFileEmbedded(SF, DevNr ); return (rvd == 2 || rvl == 2 ) ? 2 : (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index fcdfd91..27e71ee 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -17,27 +17,25 @@ public : RuntimeInfo * runtime( void ) { return ( RT ) ? RT : ( RT = new USBRun( this, Data ) ); } QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); virtual void * data( void ) { return (void *)&Data; } - virtual short generateFileEmbedded( const QString & ID, - const QString & Path, - QTextStream & TS, + virtual short generateFileEmbedded( SystemFile & TS, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : USBEdit * GUI; USBData Data; USBRun * RT; diff --git a/noncore/settings/networksettings2/usb/usbdata.h b/noncore/settings/networksettings2/usb/usbdata.h index c59f508..fa357b5 100644 --- a/noncore/settings/networksettings2/usb/usbdata.h +++ b/noncore/settings/networksettings2/usb/usbdata.h @@ -1,8 +1,9 @@ #ifndef USB_DATA_H #define USB_DATA_H -typedef struct USBData { +class USBData { +public : bool Fake; -} USBData_t; +} ; #endif diff --git a/noncore/settings/networksettings2/usb/usbedit.cpp b/noncore/settings/networksettings2/usb/usbedit.cpp index 153c497..cc96b96 100644 --- a/noncore/settings/networksettings2/usb/usbedit.cpp +++ b/noncore/settings/networksettings2/usb/usbedit.cpp @@ -1,17 +1,17 @@ #include <GUIUtils.h> #include "usbedit.h" USBEdit::USBEdit( QWidget * Parent ) : USBGUI( Parent ){ } QString USBEdit::acceptable( void ) { return QString(); } -void USBEdit::showData( USBData_t & Data ) { +void USBEdit::showData( USBData & Data ) { } -bool USBEdit::commit( USBData_t & Data ) { +bool USBEdit::commit( USBData & Data ) { return 1; } diff --git a/noncore/settings/networksettings2/usb/usbedit.h b/noncore/settings/networksettings2/usb/usbedit.h index 441f2f0..4179898 100644 --- a/noncore/settings/networksettings2/usb/usbedit.h +++ b/noncore/settings/networksettings2/usb/usbedit.h @@ -1,12 +1,12 @@ #include "usbdata.h" #include "usbGUI.h" class USBEdit : public USBGUI { public : USBEdit( QWidget * parent ); QString acceptable( void ); - bool commit( USBData_t & Data ); - void showData( USBData_t & Data ); + bool commit( USBData & Data ); + void showData( USBData & Data ); }; diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index b8ac8a8..f8824e0 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,178 +1,112 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "usbrun.h" -void USBRun::detectState( NodeCollection * NC ) { +State_t USBRun::detectState( void ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up + NodeCollection * NC = nodeCollection(); QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); Log(("Detecting for %s\n", NC->name().latin1() )); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); Log(("%s exists\n", S.latin1() )); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { - Run->assignNode( netNode() ); - assignInterface( Run ); - NC->setCurrentState( IsUp ); - return; + NC->assignInterface( Run ); + return IsUp; } } } } - Log(("Assigned %p\n", assignedInterface() )); - if( ( Run = assignedInterface() ) ) { + Log(("Assigned %p\n", NC->assignedInterface() )); + if( ( Run = NC->assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment - NC->setCurrentState( Available ); - return; + return Available; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us - assignInterface( 0 ); + NC->assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); Log(("%s %d %d=%d %d\n", Run->Name.latin1(), handlesInterface( Run->Name ), Run->CardType, ARPHRD_ETHER, ! Run->IsUp )); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER && ! Run->IsUp ) { - Log(("Released(OFF)\n" )); // proper type, and Not UP -> free - NC->setCurrentState( Off ); - return; + return Off; } } - // no free found - Log(("UNA\n" )); - NC->setCurrentState( Unavailable ); + return Unavailable; } -bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) { - - // we only handle activate and deactivate - switch( A ) { - case Activate : - { - if( NC->currentState() != Off ) { - return 0; - } - InterfaceInfo * N = getInterface(); - if( ! N ) { - // no interface available - NC->setCurrentState( Unavailable ); - return 0; - } - // because we were OFF the interface - // we get back is NOT assigned - N->assignNode( netNode() ); - assignInterface( N ); - Log(("Assing %p\n", N )); - NC->setCurrentState( Available ); - return 1; - } - case Deactivate : - if( NC->currentState() == IsUp ) { - // bring down first - if( ! connection()->setState( Down ) ) - // could not ... - return 0; - } else if( NC->currentState() != Available ) { - return 1; - } - assignedInterface()->assignNode( 0 ); // release - assignInterface( 0 ); - NC->setCurrentState( Off ); - return 1; - default : - // FT - break; - } - return 0; -} - -bool USBRun::canSetState( State_t Curr, Action_t A ) { - // we only handle up down activate and deactivate - switch( A ) { - case Activate : - { // at least available - if( Curr == Available ) { - return 1; - } - // or we can make one available - InterfaceInfo * N = getInterface(); - if( ! N || N->assignedNode() != 0 ) { - // non available or assigned - return 0; - } - return 1; - } - case Deactivate : - return ( Curr >= Available ); - default : - // FT - break; - } - return 0; +QString USBRun::setMyState( NodeCollection *, Action_t , bool ) { + return QString(); } // get interface that is free or assigned to us InterfaceInfo * USBRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; QRegExp R( "usb[0-9abcdef]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER ) { // this is a USB card - if( Run->assignedNode() == netNode() ) { + if( Run->assignedConnection() == netNode()->connection() ) { // assigned to us return Run; - } else if( Run->assignedNode() == 0 ) { + } else if( Run->assignedConnection() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool USBRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } +bool USBRun::handlesInterface( InterfaceInfo * I ) { + return handlesInterface( I->Name ); +} + diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index 03e21ab..6ce4fa2 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,37 +1,36 @@ #ifndef USBRUN_H #define USBRUN_H -#include <asdevice.h> +#include <netnode.h> #include <qregexp.h> #include "usbdata.h" -class USBRun : public AsDevice { +class USBRun : public RuntimeInfo { public : USBRun( ANetNodeInstance * NNI, USBData & Data ) : - AsDevice( NNI ), - Pat( "usb[0-9abcdef]" ) - { } + RuntimeInfo( NNI ), + Pat( "usb[0-9abcdef]" ) { + } - virtual AsDevice * device( void ) - { return (AsDevice *)this; } + virtual RuntimeInfo * device( void ) + { return this; } - virtual AsDevice * asDevice( void ) - { return (AsDevice *)this; } -protected : + bool handlesInterface( const QString & I ); + bool handlesInterface( InterfaceInfo * ); - void detectState( NodeCollection * ); - bool setState( NodeCollection * , Action_t A, bool ); - bool canSetState( State_t , Action_t A ); + State_t detectState( void ); - bool handlesInterface( const QString & I ); +protected : + + QString setMyState( NodeCollection * , Action_t, bool ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; }; #endif |