DABC (Data Acquisition Backbone Core)  2.9.9
ConnectionRequest.h
Go to the documentation of this file.
1 // $Id: ConnectionRequest.h 3862 2018-05-11 10:06: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_ConnectionRequest
17 #define DABC_ConnectionRequest
18 
19 #ifndef DABC_Parameter
20 #include "dabc/Parameter.h"
21 #endif
22 
23 #ifndef DABC_Command
24 #include "dabc/Command.h"
25 #endif
26 
27 #ifndef DABC_ConfigBase
28 #include "dabc/ConfigBase.h"
29 #endif
30 
31 namespace dabc {
32 
33  class Device;
34  class Port;
35  class Module;
36  class ConnectionManager;
37  class ConnectionRequest;
38  class ConnectionRequestFull;
39 
40 
55  public:
56 
57  enum EState {
64  sFailed
65  };
66 
67  protected:
68 
69  friend class Port;
70  friend class ConnectionManager;
71  friend class ConnectionRequest;
72  friend class ConnectionRequestFull;
73 
75 
76  std::string fLocalUrl;
77 
78  std::string fPoolName;
79 
80  // these are fields used only by connection manager and devices from their threads
81  // connection manager for a time of connection keep reference on the connection
82  // object and use these fields for establishing of connection
83  // these fields used by conn mgr and devices, therefore protected by mutex
84 
85  int fProgress;
86 
87  std::string fServerId;
88  std::string fClientId;
90  std::string fConnId;
93 
94  // these fields and methods used only by connection manager
95  // therefore it is enough to have reference on it (no mutex required)
96  double fAccDelay;
97  double fSetDelay;
98 
99  std::string fAllowedField;
100 
101  ConnectionObject(Reference port, const std::string &localurl);
102  virtual ~ConnectionObject();
103 
106  virtual bool _CanChangeField(const std::string&);
107 
108  virtual std::string DefaultFiledName() const;
109 
113  void ChangeState(EState state, bool force);
114 
116 
122  void SetDelay(double v, bool force = false)
123  {
124  if (force) {
125  fSetDelay = 0.;
126  fAccDelay = v;
127  } else {
128  if (v>0) fSetDelay = v;
129  else fSetDelay = 0.;
130  fAccDelay = 0.;
131  }
132  }
133 
135  double CheckDelay(double shift)
136  {
137  if (fSetDelay > 0.) {
139  fSetDelay = 0;
140  return fAccDelay;
141  }
142 
143  fAccDelay -= shift;
144  return fAccDelay;
145  }
146 
147  public:
148  virtual const char* ClassName() const { return "ConnectionObject"; }
149 
150  static const char* ObjectName() { return "Connection"; }
151 
152  static const char* GetStateName(EState state);
153  };
154 
155 
156 #define GET_PAR_FIELD( field_name, defvalue ) \
157  if (GetObject()) { \
158  LockGuard guard(GetObject()->fObjectMutex); \
159  return GetObject()-> field_name; \
160  } \
161  return defvalue;
162 
163 #define SET_PAR_FIELD( field_name, value ) \
164  if (GetObject()) { \
165  LockGuard guard(GetObject()->fObjectMutex); \
166  GetObject()-> field_name = value; \
167  }
168 
169 
170  // _______________________________________________________________________________
171 
181  class ConnectionRequest : public Parameter {
182 
183  friend class Port;
184  friend class Module;
185  friend class ConnectionManager;
186 
188 
189 
192 
194 
195  Reference GetPort() const { return Reference(GetObject() ? GetObject()->GetParent() : 0); }
196 
197  std::string GetLocalUrl() const { GET_PAR_FIELD(fLocalUrl,"") }
198 
199  std::string GetPoolName() const { GET_PAR_FIELD(fPoolName,"") }
200  void SetPoolName(const std::string &name) { SET_PAR_FIELD(fPoolName, name) }
201 
203  std::string GetRemoteUrl() const { return GetField("url").AsStr(); }
204 
206  bool IsServerSide() const { return GetField("server").AsBool(false); }
207 
209  bool IsOptional() const { return GetField(xmlOptionalAttr).AsBool(false); }
210 
212  std::string GetConnDevice() const { return GetField(xmlDeviceAttr).AsStr(); }
213 
215  std::string GetConnThread() const { return GetField(xmlThreadAttr).AsStr(); }
216 
218  bool GetUseAckn() const { return GetField(xmlUseacknAttr).AsBool(false); }
219 
221  double GetConnTimeout() const { return GetField(xmlTimeoutAttr).AsDouble(10.); }
222 
223  // fields can be changed only in initial state right after creation of the request
224  void SetRemoteUrl(const std::string &url) { SetField("url", url); }
225 
226  void SetServerSide(bool isserver = true) { SetField("server", isserver); }
227 
228  void SetConnDevice(const std::string &dev) { SetField(xmlDeviceAttr, dev); }
229 
230  void SetOptional(bool on = true) { SetField(xmlOptionalAttr, on); }
231 
232  void SetUseAckn(bool on = true) { SetField(xmlUseacknAttr, on); }
233 
234  void SetConnTimeout(double tm) { SetField(xmlTimeoutAttr, tm); }
235 
236  void SetConnThread(const std::string &name) { SetField(xmlThreadAttr, name); }
237 
239 
240  protected:
241 
242  void ChangeState(ConnectionObject::EState state, bool force);
243 
246 
247  void SetAllowedField(const std::string &name = "");
248 
250  virtual const char* ParReferenceKind() { return "connection"; }
251 
252  };
253 
254 }
255 
256 
257 #endif
258 
259 
#define SET_PAR_FIELD(field_name, value)
#define GET_PAR_FIELD(field_name, defvalue)
#define DABC_REFERENCE(RefClass, ParentClass, T)
Definition: Reference.h:222
Represents command with its arguments.
Definition: Command.h:99
Connections manager class.
Container for connection parameters.
int fInlineDataSize
property of the port, if does not match, will be ruled by the server
void ChangeState(EState state, bool force)
Change state of connection object.
virtual const char * ClassName() const
Returns class name of the object instance.
std::string fPoolName
pool which should be used for the connections
static const char * ObjectName()
double fAccDelay
accounting spent time, when negative - record is active
double fSetDelay
set value for delay, will be activated first time timeout processing done
@ sDisconnected
connection is down by user, will not be reconnected
@ sConnected
connection is up and working
@ sInit
connection in initial state
@ sConnecting
connection is in progress
@ sPending
connection is pending (want to be connected)
@ sBroken
connection is broken and should be reactivated by connection manager
@ sFailed
connection cannot be established by connection manager
std::string fConnId
unique id for that connection, defined by the server (can be overwritten by device)
ConnectionObject::EState GetState()
virtual std::string DefaultFiledName() const
ConnectionObject(Reference port, const std::string &localurl)
std::string fAllowedField
name of field which is allowed to change in any state
std::string fClientId
identifier for client side
EState fConnState
actual state of the connection, is parameter value
double CheckDelay(double shift)
Function accounts time spent and returns true, if delay is not yet finished.
virtual bool _CanChangeField(const std::string &)
Reimplement virtual method of ParameterContainer to block field change if object in non-init state.
Command fRemoteCmd
command from remote, interpretation depends from the state
std::string fServerId
identifier for server side
static const char * GetStateName(EState state)
void SetDelay(double v, bool force=false)
Set delay how long record is inactive.
std::string fLocalUrl
full url of local port
Reference fCustomData
implementation specific data, managed by the device, cleanuped by the record when connection is destr...
Full description of connection request.
Connection request.
void SetPoolName(const std::string &name)
bool GetUseAckn() const
Use of acknowledge in protocol.
void SetServerSide(bool isserver=true)
std::string GetPoolName() const
std::string GetConnThread() const
Thread name for transport.
void SetUseAckn(bool on=true)
std::string GetLocalUrl() const
void SetConfigFromXml(XMLNodePointer_t node)
bool IsOptional() const
indicate if connection is optional and therefore may be ignored during failure or long timeout
void ChangeState(ConnectionObject::EState state, bool force)
void SetConnDevice(const std::string &dev)
void SetRemoteUrl(const std::string &url)
void SetAllowedField(const std::string &name="")
void SetConnThread(const std::string &name)
double GetConnTimeout() const
time required to establish connection, if expired connection will be switched to "failed" state
ConnectionObject::EState GetState() const
virtual const char * ParReferenceKind()
Indicates that only connection kind can be assigned to the reference.
std::string GetRemoteUrl() const
Return url of data source to which connection should be established.
void SetConnTimeout(double tm)
std::string GetConnDevice() const
Device name which may be used to create connection (depends from url)
Reference GetPort() const
void SetInitState()
Change state of the connection to init that other parameters can be changed.
bool IsServerSide() const
Indicates if local node in connection is server or client.
void SetOptional(bool on=true)
Base for dabc::ModuleSync and dabc::ModuleAsync classes.
Definition: Module.h:42
EState GetState() const
Returns object state value.
Definition: Object.h:149
Container for parameter object.
Definition: Parameter.h:52
Parameter class
Definition: Parameter.h:163
Base class for input and output ports.
Definition: Port.h:47
bool AsBool(bool dflt=false) const
Definition: Record.cxx:477
std::string AsStr(const std::string &dflt="") const
Definition: Record.cxx:749
double AsDouble(double dflt=0.) const
Definition: Record.cxx:549
RecordField GetField(const std::string &name) const
Definition: Record.h:510
bool SetField(const std::string &name, const RecordField &v)
Definition: Record.h:516
Reference on the arbitrary object
Definition: Reference.h:73
Object * GetObject() const
Return pointer on the object.
Definition: Reference.h:129
Reference(Object *obj=nullptr)
Constructor, creates reference on the object.
Definition: Reference.cxx:25
Object * GetParent() const
Returns pointer on parent object.
Definition: Reference.cxx:162
Event manipulation API.
Definition: api.h:23
void * XMLNodePointer_t
Definition: XmlEngine.h:25
const char * xmlTimeoutAttr
Definition: ConfigBase.cxx:42
const char * xmlUseacknAttr
Definition: ConfigBase.cxx:39
const char * xmlDeviceAttr
Definition: ConfigBase.cxx:37
const char * xmlOptionalAttr
Definition: ConfigBase.cxx:40
const char * xmlThreadAttr
Definition: ConfigBase.cxx:38