summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/usb/usbrun.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/usb/usbrun.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/usb/usbrun.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp
index beacd7b..b8ac8a8 100644
--- a/noncore/settings/networksettings2/usb/usbrun.cpp
+++ b/noncore/settings/networksettings2/usb/usbrun.cpp
@@ -3,107 +3,109 @@
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <resources.h> 4#include <resources.h>
5#include "usbrun.h" 5#include "usbrun.h"
6 6
7void USBRun::detectState( NodeCollection * NC ) { 7void USBRun::detectState( NodeCollection * NC ) {
8 // unavailable : no card found 8 // unavailable : no card found
9 // available : card found and assigned to us or free 9 // available : card found and assigned to us or free
10 // up : card found and assigned to us and up 10 // up : card found and assigned to us and up
11 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); 11 QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
12 System & Sys = NSResources->system(); 12 System & Sys = NSResources->system();
13 InterfaceInfo * Run; 13 InterfaceInfo * Run;
14 QFile F( S ); 14 QFile F( S );
15 Log(("Detecting for %s\n", NC->name().latin1() ));
15 16
16 if( F.open( IO_ReadOnly ) ) { 17 if( F.open( IO_ReadOnly ) ) {
17 // could open file -> read interface and assign 18 // could open file -> read interface and assign
18 QString X; 19 QString X;
19 QTextStream TS(&F); 20 QTextStream TS(&F);
20 X = TS.readLine(); 21 X = TS.readLine();
22 Log(("%s exists\n", S.latin1() ));
21 // find interface 23 // find interface
22 if( handlesInterface( X ) ) { 24 if( handlesInterface( X ) ) {
23 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 25 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
24 It.current(); 26 It.current();
25 ++It ) { 27 ++It ) {
26 Run = It.current(); 28 Run = It.current();
27 if( X == Run->Name ) { 29 if( X == Run->Name ) {
28 Run->assignNode( netNode() ); 30 Run->assignNode( netNode() );
29 assignInterface( Run ); 31 assignInterface( Run );
30 NC->setCurrentState( IsUp ); 32 NC->setCurrentState( IsUp );
31 return; 33 return;
32 } 34 }
33 } 35 }
34 } 36 }
35 } 37 }
36 38
37 fprintf( stderr, "Assigned %p\n", assignedInterface() ); 39 Log(("Assigned %p\n", assignedInterface() ));
38 if( ( Run = assignedInterface() ) ) { 40 if( ( Run = assignedInterface() ) ) {
39 // we already have an interface assigned -> still present ? 41 // we already have an interface assigned -> still present ?
40 if( ! Run->IsUp ) { 42 if( ! Run->IsUp ) {
41 // usb is still free -> keep assignment 43 // usb is still free -> keep assignment
42 NC->setCurrentState( Available ); 44 NC->setCurrentState( Available );
43 return; 45 return;
44 } // else interface is up but NOT us -> some other profile 46 } // else interface is up but NOT us -> some other profile
45 } 47 }
46 48
47 // nothing (valid) assigned to us 49 // nothing (valid) assigned to us
48 assignInterface( 0 ); 50 assignInterface( 0 );
49 51
50 // find possible interface 52 // find possible interface
51 for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); 53 for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
52 It.current(); 54 It.current();
53 ++It ) { 55 ++It ) {
54 Run = It.current(); 56 Run = It.current();
55 57
56 fprintf( stderr, "%s %d %d=%d %d\n", 58 Log(("%s %d %d=%d %d\n",
57 Run->Name.latin1(), 59 Run->Name.latin1(),
58 handlesInterface( Run->Name ), 60 handlesInterface( Run->Name ),
59 Run->CardType, ARPHRD_ETHER, 61 Run->CardType, ARPHRD_ETHER,
60 ! Run->IsUp ); 62 ! Run->IsUp ));
61 63
62 if( handlesInterface( Run->Name ) && 64 if( handlesInterface( Run->Name ) &&
63 Run->CardType == ARPHRD_ETHER && 65 Run->CardType == ARPHRD_ETHER &&
64 ! Run->IsUp 66 ! Run->IsUp
65 ) { 67 ) {
66 fprintf( stderr, "Released(OFF)\n" ); 68 Log(("Released(OFF)\n" ));
67 // proper type, and Not UP -> free 69 // proper type, and Not UP -> free
68 NC->setCurrentState( Off ); 70 NC->setCurrentState( Off );
69 return; 71 return;
70 } 72 }
71 } 73 }
72 // no free found 74 // no free found
73 fprintf( stderr, "UNA\n" ); 75 Log(("UNA\n" ));
74 76
75 NC->setCurrentState( Unavailable ); 77 NC->setCurrentState( Unavailable );
76} 78}
77 79
78bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) { 80bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) {
79 81
80 // we only handle activate and deactivate 82 // we only handle activate and deactivate
81 switch( A ) { 83 switch( A ) {
82 case Activate : 84 case Activate :
83 { 85 {
84 if( NC->currentState() != Off ) { 86 if( NC->currentState() != Off ) {
85 return 0; 87 return 0;
86 } 88 }
87 InterfaceInfo * N = getInterface(); 89 InterfaceInfo * N = getInterface();
88 if( ! N ) { 90 if( ! N ) {
89 // no interface available 91 // no interface available
90 NC->setCurrentState( Unavailable ); 92 NC->setCurrentState( Unavailable );
91 return 0; 93 return 0;
92 } 94 }
93 // because we were OFF the interface 95 // because we were OFF the interface
94 // we get back is NOT assigned 96 // we get back is NOT assigned
95 N->assignNode( netNode() ); 97 N->assignNode( netNode() );
96 assignInterface( N ); 98 assignInterface( N );
97 fprintf( stderr, "Assing %p\n", N ); 99 Log(("Assing %p\n", N ));
98 NC->setCurrentState( Available ); 100 NC->setCurrentState( Available );
99 return 1; 101 return 1;
100 } 102 }
101 case Deactivate : 103 case Deactivate :
102 if( NC->currentState() == IsUp ) { 104 if( NC->currentState() == IsUp ) {
103 // bring down first 105 // bring down first
104 if( ! connection()->setState( Down ) ) 106 if( ! connection()->setState( Down ) )
105 // could not ... 107 // could not ...
106 return 0; 108 return 0;
107 } else if( NC->currentState() != Available ) { 109 } else if( NC->currentState() != Available ) {
108 return 1; 110 return 1;
109 } 111 }