Diffstat (limited to 'noncore/settings/networksettings2/networksettings2/netnode.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings2/netnode.h | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h new file mode 100644 index 0000000..0ecd64e --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/netnode.h | |||
@@ -0,0 +1,361 @@ | |||
1 | #ifndef NETNODE_H | ||
2 | #define NETNODE_H | ||
3 | |||
4 | #include <qtextstream.h> | ||
5 | #include <qlist.h> | ||
6 | #include <qpixmap.h> | ||
7 | #include <qobject.h> | ||
8 | #include <time.h> | ||
9 | |||
10 | // difference feature interfaces | ||
11 | class AsDevice; | ||
12 | class AsLine; | ||
13 | class AsConnection; | ||
14 | class AsFullSetup; | ||
15 | |||
16 | // needed for plugin creation function | ||
17 | #include <qlist.h> | ||
18 | |||
19 | class ANetNode; | ||
20 | class ANetNodeInstance; | ||
21 | class NodeCollection; | ||
22 | class QTextStream; | ||
23 | class RuntimeInfo; | ||
24 | class InterfaceInfo; | ||
25 | |||
26 | extern QString & deQuote( QString & X ); | ||
27 | extern QString quote( QString X ); | ||
28 | |||
29 | #include "systemfile.h" | ||
30 | |||
31 | typedef enum State { | ||
32 | // if we have not yet detected the state of the device | ||
33 | Unchecked = 0, | ||
34 | // if we cannot determine the state | ||
35 | Unknown = 1, | ||
36 | // if connection cannot be established e.g. because | ||
37 | // the hardware is not available | ||
38 | Unavailable = 2, | ||
39 | // if the connection cannot be establishec but NOT | ||
40 | // because it is physically impossible but because | ||
41 | // it has been disabled for FUNCTIONAL reasons | ||
42 | Disabled = 3, | ||
43 | // if connection is available to is currently down | ||
44 | // i.e. the corresponding hardware is not activated | ||
45 | Off = 4, | ||
46 | // if connection is available to be used (i.e. the | ||
47 | // devices if fully ready to be used | ||
48 | Available = 5, | ||
49 | // if connection is being used | ||
50 | IsUp = 6 | ||
51 | } State_t; | ||
52 | |||
53 | typedef enum Action { | ||
54 | // to make the device unavailable functionally | ||
55 | Disable = 0, | ||
56 | // to make the device available functionally | ||
57 | Enable = 1, | ||
58 | // bring the hardware up | ||
59 | Activate = 2, | ||
60 | // bring the hardware down | ||
61 | Deactivate = 3, | ||
62 | // bring the connection up | ||
63 | Up = 4, | ||
64 | // bring the connection down | ||
65 | Down = 5 | ||
66 | } Action_t; | ||
67 | |||
68 | class ANetNode : public QObject{ | ||
69 | |||
70 | public: | ||
71 | |||
72 | typedef QArray<ANetNode *> NetNodeList; | ||
73 | |||
74 | ANetNode(){}; | ||
75 | virtual ~ANetNode(){}; | ||
76 | |||
77 | // pixmap needed for this NetNode | ||
78 | virtual const QString pixmapName() = 0; | ||
79 | |||
80 | // name of this NetNode | ||
81 | virtual const QString nodeName() = 0; | ||
82 | |||
83 | // description for this NetNode | ||
84 | virtual const QString nodeDescription() = 0; | ||
85 | |||
86 | // create a blank instance of a net node | ||
87 | virtual ANetNodeInstance * createInstance( void ) = 0; | ||
88 | |||
89 | // return feature this NetNode provides | ||
90 | virtual const char * provides( void ) = 0; | ||
91 | virtual const char ** needs( void ) = 0; | ||
92 | |||
93 | // generate files specific for this node (if any) | ||
94 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; | ||
95 | // return TRUE if this node has data to be inserted in systemfile | ||
96 | // with name S | ||
97 | virtual bool hasDataFor( const QString & S ) = 0; | ||
98 | // generate data specific for the system file S | ||
99 | // called only IF data was needed | ||
100 | virtual bool generateDataForCommonFile( | ||
101 | SystemFile & SF, long DevNr, ANetNodeInstance * NNI ) = 0; | ||
102 | |||
103 | // does this Node provide a Connection | ||
104 | bool isToplevel( void ) | ||
105 | { return strcmp( provides(), "fullsetup") == 0 ; } | ||
106 | |||
107 | // compiled references to 'needed' NetNodes -> needs list | ||
108 | void setAlternatives( NetNodeList * Alt ) | ||
109 | { Alternatives = Alt; } | ||
110 | NetNodeList & alternatives( void ) | ||
111 | { return *Alternatives; } | ||
112 | |||
113 | protected : | ||
114 | |||
115 | NetNodeList * Alternatives; | ||
116 | |||
117 | private : | ||
118 | }; | ||
119 | |||
120 | class ANetNodeInstance : public QObject { | ||
121 | |||
122 | public: | ||
123 | |||
124 | ANetNodeInstance( ANetNode * NN ) : QObject() | ||
125 | { IsModified=0; NodeType = NN; IsNew = TRUE; } | ||
126 | virtual ~ANetNodeInstance( void ) { } | ||
127 | |||
128 | virtual RuntimeInfo * runtime( void ) = 0; | ||
129 | |||
130 | void setConnection( NodeCollection * NC ) | ||
131 | { Connection = NC; } | ||
132 | NodeCollection * connection( void ) | ||
133 | { return Connection; } | ||
134 | |||
135 | // create edit widget under parent | ||
136 | virtual QWidget * edit( QWidget * parent ) = 0; | ||
137 | // is given data acceptable | ||
138 | virtual QString acceptable( void ) = 0; | ||
139 | |||
140 | // return data was modified | ||
141 | void setModified( bool M ) | ||
142 | { IsModified = M; } | ||
143 | bool isModified( void ) | ||
144 | { return IsModified; } | ||
145 | |||
146 | // get data from GUI and store in node | ||
147 | virtual void commit( void ) = 0; | ||
148 | |||
149 | // get next node | ||
150 | ANetNodeInstance * nextNode(); | ||
151 | // return NetNode this is an instance of | ||
152 | ANetNode * netNode( void ) | ||
153 | { return NodeType; } | ||
154 | |||
155 | // intialize am instance of a net node | ||
156 | void initialize( void ); | ||
157 | |||
158 | // set the value of an attribute | ||
159 | void setAttribute( QString & Attr, QString & Value ) ; | ||
160 | void saveAttributes( QTextStream & TS ) ; | ||
161 | |||
162 | // return true if node isntance is NEW and not loaded | ||
163 | void setNew( bool IsN ) | ||
164 | { IsNew = IsN; } | ||
165 | bool isNew( void ) | ||
166 | { return IsNew; } | ||
167 | |||
168 | // return logical name of this instance | ||
169 | QString & nodeName( void ) | ||
170 | { return NodeName; } | ||
171 | void setNodeName( const QString & S ) | ||
172 | { NodeName = S; } | ||
173 | // return description for this instance | ||
174 | QString & description( void ) | ||
175 | { return Description; } | ||
176 | void setDescription( const QString & S ) | ||
177 | { Description = S; } | ||
178 | |||
179 | // pixmap for this instance -> from NetNode | ||
180 | const QString pixmapName( void ) | ||
181 | { return NodeType->pixmapName(); } | ||
182 | |||
183 | const char * provides( void ) | ||
184 | { return NodeType->provides(); } | ||
185 | |||
186 | const char ** needs( void ) | ||
187 | { return NodeType->needs(); } | ||
188 | |||
189 | // returns node specific data -> only useful for 'buddy' | ||
190 | virtual void * data( void ) = 0; | ||
191 | |||
192 | protected : | ||
193 | |||
194 | virtual void setSpecificAttribute( QString & , QString & ) = 0; | ||
195 | virtual void saveSpecificAttribute( QTextStream & ) = 0; | ||
196 | |||
197 | ANetNode * NodeType; | ||
198 | // connection to which this node belongs to | ||
199 | NodeCollection * Connection; | ||
200 | QString NodeName; | ||
201 | QString Description; | ||
202 | bool IsModified; | ||
203 | bool IsNew; | ||
204 | |||
205 | static long InstanceCounter; | ||
206 | }; | ||
207 | |||
208 | class RuntimeInfo : public QObject { | ||
209 | |||
210 | Q_OBJECT | ||
211 | |||
212 | public : | ||
213 | |||
214 | RuntimeInfo( ANetNodeInstance * TheNNI ) | ||
215 | { NNI = TheNNI; } | ||
216 | |||
217 | // downcast | ||
218 | AsDevice * asDevice( void ) | ||
219 | { return (AsDevice *)this; } | ||
220 | AsConnection * asConnection( void ) | ||
221 | { return (AsConnection *)this; } | ||
222 | AsLine * asLine( void ) | ||
223 | { return (AsLine *)this; } | ||
224 | AsFullSetup * asFullSetup( void ) | ||
225 | { return (AsFullSetup *)this; } | ||
226 | |||
227 | // does this node handles this interface e.g.eth0 | ||
228 | // recurse deeper if this node cannot answer that question | ||
229 | virtual bool handlesInterface( const QString & ) | ||
230 | { return 0; } | ||
231 | virtual InterfaceInfo * assignedInterface( void ); | ||
232 | virtual AsDevice * device( void ); | ||
233 | |||
234 | ANetNodeInstance * netNode() | ||
235 | { return NNI; } | ||
236 | NodeCollection * connection() | ||
237 | { return NNI->connection(); } | ||
238 | |||
239 | virtual void detectState( NodeCollection * NC ) = 0; | ||
240 | virtual bool setState( NodeCollection * NC, Action_t A ) = 0; | ||
241 | virtual bool canSetState( State_t Curr, Action_t A ) = 0; | ||
242 | |||
243 | signals : | ||
244 | |||
245 | // sent by device if state changes | ||
246 | void stateChanged( State_t S, ANetNodeInstance * NNI ); | ||
247 | |||
248 | protected : | ||
249 | |||
250 | // connection this runtime info belongs to | ||
251 | ANetNodeInstance * NNI; | ||
252 | }; | ||
253 | |||
254 | class NodeCollection : public QList<ANetNodeInstance> { | ||
255 | |||
256 | public : | ||
257 | |||
258 | NodeCollection( void ); | ||
259 | NodeCollection( QTextStream & TS ); | ||
260 | ~NodeCollection( void ); | ||
261 | |||
262 | int number( void ) | ||
263 | { return Number; } | ||
264 | void setNumber( int i ) | ||
265 | { Number = i; if( MaxNr < i ) MaxNr = i; } | ||
266 | bool isNew( void ) | ||
267 | { return IsNew; } | ||
268 | void setNew( bool N ) | ||
269 | { IsNew = N ; } | ||
270 | bool isModified( void ) | ||
271 | { return IsModified; } | ||
272 | void setModified( bool N ) | ||
273 | { IsModified = N ; } | ||
274 | |||
275 | bool handlesInterface( const QString & S ) { | ||
276 | return getToplevel()->runtime()->handlesInterface( S ); | ||
277 | } | ||
278 | |||
279 | InterfaceInfo * assignedInterface( void ) { | ||
280 | return getToplevel()->runtime()->assignedInterface(); | ||
281 | } | ||
282 | |||
283 | AsDevice * device() { | ||
284 | return getToplevel()->runtime()->device(); | ||
285 | } | ||
286 | |||
287 | State_t state( bool Update = 0 ) | ||
288 | { if( CurrentState == Unchecked || Update ) { | ||
289 | // need to get current state | ||
290 | getToplevel()->runtime()->detectState( this ); | ||
291 | } | ||
292 | return CurrentState; | ||
293 | } | ||
294 | |||
295 | // get the ixmap for this device | ||
296 | QPixmap devicePixmap( void ); | ||
297 | QPixmap statePixmap( State_t S ); | ||
298 | QPixmap statePixmap( bool Update = 0 ) | ||
299 | { return statePixmap( state(Update) ); } | ||
300 | QString stateName( State_t ); | ||
301 | QString stateName( bool Update = 0 ) | ||
302 | { return stateName( state(Update) ); } | ||
303 | |||
304 | bool setState( Action_t A ) | ||
305 | { return getToplevel()->runtime()->setState( this, A ); } | ||
306 | bool canSetState( Action_t A ) | ||
307 | { return getToplevel()->runtime()->canSetState( CurrentState, A ); } | ||
308 | |||
309 | void save( QTextStream & TS ); | ||
310 | |||
311 | void append( ANetNodeInstance * NNI ); | ||
312 | |||
313 | // makes sure that all items in the connection point to | ||
314 | // that connectoin | ||
315 | void reassign( void ); | ||
316 | |||
317 | ANetNodeInstance * getToplevel( void ); | ||
318 | ANetNodeInstance * findNext( ANetNodeInstance * NNI ); | ||
319 | ANetNodeInstance * findByName( const QString & S ); | ||
320 | |||
321 | const QString & name() | ||
322 | { return Name; } | ||
323 | |||
324 | const QString & description( void ); | ||
325 | |||
326 | void setName( const QString & N) | ||
327 | { Name = N; } | ||
328 | |||
329 | State_t currentState( void ) | ||
330 | { return CurrentState; } | ||
331 | void setCurrentState( State_t S ) | ||
332 | { CurrentState = S; } | ||
333 | |||
334 | long maxConnectionNumber( void ) | ||
335 | { return MaxNr; } | ||
336 | |||
337 | static void resetMaxNr( void ) | ||
338 | { MaxNr = -1; } | ||
339 | |||
340 | private : | ||
341 | |||
342 | int compareItems ( QCollection::Item item1, | ||
343 | QCollection::Item item2 ); | ||
344 | |||
345 | static long MaxNr; | ||
346 | long Number; | ||
347 | |||
348 | // state of this connection | ||
349 | State_t CurrentState; | ||
350 | |||
351 | QString Name; | ||
352 | // true if this collection was just created (and not | ||
353 | // loaded from file | ||
354 | bool IsNew; | ||
355 | // index in listbox | ||
356 | int Index; | ||
357 | bool IsModified; | ||
358 | |||
359 | }; | ||
360 | |||
361 | #endif | ||