DABC (Data Acquisition Backbone Core)  2.9.9
NetworkTransport.h
Go to the documentation of this file.
1 // $Id: NetworkTransport.h 4472 2020-04-15 13:33:18Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_NetworkTransport
17 #define DABC_NetworkTransport
18 
19 #ifndef DABC_Transport
20 #include "dabc/Transport.h"
21 #endif
22 
23 namespace dabc {
24 
33  public:
34 
35  virtual ~NetworkInetrface() {}
36 
37  virtual void AllocateNet(unsigned fulloutputqueue, unsigned fullinputqueue) = 0;
38 
39  virtual void SubmitSend(uint32_t recid) = 0;
40  virtual void SubmitRecv(uint32_t recid) = 0;
41  };
42 
43  // ___________________________________________________________________
44 
53  class NetworkTransport : public Transport {
54  public:
55 
56  struct NetIORec {
57  bool used;
58  uint32_t kind;
59  uint32_t extras; // remake with use of unions
61  void* header;
62  void* inlinebuf;
63 
64  NetIORec() : used(false), kind(0), extras(0), buf(), header(0), inlinebuf(0) {}
65  };
66 
67  #pragma pack(1)
68  struct NetworkHeader {
69  uint32_t chkword;
70  uint32_t kind;
71  uint32_t typid;
72  uint32_t size;
73  };
74  #pragma pack(0)
75 
77  netot_Send = 0x001U,
78  netot_Recv = 0x002U,
79  netot_HdrSend = 0x004U // use to send only network header without any additional data
80  };
81 
82  protected:
84 
86 
87  uint32_t fTransportId;
88 
89  bool fUseAckn;
90  unsigned fInputQueueCapacity; // capacity of input queue
91  unsigned fOutputQueueCapacity; // capacity of output queue
92 
93  uint32_t fNumRecs;
94  uint32_t fRecsCounter;
97 
98  unsigned fOutputQueueSize; // number of output operations, submitted to the records
99  unsigned fAcknAllowedOper;
101  bool fAcknSendBufBusy; // indicate if ackn sending is under way
102 
103  unsigned fInputQueueSize; // total number of buffers, using for receiving : in device recv queue and input queue, not yet cleaned by user
104  bool fFirstAckn; // indicates, if first ackn packet was send or not
105  unsigned fAcknReadyCounter; // counter of submitted to device recv packets
106 
107  BufferSize_t fFullHeaderSize; // total header size
108  BufferSize_t fInlineDataSize; // part of the header, which can be used for inline data (in the end of header)
109 
111 
112  uint32_t TakeRec(Buffer& buf, uint32_t kind = 0, uint32_t extras = 0);
113  void ReleaseRec(uint32_t recid);
114 
115  void FillRecvQueue(Buffer* freebuf = 0, bool onlyfreebuf = false);
116  bool CheckAcknReadyCounter(unsigned newitems = 0);
118 
119  // methods inherited from the module
120  virtual void OnThreadAssigned();
121  virtual void ProcessInputEvent(unsigned port);
122  virtual void ProcessOutputEvent(unsigned port);
123  virtual void ProcessPoolEvent(unsigned pool);
124  virtual void ProcessTimerEvent(unsigned timer);
125 
126  // methods inherited from transport
127  virtual bool StartTransport();
128  virtual bool StopTransport();
129 
130  virtual void TransportCleanup();
131 
132  public:
133  virtual const char* ClassName() const { return "NetworkTransport"; }
134 
135  NetworkTransport(dabc::Command cmd, const PortRef& inpport, const PortRef& outport,
136  bool useackn, WorkerAddon* addon);
137  virtual ~NetworkTransport();
138 
139  unsigned GetFullHeaderSize() const { return fFullHeaderSize; }
140 
145  std::string TransportPoolName() const { return PoolName(); }
146 
147  // methods should be available for NetworkAdons for back-calls
148  void SetRecHeader(uint32_t recid, void* header);
149  int PackHeader(uint32_t recid);
150 
151  unsigned NumRecs() const { return fNumRecs; }
152  NetIORec* GetRec(unsigned id) const { return id < fNumRecs ? fRecs + id : 0; }
153 
154  void ProcessSendCompl(uint32_t recid);
155  void ProcessRecvCompl(uint32_t recid);
156 
157  static void GetRequiredQueuesSizes(const PortRef& port, unsigned& input_size, unsigned& output_size);
158  static bool Make(const ConnectionRequest& req, WorkerAddon* addon, const std::string &devthrdname = "");
159  };
160 
161 
162 }
163 
164 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
Connection request.
std::string PoolName(unsigned indx=0, bool fullname=false) const
Definition: Module.cxx:195
Network interface.
virtual void SubmitRecv(uint32_t recid)=0
virtual void AllocateNet(unsigned fulloutputqueue, unsigned fullinputqueue)=0
virtual void SubmitSend(uint32_t recid)=0
Network transport.
std::string TransportPoolName() const
Provides name of memory pool, used by transport.
void SetRecHeader(uint32_t recid, void *header)
uint32_t TakeRec(Buffer &buf, uint32_t kind=0, uint32_t extras=0)
NetworkInetrface * fNet
virtual void ProcessPoolEvent(unsigned pool)
Method called by framework when pool event is produced.
void ReleaseRec(uint32_t recid)
Queue< uint32_t > NetIORecsQueue
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
virtual void TransportCleanup()
bool fStartBufReq
if true, request to memory pool was started and one should wait until it is finished
virtual bool StartTransport()
Methods activated by Port, when transport starts/stops.
NetIORec * GetRec(unsigned id) const
void FillRecvQueue(Buffer *freebuf=0, bool onlyfreebuf=false)
unsigned GetFullHeaderSize() const
virtual void ProcessInputEvent(unsigned port)
Method called by framework when input event is produced.
void ProcessRecvCompl(uint32_t recid)
virtual void OnThreadAssigned()
virtual const char * ClassName() const
Returns class name of the object.
bool CheckAcknReadyCounter(unsigned newitems=0)
void ProcessSendCompl(uint32_t recid)
NetIORecsQueue fAcknSendQueue
NetworkTransport(dabc::Command cmd, const PortRef &inpport, const PortRef &outport, bool useackn, WorkerAddon *addon)
int PackHeader(uint32_t recid)
unsigned NumRecs() const
static bool Make(const ConnectionRequest &req, WorkerAddon *addon, const std::string &devthrdname="")
virtual void ProcessOutputEvent(unsigned port)
Method called by framework when output event is produced.
static void GetRequiredQueuesSizes(const PortRef &port, unsigned &input_size, unsigned &output_size)
Reference on the dabc::Port class
Definition: Port.h:195
Base class for transport implementations.
Definition: Transport.h:37
Generic addon for dabc::Worker.
Definition: Worker.h:49
Event manipulation API.
Definition: api.h:23
uint32_t BufferSize_t
Definition: Buffer.h:32