Diffstat (limited to 'noncore/settings/networksettings2/usb') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NN.cpp | 24 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NN.h | 8 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NNI.cpp | 25 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NNI.h | 5 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usbrun.cpp | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usbrun.h | 4 |
6 files changed, 31 insertions, 41 deletions
diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index be4a2bc..30c72db 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -1,67 +1,71 @@ #include "usb_NN.h" #include "usb_NNI.h" static const char * USBNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ USBNetNode::USBNetNode() : ANetNode() { } /** * 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"; } bool USBNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool USBNetNode::hasDataFor( const QString & S, bool ) { +bool USBNetNode::hasDataFor( const QString & S ) { return (S== "interfaces"); } -bool USBNetNode::generateDataForCommonFile( +bool USBNetNode::generateDeviceDataForCommonFile( SystemFile & S , - long DevNr, - ANetNodeInstance * NNI) { - return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr); + long DevNr ) { + QString NIC = genNic( DevNr ); + + if( S.name() == "interfaces" ) { + // generate mapping stanza for this interface + S << "# check if " << NIC << " can be brought UP" << endl; + S << "mapping " << NIC << endl; + S << " script networksettings2-request" << endl << endl; + } + return 0; } -bool USBNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr, - ANetNodeInstance * NNI) { - return ((AUSB *)NNI)->generateDeviceDataForCommonFile(S, DevNr); +QString USBNetNode::genNic( long ) { + return QString( "usbf" ); } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new USBNetNode() ); } } diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index 8ff5289..ba22b1c 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -1,46 +1,46 @@ #ifndef USB_NETNODE_H #define USB_NETNODE_H #include "netnode.h" class AUSB; class USBNetNode : public ANetNode{ Q_OBJECT public: USBNetNode(); virtual ~USBNetNode(); virtual const QString pixmapName() { return "Devices/usb"; } virtual const QString nodeName() { return tr("USB Cable Connect"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S, bool DeviceSpec ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool hasDataFor( const QString & S); virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + SystemFile & SF, long DevNr ); + + virtual QString genNic( long nr ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index 6fcd6d5..e90204c 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -1,57 +1,52 @@ #include <qpe/qpeapplication.h> #include "usbedit.h" #include "usb_NNI.h" #include "usb_NN.h" AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; } void AUSB::setSpecificAttribute( QString & , QString & ) { } void AUSB::saveSpecificAttribute( QTextStream & ) { } QWidget * AUSB::edit( QWidget * parent ) { GUI = new USBEdit( parent ); GUI->showData( Data ); return GUI; } QString AUSB::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AUSB::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) { - AsDevice * Dev = runtime()->device(); - QString NIC = Dev->genNic( DevNr ); - - if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl; - } - return 0; +bool AUSB::hasDataFor( const QString & S ) { + return (S== "interfaces"); } -bool AUSB::generateDeviceDataForCommonFile( SystemFile & S, long DevNr ) { - AsDevice * Dev = runtime()->device(); - QString NIC = Dev->genNic( DevNr ); +bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) { + QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); if( S.name() == "interfaces" ) { // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; + S << " pre-up " + << QPEApplication::qpeDir() + << "bin/setmacaddress.sh " + << NIC + << " || true" + << endl; } return 0; } diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index 5dead36..d2ee217 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -1,45 +1,46 @@ #ifndef USB_H #define USB_H #include <netnode.h> #include "usbdata.h" #include "usbrun.h" class USBNetNode; class USBEdit; class AUSB : public ANetNodeInstance { public : AUSB( USBNetNode * PNN ); QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); RuntimeInfo * runtime( void ) { if( RT == 0 ) RT = new USBRun( this, Data ); return RT; } virtual void * data( void ) { return (void *)&Data; } - bool generateDataForCommonFile( SystemFile & S, long DevNr ); - bool generateDeviceDataForCommonFile( SystemFile & S, long DevNr ); + virtual bool hasDataFor( const QString & S); + virtual bool generateDataForCommonFile( + SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : USBEdit * GUI; USBData Data; USBRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 3007e79..4ce6721 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -81,102 +81,96 @@ bool USBRun::setState( NodeCollection * NC, Action_t A ) { 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 ); fprintf( stderr, "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; } // 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() ) { // assigned to us return Run; } else if( Run->assignedNode() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool USBRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } -QString USBRun::genNic( long nr ) { - QString S; - S.sprintf( "usbf" ); - return S; -} - diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index 60f9fe8..6c6e4e4 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,41 +1,37 @@ #ifndef USBRUN_H #define USBRUN_H #include <asdevice.h> #include <qregexp.h> #include "usbdata.h" class USBRun : public AsDevice { public : USBRun( ANetNodeInstance * NNI, USBData & Data ) : AsDevice( NNI ), Pat( "usb[0-9abcdef]" ) { } - virtual long count( void ) - { return 1; } - virtual QString genNic( long nr ); - virtual AsDevice * device( void ) { return (AsDevice *)this; } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } protected : void detectState( NodeCollection * ); bool setState( NodeCollection * , Action_t A ); bool canSetState( State_t , Action_t A ); bool handlesInterface( const QString & I ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; }; #endif |