DABC (Data Acquisition Backbone Core)  2.9.9
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Friends
dabc::Command Class Reference

Represents command with its arguments. More...

#include <dabc/Command.h>

Inheritance diagram for dabc::Command:
dabc::Record dabc::Reference dabc::CmdCleanupApplication dabc::CmdConnectionManagerHandle dabc::CmdCreateAny dabc::CmdCreateApplication dabc::CmdCreateDataInput dabc::CmdCreateDevice dabc::CmdCreateMemoryPool dabc::CmdCreateObject dabc::CmdCreateThread dabc::CmdCreateTransport dabc::CmdDataInputClosed dabc::CmdDataInputFailed dabc::CmdDeletePool dabc::CmdDestroyDevice dabc::CmdDestroyTransport dabc::CmdGetBinary dabc::CmdGetNamesList dabc::CmdGetNodesState dabc::CmdGlobalConnect dabc::CmdHierarchyExec dabc::CmdModule dabc::CmdParameterEvent dabc::CmdPublisher dabc::CmdSetParameter dabc::CmdStateTransition dabc::CmdSubscriber

Public Member Functions

void AddValuesFrom (const Command &cmd, bool canoverwrite=true)
 
void Cancel ()
 Call this method to cancel command execution. More...
 
void ChangeName (const std::string &name)
 Change command name, should not be used for remote commands. More...
 
void ClearResult ()
 
 Command (const std::string &name) throw ()
 Default constructor, creates empty reference on the command. More...
 
bool GetBool (const std::string &name, bool dflt=false) const
 
double GetDouble (const std::string &name, double dflt=0.) const
 
int GetInt (const std::string &name, int dflt=0) const
 
int GetPriority () const
 Returns command priority. More...
 
void * GetPtr (const std::string &name, void *deflt=0) const
 Get pointer argument from the command. More...
 
Buffer GetRawData ()
 Returns reference on raw data Can be called only once - raw data reference will be cleaned. More...
 
std::string GetReceiver () const
 
Reference GetRef (const std::string &name)
 Returns reference from the command, can be called only once. More...
 
int GetResult () const
 
std::string GetStr (const std::string &name, const std::string &dflt="") const
 
unsigned GetUInt (const std::string &name, unsigned dflt=0) const
 
bool HasResult () const
 
bool IsCanceled ()
 Return true if command was canceled. More...
 
bool IsTimedout () const
 Returns true if command timeout is expired. More...
 
bool IsTimeoutSet () const
 Return true if timeout was specified. More...
 
void Print (int lvl=0, const char *from=nullptr) const
 Show on debug output content of command. More...
 
bool ReadFromCmdString (const std::string &str)
 Read command from string, which is typed in std output. More...
 
void Release ()
 Method used to clean command - all internal data will be cleaned, command container will be released. More...
 
void RemoveReceiver ()
 
void Reply (int res=cmd_noresult)
 Replied on the command. More...
 
void ReplyBool (bool res)
 Reply on the command with true or false value. More...
 
void ReplyFalse ()
 Reply on the command with false (cmd_false==0) value. More...
 
void ReplyTimedout ()
 Reply on the command with timeout value. More...
 
void ReplyTrue ()
 Reply on the command with true (cmd_true==1) value. More...
 
void ResetTimeout ()
 Disable timeout for the command. More...
 
bool SetBool (const std::string &name, bool v)
 
bool SetDouble (const std::string &name, double v)
 
bool SetInt (const std::string &name, int v)
 
void SetPriority (int prio)
 Set command priority, defines how fast command should be treated In special cases priority allows to execute command also in worker which is not active. More...
 
void SetPtr (const std::string &name, void *p)
 Set pointer argument for the command. More...
 
bool SetRawData (Buffer rawdata)
 Set raw data to the command, which can be transported also between nodes. More...
 
CommandSetReceiver (const std::string &itemname)
 These methods prepare command so, that one can submit command to the manager like: dabc::mgr.Submit(Command("Start").SetReceiver("Generator")); Command will be queued in manager queue and than submitted to specified object. More...
 
bool SetRef (const std::string &name, Reference ref)
 Set reference to the command. More...
 
void SetResult (int res)
 
bool SetStr (const std::string &name, const char *value)
 
bool SetStr (const std::string &name, const std::string &value)
 
bool SetStrRawData (const std::string &str)
 Set raw data with string content. More...
 
CommandSetTimeout (double tm)
 Set maximum time which can be used for command execution. More...
 
bool SetUInt (const std::string &name, unsigned v)
 
double TimeTillTimeout (double extra=0.) const
 Returns time which remains until command should be timed out. More...
 
- Public Member Functions inherited from dabc::Reference
bool AddChild (Object *obj)
 Add child to list of object children. More...
 
const char * ClassName () const
 Return class name of referenced object, if object not assigned, returns "---". More...
 
void Destroy () throw ()
 Release reference and starts destroyment of referenced object. More...
 
Reference FindChild (const char *name) const
 Searches for child in referenced object. More...
 
bool GetAllChildRef (ReferencesVector *vect) const
 Return references for all childs. More...
 
Reference GetChild (unsigned n) const
 Return reference on child n. More...
 
Reference GetFolder (const std::string &name, bool force=false) throw ()
 Return folder of specified name, no special symbols are allowed. More...
 
const char * GetName () const
 Return name of referenced object, if object not assigned, returns "---". More...
 
ObjectGetObject () const
 Return pointer on the object. More...
 
ObjectGetParent () const
 Returns pointer on parent object. More...
 
Reference GetParentRef () const
 Returns reference on parent object. More...
 
bool IsName (const char *name) const
 Returns true if object name is the same as specified one. More...
 
std::string ItemName (bool compact=true) const
 Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call. More...
 
bool null () const
 Returns true if reference contains nullptr. More...
 
unsigned NumChilds () const
 Return number of childs in referenced object. More...
 
unsigned NumReferences () const
 Returns number of references on the object. More...
 
bool operator! () const
 Returns true if reference contains nullptr. More...
 
bool operator!= (const Reference &src) const
 Compare operator - return true if references refer to different object. More...
 
bool operator!= (Object *obj) const
 Compare operator - return true if reference refer to different objects. More...
 
Objectoperator() () const
 Return pointer on the object. More...
 
Referenceoperator<< (Reference &src) throw ()
 Move operator - reference moved from source to target. More...
 
Referenceoperator= (const Reference &src) throw ()
 Assignment operator - copy reference. More...
 
Referenceoperator= (Object *obj) throw ()
 Assignment operator - copy reference. More...
 
bool operator== (const Reference &src) const
 Compare operator - return true if references refer to same object. More...
 
bool operator== (Object *obj) const
 Compare operator - return true if reference refer to same object. More...
 
void Print (int lvl=0, const char *from=0) const
 Show on debug output content of reference. More...
 
 Reference (const Reference &src) throw ()
 Copy constructor, if source is transient than source reference will be emptied. More...
 
 Reference (Object *obj=nullptr)
 Constructor, creates reference on the object. More...
 
std::string RelativeName (const dabc::Reference &topitem)
 Produce name, which can be used to find item, calling topitem.FindChild(). More...
 
void Release () throw ()
 Releases reference on the object. More...
 
bool RemoveChild (const char *name, bool cleanup=true)
 Remove child with given name and return reference on that child. More...
 
bool RemoveChilds (bool cleanup=true)
 Remove all childs in referenced object If cleanup true (default) and object is owner, all objects will be destroyed. More...
 
void SetAutoDestroy (bool on=true)
 Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared. More...
 
void SetObject (Object *obj, bool withmutex=true)
 Direct set of object to reference. More...
 
Reference Take ()
 Copy reference to output object. More...
 
virtual ~Reference ()
 Destructor, releases reference on the object. More...
 

Static Public Member Functions

static const char * PriorityParName ()
 Name of the parameter, used to keep command priority. More...
 
static const char * ReceiverParName ()
 Name of the parameter, used to specified command receiver. More...
 
static const char * ResultParName ()
 Name of the parameter, used to keep command result. More...
 

Protected Member Functions

virtual void CreateRecord (const std::string &name)
 
- Protected Member Functions inherited from dabc::Reference
bool AcquireRefWithoutMutex (Reference &ref)
 Special method, which allows to generate new reference when object mutex is locked. More...
 
void Assign (const Reference &src)
 Method used in copy constructor and assigned operations. More...
 
MutexObjectMutex () const
 
template<class T >
bool verify_object (Object *src, T *&tgt)
 Method used in reference constructor/assignments to verify is object is suitable. More...
 

Private Member Functions

void AddCaller (Worker *worker, bool *exe_ready=nullptr)
 
bool IsLastCallerSync ()
 
void RemoveCaller (Worker *worker, bool *exe_ready=nullptr)
 

Friends

class CommandContainer
 
class CommandsQueue
 
int operator== (const Command &cmd1, const Command &cmd2)
 Compare operator, returns true when command contains pointer on same object. More...
 
class Thread
 
class Worker
 

Additional Inherited Members

- Protected Attributes inherited from dabc::Reference
ObjectfObj
 pointer on the object More...
 

Detailed Description

Represents command with its arguments.

Command is just container for command arguments and results. Execution of command should be implemented in dabc::Worker::ExecuteCommand() method.

Definition at line 99 of file Command.h.

Constructor & Destructor Documentation

◆ Command()

dabc::Command::Command ( const std::string &  name)
throw (
)

Default constructor, creates empty reference on the command.

Definition at line 56 of file Command.cxx.

Member Function Documentation

◆ AddCaller()

void dabc::Command::AddCaller ( Worker worker,
bool *  exe_ready = nullptr 
)
private

Definition at line 68 of file Command.cxx.

◆ RemoveCaller()

void dabc::Command::RemoveCaller ( Worker worker,
bool *  exe_ready = nullptr 
)
private

Definition at line 78 of file Command.cxx.

◆ IsLastCallerSync()

bool dabc::Command::IsLastCallerSync ( )
private

Definition at line 96 of file Command.cxx.

◆ CreateRecord()

virtual void dabc::Command::CreateRecord ( const std::string &  name)
inlineprotectedvirtual

Reimplemented from dabc::Record.

Definition at line 117 of file Command.h.

◆ ChangeName()

void dabc::Command::ChangeName ( const std::string &  name)

Change command name, should not be used for remote commands.

Definition at line 62 of file Command.cxx.

◆ SetStr() [1/2]

bool dabc::Command::SetStr ( const std::string &  name,
const char *  value 
)
inline

Definition at line 134 of file Command.h.

◆ SetStr() [2/2]

bool dabc::Command::SetStr ( const std::string &  name,
const std::string &  value 
)
inline

Definition at line 135 of file Command.h.

◆ GetStr()

std::string dabc::Command::GetStr ( const std::string &  name,
const std::string &  dflt = "" 
) const
inline

Definition at line 136 of file Command.h.

◆ SetInt()

bool dabc::Command::SetInt ( const std::string &  name,
int  v 
)
inline

Definition at line 138 of file Command.h.

◆ GetInt()

int dabc::Command::GetInt ( const std::string &  name,
int  dflt = 0 
) const
inline

Definition at line 139 of file Command.h.

◆ SetBool()

bool dabc::Command::SetBool ( const std::string &  name,
bool  v 
)
inline

Definition at line 141 of file Command.h.

◆ GetBool()

bool dabc::Command::GetBool ( const std::string &  name,
bool  dflt = false 
) const
inline

Definition at line 142 of file Command.h.

◆ SetDouble()

bool dabc::Command::SetDouble ( const std::string &  name,
double  v 
)
inline

Definition at line 144 of file Command.h.

◆ GetDouble()

double dabc::Command::GetDouble ( const std::string &  name,
double  dflt = 0. 
) const
inline

Definition at line 145 of file Command.h.

◆ SetUInt()

bool dabc::Command::SetUInt ( const std::string &  name,
unsigned  v 
)
inline

Definition at line 147 of file Command.h.

◆ GetUInt()

unsigned dabc::Command::GetUInt ( const std::string &  name,
unsigned  dflt = 0 
) const
inline

Definition at line 148 of file Command.h.

◆ SetPtr()

void dabc::Command::SetPtr ( const std::string &  name,
void *  p 
)

Set pointer argument for the command.

Definition at line 151 of file Command.cxx.

◆ GetPtr()

void * dabc::Command::GetPtr ( const std::string &  name,
void *  deflt = 0 
) const

Get pointer argument from the command.

Definition at line 158 of file Command.cxx.

◆ SetRef()

bool dabc::Command::SetRef ( const std::string &  name,
Reference  ref 
)

Set reference to the command.

Definition at line 168 of file Command.cxx.

◆ GetRef()

dabc::Reference dabc::Command::GetRef ( const std::string &  name)

Returns reference from the command, can be called only once.

Definition at line 175 of file Command.cxx.

◆ SetRawData()

bool dabc::Command::SetRawData ( Buffer  rawdata)

Set raw data to the command, which can be transported also between nodes.

Definition at line 334 of file Command.cxx.

◆ SetStrRawData()

bool dabc::Command::SetStrRawData ( const std::string &  str)

Set raw data with string content.

Definition at line 340 of file Command.cxx.

◆ GetRawData()

dabc::Buffer dabc::Command::GetRawData ( )

Returns reference on raw data Can be called only once - raw data reference will be cleaned.

Definition at line 347 of file Command.cxx.

◆ AddValuesFrom()

void dabc::Command::AddValuesFrom ( const Command cmd,
bool  canoverwrite = true 
)

Definition at line 187 of file Command.cxx.

◆ SetResult()

void dabc::Command::SetResult ( int  res)
inline

Definition at line 173 of file Command.h.

◆ GetResult()

int dabc::Command::GetResult ( ) const
inline

Definition at line 174 of file Command.h.

◆ ClearResult()

void dabc::Command::ClearResult ( )
inline

Definition at line 175 of file Command.h.

◆ HasResult()

bool dabc::Command::HasResult ( ) const
inline

Definition at line 176 of file Command.h.

◆ SetTimeout()

dabc::Command & dabc::Command::SetTimeout ( double  tm)

Set maximum time which can be used for command execution.

If command is timed out, it will be replied with 'cmd_timedout' value.

Parameters
[in]tmtimeout value, if <=0, timeout for command will be disabled
Returns
reference on command itself

Definition at line 108 of file Command.cxx.

◆ IsTimeoutSet()

bool dabc::Command::IsTimeoutSet ( ) const

Return true if timeout was specified.

Definition at line 124 of file Command.cxx.

◆ TimeTillTimeout()

double dabc::Command::TimeTillTimeout ( double  extra = 0.) const

Returns time which remains until command should be timed out.

If returns positive value, timeout was specified and not yet expired (value is time in seconds till timeout) If returns 0 timeout is happened. If returns negative value, timeout was not specified for the command. Parameter extra allows to increase/decrease timeout time

Definition at line 132 of file Command.cxx.

◆ IsTimedout()

bool dabc::Command::IsTimedout ( ) const
inline

Returns true if command timeout is expired.

Definition at line 195 of file Command.h.

◆ ResetTimeout()

void dabc::Command::ResetTimeout ( )
inline

Disable timeout for the command.

Definition at line 198 of file Command.h.

◆ ReadFromCmdString()

bool dabc::Command::ReadFromCmdString ( const std::string &  str)

Read command from string, which is typed in std output.

in simple case string is just command name One could specify arguments as list parameters, separated by spaces One also can specify arguments name with syntax arg_name=arg_value. Valid syntax is: ping ping lxg0534 ping addr=lxg0534 port=2233

Definition at line 292 of file Command.cxx.

◆ SetPriority()

void dabc::Command::SetPriority ( int  prio)
inline

Set command priority, defines how fast command should be treated In special cases priority allows to execute command also in worker which is not active.

Definition at line 213 of file Command.h.

◆ GetPriority()

int dabc::Command::GetPriority ( ) const

Returns command priority.

Definition at line 146 of file Command.cxx.

◆ Print()

void dabc::Command::Print ( int  lvl = 0,
const char *  from = nullptr 
) const

Show on debug output content of command.

Definition at line 193 of file Command.cxx.

◆ Reply()

void dabc::Command::Reply ( int  res = cmd_noresult)

Replied on the command.

Only non-negative value should be set as result value. There are several special negative values: cmd_timedout = -1 - command was timed-out If result value is already set, one can call cmd.Reply() to just inform receiver that command is executed. After call of Reply() method command is no longer available to the user.

Definition at line 225 of file Command.cxx.

◆ ReplyFalse()

void dabc::Command::ReplyFalse ( )
inline

Reply on the command with false (cmd_false==0) value.

Definition at line 232 of file Command.h.

◆ ReplyTrue()

void dabc::Command::ReplyTrue ( )
inline

Reply on the command with true (cmd_true==1) value.

Definition at line 235 of file Command.h.

◆ ReplyBool()

void dabc::Command::ReplyBool ( bool  res)
inline

Reply on the command with true or false value.

Definition at line 238 of file Command.h.

◆ ReplyTimedout()

void dabc::Command::ReplyTimedout ( )
inline

Reply on the command with timeout value.

Definition at line 241 of file Command.h.

◆ Release()

void dabc::Command::Release ( )

Method used to clean command - all internal data will be cleaned, command container will be released.

Definition at line 198 of file Command.cxx.

◆ Cancel()

void dabc::Command::Cancel ( )

Call this method to cancel command execution.

Method must be used by initiator of the command. As far as possible command execution will be canceled

Definition at line 203 of file Command.cxx.

◆ IsCanceled()

bool dabc::Command::IsCanceled ( )

Return true if command was canceled.

Definition at line 214 of file Command.cxx.

◆ SetReceiver()

Command& dabc::Command::SetReceiver ( const std::string &  itemname)
inline

These methods prepare command so, that one can submit command to the manager like: dabc::mgr.Submit(Command("Start").SetReceiver("Generator")); Command will be queued in manager queue and than submitted to specified object.

If object has own thread, it will be used for command execution name can include node address in form: dabc://node.domain:8765/Item If connection with such node established, command will be delivered

Definition at line 264 of file Command.h.

◆ GetReceiver()

std::string dabc::Command::GetReceiver ( ) const
inline

Definition at line 267 of file Command.h.

◆ RemoveReceiver()

void dabc::Command::RemoveReceiver ( )
inline

Definition at line 268 of file Command.h.

◆ ReceiverParName()

static const char* dabc::Command::ReceiverParName ( )
inlinestatic

Name of the parameter, used to specified command receiver.

It can contain full url, including node name and item name

Definition at line 272 of file Command.h.

◆ ResultParName()

static const char* dabc::Command::ResultParName ( )
inlinestatic

Name of the parameter, used to keep command result.

Definition at line 275 of file Command.h.

◆ PriorityParName()

static const char* dabc::Command::PriorityParName ( )
inlinestatic

Name of the parameter, used to keep command priority.

Definition at line 278 of file Command.h.

Friends And Related Function Documentation

◆ CommandContainer

friend class CommandContainer
friend

Definition at line 103 of file Command.h.

◆ CommandsQueue

friend class CommandsQueue
friend

Definition at line 104 of file Command.h.

◆ Worker

friend class Worker
friend

Definition at line 105 of file Command.h.

◆ Thread

friend class Thread
friend

Definition at line 106 of file Command.h.

◆ operator==

int operator== ( const Command cmd1,
const Command cmd2 
)
friend

Compare operator, returns true when command contains pointer on same object.

Definition at line 129 of file Command.h.


The documentation for this class was generated from the following files: