From 5334b639c9f97793bcae4f50f7b47c7a2ada4e2f Mon Sep 17 00:00:00 2001 From: wimpie Date: Fri, 02 Apr 2004 18:29:49 +0000 Subject: First import of NS2 app --- (limited to 'noncore/settings/networksettings2/usb') diff --git a/noncore/settings/networksettings2/usb/config.in b/noncore/settings/networksettings2/usb/config.in new file mode 100644 index 0000000..988601a --- a/dev/null +++ b/noncore/settings/networksettings2/usb/config.in @@ -0,0 +1,4 @@ + config NS2USB + boolean "opie-networksettings2plugin-usb (set up USB)" + default "n" if NS2 + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NS2 && NS2CORE diff --git a/noncore/settings/networksettings2/usb/usb.pro b/noncore/settings/networksettings2/usb/usb.pro new file mode 100644 index 0000000..cc2f9db --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usb.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +DESTDIR = $(OPIEDIR)/plugins/networksettings2 +HEADERS = usb_NN.h \ + usb_NNI.h \ + usbedit.h +SOURCES = usb_NN.cpp \ + usb_NNI.cpp \ + usbedit.cpp \ + usbrun.cpp +INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 +DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 +LIBS += -lqpe +INTERFACES = usbGUI.ui +TARGET = usb +VERSION = 1.0.0 + +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/usb/usbGUI.ui b/noncore/settings/networksettings2/usb/usbGUI.ui new file mode 100644 index 0000000..bd78ab4 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbGUI.ui @@ -0,0 +1,57 @@ + +USBGUI + + QWidget + + name + USB_FRM + + + geometry + + 0 + 0 + 279 + 199 + + + + caption + USB + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QLabel + + name + TextLabel3 + + + text + Nothing to configure + + + alignment + AlignCenter + + + hAlign + + + + + diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp new file mode 100644 index 0000000..c65771d --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -0,0 +1,60 @@ +#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("\ +

Configure Ethernet over USB.

\ +

Use this for a computer to computer USB cable connection

\ +" +); +} + +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 ) { + return (S== "interfaces"); +} + +bool USBNetNode::generateDataForCommonFile( + SystemFile & S , + long DevNr, + ANetNodeInstance * NNI) { + return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr); +} + +extern "C" { +void create_plugin( QList & PNN ) { + PNN.append( new USBNetNode() ); +} +} diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h new file mode 100644 index 0000000..3871afc --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -0,0 +1,44 @@ +#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 "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 generateDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + +private: + +}; + +extern "C" +{ + void create_plugin( QList & PNN ); +}; + +#endif diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp new file mode 100644 index 0000000..4729416 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -0,0 +1,46 @@ +#include +#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; +} + + diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h new file mode 100644 index 0000000..b09f17a --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -0,0 +1,44 @@ +#ifndef USB_H +#define USB_H + +#include +#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 ); + +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/usbdata.h b/noncore/settings/networksettings2/usb/usbdata.h new file mode 100644 index 0000000..c59f508 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbdata.h @@ -0,0 +1,8 @@ +#ifndef USB_DATA_H +#define USB_DATA_H + +typedef struct USBData { + bool Fake; +} USBData_t; + +#endif diff --git a/noncore/settings/networksettings2/usb/usbedit.cpp b/noncore/settings/networksettings2/usb/usbedit.cpp new file mode 100644 index 0000000..153c497 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbedit.cpp @@ -0,0 +1,17 @@ +#include +#include "usbedit.h" + +USBEdit::USBEdit( QWidget * Parent ) : USBGUI( Parent ){ + +} + +QString USBEdit::acceptable( void ) { + return QString(); +} + +void USBEdit::showData( USBData_t & Data ) { +} + +bool USBEdit::commit( USBData_t & Data ) { + return 1; +} diff --git a/noncore/settings/networksettings2/usb/usbedit.h b/noncore/settings/networksettings2/usb/usbedit.h new file mode 100644 index 0000000..441f2f0 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbedit.h @@ -0,0 +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 ); +}; diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp new file mode 100644 index 0000000..49b5a77 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -0,0 +1,171 @@ +#include +#include +#include +#include +#include "usbrun.h" + +void USBRun::detectState( NodeCollection * NC ) { + // unavailable : no card found + // available : card found and assigned to us or free + // up : card found and assigned to us and up + QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); + System & Sys = NSResources->system(); + 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 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 + assignInterface( 0 ); + + // find possible interface + for( QDictIterator 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 ); + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER && + ! Run->IsUp + ) { + fprintf( stderr, "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 ); + 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 ) { + 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 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 new file mode 100644 index 0000000..c9c9121 --- a/dev/null +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -0,0 +1,38 @@ +#ifndef USBRUN_H +#define USBRUN_H + +#include +#include +#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(); } + +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 -- cgit v0.9.0.2