DABC (Data Acquisition Backbone Core)  2.9.9
ServerTransport.h
Go to the documentation of this file.
1 // $Id: ServerTransport.h 4115 2018-10-05 08:24:43Z 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 MBS_ServerTransport
17 #define MBS_ServerTransport
18 
19 #ifndef DABC_Transport
20 #include "dabc/Transport.h"
21 #endif
22 
23 #ifndef DABC_SocketThread
24 #include "dabc/SocketThread.h"
25 #endif
26 
27 #ifndef DABC_DataIO
28 #include "dabc/DataIO.h"
29 #endif
30 
31 #ifndef DABC_eventsapi
32 #include "dabc/eventsapi.h"
33 #endif
34 
35 #ifndef MBS_MbsTypeDefs
36 #include "mbs/MbsTypeDefs.h"
37 #endif
38 
39 namespace mbs {
40 
44  public dabc::DataOutput {
45  protected:
46 
47  enum OutputState {
48  oInit, // when object created
49  oInitReq, // get request before init block was send
50  oWaitingReq, // waiting request from client
51  oWaitingReqBack, // waiting request from client and need to make call-back
53  oSendingEvents, // sending events
54  oSendingLastEvent, // waiting for completion of last event
57  oError
58  };
59 
61 
62  int fKind; // see EMbsServerKinds values
63  mbs::TransportInfo fServInfo; // data, send by transport server in the beginning
64  char f_sbuf[12]; // input buffer to get request
69  mbs::EventHeader fEvHdr; // additional MBS event header (for non-MBS events)
70  mbs::SubeventHeader fSubHdr; // additional MBS subevent header (for non-MBS events)
71  uint32_t fEvCounter; // special events counter
72  uint32_t fSubevId; // full id of subevent
74 
75  // from addon
76  virtual void OnThreadAssigned();
77  virtual void OnSendCompleted();
78  virtual void OnRecvCompleted();
79 
80  void MakeCallback(unsigned sz);
81 
82  virtual double ProcessTimeout(double last_diff);
83 
84  virtual void OnSocketError(int err, const std::string &info);
85 
86  virtual dabc::WorkerAddon* Write_GetAddon() { return this; }
87 
88  public:
89  ServerOutputAddon(int fd, int kind, dabc::EventsIteratorRef& iter, uint32_t subid);
90  virtual ~ServerOutputAddon();
91 
92  void FillServInfo(int32_t maxbytes, bool isnewformat);
93  void SetServerKind(int kind) { fKind = kind; }
94 
95  // code from the DataOutput
96  virtual unsigned Write_Check();
97  virtual unsigned Write_Buffer(dabc::Buffer& buf);
98  virtual double Write_Timeout() { return 0.1; }
99  };
100 
101 
102  // ===============================================================================
103 
107  protected:
108 
109  int fKind;
110  int fPortNum;
114  bool fBlocking;
115  bool fDeliverAll;
116  std::string fIterKind;
117  uint32_t fSubevId;
118 
119  virtual bool StartTransport();
120  virtual bool StopTransport();
121 
122  virtual int ExecuteCommand(dabc::Command cmd);
123 
124  virtual bool ProcessRecv(unsigned) { return SendNextBuffer(); }
125  virtual bool ProcessSend(unsigned) { return SendNextBuffer(); }
126 
127  bool SendNextBuffer();
128 
129  void ProcessConnectionActivated(const std::string &name, bool on);
130 
131  public:
132 
133  ServerTransport(dabc::Command cmd, const dabc::PortRef &outport,
134  int kind, int portnum,
135  dabc::SocketServerAddon *connaddon,
136  const dabc::Url& url);
137  virtual ~ServerTransport();
138 
139  };
140 }
141 
142 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
Interface for implementing any kind of data output.
Definition: DataIO.h:158
Reference on the dabc::Port class
Definition: Port.h:195
Socket addon for handling I/O events.
Definition: SocketThread.h:144
Socket addon for handling connection requests on server side.
Definition: SocketThread.h:285
Base class for transport implementations.
Definition: Transport.h:37
Uniform Resource Locator interpreter.
Definition: Url.h:33
Generic addon for dabc::Worker.
Definition: Worker.h:49
Addon for output of server-side different kinds of MBS server
ServerOutputAddon(int fd, int kind, dabc::EventsIteratorRef &iter, uint32_t subid)
virtual unsigned Write_Buffer(dabc::Buffer &buf)
Start writing of buffer to output.
virtual void OnRecvCompleted()
Method called when receive operation is completed.
mbs::TransportInfo fServInfo
virtual double ProcessTimeout(double last_diff)
virtual void OnSocketError(int err, const std::string &info)
Generic error handler.
virtual dabc::WorkerAddon * Write_GetAddon()
Returns addon, provided by data output If specified, supposed that I/O object is double-derived from ...
virtual unsigned Write_Check()
Check if output can be done.
void SetServerKind(int kind)
virtual void OnThreadAssigned()
void FillServInfo(int32_t maxbytes, bool isnewformat)
mbs::EventHeader fEvHdr
virtual double Write_Timeout()
Timeout in seconds for write operation.
void MakeCallback(unsigned sz)
mbs::SubeventHeader fSubHdr
virtual void OnSendCompleted()
Method called when send operation is completed.
dabc::EventsIteratorRef fIter
mbs::BufferHeader fHeader
Server transport for different kinds of MBS server.
int fKind
kind: stream or transport
uint32_t fSubevId
subevent id when non-MBS events are used
int fPortNum
used port number (only for info)
ServerTransport(dabc::Command cmd, const dabc::PortRef &outport, int kind, int portnum, dabc::SocketServerAddon *connaddon, const dabc::Url &url)
int fClientsLimit
maximum number of simultaneous clients
bool fBlocking
if true, server will block buffers until it can be delivered
int fDoingClose
0 - normal, 1 - saw EOF, 2 - all clients are gone
bool fDeliverAll
if true, server will try deliver all events when clients are there (default for transport)
virtual bool ProcessRecv(unsigned)
Method called by framework when at least one buffer available in input port.
virtual bool StopTransport()
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
int fSlaveQueueLength
queue length, used for slaves connections
void ProcessConnectionActivated(const std::string &name, bool on)
Method called when module on other side is started.
virtual bool StartTransport()
Methods activated by Port, when transport starts/stops.
std::string fIterKind
iterator kind when non-mbs events should be delivered to clients
virtual bool ProcessSend(unsigned)
Method called by framework when at least one buffer can be send to output port.
Support for MBS - standard GSI DAQ.
Definition: api.h:36
MBS buffer header.
Definition: MbsTypeDefs.h:152
MBS subevent
Definition: MbsTypeDefs.h:40
MBS server info structure.
Definition: MbsTypeDefs.h:197