]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/HOMER/AliHLTHOMERReader.cxx
string.h instead of cstring on Solaris x86
[u/mrichter/AliRoot.git] / HLT / BASE / HOMER / AliHLTHOMERReader.cxx
index adb76ac79d2edfefcffad349a306cdd89e9132ac..2b9cb4375e40d66e2f964afd2ce9e2bc713d785f 100644 (file)
 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
 #include "AliHLTHOMERReader.h"
-#include <stdio.h>
+//#include <stdio.h>
+#ifdef __SUNPRO_CC
 #include <string.h>
-#include <errno.h>
+#else
+#include <cstring>
+#endif
+#include <cerrno>
 #include <netdb.h>
 extern int h_errno;
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
+//#include <sys/types.h>
+//#include <sys/socket.h>
+//#include <netinet/in.h>
+//#include <netinet/tcp.h>
 #include <unistd.h>
 #include <rpc/types.h>
 #include <fcntl.h>
@@ -68,6 +72,12 @@ extern int h_errno;
 #define GET_ONE "GET ONE\n"
 #define GET_ALL "GET ALL\n"
 
+// MAXHOSTNAMELEN not defined on macosx
+// 686-apple-darwin9-gcc-4.0.1
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 64
+#endif
+
 #ifdef USE_ROOT
 ClassImp(AliHLTMonitoringReader);
 ClassImp(AliHLTHOMERReader);
@@ -329,13 +339,12 @@ AliHLTHOMERReader::AliHLTHOMERReader( const void* pBuffer, int size )
        fConnectionStatus = ENOMEM;
        return;
        }
-    //fConnectionStatus = AddDataSource( shmKey, shmSize, fDataSources[0] );
+    fConnectionStatus = AddDataSource(const_cast<void*>(pBuffer), size, fDataSources[0] );
     if ( fConnectionStatus )
        fErrorConnection = 0;
     else
        {
        fDataSourceCnt++;
-       fShmDataSourceCnt++;
        fDataSources[0].fNdx = 0;
        }
     }
@@ -593,6 +602,7 @@ bool AliHLTHOMERReader::AllocDataSources( unsigned int sourceCnt )
     fDataSources = new DataSource[ sourceCnt ];
     if ( !fDataSources )
        return false;
+    memset(fDataSources, 0, sizeof(DataSource)*sourceCnt);
     fDataSourceCnt = 0;
     fDataSourceMaxCnt = sourceCnt;
     return true;
@@ -702,7 +712,7 @@ int AliHLTHOMERReader::AddDataSource( void* pBuffer, int size, DataSource& sourc
 // a buffer data source is like a shm source apart from the shm attach and detach
 // procedure. Furthermore, the size indicator at the beginning of the buffer is not
 // cleared right before sources are read but after the reading.
-    int ret;
+    //int ret;
     if ( !pBuffer || size<=0) return EINVAL;
 
     char* tmpchar = new char[ MAXHOSTNAMELEN+1 ];
@@ -769,7 +779,7 @@ int AliHLTHOMERReader::ReadNextEvent( bool useTimeout, unsigned long timeout )
        return ENXIO;
     // Clean up currently active event.
     ReleaseCurrentEvent();
-    int ret;
+    int ret=0;
     // Trigger all configured data sources
     for ( unsigned n = 0; n<fDataSourceCnt; n++ )
        {
@@ -811,11 +821,17 @@ int AliHLTHOMERReader::ReadNextEvent( bool useTimeout, unsigned long timeout )
     //Check to see that all sources contributed data for the same event
     homer_uint64 eventID;
     homer_uint64 eventType;
+    if (!fDataSources[0].fData)
+      {
+       fErrorConnection = 0;
+       fConnectionStatus=56;//ENOBUF;
+       return fConnectionStatus;
+      }
     eventID = GetSourceEventID( fDataSources[0] );
     eventType = GetSourceEventType( fDataSources[0] );
     for ( unsigned n = 1; n < fDataSourceCnt; n++ )
        {
-       if ( GetSourceEventID( fDataSources[n] ) != eventID || GetSourceEventType( fDataSources[n] ) != eventType )
+       if ( !fDataSources[n].fData || GetSourceEventID( fDataSources[n] ) != eventID || GetSourceEventType( fDataSources[n] ) != eventType )
            {
            fErrorConnection = n;
            fConnectionStatus=56;//EBADRQC;
@@ -852,7 +868,10 @@ void AliHLTHOMERReader::ReleaseCurrentEvent()
            {
            if ( fDataSources[n].fType == kTCP )
                delete [] (homer_uint8*)fDataSources[n].fData;
-           fDataSources[n].fData = NULL;
+           // do not reset the data pointer for kBuf sources since this
+           // can not be set again.
+           if ( fDataSources[n].fType != kBuf )
+             fDataSources[n].fData = NULL;
            }
        fDataSources[n].fDataSize = fDataSources[n].fDataRead = 0;
        }
@@ -932,7 +951,7 @@ int AliHLTHOMERReader::TriggerTCPSource( DataSource& source, bool useTimeout, un
     return 0;
     }
 
-int AliHLTHOMERReader::TriggerShmSource( DataSource& source, bool, unsigned long )
+int AliHLTHOMERReader::TriggerShmSource( DataSource& source, bool, unsigned long ) const
     {
 // see header file for class documentation
 // clear the size indicator in the first 4 bytes of the buffer to request data
@@ -1282,15 +1301,27 @@ homer_uint32 AliHLTHOMERReader::Swap( homer_uint8 destFormat, homer_uint8 source
        ((source & 0xFF000000UL) >> 24);
     }
 
-AliHLTHOMERReader* AliHLTHOMERReaderCreate(const void* pBuffer, int size)
+AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPort(const char* hostname, unsigned short port )
+    {
+      // see header file for function documentation
+      return new AliHLTHOMERReader(hostname, port);
+    }
+
+AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPorts(unsigned int tcpCnt, const char** hostnames, unsigned short* ports)
+    {
+      // see header file for function documentation
+      return new AliHLTHOMERReader(tcpCnt, hostnames, ports);
+    }
+
+AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer(const void* pBuffer, int size)
     {
-// see header file for function documentation
+      // see header file for function documentation
       return new AliHLTHOMERReader(pBuffer, size);
     }
 
 void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance)
     {
-// see header file for function documentation
+      // see header file for function documentation
       if (pInstance) delete pInstance;
     }