ICP  1
TCPEventStreamer.h
Go to the documentation of this file.
1 #ifndef TCP_EVENT_STREAMER_H
2 #define TCP_EVENT_STREAMER_H
3 
4 #include "TCPEventStreamDefs.h"
5 
6 class CRPTProxy;
7 class EventStore;
8 
10 {
11 public:
12  virtual int numBytes() const = 0;
13  virtual int numBytesRemaining() const = 0;
14  virtual const unsigned char* currentBytes() const = 0;
15  virtual void advance(int offset) = 0;
16  virtual bool done() const = 0;
17  virtual TCPEventBuffer& operator=(const TCPEventBuffer& eb) = 0;
18  virtual ~TCPEventBuffer() { }
19 };
20 
21 template <typename T>
23 {
24 private:
25  uint32_t m_current_pos;
26  uint32_t m_num_bytes;
27  Poco::SharedPtr<T> m_ptr;
28  unsigned char* m_bytes;
29  TCPEventBufferT() { throw std::runtime_error("TCPEventBufferT"); }
30 
31 public:
33  TCPEventBufferT(T* b, uint32_t n) : m_current_pos(0), m_num_bytes(n*sizeof(T)), m_bytes(b), m_ptr(b) { }
34  virtual int numBytes() const { return m_num_bytes; }
35  virtual int numBytesRemaining() const { return m_num_bytes - m_current_pos; }
36  virtual const unsigned char* currentBytes() const { return (m_current_pos < m_num_bytes ? m_bytes + m_current_pos : NULL); }
37  virtual void advance(int offset) { m_current_pos += offset; }
38  virtual bool done() const { return m_current_pos >= m_num_bytes; }
40  {
41  if (this != &eb)
42  {
45  m_bytes = eb.m_bytes;
46  m_ptr = eb.m_ptr;
47  }
48  }
49 };
50 
51 class TCPEventStreamConnection : public Poco::Net::TCPServerConnection, ISIS::Base
52 {
53 private:
55  std::list<TCPStreamEventDataNeutron*> m_buffers;
58  Poco::RWLock m_lock;
59  uint32_t m_bytes_backlog;
60  const CRPTProxy& m_crpt;
61  static uint32_t MAX_BYTES_BACKLOG;
62 
63 public:
64  TCPEventStreamConnection(const Poco::Net::StreamSocket& s, EventStore& es, const CRPTProxy& crpt);
66  void run();
67  void allEventCallback(const DAEEventHeader* head, const DetectorEvent32* det_ev, int n, int event_source_id, const int* mapping);
68 };
69 
70 class TCPEventStreamConnectionFactory: public Poco::Net::TCPServerConnectionFactory
72 {
74  const CRPTProxy& m_crpt;
75 public:
76  TCPEventStreamConnectionFactory(EventStore& es, const CRPTProxy& crpt) : Poco::Net::TCPServerConnectionFactory(), m_es(es), m_crpt(crpt)
77  {
78  }
79 
80  Poco::Net::TCPServerConnection* createConnection(const Poco::Net::StreamSocket& socket)
81  {
82  return new TCPEventStreamConnection(socket, m_es, m_crpt);
83  }
84 };
85 
87 {
88  Poco::Net::ServerSocket* m_svs;
89  Poco::Net::TCPServer* m_srv;
90 // std::list<int> m_events;
92  const CRPTProxy& m_crpt;
93 public:
94  TCPEventStreamer(EventStore& es, const CRPTProxy& crpt);
96 };
97 
98 
99 #endif /* TCP_EVENT_STREAMER_H */
virtual void advance(int offset)=0
TCPEventBufferT(const TCPEventBufferT &eb)
uint32_t m_current_pos
TCPEventBufferT(T *b, uint32_t n)
void allEventCallback(const DAEEventHeader *head, const DetectorEvent32 *det_ev, int n, int event_source_id, const int *mapping)
fixed header marker for DAEEventHeader
Definition: dae_events.h:44
unsigned char * m_bytes
original data to send
Poco::Net::TCPServer * m_srv
virtual const unsigned char * currentBytes() const
virtual void advance(int offset)
virtual int numBytes() const =0
std::list< TCPStreamEventDataNeutron * > m_buffers
const CRPTProxy & m_crpt
virtual TCPEventBufferT & operator=(const TCPEventBufferT &eb)
TCPEventBufferT()
currrent byte offset
virtual bool done() const =0
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket &socket)
Poco::SharedPtr< T > m_ptr
total number of bytes to send
virtual TCPEventBuffer & operator=(const TCPEventBuffer &eb)=0
A factory for TimeServerConnection.
uint32_t m_num_bytes
current position in m_bytes stream
virtual bool done() const
virtual ~TCPEventBuffer()
EventStore & m_es
TCPEventStreamConnection(const Poco::Net::StreamSocket &s, EventStore &es, const CRPTProxy &crpt)
const CRPTProxy & m_crpt
static uint32_t MAX_BYTES_BACKLOG
Poco::Net::ServerSocket * m_svs
virtual int numBytes() const
virtual const unsigned char * currentBytes() const =0
TCPEventStreamConnectionFactory(EventStore &es, const CRPTProxy &crpt)
TCPEventStreamer(EventStore &es, const CRPTProxy &crpt)
virtual int numBytesRemaining() const =0
virtual int numBytesRemaining() const