33 #ifdef DABC_EXTRA_CHECKS
34 DebugObject(
"Command",
this, 1);
43 if (fCallers.size()>0) {
44 EOUT(
"Non empty callers list in cmd %s destructor", GetName());
48 DOUT4(
"CMD:%p name %s deleted",
this, GetName());
50 #ifdef DABC_EXTRA_CHECKS
51 DebugObject(
"Command",
this, -1);
87 while (iter != cont->
fCallers.end()) {
89 if ((iter->worker == worker) && ((exe_ready==0) || (iter->exe_ready==exe_ready)))
99 if (cont==0)
return false;
103 if ((cont->
fCallers.size()==0))
return false;
105 return cont->
fCallers.back().exe_ready != 0;
127 if (cont==0)
return false;
135 if (cont==0)
return -1.;
143 return (now > ref) ? 0. : (ref - now);
154 snprintf(buf,
sizeof(buf),
"%p", p);
160 std::string val = GetStr(name);
161 if (val.empty())
return deflt;
164 int res = sscanf(val.c_str(),
"%p", &p);
165 return res>0 ? p : deflt;
172 return SetField(field, ref);
189 if (!
null() && !cmd.
null())
190 GetObject()->Fields().CopyFrom(cmd.
GetObject()->Fields(), canoverwrite);
229 if (res>=0) SetResult(res);
240 if (cont->
fCallers.size()==0)
break;
248 if (rec.
worker==0)
continue;
252 if (!HasField(
"#no_warnings"))
253 EOUT(
"AAAAAAAAAAAAAAAAAAAAAAAA Problem with cmd %s worker %p", GetName(), rec.
worker);
265 while (pos < str.length()) {
267 if (str[pos]==
'\"') quote = !quote;
269 if (!quote && (str[pos] == symb))
return pos;
279 size_t len = str.length();
281 if (len < 2)
return true;
283 if (str[0] != str[len-1])
return true;
299 while (pos<str.length()) {
300 if (str[pos] ==
' ') { pos++;
continue; }
303 std::string part = str.substr(pos, next-pos);
313 if (separ == part.length()) {
317 EOUT(
"Wrong position of '=' symbol");
321 std::string argname = part.substr(0, separ-1);
322 std::string argvalue = part.substr(separ+1);
324 SetStr(argname, argvalue);
328 if (narg>0) SetInt(
"NumArg", narg);
336 return SetField(
"#RawData", rawdata);
343 return SetRawData(raw);
350 RemoveField(
"#RawData");
size_t find_symbol(const std::string &str, size_t pos, char symb)
bool remove_quotes(std::string &str)
Reference on memory from memory pool.
static Buffer CreateBuffer(BufferSize_t sz)
This static method create independent buffer for any other memory pools Therefore it can be used in s...
Container object for command which should not been seen to normal user.
bool fCanceled
indicate if command was canceled ant not need to be executed further
std::list< CallerRec > fCallers
list of callers
virtual ~CommandContainer()
TimeStamp fTimeout
absolute time when timeout will be expired
CommandContainer(const std::string &name="Command")
Represents command with its arguments.
double TimeTillTimeout(double extra=0.) const
Returns time which remains until command should be timed out.
bool ReadFromCmdString(const std::string &str)
Read command from string, which is typed in std output.
void SetPtr(const std::string &name, void *p)
Set pointer argument for the command.
void AddCaller(Worker *worker, bool *exe_ready=nullptr)
bool SetStrRawData(const std::string &str)
Set raw data with string content.
void Cancel()
Call this method to cancel command execution.
bool SetRawData(Buffer rawdata)
Set raw data to the command, which can be transported also between nodes.
Command & SetTimeout(double tm)
Set maximum time which can be used for command execution.
bool IsTimeoutSet() const
Return true if timeout was specified.
void Release()
Method used to clean command - all internal data will be cleaned, command container will be released.
void AddValuesFrom(const Command &cmd, bool canoverwrite=true)
Reference GetRef(const std::string &name)
Returns reference from the command, can be called only once.
void Print(int lvl=0, const char *from=nullptr) const
Show on debug output content of command.
bool IsCanceled()
Return true if command was canceled.
Buffer GetRawData()
Returns reference on raw data Can be called only once - raw data reference will be cleaned.
void Reply(int res=cmd_noresult)
Replied on the command.
void ChangeName(const std::string &name)
Change command name, should not be used for remote commands.
bool SetRef(const std::string &name, Reference ref)
Set reference to the command.
void RemoveCaller(Worker *worker, bool *exe_ready=nullptr)
int GetPriority() const
Returns command priority.
void * GetPtr(const std::string &name, void *deflt=0) const
Get pointer argument from the command.
Lock guard for posix mutex.
void SetFlag(unsigned fl, bool on=true)
Change value of selected flag, not thread safe
void SetNameDirect(const char *name)
Changes object name disregard of existing references.
const char * GetName() const
Returns name of the object, thread safe
@ flAutoDestroy
object will be automatically destroyed when no references exists, normally set in constructor,...
Container for records fields.
Reference on the arbitrary object
void Release()
Releases reference on the object.
Object * GetObject() const
Return pointer on the object.
void Print(int lvl=0, const char *from=0) const
Show on debug output content of reference.
bool null() const
Returns true if reference contains nullptr.
Active object, which is working inside dabc::Thread.
bool GetCommandReply(dabc::Command &cmd, bool *exe_ready)
std::string format(const char *fmt,...)
bool * exe_ready
pointer on worker, do not use reference while worker will care about correct cleanup
bool null() const
Returns true if time stamp is not initialized or its value less than 0.
void Reset()
Set time stamp value to null.
static TimeStamp Now()
Method returns TimeStamp instance with current time stamp value, measured either by fast TSC (if it i...
void GetNow()
Method to acquire current time stamp.
double AsDouble() const
Return time stamp in form of double (in seconds)