]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
f23a6e1a | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
9 | * for The ALICE HLT Project. * | |
f23a6e1a | 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 | ||
b22e91eb | 20 | /** @file AliHLT_C_Component_WrapperInterface.cxx |
21 | @author Matthias Richter, Timm Steinbeck | |
22 | @date | |
23 | @brief Pure C interface to the AliRoot HLT component handler | |
24 | */ | |
f23a6e1a | 25 | |
0c0c9d99 | 26 | #if __GNUC__>= 3 |
f23a6e1a | 27 | using namespace std; |
28 | #endif | |
29 | ||
30 | #include "AliHLT_C_Component_WrapperInterface.h" | |
31 | #include "AliHLTComponentHandler.h" | |
32 | #include "AliHLTComponent.h" | |
33 | #include <errno.h> | |
34 | ||
35 | static AliHLTComponentHandler *gComponentHandler_C = NULL; | |
9a0ef890 | 36 | static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc; |
37 | static char* gRunType=NULL; | |
f23a6e1a | 38 | |
f7561f8d | 39 | int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv ) |
f23a6e1a | 40 | { |
41 | if ( gComponentHandler_C ) | |
42 | { | |
43 | return EINPROGRESS; | |
44 | } | |
9a0ef890 | 45 | |
46 | AliHLTComponentEnvironment internalEnv; | |
47 | memset(&internalEnv, 0, sizeof(internalEnv)); | |
48 | if (comenv) { | |
49 | memcpy(&internalEnv, comenv, sizeof(internalEnv)<comenv->fStructSize?sizeof(internalEnv):comenv->fStructSize); | |
50 | } | |
51 | internalEnv.fStructSize=sizeof(internalEnv); | |
52 | ||
3ff6ace7 | 53 | // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber |
54 | // the fStructSize member was never initialized and we can not use this | |
55 | // method of synchronizing different versions | |
56 | //gComponentHandler_C = new AliHLTComponentHandler(&internalEnv); | |
57 | gComponentHandler_C = new AliHLTComponentHandler(comenv); | |
f23a6e1a | 58 | if ( !gComponentHandler_C ) |
59 | return EFAULT; | |
a742f6f8 | 60 | gComponentHandler_C->InitAliLogTrap(gComponentHandler_C); |
fa760045 | 61 | gComponentHandler_C->AnnounceVersion(); |
f23a6e1a | 62 | return 0; |
63 | } | |
64 | ||
65 | int AliHLT_C_Component_DeinitSystem() | |
66 | { | |
67 | if ( gComponentHandler_C ) | |
68 | { | |
69 | delete gComponentHandler_C; | |
70 | gComponentHandler_C = NULL; | |
71 | } | |
72 | return 0; | |
73 | } | |
74 | ||
75 | int AliHLT_C_Component_LoadLibrary( const char* libraryPath ) | |
76 | { | |
77 | if ( !gComponentHandler_C ) | |
78 | return ENXIO; | |
79 | return gComponentHandler_C->LoadLibrary( libraryPath ); | |
80 | } | |
81 | ||
d76bc02a | 82 | int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ ) |
f23a6e1a | 83 | { |
84 | if ( !gComponentHandler_C ) | |
85 | return ENXIO; | |
cbd84228 | 86 | // Matthias 26.10.2007 |
87 | // Unloading of libraries has to be re-worked. It has been commented out here | |
88 | // since the libraries will be unloaded at the destruction of the component | |
89 | // handler instance anyway. So it has no effect to the operation in PubSub. | |
90 | // With the introduction of the dynamic component registration via module | |
91 | // agents we run into trouble when cleaning up the samples managed by the | |
92 | // component handler. Destruction of the sample objects is done AFTER | |
93 | // unloading of the library and thus the destructor is not present any | |
94 | // more. | |
95 | //return gComponentHandler_C->UnloadLibrary( libraryPath ); | |
96 | return 0; | |
f23a6e1a | 97 | } |
98 | ||
f7561f8d | 99 | int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle ) |
f23a6e1a | 100 | { |
101 | if ( !gComponentHandler_C ) | |
102 | return ENXIO; | |
3294f81a | 103 | if ( !handle ) return EINVAL; |
b2065764 | 104 | AliHLTComponent* comp=NULL; |
105 | const char* cdbPath = getenv("ALIHLT_HCDBDIR"); | |
106 | if (!cdbPath) cdbPath = getenv("ALICE_ROOT"); | |
9a0ef890 | 107 | int ret = gComponentHandler_C->CreateComponent( componentType, environParam, argc, argv, comp); |
108 | if (ret>=0 && comp) { | |
109 | comp->InitCDB(cdbPath, gComponentHandler_C); | |
110 | comp->SetRunDescription(&gRunDesc, gRunType); | |
111 | const AliHLTComponentEnvironment* comenv=gComponentHandler_C->GetEnvironment(); | |
9a0ef890 | 112 | ret=comp->Init(comenv, environParam, argc, argv); |
113 | } | |
f23a6e1a | 114 | *handle = reinterpret_cast<AliHLTComponentHandle>( comp ); |
3294f81a | 115 | |
f23a6e1a | 116 | return ret; |
117 | } | |
118 | ||
119 | void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle ) | |
120 | { | |
121 | if ( !handle ) | |
122 | return; | |
3cde846d | 123 | |
124 | AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle ); | |
125 | pComp->Deinit(); | |
126 | delete pComp; | |
f23a6e1a | 127 | } |
128 | ||
45c0a780 | 129 | int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType) |
130 | { | |
131 | if (!desc) return -EINVAL; | |
132 | if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL; | |
133 | if (!gComponentHandler_C) return ENXIO; | |
134 | ||
9a0ef890 | 135 | memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc)); |
136 | gRunDesc.fStructSize=sizeof(gRunDesc); | |
137 | if (gRunType) delete [] gRunType; | |
138 | gRunType=NULL; | |
139 | if (runType) { | |
140 | gRunType=new char[strlen(runType)+1]; | |
141 | if (gRunType) strcpy(gRunType, runType); | |
142 | } | |
143 | return 0; | |
45c0a780 | 144 | } |
145 | ||
f7561f8d | 146 | int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks, |
147 | AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr, | |
f23a6e1a | 148 | AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt, |
f7561f8d | 149 | AliHLTComponentBlockData** outputBlocks, |
150 | AliHLTComponentEventDoneData** edd ) | |
f23a6e1a | 151 | { |
152 | if ( !handle ) | |
153 | return ENXIO; | |
154 | AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle ); | |
71d7c760 | 155 | return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd ); |
156 | } | |
157 | ||
f7561f8d | 158 | int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType ) |
71d7c760 | 159 | { |
160 | if ( !handle ) | |
161 | return ENXIO; | |
162 | AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle ); | |
163 | *dataType = comp->GetOutputDataType(); | |
164 | return 0; | |
165 | } | |
166 | ||
167 | int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier ) | |
168 | { | |
169 | if ( !handle ) | |
170 | return ENXIO; | |
171 | AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle ); | |
172 | comp->GetOutputDataSize( *constBase, *inputMultiplier ); | |
173 | return 0; | |
f23a6e1a | 174 | } |