19 #include "dabc/Device.h"
79 if (!ispending && !isbroken)
return;
83 EOUT(
"Connection handle not found !!!! ");
87 if (fRecs.HasObject(req())) {
88 EOUT(
"Connection %s already registered as pending - that happened??", evnt.
ParName().c_str());
106 if ((fDoingConnection == 0) && fConnCmd.null() && isbroken) {
107 DOUT0(
"Reactivate connection manager");
108 fDoingConnection = 1;
119 fDoingConnection = 0;
121 fConnCmd.ReplyFalse();
123 while (fRecs.GetSize()>0) {
134 bool iserror =
false, isonlyoptional =
true;
138 while (n<fRecs.GetSize()) {
155 case progrConnected: {
165 if (!req.
IsOptional()) isonlyoptional =
false;
172 fConnCmd.ReplyFalse();
173 DOUT2(
"SOME CONNECTIONS FINSIHED WITH FAILURE");
175 if (fRecs.GetSize()==0) fDoingConnection = 0;
177 if (fRecs.GetSize()==0) {
178 fDoingConnection = 0;
179 fConnCmd.ReplyTrue();
180 DOUT0(
"ALL CONNECTIONS FINSIHED OK");
182 if (finish_command_dueto_timeout) {
187 if (isonlyoptional) {
188 DOUT0(
"ALL NON-OPTIONAL CONNECTIONS FINSIHED OK, OPTIONAL WILL BE CONTINUED");
189 fConnCmd.ReplyTrue();
191 EOUT(
"CONNECTION COMMAND is TIMEDOUT");
192 fConnCmd.ReplyTimedout();
200 if (fDoingConnection==0)
return -1.;
202 double mindelay = 1.;
204 for (
unsigned n=0; n<fRecs.GetSize(); n++) {
207 if (req.
null())
continue;
209 double tm = req()->CheckDelay(last_diff);
211 if (tm<mindelay) mindelay = tm;
224 EOUT(
"Cannot find device %s for connection record", req.
GetConnDevice().c_str());
226 EOUT(
"Cannot find port %s for connection record", req.
GetLocalUrl().c_str());
233 req()->SetDelay(5,
true);
249 case progrDoingInit: {
252 EOUT(
"Device did not initialize record for so long time - one should do something. Now going in FAILURE");
265 req()->SetDelay(2,
true);
269 bool islocal =
false;
270 std::string remserver, remitem;
302 case progrDoingConnect: {
303 EOUT(
"Timeout when doing connect - device should be responsible here!!!");
307 case progrWaitReply: {
308 EOUT(
"Timeout when waiting for reply - command timeout should be used here till the end %5.1f!!!", fConnCmd.TimeTillTimeout());
317 double cmd_tmout = fConnCmd.TimeTillTimeout(-0.5);
319 if ((cmd_tmout>0) && (cmd_tmout<mindelay)) mindelay = cmd_tmout;
321 CheckConnectionRecs(cmd_tmout==0.);
328 for (
unsigned n=0; n<fRecs.GetSize(); n++) {
331 if (req.
match(local, remote))
return req;
340 if (cmd.
IsName(CmdGlobalConnect::CmdName())) {
346 DOUT2(
"Get request for %s -> %s found:%p",
350 EOUT(
"Request from remote for undefined connection %s %s", cmd1.
GetUrl1().c_str(), cmd1.
GetUrl2().c_str());
370 if (!FillAnswerOnRemoteConnectCmd(cmd, req))
return cmd_false;
376 EOUT(
"Two requests for %s meet together - FAILURE", req.
GetConnInfo().c_str());
380 EOUT(
"CmdGlobalConnect received in wrong progress state %d", req.
progress());
387 if (cmd.
IsName(
"ActivateConnections")) {
388 fConnCmd.ReplyFalse();
390 DOUT2(
"Start processing of connections number %u", fRecs.GetSize());
392 fDoingConnection = 1;
400 if (cmd.
IsName(
"ShutdownConnection")) {
401 fConnCmd.ReplyFalse();
403 fDoingConnection = -1;
416 if (cmd.
IsName(CmdConnectionManagerHandle::CmdName())) {
417 HandleConnectRequestCmdReply(cmd);
419 if (cmd.
IsName(CmdGlobalConnect::CmdName())) {
420 HandleCmdGlobalConnectReply(cmd);
428 if (cmd.
null() || req.
null())
return false;
433 EOUT(
"Cannot find device");
451 EOUT(
"NEVER COME HERE");
455 req()->SetDelay(100);
471 EOUT(
"Did not find connection request for reply command");
478 case progrWaitReply: {
485 DOUT2(
"Connection %s was too early, try short again", req.
GetConnInfo().c_str());
491 EOUT(
"Connection %s is rejected res = %d - why?", req.
GetConnInfo().c_str(), res);
502 EOUT(
"NEVER COME HERE");
514 int inlinesize = cmd.
GetInt(
"ServerInlineSize");
524 EOUT(
"Cannot find device");
529 req()->SetDelay(100);
539 EOUT(
"Reply on global connect in strange state");
547 if (req.
null())
return;
560 case progrDoingInit: {
576 case progrDoingConnect: {
582 CheckConnectionRecs(
false);
588 DOUT0(
"Command reply at state %d - that to do?", req.
progress());
static const char * ReqArg()
CmdConnectionManagerHandle(ConnectionRequestFull &req)
Here is description how connection between two nodes are build and which states are used.
std::string GetReq() const
std::string GetUrl2() const
void SetUrl2(const std::string &url2)
void SetUrl1(const std::string &url1)
std::string GetUrl1() const
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
bool SetBool(const std::string &name, bool v)
double GetDouble(const std::string &name, double dflt=0.) const
bool SetInt(const std::string &name, int v)
std::string GetStr(const std::string &name, const std::string &dflt="") const
Command & SetTimeout(double tm)
Set maximum time which can be used for command execution.
Command & SetReceiver(const std::string &itemname)
These methods prepare command so, that one can submit command to the manager like: dabc::mgr....
bool GetBool(const std::string &name, bool dflt=false) const
bool SetDouble(const std::string &name, double v)
int GetInt(const std::string &name, int dflt=0) const
ConnectionRequestFull FindConnection(const std::string &url1, const std::string &url2)
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
void HandleCmdGlobalConnectReply(CmdGlobalConnect cmd)
React on the reply of global connect command.
virtual double ProcessTimeout(double last_diff)
Check status of connections establishing.
void CheckConnectionRecs(bool finish_command=false)
Check current situation with connections.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual void ProcessParameterEvent(const ParameterEvent &evnt)
Process changes in connection recs.
bool FillAnswerOnRemoteConnectCmd(Command cmd, ConnectionRequestFull &req)
Fill answer on remote connection request and invoke device to start connection When device confirms t...
ConnectionManager(const std::string &name, Command cmd=nullptr)
virtual void ModuleCleanup()
Destroy all connections, if necessary - request to cleanup custom data by device.
void HandleConnectRequestCmdReply(CmdConnectionManagerHandle cmd)
Analyze reply of the command, send to the device.
virtual ~ConnectionManager()
static const char * ObjectName()
@ sConnected
connection is up and working
@ 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
static const char * GetStateName(EState state)
Full description of connection request.
std::string GetConnId() const
std::string GetConnInfo()
void SetRemoteCommand(dabc::Command cmd)
bool match(const std::string localurl, const std::string remoteurl)
std::string GetServerId() const
void ReplyRemoteCommand(bool res)
void SetConnTimeoutDirectly(double tm)
std::string GetClientId() const
void SetUseAcknDirectly(bool on)
void SetInlineDataSize(int size)
int GetInlineDataSize() const
void SetClientId(const std::string &id)
void SetServerId(const std::string &id)
void SetConnId(const std::string &id)
bool GetUseAckn() const
Use of acknowledge in protocol.
std::string GetLocalUrl() const
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)
double GetConnTimeout() const
time required to establish connection, if expired connection will be switched to "failed" state
std::string GetRemoteUrl() const
Return url of data source to which connection should be established.
std::string GetConnDevice() const
Device name which may be used to create connection (depends from url)
Reference GetPort() const
bool IsServerSide() const
Indicates if local node in connection is server or client.
Reference on dabc::Device class
WorkerRef FindDevice(const std::string &name)
Parameter FindPar(const std::string &parname)
std::string ComposeAddress(const std::string &server, const std::string &itemname="")
static const char * ConnMgrName()
Base class for user-derived code, implementing event-processing.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual void ModuleCleanup()
Method, which can be reimplemented by user and should cleanup all references on buffers and other obj...
Object * GetParent() const
Returns pointer on parent object, thread safe
std::string ParName() const
std::string ParValue() const
Reference on the dabc::Port class
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
bool null() const
Returns true if reference contains nullptr.
std::string ItemName(bool compact=true) const
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
bool RegisterForParameterEvent(const std::string &mask, bool onlychangeevent=true)
Subscribe to parameter events from local or remote node.
std::string format(const char *fmt,...)
const char * xmlUseAcknowledge