initial commit for github
This commit is contained in:
commit
60968612de
370 changed files with 68427 additions and 0 deletions
364
mapping/configuration/map_assignment.cpp
Normal file
364
mapping/configuration/map_assignment.cpp
Normal file
|
@ -0,0 +1,364 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_assignment.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapAssignment::MapAssignment() : _is_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
MapAssignment::MapAssignment(std::string strTo) : _to(strTo), _is_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
bool MapAssignment::isValid() const
|
||||
{
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getFrom() const
|
||||
{
|
||||
return _from;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getSource() const
|
||||
{
|
||||
return _source;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::connect(const std::string& strSourceElementPath)
|
||||
{
|
||||
_constant.clear();
|
||||
_function.clear();
|
||||
_modulo.clear();
|
||||
_transform.clear();
|
||||
|
||||
_from = strSourceElementPath;
|
||||
a_util::strings::trim(_from);
|
||||
_source.clear();
|
||||
// parse source out of <from>
|
||||
// parse source
|
||||
size_t idx = _from.find('.');
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
_source = _from.substr(0, idx);
|
||||
_from = _from.substr(idx + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no path when the signal itself is referenced
|
||||
_source = _from;
|
||||
_from.clear();
|
||||
}
|
||||
|
||||
if(_source.empty())
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getConstant() const
|
||||
{
|
||||
return _constant;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::setConstant(const std::string& strConstant)
|
||||
{
|
||||
_from.clear();
|
||||
_source.clear();
|
||||
_function.clear();
|
||||
_modulo.clear();
|
||||
_transform.clear();
|
||||
|
||||
_constant = strConstant;
|
||||
a_util::strings::trim(_constant);
|
||||
if(_constant.empty())
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getFunction() const
|
||||
{
|
||||
return _function;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::setSimulationTimeFunction()
|
||||
{
|
||||
_from.clear();
|
||||
_source.clear();
|
||||
_constant.clear();
|
||||
_modulo.clear();
|
||||
_transform.clear();
|
||||
|
||||
_function = "simulation_time";
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::setTriggerCounterFunction(const std::string& strModulo)
|
||||
{
|
||||
_from.clear();
|
||||
_source.clear();
|
||||
_constant.clear();
|
||||
_transform.clear();
|
||||
_function.clear();
|
||||
|
||||
_modulo = strModulo;
|
||||
a_util::strings::trim(_modulo);
|
||||
_function = "trigger_counter";
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::setReceivedFunction(const std::string& strSource)
|
||||
{
|
||||
_from.clear();
|
||||
_source.clear();
|
||||
_constant.clear();
|
||||
_modulo.clear();
|
||||
_transform.clear();
|
||||
|
||||
_source = strSource;
|
||||
a_util::strings::trim(_source);
|
||||
if(_source.empty())
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_function = "received";
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getModulo() const
|
||||
{
|
||||
return _modulo;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getTo() const
|
||||
{
|
||||
return _to;
|
||||
}
|
||||
|
||||
const std::string& MapAssignment::getTransformation() const
|
||||
{
|
||||
return _transform;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::setTransformation(const std::string& strTransformationName)
|
||||
{
|
||||
_transform.clear();
|
||||
if(_source.empty()||_from.empty())
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_transform = strTransformationName;
|
||||
a_util::strings::trim(_transform);
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::removeTransformation()
|
||||
{
|
||||
_transform.clear();
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::loadFromDOM(const a_util::xml::DOMElement& oAssignment, MapErrorList& lstErrors)
|
||||
{
|
||||
// parse attributes
|
||||
const a_util::xml::DOMAttributes mapAttrs = oAssignment.getAttributes();
|
||||
// find target element
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrTo = mapAttrs.find("to");
|
||||
if (itAttrTo == mapAttrs.end() || itAttrTo->second.empty())
|
||||
{
|
||||
lstErrors.push_back("Missing <to> attribute for an <assignment>");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_to = itAttrTo->second;
|
||||
a_util::strings::trim(_to);
|
||||
|
||||
// find Source or constant
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrFrom = mapAttrs.find("from");
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrConst = mapAttrs.find("constant");
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrFct = mapAttrs.find("function");
|
||||
if (itAttrFrom == mapAttrs.end() && itAttrConst == mapAttrs.end() && itAttrFct == mapAttrs.end())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("Missing <from>, <constant> or <function> attribute for <assignment> to '%s'",
|
||||
itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
if (itAttrFrom != mapAttrs.end() && itAttrConst != mapAttrs.end())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<from> and <constant> attributes set at the same time for <assignment> to '%s'",
|
||||
itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
if (itAttrFrom != mapAttrs.end() && itAttrFct != mapAttrs.end())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<from> and <function> attributes set at the same time for <assignment> to '%s'",
|
||||
itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
if (itAttrFct != mapAttrs.end() && itAttrConst != mapAttrs.end())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> and <constant> attributes set at the same time for <assignment> to '%s'",
|
||||
itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (itAttrFrom != mapAttrs.end())
|
||||
{
|
||||
if(itAttrFrom->second.empty())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<from> attribute empty for <assignment> to '%s'",
|
||||
itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
connect(itAttrFrom->second);
|
||||
}
|
||||
else if(itAttrConst != mapAttrs.end())
|
||||
{
|
||||
if(isFailed(setConstant(itAttrConst->second)))
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<constant> attribute empty for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(itAttrFct->second.empty())
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> attribute empty for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_function = itAttrFct->second;
|
||||
|
||||
size_t nIdx1 = _function.find('(');
|
||||
size_t nIdx2 = _function.find(')');
|
||||
if (nIdx1 == std::string::npos || nIdx2 == std::string::npos ||
|
||||
nIdx1 == 0 || nIdx2 == 0 || nIdx1 > nIdx2
|
||||
|| !(_function.find("simulation_time") == 0
|
||||
|| _function.find("trigger_counter") == 0
|
||||
|| _function.find("received") == 0))
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> should be of type 'simulation_time()', \
|
||||
'trigger_counter([Modulo])' or 'received([Signal])' for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
int64_t nLength = (int64_t)nIdx2 - (int64_t)nIdx1 - 1;
|
||||
if(_function.find("simulation_time") == 0)
|
||||
{
|
||||
if(nLength > 0)
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> of type 'simulation_time()' takes no argument for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
setSimulationTimeFunction();
|
||||
}
|
||||
if(_function.find("trigger_counter") == 0)
|
||||
{
|
||||
if(isFailed(setTriggerCounterFunction(_function.substr(nIdx1 + 1, (size_t)nLength))))
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> of type 'trigger_counter()' takes a positive Integer as argument for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
else if(_function.find("received") == 0)
|
||||
{
|
||||
if(isFailed(setReceivedFunction(_function.substr(nIdx1 + 1, (size_t)nLength))))
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<function> of type'received([Signal])' has no argument for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itAttr = mapAttrs.find("transformation");
|
||||
if (itAttr != mapAttrs.end() && !itAttr->second.empty())
|
||||
{
|
||||
if(isFailed(setTransformation(itAttr->second)))
|
||||
{
|
||||
lstErrors.push_back(a_util::strings::format("<transformation> is only accepted for connection for <assignment> \
|
||||
to '%s'", itAttrTo->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapAssignment::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("assignment");
|
||||
oDOMElement.setAttribute("to", _to);
|
||||
if(!_function.empty())
|
||||
{
|
||||
std::string strDOMFunction = _function;
|
||||
if(strDOMFunction == "simulation_time")
|
||||
{
|
||||
strDOMFunction.append("()");
|
||||
}
|
||||
else if(strDOMFunction == "trigger_counter")
|
||||
{
|
||||
strDOMFunction.append(a_util::strings::format("(%s)", _modulo.c_str()));
|
||||
}
|
||||
else if(strDOMFunction == "received")
|
||||
{
|
||||
strDOMFunction.append(a_util::strings::format("(%s)", _source.c_str()));
|
||||
}
|
||||
oDOMElement.setAttribute("function", strDOMFunction);
|
||||
}
|
||||
else if(!_source.empty())
|
||||
{
|
||||
std::string strDOMFrom = _source;
|
||||
if(!_from.empty())
|
||||
{
|
||||
strDOMFrom.push_back('.');
|
||||
strDOMFrom.append(_from);
|
||||
}
|
||||
oDOMElement.setAttribute("from", strDOMFrom);
|
||||
if(!_transform.empty())
|
||||
{
|
||||
oDOMElement.setAttribute("transformation", _transform);
|
||||
}
|
||||
}
|
||||
else if(!_constant.empty())
|
||||
{
|
||||
oDOMElement.setAttribute("constant", _constant);
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
194
mapping/configuration/map_assignment.h
Normal file
194
mapping/configuration/map_assignment.h
Normal file
|
@ -0,0 +1,194 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_ASSIGNMENT_H
|
||||
#define HEADER_MAP_ASSIGNMENT_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
typedef std::vector<std::string> MapErrorList;
|
||||
/**
|
||||
* MapAssignment
|
||||
*/
|
||||
class MapAssignment
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapAssignment();
|
||||
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] name Name of assigned signal or element
|
||||
*/
|
||||
MapAssignment(std::string to);
|
||||
|
||||
/**
|
||||
* Returns the validity for the current description
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Returns the source element name of the assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getFrom() const;
|
||||
|
||||
/**
|
||||
* Returns the source name of the assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getSource() const;
|
||||
|
||||
/**
|
||||
* Connects the target element or signal with a source
|
||||
* @param [in] source_element_path The complete path to the source element
|
||||
* it is constructed with [SignalName].[ElementName]
|
||||
* @retval ERR_INVALID_ARG Source is empty
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result connect(const std::string& source_element_path);
|
||||
|
||||
/**
|
||||
* Returns the constant of the assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getConstant() const;
|
||||
|
||||
/**
|
||||
* Setter for the constant of the assignment
|
||||
* @param [in] constant The constant to assign
|
||||
* @retval ERR_INVALID_ARG Constant is empty
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setConstant(const std::string& constant);
|
||||
|
||||
/**
|
||||
* Returns the constant of the assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getFunction() const;
|
||||
|
||||
/**
|
||||
* Setter for the SimulationTime assignment
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setSimulationTimeFunction();
|
||||
|
||||
/**
|
||||
* Setter for the TriggerCounter assignment
|
||||
* @param [in] modulo The modulo for the function
|
||||
* it represents the maximal value that can be assigned before going back to 0
|
||||
* if left empty, the limit will be the maximal value of Float64
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setTriggerCounterFunction(const std::string& modulo);
|
||||
|
||||
/**
|
||||
* Setter for the Received assignment
|
||||
* @param [in] source The name of the source to consider
|
||||
* @retval ERR_INVALID_ARG Source is empty
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setReceivedFunction(const std::string& source);
|
||||
|
||||
/**
|
||||
* Returns the constant of the assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getModulo() const;
|
||||
|
||||
/**
|
||||
* Returns the name of the target element that is assigned
|
||||
*/
|
||||
const std::string& getTo() const;
|
||||
|
||||
/**
|
||||
* Returns the associated transformation of this assignment (or an empty string)
|
||||
*/
|
||||
const std::string& getTransformation() const;
|
||||
|
||||
/**
|
||||
* Associates the transformation to this assignment
|
||||
* @param [in] transformation_name The name of the transformation to add
|
||||
* @retval ERR_INVALID_ARG Source or from is empty (no signal connected)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setTransformation(const std::string& transformation_name);
|
||||
|
||||
/**
|
||||
* Remove the transformation from this assignment
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeTransformation();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the assignment from a assignment-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] errors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing name or type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOM(const a_util::xml::DOMElement& assignment, MapErrorList& errors);
|
||||
|
||||
/**
|
||||
* Export assignment to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapTarget;
|
||||
std::string _from;
|
||||
std::string _source;
|
||||
std::string _constant;
|
||||
std::string _function; // "simulation_time" -> no args, "trigger_counter" -> arg in modulo, "received" -> arg in from
|
||||
std::string _modulo;
|
||||
std::string _to;
|
||||
std::string _transform;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
inline bool operator==(const MapAssignment& a, const MapAssignment& b)
|
||||
{
|
||||
return a.getConstant() == b.getConstant() && a.getFrom() == b.getFrom() &&
|
||||
a.getSource() == b.getSource() && a.getTo() == b.getTo() &&
|
||||
a.getFunction() == b.getFunction() && a.getModulo() == b.getModulo() &&
|
||||
a.getTransformation() == b.getTransformation();
|
||||
}
|
||||
|
||||
inline bool operator!=(const MapAssignment& a, const MapAssignment& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
/// Public composite types used in the mapping::oo namespace
|
||||
typedef std::vector<MapAssignment> MapAssignmentList;
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_ASSIGNMENT_H
|
1282
mapping/configuration/map_configuration.cpp
Normal file
1282
mapping/configuration/map_configuration.cpp
Normal file
File diff suppressed because it is too large
Load diff
577
mapping/configuration/map_configuration.h
Normal file
577
mapping/configuration/map_configuration.h
Normal file
|
@ -0,0 +1,577 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_CONFIGURATION_H
|
||||
#define HEADER_MAP_CONFIGURATION_H
|
||||
|
||||
#include <vector>
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "ddlrepresentation/ddldescription.h"
|
||||
#include "ddlrepresentation/ddldatatype_intf.h"
|
||||
|
||||
#include "map_header.h"
|
||||
#include "map_source.h"
|
||||
#include "map_transformation.h"
|
||||
#include "map_assignment.h"
|
||||
#include "map_trigger.h"
|
||||
#include "map_target.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
typedef std::vector<std::string> MapErrorList;
|
||||
/**
|
||||
* MapConfiguration is the central class of the mapping::oo namespace.
|
||||
* It represents a whole mapping configuration which can be imported from
|
||||
* a mapping configuration file.
|
||||
*/
|
||||
class MapConfiguration
|
||||
{
|
||||
public: // methods
|
||||
/// Mapping import flags (\ref loadFromFile, \ref loadFromDOM)
|
||||
enum MapConfigFlags
|
||||
{
|
||||
// replace the existing configuration
|
||||
mc_load_mapping = 0x1 << 0,
|
||||
|
||||
// merge any new configuration into the current one
|
||||
// (error on conflicting configuration)
|
||||
mc_merge_mapping = 0x1 << 1
|
||||
};
|
||||
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapConfiguration();
|
||||
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] ddl The DDL information base used for type lookup
|
||||
*/
|
||||
MapConfiguration(const ddl::DDLDescription* ddl);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~MapConfiguration();
|
||||
|
||||
/**
|
||||
* C-CTOR
|
||||
*/
|
||||
MapConfiguration(const MapConfiguration& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
MapConfiguration& operator=(const MapConfiguration& other);
|
||||
|
||||
/**
|
||||
* Set the reference ddl description
|
||||
*
|
||||
* @param [in] ddl The DDL information base used for type lookup
|
||||
* @note This call implies an internal Reset call, the configuration is reset
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDescription(const ddl::DDLDescription* ddl);
|
||||
|
||||
/**
|
||||
* Set the reference ddl description without consistency check
|
||||
*
|
||||
* @param [in] ddl The DDL information base used for type lookup
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDescriptionWithoutConsistency(const ddl::DDLDescription* ddl);
|
||||
|
||||
/**
|
||||
* Modify the reference ddl description
|
||||
* Set the new ddl description and check mapping consistency
|
||||
*
|
||||
* @param [in] ddl The DDL information base used for type lookup
|
||||
* @note This call does not imply a internal Reset call
|
||||
* @retval ERR_INVALID_TYPE Configuration is inconsistent with ddl, mapping validity updated
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result modifyDescription(const ddl::DDLDescription* ddl);
|
||||
|
||||
/**
|
||||
* Get the reference ddl description
|
||||
*/
|
||||
const ddl::DDLDescription* getDescription() const;
|
||||
|
||||
/**
|
||||
* Resets the entire map configuration to its initial, empty state
|
||||
* \note The ddl description remains untouched by this
|
||||
* @returns Nothing but doxygen won't shut up if I dont write anything here
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a file
|
||||
* Load file in DOM and call loadFromDOM()
|
||||
*
|
||||
* @param [in] file_path The file path to the configuration file
|
||||
* @param [in] flags Options for loading. See \ref MapConfigFlags
|
||||
*
|
||||
* @retval ERR_INVALID_FILE DOM Import from file failed
|
||||
* (see error list for details)
|
||||
* @retval see loadFromDOM()
|
||||
*/
|
||||
a_util::result::Result loadFromFile(const std::string& file_path,
|
||||
uint32_t flags = mc_load_mapping);
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a XML dom instance
|
||||
*
|
||||
* @param [in] dom The dom instance from which to import
|
||||
* @param [in] flags Options for loading. See \ref MapConfigFlags
|
||||
*
|
||||
* @retval ERR_INVALID_FLAGS Invalid flag combination
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_FAILED Configuration file is invalid
|
||||
* (see error list for details)
|
||||
* @retval ERR_INVALID_TYPE Configuration uses unknown DDL types
|
||||
* (see error list for details)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOM(a_util::xml::DOM& dom,
|
||||
uint32_t flags = mc_load_mapping);
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a XML dom instance without checking for DDL consistency
|
||||
*
|
||||
* @param [in] dom The dom instance from which to import
|
||||
* @param [in] flags Options for loading. See \ref MapConfigFlags
|
||||
*
|
||||
* @retval ERR_INVALID_FLAGS Invalid flag combination
|
||||
* @retval ERR_FAILED Configuration file is invalid
|
||||
* (see error list for details)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOMWithoutDDLConsistency(a_util::xml::DOM& dom,
|
||||
uint32_t flags = mc_load_mapping);
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a file
|
||||
* Load file in DOM and call loadPartiallyFromDOM()
|
||||
* Modell is loaded even if it is not consistent with the DDL description
|
||||
* Each element has a validity flag representing its consistency
|
||||
*
|
||||
* @param [in] file_path The file path to the configuration file
|
||||
* @param [in] flags Options for loading. See \ref MapConfigFlags
|
||||
*
|
||||
* @retval ERR_INVALID_FILE DOM Import from file failed
|
||||
* (see error list for details)
|
||||
* @retval see loadPartiallyFromDOM()
|
||||
*/
|
||||
a_util::result::Result loadPartiallyFromFile(const std::string& file_path,
|
||||
uint32_t flags = mc_load_mapping);
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a XML dom instance
|
||||
* Modell is laoding even if it is not consistent with the DDL description
|
||||
* Each element has a validity flag representing its consistency
|
||||
*
|
||||
* @param [in] dom The dom instance from which to import
|
||||
* @param [in] flags Options for loading. See \ref MapConfigFlags
|
||||
*
|
||||
* @retval ERR_INVALID_FLAGS Invalid flag combination
|
||||
* @retval ERR_FAILED Configuration file is invalid
|
||||
* (see error list for details)
|
||||
* @retval ERR_INVALID_TYPE Configuration uses unknown DDL types
|
||||
* (see error list for details)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadPartiallyFromDOM(a_util::xml::DOM& dom,
|
||||
uint32_t flags = mc_load_mapping);
|
||||
|
||||
/**
|
||||
* Export mapping configuration to a file
|
||||
* Call writeToDOM() and wirte DOM to file
|
||||
*
|
||||
* @param [in] file_path The file path to the configuration file
|
||||
* @retval ERR_INVALID_FILE Can not write in file
|
||||
* (see error list for details)
|
||||
* @retval see writeToDOM()
|
||||
*/
|
||||
a_util::result::Result writeToFile(const std::string& file_path);
|
||||
|
||||
/**
|
||||
* Export mapping configuration to a XML dom instance
|
||||
*
|
||||
* @param [in] dom The dom instance from which to import
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_FAILED Configuration is invalid
|
||||
* (see error list for details)
|
||||
* @retval ERR_INVALID_TYPE Configuration uses unknown DDL types
|
||||
* (see error list for details)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOM& dom);
|
||||
|
||||
/**
|
||||
* Returns the mapping header of the configuration
|
||||
*/
|
||||
const MapHeader& getHeader() const;
|
||||
|
||||
/**
|
||||
* Set the description in configuration header
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setHeaderDescription(const std::string& desc);
|
||||
|
||||
/**
|
||||
* Set the ddl paths attribute in configuration header
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setHeaderDdlPaths(const std::string& ddl_path);
|
||||
|
||||
/**
|
||||
* Get the ddl paths attribute from configuration header
|
||||
*/
|
||||
const std::string& getHeaderDdlPaths() const;
|
||||
|
||||
/**
|
||||
* Returns all transformations contained in the configuration
|
||||
*/
|
||||
const MapTransformationList& getTransformationList() const;
|
||||
|
||||
/**
|
||||
* Returns a specific transformation from the configuration
|
||||
*
|
||||
* @param [in] transformation_name The name of the transformation
|
||||
*
|
||||
* @retval The requested transformation base instance pointer
|
||||
* @retval NULL if no transformation instance was found with that name
|
||||
*/
|
||||
const MapTransformationBase* getTransformation(
|
||||
const std::string& transformation_name) const;
|
||||
|
||||
/**
|
||||
* Returns a specific transformation from the configuration
|
||||
*
|
||||
* @param [in] transformation_name The name of the transformation
|
||||
*
|
||||
* @retval The requested transformation base instance pointer
|
||||
* @retval NULL if no transformation instance was found with that name
|
||||
*/
|
||||
MapTransformationBase* getTransformation(
|
||||
const std::string& transformation_name);
|
||||
|
||||
/**
|
||||
* Add a transformation to use in mapping
|
||||
* @param [in] transformation_name The transformation name
|
||||
* @param [in] transformation_type The transformation type
|
||||
* can be "Periodic", "Signal" or "Data"
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTransformation(const std::string& transformation_name, const std::string& transformation_type);
|
||||
|
||||
/**
|
||||
* Remove a transformation
|
||||
* @param [in] transformation_name The transformation name
|
||||
* @retval ERR_NOT_FOUND Transformation not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeTransformation(const std::string& transformation_name);
|
||||
|
||||
/**
|
||||
* Returns a specific mapping source from the configuration
|
||||
*
|
||||
* @param [in] source_name The name of the source
|
||||
*
|
||||
* @retval The requested source instance pointer
|
||||
* @retval NULL if no source instance was found with that name
|
||||
*/
|
||||
const MapSource* getSource(const std::string& source_name) const;
|
||||
|
||||
/**
|
||||
* Returns a specific mapping source from the configuration
|
||||
*
|
||||
* @param [in] source_name The name of the source
|
||||
*
|
||||
* @retval The requested source instance pointer
|
||||
* @retval NULL if no source instance was found with that name
|
||||
*/
|
||||
MapSource* getSource(const std::string& source_name);
|
||||
|
||||
/**
|
||||
* Returns all mapping sources contained in the configuration
|
||||
*/
|
||||
const MapSourceList& getSourceList() const;
|
||||
|
||||
/**
|
||||
* Add a source signal to use in mapping
|
||||
* @param [in] name The name of the source
|
||||
* @param [in] type The type of the source
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addSource(const std::string& name, const std::string& type);
|
||||
|
||||
/**
|
||||
* Remove a source signal from the configuration
|
||||
* All connections using this source will be deleted
|
||||
* @param [in] name The name of the target
|
||||
* @retval ERR_NOT_FOUND Source not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeSource(const std::string& name);
|
||||
|
||||
/**
|
||||
* Returns a specific mapping target from the configuration
|
||||
*
|
||||
* @param [in] target_name The name of the target
|
||||
*
|
||||
* @retval The requested target instance pointer
|
||||
* @retval NULL if no target instance was found with that name
|
||||
*/
|
||||
const MapTarget* getTarget(const std::string& target_name) const;
|
||||
|
||||
/**
|
||||
* Returns a specific mapping target from the configuration
|
||||
*
|
||||
* @param [in] target_name The name of the target
|
||||
*
|
||||
* @retval The requested target instance pointer
|
||||
* @retval NULL if no target instance was found with that name
|
||||
*/
|
||||
MapTarget* getTarget(const std::string& target_name);
|
||||
|
||||
/**
|
||||
* Add a target signal to use in mapping
|
||||
* @param [in] name The name of the target
|
||||
* @param [in] type The type of the target
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTarget(const std::string& name, const std::string& type);
|
||||
|
||||
/**
|
||||
* Remove a target signal from the configuration
|
||||
* All connections using this source will be deleted
|
||||
* @param [in] name The name of the target
|
||||
* @retval ERR_NOT_FOUND Target not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeTarget(const std::string& name);
|
||||
|
||||
/**
|
||||
* Returns all mapping targets contained in the configuration
|
||||
*/
|
||||
const MapTargetList& getTargetList() const;
|
||||
|
||||
/**
|
||||
* Returns the error list, containing human readable error messages.
|
||||
* @note The error list is filled by \ref loadFromFile and \ref loadFromDOM
|
||||
* and is reset on every call
|
||||
* @returns Const reference to the error list
|
||||
*/
|
||||
const MapErrorList& getErrorList() const;
|
||||
|
||||
/**
|
||||
* Clear error list and verify DDL Description exists
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result resetErrors();
|
||||
|
||||
/**
|
||||
* Append error to error list
|
||||
**/
|
||||
void appendError(const std::string& error_string) const;
|
||||
|
||||
/**
|
||||
* Returns bool flag indicating whether consistency of mapping with its DDL was already checked
|
||||
* @return Bool flag indicating whether consistency was checked
|
||||
*/
|
||||
bool isConsistencyChecked();
|
||||
|
||||
/**
|
||||
* Returns bool flag indicating consistency of mapping with its DDL
|
||||
* @return Bool flag indicating consistency
|
||||
*/
|
||||
bool isConsistent();
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency with ddl representation
|
||||
* (all types, transformations etc. are known and present & many other problems)
|
||||
* @retval ERR_INVALID_TYPE Configuration is inconsistent with ddl,
|
||||
* error list is populated and validity flags are set
|
||||
* @retval a_util::result::SUCCESS Everything went fine, configuration is consistent
|
||||
*/
|
||||
a_util::result::Result checkDDLConsistency();
|
||||
|
||||
private:
|
||||
/**
|
||||
* swap implementation for use in the assignment op
|
||||
*/
|
||||
void swap(MapConfiguration& other);
|
||||
|
||||
/**
|
||||
* Set reference to new configuration
|
||||
* @param [in] config The configuration to reference
|
||||
*/
|
||||
void repairConfigReferences(MapConfiguration& config);
|
||||
|
||||
/**
|
||||
* Import mapping configuration from a XML dom instance
|
||||
*
|
||||
* @param [in] dom The dom instance from which to import
|
||||
* @param [out] tmp_config The temporary configuration to create
|
||||
* @retval ERR_INVALID_ARG DOM does not contains a valid mapping
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
static a_util::result::Result loadMappingFromDOM(a_util::xml::DOM& dom, MapConfiguration& tmp_config);
|
||||
|
||||
/**
|
||||
* Add a target signal to configuration
|
||||
* @param [in] target The target signal
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTarget(const MapTarget& target);
|
||||
|
||||
/**
|
||||
* Add a source signal to configuration
|
||||
* @param [in] source The source signal
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addSource(const MapSource& source);
|
||||
|
||||
/**
|
||||
* Checks the mapping for consistency
|
||||
* All referenced Sources and Transformations must exist in Mapping
|
||||
* @retval ERR_INVALID_ARG Unknown source or transformation is used
|
||||
* @retval a_util::result::SUCCESS Everything went fine, configuration is consistent
|
||||
*/
|
||||
a_util::result::Result checkMappingConsistency();
|
||||
|
||||
/**
|
||||
* merge another configuration into this one
|
||||
* @param [in] other The other instance to be merged
|
||||
* @retval ERR_INVALID_ARG Type conflict
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result merge(const MapConfiguration& other);
|
||||
|
||||
/**
|
||||
* find a DDL data type within a struct given a path to the element
|
||||
*
|
||||
* @param [in] struct_name Name of the struct type
|
||||
* @param [in] path Path to be found
|
||||
* @param [out] type Destination type parameter
|
||||
* @param [out] array_size Destination array size parameter
|
||||
* @retval ERR_NOT_FOUND The path is invalid or the type was not found
|
||||
* @retval ERR_INVALID_TYPE Uses dynamic type
|
||||
* @retval a_util::result::SUCCESS The type was found, type and array_size are filled
|
||||
*/
|
||||
a_util::result::Result findTypeObject(const std::string& struct_name, const std::string&
|
||||
path, const ddl::IDDLDataType*& type, int& array_size) const;
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
a_util::result::Result findTypeObject(const ddl::DDLComplex& struct_name, const std::string&
|
||||
path, const ddl::IDDLDataType*& type, int& array_size) const;
|
||||
|
||||
/**
|
||||
* Checks whether the target datatype is compatible with the source datatype
|
||||
* @param [in] source Datatype 1
|
||||
* @param [in] source_array_size Arraysize 1
|
||||
* @param [in] target Datatype 2
|
||||
* @param [in] target_array_size Arraysize 2
|
||||
* @retval true or false
|
||||
*/
|
||||
bool checkTypeCompatibility(const ddl::IDDLDataType& source, int source_array_size,
|
||||
const ddl::IDDLDataType& target, int target_array_size) const;
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new signal
|
||||
* @param [in] name The signal name
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkSignalName(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new signal
|
||||
* @param [in] type The type of the signal
|
||||
* @retval ERR_INVALID_TYPE Type not found in DDL
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkSignalType(const std::string& type) const;
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new assignment
|
||||
* @param [in] assignment The assignment to check
|
||||
* @retval ERR_INVALID_ARG Reference not found in Configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkAssignmentReferences(const MapAssignment& assignment) const;
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new assignment
|
||||
* @param [in] signal_name The name of the target signal (for error list)
|
||||
* @param [in] signal_struct The ddl structure for the signal
|
||||
* @param [in] assignment The assignment to check
|
||||
* @retval ERR_INVALID_TYPE Definition is inconsistent with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkAssignmentType(const std::string& signal_name,
|
||||
const ddl::DDLComplex& signal_struct, const MapAssignment& assignment) const;
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new trigger
|
||||
* @param [in] trigger The trigger to check
|
||||
* @retval ERR_INVALID_TYPE Definition is inconsistent with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkTriggerType(const MapTriggerBase* trigger) const;
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapSource;
|
||||
friend class MapTarget;
|
||||
friend class MapTriggerBase;
|
||||
friend class MapDataTrigger;
|
||||
MapHeader _header;
|
||||
MapSourceList _sources;
|
||||
MapTargetList _targets;
|
||||
MapTransformationList _transforms;
|
||||
// mutable because its not part of the object state
|
||||
mutable MapErrorList _errors;
|
||||
const ddl::DDLDescription* _ddl_ref;
|
||||
bool _checked_for_consistency;
|
||||
bool _is_consistent;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_CONFIGURATION_H
|
159
mapping/configuration/map_header.cpp
Normal file
159
mapping/configuration/map_header.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_header.h"
|
||||
|
||||
#include "map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapHeader::MapHeader()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getDescription() const
|
||||
{
|
||||
return _desc;
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getDllPaths() const
|
||||
{
|
||||
return _ddl;
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getLanguageVersion() const
|
||||
{
|
||||
return _lang_version;
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getAuthor() const
|
||||
{
|
||||
return _author;
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getCreationDate() const
|
||||
{
|
||||
return _creation_date;
|
||||
}
|
||||
|
||||
const std::string& MapHeader::getModificationDate() const
|
||||
{
|
||||
return _mod_date;
|
||||
}
|
||||
|
||||
void MapHeader::reset()
|
||||
{
|
||||
_desc = "Auto-generated with Signal Mapping Editor";
|
||||
_ddl.clear();
|
||||
_lang_version = "1.00";
|
||||
_author = a_util::system::getCurrentUserName();
|
||||
_creation_date = a_util::datetime::getCurrentLocalDateTime().format("%c");
|
||||
_mod_date = _creation_date;
|
||||
}
|
||||
|
||||
a_util::result::Result MapHeader::setDescription(const std::string& strDescription)
|
||||
{
|
||||
_desc = strDescription;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapHeader::setDdlPaths(const std::string& strDdlPaths)
|
||||
{
|
||||
_ddl = strDdlPaths;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapHeader::loadFromDOM(const a_util::xml::DOMElement& oHeader, MapErrorList& lstErrors)
|
||||
{
|
||||
const a_util::xml::DOMElement oLang = oHeader.getChild("language_version");
|
||||
const a_util::xml::DOMElement oAuthor = oHeader.getChild("author");
|
||||
const a_util::xml::DOMElement oCreated = oHeader.getChild("date_creation");
|
||||
const a_util::xml::DOMElement oModified = oHeader.getChild("date_change");
|
||||
const a_util::xml::DOMElement oDescription = oHeader.getChild("description");
|
||||
|
||||
if (oLang.isNull() || oAuthor.isNull() || oCreated.isNull() ||
|
||||
oModified.isNull() || oDescription.isNull())
|
||||
{
|
||||
lstErrors.push_back("Missing <language_version>, <author>, <date_creation>, "
|
||||
"<date_change> or <description> element in header");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(!a_util::strings::isDouble(oLang.getData()) || a_util::strings::toDouble(oLang.getData()) > 1)
|
||||
{
|
||||
lstErrors.push_back("<language_version> is not 1.00. No other language version exists.");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
_lang_version = oLang.getData();
|
||||
_author = oAuthor.getData();
|
||||
_creation_date = oCreated.getData();
|
||||
_mod_date = oModified.getData();
|
||||
setDescription(oDescription.getData());
|
||||
|
||||
// optional
|
||||
const a_util::xml::DOMElement oDdlPaths = oHeader.getChild("ddl");
|
||||
if (!oDdlPaths.isNull())
|
||||
{
|
||||
setDdlPaths(oDdlPaths.getData());
|
||||
}
|
||||
else
|
||||
{
|
||||
_ddl.clear();
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapHeader::writeToDOM(a_util::xml::DOMElement oDOMElement)
|
||||
{
|
||||
oDOMElement.setName("header");
|
||||
|
||||
_mod_date = a_util::datetime::getCurrentLocalDateTime().format("%c");
|
||||
|
||||
a_util::xml::DOMElement oLang = oDOMElement.createChild("language_version");
|
||||
a_util::xml::DOMElement oAuthor = oDOMElement.createChild("author");
|
||||
a_util::xml::DOMElement oCreated = oDOMElement.createChild("date_creation");
|
||||
a_util::xml::DOMElement oModified = oDOMElement.createChild("date_change");
|
||||
a_util::xml::DOMElement oDescription = oDOMElement.createChild("description");
|
||||
|
||||
oLang.setData(_lang_version);
|
||||
oAuthor.setData(_author);
|
||||
oCreated.setData(_creation_date);
|
||||
oDescription.setData(_desc);
|
||||
oModified.setData(_mod_date);
|
||||
|
||||
if(!_ddl.empty())
|
||||
{
|
||||
a_util::xml::DOMElement oDdlPaths = oDOMElement.createChild("ddl");
|
||||
oDdlPaths.setData(_ddl);
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
127
mapping/configuration/map_header.h
Normal file
127
mapping/configuration/map_header.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_HEADER_H
|
||||
#define HEADER_MAP_HEADER_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
|
||||
typedef std::vector<std::string> MapErrorList;
|
||||
|
||||
/**
|
||||
* MapHeader contains all information from the header-Tag of a mapping configuration
|
||||
*/
|
||||
class MapHeader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapHeader();
|
||||
|
||||
/**
|
||||
* Returns the description from the <description> header tag or an empty string
|
||||
*/
|
||||
const std::string& getDescription() const;
|
||||
|
||||
/**
|
||||
* Returns the list of dll paths from the <ddl> header tag or an empty string
|
||||
*/
|
||||
const std::string& getDllPaths() const;
|
||||
|
||||
/**
|
||||
* Returns the version from the language_version-header tag or an empty string
|
||||
*/
|
||||
const std::string& getLanguageVersion() const;
|
||||
|
||||
/**
|
||||
* Returns the author from the author-header tag or an empty string
|
||||
*/
|
||||
const std::string& getAuthor() const;
|
||||
|
||||
/**
|
||||
* Returns the date from the date_creation-header tag or an empty string
|
||||
*/
|
||||
const std::string& getCreationDate() const;
|
||||
|
||||
/**
|
||||
* Returns the date from the date_change-header tag or an empty string
|
||||
*/
|
||||
const std::string& getModificationDate() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Resets the instance to its initial state
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Initializes the header from a header-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] errors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Field missing
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOM(const a_util::xml::DOMElement& header, MapErrorList& errors);
|
||||
|
||||
/**
|
||||
* Export header to a XML dom element
|
||||
*
|
||||
* @param [out] dom_element The dom element to be written
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement dom_element);
|
||||
|
||||
/**
|
||||
* Set description
|
||||
* @param [in] description The description
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDescription(const std::string& description);
|
||||
|
||||
/**
|
||||
* Set ddl paths
|
||||
* @param [in] ddl_paths The string containing ddl paths
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDdlPaths(const std::string& ddl_paths);
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
std::string _lang_version;
|
||||
std::string _author;
|
||||
std::string _desc;
|
||||
std::string _ddl;
|
||||
std::string _creation_date;
|
||||
std::string _mod_date;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_HEADER_H
|
133
mapping/configuration/map_source.cpp
Normal file
133
mapping/configuration/map_source.cpp
Normal file
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_source.h"
|
||||
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-40, ERR_INVALID_STATE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapSource::MapSource(MapConfiguration* pConfig) : _is_valid(true), _config(pConfig)
|
||||
{
|
||||
}
|
||||
|
||||
MapSource::MapSource(MapConfiguration* pConfig, std::string name, std::string strType) : _config(pConfig), _is_valid(true)
|
||||
{
|
||||
_name = name;
|
||||
a_util::strings::trim(_name);
|
||||
_type = strType;
|
||||
a_util::strings::trim(_type);
|
||||
}
|
||||
|
||||
const std::string& MapSource::getName() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
const std::string& MapSource::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
bool MapSource::isValid() const
|
||||
{
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
a_util::result::Result MapSource::loadFromDOM(const a_util::xml::DOMElement& oSource)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oSource.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator itName = mapAttrs.find("name");
|
||||
if (itName == mapAttrs.end() || itName->second.empty())
|
||||
{
|
||||
_config->appendError("Missing or empty name attribute for a <source>");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_name = itName->second;
|
||||
a_util::strings::trim(_name);
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itType = mapAttrs.find("type");
|
||||
if (itType == mapAttrs.end() || itType->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing or empty type attribute for \
|
||||
<source> '%s'", itName->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_type = itType->second;
|
||||
a_util::strings::trim(_type);
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapSource::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("source");
|
||||
oDOMElement.setAttribute("name", _name);
|
||||
oDOMElement.setAttribute("type", _type);
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
a_util::result::Result MapSource::setName(const std::string& strNewName)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
RETURN_IF_FAILED(_config->checkSignalName(strNewName));
|
||||
|
||||
// modify references in Targets
|
||||
for(MapTargetList::iterator itTrg = _config->_targets.begin(); itTrg != _config->_targets.end(); itTrg++)
|
||||
{
|
||||
if(itTrg->_sources.find(_name) != itTrg->_sources.end())
|
||||
{
|
||||
itTrg->modifySourceName(_name, strNewName);
|
||||
}
|
||||
}
|
||||
|
||||
_name = strNewName;
|
||||
|
||||
return _config->checkMappingConsistency();
|
||||
}
|
||||
|
||||
a_util::result::Result MapSource::setType(const std::string& strType)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
RETURN_IF_FAILED(_config->checkSignalType(strType));
|
||||
_type = strType;
|
||||
return _config->checkDDLConsistency();
|
||||
}
|
132
mapping/configuration/map_source.h
Normal file
132
mapping/configuration/map_source.h
Normal file
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_SOURCE_H
|
||||
#define HEADER_MAP_SOURCE_H
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
class MapConfiguration;
|
||||
|
||||
/**
|
||||
* MapSource represents a mapping source from the configuration file
|
||||
*/
|
||||
class MapSource
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapSource(MapConfiguration* config);
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] name signal name
|
||||
* @param [in] type signal type
|
||||
*/
|
||||
MapSource(MapConfiguration* config, std::string name, std::string type);
|
||||
|
||||
/**
|
||||
* Returns the name of the mapping source
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param [in] new_name The new name of the target
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setName(const std::string& new_name);
|
||||
|
||||
/**
|
||||
* Returns the DDL typename of the mapping source
|
||||
*/
|
||||
const std::string& getType() const;
|
||||
|
||||
/**
|
||||
* Set type
|
||||
* @param [in] _type The type of the target
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setType(const std::string& type);
|
||||
|
||||
/**
|
||||
* Returns the validity for the current description
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the source from a source-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing name or type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOM(const a_util::xml::DOMElement& source);
|
||||
|
||||
/**
|
||||
* Export source to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element to be written
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapTarget;
|
||||
MapConfiguration* _config;
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
inline bool operator==(const MapSource& a, const MapSource& b)
|
||||
{
|
||||
return a.getName() == b.getName() && a.getType() == b.getType();
|
||||
}
|
||||
|
||||
inline bool operator!=(const MapSource& a, const MapSource& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
/// Public composite types used in the mapping::oo namespace
|
||||
typedef std::vector<MapSource> MapSourceList;
|
||||
typedef std::set<std::string> MapSourceNameList;
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_SOURCE_H
|
616
mapping/configuration/map_target.cpp
Normal file
616
mapping/configuration/map_target.cpp
Normal file
|
@ -0,0 +1,616 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_target.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-19, ERR_NOT_SUPPORTED)
|
||||
_MAKE_RESULT(-20, ERR_NOT_FOUND)
|
||||
_MAKE_RESULT(-40, ERR_INVALID_STATE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapTarget::MapTarget(MapConfiguration* pConfig) : _config(pConfig), _is_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
MapTarget::MapTarget(MapConfiguration* pConfig, std::string name, std::string strType) :
|
||||
_config(pConfig), _is_valid(true)
|
||||
{
|
||||
_name = name;
|
||||
_type = strType;
|
||||
}
|
||||
|
||||
MapTarget::MapTarget(const MapTarget& oOther)
|
||||
{
|
||||
_name = oOther._name;
|
||||
_type = oOther._type;
|
||||
_assignments = oOther._assignments;
|
||||
_sources = oOther._sources;
|
||||
_is_valid = oOther._is_valid;
|
||||
_config = oOther._config;
|
||||
for (MapTriggerList::const_iterator it = oOther._triggers.begin();
|
||||
it != oOther._triggers.end(); ++it)
|
||||
{
|
||||
_triggers.push_back((*it)->clone());
|
||||
}
|
||||
}
|
||||
|
||||
MapTarget& MapTarget::operator=(const MapTarget& oOther)
|
||||
{
|
||||
MapTarget oCopy(oOther);
|
||||
oCopy.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
MapTarget::~MapTarget()
|
||||
{
|
||||
for (MapTriggerList::iterator it = _triggers.begin();
|
||||
it != _triggers.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
_triggers.clear();
|
||||
}
|
||||
|
||||
const std::string& MapTarget::getName() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
const std::string& MapTarget::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
bool MapTarget::isValid() const
|
||||
{
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
const MapAssignmentList& MapTarget::getAssignmentList() const
|
||||
{
|
||||
return _assignments;
|
||||
}
|
||||
|
||||
|
||||
a_util::result::Result MapTarget::addAssignment(const MapAssignment& oAssignment)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
|
||||
if(!_is_valid)
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Target Signal %s is not valid, cannot add any assignment", _name.c_str()));
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
RETURN_IF_FAILED(_config->checkAssignmentReferences(oAssignment));
|
||||
RETURN_IF_FAILED(addAssignmentNoTypeCheck(oAssignment));
|
||||
|
||||
// Check new assignment with ddl
|
||||
const ddl::DDLComplex* pTargetStruct = _config->_ddl_ref->getStructByName(_type);
|
||||
// Target is valid, so the type is defined and can be dereferenced
|
||||
a_util::result::Result nRes = _config->checkAssignmentType(_name, *pTargetStruct, oAssignment);
|
||||
if(isOk(nRes))
|
||||
{
|
||||
nRes = checkDoubleAssignments();
|
||||
}
|
||||
// If assignment not consistent with DDL, remove assignment
|
||||
if(isFailed(nRes))
|
||||
{
|
||||
removeAssignmentWithoutClear(oAssignment.getTo());
|
||||
}
|
||||
|
||||
return nRes;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::removeAssignment(const std::string& strElementName)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
_config->_errors.clear();
|
||||
return removeAssignmentWithoutClear(strElementName);
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::addTrigger(MapTriggerBase* pTrigger)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
|
||||
if(!_is_valid)
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Target Signal %s is not valid, cannot add any assignment", _name.c_str()));
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if(pTrigger->_config != _config)
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Trigger refers to another configuration"));
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
RETURN_IF_FAILED(pTrigger->checkTriggerReferences());
|
||||
RETURN_IF_FAILED(_config->checkTriggerType(pTrigger));
|
||||
return addTriggerNoTypeCheck(pTrigger);
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::removeTrigger(MapTriggerBase* pTrigger)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
_config->_errors.clear();
|
||||
bool bIsRemoved = false;
|
||||
std::string strSource;
|
||||
for(MapTriggerList::iterator it = _triggers.begin(); it != _triggers.end(); it++)
|
||||
{
|
||||
if((*it)->isEqual(*pTrigger))
|
||||
{
|
||||
strSource = (*it)->getSourceDependency();
|
||||
_triggers.erase(it);
|
||||
bIsRemoved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!strSource.empty())
|
||||
{
|
||||
bool bIsSourceUsed = false;
|
||||
|
||||
for(MapAssignmentList::const_iterator it = _assignments.begin(); it != _assignments.end(); it++)
|
||||
{
|
||||
if(it->getSource() == strSource)
|
||||
{
|
||||
bIsSourceUsed = true;
|
||||
}
|
||||
}
|
||||
for(MapTriggerList::const_iterator it = _triggers.begin(); it != _triggers.end(); it++)
|
||||
{
|
||||
if((*it)->getSourceDependency() == strSource)
|
||||
{
|
||||
bIsSourceUsed = true;
|
||||
}
|
||||
}
|
||||
if(!bIsSourceUsed)
|
||||
{
|
||||
for (MapSourceNameList::iterator itSource = _sources.begin();
|
||||
itSource != _sources.end(); ++itSource)
|
||||
{
|
||||
if (*itSource == strSource)
|
||||
{
|
||||
_sources.erase(itSource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bIsRemoved)
|
||||
{
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::removeAssignmentWithoutClear(const std::string& strElementName)
|
||||
{
|
||||
bool bIsRemoved = false;
|
||||
std::string strSource;
|
||||
for(MapAssignmentList::iterator it = _assignments.begin(); it != _assignments.end(); it++)
|
||||
{
|
||||
if(it->getTo() == strElementName)
|
||||
{
|
||||
strSource = it->getSource();
|
||||
_assignments.erase(it);
|
||||
bIsRemoved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!strSource.empty())
|
||||
{
|
||||
bool isSourceUsed = false;
|
||||
|
||||
for(MapAssignmentList::const_iterator it = _assignments.begin(); it != _assignments.end(); it++)
|
||||
{
|
||||
if(it->getSource() == strSource)
|
||||
{
|
||||
isSourceUsed = true;
|
||||
}
|
||||
}
|
||||
for(MapTriggerList::const_iterator it = _triggers.begin(); it != _triggers.end(); it++)
|
||||
{
|
||||
if((*it)->getSourceDependency() == strSource)
|
||||
{
|
||||
isSourceUsed = true;
|
||||
}
|
||||
}
|
||||
if(!isSourceUsed)
|
||||
{
|
||||
for (MapSourceNameList::iterator itSource = _sources.begin();
|
||||
itSource != _sources.end(); ++itSource)
|
||||
{
|
||||
if (*itSource == strSource)
|
||||
{
|
||||
_sources.erase(itSource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bIsRemoved)
|
||||
{
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::addAssignmentNoTypeCheck(const MapAssignment& oAssignment)
|
||||
{
|
||||
// Assignment is attributed to an element
|
||||
const std::string& strTo = oAssignment.getTo();
|
||||
if(strTo.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Target element name is empty in <target> '%s'",
|
||||
_name.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
for(MapAssignmentList::iterator itAssign = _assignments.begin(); itAssign != _assignments.end(); itAssign++)
|
||||
{
|
||||
// Is To already assigned
|
||||
if (itAssign->getTo() == strTo)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Target element '%s' is already assigned in <target> '%s'",
|
||||
strTo.c_str(), getName().c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
// Assignment is a constant, a connection or a function
|
||||
if (oAssignment.getSource().empty() && oAssignment.getConstant().empty() && oAssignment.getFunction().empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <from>, <constant> or <function> attribute for <assignment> to '%s' in <target> '%s'",
|
||||
strTo.c_str(), _name.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// The constant is numeric
|
||||
if (!oAssignment.getConstant().empty() &&
|
||||
!a_util::strings::isDouble(oAssignment.getConstant()))
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Empty or non-numeric constant for <assignment> to '%s' in <target> '%s'",
|
||||
strTo.c_str(), _name.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// The trigger_counter function modulo is numeric
|
||||
if (!oAssignment.getModulo().empty())
|
||||
{
|
||||
if (!a_util::strings::isInt64(oAssignment.getModulo()) ||
|
||||
oAssignment.getModulo().find('-') != std::string::npos ||
|
||||
oAssignment.getModulo().find('+') != std::string::npos ||
|
||||
a_util::strings::toUInt64(oAssignment.getModulo()) == 0)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Non-integer or zero modulo in transmission_counter for <assignment> to '%s' in <target> '%s'",
|
||||
strTo.c_str(), _name.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
_assignments.push_back(oAssignment);
|
||||
if (!oAssignment.getSource().empty())
|
||||
{
|
||||
for (MapSourceList::const_iterator itSource = _config->getSourceList().begin();
|
||||
itSource != _config->getSourceList().end(); ++itSource)
|
||||
{
|
||||
if (itSource->getName() == oAssignment.getSource())
|
||||
{
|
||||
_sources.insert(itSource->getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::addTriggerNoTypeCheck(MapTriggerBase* pTrigger)
|
||||
{
|
||||
_triggers.push_back(pTrigger);
|
||||
|
||||
// append dependency to references sources
|
||||
std::string strSourceDep = pTrigger->getSourceDependency();
|
||||
if (!strSourceDep.empty())
|
||||
{
|
||||
for (MapSourceList::const_iterator itSource = _config->getSourceList().begin();
|
||||
itSource != _config->getSourceList().end(); ++itSource)
|
||||
{
|
||||
if (itSource->getName() == strSourceDep)
|
||||
{
|
||||
_sources.insert(itSource->getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::modifySourceName(const std::string& name, const std::string& strNewName)
|
||||
{
|
||||
_sources.erase(name);
|
||||
_sources.insert(strNewName);
|
||||
for(MapAssignmentList::iterator itAssign = _assignments.begin();
|
||||
itAssign != _assignments.end(); itAssign++)
|
||||
{
|
||||
if(itAssign->_source == name)
|
||||
{
|
||||
itAssign->_source = strNewName;
|
||||
}
|
||||
}
|
||||
for(MapTriggerList::iterator itTrigger = _triggers.begin();
|
||||
itTrigger != _triggers.end(); itTrigger++)
|
||||
{
|
||||
if((*itTrigger)->getSourceDependency() == name)
|
||||
{
|
||||
(*itTrigger)->setSourceDependency(strNewName);
|
||||
}
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const MapTriggerList& MapTarget::getTriggerList() const
|
||||
{
|
||||
return _triggers;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::loadFromDOM(const a_util::xml::DOMElement& oTarget)
|
||||
{
|
||||
_sources.clear();
|
||||
_assignments.clear();
|
||||
_triggers.clear();
|
||||
|
||||
// parse attributes
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTarget.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator itName = mapAttrs.find("name");
|
||||
if (itName == mapAttrs.end() || itName->second.empty())
|
||||
{
|
||||
_config->appendError("Missing name attribute for a <target>");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_name = itName->second;
|
||||
a_util::strings::trim(_name);
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itType = mapAttrs.find("type");
|
||||
if (itType == mapAttrs.end() || itType->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing type attribute for <target> '%s'",
|
||||
itName->second.c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_type = itType->second;
|
||||
a_util::strings::trim(_type);
|
||||
|
||||
// parse assignments and triggers
|
||||
const a_util::xml::DOMElementList lstElements = oTarget.getChildren();
|
||||
a_util::result::Result nResult = a_util::result::SUCCESS;
|
||||
for (a_util::xml::DOMElementList::const_iterator it = lstElements.begin();
|
||||
it != lstElements.end(); ++it)
|
||||
{
|
||||
const a_util::xml::DOMElement& oElem = *it;
|
||||
const std::string& name = oElem.getName();
|
||||
|
||||
if (name == "assignment")
|
||||
{
|
||||
MapAssignment oAssign;
|
||||
a_util::result::Result nRes = oAssign.loadFromDOM(oElem, _config->_errors);
|
||||
if(isOk(nRes))
|
||||
{
|
||||
nRes = addAssignmentNoTypeCheck(oAssign);
|
||||
}
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
nResult = nRes;
|
||||
}
|
||||
}
|
||||
else if (name == "trigger")
|
||||
{
|
||||
MapTriggerBase* pTrigger = NULL;
|
||||
a_util::result::Result nRes = MapTriggerBase::createFromDOM(_config,
|
||||
oElem, pTrigger);
|
||||
if(isOk(nRes))
|
||||
{
|
||||
nRes = addTriggerNoTypeCheck(pTrigger);
|
||||
}
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
nResult = nRes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Invalid element type in <target> '%s': '%s'",
|
||||
itName->second.c_str(), name.c_str()));
|
||||
nResult = ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
return nResult;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("target");
|
||||
oDOMElement.setAttribute("name", _name);
|
||||
oDOMElement.setAttribute("type", _type);
|
||||
|
||||
for(MapAssignmentList::const_iterator itAssign = _assignments.begin();
|
||||
itAssign != _assignments.end(); itAssign++)
|
||||
{
|
||||
a_util::xml::DOMElement oDOMAssign = oDOMElement.createChild("assignment");
|
||||
itAssign->writeToDOM(oDOMAssign);
|
||||
}
|
||||
|
||||
for(MapTriggerList::const_iterator itTrigger = _triggers.begin();
|
||||
itTrigger != _triggers.end(); itTrigger++)
|
||||
{
|
||||
a_util::xml::DOMElement oDOMTrigger = oDOMElement.createChild("trigger");
|
||||
(*itTrigger)->writeToDOM(oDOMTrigger);
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::checkDoubleAssignments()
|
||||
{
|
||||
a_util::result::Result nRes = a_util::result::SUCCESS;
|
||||
std::set<std::string> oAssignedElList;
|
||||
for(MapAssignmentList::iterator itAssign = _assignments.begin(); itAssign != _assignments.end(); itAssign++)
|
||||
{
|
||||
oAssignedElList.insert(itAssign->getTo());
|
||||
}
|
||||
for(MapAssignmentList::iterator itAssign = _assignments.begin(); itAssign != _assignments.end(); itAssign++)
|
||||
{
|
||||
for(std::set<std::string>::iterator itParent = oAssignedElList.begin(); itParent != oAssignedElList.end(); itParent++)
|
||||
{
|
||||
std::string strEl = itAssign->getTo();
|
||||
if(strEl.find(*itParent) == 0)
|
||||
{
|
||||
size_t pos = 0;
|
||||
while ((pos = strEl.find(*itParent, pos)) != std::string::npos)
|
||||
{
|
||||
strEl.replace(pos, itParent->length(), std::string());
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
if(strEl.find('.') == 0 ||strEl.find('[') == 0)
|
||||
{
|
||||
_config->appendError(a_util::strings::format(
|
||||
"<assignment> to '%s' not possible because of <assignment> to %s in <target> '%s'",
|
||||
strEl.c_str(), itParent->c_str(), getName().c_str()));
|
||||
itAssign->_is_valid = false;
|
||||
nRes = ERR_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
|
||||
void MapTarget::swap(MapTarget& oOther)
|
||||
{
|
||||
using std::swap;
|
||||
swap(_config, oOther._config);
|
||||
swap(_name, oOther._name);
|
||||
swap(_type, oOther._type);
|
||||
swap(_assignments, oOther._assignments);
|
||||
swap(_sources, oOther._sources);
|
||||
swap(_triggers, oOther._triggers);
|
||||
}
|
||||
|
||||
const MapSourceNameList& MapTarget::getReferencedSources() const
|
||||
{
|
||||
return _sources;
|
||||
}
|
||||
|
||||
bool mapping::oo::operator==(const MapTarget& a, const MapTarget& b)
|
||||
{
|
||||
if (a.getName() != b.getName() ||
|
||||
a.getType() != b.getType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const MapAssignmentList& lstAssignA = a.getAssignmentList();
|
||||
const MapAssignmentList& lstAssignB = b.getAssignmentList();
|
||||
|
||||
if (lstAssignA.size() != lstAssignB.size() ||
|
||||
!std::equal(lstAssignA.begin(), lstAssignA.end(), lstAssignB.begin()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const MapTriggerList& lstTriggerA = a.getTriggerList();
|
||||
const MapTriggerList& lstTriggerB = b.getTriggerList();
|
||||
if (lstTriggerA.size() != lstTriggerB.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MapTriggerList::const_iterator itA = lstTriggerA.begin();
|
||||
MapTriggerList::const_iterator itB = lstTriggerB.begin();
|
||||
for (; itA != lstTriggerA.end() && itB != lstTriggerB.end();
|
||||
++itA, ++itB)
|
||||
{
|
||||
if (!(*itA)->isEqual(*(*itB)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
a_util::result::Result MapTarget::setName(const std::string& strNewName)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
RETURN_IF_FAILED(_config->checkSignalName(strNewName));
|
||||
_name = strNewName;
|
||||
|
||||
return _config->checkMappingConsistency();
|
||||
}
|
||||
|
||||
a_util::result::Result MapTarget::setType(const std::string& strType)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
RETURN_IF_FAILED(_config->checkSignalType(strType));
|
||||
_type = strType;
|
||||
return _config->checkDDLConsistency();
|
||||
}
|
248
mapping/configuration/map_target.h
Normal file
248
mapping/configuration/map_target.h
Normal file
|
@ -0,0 +1,248 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_TARGET_H
|
||||
#define HEADER_MAP_TARGET_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
|
||||
#include "map_assignment.h"
|
||||
#include "map_trigger.h"
|
||||
#include "map_source.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
class MapConfiguration;
|
||||
|
||||
/**
|
||||
* MapTarget represents a mapped target from the mapping configuration
|
||||
*/
|
||||
class MapTarget
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapTarget(MapConfiguration* config);
|
||||
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] name The signal name
|
||||
* @param [in] type The signal type
|
||||
*/
|
||||
MapTarget(MapConfiguration* config, std::string name, std::string type);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~MapTarget();
|
||||
|
||||
/**
|
||||
* CCTOR
|
||||
*/
|
||||
MapTarget(const MapTarget& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
MapTarget& operator=(const MapTarget& other);
|
||||
|
||||
/**
|
||||
* Returns the name of the mapped target
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param [in] new_name The new name of the target
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setName(const std::string& name);
|
||||
|
||||
/**
|
||||
* Returns the DDL typename of the mapped target
|
||||
*/
|
||||
const std::string& getType() const;
|
||||
|
||||
/**
|
||||
* Set type
|
||||
* @param [in] _type The type of the target
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_ARG Signal name already used in configuration
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setType(const std::string& type);
|
||||
|
||||
/**
|
||||
* Returns the validity for the current description
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Add an assignment
|
||||
* @param [in] assignment The assignment to add
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_INVALID_ARG Inconsistency with current configuration
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval ERR_NOT_SUPPORTED Assignment overlap with existing assignments
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addAssignment(const MapAssignment& assignment);
|
||||
|
||||
/**
|
||||
* Remove an assignment
|
||||
* @param [in] element_name The name of the assigned element
|
||||
* @retval ERR_NOT_FOUND Assignement not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeAssignment(const std::string& element_name);
|
||||
|
||||
/**
|
||||
* Returns all assignments configured for this target
|
||||
*/
|
||||
const MapAssignmentList& getAssignmentList() const;
|
||||
|
||||
/**
|
||||
* Add a trigger
|
||||
* @param [in] trigger The trigger to add
|
||||
* @retval ERR_INVALID_STATE No description found
|
||||
* @retval ERR_NOT_FOUND Target not found
|
||||
* @retval ERR_INVALID_ARG Inconsistency with current configuration
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTrigger(MapTriggerBase* trigger);
|
||||
|
||||
/**
|
||||
* Remove a trigger
|
||||
* @param [in] trigger The trigger to remove
|
||||
* @retval ERR_NOT_FOUND Trigger not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeTrigger(MapTriggerBase* trigger);
|
||||
|
||||
/**
|
||||
* Returns all triggers configured for this target
|
||||
*/
|
||||
const MapTriggerList& getTriggerList() const;
|
||||
|
||||
/**
|
||||
* Returns all referenced sources for this target.
|
||||
*/
|
||||
const MapSourceNameList& getReferencedSources() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the target from a target-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [in] lstSources The list of existing sources in mapping
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing name or type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDOM(const a_util::xml::DOMElement& target);
|
||||
|
||||
/**
|
||||
* Export target to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element to be written
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Checks if the assignments overlap
|
||||
* @retval ERR_NOT_SUPPORTED Assignments overlap
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkDoubleAssignments();
|
||||
|
||||
/**
|
||||
* Add an assignment to this target
|
||||
* @param [in] assignment The assignment to add
|
||||
* @param [in] lstSources The list of existing sources in mapping
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing or erroneous attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addAssignmentNoTypeCheck(const MapAssignment& assignment);
|
||||
|
||||
/**
|
||||
* Remove an assignment from this target
|
||||
* @param [in] strTo The name of the target element to unassign
|
||||
* @retval ERR_NOT_FOUND Assignement not found
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeAssignmentWithoutClear(const std::string& element_name);
|
||||
|
||||
/**
|
||||
* Add a trigger to this target
|
||||
* @param [in] trigger The trigger to add
|
||||
* @param [in] lstSources The list of existing sources in mapping
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTriggerNoTypeCheck(MapTriggerBase* trigger);
|
||||
|
||||
/**
|
||||
* Modify a source signal name
|
||||
* @param [in] _name The name of the target
|
||||
* @param [in] new_name The new name of the target
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result modifySourceName(const std::string& name, const std::string& new_name);
|
||||
|
||||
/**
|
||||
* swap implementation
|
||||
*/
|
||||
void swap(MapTarget& other);
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapSource;
|
||||
MapConfiguration* _config;
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
MapSourceNameList _sources;
|
||||
MapAssignmentList _assignments;
|
||||
MapTriggerList _triggers;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
bool operator==(const MapTarget& a, const MapTarget& b);
|
||||
|
||||
inline bool operator!=(const MapTarget& a, const MapTarget& b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
/// Public composite types used in the mapping::oo namespace
|
||||
typedef std::vector<MapTarget> MapTargetList;
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_TARGET_H
|
600
mapping/configuration/map_transformation.cpp
Normal file
600
mapping/configuration/map_transformation.cpp
Normal file
|
@ -0,0 +1,600 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_transformation.h"
|
||||
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "ddlrepresentation/ddlenum.h"
|
||||
|
||||
#include "map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-40, ERR_INVALID_STATE)
|
||||
_MAKE_RESULT(-42, ERR_INVALID_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapTransformationBase::MapTransformationBase(MapConfiguration* pConfig, const std::string& name)
|
||||
: _config(pConfig), _name(name), _is_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
MapTransformationBase::~MapTransformationBase()
|
||||
{
|
||||
}
|
||||
|
||||
a_util::result::Result MapTransformationBase::createFromDOM(MapConfiguration* pConfig, const a_util::xml::DOMElement& oTrans,
|
||||
MapTransformationBase*& pDestination)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrans.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator it = mapAttrs.find("name");
|
||||
if (it == mapAttrs.end() || it->second.empty())
|
||||
{
|
||||
pConfig->appendError("Missing name attribute for a transformation element");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
if(pConfig->getTransformation(it->second))
|
||||
{
|
||||
pConfig->appendError("A transformation with this name already exists");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
std::string name(it->second);
|
||||
|
||||
if (oTrans.getName() == "polynomial")
|
||||
{
|
||||
MapPolynomTransformation* pPoly = new MapPolynomTransformation(pConfig, name);
|
||||
if (isFailed(pPoly->loadFromDom(oTrans)))
|
||||
{
|
||||
delete pPoly;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
pDestination = pPoly;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
if (oTrans.getName() == "enum_table")
|
||||
{
|
||||
MapEnumTableTransformation* pPoly = new MapEnumTableTransformation(pConfig, name);
|
||||
if (isFailed(pPoly->loadFromDom(oTrans)))
|
||||
{
|
||||
delete pPoly;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
pDestination = pPoly;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
pConfig->appendError("Invalid transformation element (expected <polynomial>)");
|
||||
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTransformationBase::create(MapConfiguration* pConfig,
|
||||
const std::string& name, const std::string& strType, MapTransformationBase*& pDestination)
|
||||
{
|
||||
if (strType == "polynomial")
|
||||
{
|
||||
MapPolynomTransformation* pPoly = new MapPolynomTransformation(pConfig, name);
|
||||
pDestination = pPoly;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
if (strType == "enum_table")
|
||||
{
|
||||
MapEnumTableTransformation* pPoly = new MapEnumTableTransformation(pConfig, name);
|
||||
pDestination = pPoly;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
pConfig->appendError("Invalid transformation type (expected <polynomial> or <enum_table>)");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTransformationBase::setTypeFromDDL()
|
||||
{
|
||||
MapEnumTableTransformation* pMapETransf =
|
||||
dynamic_cast<MapEnumTableTransformation*>(this);
|
||||
if(pMapETransf)
|
||||
{
|
||||
return pMapETransf->convertValuesWithDDL();
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTransformationBase::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
const MapPolynomTransformation* pMapPTransf =
|
||||
dynamic_cast<const MapPolynomTransformation*>(this);
|
||||
if(pMapPTransf)
|
||||
{
|
||||
return pMapPTransf->writeToDOM(oDOMElement);
|
||||
}
|
||||
const MapEnumTableTransformation* pMapETransf =
|
||||
dynamic_cast<const MapEnumTableTransformation*>(this);
|
||||
if(pMapETransf)
|
||||
{
|
||||
return pMapETransf->writeToDOM(oDOMElement);
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapTransformationBase::getName() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
bool MapTransformationBase::isValid() const
|
||||
{
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
MapPolynomTransformation::MapPolynomTransformation(MapConfiguration* pConfig, const std::string& name)
|
||||
: MapTransformationBase(pConfig, name), _a(0), _b(0), _c(0), _d(0), _e(0)
|
||||
{
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::getA() const
|
||||
{
|
||||
return _a;
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::getB() const
|
||||
{
|
||||
return _b;
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::getC() const
|
||||
{
|
||||
return _c;
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::getD() const
|
||||
{
|
||||
return _d;
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::getE() const
|
||||
{
|
||||
return _e;
|
||||
}
|
||||
|
||||
MapTransformationBase* MapPolynomTransformation::clone() const
|
||||
{
|
||||
return new MapPolynomTransformation(*this);
|
||||
}
|
||||
|
||||
bool MapPolynomTransformation::isEqual(const MapTransformationBase& oOther) const
|
||||
{
|
||||
if (oOther.getName() != getName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const MapPolynomTransformation* p =
|
||||
dynamic_cast<const MapPolynomTransformation*>(&oOther);
|
||||
if (p)
|
||||
{
|
||||
return getA() == p->getA() && getB() == p->getB() &&
|
||||
getC() == p->getC() && getD() == p->getD() && getE() == p->getE();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
a_util::result::Result MapPolynomTransformation::loadFromDom(const a_util::xml::DOMElement& oTrans)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrans.getAttributes();
|
||||
std::string strCoefs[5];
|
||||
char c = 'a';
|
||||
for (int i = 0; i < 5; ++i, ++c)
|
||||
{
|
||||
a_util::xml::DOMAttributes::const_iterator it = mapAttrs.find(std::string(1, c));
|
||||
if (it != mapAttrs.end())
|
||||
{
|
||||
strCoefs[i] = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return setCoefficients(strCoefs);
|
||||
}
|
||||
|
||||
a_util::result::Result MapPolynomTransformation::setCoefficients(const std::string strCoefs[5])
|
||||
{
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
double p[5] = {0};
|
||||
char c = 'a';
|
||||
for (int i = 0; i < 5; ++i, c++)
|
||||
{
|
||||
if(!strCoefs[i].empty())
|
||||
{
|
||||
if (!a_util::strings::isDouble(strCoefs[i]))
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Invalid coefficient attribute '%c' for polynomial transformation '%s' (expected number)",
|
||||
c, this->getName().c_str()));
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
p[i] = a_util::strings::toDouble(strCoefs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
_a = p[0];
|
||||
_b = p[1];
|
||||
_c = p[2];
|
||||
_d = p[3];
|
||||
_e = p[4];
|
||||
return res;
|
||||
}
|
||||
|
||||
a_util::result::Result MapPolynomTransformation::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("polynomial");
|
||||
oDOMElement.setAttribute("name", _name);
|
||||
if(_a != 0)
|
||||
{
|
||||
oDOMElement.setAttribute("a", a_util::strings::format("%g",_a));
|
||||
}
|
||||
if(_b != 0)
|
||||
{
|
||||
oDOMElement.setAttribute("b", a_util::strings::format("%g",_b));
|
||||
}
|
||||
if(_c != 0)
|
||||
{
|
||||
oDOMElement.setAttribute("c", a_util::strings::format("%g",_c));
|
||||
}
|
||||
if(_d != 0)
|
||||
{
|
||||
oDOMElement.setAttribute("d", a_util::strings::format("%g",_d));
|
||||
}
|
||||
if(_e != 0)
|
||||
{
|
||||
oDOMElement.setAttribute("e", a_util::strings::format("%g",_e));
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
double MapPolynomTransformation::evaluate(double value) const
|
||||
{
|
||||
double f64Pow2 = value*value;
|
||||
double f64Pow3 = f64Pow2*value;
|
||||
return (_a + _b*value + _c*f64Pow2 + _d*f64Pow3 + _e*f64Pow3*value);
|
||||
}
|
||||
|
||||
|
||||
MapEnumTableTransformation::MapEnumTableTransformation(MapConfiguration* pConfig, const std::string& name)
|
||||
: MapTransformationBase(pConfig, name), _default_int(0), _default_value("0")
|
||||
{
|
||||
}
|
||||
|
||||
MapTransformationBase* MapEnumTableTransformation::clone() const
|
||||
{
|
||||
return new MapEnumTableTransformation(*this);
|
||||
}
|
||||
|
||||
bool MapEnumTableTransformation::isEqual(const MapTransformationBase& oOther) const
|
||||
{
|
||||
if (oOther.getName() != getName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const MapEnumTableTransformation* p =
|
||||
dynamic_cast<const MapEnumTableTransformation*>(&oOther);
|
||||
if (p)
|
||||
{
|
||||
return getDefaultStr() == p->getDefaultStr() && getConversionsStr() == p->getConversionsStr();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::loadFromDom(const a_util::xml::DOMElement& oTrans)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrans.getAttributes();
|
||||
a_util::result::Result nRes = a_util::result::SUCCESS;
|
||||
// Read <from> attribute
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrFrom = mapAttrs.find("from");
|
||||
if (itAttrFrom == mapAttrs.end() || itAttrFrom->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <from> attribute for <transformation> '%s'",
|
||||
getName().c_str()));
|
||||
nRes = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Read <to> attribute
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrTo = mapAttrs.find("to");
|
||||
if (itAttrTo == mapAttrs.end() || itAttrTo->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <to> attribute for <transformation> '%s'",
|
||||
getName().c_str()));
|
||||
nRes = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(isOk(nRes))
|
||||
{
|
||||
setEnumsStr(itAttrFrom->second, itAttrTo->second);
|
||||
|
||||
// Read <default> attribute
|
||||
a_util::xml::DOMAttributes::const_iterator itAttrDefault = mapAttrs.find("default");
|
||||
if (itAttrDefault == mapAttrs.end() || itAttrDefault->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <default> attribute for <transformation> '%s'",
|
||||
getName().c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
setDefaultStr(itAttrDefault->second);
|
||||
|
||||
// Search conversions in DDLEnums
|
||||
const a_util::xml::DOMElementList lstConv = oTrans.getChildren();
|
||||
|
||||
for (a_util::xml::DOMElementList::const_iterator it = lstConv.begin(); it != lstConv.end(); ++it)
|
||||
{
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
const a_util::xml::DOMAttributes mapConvAttrs = it->getAttributes();
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itConvAttrFrom = mapConvAttrs.find("from");
|
||||
if (itConvAttrFrom == mapConvAttrs.end() || itConvAttrFrom->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <from> attribute for <conversion> in <transformation> '%s'",
|
||||
getName().c_str()));
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itConvAttrTo = mapConvAttrs.find("to");
|
||||
if (itConvAttrTo == mapConvAttrs.end() || itConvAttrTo->second.empty())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("Missing <to> attribute for <conversion> in <transformation> '%s'",
|
||||
getName().c_str()));
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(a_util::result::isOk(res))
|
||||
{
|
||||
if(isFailed(addConversionStr(itConvAttrFrom->second, itConvAttrTo->second)))
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<from> attribute '%s' appears more than once in <transformation> '%s'",
|
||||
itConvAttrFrom->second.c_str(), getName().c_str()));
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
if(a_util::result::isFailed(res))
|
||||
{
|
||||
nRes = res;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("enum_table");
|
||||
oDOMElement.setAttribute("name", _name);
|
||||
oDOMElement.setAttribute("from", _enum_from);
|
||||
oDOMElement.setAttribute("to", _enum_to);
|
||||
oDOMElement.setAttribute("default", _default_value);
|
||||
for(MapStrConversionList::const_iterator itConv = _conversions.begin(); itConv != _conversions.end(); itConv++)
|
||||
{
|
||||
a_util::xml::DOMElement oDOMConv = oDOMElement.createChild("conversion");
|
||||
oDOMConv.setAttribute("from", itConv->first);
|
||||
oDOMConv.setAttribute("to", itConv->second);
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapEnumTableTransformation::getEnumFrom() const
|
||||
{
|
||||
return _enum_from;
|
||||
}
|
||||
|
||||
const std::string& MapEnumTableTransformation::getEnumTo() const
|
||||
{
|
||||
return _enum_to;
|
||||
}
|
||||
|
||||
a_util::result::Result mapping::oo::MapEnumTableTransformation::setEnums(const std::string& strEnumFrom, const std::string& strEnumTo)
|
||||
{
|
||||
RETURN_IF_FAILED(setEnumsStr(strEnumFrom, strEnumTo));
|
||||
a_util::result::Result nRes = convertValuesWithDDL();
|
||||
if(isFailed(nRes))
|
||||
{
|
||||
_enum_from.clear();
|
||||
_enum_to.clear();
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
|
||||
int64_t MapEnumTableTransformation::getDefault() const
|
||||
{
|
||||
return _default_int;
|
||||
}
|
||||
|
||||
std::string MapEnumTableTransformation::getDefaultStr() const
|
||||
{
|
||||
return _default_value;
|
||||
}
|
||||
|
||||
a_util::result::Result mapping::oo::MapEnumTableTransformation::setDefault(const std::string& strDefault)
|
||||
{
|
||||
RETURN_IF_FAILED(setDefaultStr(strDefault));
|
||||
a_util::result::Result nRes = convertValuesWithDDL();
|
||||
if(isFailed(nRes))
|
||||
{
|
||||
_default_value.clear();
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
|
||||
const std::map<int64_t, int64_t>& MapEnumTableTransformation::getConversions() const
|
||||
{
|
||||
return _conversions_int;
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string>& MapEnumTableTransformation::getConversionsStr() const
|
||||
{
|
||||
return _conversions;
|
||||
}
|
||||
|
||||
a_util::result::Result mapping::oo::MapEnumTableTransformation::addConversion(const std::string& strFrom, const std::string& strTo)
|
||||
{
|
||||
RETURN_IF_FAILED(addConversionStr(strFrom, strTo));
|
||||
a_util::result::Result nRes = convertValuesWithDDL();
|
||||
if(isFailed(nRes))
|
||||
{
|
||||
_conversions.erase(strFrom);
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::removeConversion(const std::string& strFrom)
|
||||
{
|
||||
_conversions.erase(strFrom);
|
||||
return convertValuesWithDDL();
|
||||
}
|
||||
|
||||
double MapEnumTableTransformation::evaluate(double f64Value) const
|
||||
{
|
||||
std::map<int64_t, int64_t>::const_iterator it = _conversions_int.find((int64_t)f64Value);
|
||||
if(it != _conversions_int.end())
|
||||
{
|
||||
return (double)it->second;
|
||||
}
|
||||
return (double)_default_int;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::setEnumsStr(const std::string& strEnumFrom, const std::string& strEnumTo)
|
||||
{
|
||||
_enum_from = strEnumFrom;
|
||||
_enum_to = strEnumTo;
|
||||
|
||||
_conversions_int.clear();
|
||||
_conversions.clear();
|
||||
_default_value.clear();
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::setDefaultStr(const std::string& strDefault)
|
||||
{
|
||||
_default_value = strDefault;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::addConversionStr(const std::string& strFrom, const std::string& strTo)
|
||||
{
|
||||
if(_conversions.find(strFrom) != _conversions.end())
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
_conversions[strFrom] = strTo;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapEnumTableTransformation::convertValuesWithDDL()
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
if(!_config->getDescription())
|
||||
{
|
||||
_config->appendError(a_util::strings::format("No description found",
|
||||
getName().c_str()));
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
// Search <from> in DDL
|
||||
const ddl::DDLEnum * pEnumFrom = _config->getDescription()->getEnumByName(_enum_from);
|
||||
if(pEnumFrom == NULL)
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<from> attribute for <transformation> '%s' should be an enumeration",
|
||||
getName().c_str()));
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
// Search <to> in DDL
|
||||
const ddl::DDLEnum * pEnumTo = _config->getDescription()->getEnumByName(_enum_to);
|
||||
if(pEnumTo == NULL)
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<to> attribute for <transformation> '%s' should be an enumeration",
|
||||
getName().c_str()));
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
|
||||
// Search <default> in DDL
|
||||
if(!_default_value.empty())
|
||||
{
|
||||
std::string strValue;
|
||||
if(isFailed(pEnumTo->getValue(_default_value, strValue)) || !a_util::strings::isInt64(strValue))
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<default> attribute for <transformation> '%s' should be an element of '%s' <enumeration>",
|
||||
getName().c_str(), _enum_to.c_str()));
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
|
||||
_default_int = a_util::strings::toInt64(strValue);
|
||||
}
|
||||
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
_conversions_int.clear();
|
||||
for (std::map<std::string, std::string>::iterator it = _conversions.begin(); it != _conversions.end(); ++it)
|
||||
{
|
||||
std::string strFromVal, strToVal;
|
||||
|
||||
if(isFailed(pEnumFrom->getValue(it->first, strFromVal)) || !a_util::strings::isInt64(strFromVal))
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<from> attribute '%s' for <conversion> in <transformation> '%s' should be a element of '%s' <enumeration>",
|
||||
it->first.c_str(), getName().c_str(), pEnumFrom->getName().c_str()));
|
||||
_is_valid = false;
|
||||
res = ERR_INVALID_TYPE;
|
||||
}
|
||||
if(isFailed(pEnumTo->getValue(it->second, strToVal)) || !a_util::strings::isInt64(strToVal))
|
||||
{
|
||||
_config->appendError(a_util::strings::format("<to> attribute '%s' for <conversion> in <transformation> '%s' should be a element of '%s' <enumeration>",
|
||||
it->second.c_str(), getName().c_str(), pEnumTo->getName().c_str()));
|
||||
_is_valid = false;
|
||||
res = ERR_INVALID_TYPE;
|
||||
}
|
||||
|
||||
if(isOk(res))
|
||||
{
|
||||
_is_valid = true;
|
||||
_conversions_int[a_util::strings::toInt64(strFromVal)] = a_util::strings::toInt64(strToVal);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
379
mapping/configuration/map_transformation.h
Normal file
379
mapping/configuration/map_transformation.h
Normal file
|
@ -0,0 +1,379 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*
|
||||
* QNX support Copyright (c) 2019 by dSPACE GmbH, Paderborn, Germany. All Rights Reserved
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_TRANSFORMATION_H
|
||||
#define HEADER_MAP_TRANSFORMATION_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
#include "a_util/strings.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
|
||||
class MapConfiguration;
|
||||
|
||||
/**
|
||||
* cMapTransformation forms a base class for a single transformation
|
||||
*/
|
||||
class MapTransformationBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] name The transformation name
|
||||
*/
|
||||
MapTransformationBase(MapConfiguration* config, const std::string& name);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
virtual ~MapTransformationBase();
|
||||
|
||||
/**
|
||||
* Returns the name of the transformation
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
|
||||
/**
|
||||
* Returns the validity for the current description
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* Polymorphic comparison method
|
||||
*/
|
||||
virtual bool isEqual(const MapTransformationBase& other) const = 0;
|
||||
|
||||
/**
|
||||
* Polymorphic clone method
|
||||
*/
|
||||
virtual MapTransformationBase* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Polymorphic evaluation template method
|
||||
* @param [in] value The value to evaluate
|
||||
*/
|
||||
virtual double evaluate(double value) const = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* creates a polymorphic transformation instance from a dom element
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] destination The Transformation object to fill
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing name or type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
static a_util::result::Result createFromDOM(MapConfiguration* config, const a_util::xml::DOMElement& dom_element,
|
||||
MapTransformationBase*& destination);
|
||||
|
||||
/**
|
||||
* creates a polymorphic transformation instance from a dom element
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] destination The Transformation object to fill
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing name or type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
static a_util::result::Result create(MapConfiguration* config, const std::string& name,
|
||||
const std::string& type, MapTransformationBase*& destination);
|
||||
|
||||
/**
|
||||
* Export transformation to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Set Float values from Enumeration definition in DDL-File
|
||||
* @param [in] pDDLRef The ddl description
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setTypeFromDDL();
|
||||
|
||||
protected:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
MapConfiguration* _config;
|
||||
std::string _name;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// MapPolynomTransformation represents a polynom transformation in the configuration api
|
||||
/// as well as the actual implementation of the transformation in the evaluate method
|
||||
class MapPolynomTransformation : public MapTransformationBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] name The transformation name
|
||||
*/
|
||||
MapPolynomTransformation(MapConfiguration* config, const std::string& name);
|
||||
|
||||
/**
|
||||
* Returns parameter A of the polynomial
|
||||
*/
|
||||
double getA() const;
|
||||
|
||||
/**
|
||||
* Returns parameter A of the polynomial
|
||||
*/
|
||||
double getB() const;
|
||||
|
||||
/**
|
||||
* Returns parameter A of the polynomial
|
||||
*/
|
||||
double getC() const;
|
||||
|
||||
/**
|
||||
* Returns parameter A of the polynomial
|
||||
*/
|
||||
double getD() const;
|
||||
|
||||
/**
|
||||
* Returns parameter A of the polynomial
|
||||
*/
|
||||
double getE() const;
|
||||
|
||||
/**
|
||||
* Set Polynom coefficients
|
||||
* @param [in] coefs The list of coefficients
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG An attribute is not a float value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setCoefficients(const std::string coefs[5]);
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
bool isEqual(const MapTransformationBase& other) const;
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
double evaluate(double value) const;
|
||||
|
||||
/// nodoc
|
||||
MapTransformationBase* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the transformation from a target-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG An attribute is not a float value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDom(const a_util::xml::DOMElement& dom_element);
|
||||
|
||||
/**
|
||||
* Export transformation to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element to be written
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapTransformationBase;
|
||||
double _a, _b, _c, _d, _e;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// MapEnumTableTransformation represents a transformation between to enumerations
|
||||
class MapEnumTableTransformation : public MapTransformationBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] name The transformation name
|
||||
*/
|
||||
MapEnumTableTransformation(MapConfiguration* config, const std::string& name);
|
||||
|
||||
/**
|
||||
* Returns the name of the source enumeration
|
||||
*/
|
||||
const std::string& getEnumFrom() const;
|
||||
|
||||
/**
|
||||
* Returns the name of the target enumeration
|
||||
*/
|
||||
const std::string& getEnumTo() const;
|
||||
|
||||
/**
|
||||
* Set the name of the target and source enumerations
|
||||
* @param [in] enum_from input enumeration name
|
||||
* @param [in] enum_to output enumeration name
|
||||
* @retval ERR_INVALID_TYPE Enums not found in ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setEnums(const std::string& enum_from, const std::string& enum_to);
|
||||
|
||||
/**
|
||||
* Returns default value
|
||||
*/
|
||||
int64_t getDefault() const;
|
||||
|
||||
/**
|
||||
* Returns default value as string
|
||||
*/
|
||||
std::string getDefaultStr() const;
|
||||
|
||||
/**
|
||||
* Set default value as string
|
||||
* @param [in] default_value string for default value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDefault(const std::string& default_value);
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic ignored "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns conversion list
|
||||
*/
|
||||
const std::map<int64_t, int64_t>& getConversions() const;
|
||||
|
||||
/**
|
||||
* Returns conversion list as string
|
||||
*/
|
||||
const std::map<std::string, std::string>& getConversionsStr() const;
|
||||
|
||||
/**
|
||||
* Add a conversion as string
|
||||
* @param [in] from string for source value
|
||||
* @param [in] to string for target value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result addConversion(const std::string& from, const std::string& to);
|
||||
|
||||
/**
|
||||
* Remove a conversion as string
|
||||
* @param [in] from string for source value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result removeConversion(const std::string& from);
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
bool isEqual(const MapTransformationBase& other) const;
|
||||
|
||||
/**
|
||||
* @overload
|
||||
*/
|
||||
double evaluate(double value) const;
|
||||
|
||||
/// nodoc
|
||||
MapTransformationBase* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Initializes the transformation from a target-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDom(const a_util::xml::DOMElement& dom_element);
|
||||
|
||||
/**
|
||||
* Export transformation to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element to be written
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Convert string values to integer values
|
||||
* before were the integer values not filled, as the ddl is necessary for this
|
||||
*
|
||||
* @param [in] pDDLRef The ddl description
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_TYPE Inconsistency with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result convertValuesWithDDL();
|
||||
|
||||
/**
|
||||
* Set the name of the target and source enumerations
|
||||
* @param [in] enum_from input enumeration name
|
||||
* @param [in] enum_to output enumeration name
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setEnumsStr(const std::string& enum_from, const std::string& enum_to);
|
||||
|
||||
/**
|
||||
* Set default value as string
|
||||
* @param [in] default_value string for default value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setDefaultStr(const std::string& default_value);
|
||||
|
||||
/**
|
||||
* Add a conversion as string
|
||||
* @param [in] from string for source value
|
||||
* @param [in] to string for target value
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result addConversionStr(const std::string& from, const std::string& to);
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapTransformationBase;
|
||||
std::string _enum_from;
|
||||
std::string _enum_to;
|
||||
std::string _default_value;
|
||||
typedef std::map<std::string, std::string> MapStrConversionList;
|
||||
MapStrConversionList _conversions;
|
||||
int64_t _default_int;
|
||||
std::map<int64_t, int64_t> _conversions_int;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic warning "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
/// Public composite types used in the mapping::oo namespace
|
||||
typedef std::vector<MapTransformationBase*> MapTransformationList;
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_TRANSFORMATION_H
|
592
mapping/configuration/map_trigger.cpp
Normal file
592
mapping/configuration/map_trigger.cpp
Normal file
|
@ -0,0 +1,592 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#include "map_trigger.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-40, ERR_INVALID_STATE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping::oo;
|
||||
|
||||
MapTriggerBase::MapTriggerBase(MapConfiguration* pConfig) : _config(pConfig), _is_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
MapTriggerBase::~MapTriggerBase()
|
||||
{
|
||||
}
|
||||
|
||||
bool MapTriggerBase::isValid() const
|
||||
{
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
bool MapTriggerBase::checkValidity()
|
||||
{
|
||||
if(isOk(_config->checkTriggerType(this)))
|
||||
{
|
||||
_is_valid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_is_valid = false;
|
||||
}
|
||||
return _is_valid;
|
||||
}
|
||||
|
||||
std::string MapTriggerBase::getSourceDependency() const
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
a_util::result::Result MapTriggerBase::setSourceDependency(const std::string& strNewName)
|
||||
{
|
||||
MapSignalTrigger* pMapSTrigger =
|
||||
dynamic_cast<MapSignalTrigger*>(this);
|
||||
if(pMapSTrigger)
|
||||
{
|
||||
return pMapSTrigger->setVariableNoTypeCheck(strNewName);
|
||||
}
|
||||
oo::MapDataTrigger* pMapDTrigger =
|
||||
dynamic_cast<oo::MapDataTrigger*>(this);
|
||||
if(pMapDTrigger)
|
||||
{
|
||||
return pMapDTrigger->setSourceNoTypeCheck(strNewName);
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTriggerBase::createFromDOM(MapConfiguration* pConfig, const a_util::xml::DOMElement& oTrigger,
|
||||
MapTriggerBase*& pDestination)
|
||||
{
|
||||
// parse attributes
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrigger.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator it = mapAttrs.find("type");
|
||||
if (it == mapAttrs.end() || it->second.empty())
|
||||
{
|
||||
pConfig->appendError("Missing <trigger> type attribute");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (it->second == "periodic")
|
||||
{
|
||||
MapPeriodicTrigger* pTrig = new MapPeriodicTrigger(pConfig);
|
||||
if (isFailed(pTrig->loadFromDom(oTrigger)))
|
||||
{
|
||||
delete pTrig;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
pDestination = pTrig;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
if (it->second == "signal")
|
||||
{
|
||||
MapSignalTrigger* pTrig = new MapSignalTrigger(pConfig);
|
||||
if (isFailed(pTrig->loadFromDom(oTrigger)))
|
||||
{
|
||||
delete pTrig;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
pDestination = pTrig;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
if (it->second == "data")
|
||||
{
|
||||
MapDataTrigger* pTrig = new MapDataTrigger(pConfig);
|
||||
if (isFailed(pTrig->loadFromDom(oTrigger)))
|
||||
{
|
||||
delete pTrig;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
pDestination = pTrig;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
pConfig->appendError(a_util::strings::format("Unknown <trigger> type '%s'",
|
||||
it->second.c_str()));
|
||||
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTriggerBase::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setName("trigger");
|
||||
|
||||
const MapPeriodicTrigger* pMapPTrigger =
|
||||
dynamic_cast<const MapPeriodicTrigger*>(this);
|
||||
if(pMapPTrigger)
|
||||
{
|
||||
return pMapPTrigger->writeToDOM(oDOMElement);
|
||||
}
|
||||
|
||||
const MapSignalTrigger* pMapSTrigger =
|
||||
dynamic_cast<const MapSignalTrigger*>(this);
|
||||
if(pMapSTrigger)
|
||||
{
|
||||
return pMapSTrigger->writeToDOM(oDOMElement);
|
||||
}
|
||||
|
||||
const oo::MapDataTrigger* pMapDTrigger =
|
||||
dynamic_cast<const oo::MapDataTrigger*>(this);
|
||||
if(pMapDTrigger)
|
||||
{
|
||||
return pMapDTrigger->writeToDOM(oDOMElement);
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapTriggerBase::checkTriggerReferences() const
|
||||
{
|
||||
const MapSignalTrigger* pMapSTrigger =
|
||||
dynamic_cast<const MapSignalTrigger*>(this);
|
||||
if(pMapSTrigger)
|
||||
{
|
||||
const MapSource* pSrcInstance = _config->getSource(pMapSTrigger->getVariable());
|
||||
if (!pSrcInstance)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Trigger references unknown <source> '%s'",
|
||||
pMapSTrigger->getVariable().c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
const oo::MapDataTrigger* pMapDTrigger =
|
||||
dynamic_cast<const oo::MapDataTrigger*>(this);
|
||||
if(pMapDTrigger)
|
||||
{
|
||||
const MapSource* pSrcInstance = _config->getSource(pMapDTrigger->getSource());
|
||||
if (!pSrcInstance)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Assignment references unknown <source> '%s'",
|
||||
pMapDTrigger->getSource().c_str()));
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Periodic Trigger
|
||||
**/
|
||||
|
||||
MapPeriodicTrigger::MapPeriodicTrigger(MapConfiguration* pConfig) :
|
||||
MapTriggerBase(pConfig), _period(0)
|
||||
{
|
||||
}
|
||||
|
||||
double MapPeriodicTrigger::getPeriod() const
|
||||
{
|
||||
return _period;
|
||||
}
|
||||
|
||||
a_util::result::Result MapPeriodicTrigger::setPeriod(const std::string& strPeriod,
|
||||
const std::string& strUnit)
|
||||
{
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
if (!a_util::strings::isUInt32(strPeriod) || strPeriod.find('-') != std::string::npos ||
|
||||
strPeriod.find('+') != std::string::npos)
|
||||
{
|
||||
_config->appendError(
|
||||
"Invalid period attribute for periodic trigger (expected positive integer)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(!(strUnit == "us" || strUnit == "ms"
|
||||
|| strUnit == "s"))
|
||||
{
|
||||
_config->appendError(
|
||||
"Invalid unit attribute for periodic trigger (expected us, ms or s)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(isOk(res))
|
||||
{
|
||||
uint32_t nPeriod = a_util::strings::toUInt32(strPeriod);
|
||||
|
||||
if (strUnit == "us")
|
||||
{
|
||||
_period = double(nPeriod) / 1000.0;
|
||||
}
|
||||
else if (strUnit == "ms")
|
||||
{
|
||||
_period = nPeriod;
|
||||
}
|
||||
else if (strUnit == "s")
|
||||
{
|
||||
_period = double(nPeriod) * 1000.0;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
a_util::result::Result MapPeriodicTrigger::loadFromDom(const a_util::xml::DOMElement& oTrigger)
|
||||
{
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrigger.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator itPeriod = mapAttrs.find("period");
|
||||
if (itPeriod == mapAttrs.end() || itPeriod->second.empty())
|
||||
{
|
||||
_config->appendError("Missing period attribute for periodic trigger");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itUnit = mapAttrs.find("unit");
|
||||
if (itUnit == mapAttrs.end() || itUnit->second.empty())
|
||||
{
|
||||
_config->appendError("Missing unit attribute for periodic trigger (expected us, ms or s)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(isOk(res))
|
||||
{
|
||||
std::string strUnit = itUnit->second;
|
||||
a_util::strings::trim(strUnit);
|
||||
res = setPeriod(itPeriod->second, strUnit);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
a_util::result::Result MapPeriodicTrigger::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setAttribute("type", "periodic");
|
||||
if(_period == ceil(_period))
|
||||
{
|
||||
if((_period/1000) == ceil(_period/1000))
|
||||
{
|
||||
oDOMElement.setAttribute("period", a_util::strings::format("%d", (uint32_t)floor(_period/1000)));
|
||||
oDOMElement.setAttribute("unit", "s");
|
||||
}
|
||||
else
|
||||
{
|
||||
oDOMElement.setAttribute("period", a_util::strings::format("%d", (uint32_t)floor(_period)));
|
||||
oDOMElement.setAttribute("unit", "ms");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oDOMElement.setAttribute("period", a_util::strings::format("%d", (uint32_t)floor(_period*1000)));
|
||||
oDOMElement.setAttribute("unit", "us");
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
MapTriggerBase* MapPeriodicTrigger::clone() const
|
||||
{
|
||||
return new MapPeriodicTrigger(*this);
|
||||
}
|
||||
|
||||
bool MapPeriodicTrigger::isEqual(const MapTriggerBase& oOther) const
|
||||
{
|
||||
const MapPeriodicTrigger* p = dynamic_cast<const MapPeriodicTrigger*>(&oOther);
|
||||
if (p)
|
||||
{
|
||||
return getPeriod() == p->getPeriod();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal Trigger
|
||||
**/
|
||||
MapSignalTrigger::MapSignalTrigger(MapConfiguration* pConfig) : MapTriggerBase(pConfig)
|
||||
{
|
||||
}
|
||||
|
||||
std::string MapSignalTrigger::getSourceDependency() const
|
||||
{
|
||||
return _variable;
|
||||
}
|
||||
|
||||
const std::string& MapSignalTrigger::getVariable() const
|
||||
{
|
||||
return _variable;
|
||||
}
|
||||
|
||||
a_util::result::Result MapSignalTrigger::setVariable(const std::string& strSignalName)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
setVariableNoTypeCheck(strSignalName);
|
||||
if(isFailed(_config->resetErrors()))
|
||||
{
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
const MapSource* pSrcInstance = _config->getSource(_variable);
|
||||
if (!pSrcInstance)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Trigger references unknown <source> '%s'",
|
||||
_variable.c_str()));
|
||||
_variable.clear();
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
_is_valid = true;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapSignalTrigger::loadFromDom(const a_util::xml::DOMElement& oTrigger)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrigger.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator it = mapAttrs.find("variable");
|
||||
if (it == mapAttrs.end() || it->second.empty())
|
||||
{
|
||||
_config->appendError("Missing variable attribute for signal trigger");
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
return setVariableNoTypeCheck(it->second);
|
||||
}
|
||||
|
||||
a_util::result::Result MapSignalTrigger::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setAttribute("type", "signal");
|
||||
oDOMElement.setAttribute("variable", _variable);
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapSignalTrigger::setVariableNoTypeCheck(const std::string& strSignalName)
|
||||
{
|
||||
_variable = strSignalName;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
MapTriggerBase* MapSignalTrigger::clone() const
|
||||
{
|
||||
return new MapSignalTrigger(*this);
|
||||
}
|
||||
|
||||
bool MapSignalTrigger::isEqual(const MapTriggerBase& oOther) const
|
||||
{
|
||||
const MapSignalTrigger* p = dynamic_cast<const MapSignalTrigger*>(&oOther);
|
||||
if (p)
|
||||
{
|
||||
return getVariable() == p->getVariable();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data Trigger
|
||||
**/
|
||||
MapDataTrigger::MapDataTrigger(MapConfiguration* pConfig) : MapTriggerBase(pConfig)
|
||||
{
|
||||
}
|
||||
|
||||
std::string MapDataTrigger::getSourceDependency() const
|
||||
{
|
||||
return _source;
|
||||
}
|
||||
|
||||
const std::string& MapDataTrigger::getVariable() const
|
||||
{
|
||||
return _variable;
|
||||
}
|
||||
|
||||
const std::string& MapDataTrigger::getSource() const
|
||||
{
|
||||
return _source;
|
||||
}
|
||||
|
||||
|
||||
|
||||
a_util::result::Result MapDataTrigger::setSourceNoTypeCheck(const std::string& strSource)
|
||||
{
|
||||
_source = strSource;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& MapDataTrigger::getOperator() const
|
||||
{
|
||||
return _operator;
|
||||
}
|
||||
|
||||
double MapDataTrigger::getValue() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
a_util::result::Result MapDataTrigger::loadFromDom(const a_util::xml::DOMElement& oTrigger)
|
||||
{
|
||||
const a_util::xml::DOMAttributes mapAttrs = oTrigger.getAttributes();
|
||||
a_util::xml::DOMAttributes::const_iterator itVariable = mapAttrs.find("variable");
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
if (itVariable == mapAttrs.end() || itVariable->second.empty())
|
||||
{
|
||||
_config->appendError("Missing variable attribute for data trigger");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itOperator = mapAttrs.find("operator");
|
||||
if (itOperator == mapAttrs.end() || itOperator->second.empty())
|
||||
{
|
||||
_config->appendError("Missing operator attribute for data trigger");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
a_util::xml::DOMAttributes::const_iterator itValue = mapAttrs.find("value");
|
||||
if (itValue == mapAttrs.end() || itValue->second.empty())
|
||||
{
|
||||
_config->appendError("Missing value attribute for data trigger (expected a source name)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if(isOk(res))
|
||||
{
|
||||
res = setComparisonNoTypeCheck(itVariable->second, itOperator->second, itValue->second);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
a_util::result::Result MapDataTrigger::writeToDOM(a_util::xml::DOMElement& oDOMElement) const
|
||||
{
|
||||
oDOMElement.setAttribute("type", "data");
|
||||
oDOMElement.setAttribute("variable", _source + "." + _variable);
|
||||
oDOMElement.setAttribute("operator", _operator);
|
||||
oDOMElement.setAttribute("value", a_util::strings::format("%g", _value));
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MapDataTrigger::setComparisonNoTypeCheck(const std::string& strSourceElementPath,
|
||||
const std::string& strOperator, const std::string& strValue)
|
||||
{
|
||||
a_util::result::Result res = a_util::result::SUCCESS;
|
||||
|
||||
_variable = strSourceElementPath;
|
||||
a_util::strings::trim(_variable);
|
||||
_source.clear();
|
||||
|
||||
// parse source out of <from>
|
||||
size_t idx = _variable.find('.');
|
||||
if (idx != std::string::npos)
|
||||
{
|
||||
_source = _variable.substr(0, idx);
|
||||
_variable = _variable.substr(idx + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_variable.clear();
|
||||
_config->appendError("Variable attribute for data trigger should be a signal element (expected [Signal].[Element])");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
if (!(strOperator == "less_than" || strOperator == "greater_than" ||
|
||||
strOperator == "less_than_equal" || strOperator == "greater_than_equal" ||
|
||||
strOperator == "equal" || strOperator == "not_equal"))
|
||||
{
|
||||
_operator.clear();
|
||||
_config->appendError(
|
||||
"Invalid operator attribute for data trigger (expected less_than, greater_than, "
|
||||
"less_than_equal, greater_than_equal, equal or not_equal)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
_operator = strOperator;
|
||||
}
|
||||
|
||||
if (!a_util::strings::isDouble(strValue))
|
||||
{
|
||||
_value = 0;
|
||||
_config->appendError(
|
||||
"Invalid value attribute for data trigger (expected floating point value)");
|
||||
res = ERR_INVALID_ARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = a_util::strings::toDouble(strValue);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
MapTriggerBase* MapDataTrigger::clone() const
|
||||
{
|
||||
return new MapDataTrigger(*this);
|
||||
}
|
||||
|
||||
bool MapDataTrigger::isEqual(const MapTriggerBase& oOther) const
|
||||
{
|
||||
const MapDataTrigger* p = dynamic_cast<const MapDataTrigger*>(&oOther);
|
||||
if (p)
|
||||
{
|
||||
return getVariable() == p->getVariable() && getSource() == p->getSource() &&
|
||||
getOperator() == p->getOperator() && getValue() == p->getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
a_util::result::Result MapDataTrigger::setComparison(const std::string& strSourceElementPath,
|
||||
const std::string& strOperator, const std::string& strValue)
|
||||
{
|
||||
if(!_config)
|
||||
{
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
RETURN_IF_FAILED(_config->resetErrors());
|
||||
RETURN_IF_FAILED(setComparisonNoTypeCheck(strSourceElementPath, strOperator, strValue));
|
||||
const MapSource* pSrcInstance = _config->getSource(_source);
|
||||
if (!pSrcInstance)
|
||||
{
|
||||
_config->appendError(
|
||||
a_util::strings::format("Assignment references unknown <source> '%s'",
|
||||
_source.c_str()));
|
||||
_is_valid = false;
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
a_util::result::Result nRes = _config->checkTriggerType(this);
|
||||
if(isFailed(nRes))
|
||||
{
|
||||
_is_valid = false;
|
||||
}
|
||||
if(isOk(nRes))
|
||||
{
|
||||
_is_valid = true;
|
||||
}
|
||||
return nRes;
|
||||
}
|
365
mapping/configuration/map_trigger.h
Normal file
365
mapping/configuration/map_trigger.h
Normal file
|
@ -0,0 +1,365 @@
|
|||
/**
|
||||
* @file
|
||||
*
|
||||
* @copyright
|
||||
* @verbatim
|
||||
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla
|
||||
Public License, v. 2.0. If a copy of the MPL was not distributed
|
||||
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MAP_TRIGGER_H
|
||||
#define HEADER_MAP_TRIGGER_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "a_util/xml.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace oo
|
||||
{
|
||||
class MapConfiguration;
|
||||
/**
|
||||
* cMapTrigger forms a base class for a trigger contained in the configuration
|
||||
*/
|
||||
class MapTriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
*/
|
||||
MapTriggerBase(MapConfiguration* config);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
virtual ~MapTriggerBase();
|
||||
|
||||
/**
|
||||
* Returns the validity for the current description
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* returns an optional dependency on a source name
|
||||
*/
|
||||
virtual std::string getSourceDependency() const;
|
||||
|
||||
/**
|
||||
* Polymorphic comparison method
|
||||
*/
|
||||
virtual bool isEqual(const MapTriggerBase& other) const = 0;
|
||||
|
||||
/**
|
||||
* Check Trigger validity and set validity flag
|
||||
* @retval validity flag
|
||||
**/
|
||||
bool checkValidity();
|
||||
|
||||
/**
|
||||
* Checks the configuration for consistency of a new trigger
|
||||
* @param [in] _name The name of the target
|
||||
* @param [in] _type The type of the target
|
||||
* @retval ERR_INVALID_ARG Reference not found in Configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result checkTriggerReferences() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Polymorphic clone method
|
||||
*/
|
||||
virtual MapTriggerBase* clone() const = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* creates a polymorphic trigger instance from a trigger-dom element
|
||||
* @param [in] oConfig The configuration
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] destination The Trigger object to fill
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
static a_util::result::Result createFromDOM(MapConfiguration* config, const a_util::xml::DOMElement& dom_element,
|
||||
MapTriggerBase*& destination);
|
||||
|
||||
/**
|
||||
* Export trigger to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Change name for source signal
|
||||
**/
|
||||
a_util::result::Result setSourceDependency(const std::string& new_name);
|
||||
|
||||
protected:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapTarget;
|
||||
MapConfiguration* _config;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// implementation of a periodic trigger in the configuration api
|
||||
class MapPeriodicTrigger : public MapTriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
*/
|
||||
MapPeriodicTrigger(MapConfiguration* config);
|
||||
|
||||
/**
|
||||
* Returns the period of the trigger in ms
|
||||
*/
|
||||
double getPeriod() const;
|
||||
|
||||
/**
|
||||
* Set the period
|
||||
* @param [in] period The period as integer
|
||||
* @param [in] unit The unit ("us", "ms" or "s")
|
||||
**/
|
||||
a_util::result::Result setPeriod(const std::string& period,
|
||||
const std::string& unit);
|
||||
|
||||
/**
|
||||
* Polymorphic comparison method (impl. from MapTriggerBase)
|
||||
* @param [in] other The other instance
|
||||
* @returns True if both are equal
|
||||
*/
|
||||
bool isEqual(const MapTriggerBase& other) const;
|
||||
|
||||
protected:
|
||||
// implements MapTriggerBase
|
||||
MapTriggerBase* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* creates a trigger instance from a trigger-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDom(const a_util::xml::DOMElement& dom_element);
|
||||
|
||||
/**
|
||||
* Export trigger to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapTriggerBase;
|
||||
double _period;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// implementation of a signal trigger in the configuration api
|
||||
class MapSignalTrigger : public MapTriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
*/
|
||||
MapSignalTrigger(MapConfiguration* config);
|
||||
|
||||
/**
|
||||
* Overrides MapTriggerBase
|
||||
*/
|
||||
virtual std::string getSourceDependency() const;
|
||||
|
||||
/**
|
||||
* Returns the source signal
|
||||
*/
|
||||
const std::string& getVariable() const;
|
||||
|
||||
/**
|
||||
* Set the source signal
|
||||
* @param [in] signal_name The source signal name
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setVariable(const std::string& signal_name);
|
||||
|
||||
/**
|
||||
* Polymorphic comparison method (impl. from MapTriggerBase)
|
||||
* @param [in] other The other instance
|
||||
* @returns True if both are equal
|
||||
*/
|
||||
bool isEqual(const MapTriggerBase& other) const;
|
||||
|
||||
protected:
|
||||
// implements MapTriggerBase
|
||||
MapTriggerBase* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* creates a trigger instance from a trigger-dom element
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDom(const a_util::xml::DOMElement& dom_element);
|
||||
|
||||
/**
|
||||
* Export trigger to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Set the source signal
|
||||
* @param [in] signal_name The source signal name
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setVariableNoTypeCheck(const std::string& signal_name);
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapTriggerBase;
|
||||
std::string _variable;
|
||||
bool _is_valid;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// implementation of a data trigger in the configuration api
|
||||
class MapDataTrigger : public MapTriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] oConfig The configuration
|
||||
*/
|
||||
MapDataTrigger(MapConfiguration* config);
|
||||
|
||||
/**
|
||||
* Overrides MapTriggerBase
|
||||
*/
|
||||
virtual std::string getSourceDependency() const;
|
||||
|
||||
/**
|
||||
* Returns the variable to compare
|
||||
*/
|
||||
const std::string& getVariable() const;
|
||||
|
||||
/**
|
||||
* Returns the source signal
|
||||
*/
|
||||
const std::string& getSource() const;
|
||||
|
||||
/**
|
||||
* Returns the operator for the comparison
|
||||
*/
|
||||
const std::string& getOperator() const;
|
||||
|
||||
/**
|
||||
* Returns the value to compare to
|
||||
*/
|
||||
double getValue() const;
|
||||
|
||||
/**
|
||||
* Set the comparison
|
||||
* @param [in] source_element_path The path to the element ([SourceSignal].[Element])
|
||||
* @param [in] comp_operator The operator for the comparison
|
||||
* @param [in] value The value to compare to
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval ERR_INVALID_TYPE Definition is inconsistent with ddl
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setComparison(const std::string& source_element_path,
|
||||
const std::string& comp_operator,
|
||||
const std::string& value);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Polymorphic comparison method (impl. from MapTriggerBase)
|
||||
* @param [in] other The other instance
|
||||
* @returns True if both are equal
|
||||
*/
|
||||
bool isEqual(const MapTriggerBase& other) const;
|
||||
|
||||
protected: // implements MapTriggerBase
|
||||
MapTriggerBase* clone() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* creates a trigger instance from a trigger-dom element
|
||||
* @param [in] trigger_element The dom element from which to import
|
||||
* @param [out] lstErrors The error list for debug
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result loadFromDom(const a_util::xml::DOMElement& trigger_element);
|
||||
|
||||
/**
|
||||
* Export trigger to a XML dom element
|
||||
*
|
||||
* @param [in] dom_element The dom element from which to import
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result writeToDOM(a_util::xml::DOMElement& dom_element) const;
|
||||
|
||||
/**
|
||||
* Set the comparison
|
||||
* @param [in] source_element_path The path to the element ([SourceSignal].[Element])
|
||||
* @param [in] comp_operator The operator for the comparison
|
||||
* @param [in] value The value to compare to
|
||||
* @retval ERR_INVALID_ARG Missing attribute
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setComparisonNoTypeCheck(const std::string& source_element_path,
|
||||
const std::string& comp_operator,
|
||||
const std::string& value);
|
||||
|
||||
/**
|
||||
* Set the source
|
||||
* @param [in] source The source signal
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
**/
|
||||
a_util::result::Result setSourceNoTypeCheck(const std::string& source);
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
friend class MapConfiguration;
|
||||
friend class MapTriggerBase;
|
||||
std::string _variable;
|
||||
std::string _source;
|
||||
std::string _operator;
|
||||
double _value;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
/// Public composite types used in the mapping::oo namespace
|
||||
typedef std::vector<MapTriggerBase*> MapTriggerList;
|
||||
|
||||
} // namespace oo
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_MAP_TRIGGER_H
|
Loading…
Add table
Add a link
Reference in a new issue