1 #ifndef EUDAQ_INCLUDED_TransportBase
2 #define EUDAQ_INCLUDED_TransportBase
7 #include "eudaq/Platform.hh"
8 #include "eudaq/Mutex.hh"
9 #include "eudaq/Exception.hh"
10 #include "eudaq/BufferSerializer.hh"
25 : m_state(0), m_name(name) { }
28 : m_state(0), m_name(name), m_type(type) { }
32 virtual void Print(std::ostream &)
const;
34 bool IsEnabled()
const {
return m_state >= 0; }
35 int GetState()
const {
return m_state; }
36 void SetState(
int state) { m_state = state; }
37 std::string GetType()
const {
return m_type; }
38 void SetType(
const std::string &type) { m_type = type; }
39 std::string GetName()
const {
return m_name; }
40 void SetName(
const std::string &name) { m_name = name; }
42 int GetRemoteInfo()
const;
43 virtual std::string GetRemote()
const {
return m_host; }
51 return(GetRemoteInfo() < comp.GetRemoteInfo());
62 std::string m_type, m_name;
72 inline std::ostream &operator<<(std::ostream &os,
const ConnectionInfo &
id) {
82 enum EventType { CONNECT, DISCONNECT, RECEIVE };
105 virtual Helper *Clone()
const = 0;
110 class HelperFunction :
public Helper {
113 HelperFunction(FuncType func) : m_func(func) {}
115 virtual Helper *Clone()
const {
return new HelperFunction(*
this); }
125 template <
typename T>
class HelperMember :
public Helper {
129 HelperMember(ObjType *obj, FuncType func) : m_obj(obj), m_func(func) {}
131 virtual Helper *Clone()
const {
return new HelperMember(*
this); }
141 : m_helper(
new HelperFunction(funcptr)) {}
142 template <
typename T>
144 : m_helper(
new HelperMember<T>(obj, func)) {}
150 : m_helper(other.m_helper->Clone()) {}
153 m_helper = other.m_helper->Clone();
178 virtual void SendPacket(
const unsigned char *data,
size_t len,
180 bool duringconnect =
false) = 0;
183 bool duringconnect =
false) {
185 SendPacket(reinterpret_cast<const unsigned char *>(&data[0]),
186 data.length(), inf, duringconnect);
190 bool duringconnect =
false) {
192 SendPacket(reinterpret_cast<const unsigned char *>(str), std::strlen(str),
197 bool duringconnect =
false) {
198 SendPacket(&t[0], t.size(), inf, duringconnect);
217 void Process(
int timeout = -1);
218 bool ReceivePacket(std::string *packet,
int timeout = -1,
220 bool SendReceivePacket(
const std::string &sendpacket,
221 std::string *recpacket,
223 template <
typename T>
224 T SendReceivePacket(
const std::string &packet,
227 virtual bool IsNull()
const {
return false; }
230 std::queue<TransportEvent>
237 template <
typename T>
238 inline T TransportBase::SendReceivePacket(
const std::string &packet,
242 bool ok = SendReceivePacket(packet, &buf, connection, timeout);
244 EUDAQ_THROW(
"Timeout: No response in SendReceivePacket");
252 #endif // EUDAQ_INCLUDED_TransportBase
Definition: TransportBase.hh:80
virtual void SendPacket(const unsigned char *data, size_t len, const ConnectionInfo &=ConnectionInfo::ALL, bool duringconnect=false)=0
std::queue< TransportEvent > m_events
A buffer to queue up events until they are handled.
Definition: TransportBase.hh:231
std::string packet
The packet of data in case of a RECEIVE event.
Definition: TransportBase.hh:87
virtual void Close(const ConnectionInfo &)
Definition: TransportBase.hh:206
virtual void ProcessEvents(int timeout)=0
ConnectionInfo & id
The id of the connection.
Definition: TransportBase.hh:86
TransportCallback m_callback
The callback function to invoke on a transport event.
Definition: TransportBase.hh:233
Definition: TransportBase.hh:168
EventType etype
The type of event.
Definition: TransportBase.hh:85
Definition: TransportBase.hh:97
Definition: TransportBase.hh:22
Definition: BufferSerializer.hh:12