Public Member Functions | |
QCommand () | |
ctor | |
virtual | ~QCommand () |
dtor | |
bool | IsValid () const |
check whether all mandatory parameters were provided for this command | |
const std::map< std::string, std::list< std::string > > & | GetAnswerMap () const |
get map containing command answer informations | |
virtual void | Execute ()=0 |
execute command | |
virtual void | CheckParams ()=0 |
chech whether all parameters are present and meaningful | |
Protected Member Functions | |
const std::string & | GetModifier () const |
get command modifier | |
void | SetError (const QError &err) |
bool | GetBool (const std::string &name, bool &val) const |
get bool parameter | |
bool | GetBoolList (const std::string &name, std::list< bool > &values) const |
get list of bool values associated to a given parameter name | |
bool | GetInt (const std::string &name, int &val) const |
get int parameter | |
bool | GetIntList (const std::string &name, std::list< int > &values) const |
get list of int values associated to a given parameter name | |
bool | GetDouble (const std::string &name, double &val) const |
get double parameter | |
bool | GetDoubleList (const std::string &name, std::list< double > &values) const |
get list of double values associated to a given parameter name | |
bool | GetString (const std::string &name, std::string &val) const |
get string parameter | |
bool | GetStringList (const std::string &name, std::list< std::string > &values) const |
get list of string values associated to a given parameter name | |
bool | IsParamDefined (const std::string &name) const |
check whether a parameter named name is defined | |
const std::map< std::string, std::list< std::string > > & | GetParMap () const |
bool | AddBoolToAnswer (const std::string &parName, bool val) |
add bool parameter named parName to answer map | |
bool | AddIntToAnswer (const std::string &parName, int val) |
add int parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details | |
bool | AddDoubleToAnswer (const std::string &parName, double val) |
add double parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details | |
bool | AddStringToAnswer (const std::string &parName, const std::string &val) |
add string parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details | |
bool | AddToAnswer (const std::string &parName, const std::list< std::string > &values) |
add list of values whose parameter name is parName to the answer map. | |
bool | SetSuccess () |
utility function equivalent to AddBoolToAnswer("success",true) | |
Private Member Functions | |
void | Reset () |
void | SetModifier (const std::string &mod) |
void | SetParams (const std::map< std::string, std::list< std::string > > &parMap) |
set parameters map | |
Private Attributes | |
std::string | fModifier |
bool | fHasError |
std::map< std::string, std::list< std::string > > | fParamMap |
std::map< std::string, std::list< std::string > > | fAnswerMap |
Friends | |
class | QBaseCmdParser |
virtual void QCommand::Execute | ( | ) | [pure virtual] |
execute command
This method should be called after CheckParams(), and only if after calling CheckParams() the command is still valid and has no errors.
This method is expected to execute the command by calling the appropriate method of the main server object based on the modifier and the parameters obtained in CheckParams().
Implemented in QDaqStateCommand, QMsgCommand, QMsgGetCommand, QSlowBaseCommand, and QNullCommand.
Referenced by QCommandHandler::HandleCommand().
virtual void QCommand::CheckParams | ( | ) | [pure virtual] |
chech whether all parameters are present and meaningful
The aim of this method is to separate checks on command correctness from command execution (performed in Execute()).
This method should check whether all the parameters needed for the requested command/modifier pair are present and make sense.
In case of failure an error must be set by calling SetError()
Implemented in QDaqStateCommand, QMsgCommand, QMsgGetCommand, QSlowBaseCommand, and QNullCommand.
void QCommand::SetError | ( | const QError & | err | ) | [protected] |
set error
References fAnswerMap, fHasError, QError::GetCode(), QError::GetDescription(), and QStringHandler::IntToString().
Referenced by QDaqStateCommand::CheckParams(), QDaqStateCommand::CheckStartParams(), QDaqStateCommand::CheckStopParams(), QMsgGetCommand::Execute(), QDaqStateCommand::Execute(), and QNullCommand::QNullCommand().
bool QCommand::GetBool | ( | const std::string & | name, | |
bool & | val | |||
) | const [protected] |
get bool parameter
val | is filled with value of requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToBool().
bool QCommand::GetBoolList | ( | const std::string & | name, | |
std::list< bool > & | values | |||
) | const [protected] |
get list of bool values associated to a given parameter name
values | is filled with values of the requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToBool().
bool QCommand::GetInt | ( | const std::string & | name, | |
int & | val | |||
) | const [protected] |
get int parameter
val | is filled with value of requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToInt().
Referenced by QDaqStateCommand::CheckStartParams(), and QDaqStateCommand::CheckStopParams().
bool QCommand::GetIntList | ( | const std::string & | name, | |
std::list< int > & | values | |||
) | const [protected] |
get list of int values associated to a given parameter name
values | is filled with values of the requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToInt().
bool QCommand::GetDouble | ( | const std::string & | name, | |
double & | val | |||
) | const [protected] |
get double parameter
val | is filled with value of requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToDouble().
bool QCommand::GetDoubleList | ( | const std::string & | name, | |
std::list< double > & | values | |||
) | const [protected] |
get list of double values associated to a given parameter name
values | is filled with values of the requested parameter |
References fParamMap, IsParamDefined(), and QStringHandler::StringToDouble().
bool QCommand::GetString | ( | const std::string & | name, | |
std::string & | val | |||
) | const [protected] |
get string parameter
val | is filled with value of requested parameter |
References fParamMap, and IsParamDefined().
Referenced by QDaqStateCommand::CheckStartParams(), and QDaqStateCommand::CheckStopParams().
bool QCommand::GetStringList | ( | const std::string & | name, | |
std::list< std::string > & | values | |||
) | const [protected] |
get list of string values associated to a given parameter name
values | is filled with values of the requested parameter |
References fParamMap, and IsParamDefined().
const std::map<std::string, std::list<std::string> >& QCommand::GetParMap | ( | ) | const [inline, protected] |
get parameters map
References fParamMap.
bool QCommand::AddBoolToAnswer | ( | const std::string & | parName, | |
bool | val | |||
) | [protected] |
add bool parameter named parName to answer map
References QStringHandler::BoolToString(), fAnswerMap, and IsValid().
Referenced by SetSuccess().
bool QCommand::AddIntToAnswer | ( | const std::string & | parName, | |
int | val | |||
) | [protected] |
add int parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details
References fAnswerMap, QStringHandler::IntToString(), and IsValid().
bool QCommand::AddDoubleToAnswer | ( | const std::string & | parName, | |
double | val | |||
) | [protected] |
add double parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details
References QStringHandler::DoubleToString(), fAnswerMap, and IsValid().
bool QCommand::AddStringToAnswer | ( | const std::string & | parName, | |
const std::string & | val | |||
) | [protected] |
add string parameter named parName to answer map. See documentation of AddBoolToAnswer() for further details
References fAnswerMap, and IsValid().
bool QCommand::AddToAnswer | ( | const std::string & | parName, | |
const std::list< std::string > & | values | |||
) | [protected] |
add list of values whose parameter name is parName to the answer map.
References fAnswerMap, and IsValid().
void QCommand::Reset | ( | ) | [private] |
reset modifier, parameters map, answer and error
References fAnswerMap, fHasError, fModifier, and fParamMap.
void QCommand::SetModifier | ( | const std::string & | mod | ) | [inline, private] |
set modifier
References fModifier.
void QCommand::SetParams | ( | const std::map< std::string, std::list< std::string > > & | parMap | ) | [inline, private] |
set parameters map
It is assumed by this object that at least one element is contained in list associated to each parameter name in parMap.
References fParamMap.
std::string QCommand::fModifier [private] |
command modifier
Referenced by GetModifier(), Reset(), and SetModifier().
bool QCommand::fHasError [private] |
whether command has error
Referenced by IsValid(), Reset(), and SetError().
std::map<std::string, std::list<std::string> > QCommand::fParamMap [private] |
key: parameter name, value: list of corresponding parameter values
Referenced by GetBool(), GetBoolList(), GetDouble(), GetDoubleList(), GetInt(), GetIntList(), GetParMap(), GetString(), GetStringList(), IsParamDefined(), Reset(), and SetParams().
std::map<std::string, std::list<std::string> > QCommand::fAnswerMap [private] |
map with results of executed commad, used to build answer to be sent back to client.
The structure of this map is the same as fParamMap.
Referenced by AddBoolToAnswer(), AddDoubleToAnswer(), AddIntToAnswer(), AddStringToAnswer(), AddToAnswer(), GetAnswerMap(), Reset(), and SetError().