author | wimpie <wimpie> | 2004-04-02 18:30:55 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-02 18:30:55 (UTC) |
commit | 4ea2f227d3fb0d9591bb4f18555420ac47f3397d (patch) (unidiff) | |
tree | 4fdd216cf7af4a747e2ca71e35d15f3d9e646333 /noncore/settings/networksettings2/lancard | |
parent | 5334b639c9f97793bcae4f50f7b47c7a2ada4e2f (diff) | |
download | opie-4ea2f227d3fb0d9591bb4f18555420ac47f3397d.zip opie-4ea2f227d3fb0d9591bb4f18555420ac47f3397d.tar.gz opie-4ea2f227d3fb0d9591bb4f18555420ac47f3397d.tar.bz2 |
first import of NS2 app
Diffstat (limited to 'noncore/settings/networksettings2/lancard') (more/less context) (ignore whitespace changes)
12 files changed, 662 insertions, 0 deletions
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 @@ | |||
1 | config NS2LANCARD | ||
2 | boolean "opie-networksettings2plugin-lancard (regular wired lan card)" | ||
3 | default "n" if NS2 | ||
4 | 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 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt warn_on release | ||
3 | DESTDIR = $(OPIEDIR)/plugins/networksettings2 | ||
4 | HEADERS = lancard_NN.h \ | ||
5 | lancard_NNI.h \ | ||
6 | lancardedit.h | ||
7 | SOURCES = lancard_NN.cpp \ | ||
8 | lancard_NNI.cpp \ | ||
9 | lancardedit.cpp \ | ||
10 | lancardrun.cpp | ||
11 | INCLUDEPATH+= $(OPIEDIR)/include ../ ../networksettings2 | ||
12 | DEPENDPATH+= $(OPIEDIR)/include ../ ../networksettings2 | ||
13 | LIBS += -lqpe | ||
14 | INTERFACES= lancardGUI.ui | ||
15 | TARGET = lancard | ||
16 | VERSION = 1.0.0 | ||
17 | |||
18 | 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 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>LanCardGUI</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>Lancard_FRM</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>362</width> | ||
15 | <height>359</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>LAN card</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <vbox> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>2</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>2</number> | ||
36 | </property> | ||
37 | <widget> | ||
38 | <class>QCheckBox</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>AnyCard_CB</cstring> | ||
42 | </property> | ||
43 | <property stdset="1"> | ||
44 | <name>text</name> | ||
45 | <string>Any available LAN card</string> | ||
46 | </property> | ||
47 | <property stdset="1"> | ||
48 | <name>checked</name> | ||
49 | <bool>true</bool> | ||
50 | </property> | ||
51 | </widget> | ||
52 | <widget> | ||
53 | <class>QGroupBox</class> | ||
54 | <property stdset="1"> | ||
55 | <name>name</name> | ||
56 | <cstring>GroupBox1</cstring> | ||
57 | </property> | ||
58 | <property stdset="1"> | ||
59 | <name>enabled</name> | ||
60 | <bool>false</bool> | ||
61 | </property> | ||
62 | <property stdset="1"> | ||
63 | <name>title</name> | ||
64 | <string>Select Card</string> | ||
65 | </property> | ||
66 | <property> | ||
67 | <name>layoutMargin</name> | ||
68 | </property> | ||
69 | <vbox> | ||
70 | <property stdset="1"> | ||
71 | <name>margin</name> | ||
72 | <number>11</number> | ||
73 | </property> | ||
74 | <property stdset="1"> | ||
75 | <name>spacing</name> | ||
76 | <number>6</number> | ||
77 | </property> | ||
78 | <widget> | ||
79 | <class>QListView</class> | ||
80 | <column> | ||
81 | <property> | ||
82 | <name>text</name> | ||
83 | <string>Name</string> | ||
84 | </property> | ||
85 | <property> | ||
86 | <name>clickable</name> | ||
87 | <bool>true</bool> | ||
88 | </property> | ||
89 | <property> | ||
90 | <name>resizeable</name> | ||
91 | <bool>true</bool> | ||
92 | </property> | ||
93 | </column> | ||
94 | <column> | ||
95 | <property> | ||
96 | <name>text</name> | ||
97 | <string>MACAddress</string> | ||
98 | </property> | ||
99 | <property> | ||
100 | <name>clickable</name> | ||
101 | <bool>true</bool> | ||
102 | </property> | ||
103 | <property> | ||
104 | <name>resizeable</name> | ||
105 | <bool>true</bool> | ||
106 | </property> | ||
107 | </column> | ||
108 | <property stdset="1"> | ||
109 | <name>name</name> | ||
110 | <cstring>LanCards_LV</cstring> | ||
111 | </property> | ||
112 | <property stdset="1"> | ||
113 | <name>allColumnsShowFocus</name> | ||
114 | <bool>true</bool> | ||
115 | </property> | ||
116 | </widget> | ||
117 | </vbox> | ||
118 | </widget> | ||
119 | </vbox> | ||
120 | </widget> | ||
121 | <connections> | ||
122 | <connection> | ||
123 | <sender>AnyCard_CB</sender> | ||
124 | <signal>toggled(bool)</signal> | ||
125 | <receiver>GroupBox1</receiver> | ||
126 | <slot>setDisabled(bool)</slot> | ||
127 | </connection> | ||
128 | </connections> | ||
129 | </UI> | ||
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 @@ | |||
1 | #include "lancard_NN.h" | ||
2 | #include "lancard_NNI.h" | ||
3 | |||
4 | static const char * LanCardNeeds[] = | ||
5 | { 0 }; | ||
6 | |||
7 | /** | ||
8 | * Constructor, find all of the possible interfaces | ||
9 | */ | ||
10 | LanCardNetNode::LanCardNetNode() : ANetNode() { | ||
11 | } | ||
12 | |||
13 | /** | ||
14 | * Delete any interfaces that we own. | ||
15 | */ | ||
16 | LanCardNetNode::~LanCardNetNode(){ | ||
17 | } | ||
18 | |||
19 | const QString LanCardNetNode::nodeDescription(){ | ||
20 | return tr("\ | ||
21 | <p>Sets up a wired regular LAN card.</p>\ | ||
22 | <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ | ||
23 | " | ||
24 | ); | ||
25 | } | ||
26 | |||
27 | ANetNodeInstance * LanCardNetNode::createInstance( void ) { | ||
28 | return new ALanCard( this ); | ||
29 | } | ||
30 | |||
31 | |||
32 | const char ** LanCardNetNode::needs( void ) { | ||
33 | return LanCardNeeds; | ||
34 | } | ||
35 | |||
36 | const char * LanCardNetNode::provides( void ) { | ||
37 | return "device"; | ||
38 | } | ||
39 | |||
40 | bool LanCardNetNode::generateProperFilesFor( | ||
41 | ANetNodeInstance * ) { | ||
42 | return 1; | ||
43 | } | ||
44 | |||
45 | bool LanCardNetNode::hasDataFor( const QString & ) { | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | bool LanCardNetNode::generateDataForCommonFile( | ||
50 | SystemFile & , | ||
51 | long , | ||
52 | ANetNodeInstance * ) { | ||
53 | return 1; | ||
54 | } | ||
55 | |||
56 | extern "C" { | ||
57 | void create_plugin( QList<ANetNode> & PNN ) { | ||
58 | PNN.append( new LanCardNetNode() ); | ||
59 | } | ||
60 | } | ||
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 @@ | |||
1 | #ifndef LANCARD_NETNODE_H | ||
2 | #define LANCARD_NETNODE_H | ||
3 | |||
4 | #include "netnode.h" | ||
5 | |||
6 | class ALanCard; | ||
7 | |||
8 | class LanCardNetNode : public ANetNode{ | ||
9 | |||
10 | Q_OBJECT | ||
11 | |||
12 | public: | ||
13 | |||
14 | LanCardNetNode(); | ||
15 | virtual ~LanCardNetNode(); | ||
16 | |||
17 | virtual const QString pixmapName() | ||
18 | { return "card"; } | ||
19 | |||
20 | virtual const QString nodeName() | ||
21 | { return tr("LAN card"); } | ||
22 | |||
23 | virtual const QString nodeDescription() ; | ||
24 | |||
25 | virtual ANetNodeInstance * createInstance( void ); | ||
26 | |||
27 | virtual const char ** needs( void ); | ||
28 | virtual const char * provides( void ); | ||
29 | |||
30 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); | ||
31 | virtual bool hasDataFor( const QString & S ); | ||
32 | virtual bool generateDataForCommonFile( | ||
33 | SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); | ||
34 | |||
35 | private: | ||
36 | |||
37 | }; | ||
38 | |||
39 | extern "C" | ||
40 | { | ||
41 | void create_plugin( QList<ANetNode> & PNN ); | ||
42 | }; | ||
43 | |||
44 | #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 @@ | |||
1 | #include "lancardedit.h" | ||
2 | #include "lancard_NNI.h" | ||
3 | #include "lancard_NN.h" | ||
4 | |||
5 | ALanCard::ALanCard( LanCardNetNode * PNN ) : ANetNodeInstance( PNN ) { | ||
6 | |||
7 | Data.AnyLanCard = 1; | ||
8 | Data.HWAddresses.clear(); | ||
9 | |||
10 | GUI = 0; | ||
11 | RT = 0; | ||
12 | } | ||
13 | |||
14 | void ALanCard::setSpecificAttribute( QString & A, QString & V ) { | ||
15 | if( A == "matchanycard" ) { | ||
16 | Data.AnyLanCard = (V == "yes" ); | ||
17 | } else if( A == "match" ) { | ||
18 | Data.HWAddresses.append( V ); | ||
19 | } | ||
20 | } | ||
21 | |||
22 | void ALanCard::saveSpecificAttribute( QTextStream & TS) { | ||
23 | TS << "matchanycard=" << | ||
24 | ((Data.AnyLanCard) ? "yes" : "no") << endl; | ||
25 | for( QStringList::Iterator it = Data.HWAddresses.begin(); | ||
26 | it != Data.HWAddresses.end(); ++it ) { | ||
27 | TS << "match=" << quote( *it ) << endl; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | QWidget * ALanCard::edit( QWidget * parent ) { | ||
32 | GUI = new LanCardEdit( parent ); | ||
33 | GUI->showData( Data ); | ||
34 | return GUI; | ||
35 | } | ||
36 | |||
37 | QString ALanCard::acceptable( void ) { | ||
38 | return ( GUI ) ? GUI->acceptable( ) : QString(); | ||
39 | } | ||
40 | |||
41 | void ALanCard::commit( void ) { | ||
42 | if( GUI && GUI->commit( Data ) ) | ||
43 | setModified( 1 ); | ||
44 | } | ||
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 @@ | |||
1 | #ifndef LANCARD_H | ||
2 | #define LANCARD_H | ||
3 | |||
4 | #include <netnode.h> | ||
5 | #include "lancarddata.h" | ||
6 | #include "lancardrun.h" | ||
7 | |||
8 | class LanCardNetNode; | ||
9 | class LanCardEdit; | ||
10 | |||
11 | class ALanCard : public ANetNodeInstance { | ||
12 | |||
13 | public : | ||
14 | |||
15 | ALanCard( LanCardNetNode * PNN ); | ||
16 | |||
17 | QWidget * edit( QWidget * parent ); | ||
18 | QString acceptable( void ); | ||
19 | void commit( void ); | ||
20 | |||
21 | RuntimeInfo * runtime( void ) | ||
22 | { if( RT == 0 ) | ||
23 | RT = new LanCardRun( this, Data ); | ||
24 | return RT; | ||
25 | } | ||
26 | |||
27 | virtual void * data( void ) | ||
28 | { return (void *)&Data; } | ||
29 | |||
30 | protected : | ||
31 | |||
32 | virtual void setSpecificAttribute( QString & Attr, QString & Value ); | ||
33 | virtual void saveSpecificAttribute( QTextStream & TS ); | ||
34 | |||
35 | private : | ||
36 | |||
37 | LanCardEdit * GUI; | ||
38 | LanCardData Data; | ||
39 | LanCardRun * RT; | ||
40 | |||
41 | }; | ||
42 | |||
43 | #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 @@ | |||
1 | #ifndef LANCARD_DATA_H | ||
2 | #define LANCARD_DATA_H | ||
3 | |||
4 | #include <qstringlist.h> | ||
5 | #include <qstring.h> | ||
6 | |||
7 | typedef struct LanCardData { | ||
8 | bool AnyLanCard; | ||
9 | QStringList HWAddresses; | ||
10 | |||
11 | } LanCardData_t; | ||
12 | |||
13 | #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 @@ | |||
1 | #include <GUIUtils.h> | ||
2 | #include <resources.h> | ||
3 | #include <qlistview.h> | ||
4 | #include <qcheckbox.h> | ||
5 | #include <qheader.h> | ||
6 | #include <qregexp.h> | ||
7 | #include "lancardedit.h" | ||
8 | |||
9 | LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){ | ||
10 | System & S = NSResources->system(); | ||
11 | QRegExp R( "eth[0-9]" ); | ||
12 | QCheckListItem * CLI; | ||
13 | |||
14 | LanCards_LV->header()->hide(); | ||
15 | |||
16 | // populate with all lancards in system | ||
17 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
18 | It.current(); | ||
19 | ++It ) { | ||
20 | if( R.match( It.current()->Name ) >= 0 && | ||
21 | It.current()->CardType == ARPHRD_ETHER | ||
22 | ) { | ||
23 | CLI = new QCheckListItem( LanCards_LV, It.current()->Name, | ||
24 | QCheckListItem::CheckBox ); | ||
25 | CLI->setText( 1, It.current()->MACAddress ); | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | QString LanCardEdit::acceptable( void ) { | ||
31 | return QString(); | ||
32 | } | ||
33 | |||
34 | |||
35 | bool LanCardEdit::commit( LanCardData & Data ) { | ||
36 | bool SM = 0; | ||
37 | CBM( Data.AnyLanCard, AnyCard_CB, SM ); | ||
38 | |||
39 | if( ! Data.AnyLanCard ) { | ||
40 | // collect set of lancards that match | ||
41 | int idx; | ||
42 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); | ||
43 | while( CLI ) { | ||
44 | idx = Data.HWAddresses.findIndex(CLI->text(1)); | ||
45 | if( CLI->isOn() ) { | ||
46 | if( idx < 0 ) { | ||
47 | // should be in list | ||
48 | Data.HWAddresses.append( CLI->text(1) ); | ||
49 | SM = 1; | ||
50 | } | ||
51 | } else { | ||
52 | // should not be in list | ||
53 | if( idx >= 0 ) { | ||
54 | Data.HWAddresses.remove( Data.HWAddresses.at(idx) ); | ||
55 | SM = 1; | ||
56 | } | ||
57 | } | ||
58 | CLI = (QCheckListItem *)CLI->nextSibling(); | ||
59 | } | ||
60 | } | ||
61 | return SM || ContainedObsoleteMAC ; | ||
62 | } | ||
63 | |||
64 | void LanCardEdit::showData( LanCardData & Data ) { | ||
65 | AnyCard_CB->setChecked( Data.AnyLanCard ); | ||
66 | |||
67 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); | ||
68 | |||
69 | ContainedObsoleteMAC = 0; | ||
70 | // remove obsolete address | ||
71 | for( QStringList::Iterator it=Data.HWAddresses.begin(); | ||
72 | it != Data.HWAddresses.end(); | ||
73 | ) { | ||
74 | CLI = (QCheckListItem *)LanCards_LV->firstChild(); | ||
75 | while( CLI ) { | ||
76 | if( CLI->text(1) == (*it) ) | ||
77 | // still valid | ||
78 | break; | ||
79 | CLI = (QCheckListItem *)CLI->nextSibling(); | ||
80 | } | ||
81 | if( CLI == 0 ) { | ||
82 | // address not found -> remove | ||
83 | ContainedObsoleteMAC = 1; | ||
84 | Data.HWAddresses.remove( it ); | ||
85 | } else { | ||
86 | ++ it; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | // set checks | ||
91 | while( CLI ) { | ||
92 | CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 ); | ||
93 | CLI = (QCheckListItem *)CLI->nextSibling(); | ||
94 | } | ||
95 | } | ||
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 @@ | |||
1 | #include "lancarddata.h" | ||
2 | #include "lancardGUI.h" | ||
3 | |||
4 | class LanCardEdit : public LanCardGUI { | ||
5 | |||
6 | public : | ||
7 | |||
8 | LanCardEdit( QWidget * parent ); | ||
9 | QString acceptable( void ); | ||
10 | bool commit( LanCardData & Data ); | ||
11 | void showData( LanCardData & Data ); | ||
12 | |||
13 | private : | ||
14 | |||
15 | bool ContainedObsoleteMAC; | ||
16 | }; | ||
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 @@ | |||
1 | #include <qfile.h> | ||
2 | #include <qtextstream.h> | ||
3 | #include <resources.h> | ||
4 | #include "lancardrun.h" | ||
5 | |||
6 | void LanCardRun::detectState( NodeCollection * NC ) { | ||
7 | |||
8 | // unavailable : no card found | ||
9 | // available : card found and assigned to us or free | ||
10 | // up : card found and assigned to us and up | ||
11 | |||
12 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); | ||
13 | System & Sys = NSResources->system(); | ||
14 | InterfaceInfo * Run; | ||
15 | |||
16 | QFile F( S ); | ||
17 | |||
18 | if( F.open( IO_ReadOnly ) ) { | ||
19 | // could open file -> read interface and assign | ||
20 | QString X; | ||
21 | QTextStream TS(&F); | ||
22 | X = TS.readLine(); | ||
23 | // find interface | ||
24 | if( handlesInterface( X ) ) { | ||
25 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | ||
26 | It.current(); | ||
27 | ++It ) { | ||
28 | Run = It.current(); | ||
29 | if( X == Run->Name ) { | ||
30 | Run->assignNode( netNode() ); | ||
31 | assignInterface( Run ); | ||
32 | NC->setCurrentState( IsUp ); | ||
33 | return; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
39 | // we are certainly not UP | ||
40 | assignInterface( 0 ); | ||
41 | |||
42 | // find possible interface | ||
43 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | ||
44 | It.current(); | ||
45 | ++It ) { | ||
46 | Run = It.current(); | ||
47 | if( handlesInterface( Run->Name ) && | ||
48 | Run->CardType == ARPHRD_ETHER && | ||
49 | ! Run->IsUp | ||
50 | ) { | ||
51 | // proper type, and Not UP -> free | ||
52 | NC->setCurrentState( Off ); | ||
53 | return; | ||
54 | } | ||
55 | } | ||
56 | // no free found | ||
57 | |||
58 | NC->setCurrentState( Unavailable ); | ||
59 | |||
60 | } | ||
61 | |||
62 | bool LanCardRun::setState( NodeCollection * NC, Action_t A ) { | ||
63 | |||
64 | // we only handle activate and deactivate | ||
65 | switch( A ) { | ||
66 | case Activate : | ||
67 | { | ||
68 | if( NC->currentState() != Off ) { | ||
69 | return 0; | ||
70 | } | ||
71 | InterfaceInfo * N = getInterface(); | ||
72 | if( ! N ) { | ||
73 | // no interface available | ||
74 | NC->setCurrentState( Unavailable ); | ||
75 | return 0; | ||
76 | } | ||
77 | // because we were OFF the interface | ||
78 | // we get back is NOT assigned | ||
79 | N->assignNode( netNode() ); | ||
80 | assignInterface( N ); | ||
81 | NC->setCurrentState( Available ); | ||
82 | return 1; | ||
83 | } | ||
84 | case Deactivate : | ||
85 | if( NC->currentState() == IsUp ) { | ||
86 | // bring down first | ||
87 | if( ! connection()->setState( Down ) ) | ||
88 | // could not ... | ||
89 | return 0; | ||
90 | } | ||
91 | if( NC->currentState() != Available ) { | ||
92 | return 1; | ||
93 | } | ||
94 | assignedInterface()->assignNode( 0 ); // release | ||
95 | assignInterface( 0 ); | ||
96 | NC->setCurrentState( Off ); | ||
97 | return 1; | ||
98 | default : | ||
99 | // FT | ||
100 | break; | ||
101 | } | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | bool LanCardRun::canSetState( State_t Curr, Action_t A ) { | ||
106 | // we only handle up down activate and deactivate | ||
107 | switch( A ) { | ||
108 | case Activate : | ||
109 | { // at least available | ||
110 | if( Curr == Available ) { | ||
111 | return 1; | ||
112 | } | ||
113 | // or we can make one available | ||
114 | InterfaceInfo * N = getInterface(); | ||
115 | if( ! N || N->assignedNode() != 0 ) { | ||
116 | // non available or assigned | ||
117 | return 0; | ||
118 | } | ||
119 | return 1; | ||
120 | } | ||
121 | case Deactivate : | ||
122 | return ( Curr >= Available ); | ||
123 | default : | ||
124 | // FT | ||
125 | break; | ||
126 | } | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | // get interface that is free or assigned to us | ||
131 | InterfaceInfo * LanCardRun::getInterface( void ) { | ||
132 | |||
133 | System & S = NSResources->system(); | ||
134 | InterfaceInfo * best = 0, * Run; | ||
135 | |||
136 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
137 | It.current(); | ||
138 | ++It ) { | ||
139 | Run = It.current(); | ||
140 | if( handlesInterface( Run->Name ) && | ||
141 | Run->CardType == ARPHRD_ETHER | ||
142 | ) { | ||
143 | // this is a LAN card | ||
144 | if( Run->assignedNode() == netNode() ) { | ||
145 | // assigned to us | ||
146 | return Run; | ||
147 | } else if( Run->assignedNode() == 0 ) { | ||
148 | // free | ||
149 | best = Run; | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | return best; // can be 0 | ||
154 | } | ||
155 | |||
156 | bool LanCardRun::handlesInterface( const QString & S ) { | ||
157 | return Pat.match( S ) >= 0; | ||
158 | } | ||
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 @@ | |||
1 | #ifndef LANCARDRUN_H | ||
2 | #define LANCARDRUN_H | ||
3 | |||
4 | #include <asdevice.h> | ||
5 | #include <qregexp.h> | ||
6 | #include "lancarddata.h" | ||
7 | |||
8 | class LanCardRun : public AsDevice { | ||
9 | |||
10 | public : | ||
11 | |||
12 | LanCardRun( ANetNodeInstance * NNI, | ||
13 | LanCardData & Data ) : AsDevice( NNI ), | ||
14 | Pat( "eth[0-9]" ) | ||
15 | { } | ||
16 | |||
17 | virtual long count( void ) | ||
18 | { return 2; } | ||
19 | virtual QString genNic( long nr ) | ||
20 | { QString S; return S.sprintf( "eth%ld", nr ); } | ||
21 | virtual AsDevice * device( void ) | ||
22 | { return asDevice(); } | ||
23 | |||
24 | protected : | ||
25 | |||
26 | void detectState( NodeCollection * NC ); | ||
27 | bool setState( NodeCollection * NC, Action_t A ); | ||
28 | bool canSetState( State_t Curr, Action_t A ); | ||
29 | |||
30 | bool handlesInterface( const QString & I ); | ||
31 | |||
32 | private : | ||
33 | |||
34 | InterfaceInfo * getInterface( void ); | ||
35 | QRegExp Pat; | ||
36 | |||
37 | }; | ||
38 | #endif | ||