author | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
commit | a9c188235c97e07b0eb96b13adbcdfd4bad64767 (patch) (unidiff) | |
tree | 13f6ae5c499dc0c1d1bd4b763a1973a0fa8635cf /noncore/settings/networksettings2/nsdata.cpp | |
parent | 48b6cd5966ec6cc0b968edf10ba1a1ad96ef165f (diff) | |
download | opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.zip opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.gz opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.bz2 |
CONTROL files : changed version string
NS2 many changes and first release of OT2
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 252 |
1 files changed, 187 insertions, 65 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index e2dd5b5..698a941 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,167 +1,210 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | ||
2 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
3 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
4 | #include <qdir.h> | 5 | #include <qdir.h> |
5 | #include <qfile.h> | 6 | #include <qfile.h> |
6 | #include <qfileinfo.h> | 7 | #include <qfileinfo.h> |
7 | 8 | ||
8 | #include "nsdata.h" | 9 | #include "nsdata.h" |
9 | #include <asdevice.h> | 10 | #include <netnode.h> |
10 | #include <resources.h> | 11 | #include <resources.h> |
11 | 12 | ||
12 | static QString CfgFile; | 13 | static QString CfgFile; |
13 | 14 | ||
14 | NetworkSettingsData::NetworkSettingsData( void ) { | 15 | NetworkSettingsData::NetworkSettingsData( void ) { |
15 | // init global resources structure | 16 | // init global resources structure |
16 | new TheNSResources(); | 17 | new TheNSResources(); |
17 | 18 | ||
18 | if( ! NSResources->userKnown() ) { | 19 | if( ! NSResources->userKnown() ) { |
19 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", | 20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", |
20 | NSResources->currentUser().HomeDir.latin1(), | 21 | NSResources->currentUser().HomeDir.latin1(), |
21 | NSResources->currentUser().UserName.latin1() )); | 22 | NSResources->currentUser().UserName.latin1() )); |
22 | return; | 23 | return; |
23 | } | 24 | } |
24 | 25 | ||
25 | CfgFile.sprintf( "%s/Settings/NS2.conf", | 26 | CfgFile.sprintf( "%s/Settings/NS2.conf", |
26 | NSResources->currentUser().HomeDir.latin1() ); | 27 | NSResources->currentUser().HomeDir.latin1() ); |
27 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
28 | 29 | ||
29 | // load settings | 30 | // load settings |
30 | IsModified = 0; | ||
31 | loadSettings(); | 31 | loadSettings(); |
32 | |||
33 | // assign interfaces by scanning /tmp/profile-%s.Up files | ||
34 | { QDir D( "/tmp" ); | ||
35 | QFile * F = new QFile; | ||
36 | int profilenr; | ||
37 | QString interfacename; | ||
38 | QTextStream TS ( F ); | ||
39 | |||
40 | QStringList SL = D.entryList( "profile-*.up"); | ||
41 | |||
42 | Log(( "System reports %d interfaces. Found %d up\n", | ||
43 | NSResources->system().interfaces().count(), | ||
44 | SL.count() )); | ||
45 | |||
46 | for ( QStringList::Iterator it = SL.begin(); | ||
47 | it != SL.end(); | ||
48 | ++it ) { | ||
49 | profilenr = atol( (*it).mid( 8 ).latin1() ); | ||
50 | // read the interface store int 'up' | ||
51 | F->setName( D.path() + "/" + (*it) ); | ||
52 | if( F->open( IO_ReadOnly ) ) { | ||
53 | NodeCollection * NC; | ||
54 | interfacename = TS.readLine(); | ||
55 | F->close(); | ||
56 | |||
57 | Log(( "Assign interface %s to Profile nr %d\n", | ||
58 | interfacename.latin1(), profilenr )); | ||
59 | |||
60 | NC = NSResources->getConnection( profilenr ); | ||
61 | if( NC ) { | ||
62 | NC->assignInterface( | ||
63 | NSResources->system().findInterface( interfacename ) ); | ||
64 | } else { | ||
65 | Log(( "Profile nr %d no longer defined\n", | ||
66 | profilenr )); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | } | ||
32 | } | 71 | } |
33 | 72 | ||
34 | // saving is done by caller | 73 | // saving is done by caller |
35 | NetworkSettingsData::~NetworkSettingsData( void ) { | 74 | NetworkSettingsData::~NetworkSettingsData( void ) { |
36 | delete NSResources; | 75 | delete NSResources; |
37 | } | 76 | } |
38 | 77 | ||
39 | void NetworkSettingsData::loadSettings( void ) { | 78 | void NetworkSettingsData::loadSettings( void ) { |
40 | QString Line, S; | 79 | QString Line, S; |
41 | QString Attr, Value; | 80 | QString Attr, Value; |
42 | long idx; | 81 | long idx; |
43 | 82 | ||
44 | QFile F( CfgFile ); | 83 | QFile F( CfgFile ); |
45 | QTextStream TS( &F ); | 84 | QTextStream TS( &F ); |
46 | 85 | ||
86 | ForceModified = 0; | ||
87 | |||
47 | do { | 88 | do { |
48 | 89 | ||
49 | if( ! F.open(IO_ReadOnly) ) | 90 | if( ! F.open(IO_ReadOnly) ) |
50 | break; | 91 | break; |
51 | 92 | ||
52 | /* load the file -> | 93 | /* load the file -> |
53 | 94 | ||
54 | FORMAT : | 95 | FORMAT : |
55 | 96 | ||
56 | [NETNODETYPE] | 97 | [NETNODETYPE] |
57 | Entries ... | 98 | Entries ... |
58 | <EMPTYLINE> | 99 | <EMPTYLINE> |
59 | [connection] | 100 | [connection] |
60 | Name=Name | 101 | Name=Name |
61 | Node=Name | 102 | Node=Name |
62 | <EMPTYLINE> | 103 | <EMPTYLINE> |
63 | */ | 104 | */ |
64 | while( ! TS.atEnd() ) { | 105 | while( ! TS.atEnd() ) { |
65 | S = Line = TS.readLine(); | 106 | S = Line = TS.readLine(); |
66 | 107 | ||
67 | if ( S.isEmpty() || S[0] != '[' ) | 108 | if ( S.isEmpty() || S[0] != '[' ) |
68 | continue; | 109 | continue; |
69 | 110 | ||
70 | S = S.mid( 1, S.length()-2 ); | 111 | S = S.mid( 1, S.length()-2 ); |
71 | 112 | ||
72 | if( ! NSResources ) { | 113 | if( ! NSResources ) { |
73 | continue; | 114 | continue; |
74 | } | 115 | } |
75 | 116 | ||
76 | if( S == "connection" ) { | 117 | if( S == "connection" ) { |
77 | // load connections -> collections of nodes | 118 | // load connections -> collections of nodes |
78 | NodeCollection * NC = new NodeCollection( TS ); | 119 | NodeCollection * NC = new NodeCollection( TS ); |
79 | NSResources->addConnection( NC ); | 120 | NSResources->addConnection( NC ); |
80 | } else { | 121 | } else { |
81 | ANetNode * NN = 0; | 122 | ANetNode * NN = 0; |
82 | ANetNodeInstance* NNI = 0; | 123 | ANetNodeInstance* NNI = 0; |
83 | if( S.startsWith( "nodetype " ) ) { | 124 | if( S.startsWith( "nodetype " ) ) { |
84 | S = S.mid( 9, S.length()-9 ); | 125 | S = S.mid( 9, S.length()-9 ); |
85 | S = deQuote(S); | 126 | S = deQuote(S); |
86 | // try to find netnode | 127 | // try to find netnode |
87 | NN = NSResources->findNetNode( S ); | 128 | NN = NSResources->findNetNode( S ); |
88 | Log( ( "Node %s : %p\n", S.latin1(), NN ) ); | ||
89 | } else { | 129 | } else { |
90 | // try to find instance | 130 | // try to find instance |
91 | NNI = NSResources->createNodeInstance( S ); | 131 | NNI = NSResources->createNodeInstance( S ); |
92 | Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); | ||
93 | } | 132 | } |
94 | 133 | ||
95 | if( NN == 0 && NNI == 0 ) { | 134 | if( NN == 0 && NNI == 0 ) { |
96 | LeftOvers.append( Line ); | 135 | LeftOvers.append( Line ); |
97 | } | 136 | } |
98 | 137 | ||
99 | do { | 138 | do { |
100 | S = Line = TS.readLine(); | 139 | S = Line = TS.readLine(); |
101 | 140 | ||
102 | if( NN || NNI ) { | 141 | if( NN || NNI ) { |
103 | if( S.isEmpty() ) { | 142 | if( S.isEmpty() ) { |
104 | // empty line | 143 | // empty line |
105 | break; | 144 | break; |
106 | } | 145 | } |
107 | idx = S.find( '=' ); | 146 | idx = S.find( '=' ); |
108 | if( idx > 0 ) { | 147 | if( idx > 0 ) { |
109 | Attr = S.left( idx ); | 148 | Attr = S.left( idx ); |
110 | Value = S.mid( idx+1, S.length() ); | 149 | Value = S.mid( idx+1, S.length() ); |
111 | } else { | 150 | } else { |
112 | Value=""; | 151 | Value=""; |
113 | Attr = S; | 152 | Attr = S; |
114 | } | 153 | } |
115 | 154 | ||
116 | Value.stripWhiteSpace(); | 155 | Value.stripWhiteSpace(); |
117 | Attr.stripWhiteSpace(); | 156 | Attr.stripWhiteSpace(); |
118 | Attr.lower(); | 157 | Attr.lower(); |
119 | // dequote Attr | 158 | // dequote Attr |
120 | Value = deQuote(Value); | 159 | Value = deQuote(Value); |
121 | 160 | ||
122 | if( NN ) { | 161 | if( NN ) { |
123 | // set the attribute | 162 | // set the attribute |
124 | NN->setAttribute( Attr, Value ); | 163 | NN->setAttribute( Attr, Value ); |
125 | } else { | 164 | } else { |
126 | // set the attribute | 165 | // set the attribute |
127 | NNI->setAttribute( Attr, Value ); | 166 | NNI->setAttribute( Attr, Value ); |
128 | } | 167 | } |
129 | } else { | 168 | } else { |
130 | LeftOvers.append( Line ); | 169 | LeftOvers.append( Line ); |
131 | // add empty line too as delimiter | 170 | // add empty line too as delimiter |
132 | if( S.isEmpty() ) { | 171 | if( S.isEmpty() ) { |
133 | // empty line | 172 | // empty line |
134 | break; | 173 | break; |
135 | } | 174 | } |
136 | } | 175 | } |
137 | } while( 1 ); | 176 | } while( 1 ); |
138 | 177 | ||
139 | if( NNI ) { | 178 | if( NNI ) { |
140 | // loading from file -> exists | 179 | // loading from file -> exists |
180 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); | ||
141 | NNI->setNew( FALSE ); | 181 | NNI->setNew( FALSE ); |
142 | NSResources->addNodeInstance( NNI ); | 182 | NSResources->addNodeInstance( NNI ); |
143 | } | 183 | } |
184 | if( NN ) { | ||
185 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | ||
186 | } | ||
144 | } | 187 | } |
145 | } | 188 | } |
146 | 189 | ||
147 | } while( 0 ); | 190 | } while( 0 ); |
148 | 191 | ||
149 | } | 192 | } |
150 | 193 | ||
151 | QString NetworkSettingsData::saveSettings( void ) { | 194 | QString NetworkSettingsData::saveSettings( void ) { |
152 | QString ErrS = ""; | 195 | QString ErrS = ""; |
153 | 196 | ||
154 | if( ! isModified() ) | 197 | if( ! isModified() ) |
155 | return ErrS; | 198 | return ErrS; |
156 | 199 | ||
157 | QString S; | 200 | QString S; |
158 | QFile F( CfgFile + ".bup" ); | 201 | QFile F( CfgFile + ".bup" ); |
159 | 202 | ||
160 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); | 203 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); |
161 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | 204 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { |
162 | ErrS = qApp->translate( "NetworkSettings", | 205 | ErrS = qApp->translate( "NetworkSettings", |
163 | "<p>Could not save setup to \"%1\" !</p>" ). | 206 | "<p>Could not save setup to \"%1\" !</p>" ). |
164 | arg(CfgFile); | 207 | arg(CfgFile); |
165 | // problem | 208 | // problem |
166 | return ErrS; | 209 | return ErrS; |
167 | } | 210 | } |
@@ -199,288 +242,361 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
199 | nit.current(); | 242 | nit.current(); |
200 | ++nit ) { | 243 | ++nit ) { |
201 | // header | 244 | // header |
202 | NNI = nit.current(); | 245 | NNI = nit.current(); |
203 | TS << '[' | 246 | TS << '[' |
204 | << QString(NNI->nodeClass()->name()) | 247 | << QString(NNI->nodeClass()->name()) |
205 | << ']' | 248 | << ']' |
206 | << endl; | 249 | << endl; |
207 | NNI->saveAttributes( TS ); | 250 | NNI->saveAttributes( TS ); |
208 | TS << endl; | 251 | TS << endl; |
209 | } | 252 | } |
210 | 253 | ||
211 | TS << "[connection]" << endl; | 254 | TS << "[connection]" << endl; |
212 | it.current()->save(TS); | 255 | it.current()->save(TS); |
213 | } | 256 | } |
214 | } | 257 | } |
215 | 258 | ||
216 | QDir D("."); | 259 | QDir D("."); |
217 | D.rename( CfgFile + ".bup", CfgFile ); | 260 | D.rename( CfgFile + ".bup", CfgFile ); |
218 | 261 | ||
219 | // | 262 | // |
220 | // proper files AND system files regenerated | 263 | // proper files AND system files regenerated |
221 | // | 264 | // |
222 | 265 | ||
223 | setModified( 0 ); | 266 | |
267 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | ||
268 | it.current(); | ||
269 | ++it ) { | ||
270 | it.current()->setModified( 0 ); | ||
271 | } | ||
272 | |||
224 | return ErrS; | 273 | return ErrS; |
225 | } | 274 | } |
226 | 275 | ||
227 | QString NetworkSettingsData::generateSettings( void ) { | 276 | QString NetworkSettingsData::generateSettings( void ) { |
228 | QString S = ""; | 277 | QString S = ""; |
229 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | 278 | Name2SystemFile_t & SFM = NSResources->systemFiles(); |
230 | Name2Connection_t & M = NSResources->connections(); | 279 | Name2Connection_t & M = NSResources->connections(); |
231 | NodeCollection * NC; | 280 | NodeCollection * NC; |
232 | ANetNodeInstance * NNI; | 281 | ANetNodeInstance * NNI; |
233 | ANetNodeInstance * FirstWithData; | 282 | ANetNodeInstance * FirstWithData; |
234 | SystemFile * SF; | 283 | RuntimeInfo * CurDev; |
235 | AsDevice * CurDev; | ||
236 | ANetNode * NN, * CurDevNN = 0; | 284 | ANetNode * NN, * CurDevNN = 0; |
237 | long NoOfDevs; | 285 | long NoOfDevs; |
238 | long DevCtStart; | 286 | long DevCtStart; |
239 | bool needToGenerate; | 287 | bool needToGenerate; |
240 | 288 | ||
241 | // regenerate system files | 289 | // regenerate system files |
242 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 290 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
243 | 291 | ||
244 | // | 292 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
245 | // generate files proper to each netnodeinstance | 293 | nnit.current(); |
246 | // | 294 | ++nnit ) { |
247 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | 295 | { QStringList SL; |
248 | 296 | bool FirstItem = 1; | |
249 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 297 | bool Generated = 0; |
250 | NNIIt.current(); | 298 | |
251 | ++NNIIt ) { | 299 | CurDevNN = nnit.current()->NetNode; |
252 | // for all nodes find those that are modified | 300 | SL = CurDevNN->properFiles(); |
253 | NNI = NNIIt.current(); | 301 | |
254 | 302 | for ( QStringList::Iterator it = SL.begin(); | |
255 | { // get list of proper files for this nodeclass (if any) | 303 | it != SL.end(); |
256 | QStringList * PF = NNI->nodeClass()->properFiles(); | 304 | ++it ) { |
257 | 305 | ||
258 | if( PF ) { | 306 | Generated = 0; |
259 | for ( QStringList::Iterator it = PF->begin(); | 307 | FirstItem = 1; |
260 | it != PF->end(); | 308 | // iterate over NNI's of this class |
261 | ++it ) { | 309 | for( QDictIterator<ANetNodeInstance> nniit( |
262 | QFile * F = NNI->openFile( (*it) ); | 310 | NSResources->netNodeInstances() ); |
263 | if( F ) { | 311 | nniit.current(); |
264 | QTextStream TS( F ); | 312 | ++nniit ) { |
265 | if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { | 313 | if( nniit.current()->nodeClass() != CurDevNN ) |
266 | // problem generating | 314 | // different class |
315 | continue; | ||
316 | |||
317 | // open proper file | ||
318 | { SystemFile SF( (*it) ); | ||
319 | |||
320 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { | ||
321 | // cannot open | ||
322 | S = qApp->translate( "NetworkSettings", | ||
323 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
324 | arg( (*it) ).arg( CurDevNN->name() ); | ||
325 | return S; | ||
326 | } | ||
327 | |||
328 | if( ! SF.open() ) { | ||
329 | S = qApp->translate( "NetworkSettings", | ||
330 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
331 | arg( (*it) ).arg( CurDevNN->name() ); | ||
332 | return S; | ||
333 | } | ||
334 | |||
335 | // preamble on first | ||
336 | if( FirstItem ) { | ||
337 | if( CurDevNN->generatePreamble( SF ) == 2 ) { | ||
267 | S = qApp->translate( "NetworkSettings", | 338 | S = qApp->translate( "NetworkSettings", |
268 | "<p>Cannot generate files proper to \"%1\"</p>" ). | 339 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
269 | arg(NNI->nodeClass()->name()) ; | 340 | arg( (*it) ). |
270 | delete F; | 341 | arg( CurDevNN->name() ); |
271 | return S; | 342 | return S; |
272 | } | 343 | } |
273 | delete F; | 344 | } |
345 | FirstItem = 0; | ||
346 | Generated = 1; | ||
347 | |||
348 | // item specific | ||
349 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { | ||
350 | S = qApp->translate( "NetworkSettings", | ||
351 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). | ||
352 | arg( nniit.current()->name() ). | ||
353 | arg( (*it) ). | ||
354 | arg( CurDevNN->name() ); | ||
355 | return S; | ||
274 | } | 356 | } |
275 | } | 357 | } |
276 | } | 358 | } |
359 | |||
360 | if( Generated ) { | ||
361 | SystemFile SF( (*it) ); | ||
362 | |||
363 | if( CurDevNN->openFile( SF, 0 ) && | ||
364 | ! SF.path().isEmpty() | ||
365 | ) { | ||
366 | |||
367 | if( ! SF.open() ) { | ||
368 | S = qApp->translate( "NetworkSettings", | ||
369 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | ||
370 | arg( (*it) ).arg( CurDevNN->name() ); | ||
371 | return S; | ||
372 | } | ||
373 | |||
374 | if( CurDevNN->generatePostamble( SF ) == 2 ) { | ||
375 | S = qApp->translate( "NetworkSettings", | ||
376 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). | ||
377 | arg( (*it) ). | ||
378 | arg( CurDevNN->name() ); | ||
379 | return S; | ||
380 | } | ||
381 | } // no postamble | ||
382 | } | ||
277 | } | 383 | } |
278 | } | 384 | } |
279 | } | 385 | } |
280 | 386 | ||
281 | // | 387 | // |
282 | // generate all system files | 388 | // generate all registered files |
283 | // | 389 | // |
284 | for( QDictIterator<SystemFile> sfit(SFM); | 390 | for( QDictIterator<SystemFile> sfit(SFM); |
285 | sfit.current(); | 391 | sfit.current(); |
286 | ++sfit ) { | 392 | ++sfit ) { |
393 | SystemFile * SF; | ||
394 | |||
287 | SF = sfit.current(); | 395 | SF = sfit.current(); |
288 | 396 | ||
289 | // reset all | 397 | // reset all |
290 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 398 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
291 | nnit.current(); | 399 | nnit.current(); |
292 | ++nnit ) { | 400 | ++nnit ) { |
293 | nnit.current()->NetNode->setDone(0); | 401 | nnit.current()->NetNode->setDone(0); |
294 | } | 402 | } |
295 | 403 | ||
296 | for( QDictIterator<ANetNodeInstance> nniit( | 404 | for( QDictIterator<ANetNodeInstance> nniit( |
297 | NSResources->netNodeInstances() ); | 405 | NSResources->netNodeInstances() ); |
298 | nniit.current(); | 406 | nniit.current(); |
299 | ++nniit ) { | 407 | ++nniit ) { |
300 | nniit.current()->setDone(0); | 408 | nniit.current()->setDone(0); |
301 | } | 409 | } |
302 | 410 | ||
303 | for( QDictIterator<NodeCollection> ncit(M); | 411 | for( QDictIterator<NodeCollection> ncit(M); |
304 | ncit.current(); | 412 | ncit.current(); |
305 | ++ncit ) { | 413 | ++ncit ) { |
306 | ncit.current()->setDone(0); | 414 | ncit.current()->setDone(0); |
307 | } | 415 | } |
308 | 416 | ||
309 | Log( ( "Generating %s\n", SF->name().latin1() )); | 417 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
310 | 418 | ||
311 | needToGenerate = 0; | 419 | needToGenerate = 0; |
312 | 420 | ||
313 | // are there netnodes that have instances and need | 421 | // are there netnodes that have instances and need |
314 | // to write data in this system file ? | 422 | // to write data in this system file ? |
315 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); | 423 | for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); |
316 | ! needToGenerate && nnit.current(); | 424 | ! needToGenerate && nnit.current(); |
317 | ++nnit ) { | 425 | ++nnit ) { |
318 | 426 | ||
319 | NN = nnit.current()->NetNode; | 427 | NN = nnit.current()->NetNode; |
320 | 428 | ||
321 | if( NN->hasDataForFile( SF->name() ) ) { | 429 | if( NN->hasDataForFile( *SF ) ) { |
322 | // netnode can have data | 430 | // netnode can have data |
323 | 431 | ||
324 | // are there instances of this node ? | 432 | // are there instances of this node ? |
325 | for( QDictIterator<ANetNodeInstance> nniit( | 433 | for( QDictIterator<ANetNodeInstance> nniit( |
326 | NSResources->netNodeInstances() ); | 434 | NSResources->netNodeInstances() ); |
327 | ! needToGenerate && nniit.current(); | 435 | ! needToGenerate && nniit.current(); |
328 | ++nniit ) { | 436 | ++nniit ) { |
329 | if( nniit.current()->nodeClass() == NN ) { | 437 | if( nniit.current()->nodeClass() == NN ) { |
330 | // yes | 438 | // yes |
331 | Log(("Node %s has data\n", | 439 | Log(("Node %s has data\n", |
332 | nniit.current()->name() )); | 440 | nniit.current()->name() )); |
333 | needToGenerate = 1; | 441 | needToGenerate = 1; |
334 | break; | 442 | break; |
335 | } | 443 | } |
336 | } | 444 | } |
337 | } | 445 | } |
338 | } | 446 | } |
339 | 447 | ||
340 | if( ! needToGenerate ) { | 448 | if( ! needToGenerate ) { |
341 | // no instances found that might need to write data | 449 | // no instances found that might need to write data |
342 | // in this systemfile | 450 | // in this systemfile |
343 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); | 451 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |
344 | continue; | 452 | continue; |
345 | } | 453 | } |
346 | 454 | ||
347 | // ok generate this system file | 455 | // ok generate this system file |
348 | SF->open(); | 456 | if( ! SF->open() ) { |
457 | S = qApp->translate( "NetworkSettings", | ||
458 | "<p>Cannot open system file \"%1\"</p>" ). | ||
459 | arg( SF->name() ); | ||
460 | return S; | ||
461 | } | ||
349 | 462 | ||
350 | // global presection for this system file | 463 | // global presection for this system file |
351 | if( ! SF->preSection() ) { | 464 | if( ! SF->preSection() ) { |
352 | S = qApp->translate( "NetworkSettings", | 465 | S = qApp->translate( "NetworkSettings", |
353 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). | 466 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). |
354 | arg( SF->name() ); | 467 | arg( SF->name() ); |
355 | return S; | 468 | return S; |
356 | } | 469 | } |
357 | 470 | ||
358 | // find connections that want to write to this file | 471 | // find connections that want to write to this file |
359 | for( QDictIterator<NodeCollection> ncit(M); | 472 | for( QDictIterator<NodeCollection> ncit(M); |
360 | ncit.current(); | 473 | ncit.current(); |
361 | ++ncit ) { | 474 | ++ncit ) { |
362 | 475 | ||
363 | NC = ncit.current(); | 476 | NC = ncit.current(); |
364 | 477 | ||
365 | if( NC->done() ) { | 478 | if( NC->done() ) { |
366 | // already done | 479 | // already done |
367 | continue; | 480 | continue; |
368 | } | 481 | } |
369 | 482 | ||
370 | if( ! NC->hasDataForFile( SF->name() ) ) { | 483 | if( ! NC->hasDataForFile( *SF ) ) { |
371 | // no data | 484 | // no data |
372 | continue; | 485 | continue; |
373 | } | 486 | } |
374 | 487 | ||
375 | Log(("Generating %s for connection %s\n", | 488 | Log(("Generating %s for connection %s\n", |
376 | SF->name().latin1(), NC->name().latin1() )); | 489 | SF->name().latin1(), NC->name().latin1() )); |
377 | // find highest item that wants to write data to this file | 490 | // find highest item that wants to write data to this file |
378 | FirstWithData = NC->firstWithDataForFile( SF->name() ); | 491 | FirstWithData = NC->firstWithDataForFile( *SF ); |
379 | 492 | ||
380 | // find device on which this connection works | 493 | // find device on which this connection works |
381 | CurDev = NC->device(); | 494 | CurDev = NC->device(); |
382 | // class of that node | 495 | // class of that node |
383 | CurDevNN = CurDev->netNode()->nodeClass(); | 496 | CurDevNN = CurDev->netNode()->nodeClass(); |
384 | 497 | ||
385 | Log(( "%s is done %d\n", | ||
386 | FirstWithData->nodeClass()->name(), | ||
387 | FirstWithData->nodeClass()->done() )); | ||
388 | |||
389 | if( ! FirstWithData->nodeClass()->done() ) { | 498 | if( ! FirstWithData->nodeClass()->done() ) { |
390 | // generate fixed part | 499 | // generate fixed part |
391 | if( ! SF->preDeviceSection( CurDevNN ) ) { | 500 | if( ! SF->preDeviceSection( CurDevNN ) ) { |
392 | S = qApp->translate( "NetworkSettings", | 501 | S = qApp->translate( "NetworkSettings", |
393 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). | 502 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). |
394 | arg( SF->name() ); | 503 | arg( SF->name() ); |
395 | return S; | 504 | return S; |
396 | } | 505 | } |
397 | 506 | ||
398 | if( FirstWithData->nodeClass()->generateFile( | 507 | if( FirstWithData->nodeClass()->generateFile( |
399 | SF->name(), SF->path(), *SF, -1 ) == 2 ) { | 508 | *SF, |
509 | FirstWithData, | ||
510 | -2 ) == 2 ) { | ||
400 | S = qApp->translate( "NetworkSettings", | 511 | S = qApp->translate( "NetworkSettings", |
401 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | 512 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
402 | arg( SF->name() ). | 513 | arg( SF->name() ). |
403 | arg( CurDevNN->name() ); | 514 | arg( CurDevNN->name() ); |
404 | return S; | 515 | return S; |
405 | } | 516 | } |
406 | FirstWithData->nodeClass()->setDone( 1 ); | 517 | FirstWithData->nodeClass()->setDone( 1 ); |
518 | Log(( "Systemfile %s for node instance %s is done\n", | ||
519 | SF->name().latin1(), | ||
520 | FirstWithData->name() )); | ||
407 | } | 521 | } |
408 | 522 | ||
409 | NoOfDevs = 0; | 523 | NoOfDevs = 0; |
410 | DevCtStart = -1; | 524 | DevCtStart = -1; |
411 | 525 | ||
412 | if( SF->knowsDeviceInstances() ) { | 526 | if( SF->knowsDeviceInstances() ) { |
413 | DevCtStart = 0; | 527 | DevCtStart = 0; |
414 | NoOfDevs = CurDevNN->instanceCount(); | 528 | NoOfDevs = CurDevNN->instanceCount(); |
415 | } | 529 | } |
416 | 530 | ||
417 | Log(( "Node %s is done %d\n", | ||
418 | CurDev->netNode()->nodeClass()->name(), | ||
419 | CurDev->netNode()->nodeClass()->done() )); | ||
420 | |||
421 | if( ! CurDev->netNode()->nodeClass()->done() ) { | 531 | if( ! CurDev->netNode()->nodeClass()->done() ) { |
422 | // first time this device is handled | 532 | // first time this device is handled |
423 | // generate common device specific part | 533 | // generate common device specific part |
424 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 534 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
425 | 535 | ||
426 | if( FirstWithData->nodeClass()->generateFile( | 536 | if( FirstWithData->nodeClass()->generateFile( |
427 | SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { | 537 | *SF, CurDev->netNode(), i ) == 2 ) { |
428 | S = qApp->translate( "NetworkSettings", | 538 | S = qApp->translate( "NetworkSettings", |
429 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | 539 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
430 | arg( SF->name() ). | 540 | arg( SF->name() ). |
431 | arg( CurDevNN->name() ); | 541 | arg( CurDevNN->name() ); |
432 | return S; | 542 | return S; |
433 | } | 543 | } |
434 | } | 544 | } |
435 | CurDev->netNode()->nodeClass()->setDone( 1 ); | 545 | CurDev->netNode()->nodeClass()->setDone( 1 ); |
546 | |||
547 | Log(( "Systemfile %s for Nodeclass %s is done\n", | ||
548 | SF->name().latin1(), | ||
549 | CurDev->netNode()->nodeClass()->name() | ||
550 | )); | ||
436 | } | 551 | } |
437 | 552 | ||
438 | // generate profile specific info | 553 | // generate profile specific info |
439 | // for all nodeconnections that work on the same device | 554 | // for all nodeconnections that work on the same device |
440 | for( QDictIterator<NodeCollection> ncit2(M); | 555 | for( QDictIterator<NodeCollection> ncit2(M); |
441 | ncit2.current(); | 556 | ncit2.current(); |
442 | ++ncit2 ) { | 557 | ++ncit2 ) { |
443 | 558 | ||
444 | if( ncit2.current()->device() != CurDev ) { | 559 | if( ncit2.current()->device() != CurDev ) { |
445 | // different device | 560 | // different device |
446 | continue; | 561 | continue; |
447 | } | 562 | } |
448 | 563 | ||
449 | Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); | 564 | Log(("Connection %s of family %s\n", |
565 | ncit2.current()->name().latin1(), | ||
566 | CurDev->name() )); | ||
450 | // generate | 567 | // generate |
451 | NNI = ncit2.current()->firstWithDataForFile( SF->name() ); | 568 | NNI = ncit2.current()->firstWithDataForFile( *SF ); |
452 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 569 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
453 | if( ! SF->preNodeSection( NNI, i ) ) { | 570 | if( ! SF->preNodeSection( NNI, i ) ) { |
454 | S = qApp->translate( "NetworkSettings", | 571 | S = qApp->translate( "NetworkSettings", |
455 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 572 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
456 | arg( SF->name() ). | 573 | arg( SF->name() ). |
457 | arg( CurDevNN->name() ); | 574 | arg( CurDevNN->name() ); |
458 | return S; | 575 | return S; |
459 | } | 576 | } |
460 | 577 | ||
461 | switch( NNI->generateFile( | 578 | switch( NNI->generateFile( *SF, i ) ) { |
462 | SF->name(), SF->path(), *SF, i ) ) { | ||
463 | case 0 : | 579 | case 0 : |
464 | (*SF) << endl; | 580 | (*SF) << endl; |
465 | break; | 581 | break; |
466 | case 1 : | 582 | case 1 : |
467 | break; | 583 | break; |
468 | case 2 : | 584 | case 2 : |
469 | S = qApp->translate( "NetworkSettings", | 585 | S = qApp->translate( "NetworkSettings", |
470 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | 586 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). |
471 | arg( SF->name() ). | 587 | arg( SF->name() ). |
472 | arg( CurDevNN->name() ); | 588 | arg( CurDevNN->name() ); |
473 | return S; | 589 | return S; |
474 | } | 590 | } |
475 | 591 | ||
476 | if( ! SF->postNodeSection( NNI, i ) ) { | 592 | if( ! SF->postNodeSection( NNI, i ) ) { |
477 | S = qApp->translate( "NetworkSettings", | 593 | S = qApp->translate( "NetworkSettings", |
478 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 594 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
479 | arg( SF->name() ). | 595 | arg( SF->name() ). |
480 | arg( CurDevNN->name() ); | 596 | arg( CurDevNN->name() ); |
481 | return S; | 597 | return S; |
482 | } | 598 | } |
483 | } | 599 | } |
484 | 600 | ||
485 | ncit2.current()->setDone( 1 ); | 601 | ncit2.current()->setDone( 1 ); |
486 | 602 | ||
@@ -548,56 +664,62 @@ bool NetworkSettingsData::canStart( const char * Interface ) { | |||
548 | 664 | ||
549 | Log( ( "for %s : Possiblilies %d\n", | 665 | Log( ( "for %s : Possiblilies %d\n", |
550 | Interface, PossibleConnections.count() )); | 666 | Interface, PossibleConnections.count() )); |
551 | switch( PossibleConnections.count() ) { | 667 | switch( PossibleConnections.count() ) { |
552 | case 0 : // no connections | 668 | case 0 : // no connections |
553 | break; | 669 | break; |
554 | case 1 : // one connection | 670 | case 1 : // one connection |
555 | NC = PossibleConnections.first(); | 671 | NC = PossibleConnections.first(); |
556 | break; | 672 | break; |
557 | default : // need to ask user ? | 673 | default : // need to ask user ? |
558 | return 1; | 674 | return 1; |
559 | } | 675 | } |
560 | 676 | ||
561 | if( NC ) { | 677 | if( NC ) { |
562 | switch( NC->state() ) { | 678 | switch( NC->state() ) { |
563 | case Unchecked : | 679 | case Unchecked : |
564 | case Unknown : | 680 | case Unknown : |
565 | case Unavailable : | 681 | case Unavailable : |
566 | case Disabled : | 682 | case Disabled : |
567 | // this profile does not allow interface to be UP | 683 | // this profile does not allow interface to be UP |
568 | // -> try others | 684 | // -> try others |
569 | break; | 685 | break; |
570 | case Off : | 686 | case Off : |
571 | // try to UP the device | 687 | // try to UP the device |
572 | if( ! NC->setState( Activate ) ) { | 688 | { QString S= NC->setState( Activate ); |
573 | // cannot bring device Online -> try other alters | 689 | if( ! S.isEmpty() ) { |
574 | break; | 690 | // could not bring device Online -> try other alters |
691 | Log(( "%s-c%d-disallowed : %s\n", | ||
692 | Interface, NC->number(), S.latin1() )); | ||
693 | break; | ||
694 | } | ||
695 | // interface assigned | ||
575 | } | 696 | } |
576 | // FT | 697 | // FT |
577 | case Available : | 698 | case Available : |
578 | case IsUp : // also called for 'ifdown' | 699 | case IsUp : // also called for 'ifdown' |
579 | // device is ready -> done | 700 | // device is ready -> done |
580 | Log(( "%s-c%d-allowed\n", Interface, NC->number() )); | 701 | Log(( "%s-c%d-allowed\n", Interface, NC->number() )); |
581 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | 702 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); |
582 | return 0; | 703 | return 0; |
583 | } | 704 | } |
584 | } | 705 | } |
585 | 706 | ||
586 | // if we come here no alternatives are possible | 707 | // if we come here no alternatives are possible |
587 | Log(( "%s-cnn-disallowed\n", Interface )); | 708 | Log(( "%s-cnn-disallowed\n", Interface )); |
588 | printf( "%s-cnn-disallowed\n", Interface ); | 709 | printf( "%s-cnn-disallowed\n", Interface ); |
589 | return 0; | 710 | return 0; |
590 | } | 711 | } |
591 | 712 | ||
592 | /* | 713 | bool NetworkSettingsData::isModified( void ) { |
593 | Called by the system to regenerate config files | 714 | if( ForceModified ) |
594 | */ | ||
595 | |||
596 | bool NetworkSettingsData::regenerate( void ) { | ||
597 | QString S = generateSettings(); | ||
598 | if( ! S.isEmpty() ) { | ||
599 | fprintf( stdout, "%s\n", S.latin1() ); | ||
600 | return 1; | 715 | return 1; |
716 | |||
717 | for( QDictIterator<NodeCollection> it(NSResources->connections()); | ||
718 | it.current(); | ||
719 | ++it ) { | ||
720 | if( it.current()->isModified() ) { | ||
721 | return 1; | ||
722 | } | ||
601 | } | 723 | } |
602 | return 0; | 724 | return 0; |
603 | } | 725 | } |