added conditional messages to find command with "-a" option and include condition prefix for CSV format
also allow passing scan messages with --checkconfig and --scanconfig (without --inject) be more verbose on errors in configuration files improved code style
This commit is contained in:
+165
-180
@@ -92,12 +92,12 @@ class Message : public AttributedItem {
|
||||
* @param pollPriority the priority for polling, or 0 for no polling at all.
|
||||
* @param condition the @a Condition for this message, or NULL.
|
||||
*/
|
||||
Message(const string circuit, const string level, const string name,
|
||||
const bool isWrite, const bool isPassive, const map<string, string>& attributes,
|
||||
const symbol_t srcAddress, const symbol_t dstAddress,
|
||||
const vector<symbol_t> id,
|
||||
const DataField* data, const bool deleteData,
|
||||
const size_t pollPriority = 0,
|
||||
Message(const string& circuit, const string& level, const string& name,
|
||||
bool isWrite, bool isPassive, const map<string, string>& attributes,
|
||||
symbol_t srcAddress, symbol_t dstAddress,
|
||||
const vector<symbol_t>& id,
|
||||
const DataField* data, bool deleteData,
|
||||
size_t pollPriority = 0,
|
||||
Condition* condition = NULL);
|
||||
|
||||
|
||||
@@ -113,9 +113,9 @@ class Message : public AttributedItem {
|
||||
* @param data the @a DataField for encoding/decoding the message.
|
||||
* @param deleteData whether to delete the @a DataField during destruction.
|
||||
*/
|
||||
Message(const string circuit, const string level, const string name,
|
||||
const symbol_t pb, const symbol_t sb,
|
||||
const bool broadcast, const DataField* data, const bool deleteData);
|
||||
Message(const string& circuit, const string& level, const string& name,
|
||||
symbol_t pb, symbol_t sb,
|
||||
bool broadcast, const DataField* data, bool deleteData);
|
||||
|
||||
|
||||
public:
|
||||
@@ -134,9 +134,8 @@ class Message : public AttributedItem {
|
||||
* @param dstAddress the destination address, or @a SYN for any (set later).
|
||||
* @return the key for the ID.
|
||||
*/
|
||||
static uint64_t createKey(const vector<symbol_t> id,
|
||||
const bool isWrite, const bool isPassive,
|
||||
const symbol_t srcAddress, const symbol_t dstAddress);
|
||||
static uint64_t createKey(const vector<symbol_t>& id, bool isWrite, bool isPassive, symbol_t srcAddress,
|
||||
symbol_t dstAddress);
|
||||
|
||||
/**
|
||||
* Calculate the key for the @a MasterSymbolString.
|
||||
@@ -154,7 +153,7 @@ class Message : public AttributedItem {
|
||||
* @param broadcast true for broadcast scan message, false for scan message to be sent to a slave address.
|
||||
* @return the key for the scan message.
|
||||
*/
|
||||
static uint64_t createKey(const symbol_t pb, const symbol_t sb, const bool broadcast);
|
||||
static uint64_t createKey(symbol_t pb, symbol_t sb, bool broadcast);
|
||||
|
||||
/**
|
||||
* Get the length field from the key.
|
||||
@@ -169,26 +168,29 @@ class Message : public AttributedItem {
|
||||
* @param id the vector to which to add the parsed values.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
static result_t parseId(string input, vector<symbol_t>& id);
|
||||
static result_t parseId(const string& input, vector<symbol_t>* id);
|
||||
|
||||
/**
|
||||
* Factory method for creating new instances.
|
||||
* @param row the mapped message definition row.
|
||||
* @param subRows the mapped field definition rows.
|
||||
* @param rowDefaults the mapped message definition defaults.
|
||||
* @param subRowDefaults the mapped field definition defaults.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param condition the @a Condition instance for the message, or NULL.
|
||||
* @param filename the name of the file being read.
|
||||
* @param templates the @a DataFieldTemplates to be referenced by name, or NULL.
|
||||
* @param rowDefaults the mapped message definition defaults.
|
||||
* @param subRowDefaults the mapped field definition defaults.
|
||||
* @param typeStr the single type of message to create.
|
||||
* @param condition the @a Condition instance for the message, or NULL.
|
||||
* @param row the mapped message definition row (may be modified).
|
||||
* @param subRows the mapped field definition rows (may be modified).
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param messages the @a vector to which to add created instances.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
* Note: the caller needs to free the created instances.
|
||||
*/
|
||||
static result_t create(map<string, string> row, vector< map<string, string> > subRows,
|
||||
map<string, map<string, string> >& rowDefaults, map<string, vector< map<string, string> > >& subRowDefaults,
|
||||
string& errorDescription, Condition* condition, const string filename, DataFieldTemplates* templates,
|
||||
vector<Message*>& messages);
|
||||
static result_t create(const string& filename, const DataFieldTemplates* templates,
|
||||
const map<string, map<string, string> >& rowDefaults,
|
||||
const map<string, vector< map<string, string> > >& subRowDefaults,
|
||||
const string& typeStr, Condition* condition,
|
||||
map<string, string>* row, vector< map<string, string> >* subRows,
|
||||
string* errorDescription, vector<Message*>* messages);
|
||||
|
||||
/**
|
||||
* Create a new scan @a Message instance.
|
||||
@@ -200,11 +202,11 @@ class Message : public AttributedItem {
|
||||
/**
|
||||
* Extract the known field names from the input string.
|
||||
* @param str the input string with the field names separated by @a FIELD_SEPARATOR.
|
||||
* @param fields the vector to update with the extracted normalized field names with.
|
||||
* @param checkAbbreviated true to also check for abbreviated field names.
|
||||
* @param fields the vector to update with the extracted normalized field names with.
|
||||
* @return true when all fields are valid.
|
||||
*/
|
||||
static bool extractFieldNames(string str, vector<string>& fields, bool checkAbbreviated = true);
|
||||
static bool extractFieldNames(const string& str, bool checkAbbreviated, vector<string>* fields);
|
||||
|
||||
/**
|
||||
* Set that this is a special scanning @a Message instance.
|
||||
@@ -224,8 +226,7 @@ class Message : public AttributedItem {
|
||||
* @param circuit the new circuit name, or empty to use the current circuit name.
|
||||
* @return the derived @a Message instance.
|
||||
*/
|
||||
virtual Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
|
||||
const string circuit = "") const;
|
||||
virtual Message* derive(symbol_t dstAddress, symbol_t srcAddress, const string& circuit) const;
|
||||
|
||||
/**
|
||||
* Derive a new @a Message from this message.
|
||||
@@ -233,7 +234,7 @@ class Message : public AttributedItem {
|
||||
* @param extendCircuit whether to extend the current circuit name with a dot and the new destination address in hex.
|
||||
* @return the derived @a ScanMessage instance.
|
||||
*/
|
||||
Message* derive(const symbol_t dstAddress, const bool extendCircuit) const;
|
||||
Message* derive(symbol_t dstAddress, bool extendCircuit) const;
|
||||
|
||||
/**
|
||||
* Get the optional circuit name.
|
||||
@@ -254,7 +255,7 @@ class Message : public AttributedItem {
|
||||
* level to check.
|
||||
* @return true when access is granted.
|
||||
*/
|
||||
bool hasLevel(const string levels, bool includeEmpty = true) const {
|
||||
bool hasLevel(const string& levels, bool includeEmpty = true) const {
|
||||
return m_level.empty() ? (includeEmpty || levels.empty()) : checkLevel(m_level, levels);
|
||||
}
|
||||
|
||||
@@ -264,14 +265,14 @@ class Message : public AttributedItem {
|
||||
* @param checkLevels the access levels to check against, separated by semicolon.
|
||||
* @return whether the access level matches.
|
||||
*/
|
||||
static bool checkLevel(const string level, const string checkLevels);
|
||||
static bool checkLevel(const string& level, const string& checkLevels);
|
||||
|
||||
/**
|
||||
* Get the specified field name.
|
||||
* @param fieldIndex the index of the field.
|
||||
* @return the field name, or the index as string if not unique or not available.
|
||||
*/
|
||||
virtual string getFieldName(const ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
|
||||
virtual string getFieldName(ssize_t fieldIndex) const { return m_data->getName(fieldIndex); }
|
||||
|
||||
/**
|
||||
* Get whether this is a write message.
|
||||
@@ -329,14 +330,14 @@ class Message : public AttributedItem {
|
||||
* @param index the variable in which to store the message part index, or NULL to ignore.
|
||||
* @return true if the ID matches, false otherwise.
|
||||
*/
|
||||
virtual bool checkId(const MasterSymbolString& master, size_t* index = NULL) const;
|
||||
virtual bool checkId(const MasterSymbolString& master, size_t* index) const;
|
||||
|
||||
/**
|
||||
* Check the ID against the other @a Message.
|
||||
* @param other the other @a Message to check against.
|
||||
* @return true if the ID matches, false otherwise.
|
||||
*/
|
||||
virtual bool checkId(Message& other) const;
|
||||
virtual bool checkId(const Message& other) const;
|
||||
|
||||
/**
|
||||
* Return the key for storing in @a MessageMap.
|
||||
@@ -349,7 +350,7 @@ class Message : public AttributedItem {
|
||||
* @param dstAddress the destination address for the derivation.
|
||||
* @return the derived key for storing in @a MessageMap.
|
||||
*/
|
||||
uint64_t getDerivedKey(const symbol_t dstAddress) const;
|
||||
uint64_t getDerivedKey(symbol_t dstAddress) const;
|
||||
|
||||
/**
|
||||
* Get the polling priority, or 0 for no polling at all.
|
||||
@@ -362,7 +363,7 @@ class Message : public AttributedItem {
|
||||
* @param priority the polling priority, or 0 for no polling at all.
|
||||
* @return true when the priority was changed and polling was not enabled before, false otherwise.
|
||||
*/
|
||||
bool setPollPriority(size_t priority);
|
||||
bool setPollPriority(const size_t priority);
|
||||
|
||||
/**
|
||||
* Set the poll priority suitable for resolving a @a Condition.
|
||||
@@ -396,30 +397,28 @@ class Message : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Prepare the master @a SymbolString for sending a query or command to the bus.
|
||||
* @param srcAddress the source address to set.
|
||||
* @param master the @a MasterSymbolString for writing symbols to.
|
||||
* @param input the @a istringstream to parse the formatted value(s) from.
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
|
||||
* @param index the index of the part to prepare.
|
||||
* @param srcAddress the source address to set.
|
||||
* @param dstAddress the destination address to set, or @a SYN to keep the address defined during construction.
|
||||
* @param separator the separator character between multiple fields (e.g. @a UI_FIELD_SEPARATOR).
|
||||
* @param input the @a istringstream to parse the formatted value(s) from.
|
||||
* @param master the @a MasterSymbolString for writing symbols to.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t prepareMaster(const symbol_t srcAddress, MasterSymbolString& master,
|
||||
istringstream& input, char separator = UI_FIELD_SEPARATOR,
|
||||
const symbol_t dstAddress = SYN, size_t index = 0);
|
||||
result_t prepareMaster(size_t index, symbol_t srcAddress, symbol_t dstAddress,
|
||||
char separator, istringstream* input, MasterSymbolString* master);
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Prepare a part of the master data @a SymbolString for sending (everything including NN).
|
||||
* @param master the @a MasterSymbolString for writing symbols to.
|
||||
* @param input the @a istringstream to parse the formatted value(s) from.
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @param index the index of the part to prepare.
|
||||
* @param separator the separator character between multiple fields.
|
||||
* @param input the @a istringstream to parse the formatted value(s) from.
|
||||
* @param master the @a MasterSymbolString for writing symbols to.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
|
||||
size_t index);
|
||||
virtual result_t prepareMasterPart(size_t index, char separator, istringstream* input, MasterSymbolString* master);
|
||||
|
||||
|
||||
public:
|
||||
@@ -429,7 +428,7 @@ class Message : public AttributedItem {
|
||||
* @param slave the @a SlaveSymbolString for writing symbols to.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t prepareSlave(istringstream& input, SlaveSymbolString& slave);
|
||||
virtual result_t prepareSlave(istringstream* input, SlaveSymbolString* slave);
|
||||
|
||||
/**
|
||||
* Store the last seen master and slave data.
|
||||
@@ -437,68 +436,57 @@ class Message : public AttributedItem {
|
||||
* @param slave the last seen @a SlaveSymbolString.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave);
|
||||
virtual result_t storeLastData(const MasterSymbolString& master, const SlaveSymbolString& slave);
|
||||
|
||||
/**
|
||||
* Store last seen master data.
|
||||
* @param data the last @a MasterSymbolString.
|
||||
* @param index the index of the part to store.
|
||||
* @param data the last @a MasterSymbolString.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t storeLastData(MasterSymbolString& data, size_t index);
|
||||
virtual result_t storeLastData(size_t index, const MasterSymbolString& data);
|
||||
|
||||
/**
|
||||
* Store last seen slave data.
|
||||
* @param data the last seen @a SlaveSymbolString.
|
||||
* @param index the index of the part to store.
|
||||
* @param data the last seen @a SlaveSymbolString.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t storeLastData(SlaveSymbolString& data, size_t index);
|
||||
virtual result_t storeLastData(size_t index, const SlaveSymbolString& data);
|
||||
|
||||
/**
|
||||
* Decode the value from the last stored master data.
|
||||
* @param output the @a ostringstream to append the formatted value to.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* Decode the value from the last stored master or slave data.
|
||||
* @param master true for deocding the master data, false for slave.
|
||||
* @param leadingSeparator whether to prepend a separator before the formatted value.
|
||||
* @param fieldName the optional name of a field to limit the output to.
|
||||
* @param fieldIndex the optional index of the named field to limit the output to, or -1.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t decodeLastMasterData(ostringstream& output, OutputFormat outputFormat = 0,
|
||||
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) const;
|
||||
virtual result_t decodeLastData(bool master, bool leadingSeparator, const char* fieldName,
|
||||
ssize_t fieldIndex, OutputFormat outputFormat, ostream* output) const;
|
||||
|
||||
/**
|
||||
* Decode the value from the last stored slave data.
|
||||
* @param output the @a ostringstream to append the formatted value to.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* Decode the value from the last stored master and slave data.
|
||||
* @param leadingSeparator whether to prepend a separator before the formatted value.
|
||||
* @param fieldName the optional name of a field to limit the output to.
|
||||
* @param fieldIndex the optional index of the named field to limit the output to, or -1.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t decodeLastSlaveData(ostringstream& output, OutputFormat outputFormat = 0,
|
||||
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) const;
|
||||
|
||||
/**
|
||||
* Decode the value from the last stored data.
|
||||
* @param output the @a ostringstream to append the formatted value to.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param leadingSeparator whether to prepend a separator before the formatted value.
|
||||
* @param fieldName the optional name of a field to limit the output to.
|
||||
* @param fieldIndex the optional index of the named field to limit the output to, or -1.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t decodeLastData(ostringstream& output, OutputFormat outputFormat = 0,
|
||||
bool leadingSeparator = false, const char* fieldName = NULL, ssize_t fieldIndex = -1) const;
|
||||
virtual result_t decodeLastData(bool leadingSeparator, const char* fieldName,
|
||||
ssize_t fieldIndex, OutputFormat outputFormat, ostream* output) const;
|
||||
|
||||
/**
|
||||
* Decode a particular numeric field value from the last stored data.
|
||||
* @param output the variable in which to store the value.
|
||||
* @param fieldName the name of the field to decode, or NULL for the first field.
|
||||
* @param fieldIndex the optional index of the named field, or -1.
|
||||
* @param output the variable in which to store the value.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t decodeLastDataNumField(unsigned int& output, const char* fieldName, ssize_t fieldIndex = -1) const;
|
||||
virtual result_t decodeLastDataNumField(const char* fieldName, ssize_t fieldIndex, unsigned int* output) const;
|
||||
|
||||
/**
|
||||
* Get the last seen master data.
|
||||
@@ -539,36 +527,36 @@ class Message : public AttributedItem {
|
||||
|
||||
/**
|
||||
* Write the message definition header or parts of it to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
* @param fieldNames the list of field names to write, or NULL for all.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
static void dumpHeader(ostream& output, vector<string>* fieldNames = NULL);
|
||||
static void dumpHeader(const vector<string>* fieldNames, ostream* output);
|
||||
|
||||
/**
|
||||
* Write the message definition or parts of it to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
* @param fieldNames the list of field names to write, or NULL for all.
|
||||
* @param withConditions whether to include the optional conditions prefix.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
void dump(ostream& output, vector<string>* fieldNames = NULL, bool withConditions = false) const;
|
||||
void dump(const vector<string>* fieldNames, bool withConditions, ostream* output) const;
|
||||
|
||||
/**
|
||||
* Write the specified field to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
* @param fieldName the field name to write.
|
||||
* @param withConditions whether to include the optional conditions prefix.
|
||||
* @param output the @a ostream to append the formatted value to.
|
||||
*/
|
||||
virtual void dumpField(ostream& output, string fieldName, bool withConditions = false) const;
|
||||
virtual void dumpField(const string& fieldName, bool withConditions, ostream* output) const;
|
||||
|
||||
/**
|
||||
* Decode the message from the last stored data.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param leadingSeparator whether to prepend a separator before the first value.
|
||||
* @param fields the list of message and/or data field fields to write, or NULL for all.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
*/
|
||||
virtual void decode(ostringstream& output, OutputFormat outputFormat = 0, bool leadingSeparator = false,
|
||||
vector<string>* fields = NULL) const;
|
||||
virtual void decode(bool leadingSeparator, const vector<string>* fields,
|
||||
OutputFormat outputFormat, ostringstream* output) const;
|
||||
|
||||
protected:
|
||||
/** the optional circuit name. */
|
||||
@@ -676,29 +664,28 @@ class ChainedMessage : public Message {
|
||||
* @param pollPriority the priority for polling, or 0 for no polling at all.
|
||||
* @param condition the @a Condition for this message, or NULL.
|
||||
*/
|
||||
ChainedMessage(const string circuit, const string level, const string name,
|
||||
const bool isWrite, const map<string, string>& attributes,
|
||||
const symbol_t srcAddress, const symbol_t dstAddress,
|
||||
const vector<symbol_t> id,
|
||||
vector< vector<symbol_t> > ids, vector<size_t> lengths,
|
||||
const DataField* data, const bool deleteData,
|
||||
const size_t pollPriority,
|
||||
ChainedMessage(const string& circuit, const string& level, const string& name,
|
||||
bool isWrite, const map<string, string>& attributes,
|
||||
symbol_t srcAddress, symbol_t dstAddress,
|
||||
const vector<symbol_t>& id,
|
||||
const vector< vector<symbol_t> >& ids, const vector<size_t>& lengths,
|
||||
const DataField* data, bool deleteData,
|
||||
size_t pollPriority = 0,
|
||||
Condition* condition = NULL);
|
||||
|
||||
virtual ~ChainedMessage();
|
||||
|
||||
// @copydoc
|
||||
Message* derive(const symbol_t dstAddress, const symbol_t srcAddress = SYN,
|
||||
const string circuit = "") const override;
|
||||
Message* derive(symbol_t dstAddress, symbol_t srcAddress, const string& circuit) const override;
|
||||
|
||||
// @copydoc
|
||||
size_t getIdLength() const override { return m_ids[0].size() - 2; }
|
||||
|
||||
// @copydoc
|
||||
bool checkId(const MasterSymbolString& master, size_t* index = NULL) const override;
|
||||
bool checkId(const MasterSymbolString& master, size_t* index) const override;
|
||||
|
||||
// @copydoc
|
||||
bool checkId(Message& other) const override;
|
||||
bool checkId(const Message& other) const override;
|
||||
|
||||
// @copydoc
|
||||
size_t getCount() const override { return m_ids.size(); }
|
||||
@@ -706,19 +693,19 @@ class ChainedMessage : public Message {
|
||||
|
||||
protected:
|
||||
// @copydoc
|
||||
result_t prepareMasterPart(MasterSymbolString& master, istringstream& input, char separator,
|
||||
size_t index) override;
|
||||
result_t prepareMasterPart(size_t index, const char separator, istringstream* input,
|
||||
MasterSymbolString* master) override;
|
||||
|
||||
|
||||
public:
|
||||
// @copydoc
|
||||
result_t storeLastData(MasterSymbolString& master, SlaveSymbolString& slave) override;
|
||||
result_t storeLastData(const MasterSymbolString& master, const SlaveSymbolString& slave) override;
|
||||
|
||||
// @copydoc
|
||||
result_t storeLastData(MasterSymbolString& data, size_t index) override;
|
||||
result_t storeLastData(size_t index, const MasterSymbolString& data) override;
|
||||
|
||||
// @copydoc
|
||||
result_t storeLastData(SlaveSymbolString& data, size_t index) override;
|
||||
result_t storeLastData(size_t index, const SlaveSymbolString& data) override;
|
||||
|
||||
/**
|
||||
* Combine all last stored data.
|
||||
@@ -728,7 +715,7 @@ class ChainedMessage : public Message {
|
||||
|
||||
protected:
|
||||
// @copydoc
|
||||
void dumpField(ostream& output, string fieldName, bool withConditions = false) const override;
|
||||
void dumpField(const string& fieldName, bool withConditions, ostream* output) const override;
|
||||
|
||||
|
||||
private:
|
||||
@@ -810,27 +797,27 @@ class Condition {
|
||||
/**
|
||||
* Factory method for creating a new instance.
|
||||
* @param condName the name of the condition.
|
||||
* @param row the mapped definition row.
|
||||
* @param rowDefaults the mapped definition defaults.
|
||||
* @param row the mapped definition row.
|
||||
* @param returnValue the variable in which to store the created instance.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
static result_t create(const string condName, map<string, string> row, map<string, string> rowDefaults,
|
||||
SimpleCondition*& returnValue);
|
||||
static result_t create(const string& condName, const map<string, string>& rowDefaults,
|
||||
map<string, string>* row, SimpleCondition** returnValue);
|
||||
|
||||
/**
|
||||
* Derive a new @a SimpleCondition from this condition.
|
||||
* @param valueList the @a string with the new list of values.
|
||||
* @return the derived @a SimpleCondition instance, or NULL if the value list is invalid.
|
||||
*/
|
||||
virtual SimpleCondition* derive(string valueList) const { return NULL; }
|
||||
virtual SimpleCondition* derive(const string& valueList) const { return NULL; }
|
||||
|
||||
/**
|
||||
* Write the condition definition or resolved expression to the @a ostream.
|
||||
* @param output the @a ostream to append to.
|
||||
* @param matched true for dumping the matched value if the condition is true, false for dumping the definition.
|
||||
* @param output the @a ostream to append to.
|
||||
*/
|
||||
virtual void dump(ostream& output, bool matched = false) const = 0;
|
||||
virtual void dump(bool matched, ostream* output) const = 0;
|
||||
|
||||
/**
|
||||
* Combine this condition with another instance using a logical and.
|
||||
@@ -842,12 +829,12 @@ class Condition {
|
||||
/**
|
||||
* Resolve the referred @a Message instance(s) and field index(es).
|
||||
* @param messages the @a MessageMap instance for resolving.
|
||||
* @param errorMessage a @a ostringstream to which to add optional error messages.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or NULL.
|
||||
* @param errorMessage a @a ostringstream to which to add optional error messages.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t resolve(MessageMap* messages, ostringstream& errorMessage,
|
||||
void (*readMessageFunc)(Message* message) = NULL) = 0;
|
||||
virtual result_t resolve(void (*readMessageFunc)(Message* message), MessageMap* messages,
|
||||
ostringstream* errorMessage) = 0;
|
||||
|
||||
/**
|
||||
* Check and return whether this condition is fulfilled.
|
||||
@@ -882,8 +869,8 @@ class SimpleCondition : public Condition {
|
||||
* @param field the field name.
|
||||
* @param hasValues whether a value has to be checked against.
|
||||
*/
|
||||
SimpleCondition(const string condName, const string refName, const string circuit, const string level,
|
||||
const string name, const symbol_t dstAddress, const string field, const bool hasValues = false)
|
||||
SimpleCondition(const string& condName, const string& refName, const string& circuit, const string& level,
|
||||
const string& name, symbol_t dstAddress, const string& field, bool hasValues = false)
|
||||
: Condition(),
|
||||
m_condName(condName), m_refName(refName), m_circuit(circuit), m_level(level), m_name(name),
|
||||
m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { }
|
||||
@@ -894,17 +881,17 @@ class SimpleCondition : public Condition {
|
||||
virtual ~SimpleCondition() {}
|
||||
|
||||
// @copydoc
|
||||
SimpleCondition* derive(string valueList) const override;
|
||||
SimpleCondition* derive(const string& valueList) const override;
|
||||
|
||||
// @copydoc
|
||||
void dump(ostream& output, bool matched = false) const override;
|
||||
void dump(bool matched, ostream* output) const override;
|
||||
|
||||
// @copydoc
|
||||
CombinedCondition* combineAnd(Condition* other) override;
|
||||
|
||||
// @copydoc
|
||||
result_t resolve(MessageMap* messages, ostringstream& errorMessage,
|
||||
void (*readMessageFunc)(Message* message) = NULL) override;
|
||||
result_t resolve(void (*readMessageFunc)(Message* message), MessageMap* messages,
|
||||
ostringstream* errorMessage) override;
|
||||
|
||||
// @copydoc
|
||||
bool isTrue() override;
|
||||
@@ -923,7 +910,7 @@ class SimpleCondition : public Condition {
|
||||
* @param field the field name to check against, or empty for first field.
|
||||
* @return whether the field matches one of the valid values.
|
||||
*/
|
||||
virtual bool checkValue(Message* message, const string field) { return true; }
|
||||
virtual bool checkValue(const Message* message, const string& field) { return true; }
|
||||
|
||||
/** the value that matched in @a checkValue. */
|
||||
string m_matchedValue;
|
||||
@@ -976,8 +963,8 @@ class SimpleNumericCondition : public SimpleCondition {
|
||||
* @param field the field name.
|
||||
* @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check.
|
||||
*/
|
||||
SimpleNumericCondition(const string condName, const string refName, const string circuit, const string level,
|
||||
const string name, const symbol_t dstAddress, const string field, const vector<unsigned int> valueRanges)
|
||||
SimpleNumericCondition(const string& condName, const string& refName, const string& circuit, const string& level,
|
||||
const string& name, symbol_t dstAddress, const string& field, const vector<unsigned int>& valueRanges)
|
||||
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
|
||||
m_valueRanges(valueRanges) { }
|
||||
|
||||
@@ -989,7 +976,7 @@ class SimpleNumericCondition : public SimpleCondition {
|
||||
|
||||
protected:
|
||||
// @copydoc
|
||||
bool checkValue(Message* message, const string field) override;
|
||||
bool checkValue(const Message* message, const string& field) override;
|
||||
|
||||
|
||||
private:
|
||||
@@ -1014,8 +1001,8 @@ class SimpleStringCondition : public SimpleCondition {
|
||||
* @param field the field name.
|
||||
* @param values the valid values.
|
||||
*/
|
||||
SimpleStringCondition(const string condName, const string refName, const string circuit, const string level,
|
||||
const string name, const symbol_t dstAddress, const string field, const vector<string> values)
|
||||
SimpleStringCondition(const string& condName, const string& refName, const string& circuit, const string& level,
|
||||
const string& name, symbol_t dstAddress, const string& field, const vector<string>& values)
|
||||
: SimpleCondition(condName, refName, circuit, level, name, dstAddress, field, true),
|
||||
m_values(values) { }
|
||||
|
||||
@@ -1030,7 +1017,7 @@ class SimpleStringCondition : public SimpleCondition {
|
||||
|
||||
protected:
|
||||
// @copydoc
|
||||
bool checkValue(Message* message, const string field) override;
|
||||
bool checkValue(const Message* message, const string& field) override;
|
||||
|
||||
|
||||
private:
|
||||
@@ -1056,14 +1043,14 @@ class CombinedCondition : public Condition {
|
||||
virtual ~CombinedCondition() {}
|
||||
|
||||
// @copydoc
|
||||
void dump(ostream& output, bool matched = false) const override;
|
||||
void dump(bool matched, ostream* output) const override;
|
||||
|
||||
// @copydoc
|
||||
CombinedCondition* combineAnd(Condition* other) override { m_conditions.push_back(other); return this; }
|
||||
|
||||
// @copydoc
|
||||
result_t resolve(MessageMap* messages, ostringstream& errorMessage,
|
||||
void (*readMessageFunc)(Message* message) = NULL) override;
|
||||
result_t resolve(void (*readMessageFunc)(Message* message), MessageMap* messages,
|
||||
ostringstream* errorMessage) override;
|
||||
|
||||
// @copydoc
|
||||
bool isTrue() override;
|
||||
@@ -1087,7 +1074,7 @@ class Instruction {
|
||||
* executed for the same source file.
|
||||
* @param defaults the mapped definition defaults.
|
||||
*/
|
||||
Instruction(Condition* condition, const bool singleton, const map<string, string>& defaults)
|
||||
Instruction(bool singleton, const map<string, string>& defaults, Condition* condition)
|
||||
: m_condition(condition), m_singleton(singleton), m_defaults(defaults) { }
|
||||
|
||||
/**
|
||||
@@ -1105,9 +1092,9 @@ class Instruction {
|
||||
* @param returnValue the variable in which to store the created instance.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
static result_t create(const string& contextPath, const string type,
|
||||
Condition* condition, map<string, string>& row, map<string, string>& defaults,
|
||||
Instruction*& returnValue);
|
||||
static result_t create(const string& contextPath, const string& type,
|
||||
Condition* condition, const map<string, string>& row, const map<string, string>& defaults,
|
||||
Instruction** returnValue);
|
||||
|
||||
/**
|
||||
* Return the @a Condition this instruction requires.
|
||||
@@ -1133,13 +1120,12 @@ class Instruction {
|
||||
* Execute the instruction.
|
||||
* @param messages the @a MessageMap.
|
||||
* @param log the @a ostringstream to log success messages to (if necessary).
|
||||
* @param condition the @a Condition that was successfully evaluated for execution, or NULL.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
virtual result_t execute(MessageMap* messages, ostringstream& log, Condition* condition) = 0;
|
||||
virtual result_t execute(MessageMap* messages, ostringstream* log) = 0;
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
/** the @a Condition this instruction requires, or null. */
|
||||
Condition* m_condition;
|
||||
|
||||
@@ -1147,8 +1133,6 @@ class Instruction {
|
||||
* same source file. */
|
||||
const bool m_singleton;
|
||||
|
||||
|
||||
protected:
|
||||
/** the defaults by field name. */
|
||||
map<string, string> m_defaults;
|
||||
};
|
||||
@@ -1167,8 +1151,9 @@ class LoadInstruction : public Instruction {
|
||||
* @param defaults the mapped definition defaults.
|
||||
* @param filename the name of the file to load.
|
||||
*/
|
||||
LoadInstruction(Condition* condition, const bool singleton, map<string, string>& defaults, const string filename)
|
||||
: Instruction(condition, singleton, defaults), m_filename(filename) { }
|
||||
LoadInstruction(bool singleton, const map<string, string>& defaults, const string& filename,
|
||||
Condition* condition)
|
||||
: Instruction(singleton, defaults, condition), m_filename(filename) { }
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -1176,7 +1161,7 @@ class LoadInstruction : public Instruction {
|
||||
virtual ~LoadInstruction() { }
|
||||
|
||||
// @copydoc
|
||||
result_t execute(MessageMap* messages, ostringstream& log, Condition* condition) override;
|
||||
result_t execute(MessageMap* messages, ostringstream* log) override;
|
||||
|
||||
|
||||
private:
|
||||
@@ -1215,7 +1200,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param addAll whether to add all messages, even if duplicate.
|
||||
* @param preferLanguage the preferred language to use, or empty.
|
||||
*/
|
||||
explicit MessageMap(const string configPath, const bool addAll = false, const string preferLanguage = "")
|
||||
explicit MessageMap(const string& configPath, bool addAll = false, const string& preferLanguage = "")
|
||||
: MappedFileReader::MappedFileReader(true),
|
||||
m_configPath(configPath),
|
||||
m_addAll(addAll), m_additionalScanMessages(false), m_maxIdLength(0), m_maxBroadcastIdLength(0),
|
||||
@@ -1244,7 +1229,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param filename the name of the configuration file (including relative path).
|
||||
* @return the relative file name.
|
||||
*/
|
||||
const string getRelativePath(const string filename) const;
|
||||
const string getRelativePath(const string& filename) const;
|
||||
|
||||
/**
|
||||
* Add a @a Message instance to this set.
|
||||
@@ -1253,36 +1238,36 @@ class MessageMap : public MappedFileReader {
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
* Note: the caller may not free the added instance on success.
|
||||
*/
|
||||
result_t add(Message* message, bool storeByName = true);
|
||||
result_t add(bool storeByName, Message* message);
|
||||
|
||||
// @copydoc
|
||||
result_t getFieldMap(vector<string>& row, string& errorDescription, const string preferLanguage) const override;
|
||||
result_t getFieldMap(const string& preferLanguage, vector<string>* row, string* errorDescription) const override;
|
||||
|
||||
// @copydoc
|
||||
result_t addDefaultFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
|
||||
string& errorDescription, const string filename, unsigned int lineNo) override;
|
||||
result_t addDefaultFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription) override;
|
||||
|
||||
/**
|
||||
* Read the @a Condition instance(s) from the types field.
|
||||
* @param types the field from which to read the @a Condition instance(s).
|
||||
* @param filename the name of the file being read.
|
||||
* @param types the field from which to read the @a Condition instance(s) and remove the definition prefix.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param condition the variable in which to store the result.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t readConditions(string& types, const string filename, string& errorDescription, Condition*& condition);
|
||||
result_t readConditions(const string& filename, string* types, string* errorDescription, Condition** condition);
|
||||
|
||||
// @copydoc
|
||||
bool extractDefaultsFromFilename(string filename, map<string, string>& defaults,
|
||||
symbol_t* destAddress = NULL, unsigned int* software = NULL, unsigned int* hardware = NULL) const override;
|
||||
bool extractDefaultsFromFilename(const string& filename, map<string, string>* defaults,
|
||||
symbol_t* destAddress, unsigned int* software, unsigned int* hardware) const override;
|
||||
|
||||
// @copydoc
|
||||
result_t readFromFile(const string filename, string& errorDescription, bool verbose = false,
|
||||
map<string, string>* defaults = NULL, size_t* hash = NULL, size_t* size = NULL, time_t* time = NULL) override;
|
||||
result_t readFromFile(const string& filename, bool verbose, map<string, string>* defaults,
|
||||
string* errorDescription, size_t* hash, size_t* size, time_t* time) override;
|
||||
|
||||
// @copydoc
|
||||
result_t addFromFile(map<string, string>& row, vector< map<string, string> >& subRows,
|
||||
string& errorDescription, const string filename, unsigned int lineNo) override;
|
||||
result_t addFromFile(const string& filename, unsigned int lineNo, map<string, string>* row,
|
||||
vector< map<string, string> >* subRows, string* errorDescription) override;
|
||||
|
||||
/**
|
||||
* Get the scan @a Message instance for the specified address.
|
||||
@@ -1299,30 +1284,30 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
/**
|
||||
* Resolve all @a Condition instances.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param verbose whether to verbosely add all problems to the error message.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t resolveConditions(string& errorDescription, bool verbose = false);
|
||||
result_t resolveConditions(bool verbose, string* errorDescription);
|
||||
|
||||
/**
|
||||
* Resolve a @a Condition.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or NULL.
|
||||
* @param condition the @a Condition to resolve.
|
||||
* @param errorDescription a string in which to store the error description in case of error.
|
||||
* @param readMessageFunc the function to call for immediate reading of a @a Message from the bus, or NULL.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t resolveCondition(Condition* condition, string& errorDescription,
|
||||
void (*readMessageFunc)(Message* message) = NULL);
|
||||
result_t resolveCondition(void (*readMessageFunc)(Message* message), Condition* condition,
|
||||
string* errorDescription);
|
||||
|
||||
/**
|
||||
* Run all executable @a Instruction instances.
|
||||
* @param log the @a ostringstream to log success messages to (if necessary).
|
||||
* @param readMessageFunc the function to call for immediate reading of a
|
||||
* @a Message values from the bus required for singleton instructions, or NULL.
|
||||
* @param log the @a ostringstream to log success messages to (if necessary).
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
result_t executeInstructions(ostringstream& log, void (*readMessageFunc)(Message* message) = NULL);
|
||||
result_t executeInstructions(void (*readMessageFunc)(Message* message), ostringstream* log);
|
||||
|
||||
/**
|
||||
* Add a loaded file to a participant.
|
||||
@@ -1330,14 +1315,14 @@ class MessageMap : public MappedFileReader {
|
||||
* @param filename the name of the configuration file (including relative path).
|
||||
* @param comment an optional comment.
|
||||
*/
|
||||
void addLoadedFile(const symbol_t address, const string filename, const string comment = "");
|
||||
void addLoadedFile(symbol_t address, const string& filename, const string& comment = "");
|
||||
|
||||
/**
|
||||
* Get the loaded files for a participant.
|
||||
* @param address the slave address.
|
||||
* @return the loaded configuration files (list of file names with relative path).
|
||||
*/
|
||||
const vector<string>& getLoadedFiles(const symbol_t address) const;
|
||||
const vector<string>& getLoadedFiles(symbol_t address) const;
|
||||
|
||||
/**
|
||||
* Get all loaded files.
|
||||
@@ -1354,7 +1339,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
|
||||
* @return true if the file info was found, false otherwise.
|
||||
*/
|
||||
bool getLoadedFileInfo(const string filename, string& comment, size_t* hash = NULL, size_t* size = NULL,
|
||||
bool getLoadedFileInfo(const string& filename, string* comment, size_t* hash = NULL, size_t* size = NULL,
|
||||
time_t* time = NULL) const;
|
||||
|
||||
/**
|
||||
@@ -1363,7 +1348,7 @@ class MessageMap : public MappedFileReader {
|
||||
* @return the found @a Message instances, or NULL.
|
||||
* Note: the caller may not free the returned instances.
|
||||
*/
|
||||
const vector<Message*>* getByKey(const uint64_t key) const;
|
||||
const vector<Message*>* getByKey(uint64_t key) const;
|
||||
|
||||
/**
|
||||
* Find the @a Message instance for the specified circuit and name.
|
||||
@@ -1375,8 +1360,8 @@ class MessageMap : public MappedFileReader {
|
||||
* @return the @a Message instance, or NULL.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
Message* find(const string& circuit, const string& name, const string& levels, const bool isWrite,
|
||||
const bool isPassive = false) const;
|
||||
Message* find(const string& circuit, const string& name, const string& levels, bool isWrite,
|
||||
bool isPassive = false) const;
|
||||
|
||||
/**
|
||||
* Find all active get @a Message instances for the specified circuit and name.
|
||||
@@ -1400,9 +1385,9 @@ class MessageMap : public MappedFileReader {
|
||||
* Note: the caller may not free the returned instances.
|
||||
*/
|
||||
deque<Message*> findAll(const string& circuit, const string& name, const string& levels,
|
||||
const bool completeMatch = true, const bool withRead = true, const bool withWrite = false,
|
||||
const bool withPassive = false, const bool includeEmptyLevel = true, const bool onlyAvailable = true,
|
||||
const time_t since = 0, const time_t until = 0) const;
|
||||
bool completeMatch = true, bool withRead = true, bool withWrite = false,
|
||||
bool withPassive = false, bool includeEmptyLevel = true, bool onlyAvailable = true,
|
||||
time_t since = 0, time_t until = 0) const;
|
||||
|
||||
/**
|
||||
* Find the @a Message instance for the specified master data.
|
||||
@@ -1416,8 +1401,8 @@ class MessageMap : public MappedFileReader {
|
||||
* @return the @a Message instance, or NULL.
|
||||
* Note: the caller may not free the returned instance.
|
||||
*/
|
||||
Message* find(const MasterSymbolString& master, const bool anyDestination = false, const bool withRead = true,
|
||||
const bool withWrite = true, const bool withPassive = true, const bool onlyAvailable = true) const;
|
||||
Message* find(const MasterSymbolString& master, bool anyDestination = false, bool withRead = true,
|
||||
bool withWrite = true, bool withPassive = true, bool onlyAvailable = true) const;
|
||||
|
||||
/**
|
||||
* Invalidate cached data of the @a Message and all other instances with a matching name key.
|
||||
@@ -1427,19 +1412,19 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
/**
|
||||
* Add a @a Message to the list of instances to poll.
|
||||
* @param message the @a Message to poll.
|
||||
* @param toFront whether to add the @a Message to the very front of the poll queue.
|
||||
* @param message the @a Message to poll.
|
||||
*/
|
||||
void addPollMessage(Message* message, bool toFront = false);
|
||||
void addPollMessage(bool toFront, Message* message);
|
||||
|
||||
/**
|
||||
* Decode circuit specific data.
|
||||
* @param circuit the name of the circuit.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
* @param outputFormat the @a OutputFormat options to use.
|
||||
* @param output the @a ostringstream to append the decoded value(s) to.
|
||||
* @return true if data was added, false otherwise.
|
||||
*/
|
||||
bool decodeCircuit(const string circuit, ostringstream& output, OutputFormat outputFormat) const;
|
||||
bool decodeCircuit(const string& circuit, OutputFormat outputFormat, ostringstream* output) const;
|
||||
|
||||
/**
|
||||
* Removes all @a Message instances.
|
||||
@@ -1491,10 +1476,10 @@ class MessageMap : public MappedFileReader {
|
||||
|
||||
/**
|
||||
* Write the message definitions to the @a ostream.
|
||||
* @param output the @a ostream to append the formatted messages to.
|
||||
* @param withConditions whether to include the optional conditions prefix.
|
||||
* @param output the @a ostream to append the formatted messages to.
|
||||
*/
|
||||
void dump(ostream& output, const bool withConditions = false) const;
|
||||
void dump(bool withConditions, ostream* output) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user