]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 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 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
f23a6e1a | 8 | * for The ALICE Off-line Project. * |
9 | * * | |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
b22e91eb | 19 | /** @file AliHLTComponentHandler.cxx |
20 | @author Matthias Richter, Timm Steinbeck | |
21 | @date | |
22 | @brief Implementation of HLT component handler. */ | |
f23a6e1a | 23 | |
0c0c9d99 | 24 | #if __GNUC__>= 3 |
f23a6e1a | 25 | using namespace std; |
26 | #endif | |
53feaef5 | 27 | //#undef HAVE_DLFCN_H |
28 | #ifdef HAVE_DLFCN_H | |
f23a6e1a | 29 | #include <dlfcn.h> |
53feaef5 | 30 | #else |
31 | //#include <Riostream.h> | |
32 | #include <TSystem.h> | |
33 | #endif //HAVE_DLFCN_H | |
85869391 | 34 | #include "AliHLTStdIncludes.h" |
f23a6e1a | 35 | #include "AliHLTComponentHandler.h" |
36 | #include "AliHLTComponent.h" | |
37 | #include "AliHLTDataTypes.h" | |
38 | #include "AliHLTSystem.h" | |
39 | ||
b22e91eb | 40 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 41 | ClassImp(AliHLTComponentHandler) |
42 | ||
43 | AliHLTComponentHandler::AliHLTComponentHandler() | |
85869391 | 44 | : |
45 | fComponentList(), | |
46 | fScheduleList(), | |
47 | fLibraryList(), | |
48 | fEnvironment() | |
f23a6e1a | 49 | { |
85869391 | 50 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
f23a6e1a | 51 | } |
52 | ||
f23a6e1a | 53 | AliHLTComponentHandler::~AliHLTComponentHandler() |
54 | { | |
55 | UnloadLibraries(); | |
56 | } | |
57 | ||
fa760045 | 58 | int AliHLTComponentHandler::AnnounceVersion() |
59 | { | |
60 | int iResult=0; | |
61 | #ifdef PACKAGE_STRING | |
62 | void HLTbaseCompileInfo( char*& date, char*& time); | |
63 | char* date=""; | |
64 | char* time=""; | |
65 | HLTbaseCompileInfo(date, time); | |
66 | if (!date) date="unknown"; | |
67 | if (!time) time="unknown"; | |
68 | HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time); | |
69 | #else | |
70 | HLTInfo("ALICE High Level Trigger (embedded AliRoot build)"); | |
71 | #endif | |
72 | return iResult; | |
73 | } | |
74 | ||
f23a6e1a | 75 | Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample) |
76 | { | |
77 | Int_t iResult=0; | |
78 | if (pSample) { | |
79 | if (FindComponent(pSample->GetComponentID())==NULL) { | |
80 | iResult=InsertComponent(pSample); | |
81 | if (iResult>=0) { | |
85465857 | 82 | HLTInfo("component %s registered", pSample->GetComponentID()); |
f23a6e1a | 83 | } |
84 | } else { | |
85 | // component already registered | |
fa760045 | 86 | HLTDebug("component %s already registered, skipped", pSample->GetComponentID()); |
f23a6e1a | 87 | iResult=-EEXIST; |
88 | } | |
89 | } else { | |
90 | iResult=-EINVAL; | |
91 | } | |
92 | return iResult; | |
93 | } | |
94 | ||
95 | int AliHLTComponentHandler::DeregisterComponent( const char* componentID ) | |
96 | { | |
53feaef5 | 97 | int iResult=0; |
98 | if (componentID) { | |
99 | } else { | |
100 | iResult=-EINVAL; | |
101 | } | |
102 | return iResult; | |
f23a6e1a | 103 | } |
104 | ||
105 | Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample) | |
106 | { | |
107 | Int_t iResult=0; | |
108 | if (pSample) { | |
109 | fScheduleList.push_back(pSample); | |
110 | } else { | |
111 | iResult=-EINVAL; | |
112 | } | |
113 | return iResult; | |
114 | } | |
115 | ||
2d7ff710 | 116 | int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component ) |
f23a6e1a | 117 | { |
118 | int iResult=0; | |
119 | if (componentID) { | |
120 | AliHLTComponent* pSample=FindComponent(componentID); | |
121 | if (pSample!=NULL) { | |
122 | component=pSample->Spawn(); | |
123 | if (component) { | |
85465857 | 124 | HLTDebug("component \"%s\" created (%p)", componentID, component); |
2d7ff710 | 125 | if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) { |
84645eb0 | 126 | HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult); |
127 | delete component; | |
128 | component=NULL; | |
129 | } | |
5ec8e281 | 130 | } else { |
85465857 | 131 | HLTError("can not spawn component \"%s\"", componentID); |
5ec8e281 | 132 | iResult=-ENOENT; |
f23a6e1a | 133 | } |
5ec8e281 | 134 | } else { |
85465857 | 135 | HLTWarning("can not find component \"%s\"", componentID); |
5ec8e281 | 136 | iResult=-ENOENT; |
f23a6e1a | 137 | } |
138 | } else { | |
139 | iResult=-EINVAL; | |
140 | } | |
141 | return iResult; | |
142 | } | |
143 | ||
db16520a | 144 | Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID) |
f23a6e1a | 145 | { |
146 | Int_t iResult=0; | |
147 | if (componentID) { | |
148 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); | |
149 | while (element!=fComponentList.end() && iResult>=0) { | |
150 | if (strcmp(componentID, (*element)->GetComponentID())==0) { | |
151 | break; | |
152 | } | |
153 | element++; | |
154 | iResult++; | |
155 | } | |
156 | if (element==fComponentList.end()) iResult=-ENOENT; | |
157 | } else { | |
158 | iResult=-EINVAL; | |
159 | } | |
160 | return iResult; | |
161 | } | |
162 | ||
db16520a | 163 | AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID) |
f23a6e1a | 164 | { |
165 | AliHLTComponent* pSample=NULL; | |
166 | Int_t index=FindComponentIndex(componentID); | |
167 | if (index>=0) { | |
168 | pSample=(AliHLTComponent*)fComponentList.at(index); | |
169 | } | |
170 | return pSample; | |
171 | } | |
172 | ||
173 | Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample) | |
174 | { | |
175 | Int_t iResult=0; | |
176 | if (pSample!=NULL) { | |
177 | fComponentList.push_back(pSample); | |
178 | } else { | |
179 | iResult=-EINVAL; | |
180 | } | |
181 | return iResult; | |
182 | } | |
183 | ||
184 | void AliHLTComponentHandler::List() { | |
185 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); | |
186 | int index=0; | |
187 | while (element!=fComponentList.end()) { | |
85465857 | 188 | HLTInfo("%d. %s", index++, (*element++)->GetComponentID()); |
f23a6e1a | 189 | } |
190 | } | |
191 | ||
192 | void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) { | |
193 | if (pEnv) { | |
194 | memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment)); | |
bb16cc41 | 195 | AliHLTLogging::Init(fEnvironment.fLoggingFunc); |
f23a6e1a | 196 | } |
197 | } | |
198 | ||
199 | int AliHLTComponentHandler::LoadLibrary( const char* libraryPath ) | |
200 | { | |
201 | int iResult=0; | |
202 | if (libraryPath) { | |
203 | AliHLTComponent::SetGlobalComponentHandler(this); | |
53feaef5 | 204 | AliHLTLibHandle hLib=NULL; |
205 | #ifdef HAVE_DLFCN_H | |
206 | // use interface to the dynamic linking loader | |
207 | hLib=dlopen(libraryPath, RTLD_NOW); | |
208 | #else | |
209 | // use ROOT dynamic loader | |
210 | if (gSystem->Load(libraryPath)==0) { | |
211 | // create TString object to store library path and use pointer as handle | |
212 | hLib=reinterpret_cast<AliHLTLibHandle>(new TString(libraryPath)); | |
213 | } | |
214 | #endif //HAVE_DLFCN_H | |
f23a6e1a | 215 | if (hLib) { |
fa760045 | 216 | HLTInfo("library %s loaded", libraryPath); |
f23a6e1a | 217 | fLibraryList.push_back(hLib); |
218 | vector<AliHLTComponent*>::iterator element=fScheduleList.begin(); | |
219 | int iSize=fScheduleList.size(); | |
220 | int iLocalResult=0; | |
221 | while (iSize-- > 0) { | |
222 | element=fScheduleList.begin(); | |
223 | iLocalResult=RegisterComponent(*element); | |
224 | if (iResult==0) iResult=iLocalResult; | |
225 | fScheduleList.erase(element); | |
226 | } | |
227 | } else { | |
85465857 | 228 | HLTError("can not load library %s", libraryPath); |
53feaef5 | 229 | #ifdef HAVE_DLFCN_H |
85465857 | 230 | HLTError("dlopen error: %s", dlerror()); |
53feaef5 | 231 | #endif //HAVE_DLFCN_H |
0fe88043 | 232 | #ifdef __APPLE__ |
233 | iResult=-EFTYPE; | |
234 | #else | |
f23a6e1a | 235 | iResult=-ELIBACC; |
0fe88043 | 236 | #endif |
f23a6e1a | 237 | } |
2bbbadd1 | 238 | AliHLTComponent::UnsetGlobalComponentHandler(); |
f23a6e1a | 239 | } else { |
240 | iResult=-EINVAL; | |
241 | } | |
242 | return iResult; | |
243 | } | |
244 | ||
245 | int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath ) | |
246 | { | |
247 | int iResult=0; | |
53feaef5 | 248 | if (libraryPath) { |
249 | } else { | |
250 | iResult=-EINVAL; | |
251 | } | |
f23a6e1a | 252 | return iResult; |
253 | } | |
254 | ||
255 | int AliHLTComponentHandler::UnloadLibraries() | |
256 | { | |
257 | int iResult=0; | |
258 | vector<AliHLTLibHandle>::iterator element=fLibraryList.begin(); | |
259 | while (element!=fLibraryList.end()) { | |
53feaef5 | 260 | #ifdef HAVE_DLFCN_H |
f23a6e1a | 261 | dlclose(*element); |
53feaef5 | 262 | #else |
263 | TString* libraryPath=reinterpret_cast<TString*>(*element); | |
264 | gSystem->Unload(libraryPath->Data()); | |
265 | delete libraryPath; | |
266 | #endif //HAVE_DLFCN_H | |
f23a6e1a | 267 | element++; |
268 | } | |
269 | return iResult; | |
270 | } |