QCommand Class Reference
[ApolloNetworking]

Inheritance diagram for QCommand:

QDaqStateCommand QMsgCommand QMsgGetCommand QNullCommand QSlowBaseCommand

List of all members.


Detailed Description

base class for server side command handling

Author:
Sergio Di Domizio

Marco Pallavicini

Andrea Giachero


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

Member Function Documentation

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]

bool QCommand::GetBool ( const std::string &  name,
bool &  val 
) const [protected]

get bool parameter

Parameters:
val is filled with value of requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to bool fails
This method returns the first element of the list of values for parameter named name, converted to bool

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

Parameters:
values is filled with values of the requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to bool fails

References fParamMap, IsParamDefined(), and QStringHandler::StringToBool().

bool QCommand::GetInt ( const std::string &  name,
int &  val 
) const [protected]

get int parameter

Parameters:
val is filled with value of requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to int fails
This method returns the first element of the list of values for parameter named name, converted to int

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

Parameters:
values is filled with values of the requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to int fails

References fParamMap, IsParamDefined(), and QStringHandler::StringToInt().

bool QCommand::GetDouble ( const std::string &  name,
double &  val 
) const [protected]

get double parameter

Parameters:
val is filled with value of requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to double fails
This method returns the first element of the list of values for parameter named name

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

Parameters:
values is filled with values of the requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map or if conversion to double fails

References fParamMap, IsParamDefined(), and QStringHandler::StringToDouble().

bool QCommand::GetString ( const std::string &  name,
std::string &  val 
) const [protected]

get string parameter

Parameters:
val is filled with value of requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map
This method returns the first element of the list of values for parameter named name

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

Parameters:
values is filled with values of the requested parameter
Returns:
true on success, false if requested parameter cannot be found in parameters map

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

Returns:
true unless IsValid() is false
The list of values associated to the parameter named parName is cleared before adding val.
Use AddToAnswer() method to add a list of value to a single parameter name.

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

Returns:
true unless IsValid() is false

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

Returns:
true unless IsValid() is false

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

Returns:
true unless IsValid() is false

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.

Returns:
true unless IsValid() is false
Pre-existing content of the list associated to parName is eliminated before adding new values.

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.


Member Data Documentation

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().


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

Generated on Tue Nov 16 10:50:05 2010 for CUORE Software by  doxygen 1.5.6