]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponentHandler.cxx
- adaption to gcc >=3
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.cxx
CommitLineData
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> *
8 * Artur Szostak <artursz@iafrica.com> *
9 * for The ALICE Off-line Project. *
10 * *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// handler class for HLT analysis components //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
0c0c9d99 26#if __GNUC__>= 3
f23a6e1a 27using namespace std;
28#endif
29
a5854ddd 30#include <cerrno>
31#include <string>
f23a6e1a 32#include <dlfcn.h>
33#include "AliL3StandardIncludes.h"
34#include "AliHLTComponentHandler.h"
35#include "AliHLTComponent.h"
36#include "AliHLTDataTypes.h"
37#include "AliHLTSystem.h"
38
39ClassImp(AliHLTComponentHandler)
40
41AliHLTComponentHandler::AliHLTComponentHandler()
42{
43}
44
45
46AliHLTComponentHandler::~AliHLTComponentHandler()
47{
48 UnloadLibraries();
49}
50
51Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
52{
53 Int_t iResult=0;
54 if (pSample) {
55 if (FindComponent(pSample->GetComponentID())==NULL) {
56 iResult=InsertComponent(pSample);
57 if (iResult>=0) {
85465857 58 HLTInfo("component %s registered", pSample->GetComponentID());
f23a6e1a 59 }
60 } else {
61 // component already registered
85465857 62 HLTInfo("component %s already registered, skipped", pSample->GetComponentID());
f23a6e1a 63 iResult=-EEXIST;
64 }
65 } else {
66 iResult=-EINVAL;
67 }
68 return iResult;
69}
70
71int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
72{
73 return 0;
74}
75
76Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
77{
78 Int_t iResult=0;
79 if (pSample) {
80 fScheduleList.push_back(pSample);
81 } else {
82 iResult=-EINVAL;
83 }
84 return iResult;
85}
86
87int AliHLTComponentHandler::CreateComponent(const Char_t* componentID, void* environ_param, int argc, const char** argv, AliHLTComponent*& component )
88{
89 int iResult=0;
90 if (componentID) {
91 AliHLTComponent* pSample=FindComponent(componentID);
92 if (pSample!=NULL) {
93 component=pSample->Spawn();
94 if (component) {
85465857 95 HLTDebug("component \"%s\" created (%p)", componentID, component);
f23a6e1a 96 component->Init(&fEnvironment, environ_param, argc, argv);
5ec8e281 97 } else {
85465857 98 HLTError("can not spawn component \"%s\"", componentID);
5ec8e281 99 iResult=-ENOENT;
f23a6e1a 100 }
5ec8e281 101 } else {
85465857 102 HLTWarning("can not find component \"%s\"", componentID);
5ec8e281 103 iResult=-ENOENT;
f23a6e1a 104 }
105 } else {
106 iResult=-EINVAL;
107 }
108 return iResult;
109}
110
111Int_t AliHLTComponentHandler::FindComponentIndex(const Char_t* componentID)
112{
113 Int_t iResult=0;
114 if (componentID) {
115 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
116 while (element!=fComponentList.end() && iResult>=0) {
117 if (strcmp(componentID, (*element)->GetComponentID())==0) {
118 break;
119 }
120 element++;
121 iResult++;
122 }
123 if (element==fComponentList.end()) iResult=-ENOENT;
124 } else {
125 iResult=-EINVAL;
126 }
127 return iResult;
128}
129
130AliHLTComponent* AliHLTComponentHandler::FindComponent(const Char_t* componentID)
131{
132 AliHLTComponent* pSample=NULL;
133 Int_t index=FindComponentIndex(componentID);
134 if (index>=0) {
135 pSample=(AliHLTComponent*)fComponentList.at(index);
136 }
137 return pSample;
138}
139
140Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
141{
142 Int_t iResult=0;
143 if (pSample!=NULL) {
144 fComponentList.push_back(pSample);
145 } else {
146 iResult=-EINVAL;
147 }
148 return iResult;
149}
150
151void AliHLTComponentHandler::List() {
152 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
153 int index=0;
154 while (element!=fComponentList.end()) {
85465857 155 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
f23a6e1a 156 }
157}
158
159void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
160 if (pEnv) {
161 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
bb16cc41 162 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
f23a6e1a 163 }
164}
165
166int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
167{
168 int iResult=0;
169 if (libraryPath) {
170 AliHLTComponent::SetGlobalComponentHandler(this);
171 AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
172 if (hLib) {
173 AliHLTComponent::UnsetGlobalComponentHandler();
85465857 174 HLTDebug("library %s loaded", libraryPath);
f23a6e1a 175 fLibraryList.push_back(hLib);
176 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
177 int iSize=fScheduleList.size();
178 int iLocalResult=0;
179 while (iSize-- > 0) {
180 element=fScheduleList.begin();
181 iLocalResult=RegisterComponent(*element);
182 if (iResult==0) iResult=iLocalResult;
183 fScheduleList.erase(element);
184 }
185 } else {
85465857 186 HLTError("can not load library %s", libraryPath);
187 HLTError("dlopen error: %s", dlerror());
f23a6e1a 188 iResult=-ELIBACC;
189 }
190 } else {
191 iResult=-EINVAL;
192 }
193 return iResult;
194}
195
196int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
197{
198 int iResult=0;
199 return iResult;
200}
201
202int AliHLTComponentHandler::UnloadLibraries()
203{
204 int iResult=0;
205 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
206 while (element!=fLibraryList.end()) {
207 dlclose(*element);
208 element++;
209 }
210 return iResult;
211}