]>
Commit | Line | Data |
---|---|---|
3495cce2 | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | * for The ALICE Off-line Project. * | |
8 | * * | |
9 | * Permission to use, copy, modify and distribute this software and its * | |
10 | * documentation strictly for non-commercial purposes is hereby granted * | |
11 | * without fee, provided that the above copyright notice appears in all * | |
12 | * copies and that both the copyright notice and this permission notice * | |
13 | * appear in the supporting documentation. The authors make no claims * | |
14 | * about the suitability of this software for any purpose. It is * | |
15 | * provided "as is" without express or implied warranty. * | |
16 | **************************************************************************/ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
20 | // HLT configuration handling // | |
21 | // // | |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | #if __GNUC__== 3 | |
25 | using namespace std; | |
26 | #endif | |
27 | ||
28 | #include <errno.h> | |
29 | #include "AliHLTConfiguration.h" | |
30 | #include "AliHLTComponent.h" | |
31 | #include "AliHLTComponentHandler.h" | |
32 | #include <iostream> | |
33 | #include <string.h> | |
34 | ||
35 | ClassImp(AliHLTConfiguration) | |
36 | ||
37 | AliHLTConfiguration::AliHLTConfiguration() | |
38 | { | |
39 | fID=NULL; | |
40 | fComponent=NULL; | |
41 | fStringSources=NULL; | |
42 | fNofSources=-1; | |
43 | fArguments=NULL; | |
44 | fArgc=-1; | |
45 | fArgv=NULL; | |
46 | fListSrcElement=fListSources.begin(); | |
47 | } | |
48 | ||
49 | AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments) | |
50 | { | |
51 | fArgc=-1; | |
52 | fArgv=NULL; | |
53 | ||
54 | if (id && component) { | |
55 | fID=id; | |
56 | fComponent=component; | |
57 | fStringSources=sources; | |
58 | fNofSources=-1; | |
59 | fArguments=arguments; | |
60 | fListSrcElement=fListSources.begin(); | |
61 | AliHLTConfigurationHandler::RegisterConfiguration(this); | |
62 | } | |
63 | } | |
64 | ||
65 | AliHLTConfiguration::~AliHLTConfiguration() | |
66 | { | |
67 | if (AliHLTConfigurationHandler::FindConfiguration(fID)!=NULL) { | |
68 | AliHLTConfigurationHandler::RemoveConfiguration(this); | |
69 | } | |
70 | if (fArgv != NULL) { | |
71 | if (fArgc>0) { | |
72 | for (int i=0; i<fArgc; i++) { | |
73 | delete[] fArgv[i]; | |
74 | } | |
75 | } | |
76 | delete[] fArgv; | |
77 | fArgv=NULL; | |
78 | } | |
79 | } | |
80 | ||
81 | const char* AliHLTConfiguration::GetName() const { | |
82 | if (fID) | |
83 | return fID; | |
84 | return TObject::GetName(); | |
85 | } | |
86 | ||
87 | AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id) | |
88 | { | |
89 | AliHLTConfiguration* pSrc=NULL; | |
90 | if (id) { | |
91 | // first check the current element | |
92 | if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) { | |
93 | pSrc=*fListSrcElement; | |
94 | } else { | |
95 | // check the list | |
96 | ||
97 | pSrc=GetFirstSource(); | |
98 | while (pSrc) { | |
99 | if (strcmp(id, pSrc->GetName())==0) | |
100 | break; | |
101 | pSrc=GetNextSource(); | |
102 | } | |
103 | } | |
104 | } | |
105 | return pSrc; | |
106 | } | |
107 | ||
108 | AliHLTConfiguration* AliHLTConfiguration::GetFirstSource() | |
109 | { | |
110 | AliHLTConfiguration* pSrc=NULL; | |
111 | if (fNofSources>=0 || ExtractSources()) { | |
112 | fListSrcElement=fListSources.begin(); | |
113 | if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement; | |
114 | } | |
115 | return pSrc; | |
116 | } | |
117 | ||
118 | AliHLTConfiguration* AliHLTConfiguration::GetNextSource() | |
119 | { | |
120 | AliHLTConfiguration* pSrc=NULL; | |
121 | if (fNofSources>0) { | |
122 | if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) | |
123 | pSrc=*fListSrcElement; | |
124 | } | |
125 | return pSrc; | |
126 | } | |
127 | ||
128 | int AliHLTConfiguration::SourcesResolved(int bAuto) | |
129 | { | |
130 | int iResult=0; | |
131 | if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) { | |
132 | //Logging(kHLTLogDebug, "BASE", "Configuration", "fNofSources=%d", fNofSources); | |
133 | //Logging(kHLTLogDebug, "BASE", "Configuration", "list size = %d", fListSources.size()); | |
134 | iResult=fNofSources==(int)fListSources.size(); | |
135 | } | |
136 | return iResult; | |
137 | } | |
138 | ||
139 | int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf) | |
140 | { | |
141 | int iResult=0; | |
142 | if (pConf) { | |
143 | vector<AliHLTConfiguration*>::iterator element=fListSources.begin(); | |
144 | while (element!=fListSources.end()) { | |
145 | if (*element==pConf) { | |
146 | fListSources.erase(element); | |
147 | fListSrcElement=fListSources.end(); | |
148 | // there is no need to re-evaluate until there was a new configuration registered | |
149 | // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration | |
150 | //InvalidateSources(); | |
151 | break; | |
152 | } | |
153 | element++; | |
154 | } | |
155 | } else { | |
156 | iResult=-EINVAL; | |
157 | } | |
158 | return iResult; | |
159 | } | |
160 | ||
161 | void AliHLTConfiguration::PrintStatus() | |
162 | { | |
163 | Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "status of configuration \"%s\" (%p)", GetName(), this); | |
164 | if (fComponent) Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " - component: \"%s\"", fComponent); | |
165 | else Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " - component string invalid"); | |
166 | if (fStringSources) Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " - sources: \"%s\"", fStringSources); | |
167 | else Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " - no sources"); | |
168 | if (SourcesResolved(1)<=0) | |
169 | Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " there are unresolved sources"); | |
170 | AliHLTConfiguration* pSrc=GetFirstSource(); | |
171 | while (pSrc) { | |
172 | Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", " source \"%s\" (%p) resolved", pSrc->GetName(), pSrc); | |
173 | pSrc=GetNextSource(); | |
174 | } | |
175 | } | |
176 | ||
177 | int AliHLTConfiguration::GetArguments(int* pArgc, const char*** pArgv) | |
178 | { | |
179 | int iResult=0; | |
180 | if (pArgc && pArgv) { | |
181 | *pArgc=fArgc; | |
182 | *pArgv=(const char**)fArgv; | |
183 | } else { | |
184 | iResult=-EINVAL; | |
185 | } | |
186 | return iResult; | |
187 | } | |
188 | ||
189 | ||
190 | int AliHLTConfiguration::ExtractSources() | |
191 | { | |
192 | int iResult=0; | |
193 | fNofSources=0; | |
194 | if (fStringSources!=NULL) { | |
195 | vector<char*> tgtList; | |
196 | fListSources.clear(); | |
197 | if ((iResult=InterpreteString(fStringSources, tgtList))>=0) { | |
198 | fNofSources=tgtList.size(); | |
199 | vector<char*>::iterator element=tgtList.begin(); | |
200 | while ((element=tgtList.begin())!=tgtList.end() && iResult>=0) { | |
201 | AliHLTConfiguration* pConf=AliHLTConfigurationHandler::FindConfiguration(*element); | |
202 | if (pConf) { | |
203 | Logging(kHLTLogDebug, "BASE", "Configuration", "source \"%s\" inserted", pConf->GetName()); | |
204 | fListSources.push_back(pConf); | |
205 | } else { | |
206 | Logging(kHLTLogError, "BASE", "Configuration", "can not find source \"%s\"", (*element)); | |
207 | iResult=-ENOENT; | |
208 | } | |
209 | delete[] (*element); | |
210 | tgtList.erase(element); | |
211 | } | |
212 | fListSrcElement=fListSources.begin(); | |
213 | } | |
214 | } | |
215 | return iResult; | |
216 | } | |
217 | ||
218 | int AliHLTConfiguration::ExtractArguments() | |
219 | { | |
220 | int iResult=0; | |
221 | if (fArguments!=NULL) { | |
222 | vector<char*> tgtList; | |
223 | if ((iResult=InterpreteString(fArguments, tgtList))>=0) { | |
224 | fArgc=tgtList.size(); | |
225 | //Logging(kHLTLogDebug, "BASE", "Configuration", "found %d arguments", fArgc); | |
226 | if (fArgc>0) { | |
227 | fArgv = new char*[fArgc]; | |
228 | if (fArgv) { | |
229 | vector<char*>::iterator element=tgtList.begin(); | |
230 | int i=0; | |
231 | while (element!=tgtList.end()) { | |
232 | //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "assign arguments %d (%s)", i, *element); | |
233 | fArgv[i++]=(*element); | |
234 | element++; | |
235 | } | |
236 | } else { | |
237 | iResult=-ENOMEM; | |
238 | } | |
239 | } | |
240 | } | |
241 | } | |
242 | return iResult; | |
243 | } | |
244 | ||
245 | int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList) | |
246 | { | |
247 | int iResult=0; | |
248 | if (arg) { | |
249 | //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "interprete \"%s\"", arg); | |
250 | int i=0; | |
251 | int prec=-1; | |
252 | do { | |
253 | if (arg[i]==0 || arg[i]==' ') { | |
254 | if (prec>=0) { | |
255 | char* pEntry= new char[i-prec+1]; | |
256 | if (pEntry) { | |
257 | strncpy(pEntry, &arg[prec], i-prec); | |
258 | pEntry[i-prec]=0; // terminate string | |
259 | //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "create string \"%s\", insert at %d", pEntry, argList.size()); | |
260 | argList.push_back(pEntry); | |
261 | } else | |
262 | iResult=-ENOMEM; | |
263 | prec=-1; | |
264 | } | |
265 | } else if (prec==-1) prec=i; | |
266 | } while (arg[i++]!=0 && iResult>=0); | |
267 | } else { | |
268 | iResult=-EINVAL; | |
269 | } | |
270 | return iResult; | |
271 | } | |
272 | ||
273 | int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList) | |
274 | { | |
275 | int iResult=0; | |
276 | if (id) { | |
277 | AliHLTConfiguration* pDep=NULL; | |
278 | if ((pDep=GetSource(id))!=NULL) { | |
279 | if (pTgtList) pTgtList->Add(pDep); | |
280 | iResult++; | |
281 | } else { | |
282 | pDep=GetFirstSource(); | |
283 | while (pDep && iResult==0) { | |
284 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
285 | if (pTgtList) pTgtList->AddFirst(pDep); | |
286 | iResult++; | |
287 | } | |
288 | pDep=GetNextSource(); | |
289 | } | |
290 | } | |
291 | } else { | |
292 | iResult=-EINVAL; | |
293 | } | |
294 | return iResult; | |
295 | } | |
296 | ||
297 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
298 | ||
299 | ClassImp(AliHLTTask) | |
300 | ||
301 | AliHLTTask::AliHLTTask() | |
302 | { | |
303 | fpConfiguration=NULL; | |
304 | fpComponent=NULL; | |
305 | fpBlockDataArray=NULL; | |
306 | } | |
307 | ||
308 | AliHLTTask::AliHLTTask(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH) | |
309 | { | |
310 | fpConfiguration=NULL; | |
311 | fpComponent=NULL; | |
312 | fpBlockDataArray=NULL; | |
313 | Init(fConf, pCH); | |
314 | } | |
315 | ||
316 | AliHLTTask::~AliHLTTask() | |
317 | { | |
318 | if (fpComponent) delete fpComponent; | |
319 | fpComponent=NULL; | |
320 | if (fpBlockDataArray) delete[] fpBlockDataArray; | |
321 | fpBlockDataArray=NULL; | |
322 | } | |
323 | ||
324 | int AliHLTTask::Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH) | |
325 | { | |
326 | int iResult=0; | |
327 | if (fConf) { | |
328 | fpConfiguration=fConf; | |
329 | if (pCH) { | |
330 | int argc=0; | |
331 | const char** argv=NULL; | |
332 | if ((iResult=fConf->GetArguments(&argc, &argv))>=0) { | |
333 | iResult=pCH->CreateComponent(fConf->GetComponentID(), NULL, argc, argv, fpComponent); | |
334 | if (fpComponent) { | |
335 | } else { | |
336 | Logging(kHLTLogError, "BASE", "AliHLTTask", "can not find component \"%s\"", fConf->GetComponentID()); | |
337 | } | |
338 | } | |
339 | } | |
340 | } else { | |
341 | iResult=-EINVAL; | |
342 | } | |
343 | return iResult; | |
344 | } | |
345 | ||
346 | const char *AliHLTTask::GetName() const | |
347 | { | |
348 | if (fpConfiguration) | |
349 | return fpConfiguration->GetName(); | |
350 | return TObject::GetName(); | |
351 | } | |
352 | ||
353 | AliHLTConfiguration* AliHLTTask::GetConf() | |
354 | { | |
355 | return fpConfiguration; | |
356 | } | |
357 | ||
358 | AliHLTComponent* AliHLTTask::GetComponent() | |
359 | { | |
360 | return fpComponent; | |
361 | } | |
362 | ||
363 | AliHLTTask* AliHLTTask::FindDependency(const char* id) | |
364 | { | |
365 | AliHLTTask* pTask=NULL; | |
366 | if (id) { | |
367 | pTask=(AliHLTTask*)fListDependencies.FindObject(id); | |
368 | } | |
369 | return pTask; | |
370 | } | |
371 | ||
372 | int AliHLTTask::FollowDependency(const char* id, TList* pTgtList) | |
373 | { | |
374 | int iResult=0; | |
375 | if (id) { | |
376 | AliHLTTask* pDep=NULL; | |
377 | if ((pDep=(AliHLTTask*)fListDependencies.FindObject(id))!=NULL) { | |
378 | if (pTgtList) pTgtList->Add(pDep); | |
379 | iResult++; | |
380 | } else { | |
381 | TObjLink* lnk=fListDependencies.FirstLink(); | |
382 | while (lnk && iResult==0) { | |
383 | pDep=(AliHLTTask*)lnk->GetObject(); | |
384 | if (pDep) { | |
385 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
386 | if (pTgtList) pTgtList->AddFirst(pDep); | |
387 | iResult++; | |
388 | } | |
389 | } else { | |
390 | iResult=-EFAULT; | |
391 | } | |
392 | lnk=lnk->Next(); | |
393 | } | |
394 | } | |
395 | } else { | |
396 | iResult=-EINVAL; | |
397 | } | |
398 | return iResult; | |
399 | } | |
400 | ||
401 | void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration) | |
402 | { | |
403 | int iResult=0; | |
404 | TList tgtList; | |
405 | if (bFromConfiguration) { | |
406 | if (fpConfiguration) | |
407 | iResult=fpConfiguration->FollowDependency(id, &tgtList); | |
408 | else | |
409 | iResult=-EFAULT; | |
410 | } else | |
411 | iResult=FollowDependency(id, &tgtList); | |
412 | if (iResult>0) { | |
413 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " task \"%s\": dependency level %d ", GetName(), iResult); | |
414 | TObjLink* lnk=tgtList.FirstLink(); | |
415 | int i=iResult; | |
416 | char* pSpace = new char[iResult+1]; | |
417 | if (pSpace) { | |
418 | memset(pSpace, 32, iResult); | |
419 | pSpace[i]=0; | |
420 | while (lnk) { | |
421 | TObject* obj=lnk->GetObject(); | |
422 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " %s^-- %s ", &pSpace[i--], obj->GetName()); | |
423 | lnk=lnk->Next(); | |
424 | } | |
425 | delete [] pSpace; | |
426 | } else { | |
427 | iResult=-ENOMEM; | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | int AliHLTTask::InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource) | |
433 | { | |
434 | int iResult=0; | |
435 | return iResult; | |
436 | } | |
437 | ||
438 | int AliHLTTask::SetDependency(AliHLTTask* pDep) | |
439 | { | |
440 | int iResult=0; | |
441 | if (pDep) { | |
442 | if (FindDependency(pDep->GetName())==NULL) { | |
443 | fListDependencies.Add(pDep); | |
444 | } else { | |
445 | iResult=-EEXIST; | |
446 | } | |
447 | } else { | |
448 | iResult=-EINVAL; | |
449 | } | |
450 | return iResult; | |
451 | } | |
452 | ||
453 | int AliHLTTask::CheckDependencies() | |
454 | { | |
455 | int iResult=0; | |
456 | AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource(); | |
457 | while (pSrc) { | |
458 | if (FindDependency(pSrc->GetName())==NULL) { | |
459 | //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "dependency \"%s\" unresolved", pSrc->GetName()); | |
460 | iResult++; | |
461 | } | |
462 | pSrc=fpConfiguration->GetNextSource(); | |
463 | } | |
464 | return iResult; | |
465 | } | |
466 | ||
467 | ||
468 | int AliHLTTask::Depends(AliHLTTask* pTask) | |
469 | { | |
470 | int iResult=0; | |
471 | if (pTask) { | |
472 | if (fpConfiguration) { | |
473 | iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL; | |
474 | if (iResult>0) { | |
475 | //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task \"%s\" depends on \"%s\"", GetName(), pTask->GetName()); | |
476 | } else { | |
477 | //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task \"%s\" independend of \"%s\"", GetName(), pTask->GetName()); | |
478 | } | |
479 | } else { | |
480 | iResult=-EFAULT; | |
481 | } | |
482 | } else { | |
483 | iResult=-EINVAL; | |
484 | } | |
485 | return iResult; | |
486 | } | |
487 | ||
488 | AliHLTTask* AliHLTTask::FindTarget(const char* id) | |
489 | { | |
490 | AliHLTTask* pTask=NULL; | |
491 | if (id) { | |
492 | pTask=(AliHLTTask*)fListTargets.FindObject(id); | |
493 | } | |
494 | return pTask; | |
495 | } | |
496 | ||
497 | int AliHLTTask::SetTarget(AliHLTTask* pTgt) | |
498 | { | |
499 | int iResult=0; | |
500 | if (pTgt) { | |
501 | if (FindTarget(pTgt->GetName())==NULL) { | |
502 | fListTargets.Add(pTgt); | |
503 | } else { | |
504 | iResult=-EEXIST; | |
505 | } | |
506 | } else { | |
507 | iResult=-EINVAL; | |
508 | } | |
509 | return iResult; | |
510 | } | |
511 | ||
512 | int AliHLTTask::BuildBlockDataArray(AliHLTComponent_BlockData*& pTgt) | |
513 | { | |
514 | int iResult=0; | |
515 | return iResult; | |
516 | } | |
517 | ||
518 | ||
519 | // int AliHLTTask::ProcessTask(...) | |
520 | // { | |
521 | // int iResult=0; | |
522 | // return iResult; | |
523 | // } | |
524 | ||
525 | ||
526 | int AliHLTTask::ClearSourceBlocks() | |
527 | { | |
528 | int iResult=0; | |
529 | return iResult; | |
530 | } | |
531 | ||
532 | void AliHLTTask::PrintStatus() | |
533 | { | |
534 | if (fpComponent) { | |
535 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " component: %s (%p)", fpComponent->GetComponentID(), fpComponent); | |
536 | } else { | |
537 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " no component set!"); | |
538 | } | |
539 | if (fpConfiguration) { | |
540 | AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource(); | |
541 | while (pSrc) { | |
542 | const char* pQualifier="unresolved"; | |
543 | if (FindDependency(pSrc->GetName())) | |
544 | pQualifier="resolved"; | |
545 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " source: %s (%s)", pSrc->GetName(), pQualifier); | |
546 | pSrc=fpConfiguration->GetNextSource(); | |
547 | } | |
548 | TObjLink* lnk = fListTargets.FirstLink(); | |
549 | while (lnk) { | |
550 | TObject *obj = lnk->GetObject(); | |
551 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " target: %s", obj->GetName()); | |
552 | lnk = lnk->Next(); | |
553 | } | |
554 | } else { | |
555 | Logging(kHLTLogInfo, "BASE", "AliHLTTask", " task \"%s\" not initialized", GetName()); | |
556 | } | |
557 | } | |
558 | ||
559 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
560 | ||
561 | TList AliHLTConfigurationHandler::fListConfigurations; | |
562 | TList AliHLTConfigurationHandler::fListDynamicConfigurations; | |
563 | ||
564 | ClassImp(AliHLTConfigurationHandler) | |
565 | ||
566 | AliHLTConfigurationHandler::AliHLTConfigurationHandler() | |
567 | { | |
568 | } | |
569 | ||
570 | AliHLTConfigurationHandler::~AliHLTConfigurationHandler() | |
571 | { | |
572 | TObjLink* lnk=fListDynamicConfigurations.FirstLink(); | |
573 | while (lnk) { | |
574 | TObject* obj=lnk->GetObject(); | |
575 | if (fListConfigurations.FindObject(obj->GetName())==NULL) { | |
576 | Logging(kHLTLogDebug, "BASE", "Configuration Handler", "delete dynamic configuration \"%s\"", obj->GetName()); | |
577 | delete obj; | |
578 | } | |
579 | lnk=lnk->Next(); | |
580 | } | |
581 | } | |
582 | ||
583 | int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf) | |
584 | { | |
585 | int iResult=0; | |
586 | if (pConf) { | |
587 | if (FindConfiguration(pConf->GetName()) == NULL) { | |
588 | fListConfigurations.Add(pConf); | |
589 | //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "configuration \"%s\" registered", pConf->GetName()); | |
590 | ||
591 | // mark all configurations with unresolved dependencies for re-evaluation | |
592 | TObjLink* lnk=fListConfigurations.FirstLink(); | |
593 | while (lnk) { | |
594 | AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject(); | |
595 | if (pSrc && pSrc!=pConf && pSrc->SourcesResolved()!=1) { | |
596 | pSrc->InvalidateSources(); | |
597 | } | |
598 | lnk=lnk->Next(); | |
599 | } | |
600 | } else { | |
601 | iResult=-EEXIST; | |
602 | Logging(kHLTLogWarning, "BASE", "Configuration Handler", "configuration \"%s\" already registered", pConf->GetName()); | |
603 | } | |
604 | } else { | |
605 | iResult=-EINVAL; | |
606 | } | |
607 | return iResult; | |
608 | } | |
609 | ||
610 | int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments) | |
611 | { | |
612 | int iResult=0; | |
613 | AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments); | |
614 | if (pConf) { | |
615 | // the configuration will be registered automatically, if this failes the configuration | |
616 | // is missing -> delete it | |
617 | if (FindConfiguration(id)==NULL) { | |
618 | delete pConf; | |
619 | pConf=NULL; | |
620 | iResult=-EEXIST; | |
621 | } else { | |
622 | fListDynamicConfigurations.Add(pConf); | |
623 | } | |
624 | } else { | |
625 | Logging(kHLTLogError, "BASE", "Configuration Handler", "system error: object allocation failed"); | |
626 | iResult=-ENOMEM; | |
627 | } | |
628 | return iResult; | |
629 | } | |
630 | ||
631 | void AliHLTConfigurationHandler::PrintConfigurations() | |
632 | { | |
633 | Logging(kHLTLogInfo, "BASE", "Configuration Handler", "registered configurations:"); | |
634 | TObjLink *lnk = fListConfigurations.FirstLink(); | |
635 | while (lnk) { | |
636 | TObject *obj = lnk->GetObject(); | |
637 | Logging(kHLTLogInfo, "BASE", "Configuration Handler", " %s", obj->GetName()); | |
638 | lnk = lnk->Next(); | |
639 | } | |
640 | } | |
641 | ||
642 | int AliHLTConfigurationHandler::RemoveConfiguration(const char* id) | |
643 | { | |
644 | int iResult=0; | |
645 | if (id) { | |
646 | AliHLTConfiguration* pConf=NULL; | |
647 | if ((pConf=FindConfiguration(id))!=NULL) { | |
648 | iResult=RemoveConfiguration(pConf); | |
649 | } else { | |
650 | Logging(kHLTLogWarning, "BASE", "Configuration Handler", "can not find configuration \"%s\"", id); | |
651 | iResult=-ENOENT; | |
652 | } | |
653 | } else { | |
654 | iResult=-EINVAL; | |
655 | } | |
656 | return iResult; | |
657 | } | |
658 | ||
659 | int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf) | |
660 | { | |
661 | int iResult=0; | |
662 | if (pConf) { | |
663 | // remove the configuration from the list | |
664 | fListConfigurations.Remove(pConf); | |
665 | // remove cross links in the remaining configurations | |
666 | TObjLink* lnk=fListConfigurations.FirstLink(); | |
667 | while (lnk && iResult>=0) { | |
668 | AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject(); | |
669 | if (pRem) { | |
670 | pRem->InvalidateSource(pConf); | |
671 | } else { | |
672 | iResult=-EFAULT; | |
673 | } | |
674 | lnk=lnk->Next(); | |
675 | } | |
676 | } | |
677 | return iResult; | |
678 | } | |
679 | ||
680 | AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id) | |
681 | { | |
682 | AliHLTConfiguration* pConf=NULL; | |
683 | if (id) { | |
684 | pConf=(AliHLTConfiguration*)fListConfigurations.FindObject(id); | |
685 | } | |
686 | return pConf; | |
687 | } | |
688 |