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 | |||
@@ -10,6 +10,7 @@ | |||
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 |
15 | class AsDevice; | 16 | class AsDevice; |
@@ -26,6 +27,7 @@ class NodeCollection; | |||
26 | class QTextStream; | 27 | class QTextStream; |
27 | class RuntimeInfo; | 28 | class RuntimeInfo; |
28 | class InterfaceInfo; | 29 | class InterfaceInfo; |
30 | class NSResources; | ||
29 | 31 | ||
30 | extern QString & deQuote( QString & X ); | 32 | extern QString & deQuote( QString & X ); |
31 | extern QString quote( QString X ); | 33 | extern QString quote( QString X ); |
@@ -55,17 +57,17 @@ typedef enum State { | |||
55 | } State_t; | 57 | } State_t; |
56 | 58 | ||
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 |
70 | } Action_t; | 72 | } Action_t; |
71 | 73 | ||
@@ -90,8 +92,7 @@ public: | |||
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 ) ; |
@@ -110,27 +111,38 @@ public: | |||
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 ) |
@@ -141,9 +153,10 @@ public: | |||
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 | // |
@@ -160,8 +173,10 @@ public: | |||
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 | ||
167 | protected : | 182 | protected : |
@@ -224,7 +239,7 @@ public: | |||
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 ) |
@@ -244,32 +259,28 @@ public: | |||
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 |
@@ -323,33 +334,118 @@ public : | |||
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 | ||
354 | signals : | 450 | signals : |
355 | 451 | ||
@@ -358,6 +454,11 @@ signals : | |||
358 | 454 | ||
359 | protected : | 455 | 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 |
362 | ANetNodeInstance * NNI; | 463 | ANetNodeInstance * NNI; |
363 | }; | 464 | }; |
@@ -392,29 +493,33 @@ public : | |||
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 ); |
@@ -424,10 +529,7 @@ public : | |||
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 | ||
@@ -456,16 +558,14 @@ public : | |||
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 ); } |
@@ -489,6 +589,8 @@ private : | |||
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 |