Diffstat (limited to 'noncore/settings/networksettings2/usb') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NN.cpp | 9 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NN.h | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NNI.cpp | 11 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usb_NNI.h | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usbrun.cpp | 29 | ||||
-rw-r--r-- | noncore/settings/networksettings2/usb/usbrun.h | 5 |
6 files changed, 47 insertions, 12 deletions
diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index c65771d..be4a2bc 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -21,40 +21,47 @@ 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 USBNetNode::hasDataFor( const QString & S, bool ) { return (S== "interfaces"); } bool USBNetNode::generateDataForCommonFile( SystemFile & S , long DevNr, ANetNodeInstance * NNI) { return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr); } +bool USBNetNode::generateDeviceDataForCommonFile( + SystemFile & S , + long DevNr, + ANetNodeInstance * NNI) { + return ((AUSB *)NNI)->generateDeviceDataForCommonFile(S, DevNr); +} + 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 8b97452..8ff5289 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -7,38 +7,40 @@ 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 ); + virtual bool hasDataFor( const QString & S, bool DeviceSpec ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); 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 4729416..6fcd6d5 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -22,25 +22,36 @@ QWidget * AUSB::edit( QWidget * parent ) { 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::generateDeviceDataForCommonFile( SystemFile & S, long DevNr ) { + AsDevice * Dev = runtime()->device(); + QString NIC = Dev->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; +} diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index b09f17a..5dead36 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -7,38 +7,39 @@ 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 ); 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 49b5a77..3007e79 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -13,108 +13,119 @@ void USBRun::detectState( NodeCollection * NC ) { InterfaceInfo * Run; QFile F( S ); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); // 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; } } } } - fprintf( stderr, "NUP\n" ); - // definitively not up + fprintf( stderr, "Assigned %p\n", assignedInterface() ); + if( ( Run = assignedInterface() ) ) { + // we already have an interface assigned -> still present ? + if( ! Run->IsUp ) { + // usb is still free -> keep assignment + NC->setCurrentState( Available ); + return; + } // else interface is up but NOT us -> some other profile + } + + // nothing (valid) assigned to us assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); + fprintf( stderr, "%s %d %d=%d %d\n", - Run->Name.latin1(), - handlesInterface( Run->Name ), - Run->CardType, ARPHRD_ETHER, - ! Run->IsUp ); + Run->Name.latin1(), + handlesInterface( Run->Name ), + Run->CardType, ARPHRD_ETHER, + ! Run->IsUp ); + if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER && ! Run->IsUp ) { - fprintf( stderr, "OFF\n" ); + fprintf( stderr, "Released(OFF)\n" ); // proper type, and Not UP -> free NC->setCurrentState( Off ); return; } } // no free found fprintf( stderr, "UNA\n" ); NC->setCurrentState( Unavailable ); } bool USBRun::setState( NodeCollection * NC, Action_t A ) { // 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 ); + 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; - } - if( NC->currentState() != Available ) { + } 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 ) { diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index c9c9121..60f9fe8 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,38 +1,41 @@ #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(); } + { 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 |