• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

faspplugin/fasp/Transport.h (r4864/r3689)

Go to the documentation of this file.
00001 /********************************************************************
00002  * The Data Acquisition Backbone Core (DABC)
00003  ********************************************************************
00004  * Copyright (C) 2009-
00005  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
00006  * Planckstr. 1
00007  * 64291 Darmstadt
00008  * Germany
00009  * Contact:  http://dabc.gsi.de
00010  ********************************************************************
00011  * This software can be used under the GPL license agreements as stated
00012  * in LICENSE.txt file which is part of the distribution.
00013  ********************************************************************/
00014 
00015 #ifndef FASP_Transport
00016 #define FASP_Transport
00017 
00018 #ifndef DABC_SocketThread
00019 #include "dabc/SocketThread.h"
00020 #endif
00021 
00022 #ifndef DABC_Transport
00023 #include "dabc/Transport.h"
00024 #endif
00025 
00026 #ifndef DABC_BuffersQueue
00027 #include "dabc/BuffersQueue.h"
00028 #endif
00029 
00030 #ifndef DABC_Pointer
00031 #include "dabc/Pointer.h"
00032 #endif
00033 
00034 #ifndef DABC_MemoryPool
00035 #include "dabc/MemoryPool.h"
00036 #endif
00037 
00038 // #include <netinet/in.h>              // EV obsolete ?
00039 #include <linux/if_packet.h>
00040 #include <sys/ioctl.h>
00041 #include <sys/socket.h>
00042 #include <net/if.h>
00043 #include <netinet/ether.h>
00044 
00045 namespace fasp {
00046 
00047    class Transport : public dabc::SocketWorker,
00048                      public dabc::Transport,
00049                      protected dabc::MemoryPoolRequester {
00050 
00051       DABC_TRANSPORT(dabc::SocketWorker)
00052 
00053       enum { BUF_SIZ = 1024 };
00054 
00055       enum { FaspBlockSize = 44, FaspSyncPos = 34 };
00056 
00057       enum { DummySync = 0xffffffff };
00058 
00059       protected:
00060 
00061          std::string fIfName;          // interface name like eth0
00062 
00063          int fSockfd;                                    // EV new socket id
00064          uint8_t fSendbuf[BUF_SIZ];                         //.EV buffer for sending data througth socket
00065          uint8_t fLastRecvedBlock[BUF_SIZ];                // Size should be 11 * 46 = 506
00066          struct sockaddr_ll fSockAddr;
00067 
00068          uint8_t fSourceMAC[6];                            // MAC address of itself
00069          uint8_t fDestMAC[6];                              // EV destination MAC adress
00070          double  fSendDelay;      // time delays between next send
00071          bool    fPlainData;       // store single packet in MBS event
00072 
00073 
00074          int rcvCounterNew;
00075          int rcvCounterDubl;
00076          
00077          dabc::TimeStamp    fLastFlushTime;
00078          dabc::TimeStamp    fLastSendTime;
00079 
00080          //struct sockaddr_in    fSockAddr;               // EV obsolete?
00081 
00082          size_t             fMTU;
00083          dabc::Mutex        fQueueMutex;
00084          dabc::BuffersQueue fQueue;
00085 
00086          dabc::Buffer       fTgtBuf;   // buffer for data
00087          dabc::Pointer      fHdrPtr;   // pointer on header
00088          dabc::Pointer      fDataPtr;   // pointer on next raw data
00089          unsigned           fBufferSize;
00090          unsigned           fRawSync;  // currently accumulated sync number
00091          
00092 
00093          dabc::MemoryPoolRef fPool;  // reference on the pool, reference should help us to preserve pool as long as we are using it
00094 
00095          double             fFlushTimeout;  // timeout for controls parameter update
00096 
00097          //virtual bool ReplyCommand(dabc::Command cmd);
00098 
00099          virtual void ProcessPoolChanged(dabc::MemoryPool* pool) {}
00100 
00101          virtual bool ProcessPoolRequest();
00102 
00103          virtual double ProcessTimeout(double lastdiff);
00104 
00105          void ConfigureFor(dabc::Port* port, dabc::Command cmd);
00106 
00108          bool ReadFromSocket();
00109 
00110          void WriteToSocket();
00111 
00112          void setFlushTimeout(double tmout) { fFlushTimeout = tmout; }
00113          double getFlushTimeout() const {  return fFlushTimeout; }
00114 
00115          /* Switch to next dabc buffer, put old one into receive queue
00116           * copyspanning will copy a spanning hadtu fragment from old to new buffers*/
00117          void FlushBuffer(bool force = false);
00118 
00119          // close current MBS event
00120          void CloseCurrentEvent();
00121 
00122       public:
00123          Transport(dabc::Reference port, dabc::Command cmd);
00124          virtual ~Transport();
00125 
00126          bool IsRawSocket() const { return fSockfd > 0; }
00127 
00128          virtual void ProcessEvent(const dabc::EventId&);
00129 
00130 
00131          virtual bool ProvidesInput() { return true; }
00132          virtual bool ProvidesOutput() { return false; }
00133 
00134          virtual bool Recv(dabc::Buffer& buf);
00135          virtual unsigned  RecvQueueSize() const;
00136          virtual dabc::Buffer& RecvBuffer(unsigned indx) const;
00137          virtual bool Send(const dabc::Buffer& buf) { return false; }
00138          virtual unsigned SendQueueSize() { return 0; }
00139          virtual unsigned MaxSendSegments() { return 0; }
00140 
00141          virtual void StartTransport();
00142          virtual void StopTransport();
00143    };
00144 }
00145 
00146 #endif

Generated on Tue Dec 10 2013 04:52:22 for ROCsoft by  doxygen 1.7.1