]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
Adding extra protection to prevent cycles in the Agent linked list, which can cause...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLT_C_Component_WrapperInterface.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9  *                  for The ALICE HLT 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 /** @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 */
25
26 #if __GNUC__>= 3
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;
36 static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
37 static char* gRunType=NULL;
38
39 int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
40 {
41   if ( gComponentHandler_C )
42     {
43       return EINPROGRESS;
44     }
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
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);
58   if ( !gComponentHandler_C )
59     return EFAULT;
60   gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
61   gComponentHandler_C->AnnounceVersion();
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
82 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
83 {
84   if ( !gComponentHandler_C )
85     return ENXIO;
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;
97 }
98
99 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
100 {
101   if ( !gComponentHandler_C )
102     return ENXIO;
103   if ( !handle ) return EINVAL;
104   AliHLTComponent* comp=NULL;
105   const char* cdbPath = getenv("ALIHLT_HCDBDIR");
106   if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
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();
112     ret=comp->Init(comenv, environParam, argc, argv);
113   }
114   *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
115
116   return ret;
117 }
118
119 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
120 {
121   if ( !handle )
122     return;
123   
124   AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
125   pComp->Deinit();
126   delete pComp;
127 }
128
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
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;
144 }
145
146 int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks, 
147                            AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
148                            AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt, 
149                            AliHLTComponentBlockData** outputBlocks,
150                            AliHLTComponentEventDoneData** edd )
151 {
152   if ( !handle )
153     return ENXIO;
154   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
155   return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
156 }
157
158 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
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;
174 }