23 dabc::ModuleAsync(name, cmd)
29 cmddef.
AddArg(
"cmd",
"string",
true,
"-");
33 ui.
SetField(
"_UserFilePath",
"${DABCSYS}/plugins/gosip/htm/");
34 ui.
SetField(
"_UserFileMain",
"main.htm");
54 if (cmd.
IsName(
"CmdGosip")) {
56 int sfp = cmd.
GetInt(
"sfp", 0);
57 int dev = cmd.
GetInt(
"dev", 0);
59 bool log_output = cmd.
GetInt(
"log") > 0;
62 if ((sfp<0) || (dev<0))
69 std::vector<std::string> gosipres;
70 std::vector<std::string> gosiplog;
72 DOUT2(
"*** CmdGosip len %u ****", gosipcmd.size());
73 for (
unsigned n=0;n<gosipcmd.size();n++) {
75 std::string currcmd = gosipcmd[n];
77 bool isreading = (currcmd.find(
"-r")==0);
78 bool iswriting = (currcmd.find(
"-w")==0);
80 if (!isreading && !iswriting && (currcmd[0]!=
'-')) {
82 currcmd = std::string(
"-r adr ") + currcmd;
85 size_t ppp = currcmd.find(
"adr");
86 if (ppp!=std::string::npos) currcmd.replace(ppp,3,addr);
88 currcmd =
"gosipcmd " + currcmd;
90 if (log_output) gosiplog.push_back(currcmd);
94 FILE* pipe = popen(currcmd.c_str(),
"r");
97 gosipres.push_back(
"<err>");
102 memset(buf, 0,
sizeof(buf));
105 while(!feof(pipe) && (totalsize<200000)) {
106 int size = (int)fread(buf,1,
sizeof(buf)-1, pipe);
108 while ((size>0) && ((buf[size-1]==
' ') || (buf[size-1]==
'\n'))) size--;
111 if (log_output && (size>0)) gosiplog.push_back(buf);
121 if (strlen(buf) > 2) {
122 gosipres.push_back(
"<err>");
126 gosipres.push_back(
"<ok>");
133 gosipres.push_back(
"<err>");
142 gosipres.push_back(
"<undef>");
145 while (gosipres.size() < gosipcmd.size()) gosipres.push_back(
"<skip>");
151 DOUT2(
"*** CmdGosip finished ****");
Command definition class.
CommandDefinition & AddArg(const std::string &name, const std::string &kind="string", bool required=true, const RecordField &dflt=RecordField())
Represents command with its arguments.
int GetInt(const std::string &name, int dflt=0) const
Represents objects hierarchy of remote (or local) DABC process.
Hierarchy CreateHChild(const std::string &name, bool allowslahes=false, bool sortorder=false)
Create child item in hierarchy with specified name If allowslahes enabled, instead of subfolders item...
void Create(const std::string &name, bool withmutex=false)
Create top-level object with specified name.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
unsigned CreateTimer(const std::string &name, double period_sec=-1., bool synchron=false)
std::vector< std::string > AsStrVect() const
RecordField GetField(const std::string &name) const
bool SetField(const std::string &name, const RecordField &v)
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
CommandDefinition CreateCmdDef(const std::string &name)
Hierarchy fWorkerHierarchy
place for publishing of worker parameters
virtual bool PublishPars(const std::string &path)
Player(const std::string &name, dabc::Command cmd=nullptr)
virtual void ProcessTimerEvent(unsigned timer)
Method called by framework when timer event is produced.
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
std::string format(const char *fmt,...)
bool str_to_lint(const char *val, long *res)
Convert string to long integer value.