00001 #ifndef NETNODE_H
00002 #define NETNODE_H
00003
00004 #include <qtextstream.h>
00005 #include <qlist.h>
00006 #include <qdict.h>
00007 #include <qpixmap.h>
00008 #include <qstringlist.h>
00009 #include <qobject.h>
00010 #include <time.h>
00011
00012 #include <Utils.h>
00013 #include <system.h>
00014
00015
00016 class AsDevice;
00017 class AsLine;
00018 class AsNetworkSetup;
00019 class AsFullSetup;
00020
00021
00022 #include <qlist.h>
00023
00024 class ANetNode;
00025 class ANetNodeInstance;
00026 class NetworkSetup;
00027 class QTextStream;
00028 class RuntimeInfo;
00029 class InterfaceInfo;
00030 class NSResources;
00031
00032 extern QString & deQuote( QString & X );
00033 extern QString quote( QString X );
00034
00035 #include "systemfile.h"
00036
00037 typedef enum State {
00038
00039 Unchecked = 0,
00040
00041 Unknown = 1,
00042
00043
00044 Unavailable = 2,
00045
00046
00047
00048 Disabled = 3,
00049
00050
00051 Off = 4,
00052
00053
00054 Available = 5,
00055
00056 IsUp = 6
00057 } State_t;
00058
00059 typedef enum Action {
00060
00061 Disable = 0,
00062
00063 Enable = 1,
00064
00065 Activate = 2,
00066
00067 Deactivate = 3,
00068
00069 Up = 4,
00070
00071 Down = 5
00072 } Action_t;
00073
00074 class ANetNode : public QObject {
00075
00076 public:
00077
00078 typedef QArray<ANetNode *> NetNodeList;
00079
00080 ANetNode( const char * Name ) : QObject( 0, Name ) {}
00081 virtual ~ANetNode(){};
00082
00083
00084
00085
00086
00087
00088
00089 inline int done( void )
00090 { return Done; }
00091 inline void setDone( int D )
00092 { Done = D; }
00093
00094
00095 bool isToplevel( void );
00096
00097
00098 void setAttribute( QString & Attr, QString & Value ) ;
00099 void saveAttributes( QTextStream & TS ) ;
00100
00101
00102 inline void setAlternatives( NetNodeList * Alt )
00103 { Alternatives = Alt; }
00104 inline NetNodeList & alternatives( void )
00105 { return *Alternatives; }
00106
00107
00108
00109
00110
00111
00112
00113
00114 virtual bool hasDataForFile( SystemFile & )
00115 { return 0; }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 virtual bool openFile( SystemFile &SF,
00131 ANetNodeInstance * NNI,
00132 QStringList & PathToCreate );
00133
00134
00135
00136 virtual short generatePreamble( SystemFile & )
00137 { return 1; }
00138
00139
00140
00141 virtual short generatePostamble( SystemFile & )
00142 { return 1; }
00143
00144
00145
00146 virtual short generateFile( SystemFile &,
00147 ANetNodeInstance * ,
00148 long )
00149 { return 1; }
00150
00151
00152
00153 virtual QString genNic( long )
00154 { return QString(""); }
00155
00156
00157
00158 virtual long instanceCount( void )
00159 { return 1; }
00160
00161
00162
00163 virtual QStringList properFiles( void )
00164 { return QStringList(); }
00165
00166
00167
00168
00169
00170
00171
00172
00173 virtual const QString pixmapName() = 0;
00174
00175
00176 virtual const QString nodeDescription() = 0;
00177
00178
00179 virtual ANetNodeInstance * createInstance( void ) = 0;
00180
00181
00182 virtual const char ** provides( void ) = 0;
00183
00184
00185 virtual const char ** needs( void ) = 0;
00186
00187 protected :
00188
00189 NetNodeList * Alternatives;
00190
00191 private :
00192
00193 virtual void setSpecificAttribute( QString & , QString & ) = 0;
00194 virtual void saveSpecificAttribute( QTextStream & ) = 0;
00195 int Done;
00196
00197 };
00198
00199 class ANetNodeInstance : public QObject {
00200
00201 public:
00202
00203 ANetNodeInstance( ANetNode * NN ) : QObject()
00204 { IsModified=0; NodeType = NN; IsNew = TRUE; }
00205 virtual ~ANetNodeInstance( void ) { }
00206
00207 inline int done( void )
00208 { return Done; }
00209 inline void setDone( int D )
00210 { Done = D; }
00211
00212
00213 inline void setModified( bool M )
00214 { IsModified = M; }
00215 inline bool isModified( void )
00216 { return IsModified; }
00217
00218
00219 ANetNodeInstance * nextNode();
00220
00221 ANetNode * nodeClass( void )
00222 { return NodeType; }
00223
00224
00225 void initialize( void );
00226
00227
00228 void setAttribute( QString & Attr, QString & Value ) ;
00229 void saveAttributes( QTextStream & TS ) ;
00230
00231
00232 inline void setNew( bool IsN )
00233 { IsNew = IsN; }
00234 inline bool isNew( void )
00235 { return IsNew; }
00236
00237
00238 inline QString & description( void )
00239 { return Description; }
00240 inline void setDescription( const QString & S )
00241 { Description = S; }
00242
00243
00244 inline const QString pixmapName( void )
00245 { return NodeType->pixmapName(); }
00246
00247 inline const char ** provides( void )
00248 { return NodeType->provides(); }
00249
00250 inline const char ** needs( void )
00251 { return NodeType->needs(); }
00252
00253 inline void setNetworkSetup( NetworkSetup * NC )
00254 { TheNetworkSetup = NC; }
00255 inline NetworkSetup * networkSetup( void )
00256 { return TheNetworkSetup; }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 virtual bool openFile( SystemFile &,
00268 QStringList & )
00269 { return 0; }
00270
00271
00272 virtual bool hasDataForFile( SystemFile & S )
00273 { return nodeClass()->hasDataForFile( S ); }
00274
00275
00276
00277
00278 virtual short generateFileEmbedded( SystemFile & SF,
00279 long DevNr )
00280 { ANetNodeInstance * NNI = nextNode();
00281 return (NNI) ? NNI->generateFileEmbedded( SF, DevNr ) : 1;
00282 }
00283
00284
00285
00286 virtual short generateFile( SystemFile & SF,
00287 long DevNr )
00288 { ANetNodeInstance * NNI = nextNode();
00289 return (NNI) ? NNI->generateFile( SF, DevNr ) : 1;
00290 }
00291
00292
00293
00294 virtual bool triggeredBy( const QString & )
00295 { return 0; }
00296
00297
00298
00299
00300
00301
00302
00303
00304 virtual RuntimeInfo * runtime( void ) = 0;
00305
00306
00307 virtual QWidget * edit( QWidget * parent ) = 0;
00308
00309
00310 virtual QString acceptable( void ) = 0;
00311
00312
00313 virtual void commit( void ) = 0;
00314
00315
00316 virtual void * data( void ) = 0;
00317
00318 protected :
00319
00320 virtual void setSpecificAttribute( QString & , QString & ) = 0;
00321 virtual void saveSpecificAttribute( QTextStream & ) = 0;
00322
00323 ANetNode * NodeType;
00324
00325 NetworkSetup * TheNetworkSetup;
00326 QString Description;
00327 bool IsModified;
00328
00329
00330 bool IsNew;
00331 int Done;
00332
00333 static long InstanceCounter;
00334 };
00335
00336 class ErrorNNI: public ANetNodeInstance {
00337
00338 public:
00339
00340 ErrorNNI( const QString & _Name ) : ANetNodeInstance( 0 ) {
00341 setName( _Name.latin1() );
00342 }
00343
00344 RuntimeInfo * runtime( void ) {
00345 return 0;
00346 }
00347
00348
00349 QWidget * edit( QWidget * parent ) {
00350 return 0;
00351 }
00352
00353
00354 QString acceptable( void ) {
00355 return QString();
00356 }
00357
00358
00359 void commit( void ) {
00360 }
00361
00362
00363 void * data( void ) {
00364 return 0;
00365 }
00366
00367 protected :
00368
00369 void setSpecificAttribute( QString & , QString & ) {
00370 }
00371
00372 void saveSpecificAttribute( QTextStream & ) {
00373 }
00374 };
00375
00376 class RuntimeInfo : public QObject {
00377
00378 Q_OBJECT
00379
00380 public :
00381
00382 RuntimeInfo( ANetNodeInstance * TheNNI )
00383 { NNI = TheNNI; }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 virtual bool handlesInterface( const QString & S ) {
00403 RuntimeInfo * RI = device();
00404 if( RI ) {
00405 return RI->handlesInterface( S );
00406 }
00407 return 0;
00408 }
00409 bool handlesInterface( const InterfaceInfo & I ) {
00410 RuntimeInfo * RI = device();
00411 if( RI ) {
00412 return RI->handlesInterface( I );
00413 }
00414 return 0;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 virtual const QString & description( void ) {
00426 return fullSetup()->description( );
00427 }
00428
00429
00430 virtual const QStringList & triggers( void ) {
00431 return fullSetup()->triggers( );
00432 }
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 virtual QString deviceFile( void ) {
00444 RuntimeInfo * RI = line();
00445 if( RI ) {
00446 return RI->deviceFile();
00447 }
00448 return QString();
00449 }
00450
00451
00452
00453
00454
00455
00456
00457
00458 virtual RuntimeInfo * device( void )
00459 { RuntimeInfo * RI = nextNode();
00460 return (RI) ? RI->device() : 0;
00461 }
00462
00463
00464 virtual RuntimeInfo * connection( void )
00465 { RuntimeInfo * RI = nextNode();
00466 return (RI) ? RI->connection() : 0;
00467 }
00468
00469
00470 virtual RuntimeInfo * line( void )
00471 { RuntimeInfo * RI = nextNode();
00472 return (RI) ? RI->line() : 0;
00473 }
00474
00475
00476 virtual RuntimeInfo * fullSetup( void )
00477 { RuntimeInfo * RI = nextNode();
00478 return (RI) ? RI->fullSetup() : 0;
00479 }
00480
00481 inline ANetNodeInstance * netNode()
00482 { return NNI; }
00483
00484 inline NetworkSetup * networkSetup()
00485 { return NNI->networkSetup(); }
00486
00487 virtual State_t detectState( void ) = 0;
00488
00489 virtual QString setState( NetworkSetup * NC,
00490 Action_t A,
00491 bool Force = 0 );
00492
00493 inline RuntimeInfo * nextNode( void ) {
00494 ANetNodeInstance * NNI = netNode()->nextNode();
00495 return (NNI) ? NNI->runtime() : 0;
00496 }
00497
00498 signals :
00499
00500
00501 void stateChanged( State_t S, ANetNodeInstance * NNI );
00502
00503 protected :
00504
00505
00506 virtual QString setMyState( NetworkSetup * NC,
00507 Action_t A,
00508 bool Force = 0 ) = 0;
00509
00510
00511 ANetNodeInstance * NNI;
00512 };
00513
00514 class NetworkSetup : public QList<ANetNodeInstance> {
00515
00516 public :
00517
00518 NetworkSetup( void );
00519 NetworkSetup( QTextStream & TS, bool & Dangling );
00520 ~NetworkSetup( void );
00521
00522
00523 void copyFrom( const NetworkSetup & NC );
00524
00525 inline int done( void )
00526 { return Done; }
00527 inline void setDone( int D )
00528 { Done = D; }
00529
00530 inline int number( void )
00531 { return Number; }
00532 inline void setNumber( int i )
00533 { Number = i; }
00534 inline bool isNew( void )
00535 { return IsNew; }
00536 inline void setNew( bool N )
00537 { IsNew = N ; }
00538 inline bool isModified( void )
00539 { return IsModified; }
00540 inline void setModified( bool N )
00541 { IsModified = N ; }
00542
00543 inline bool handlesInterface( const QString & S ) {
00544 return getToplevel()->runtime()->handlesInterface( S );
00545 }
00546
00547
00548
00549 inline InterfaceInfo * assignedInterface( void ) {
00550 return AssignedInterface;
00551 }
00552
00553
00554 inline void assignInterface( InterfaceInfo * NI ) {
00555
00556 if( AssignedInterface ) {
00557 AssignedInterface->assignToNetworkSetup( 0 );
00558 }
00559 if( NI ) {
00560
00561 NI->assignToNetworkSetup( this );
00562 }
00563 AssignedInterface = NI;
00564 }
00565
00566 inline RuntimeInfo * device() {
00567 return getToplevel()->runtime()->device();
00568 }
00569
00570 const QStringList & triggers();
00571
00572 State_t state( bool Update = 0 );
00573
00574
00575 QPixmap devicePixmap( void );
00576 QPixmap statePixmap( State_t S );
00577 inline QPixmap statePixmap( bool Update = 0 )
00578 { return statePixmap( state(Update) ); }
00579 QString stateName( State_t );
00580 inline QString stateName( bool Update = 0 )
00581 { return stateName( state(Update) ); }
00582
00583 QString setState( Action_t A, bool Force = 0 );
00584
00585 void save( QTextStream & TS );
00586
00587 void append( ANetNodeInstance * NNI );
00588
00589
00590
00591 void reassign( void );
00592
00593 ANetNodeInstance * getToplevel( void );
00594 ANetNodeInstance * findNext( ANetNodeInstance * NNI );
00595 ANetNodeInstance * findByName( const QString & S );
00596
00597 inline const QString & name()
00598 { return Name; }
00599
00600 const QString & description( void );
00601
00602 inline void setName( const QString & N)
00603 { Name = N; }
00604
00605 inline State_t currentState( void )
00606 { return CurrentState; }
00607 inline void setCurrentState( State_t S )
00608 { CurrentState = S; }
00609
00610
00611
00612 bool hasDataForFile( SystemFile & S );
00613 ANetNodeInstance * firstWithDataForFile( SystemFile & );
00614
00615
00616 short generateFile( SystemFile & SF,
00617 long DN
00618 )
00619 { return getToplevel()->generateFile( SF, DN ); }
00620
00621 bool triggeredBy( const QString & Trigger )
00622 { return getToplevel()->triggeredBy( Trigger ); }
00623
00624 private :
00625
00626 int compareItems ( QCollection::Item item1,
00627 QCollection::Item item2 );
00628
00629 long Number;
00630
00631
00632 State_t CurrentState;
00633
00634 QString Name;
00635
00636
00637 bool IsNew;
00638
00639 int Index;
00640 bool IsModified;
00641 int Done;
00642
00643 InterfaceInfo * AssignedInterface;
00644
00645 };
00646
00647 #endif