summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/netnode.h
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.h') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.h262
1 files changed, 182 insertions, 80 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h
index d3d7b34..4626381 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.h
+++ b/noncore/settings/networksettings2/networksettings2/netnode.h
@@ -7,12 +7,13 @@
7#include <qpixmap.h> 7#include <qpixmap.h>
8#include <qstringlist.h> 8#include <qstringlist.h>
9#include <qobject.h> 9#include <qobject.h>
10#include <time.h> 10#include <time.h>
11 11
12#include <Utils.h> 12#include <Utils.h>
13#include <system.h>
13 14
14// difference feature interfaces 15// difference feature interfaces
15class AsDevice; 16class AsDevice;
16class AsLine; 17class AsLine;
17class AsConnection; 18class AsConnection;
18class AsFullSetup; 19class AsFullSetup;
@@ -23,12 +24,13 @@ class AsFullSetup;
23class ANetNode; 24class ANetNode;
24class ANetNodeInstance; 25class ANetNodeInstance;
25class NodeCollection; 26class NodeCollection;
26class QTextStream; 27class QTextStream;
27class RuntimeInfo; 28class RuntimeInfo;
28class InterfaceInfo; 29class InterfaceInfo;
30class NSResources;
29 31
30extern QString & deQuote( QString & X ); 32extern QString & deQuote( QString & X );
31extern QString quote( QString X ); 33extern QString quote( QString X );
32 34
33#include "systemfile.h" 35#include "systemfile.h"
34 36
@@ -52,23 +54,23 @@ typedef enum State {
52 Available = 5, 54 Available = 5,
53 // if connection is being used 55 // if connection is being used
54 IsUp = 6 56 IsUp = 6
55} State_t; 57} State_t;
56 58
57typedef enum Action { 59typedef enum Action {
58 // to make the device unavailable functionally 60 // to make the device unavailable functionally -> to disabled
59 Disable = 0, 61 Disable = 0,
60 // to make the device available functionally 62 // to make the device available functionally -> to off
61 Enable = 1, 63 Enable = 1,
62 // bring the hardware up 64 // bring the hardware up -> to Available
63 Activate = 2, 65 Activate = 2,
64 // bring the hardware down 66 // bring the hardware down -> to off
65 Deactivate = 3, 67 Deactivate = 3,
66 // bring the connection up 68 // bring the connection up -> to IsUp
67 Up = 4, 69 Up = 4,
68 // bring the connection down 70 // bring the connection down -> to Available
69 Down = 5 71 Down = 5
70} Action_t; 72} Action_t;
71 73
72class ANetNode : public QObject{ 74class ANetNode : public QObject{
73 75
74public: 76public:
@@ -87,14 +89,13 @@ public:
87 inline int done( void ) 89 inline int done( void )
88 { return Done; } 90 { return Done; }
89 inline void setDone( int D ) 91 inline void setDone( int D )
90 { Done = D; } 92 { Done = D; }
91 93
92 // does this Node provide a Connection 94 // does this Node provide a Connection
93 inline bool isToplevel( void ) 95 bool isToplevel( void );
94 { return strcmp( provides(), "fullsetup") == 0 ; }
95 96
96 // set the value of an attribute 97 // set the value of an attribute
97 void setAttribute( QString & Attr, QString & Value ) ; 98 void setAttribute( QString & Attr, QString & Value ) ;
98 void saveAttributes( QTextStream & TS ) ; 99 void saveAttributes( QTextStream & TS ) ;
99 100
100 // compiled references to 'needed' NetNodes -> needs list 101 // compiled references to 'needed' NetNodes -> needs list
@@ -107,46 +108,58 @@ public:
107 // 108 //
108 // Virtual methods with sensible default 109 // Virtual methods with sensible default
109 // 110 //
110 // 111 //
111 112
112 // do instances of this noce class have data for this file 113 // do instances of this noce class have data for this file
113 virtual bool hasDataForFile( const QString & ) 114 virtual bool hasDataForFile( SystemFile & )
114 { return 0; } 115 { return 0; }
115 116
117 // open proper file SF identified by S
118 // this method is called by NS2.
119 //
120 // overrule this ONLY if this proper file is a common file
121 // for all NNI of this node class and the data generated
122 // by each of the NNI needs to be put in one file
123 //
124 // if this is the case the file should be (re)opened in append
125 // return 0 if file cannot be opened
126 virtual bool openFile( SystemFile &SF,
127 ANetNodeInstance * NNI );
128
116 // generate instance independent stuff 129 // generate instance independent stuff
117 // 0 : data output, 1 no data, 2 error 130 // 0 : data output, 1 no data, 2 error
118 virtual short generateFile( const QString & , 131 virtual short generatePreamble( SystemFile & )
119 const QString & , 132 { return 1; }
120 QTextStream & , 133
121 long ) 134 // generate instance independent stuff
135 // 0 : data output, 1 no data, 2 error
136 virtual short generatePostamble( SystemFile & )
122 { return 1; } 137 { return 1; }
123 138
124 // generate instance dependent but profile common stuff 139 // generate instance dependent but instance common stuff
125 // 0 : data output, 1 no data, 2 error 140 // 0 : data output, 1 no data, 2 error
126 virtual short generateFile( const QString & , 141 virtual short generateFile( SystemFile &,
127 const QString & ,
128 QTextStream & ,
129 ANetNodeInstance * , 142 ANetNodeInstance * ,
130 long ) 143 long )
131 { return 1; } 144 { return 1; }
132 145
133
134 // generate NIC name based on instance nr 146 // generate NIC name based on instance nr
135 // only relevant if node instances are devices 147 // only relevant if node instances are devices
136 virtual QString genNic( long ) 148 virtual QString genNic( long )
137 { return QString(""); } 149 { return QString(""); }
138 150
139 // max number of instances for this node type 151 // max number of instances for this node type
140 // only relevant if node instances are devices 152 // only relevant if node instances are devices
141 virtual long instanceCount( void ) 153 virtual long instanceCount( void )
142 { return 1; } 154 { return 1; }
143 155
144 // return list of files that are specific for this node class 156 // return ID list for each file generated specially for
145 virtual QStringList * properFiles( void ) 157 // this node type
146 { return 0; } 158 virtual QStringList properFiles( void )
159 { return QStringList(); }
147 160
148 // 161 //
149 // 162 //
150 // pure virtual methods with sensible default 163 // pure virtual methods with sensible default
151 // 164 //
152 // 165 //
@@ -157,14 +170,16 @@ public:
157 // description for this NetNode 170 // description for this NetNode
158 virtual const QString nodeDescription() = 0; 171 virtual const QString nodeDescription() = 0;
159 172
160 // create a blank instance of a net node 173 // create a blank instance of a net node
161 virtual ANetNodeInstance * createInstance( void ) = 0; 174 virtual ANetNodeInstance * createInstance( void ) = 0;
162 175
163 // return feature this NetNode provides 176 // return features this NetNode provides
164 virtual const char * provides( void ) = 0; 177 virtual const char ** provides( void ) = 0;
178
179 // return features this NetNode needs
165 virtual const char ** needs( void ) = 0; 180 virtual const char ** needs( void ) = 0;
166 181
167protected : 182protected :
168 183
169 NetNodeList * Alternatives; 184 NetNodeList * Alternatives;
170 185
@@ -221,13 +236,13 @@ public:
221 { Description = S; } 236 { Description = S; }
222 237
223 // pixmap for this instance -> from NetNode 238 // pixmap for this instance -> from NetNode
224 inline const QString pixmapName( void ) 239 inline const QString pixmapName( void )
225 { return NodeType->pixmapName(); } 240 { return NodeType->pixmapName(); }
226 241
227 inline const char * provides( void ) 242 inline const char ** provides( void )
228 { return NodeType->provides(); } 243 { return NodeType->provides(); }
229 244
230 inline const char ** needs( void ) 245 inline const char ** needs( void )
231 { return NodeType->needs(); } 246 { return NodeType->needs(); }
232 247
233 inline void setConnection( NodeCollection * NC ) 248 inline void setConnection( NodeCollection * NC )
@@ -241,38 +256,34 @@ public:
241 // 256 //
242 // 257 //
243 258
244 259
245 260
246 // open proper file identified by S 261 // open proper file identified by S
247 virtual QFile * openFile( const QString & ) 262 virtual bool openFile( SystemFile & )
248 { return 0; } 263 { return 0; }
249 264
250 // check if this node (or sub nodes) have data for this file 265 // check if this node (or sub nodes) have data for this file
251 virtual bool hasDataForFile( const QString & S ) 266 virtual bool hasDataForFile( SystemFile & S )
252 { return nodeClass()->hasDataForFile( S ); } 267 { return nodeClass()->hasDataForFile( S ); }
253 268
254 // generate code specific for this node but embedded 269 // generate code specific for this node but embedded
255 // in the section of the parent 270 // in the section of the parent
256 // this is called within the code of the parent 271 // this is called within the code of the parent
257 virtual short generateFileEmbedded( const QString & ID, 272 virtual short generateFileEmbedded( SystemFile & SF,
258 const QString & Path,
259 QTextStream & TS,
260 long DevNr ) 273 long DevNr )
261 { ANetNodeInstance * NNI = nextNode(); 274 { ANetNodeInstance * NNI = nextNode();
262 return (NNI) ? NNI->generateFileEmbedded( ID, Path, TS, DevNr ) : 1; 275 return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1;
263 } 276 }
264 277
265 // generate code specific for this node 278 // generate code specific for this node
266 // (or find the first node that does) 279 // (or find the first node that does)
267 virtual short generateFile( const QString & ID, 280 virtual short generateFile( SystemFile & SF,
268 const QString & Path,
269 QTextStream & TS,
270 long DevNr ) 281 long DevNr )
271 { ANetNodeInstance * NNI = nextNode(); 282 { ANetNodeInstance * NNI = nextNode();
272 return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1; 283 return (NNI) ? NNI->generateFile( SF, DevNr ) : 1;
273 } 284 }
274 285
275 // return true if this node instance is triggered by this trigger 286 // return true if this node instance is triggered by this trigger
276 // could be delegated to deeper instances 287 // could be delegated to deeper instances
277 virtual bool triggeredBy( const QString & ) 288 virtual bool triggeredBy( const QString & )
278 { return 0; } 289 { return 0; }
@@ -320,47 +331,137 @@ class RuntimeInfo : public QObject {
320 331
321public : 332public :
322 333
323 RuntimeInfo( ANetNodeInstance * TheNNI ) 334 RuntimeInfo( ANetNodeInstance * TheNNI )
324 { NNI = TheNNI; } 335 { NNI = TheNNI; }
325 336
326 // downcast implemented by specify runtime classes 337 //
327 virtual AsDevice * asDevice( void ) 338 //
328 { return 0; } 339 // methods to be overloaded by connection capable
329 virtual AsConnection * asConnection( void ) 340 // runtimes
330 { return 0; } 341 //
331 virtual AsLine * asLine( void ) 342 //
332 { return 0; } 343
333 virtual AsFullSetup * asFullSetup( void ) 344
334 { return 0; } 345 //
346 //
347 // methods to be overloaded by device capable
348 // runtimes
349 //
350 //
335 351
336 // does this node handles this interface e.g.eth0 352 // does this node handles this interface e.g.eth0
337 // recurse deeper if this node cannot answer that question 353 // recurse deeper if this node cannot answer that question
338 virtual bool handlesInterface( const QString & ) 354 virtual bool handlesInterface( const QString & S ) {
339 { return 0; } 355 RuntimeInfo * RI = device();
340 virtual bool handlesInterface( const InterfaceInfo & ) 356 if( RI ) {
341 { return 0; } 357 return RI->handlesInterface( S );
342 virtual InterfaceInfo * assignedInterface( void ); 358 }
343 virtual AsDevice * device( void ); 359 return 0;
360 }
361 bool handlesInterface( const InterfaceInfo & I ) {
362 RuntimeInfo * RI = device();
363 if( RI ) {
364 return RI->handlesInterface( I );
365 }
366 return 0;
367 }
344 368
345 ANetNodeInstance * netNode() 369 //
370 //
371 // methods to be overloaded by full setup capable
372 // runtimes
373 //
374 //
375
376 // return description for this full setup
377 virtual const QString & description( void ) {
378 return fullSetup()->description( );
379 }
380 // return triggers that should fire when this
381 // setup is brought up
382 virtual const QStringList & triggers( void ) {
383 return fullSetup()->triggers( );
384 }
385
386 //
387 //
388 // methods to be overloaded by line capable
389 // runtimes
390 //
391 //
392
393 // return the device file ('/dev/xxx') created
394 // by this line capable runtime
395 virtual QString deviceFile( void ) {
396 RuntimeInfo * RI = line();
397 if( RI ) {
398 return RI->deviceFile();
399 }
400 return QString();
401 }
402
403 //
404 //
405 // runtime interface
406 //
407 //
408
409 // return the node that offers device capability
410 virtual RuntimeInfo * device( void )
411 { RuntimeInfo * RI = nextNode();
412 return (RI) ? RI->device() : 0;
413 }
414
415 // return the node that offers connection capability
416 virtual RuntimeInfo * connection( void )
417 { RuntimeInfo * RI = nextNode();
418 return (RI) ? RI->connection() : 0;
419 }
420
421 // return the node that offers line capability
422 virtual RuntimeInfo * line( void )
423 { RuntimeInfo * RI = nextNode();
424 return (RI) ? RI->line() : 0;
425 }
426
427 // return the node that offers full setup capability
428 virtual RuntimeInfo * fullSetup( void )
429 { RuntimeInfo * RI = nextNode();
430 return (RI) ? RI->fullSetup() : 0;
431 }
432
433 inline ANetNodeInstance * netNode()
346 { return NNI; } 434 { return NNI; }
347 NodeCollection * connection() 435
436 inline NodeCollection * nodeCollection()
348 { return NNI->connection(); } 437 { return NNI->connection(); }
349 438
350 virtual void detectState( NodeCollection * NC ) = 0; 439 virtual State_t detectState( void ) = 0;
351 virtual bool setState( NodeCollection * NC, Action_t A, bool Force = 0 ) = 0; 440 // public API to set the state
352 virtual bool canSetState( State_t Curr, Action_t A ) = 0; 441 virtual QString setState( NodeCollection * NC,
442 Action_t A,
443 bool Force = 0 );
444
445 inline RuntimeInfo * nextNode( void ) {
446 ANetNodeInstance * NNI = netNode()->nextNode();
447 return (NNI) ? NNI->runtime() : 0;
448 }
353 449
354signals : 450signals :
355 451
356 // sent by device if state changes 452 // sent by device if state changes
357 void stateChanged( State_t S, ANetNodeInstance * NNI ); 453 void stateChanged( State_t S, ANetNodeInstance * NNI );
358 454
359protected : 455protected :
360 456
457 // set state of this node (private API)
458 virtual QString setMyState( NodeCollection * NC,
459 Action_t A,
460 bool Force = 0 ) = 0;
461
361 // connection this runtime info belongs to 462 // connection this runtime info belongs to
362 ANetNodeInstance * NNI; 463 ANetNodeInstance * NNI;
363}; 464};
364 465
365class NodeCollection : public QList<ANetNodeInstance> { 466class NodeCollection : public QList<ANetNodeInstance> {
366 467
@@ -389,48 +490,49 @@ public :
389 { IsModified = N ; } 490 { IsModified = N ; }
390 491
391 inline bool handlesInterface( const QString & S ) { 492 inline bool handlesInterface( const QString & S ) {
392 return getToplevel()->runtime()->handlesInterface( S ); 493 return getToplevel()->runtime()->handlesInterface( S );
393 } 494 }
394 495
496 // return the interface in the OS that is assigned to
497 // this device
395 inline InterfaceInfo * assignedInterface( void ) { 498 inline InterfaceInfo * assignedInterface( void ) {
396 return getToplevel()->runtime()->assignedInterface(); 499 return AssignedInterface;
397 } 500 }
398 501
399 inline AsDevice * device() { 502 // assign the interface to this device
400 return getToplevel()->runtime()->device(); 503 inline void assignInterface( InterfaceInfo * NI ) {
504 if( NI == 0 ) {
505 if( AssignedInterface ) {
506 AssignedInterface->assignConnection( 0 );
401 } 507 }
402
403 bool triggersVPN();
404
405 inline State_t state( bool Update = 0 )
406 { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState,
407 Unchecked ));
408 if( CurrentState == Unchecked || Update ) {
409 Log(( "TL %p TLR %p\n",
410 getToplevel(),
411 getToplevel()->runtime() ));
412 // need to get current state
413 getToplevel()->runtime()->detectState( this );
414 } 508 }
415 return CurrentState; 509 AssignedInterface = NI;
510 if( AssignedInterface ) {
511 AssignedInterface->assignConnection( this );
512 }
416 } 513 }
417 514
515 inline RuntimeInfo * device() {
516 return getToplevel()->runtime()->device();
517 }
518
519 const QStringList & triggers();
520
521 State_t state( bool Update = 0 );
522
418 // get the ixmap for this device 523 // get the ixmap for this device
419 QPixmap devicePixmap( void ); 524 QPixmap devicePixmap( void );
420 QPixmap statePixmap( State_t S ); 525 QPixmap statePixmap( State_t S );
421 inline QPixmap statePixmap( bool Update = 0 ) 526 inline QPixmap statePixmap( bool Update = 0 )
422 { return statePixmap( state(Update) ); } 527 { return statePixmap( state(Update) ); }
423 QString stateName( State_t ); 528 QString stateName( State_t );
424 inline QString stateName( bool Update = 0 ) 529 inline QString stateName( bool Update = 0 )
425 { return stateName( state(Update) ); } 530 { return stateName( state(Update) ); }
426 531
427 inline bool setState( Action_t A, bool Force =0 ) 532 QString setState( Action_t A, bool Force = 0 );
428 { return getToplevel()->runtime()->setState( this, A, Force ); }
429 inline bool canSetState( Action_t A )
430 { return getToplevel()->runtime()->canSetState( CurrentState, A ); }
431 533
432 void save( QTextStream & TS ); 534 void save( QTextStream & TS );
433 535
434 void append( ANetNodeInstance * NNI ); 536 void append( ANetNodeInstance * NNI );
435 537
436 // makes sure that all items in the connection point to 538 // makes sure that all items in the connection point to
@@ -453,22 +555,20 @@ public :
453 { return CurrentState; } 555 { return CurrentState; }
454 inline void setCurrentState( State_t S ) 556 inline void setCurrentState( State_t S )
455 { CurrentState = S; } 557 { CurrentState = S; }
456 558
457 // return TRUE if this node can have data to be inserted in 559 // return TRUE if this node can have data to be inserted in
458 // file identified by S 560 // file identified by S
459 bool hasDataForFile( const QString & S ); 561 bool hasDataForFile( SystemFile & S );
460 ANetNodeInstance * firstWithDataForFile( const QString & S ); 562 ANetNodeInstance * firstWithDataForFile( SystemFile & );
461 563
462 // generate items for this file -> toplevel call 564 // generate items for this file -> toplevel call
463 short generateFile( const QString & FID, // identification of file 565 short generateFile( SystemFile & SF,
464 const QString & FName, // effective filename of file
465 QTextStream & TS, // stream to file
466 long DN // device number 566 long DN // device number
467 ) 567 )
468 { return getToplevel()->generateFile( FID, FName, TS, DN ); } 568 { return getToplevel()->generateFile( SF, DN ); }
469 569
470 bool triggeredBy( const QString & Trigger ) 570 bool triggeredBy( const QString & Trigger )
471 { return getToplevel()->triggeredBy( Trigger ); } 571 { return getToplevel()->triggeredBy( Trigger ); }
472 572
473private : 573private :
474 574
@@ -486,9 +586,11 @@ private :
486 bool IsNew; 586 bool IsNew;
487 // index in listbox 587 // index in listbox
488 int Index; 588 int Index;
489 bool IsModified; 589 bool IsModified;
490 int Done; 590 int Done;
491 591
592 InterfaceInfo * AssignedInterface;
593
492}; 594};
493 595
494#endif 596#endif