28 fAnyModuleWasRunning(false),
72 std::string tgtstate = cmd.
GetStr(
"StateCmdTarget");
75 if (tgtstate == stRunning() && (res ==
cmd_true)) {
78 if ((res==
cmd_true) && fSelfControl) ActivateTimeout(0.2);
81 if (res==
cmd_true) SetAppState(tgtstate);
82 if (res==
cmd_false) SetAppState(stFailure());
91 if (cmd.
IsName(CmdStateTransition::CmdName()))
92 return DoTransition(cmd.
GetStr(
"State"), cmd);
94 if (cmd.
IsName(stcmdDoConfigure()))
95 return DoTransition(stReady(), cmd);
97 if (cmd.
IsName(stcmdDoStart()))
98 return DoTransition(stRunning(), cmd);
100 if (cmd.
IsName(stcmdDoStop()))
101 return DoTransition(stReady(), cmd);
103 if (cmd.
IsName(stcmdDoHalt()))
104 return DoTransition(stHalted(), cmd);
106 if (cmd.
IsName(
"AddAppObject")) {
107 if (cmd.
GetStr(
"kind") ==
"device")
108 fAppDevices.push_back(cmd.
GetStr(
"name"));
110 if (cmd.
GetStr(
"kind") ==
"pool")
111 fAppPools.push_back(cmd.
GetStr(
"name"));
113 if (cmd.
GetStr(
"kind") ==
"module")
114 fAppModules.push_back(cmd.
GetStr(
"name"));
137 fInitFunc = initfunc;
142 SetParValue(StateParName(), name);
143 if (name == stFailure())
DOUT0(
"Application switched to FAILURE state");
148 std::string currstate = GetState();
150 DOUT3(
"Doing transition curr %s tgt %s", currstate.c_str(), tgtstate.c_str());
152 if (currstate == tgtstate)
return cmd_true;
155 if (currstate == stTransition())
return cmd_false;
157 SetAppState(stTransition());
162 if (currstate == stFailure()) {
163 res = CleanupApplication();
164 if (res) currstate = stHalted();
167 if (tgtstate == stHalted()) {
168 if (currstate == stRunning()) res = cmd_bool(StopModules());
169 if (!CleanupApplication()) res =
cmd_false;
171 if (tgtstate == stReady()) {
172 if (currstate == stHalted()) res = CallInitFunc(cmd, tgtstate);
else
173 if (currstate == stRunning()) res = cmd_bool(StopModules());
175 if (tgtstate == stRunning()) {
176 if (currstate == stHalted()) {
177 res = CallInitFunc(cmd, tgtstate);
178 if (res ==
cmd_true) currstate = stReady();
180 if (currstate == stReady())
184 if ((res==
cmd_true) && fSelfControl) ActivateTimeout(0.2);
187 if (tgtstate == stFailure()) {
190 EOUT(
"Unsupported state name %s", tgtstate.c_str());
194 if (res==
cmd_true) SetAppState(tgtstate);
195 if (res==
cmd_false) SetAppState(stFailure());
202 if (!fSelfControl || (GetState() != stRunning()))
return -1;
204 if (IsModulesRunning()) { fAnyModuleWasRunning =
true;
return 0.2; }
207 if (!fAnyModuleWasRunning)
return 0.2;
218 for (
unsigned n=0;n<fAppModules.size();n++) {
235 if (CreateAppModules())
return cmd_true;
243 if ((name==0) || (clname==0))
continue;
245 fAppDevices.push_back(name);
247 if (!
dabc::mgr.CreateDevice(clname, name)) {
248 EOUT(
"Fail to create device %s class %s", name, clname);
257 if (name==0)
continue;
259 if (devname==0) devname =
"";
260 DOUT2(
"Create thread %s", name);
266 fAppPools.push_back(name);
267 DOUT2(
"Create memory pool %s", name);
269 EOUT(
"Fail to create memory pool %s", name);
278 if (clname==0)
continue;
279 if (thrdname==0) thrdname=
"";
283 if (!m.
null())
continue;
286 if (strcmp(clname,
"dabc::Publisher")==0)
continue;
288 fAppModules.push_back(name);
290 DOUT2(
"Create module %s class %s", name, clname);
295 EOUT(
"Fail to create module %s class %s", name, clname);
299 for (
unsigned n = 0; n < m.
NumInputs(); n++) {
305 EOUT(
"Cannot create input transport for port %s", m.
InputName(n).c_str());
310 for (
unsigned n = 0; n < m.
NumOutputs(); n++) {
316 EOUT(
"Cannot create output transport for port %s", m.
OutputName(n).c_str());
330 if ((outputname==0) || (inputname==0))
continue;
335 if (kind && (strcmp(kind,
"all-to-all")==0)) {
339 DOUT2(
"Create all-to-all connections for %d nodes", numnodes);
341 for (
int nsender=0; nsender<numnodes; nsender++)
342 for (
int nreceiver=0;nreceiver<numnodes;nreceiver++) {
353 std::vector<std::string> arr = fld.
AsStrVect();
354 for (
unsigned n = 0; n < arr.size(); ++n) {
363 if (!req.
null()) nconn++;
368 if (!req.
null()) nconn++;
378 cmd.
SetRef(
"StateCmd", statecmd);
379 cmd.
SetStr(
"StateCmdTarget", tgtstate);
391 for (
unsigned n=0;n<fAppModules.size();n++)
399 for (
unsigned n=0;n<fAppModules.size();n++)
407 for (
unsigned n=0;n<fAppModules.size();n++)
410 for (
unsigned n=0;n<fAppPools.size();n++)
413 for (
unsigned n=0;n<fAppDevices.size();n++)
bool AddObject(const std::string &kind, const std::string &name)
Adds object into application list List used when objects must be destroyed or application start/stop ...
virtual int DoTransition(const std::string &state, Command cmd)
Do action, required to make transition into specified state.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual bool IsModulesRunning()
Return true if all application-relevant modules are running.
static const char * stcmdDoHalt()
virtual bool Find(ConfigIO &cfg)
Method to locate object in xml file.
virtual void OnThreadAssigned()
Method called at thread assignment - application may switch into running state.
static const char * StateParName()
static const char * stcmdDoStop()
void SetInitFunc(ExternalFunction *initfunc)
Set external function, which creates all necessary components of the application.
virtual void BuildFieldsMap(RecordFieldsMap *cont)
Fill fields map, which is relevant for the object Objects hierarchy produced from dabc::Manager.
void SetAppState(const std::string &name)
Directly changes value of the state parameter.
Application(const char *classname=0)
static const char * stHalted()
bool fSelfControl
when true, application itself decide when stop main loop
virtual bool StartModules()
Start all application modules.
virtual double ProcessTimeout(double)
Timeout used by application to control stop state of modules and brake application.
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
virtual bool CleanupApplication()
Delete all components created in application, excluding state parameter.
double fConnTimeout
time for connecting all modules, default 5s
static const char * stcmdDoConfigure()
int CallInitFunc(Command statecmd, const std::string &tgtstate)
virtual bool StopModules()
Stop all application modules.
virtual void ObjectCleanup()
Cleanup application.
static const char * stcmdDoStart()
static const char * CmdName()
static const char * CmdName()
Represents command with its arguments.
bool SetStr(const std::string &name, const char *value)
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....
Reference GetRef(const std::string &name)
Returns reference from the command, can be called only once.
void Reply(int res=cmd_noresult)
Replied on the command.
bool SetRef(const std::string &name, Reference ref)
Set reference to the command.
std::string ResolveEnv(const std::string &arg, int id=-1)
Replaces entries like ${name} be variable value.
Interface class between xml configuration and dabc objects.
bool FindItem(const char *name)
bool CheckAttr(const char *name, const char *value)
Check if item, found by FindItem routine, has attribute with specified value.
Full-functional class to reading configuration from xml files.
bool NextCreationNode(XMLNodePointer_t &prev, const char *nodename, bool check_name_for_multicast)
Method is used to find xml nodes like Module, MemoryPool, Connection in the xml file which should be ...
void SetConfigFromXml(XMLNodePointer_t node)
ModuleRef CreateModule(const std::string &classname, const std::string &modulename, const std::string &thrdname="")
ConnectionRequest Connect(const std::string &port1, const std::string &port2)
Request connection between two ports.
ModuleRef FindModule(const std::string &name)
ThreadRef CreateThread(const std::string &thrdname, const std::string &classname="", const std::string &devname="")
static const char * ConnMgrName()
Reference on dabc::Module class
std::string OutputName(unsigned n=0, bool itemname=true)
Return item name of the output, can be used in connect command.
unsigned NumOutputs()
Returns number of outputs in the module.
unsigned NumInputs()
Returns number of inputs in the module.
PortRef FindPort(const std::string &name)
Return reference on the port.
std::string InputName(unsigned n=0, bool itemname=true)
Return item name of the input, can be used in connect command.
Parameter & SetSynchron(bool on, double interval=1., bool everyevnt=false)
Indicate if parameter is should generate events synchron with code which modified it.
Reference on the dabc::Port class
bool SetStr(const std::string &v)
std::vector< std::string > AsStrVect() const
bool AsBool(bool dflt=false) const
double AsDouble(double dflt=0.) const
RecordField & Field(const std::string &name)
Direct access to the fields.
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.
static std::string ComposePortName(int nodeid, const std::string &fullportname, int portid=-1)
! Method creates url string with port address, which includes nodeid and full portname If optional pa...
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration record of specified name.
Active object, which is working inside dabc::Thread.
CommandDefinition CreateCmdDef(const std::string &name)
RecordField Cfg(const std::string &name, Command cmd=nullptr) const
Returns configuration field of specified name Configuration value of specified name searched in follo...
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
virtual bool PublishPars(const std::string &path)
virtual bool ReplyCommand(Command cmd)
Reimplement this method to react on command reply Return true if command can be destroyed by framewor...
virtual void ObjectCleanup()
Central cleanup method for worker.
virtual Parameter CreatePar(const std::string &name, const std::string &kind="")
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
std::string replace_all(const std::string &str, const std::string &match, const std::string &replace)
Replace all matches in the string.
const char * xmlDeviceAttr
std::string format(const char *fmt,...)
const char * xmlAppDfltName
const char * xmlApplication
const char * xmlConnectionNode
const char * xmlThreadAttr
const char * xmlMemoryPoolNode
const char * xmlModuleNode
const char * xmlClassAttr
const char * xmlDeviceNode
const char * xmlThreadNode
const char * typeApplication