Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/netnode.h | 262 |
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 | |||
@@ -12,2 +12,3 @@ | |||
12 | #include <Utils.h> | 12 | #include <Utils.h> |
13 | #include <system.h> | ||
13 | 14 | ||
@@ -28,2 +29,3 @@ class RuntimeInfo; | |||
28 | class InterfaceInfo; | 29 | class InterfaceInfo; |
30 | class NSResources; | ||
29 | 31 | ||
@@ -57,13 +59,13 @@ typedef enum State { | |||
57 | typedef enum Action { | 59 | typedef 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 |
@@ -92,4 +94,3 @@ public: | |||
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 | ||
@@ -112,18 +113,30 @@ public: | |||
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 * , |
@@ -132,3 +145,2 @@ public: | |||
132 | 145 | ||
133 | |||
134 | // generate NIC name based on instance nr | 146 | // generate NIC name based on instance nr |
@@ -143,5 +155,6 @@ public: | |||
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 | ||
@@ -162,4 +175,6 @@ public: | |||
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; |
@@ -226,3 +241,3 @@ public: | |||
226 | 241 | ||
227 | inline const char * provides( void ) | 242 | inline const char ** provides( void ) |
228 | { return NodeType->provides(); } | 243 | { return NodeType->provides(); } |
@@ -246,3 +261,3 @@ public: | |||
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; } |
@@ -250,3 +265,3 @@ public: | |||
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 ); } |
@@ -256,8 +271,6 @@ public: | |||
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 | } |
@@ -266,8 +279,6 @@ public: | |||
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 | } |
@@ -325,11 +336,16 @@ public : | |||
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 | ||
@@ -337,17 +353,97 @@ public : | |||
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 | ||
@@ -360,2 +456,7 @@ protected : | |||
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 |
@@ -394,25 +495,29 @@ public : | |||
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 |
@@ -426,6 +531,3 @@ public : | |||
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 | ||
@@ -458,12 +560,10 @@ public : | |||
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 | ||
@@ -491,2 +591,4 @@ private : | |||
491 | 591 | ||
592 | InterfaceInfo * AssignedInterface; | ||
593 | |||
492 | }; | 594 | }; |