28 std::string name = inpport.ItemName();
29 if (name.empty()) name = outport.ItemName();
33 while ((pos=name.find(
"/")) != std::string::npos)
36 return std::string(
"#") + name;
41 ModuleAsync(MakeName(inpport, outport)),
43 fTransportState(stInit),
44 fIsInputTransport(false),
45 fIsOutputTransport(false),
47 fTransportInfoInterval(-1.),
52 if (!inpport.null()) {
54 unsigned trqueue = inpport.Cfg(
"TransportQueue", cmd).AsUInt(1);
55 if (trqueue < inpport.QueueCapacity()) trqueue = inpport.QueueCapacity();
59 CreateOutput(
"Output", trqueue);
61 SetPortLoopLength(OutputName(), 1);
63 fTransportInfoName = inpport.InfoParName();
65 fIsInputTransport =
true;
68 if (!outport.null()) {
70 unsigned trqueue = outport.Cfg(
"TransportQueue", cmd).AsUInt(1);
71 if (trqueue < outport.QueueCapacity()) trqueue = outport.QueueCapacity();
75 CreateInput(
"Input", trqueue);
77 SetPortLoopLength(InputName(), 1);
79 if (fTransportInfoName.empty())
80 fTransportInfoName = outport.InfoParName();
82 fIsOutputTransport =
true;
85 if (!fTransportInfoName.empty()) {
86 fTransportInfoInterval = 1;
87 fTransportInfoTm.GetNow();
95 if (!poolname.empty() && (NumPools()==0)) {
99 CreatePoolHandle(poolname, fIsInputTransport ? 10 : 0);
110 DOUT3(
"Transport %s CLEANUP", ItemName().c_str());
116 fTransportDevice.Release();
122 if (fTransportInfoName.empty() || (fTransportInfoInterval<=0))
return false;
124 return fTransportInfoTm.Expired(fTransportInfoInterval);
129 if (fTransportInfoName.empty())
return;
133 fTransportInfoTm.GetNow();
135 if (par.null())
return;
144 if (IsValidPool(FindPool(name)))
return;
146 DOUT5(
"$$$$$$ Transport %s %p Port %s Activated %s", GetName(),
this, name.c_str(),
DBOOL(on));
149 if ((GetTransportState()==stInit) || (GetTransportState()==stStopped)) {
150 DOUT2(
"Connection %s activated in transport %s - start it", name.c_str(), GetName());
152 if (StartTransport()) {
153 fTransportState = stRunning;
155 fTransportState = stError;
159 DOUT2(
"Transport %s is running, ignore start message from port %s", GetName(), name.c_str());
163 if (GetTransportState()==stRunning) {
164 DOUT2(
"Connection %s deactivated in transport %s - stop it", name.c_str(), GetName());
165 if (StopTransport()) {
166 fTransportState = stStopped;
168 fTransportState = stError;
177 DOUT5(
"$$$$$$ Transport %s %p %s event port %s\n", GetName(),
this, on ?
"connect" :
"DISCONNECT", name.c_str());
182 if (IsInputTransport() && (name == OutputName())) {
183 DOUT2(
"Transport %s port %s is disconnected - automatic transport destroyment is started", GetName(), name.c_str());
188 if (IsOutputTransport() && (name == InputName())) {
189 DOUT2(
"Transport %s port %s is disconnected - automatic transport destroyment is started", GetName(), name.c_str());
198 DisconnectAllPorts(witherr);
204 if (cmd.IsName(
"CloseTransport")) {
205 CloseTransport(cmd.GetBool(
"IsError",
true));
208 if (cmd.IsName(dabc::CmdGetBinary::CmdName()) && (cmd.GetStr(
"Kind")==
"transport.json")) {
211 info.
SetField(
"IsInput", IsInputTransport());
212 info.
SetField(
"IsOutput", IsOutputTransport());
222 if (IsRunning())
return true;
224 DOUT3(
"Start transport %s", GetName());
226 fAddon.Notify(
"StartTransport");
233 if (!IsRunning())
return true;
235 DOUT3(
"Stop transport %s", GetName());
237 fAddon.Notify(
"StopTransport");
Represents command with its arguments.
Parameter FindPar(const std::string &parname)
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
bool Stop()
Stops execution of the module code.
bool Start()
Starts execution of the module code.
std::string ItemName(bool compact=true) const
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
bool SetField(const std::string &name, const RecordField &v)
std::string SaveToJson(unsigned mask=0)
Store record in JSON form.
virtual void CreateRecord(const std::string &name)
Transport(dabc::Command cmd, const PortRef &inpport=0, const PortRef &outport=0)
virtual bool StopTransport()
virtual bool StartTransport()
Methods activated by Port, when transport starts/stops.
virtual void ProcessConnectionActivated(const std::string &name, bool on)
Method called when module on other side is started.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual void CloseTransport(bool witherr=false)
virtual void ProcessConnectEvent(const std::string &name, bool on)
Method called by framework when connection state of the item is changed.
virtual void ModuleCleanup()
Reimplemented method from module.
static std::string MakeName(const PortRef &inpport, const PortRef &outport)
void ProvideInfo(int lvl, const std::string &info)
Method provides transport info to specified parameter.
bool InfoExpected() const
Returns true when next info can be provided If info parameter was configured, one could use it regula...
const unsigned AcknoledgeQueueLength