]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponentHandler.cxx
- made package indepentend of src
[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> *
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 25using namespace std;
26#endif
27
f23a6e1a 28#include <dlfcn.h>
85869391 29#include "AliHLTStdIncludes.h"
f23a6e1a 30#include "AliHLTComponentHandler.h"
31#include "AliHLTComponent.h"
32#include "AliHLTDataTypes.h"
33#include "AliHLTSystem.h"
34
b22e91eb 35/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 36ClassImp(AliHLTComponentHandler)
37
38AliHLTComponentHandler::AliHLTComponentHandler()
85869391 39 :
40 fComponentList(),
41 fScheduleList(),
42 fLibraryList(),
43 fEnvironment()
f23a6e1a 44{
85869391 45 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
f23a6e1a 46}
47
f23a6e1a 48AliHLTComponentHandler::~AliHLTComponentHandler()
49{
50 UnloadLibraries();
51}
52
53Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
54{
55 Int_t iResult=0;
56 if (pSample) {
57 if (FindComponent(pSample->GetComponentID())==NULL) {
58 iResult=InsertComponent(pSample);
59 if (iResult>=0) {
85465857 60 HLTInfo("component %s registered", pSample->GetComponentID());
f23a6e1a 61 }
62 } else {
63 // component already registered
85465857 64 HLTInfo("component %s already registered, skipped", pSample->GetComponentID());
f23a6e1a 65 iResult=-EEXIST;
66 }
67 } else {
68 iResult=-EINVAL;
69 }
70 return iResult;
71}
72
73int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
74{
75 return 0;
76}
77
78Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
79{
80 Int_t iResult=0;
81 if (pSample) {
82 fScheduleList.push_back(pSample);
83 } else {
84 iResult=-EINVAL;
85 }
86 return iResult;
87}
88
b22e91eb 89int AliHLTComponentHandler::CreateComponent(const char* componentID, void* environ_param, int argc, const char** argv, AliHLTComponent*& component )
f23a6e1a 90{
91 int iResult=0;
92 if (componentID) {
93 AliHLTComponent* pSample=FindComponent(componentID);
94 if (pSample!=NULL) {
95 component=pSample->Spawn();
96 if (component) {
85465857 97 HLTDebug("component \"%s\" created (%p)", componentID, component);
f23a6e1a 98 component->Init(&fEnvironment, environ_param, argc, argv);
5ec8e281 99 } else {
85465857 100 HLTError("can not spawn component \"%s\"", componentID);
5ec8e281 101 iResult=-ENOENT;
f23a6e1a 102 }
5ec8e281 103 } else {
85465857 104 HLTWarning("can not find component \"%s\"", componentID);
5ec8e281 105 iResult=-ENOENT;
f23a6e1a 106 }
107 } else {
108 iResult=-EINVAL;
109 }
110 return iResult;
111}
112
113Int_t AliHLTComponentHandler::FindComponentIndex(const Char_t* componentID)
114{
115 Int_t iResult=0;
116 if (componentID) {
117 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
118 while (element!=fComponentList.end() && iResult>=0) {
119 if (strcmp(componentID, (*element)->GetComponentID())==0) {
120 break;
121 }
122 element++;
123 iResult++;
124 }
125 if (element==fComponentList.end()) iResult=-ENOENT;
126 } else {
127 iResult=-EINVAL;
128 }
129 return iResult;
130}
131
132AliHLTComponent* AliHLTComponentHandler::FindComponent(const Char_t* componentID)
133{
134 AliHLTComponent* pSample=NULL;
135 Int_t index=FindComponentIndex(componentID);
136 if (index>=0) {
137 pSample=(AliHLTComponent*)fComponentList.at(index);
138 }
139 return pSample;
140}
141
142Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
143{
144 Int_t iResult=0;
145 if (pSample!=NULL) {
146 fComponentList.push_back(pSample);
147 } else {
148 iResult=-EINVAL;
149 }
150 return iResult;
151}
152
153void AliHLTComponentHandler::List() {
154 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
155 int index=0;
156 while (element!=fComponentList.end()) {
85465857 157 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
f23a6e1a 158 }
159}
160
161void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
162 if (pEnv) {
163 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
bb16cc41 164 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
f23a6e1a 165 }
166}
167
168int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
169{
170 int iResult=0;
171 if (libraryPath) {
172 AliHLTComponent::SetGlobalComponentHandler(this);
173 AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
174 if (hLib) {
175 AliHLTComponent::UnsetGlobalComponentHandler();
85465857 176 HLTDebug("library %s loaded", libraryPath);
f23a6e1a 177 fLibraryList.push_back(hLib);
178 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
179 int iSize=fScheduleList.size();
180 int iLocalResult=0;
181 while (iSize-- > 0) {
182 element=fScheduleList.begin();
183 iLocalResult=RegisterComponent(*element);
184 if (iResult==0) iResult=iLocalResult;
185 fScheduleList.erase(element);
186 }
187 } else {
85465857 188 HLTError("can not load library %s", libraryPath);
189 HLTError("dlopen error: %s", dlerror());
f23a6e1a 190 iResult=-ELIBACC;
191 }
192 } else {
193 iResult=-EINVAL;
194 }
195 return iResult;
196}
197
198int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
199{
200 int iResult=0;
201 return iResult;
202}
203
204int AliHLTComponentHandler::UnloadLibraries()
205{
206 int iResult=0;
207 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
208 while (element!=fLibraryList.end()) {
209 dlclose(*element);
210 element++;
211 }
212 return iResult;
213}