From 4ea2f227d3fb0d9591bb4f18555420ac47f3397d Mon Sep 17 00:00:00 2001 From: wimpie Date: Fri, 02 Apr 2004 18:30:55 +0000 Subject: first import of NS2 app --- (limited to 'noncore/settings/networksettings2/lancard') diff --git a/noncore/settings/networksettings2/lancard/config.in b/noncore/settings/networksettings2/lancard/config.in new file mode 100644 index 0000000..d190f6e --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/config.in @@ -0,0 +1,4 @@ + config NS2LANCARD + boolean "opie-networksettings2plugin-lancard (regular wired lan card)" + default "n" if NS2 + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NS2 && NS2CORE diff --git a/noncore/settings/networksettings2/lancard/lancard.pro b/noncore/settings/networksettings2/lancard/lancard.pro new file mode 100644 index 0000000..f188d2b --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancard.pro @@ -0,0 +1,18 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +DESTDIR = $(OPIEDIR)/plugins/networksettings2 +HEADERS = lancard_NN.h \ + lancard_NNI.h \ + lancardedit.h +SOURCES = lancard_NN.cpp \ + lancard_NNI.cpp \ + lancardedit.cpp \ + lancardrun.cpp +INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2 +DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2 +LIBS += -lqpe +INTERFACES = lancardGUI.ui +TARGET = lancard +VERSION = 1.0.0 + +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/lancard/lancardGUI.ui b/noncore/settings/networksettings2/lancard/lancardGUI.ui new file mode 100644 index 0000000..8d94816 --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancardGUI.ui @@ -0,0 +1,129 @@ + +LanCardGUI + + QWidget + + name + Lancard_FRM + + + geometry + + 0 + 0 + 362 + 359 + + + + caption + LAN card + + + layoutMargin + + + layoutSpacing + + + + margin + 2 + + + spacing + 2 + + + QCheckBox + + name + AnyCard_CB + + + text + Any available LAN card + + + checked + true + + + + QGroupBox + + name + GroupBox1 + + + enabled + false + + + title + Select Card + + + layoutMargin + + + + margin + 11 + + + spacing + 6 + + + QListView + + + text + Name + + + clickable + true + + + resizeable + true + + + + + text + MACAddress + + + clickable + true + + + resizeable + true + + + + name + LanCards_LV + + + allColumnsShowFocus + true + + + + + + + + + AnyCard_CB + toggled(bool) + GroupBox1 + setDisabled(bool) + + + diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp new file mode 100644 index 0000000..a45496d --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -0,0 +1,60 @@ +#include "lancard_NN.h" +#include "lancard_NNI.h" + +static const char * LanCardNeeds[] = + { 0 }; + +/** + * Constructor, find all of the possible interfaces + */ +LanCardNetNode::LanCardNetNode() : ANetNode() { +} + +/** + * Delete any interfaces that we own. + */ +LanCardNetNode::~LanCardNetNode(){ +} + +const QString LanCardNetNode::nodeDescription(){ + return tr("\ +

Sets up a wired regular LAN card.

\ +

Use this to set up 10/100/1000 MBit LAN cards.

\ +" +); +} + +ANetNodeInstance * LanCardNetNode::createInstance( void ) { + return new ALanCard( this ); +} + + +const char ** LanCardNetNode::needs( void ) { + return LanCardNeeds; +} + +const char * LanCardNetNode::provides( void ) { + return "device"; +} + +bool LanCardNetNode::generateProperFilesFor( + ANetNodeInstance * ) { + return 1; +} + +bool LanCardNetNode::hasDataFor( const QString & ) { + return 0; +} + +bool LanCardNetNode::generateDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + +extern "C" { +void create_plugin( QList & PNN ) { + PNN.append( new LanCardNetNode() ); +} +} diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h new file mode 100644 index 0000000..576a6e0 --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancard_NN.h @@ -0,0 +1,44 @@ +#ifndef LANCARD_NETNODE_H +#define LANCARD_NETNODE_H + +#include "netnode.h" + +class ALanCard; + +class LanCardNetNode : public ANetNode{ + + Q_OBJECT + +public: + + LanCardNetNode(); + virtual ~LanCardNetNode(); + + virtual const QString pixmapName() + { return "card"; } + + virtual const QString nodeName() + { return tr("LAN card"); } + + 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/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp new file mode 100644 index 0000000..9595e2e --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp @@ -0,0 +1,44 @@ +#include "lancardedit.h" +#include "lancard_NNI.h" +#include "lancard_NN.h" + +ALanCard::ALanCard( LanCardNetNode * PNN ) : ANetNodeInstance( PNN ) { + + Data.AnyLanCard = 1; + Data.HWAddresses.clear(); + + GUI = 0; + RT = 0; +} + +void ALanCard::setSpecificAttribute( QString & A, QString & V ) { + if( A == "matchanycard" ) { + Data.AnyLanCard = (V == "yes" ); + } else if( A == "match" ) { + Data.HWAddresses.append( V ); + } +} + +void ALanCard::saveSpecificAttribute( QTextStream & TS) { + TS << "matchanycard=" << + ((Data.AnyLanCard) ? "yes" : "no") << endl; + for( QStringList::Iterator it = Data.HWAddresses.begin(); + it != Data.HWAddresses.end(); ++it ) { + TS << "match=" << quote( *it ) << endl; + } +} + +QWidget * ALanCard::edit( QWidget * parent ) { + GUI = new LanCardEdit( parent ); + GUI->showData( Data ); + return GUI; +} + +QString ALanCard::acceptable( void ) { + return ( GUI ) ? GUI->acceptable( ) : QString(); +} + +void ALanCard::commit( void ) { + if( GUI && GUI->commit( Data ) ) + setModified( 1 ); +} diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.h b/noncore/settings/networksettings2/lancard/lancard_NNI.h new file mode 100644 index 0000000..8fc8868 --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.h @@ -0,0 +1,43 @@ +#ifndef LANCARD_H +#define LANCARD_H + +#include +#include "lancarddata.h" +#include "lancardrun.h" + +class LanCardNetNode; +class LanCardEdit; + +class ALanCard : public ANetNodeInstance { + +public : + + ALanCard( LanCardNetNode * PNN ); + + QWidget * edit( QWidget * parent ); + QString acceptable( void ); + void commit( void ); + + RuntimeInfo * runtime( void ) + { if( RT == 0 ) + RT = new LanCardRun( this, Data ); + return RT; + } + + virtual void * data( void ) + { return (void *)&Data; } + +protected : + + virtual void setSpecificAttribute( QString & Attr, QString & Value ); + virtual void saveSpecificAttribute( QTextStream & TS ); + +private : + + LanCardEdit * GUI; + LanCardData Data; + LanCardRun * RT; + +}; + +#endif diff --git a/noncore/settings/networksettings2/lancard/lancarddata.h b/noncore/settings/networksettings2/lancard/lancarddata.h new file mode 100644 index 0000000..c76767f --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancarddata.h @@ -0,0 +1,13 @@ +#ifndef LANCARD_DATA_H +#define LANCARD_DATA_H + +#include +#include + +typedef struct LanCardData { + bool AnyLanCard; + QStringList HWAddresses; + +} LanCardData_t; + +#endif diff --git a/noncore/settings/networksettings2/lancard/lancardedit.cpp b/noncore/settings/networksettings2/lancard/lancardedit.cpp new file mode 100644 index 0000000..fa7f6dc --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancardedit.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include "lancardedit.h" + +LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){ + System & S = NSResources->system(); + QRegExp R( "eth[0-9]" ); + QCheckListItem * CLI; + + LanCards_LV->header()->hide(); + + // populate with all lancards in system + for( QDictIterator It(S.interfaces()); + It.current(); + ++It ) { + if( R.match( It.current()->Name ) >= 0 && + It.current()->CardType == ARPHRD_ETHER + ) { + CLI = new QCheckListItem( LanCards_LV, It.current()->Name, + QCheckListItem::CheckBox ); + CLI->setText( 1, It.current()->MACAddress ); + } + } +} + +QString LanCardEdit::acceptable( void ) { + return QString(); +} + + +bool LanCardEdit::commit( LanCardData & Data ) { + bool SM = 0; + CBM( Data.AnyLanCard, AnyCard_CB, SM ); + + if( ! Data.AnyLanCard ) { + // collect set of lancards that match + int idx; + QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); + while( CLI ) { + idx = Data.HWAddresses.findIndex(CLI->text(1)); + if( CLI->isOn() ) { + if( idx < 0 ) { + // should be in list + Data.HWAddresses.append( CLI->text(1) ); + SM = 1; + } + } else { + // should not be in list + if( idx >= 0 ) { + Data.HWAddresses.remove( Data.HWAddresses.at(idx) ); + SM = 1; + } + } + CLI = (QCheckListItem *)CLI->nextSibling(); + } + } + return SM || ContainedObsoleteMAC ; +} + +void LanCardEdit::showData( LanCardData & Data ) { + AnyCard_CB->setChecked( Data.AnyLanCard ); + + QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); + + ContainedObsoleteMAC = 0; + // remove obsolete address + for( QStringList::Iterator it=Data.HWAddresses.begin(); + it != Data.HWAddresses.end(); + ) { + CLI = (QCheckListItem *)LanCards_LV->firstChild(); + while( CLI ) { + if( CLI->text(1) == (*it) ) + // still valid + break; + CLI = (QCheckListItem *)CLI->nextSibling(); + } + if( CLI == 0 ) { + // address not found -> remove + ContainedObsoleteMAC = 1; + Data.HWAddresses.remove( it ); + } else { + ++ it; + } + } + + // set checks + while( CLI ) { + CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 ); + CLI = (QCheckListItem *)CLI->nextSibling(); + } +} diff --git a/noncore/settings/networksettings2/lancard/lancardedit.h b/noncore/settings/networksettings2/lancard/lancardedit.h new file mode 100644 index 0000000..8def789 --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancardedit.h @@ -0,0 +1,16 @@ +#include "lancarddata.h" +#include "lancardGUI.h" + +class LanCardEdit : public LanCardGUI { + +public : + + LanCardEdit( QWidget * parent ); + QString acceptable( void ); + bool commit( LanCardData & Data ); + void showData( LanCardData & Data ); + +private : + + bool ContainedObsoleteMAC; +}; diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp new file mode 100644 index 0000000..b3b592b --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include "lancardrun.h" + +void LanCardRun::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; + } + } + } + } + + // we are certainly not UP + assignInterface( 0 ); + + // find possible interface + for( QDictIterator It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER && + ! Run->IsUp + ) { + // proper type, and Not UP -> free + NC->setCurrentState( Off ); + return; + } + } + // no free found + + NC->setCurrentState( Unavailable ); + +} + +bool LanCardRun::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 LanCardRun::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 * LanCardRun::getInterface( void ) { + + System & S = NSResources->system(); + InterfaceInfo * best = 0, * Run; + + for( QDictIterator It(S.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( Run->Name ) && + Run->CardType == ARPHRD_ETHER + ) { + // this is a LAN card + if( Run->assignedNode() == netNode() ) { + // assigned to us + return Run; + } else if( Run->assignedNode() == 0 ) { + // free + best = Run; + } + } + } + return best; // can be 0 +} + +bool LanCardRun::handlesInterface( const QString & S ) { + return Pat.match( S ) >= 0; +} diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h new file mode 100644 index 0000000..5f004e0 --- a/dev/null +++ b/noncore/settings/networksettings2/lancard/lancardrun.h @@ -0,0 +1,38 @@ +#ifndef LANCARDRUN_H +#define LANCARDRUN_H + +#include +#include +#include "lancarddata.h" + +class LanCardRun : public AsDevice { + +public : + + LanCardRun( ANetNodeInstance * NNI, + LanCardData & Data ) : AsDevice( NNI ), + Pat( "eth[0-9]" ) + { } + + virtual long count( void ) + { return 2; } + virtual QString genNic( long nr ) + { QString S; return S.sprintf( "eth%ld", nr ); } + virtual AsDevice * device( void ) + { return asDevice(); } + +protected : + + void detectState( NodeCollection * NC ); + bool setState( NodeCollection * NC, Action_t A ); + bool canSetState( State_t Curr, Action_t A ); + + bool handlesInterface( const QString & I ); + +private : + + InterfaceInfo * getInterface( void ); + QRegExp Pat; + +}; +#endif -- cgit v0.9.0.2