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
|
135
mapping/ddl_helper.cpp
Normal file
135
mapping/ddl_helper.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* @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 "ddl_helper.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "a_util/strings.h"
|
||||
|
||||
using namespace mapping;
|
||||
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
_MAKE_RESULT(-20, ERR_NOT_FOUND)
|
||||
}
|
||||
|
||||
static a_util::result::Result ParseElementPath(const std::string& strPath,
|
||||
std::vector<std::pair<std::string, int> >& vecPath)
|
||||
{
|
||||
vecPath.clear();
|
||||
|
||||
std::vector<std::string> lstPath = a_util::strings::split(strPath, ".");
|
||||
|
||||
for (std::vector<std::string>::const_iterator it = lstPath.begin(); it != lstPath.end(); ++it)
|
||||
{
|
||||
const std::string& strPathElem = *it;
|
||||
|
||||
std::pair<std::string, int> oPair;
|
||||
size_t idxBegin = strPathElem.find('[');
|
||||
if (idxBegin != std::string::npos)
|
||||
{
|
||||
size_t idxEnd = strPathElem.find(']', idxBegin);
|
||||
if (idxEnd == std::string::npos || idxEnd != strPathElem.size() - 1)
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
oPair.first = strPathElem.substr(0, idxBegin);
|
||||
std::string strSubscript = strPathElem.substr(idxBegin + 1);
|
||||
strSubscript.erase(strSubscript.size() - 1);
|
||||
int nSubscript = a_util::strings::toInt32(strSubscript);
|
||||
if (!a_util::strings::isInt64(strSubscript) || nSubscript < 0)
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
oPair.second = nSubscript;
|
||||
}
|
||||
else
|
||||
{
|
||||
oPair.first = strPathElem;
|
||||
oPair.second = -1;
|
||||
}
|
||||
|
||||
vecPath.push_back(oPair);
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
static const ddl::DDLElement* GetNestedElement(const ddl::DDLElementVec& vecElements,
|
||||
std::vector<std::pair<std::string, int> > vecPath)
|
||||
{
|
||||
std::pair<std::string, int> oPair = vecPath.front();
|
||||
vecPath.erase(vecPath.begin());
|
||||
|
||||
for (ddl::DDLElementItConst it = vecElements.begin(); it != vecElements.end(); ++it)
|
||||
{
|
||||
if ((*it)->getName() == oPair.first)
|
||||
{
|
||||
// check array size
|
||||
if (oPair.second > -1)
|
||||
{
|
||||
if ((*it)->getArraysize() <= (unsigned int)oPair.second)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (vecPath.empty())
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
else
|
||||
{
|
||||
const ddl::DDLComplex* pCmplx =
|
||||
dynamic_cast<const ddl::DDLComplex*>((*it)->getTypeObject());
|
||||
if (pCmplx)
|
||||
{
|
||||
return GetNestedElement(pCmplx->getElements(), vecPath);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
a_util::result::Result DDLHelper::LookupElement(const ddl::DDLComplex& oStruct,
|
||||
const std::string& strPath, const ddl::DDLElement*& pElement, bool& bIsArrayElement)
|
||||
{
|
||||
std::vector<std::pair<std::string, int> > vecPath;
|
||||
if (isFailed(ParseElementPath(strPath, vecPath)))
|
||||
{
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
const ddl::DDLElement* pElem = GetNestedElement(oStruct.getElements(), vecPath);
|
||||
if (pElem)
|
||||
{
|
||||
pElement = pElem;
|
||||
bIsArrayElement = vecPath.back().second > -1;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
return ERR_NOT_FOUND;
|
||||
}
|
88
mapping/ddl_helper.h
Normal file
88
mapping/ddl_helper.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* @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_DDL_HELPER_H
|
||||
#define HEADER_DDL_HELPER_H
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "ddlrepresentation/ddlcomplex.h"
|
||||
#include "ddlrepresentation/ddlelement.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic ignored "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
/// String -> Datatype Enum Map
|
||||
typedef std::map<std::string, uint8_t> TypeMap;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic warning "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
/// Enum for all relevant data types
|
||||
enum DataTypes
|
||||
{
|
||||
e_uint8 = 1,
|
||||
e_uint16,
|
||||
e_uint32,
|
||||
e_uint64,
|
||||
e_int8,
|
||||
e_int16,
|
||||
e_int32,
|
||||
e_int64,
|
||||
e_float32,
|
||||
e_float64,
|
||||
e_bool,
|
||||
e_char,
|
||||
};
|
||||
|
||||
/**
|
||||
* DDLHelper provides common DDL helper functionality needed
|
||||
* by both the mapping configuration and runtime
|
||||
*/
|
||||
class DDLHelper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \c LookupElement finds a DDLElement located inside a DDLComplex
|
||||
* by means of a path string. If the path represents an array element,
|
||||
* the array itself is returned.
|
||||
*
|
||||
* @param [in] ddl_struct The base structure of the path
|
||||
* @param [in] path The path to be looked up
|
||||
* @param [out] element The destination target parameter
|
||||
* @param [out] is_array_element Flag indicating whether the path referenced an array element
|
||||
*
|
||||
* @retval ERR_NOT_FOUND The element was not found or the path is invalid
|
||||
* @retval a_util::result::SUCCESS The path was found and oElement contains the element
|
||||
*/
|
||||
static a_util::result::Result LookupElement(const ddl::DDLComplex& ddl_struct,
|
||||
const std::string& path, const ddl::DDLElement*& element, bool& is_array_element);
|
||||
};
|
||||
|
||||
} // namespace mapping
|
||||
|
||||
#endif // HEADER_DDL_HELPER_H
|
122
mapping/engine/data_trigger.cpp
Normal file
122
mapping/engine/data_trigger.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* @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 "data_trigger.h"
|
||||
|
||||
using namespace mapping::rt;
|
||||
|
||||
DataTrigger::DataTrigger(IMappingEnvironment& oEnv,
|
||||
const std::string& strTriggerName,
|
||||
const std::string& strVariableName,
|
||||
const std::string& strOperator,
|
||||
const double& f64Value) : _env(oEnv),
|
||||
_name(strTriggerName), _variable_name(strVariableName),
|
||||
_value(f64Value), _is_running(false)
|
||||
{
|
||||
if(strOperator == "equal")
|
||||
{
|
||||
_operator = e_equal;
|
||||
}
|
||||
else if(strOperator == "not_equal")
|
||||
{
|
||||
_operator = e_not_equal;
|
||||
}
|
||||
else if(strOperator == "less_than")
|
||||
{
|
||||
_operator = e_less_than;
|
||||
}
|
||||
else if(strOperator == "greater_than")
|
||||
{
|
||||
_operator = e_greater_than;
|
||||
}
|
||||
else if(strOperator == "less_than_equal")
|
||||
{
|
||||
_operator = e_less_than_equal;
|
||||
}
|
||||
else if(strOperator == "greater_than_equal")
|
||||
{
|
||||
_operator = e_greater_than_equal;
|
||||
}
|
||||
}
|
||||
|
||||
DataTrigger::~DataTrigger()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
a_util::result::Result DataTrigger::start()
|
||||
{
|
||||
_is_running = true;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result DataTrigger::stop()
|
||||
{
|
||||
_is_running = false;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
bool DataTrigger::compare(double f64Val)
|
||||
{
|
||||
switch(_operator)
|
||||
{
|
||||
case e_equal:
|
||||
return f64Val == _value;
|
||||
case e_not_equal:
|
||||
return f64Val != _value;
|
||||
case e_less_than:
|
||||
return f64Val < _value;
|
||||
case e_greater_than:
|
||||
return f64Val > _value;
|
||||
case e_less_than_equal:
|
||||
return f64Val <= _value;
|
||||
case e_greater_than_equal:
|
||||
return f64Val >= _value;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
a_util::result::Result DataTrigger::transmit()
|
||||
{
|
||||
if(_is_running)
|
||||
{
|
||||
for(TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it)
|
||||
{
|
||||
const void* pBuffer = NULL;
|
||||
size_t szBuffer = 0;
|
||||
(*it)->aquireReadLock();
|
||||
(*it)->updateTriggerFunctionValues();
|
||||
if (isOk((*it)->getBufferRef(pBuffer, szBuffer)))
|
||||
{
|
||||
_env.sendTarget((handle_t)*it, pBuffer, szBuffer, 0);
|
||||
}
|
||||
(*it)->releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& DataTrigger::getVariable() const
|
||||
{
|
||||
return _variable_name;
|
||||
}
|
109
mapping/engine/data_trigger.h
Normal file
109
mapping/engine/data_trigger.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* @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 DATA_TRIGGER_HEADER
|
||||
#define DATA_TRIGGER_HEADER
|
||||
|
||||
#include "trigger.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
enum Operator
|
||||
{
|
||||
e_equal = 1,
|
||||
e_not_equal,
|
||||
e_less_than,
|
||||
e_greater_than,
|
||||
e_less_than_equal,
|
||||
e_greater_than_equal
|
||||
};
|
||||
|
||||
/// DataTrigger implements a concrete periodic trigger in the runtime
|
||||
class DataTrigger : public TriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] env The mapping environment
|
||||
* @param [in] trigger_name The name of the trigger
|
||||
* @param [in] fPeriod The period of the trigger
|
||||
*/
|
||||
DataTrigger(IMappingEnvironment& env,
|
||||
const std::string& trigger_name,
|
||||
const std::string& variable_name,
|
||||
const std::string& comp_operator,
|
||||
const double& value);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~DataTrigger();
|
||||
|
||||
/**
|
||||
* Method to start trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
a_util::result::Result start();
|
||||
|
||||
/**
|
||||
* Method to stop trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result stop();
|
||||
|
||||
/**
|
||||
* Method to transmit targets
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result transmit();
|
||||
|
||||
/**
|
||||
* Method to make the comparison
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
bool compare(double value);
|
||||
|
||||
/**
|
||||
* Returns the period of the trigger in ms
|
||||
*/
|
||||
const std::string& getVariable() const;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
IMappingEnvironment& _env;
|
||||
std::string _name;
|
||||
std::string _variable_name;
|
||||
Operator _operator;
|
||||
double _value;
|
||||
bool _is_running;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //DATA_TRIGGER_HEADER
|
445
mapping/engine/element.cpp
Normal file
445
mapping/engine/element.cpp
Normal file
|
@ -0,0 +1,445 @@
|
|||
/**
|
||||
* @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 "element.h"
|
||||
|
||||
using namespace mapping;
|
||||
using namespace mapping::rt;
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-3, ERR_UNEXPECTED)
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-42, ERR_INVALID_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper method that sets a casted value in the coder
|
||||
template <typename T>
|
||||
static void SetCastedValue(void* pDestination, unsigned int nArrayIndex, T* pData,
|
||||
uint32_t type32)
|
||||
{
|
||||
switch (type32)
|
||||
{
|
||||
case e_uint8:
|
||||
{
|
||||
uint8_t ui8Temp = static_cast<uint8_t>(*pData);
|
||||
a_util::memory::copy((uint8_t*)pDestination + nArrayIndex, sizeof(uint8_t), &ui8Temp, sizeof(uint8_t));
|
||||
}
|
||||
break;
|
||||
case e_uint16:
|
||||
{
|
||||
uint16_t ui16Temp = static_cast<uint16_t>(*pData);
|
||||
a_util::memory::copy((uint16_t*)pDestination + nArrayIndex, sizeof(uint16_t), &ui16Temp, sizeof(uint16_t));
|
||||
}
|
||||
break;
|
||||
case e_uint32:
|
||||
{
|
||||
uint32_t ui32Temp = static_cast<uint32_t>(*pData);
|
||||
a_util::memory::copy((uint32_t*)pDestination + nArrayIndex, sizeof(uint32_t), &ui32Temp, sizeof(uint32_t));
|
||||
}
|
||||
break;
|
||||
case e_uint64:
|
||||
{
|
||||
uint64_t ui64Temp = static_cast<uint64_t>(*pData);
|
||||
a_util::memory::copy((uint64_t*)pDestination + nArrayIndex, sizeof(uint64_t), &ui64Temp, sizeof(uint64_t));
|
||||
}
|
||||
break;
|
||||
case e_int8:
|
||||
{
|
||||
int8_t i8Temp = static_cast<int8_t>(*pData);
|
||||
a_util::memory::copy((int8_t*)pDestination + nArrayIndex, sizeof(int8_t), &i8Temp, sizeof(int8_t));
|
||||
}
|
||||
break;
|
||||
case e_int16:
|
||||
{
|
||||
int16_t i16Temp = static_cast<int16_t>(*pData);
|
||||
a_util::memory::copy((int16_t*)pDestination + nArrayIndex, sizeof(int16_t), &i16Temp, sizeof(int16_t));
|
||||
}
|
||||
break;
|
||||
case e_int32:
|
||||
{
|
||||
int32_t i32Temp = static_cast<int32_t>(*pData);
|
||||
a_util::memory::copy((int32_t*)pDestination + nArrayIndex, sizeof(int32_t), &i32Temp, sizeof(int32_t));
|
||||
}
|
||||
break;
|
||||
case e_int64:
|
||||
{
|
||||
int64_t i64Temp = static_cast<int64_t>(*pData);
|
||||
a_util::memory::copy((int64_t*)pDestination + nArrayIndex, sizeof(int64_t), &i64Temp, sizeof(int64_t));
|
||||
}
|
||||
break;
|
||||
case e_float32:
|
||||
{
|
||||
float f32Temp = static_cast<float>(*pData);
|
||||
a_util::memory::copy((float*)pDestination + nArrayIndex, sizeof(float), &f32Temp, sizeof(float));
|
||||
}
|
||||
break;
|
||||
case e_float64:
|
||||
{
|
||||
double f64Temp = static_cast<double>(*pData);
|
||||
a_util::memory::copy((double*)pDestination + nArrayIndex, sizeof(double), &f64Temp, sizeof(double));
|
||||
}
|
||||
break;
|
||||
case e_bool:
|
||||
{
|
||||
bool bTemp = *pData != 0 ? true : false;
|
||||
a_util::memory::copy((bool*)pDestination + nArrayIndex, sizeof(bool), &bTemp, sizeof(bool));
|
||||
}
|
||||
break;
|
||||
case e_char:
|
||||
{
|
||||
char cTemp = static_cast<char>(*pData);
|
||||
a_util::memory::copy((char*)pDestination + nArrayIndex, sizeof(char), &cTemp, sizeof(char));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void SetCastedValue<bool>(void* pDestination, unsigned int nArrayIndex, bool* pData,
|
||||
uint32_t type32)
|
||||
{
|
||||
int nBool = *pData ? 1 : 0;
|
||||
switch (type32)
|
||||
{
|
||||
case e_uint8:
|
||||
{
|
||||
uint8_t ui8Temp = static_cast<uint8_t>(nBool);
|
||||
a_util::memory::copy((uint8_t*)pDestination + nArrayIndex, sizeof(uint8_t), &ui8Temp, sizeof(uint8_t));
|
||||
}
|
||||
break;
|
||||
case e_uint16:
|
||||
{
|
||||
uint16_t ui16Temp = static_cast<uint16_t>(nBool);
|
||||
a_util::memory::copy((uint16_t*)pDestination + nArrayIndex, sizeof(uint16_t), &ui16Temp, sizeof(uint16_t));
|
||||
}
|
||||
break;
|
||||
case e_uint32:
|
||||
{
|
||||
uint32_t ui32Temp = static_cast<uint32_t>(nBool);
|
||||
a_util::memory::copy((uint32_t*)pDestination + nArrayIndex, sizeof(uint32_t), &ui32Temp, sizeof(uint32_t));
|
||||
}
|
||||
break;
|
||||
case e_uint64:
|
||||
{
|
||||
uint64_t ui64Temp = static_cast<uint64_t>(nBool);
|
||||
a_util::memory::copy((uint64_t*)pDestination + nArrayIndex, sizeof(uint64_t), &ui64Temp, sizeof(uint64_t));
|
||||
}
|
||||
break;
|
||||
case e_int8:
|
||||
{
|
||||
int8_t i8Temp = static_cast<int8_t>(nBool);
|
||||
a_util::memory::copy((int8_t*)pDestination + nArrayIndex, sizeof(int8_t), &i8Temp, sizeof(int8_t));
|
||||
}
|
||||
break;
|
||||
case e_int16:
|
||||
{
|
||||
int16_t i16Temp = static_cast<int16_t>(nBool);
|
||||
a_util::memory::copy((int16_t*)pDestination + nArrayIndex, sizeof(int16_t), &i16Temp, sizeof(int16_t));
|
||||
}
|
||||
break;
|
||||
case e_int32:
|
||||
{
|
||||
int32_t i32Temp = static_cast<int32_t>(nBool);
|
||||
a_util::memory::copy((int32_t*)pDestination + nArrayIndex, sizeof(int32_t), &i32Temp, sizeof(int32_t));
|
||||
}
|
||||
break;
|
||||
case e_int64:
|
||||
{
|
||||
int64_t i64Temp = static_cast<int64_t>(nBool);
|
||||
a_util::memory::copy((int64_t*)pDestination + nArrayIndex, sizeof(int64_t), &i64Temp, sizeof(int64_t));
|
||||
}
|
||||
break;
|
||||
case e_float32:
|
||||
{
|
||||
float f32Temp = static_cast<float>(nBool);
|
||||
a_util::memory::copy((float*)pDestination + nArrayIndex, sizeof(float), &f32Temp, sizeof(float));
|
||||
}
|
||||
break;
|
||||
case e_float64:
|
||||
{
|
||||
double f64Temp = static_cast<double>(nBool);
|
||||
a_util::memory::copy((double*)pDestination + nArrayIndex, sizeof(double), &f64Temp, sizeof(double));
|
||||
}
|
||||
break;
|
||||
case e_bool:
|
||||
a_util::memory::copy((bool*)pDestination + nArrayIndex, sizeof(bool), pData, sizeof(bool));
|
||||
break;
|
||||
case e_char:
|
||||
{
|
||||
char cTemp = static_cast<char>(nBool);
|
||||
a_util::memory::copy((char*)pDestination + nArrayIndex, sizeof(char), &cTemp, sizeof(char));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline void TransformAndSetValueImpl(const void* pData, void* pDestination,
|
||||
unsigned int nArraySize, const oo::MapTransformationBase* pTrans, uint32_t type32)
|
||||
{
|
||||
assert(pTrans);
|
||||
assert(pData);
|
||||
for(unsigned int i = 0; i < nArraySize; i++)
|
||||
{
|
||||
double fValue = pTrans->evaluate(static_cast<double>(*((T*)pData + i)));
|
||||
SetCastedValue(pDestination, i, &fValue, type32);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline void SetValueImpl(const void* pData, void* pDestination, unsigned int nArraySize,
|
||||
uint32_t type32)
|
||||
{
|
||||
assert(pData);
|
||||
for(unsigned int i = 0; i < nArraySize; i++)
|
||||
{
|
||||
SetCastedValue<T>(pDestination, i, (T*)pData + i, type32);
|
||||
}
|
||||
}
|
||||
|
||||
TargetElement::TargetElement(Target* pTarget) :
|
||||
_target(pTarget), _element_ptr(NULL), _type_int(0),
|
||||
_type(NULL), _struct(NULL),
|
||||
_array_size(0), _transformation(NULL)
|
||||
{
|
||||
_type_map["tUInt8"] = e_uint8;
|
||||
_type_map["tUInt16"] = e_uint16;
|
||||
_type_map["tUInt32"] = e_uint32;
|
||||
_type_map["tUInt64"] = e_uint64;
|
||||
_type_map["tInt8"] = e_int8;
|
||||
_type_map["tInt16"] = e_int16;
|
||||
_type_map["tInt32"] = e_int32;
|
||||
_type_map["tInt64"] = e_int64;
|
||||
_type_map["tFloat32"] = e_float32;
|
||||
_type_map["tFloat64"] = e_float64;
|
||||
_type_map["tBool"] = e_bool;
|
||||
_type_map["tChar"] = e_char;
|
||||
}
|
||||
|
||||
TargetElement::~TargetElement()
|
||||
{
|
||||
delete _transformation;
|
||||
_transformation = NULL;
|
||||
}
|
||||
|
||||
a_util::result::Result TargetElement::create(void* pElementPtr, ddl::IDDLDataType* pDataType,
|
||||
const unsigned int nArraySize, const std::string& strElementName)
|
||||
{
|
||||
_element_ptr = pElementPtr;
|
||||
_array_size = nArraySize;
|
||||
_element_name = strElementName;
|
||||
|
||||
_type = dynamic_cast<ddl::DDLDataType*>(pDataType);
|
||||
_struct = dynamic_cast<ddl::DDLComplex*>(pDataType);
|
||||
_enum = dynamic_cast<ddl::DDLEnum*>(pDataType);
|
||||
|
||||
if (_enum)
|
||||
{
|
||||
_type = dynamic_cast<ddl::DDLDataType*>(_enum->getTypeObject());
|
||||
if (!_type)
|
||||
{
|
||||
return ERR_UNEXPECTED;
|
||||
}
|
||||
|
||||
_enum = NULL;
|
||||
}
|
||||
|
||||
if(_type)
|
||||
{
|
||||
TypeMap::const_iterator it = _type_map.find(_type->getName());
|
||||
if(it != _type_map.end())
|
||||
{
|
||||
_type_int = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result TargetElement::setTransformation(const oo::MapTransformationBase* pTransformation)
|
||||
{
|
||||
if (_transformation)
|
||||
{
|
||||
delete _transformation;
|
||||
_transformation = NULL;
|
||||
}
|
||||
|
||||
if (pTransformation)
|
||||
{
|
||||
_transformation = pTransformation->clone();
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result TargetElement::setValue(const void* pData, uint32_t ui32SrcType, size_t szMem)
|
||||
{
|
||||
// Scalars (and enums converted to scalars)
|
||||
if(_type)
|
||||
{
|
||||
if(_transformation)
|
||||
{
|
||||
switch(ui32SrcType)
|
||||
{
|
||||
case e_uint8:
|
||||
TransformAndSetValueImpl<uint8_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_uint16:
|
||||
TransformAndSetValueImpl<uint16_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_uint32:
|
||||
TransformAndSetValueImpl<uint32_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_uint64:
|
||||
TransformAndSetValueImpl<uint64_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_int8:
|
||||
TransformAndSetValueImpl<int8_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_int16:
|
||||
TransformAndSetValueImpl<int16_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_int32:
|
||||
TransformAndSetValueImpl<int32_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_int64:
|
||||
TransformAndSetValueImpl<int64_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_float32:
|
||||
TransformAndSetValueImpl<float>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_float64:
|
||||
TransformAndSetValueImpl<double>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_bool:
|
||||
TransformAndSetValueImpl<uint8_t>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
case e_char:
|
||||
TransformAndSetValueImpl<char>(pData, _element_ptr, _array_size, _transformation, _type_int);
|
||||
break;
|
||||
default:
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
}
|
||||
else if(_type_int == ui32SrcType)
|
||||
{
|
||||
// Source and target have the same type
|
||||
a_util::memory::copy(_element_ptr, szMem, pData, szMem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Source and target have different types
|
||||
switch(ui32SrcType)
|
||||
{
|
||||
case e_uint8:
|
||||
SetValueImpl<uint8_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_uint16:
|
||||
SetValueImpl<uint16_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_uint32:
|
||||
SetValueImpl<uint32_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_uint64:
|
||||
SetValueImpl<uint64_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_int8:
|
||||
SetValueImpl<int8_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_int16:
|
||||
SetValueImpl<int16_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_int32:
|
||||
SetValueImpl<int32_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_int64:
|
||||
SetValueImpl<int64_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_float32:
|
||||
SetValueImpl<float>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_float64:
|
||||
SetValueImpl<double>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_bool:
|
||||
SetValueImpl<uint8_t>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
case e_char:
|
||||
SetValueImpl<char>(pData, _element_ptr, _array_size, _type_int);
|
||||
break;
|
||||
default:
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(_struct) // Structures
|
||||
{
|
||||
// Transformations are not allowed
|
||||
a_util::memory::copy(_element_ptr, szMem, pData, szMem);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
Target* TargetElement::getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
a_util::result::Result TargetElement::setDefaultValue(const std::string& strDefault)
|
||||
{
|
||||
// Scalars and arrays
|
||||
if(_type)
|
||||
{
|
||||
double fVal = 0;
|
||||
if(!strDefault.empty() && a_util::strings::isDouble(strDefault))
|
||||
{
|
||||
fVal = a_util::strings::toDouble(strDefault);
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < _array_size; i++)
|
||||
{
|
||||
SetCastedValue<double>(_element_ptr, i, &fVal, _type_int);
|
||||
}
|
||||
}
|
||||
|
||||
//Structures
|
||||
if(_struct)
|
||||
{
|
||||
//TODO: What is default value for a structure?
|
||||
return ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
116
mapping/engine/element.h
Normal file
116
mapping/engine/element.h
Normal file
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
* @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 ELEMENT_HEADER
|
||||
#define ELEMENT_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "ddlrepresentation/ddldatatype_intf.h"
|
||||
#include "ddlrepresentation/ddldatatype.h"
|
||||
#include "ddlrepresentation/ddlcomplex.h"
|
||||
#include "ddlrepresentation/ddlenum.h"
|
||||
|
||||
#include "mapping/configuration/map_transformation.h"
|
||||
#include "mapping/ddl_helper.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
class Target;
|
||||
|
||||
/// TargetElement represents a single signal element in the target
|
||||
class TargetElement
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param[in] target The target containing this element
|
||||
*/
|
||||
TargetElement(Target* target);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~TargetElement();
|
||||
|
||||
/**
|
||||
* Creation method to initialize the object
|
||||
* @param [in] element_ptr The Pointer referencing the element in target buffer
|
||||
* @param [in] pDatatType The element datatype
|
||||
* @param [in] array_size The array size of the element
|
||||
* @param [in] element_name The name of the element in Assignment, for debug only
|
||||
* @returns Standard result
|
||||
*/
|
||||
a_util::result::Result create(void* element_ptr, ddl::IDDLDataType* data_type,
|
||||
const unsigned int array_size, const std::string& element_name);
|
||||
|
||||
/**
|
||||
* Setter for transformation
|
||||
* Write constant from Mapping or default value from DDL or 0
|
||||
* @param [in] transformation The transformation to apply for to element
|
||||
* @returns Standard result
|
||||
*/
|
||||
a_util::result::Result setTransformation(const oo::MapTransformationBase* transformation);
|
||||
|
||||
/**
|
||||
* Method to give a default value to the element
|
||||
* @param [in] default_value The default value as a string
|
||||
* @returns Standard result
|
||||
*/
|
||||
a_util::result::Result setDefaultValue(const std::string& default_value);
|
||||
|
||||
/**
|
||||
* Setter value to the element
|
||||
* @param [in] data The pointer referencing the source buffer
|
||||
* @param [in] src_type The datatype of the source element
|
||||
* @param [in] mem_size The size of the source buffer
|
||||
* @returns Standard result
|
||||
*/
|
||||
a_util::result::Result setValue(const void* data, uint32_t src_type, size_t mem_size);
|
||||
|
||||
/**
|
||||
* Getter for the parent target reference
|
||||
* @returns The target
|
||||
*/
|
||||
Target* getTarget();
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
Target* _target;
|
||||
void* _element_ptr;
|
||||
TypeMap _type_map;
|
||||
uint32_t _type_int;
|
||||
ddl::DDLDataType* _type;
|
||||
ddl::DDLComplex* _struct;
|
||||
ddl::DDLEnum* _enum;
|
||||
unsigned int _array_size;
|
||||
const oo::MapTransformationBase* _transformation;
|
||||
// For Debug only
|
||||
std::string _element_name;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
typedef std::vector<TargetElement*> TargetElementList;
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //ELEMENT_HEADER
|
423
mapping/engine/mapping_engine.cpp
Normal file
423
mapping/engine/mapping_engine.cpp
Normal file
|
@ -0,0 +1,423 @@
|
|||
/**
|
||||
* @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 "mapping_engine.h"
|
||||
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-4, ERR_POINTER)
|
||||
_MAKE_RESULT(-5, ERR_INVALID_ARG)
|
||||
_MAKE_RESULT(-16, ERR_NOT_IMPL)
|
||||
_MAKE_RESULT(-40, ERR_INVALID_STATE)
|
||||
_MAKE_RESULT(-42, ERR_INVALID_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping;
|
||||
using namespace mapping::rt;
|
||||
|
||||
MappingEngine::MappingEngine(IMappingEnvironment& oEnv):
|
||||
_env(oEnv), _map_config(NULL), _running(false)
|
||||
{
|
||||
}
|
||||
|
||||
MappingEngine::~MappingEngine()
|
||||
{
|
||||
stop();
|
||||
unmapAll();
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::setConfiguration(const oo::MapConfiguration& oConfig)
|
||||
{
|
||||
_map_config = oConfig;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::Map(const std::string& strTargetName, handle_t& hMappedSignal)
|
||||
{
|
||||
a_util::result::Result nRes = a_util::result::SUCCESS;
|
||||
|
||||
// If the target is already in the List, return invalid error
|
||||
if(_targets.find(strTargetName) != _targets.end())
|
||||
{
|
||||
nRes = ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
const oo::MapTarget* pMapTarget = NULL;
|
||||
std::string strTargetDesc;
|
||||
if (isOk(nRes))
|
||||
{
|
||||
pMapTarget = _map_config.getTarget(strTargetName);
|
||||
// If the target is not found in the mapping configuration, return invalid error
|
||||
if(pMapTarget == NULL)
|
||||
{
|
||||
nRes = ERR_INVALID_ARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* desc = 0;
|
||||
if (isFailed(_env.resolveType(pMapTarget->getType().c_str(), desc)))
|
||||
{
|
||||
nRes = ERR_INVALID_TYPE;
|
||||
}
|
||||
// save a copy, never know how long the environment holds the memory
|
||||
strTargetDesc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
// Backup storage for error cleanup
|
||||
SourceMap oSourceCleanup;
|
||||
TriggerMap oTriggerCleanup;
|
||||
|
||||
if (isOk(nRes))
|
||||
{
|
||||
// Create sources
|
||||
const oo::MapSourceNameList& lstSources = pMapTarget->getReferencedSources();
|
||||
for (oo::MapSourceNameList::const_iterator it = lstSources.begin();
|
||||
it != lstSources.end(); ++it)
|
||||
{
|
||||
const oo::MapSource* pMapSource = _map_config.getSource(*it);
|
||||
if (_sources.find(pMapSource->getName()) == _sources.end())
|
||||
{
|
||||
const char* strSourceDesc = 0;
|
||||
nRes = _env.resolveType(pMapSource->getType().c_str(), strSourceDesc);
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Source* pSrc = new Source(_env);
|
||||
nRes = pSrc->create(*pMapSource, strSourceDesc);
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
delete pSrc;
|
||||
break;
|
||||
}
|
||||
|
||||
_sources[pMapSource->getName()] = pSrc;
|
||||
oSourceCleanup[pMapSource->getName()] = pSrc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Target* pTarget = NULL;
|
||||
if (isOk(nRes))
|
||||
{
|
||||
// Create Target
|
||||
pTarget = new Target(_env);
|
||||
nRes = pTarget->create(_map_config, *pMapTarget, strTargetDesc, _sources);
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
delete pTarget;
|
||||
pTarget = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
_targets[strTargetName] = pTarget;
|
||||
}
|
||||
}
|
||||
|
||||
if (isOk(nRes))
|
||||
{
|
||||
//Create Triggers
|
||||
const oo::MapTriggerList& oTriggerList = pMapTarget->getTriggerList();
|
||||
for(oo::MapTriggerList::const_iterator it = oTriggerList.begin();
|
||||
it != oTriggerList.end(); it++)
|
||||
{
|
||||
const oo::MapPeriodicTrigger* pMapPTrigger =
|
||||
dynamic_cast<const oo::MapPeriodicTrigger*>(*it);
|
||||
const oo::MapSignalTrigger* pMapSigTrigger =
|
||||
dynamic_cast<const oo::MapSignalTrigger*>(*it);
|
||||
const oo::MapDataTrigger* pMapDataTrigger =
|
||||
dynamic_cast<const oo::MapDataTrigger*>(*it);
|
||||
|
||||
if(!pMapPTrigger && !pMapSigTrigger && !pMapDataTrigger)
|
||||
{
|
||||
nRes = ERR_NOT_IMPL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pMapPTrigger)
|
||||
{
|
||||
std::string strTrigName;
|
||||
if(pMapPTrigger->getPeriod() == 0)
|
||||
{
|
||||
strTrigName = "ini";
|
||||
}
|
||||
else
|
||||
{
|
||||
strTrigName = a_util::strings::toString(pMapPTrigger->getPeriod()) + "ms";
|
||||
}
|
||||
|
||||
if(_triggers.find(strTrigName) == _triggers.end())
|
||||
{
|
||||
PeriodicTrigger* pTrigger = new PeriodicTrigger(_env, strTrigName,
|
||||
pMapPTrigger->getPeriod());
|
||||
nRes = pTrigger->create();
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
delete pTrigger;
|
||||
break;
|
||||
}
|
||||
|
||||
_triggers[strTrigName] = pTrigger;
|
||||
oTriggerCleanup[strTrigName] = pTrigger;
|
||||
}
|
||||
|
||||
_triggers[strTrigName]->addTarget(pTarget);
|
||||
}
|
||||
|
||||
if (pMapSigTrigger)
|
||||
{
|
||||
std::string strSourceName = pMapSigTrigger->getVariable();
|
||||
|
||||
TriggerMap::iterator iter = _triggers.find(strSourceName);
|
||||
if(iter == _triggers.end())
|
||||
{
|
||||
SignalTrigger* pTrigger = new SignalTrigger(_env, strSourceName);
|
||||
std::pair<TriggerMap::iterator, bool> oNewElem =
|
||||
_triggers.insert(std::make_pair(strSourceName, pTrigger));
|
||||
iter = oNewElem.first;
|
||||
|
||||
oTriggerCleanup[strSourceName] = pTrigger;
|
||||
}
|
||||
|
||||
iter->second->addTarget(pTarget);
|
||||
_sources[strSourceName]->addTrigger(_map_config, iter->second);
|
||||
}
|
||||
|
||||
if (pMapDataTrigger)
|
||||
{
|
||||
std::string name = pMapDataTrigger->getSource() + "." + pMapDataTrigger->getVariable()
|
||||
+ pMapDataTrigger->getOperator();
|
||||
name.append(a_util::strings::format("%f", pMapDataTrigger->getValue()));
|
||||
|
||||
TriggerMap::iterator iter = _triggers.find(name);
|
||||
if(_triggers.find(name) == _triggers.end())
|
||||
{
|
||||
DataTrigger* pTrigger = new DataTrigger(_env, name,
|
||||
pMapDataTrigger->getVariable(), pMapDataTrigger->getOperator(),
|
||||
pMapDataTrigger->getValue());
|
||||
std::pair<TriggerMap::iterator, bool> oNewElem =
|
||||
_triggers.insert(std::make_pair(name, pTrigger));
|
||||
iter = oNewElem.first;
|
||||
|
||||
oTriggerCleanup[name] = pTrigger;
|
||||
}
|
||||
|
||||
iter->second->addTarget(pTarget);
|
||||
_sources[pMapDataTrigger->getSource()]->addTrigger(_map_config, iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup on error
|
||||
if (isFailed(nRes))
|
||||
{
|
||||
for (SourceMap::iterator it = oSourceCleanup.begin();
|
||||
it != oSourceCleanup.end(); ++it)
|
||||
{
|
||||
_sources.erase(it->first);
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
for (TriggerMap::iterator it = _triggers.begin();
|
||||
it != _triggers.end(); ++it)
|
||||
{
|
||||
it->second->removeTarget(pTarget);
|
||||
}
|
||||
|
||||
for (TriggerMap::iterator it = oTriggerCleanup.begin();
|
||||
it != oTriggerCleanup.end(); ++it)
|
||||
{
|
||||
_triggers.erase(it->first);
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(isOk(nRes))
|
||||
{
|
||||
hMappedSignal = reinterpret_cast<handle_t>(pTarget);
|
||||
_env.targetMapped(strTargetName.c_str(), pTarget->getType().c_str(), hMappedSignal, pTarget->getSize());
|
||||
}
|
||||
|
||||
return nRes;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::reset()
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
// Reset the target buffers
|
||||
for(TargetMap::iterator it = _targets.begin(); it != _targets.end(); it++)
|
||||
{
|
||||
RETURN_IF_FAILED(it->second->reset(_map_config));
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::start()
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
_running = true;
|
||||
|
||||
// start the triggers in order to send targets
|
||||
for(TriggerMap::iterator it = _triggers.begin(); it != _triggers.end(); it++)
|
||||
{
|
||||
it->second->start();
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
bool MappingEngine::hasTriggers(handle_t mapped_signal) const
|
||||
{
|
||||
Target* target_signal = reinterpret_cast<Target*>(mapped_signal);
|
||||
if (!target_signal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool has_trigger = false;
|
||||
for (const auto& trigga : _triggers)
|
||||
{
|
||||
if (has_trigger)
|
||||
{
|
||||
break;
|
||||
}
|
||||
const auto& target_list = trigga.second->getTargetList();
|
||||
for (const auto& target : target_list)
|
||||
{
|
||||
if (target == target_signal)
|
||||
{
|
||||
has_trigger = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return has_trigger;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::stop()
|
||||
{
|
||||
if (!_running)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
_running = false;
|
||||
|
||||
// stop the triggers in order to send targets
|
||||
for(TriggerMap::iterator it = _triggers.begin(); it != _triggers.end(); it++)
|
||||
{
|
||||
it->second->stop();
|
||||
}
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::unmap(handle_t hMappedSignal)
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
Target* pTarget = reinterpret_cast<Target*>(hMappedSignal);
|
||||
if (!pTarget) { return ERR_POINTER; }
|
||||
|
||||
std::vector<TriggerMap::iterator> vecEraseTrig;
|
||||
for(TriggerMap::iterator it = _triggers.begin(); it != _triggers.end(); ++it)
|
||||
{
|
||||
it->second->removeTarget(pTarget);
|
||||
if (it->second->getTargetList().empty())
|
||||
{
|
||||
delete it->second;
|
||||
vecEraseTrig.push_back(it);
|
||||
}
|
||||
}
|
||||
for (std::vector<TriggerMap::iterator>::iterator it = vecEraseTrig.begin();
|
||||
it != vecEraseTrig.end(); ++it)
|
||||
{
|
||||
_triggers.erase(*it);
|
||||
}
|
||||
|
||||
std::vector<SourceMap::iterator> vecEraseSrc;
|
||||
for(SourceMap::iterator it = _sources.begin(); it != _sources.end(); ++it)
|
||||
{
|
||||
it->second->removeAssignmentsFor(pTarget);
|
||||
if (it->second->getAssigmentList().empty())
|
||||
{
|
||||
delete it->second;
|
||||
vecEraseSrc.push_back(it);
|
||||
}
|
||||
}
|
||||
for (std::vector<SourceMap::iterator>::iterator it = vecEraseSrc.begin();
|
||||
it != vecEraseSrc.end(); ++it)
|
||||
{
|
||||
_sources.erase(*it);
|
||||
}
|
||||
|
||||
_env.targetUnmapped(pTarget->getName().c_str(), hMappedSignal);
|
||||
_targets.erase(pTarget->getName());
|
||||
delete pTarget;
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::unmapAll()
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
while (!_targets.empty())
|
||||
{
|
||||
unmap(reinterpret_cast<handle_t>(_targets.begin()->second));
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result MappingEngine::getCurrentData(handle_t hMappedSignal,
|
||||
void* pTargetBuffer, size_t szTargetBuffer) const
|
||||
{
|
||||
Target* pTarget = reinterpret_cast<Target*>(hMappedSignal);
|
||||
if (!pTarget) { return ERR_POINTER; }
|
||||
if (!pTargetBuffer) { return ERR_POINTER; }
|
||||
|
||||
return pTarget->getCurrentBuffer(pTargetBuffer, szTargetBuffer);
|
||||
}
|
||||
|
||||
// empty definitions of mapping environment destruktors
|
||||
ISignalListener::~ISignalListener() {}
|
||||
IPeriodicListener::~IPeriodicListener() {}
|
||||
IMappingEnvironment::~IMappingEnvironment() {}
|
162
mapping/engine/mapping_engine.h
Normal file
162
mapping/engine/mapping_engine.h
Normal file
|
@ -0,0 +1,162 @@
|
|||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
/*! Mapping Engine
|
||||
*
|
||||
* \section intro_sec Introduction
|
||||
*
|
||||
* This is the Mapping Engine documentation.
|
||||
*/
|
||||
|
||||
#ifndef MAPPINGENGINE_HEADER
|
||||
#define MAPPINGENGINE_HEADER
|
||||
|
||||
#include "mapping/configuration/map_configuration.h"
|
||||
|
||||
#include "mapping_environment_intf.h"
|
||||
#include "element.h"
|
||||
#include "source.h"
|
||||
#include "target.h"
|
||||
#include "trigger.h"
|
||||
#include "periodic_trigger.h"
|
||||
#include "data_trigger.h"
|
||||
#include "signal_trigger.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
class MappingEngine
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param[in] env - Mapping environment, used as interface
|
||||
*/
|
||||
MappingEngine(IMappingEnvironment& env);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~MappingEngine();
|
||||
|
||||
/**
|
||||
* Setter for the current mapping configuration
|
||||
* @param[in] config - The Configuration instance
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result setConfiguration(const oo::MapConfiguration& config);
|
||||
|
||||
/**
|
||||
* Method to instanciate or expand the mapping structure for one particular target
|
||||
* @param [in] target_name The target name
|
||||
* @param [out] mapped_signal - Destination parameter for the signal handle
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_INVALID_ARG Error target already mapped or not found in mapping configuration
|
||||
* @retval ERR_FAILED Error during creation of the mapping
|
||||
*/
|
||||
a_util::result::Result Map(const std::string& target_name, handle_t& mapped_signal);
|
||||
|
||||
/**
|
||||
* Method to reset target buffers
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
a_util::result::Result reset();
|
||||
|
||||
/**
|
||||
* Method to start mapping
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
a_util::result::Result start();
|
||||
|
||||
/**
|
||||
* Method to stop mapping
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result stop();
|
||||
|
||||
/**
|
||||
* Method to remove a target from the existing mapping structure
|
||||
* @param [in] mapped_signal - Target handle
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_INVALID_ARG Error target not found in mapping structure
|
||||
* @retval ERR_FAILED Error during removal
|
||||
*/
|
||||
a_util::result::Result unmap(handle_t mapped_signal);
|
||||
|
||||
/**
|
||||
* Method to know if signal has triggers or not
|
||||
*
|
||||
* @param [in] mapped_signal The target handle
|
||||
* @retval true Signal has triggers
|
||||
* @retval false Signal has no triggers
|
||||
*/
|
||||
bool hasTriggers(handle_t mapped_signal) const;
|
||||
|
||||
/**
|
||||
* Method to send current data
|
||||
*
|
||||
* @param [in] mapped_signal The target handle
|
||||
* @param [in] target_buffer The pointer referencing the target buffer
|
||||
* @param [in] target_buffer_size The size of the target buffer
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_INVALID_ARG Invalid target handle or target buffer is NULL
|
||||
* @retval ERR_MEMORY Target buffer not large enough
|
||||
*/
|
||||
a_util::result::Result getCurrentData(handle_t mapped_signal, void* target_buffer, size_t target_buffer_size) const;
|
||||
|
||||
/**
|
||||
* Method to reinitialize the existing mapping structure
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during reinitialization
|
||||
*/
|
||||
a_util::result::Result unmapAll();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Method to give an initial value to all targets
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during initialization
|
||||
*/
|
||||
a_util::result::Result initializeModel();
|
||||
|
||||
private:
|
||||
IMappingEnvironment& _env;
|
||||
bool _running;
|
||||
|
||||
oo::MapConfiguration _map_config;
|
||||
TargetMap _targets;
|
||||
SourceMap _sources;
|
||||
TriggerMap _triggers;
|
||||
};
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //MAPPINGENGINE_HEADER
|
167
mapping/engine/mapping_environment_intf.h
Normal file
167
mapping/engine/mapping_environment_intf.h
Normal file
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @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 MAPPINGENVIRONMENT_HEADER
|
||||
#define MAPPINGENVIRONMENT_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
/// Signal listener interface class
|
||||
class ISignalListener
|
||||
{
|
||||
public:
|
||||
/// DTOR
|
||||
virtual ~ISignalListener();
|
||||
|
||||
/**
|
||||
* \c onSampleReceived is to be called by the mapping environment
|
||||
* upon receiving a sample on a registered source signal.
|
||||
*
|
||||
* @param [in] data The data contained in the sample
|
||||
* @param [in] size The size of the data
|
||||
* @returns Standard result
|
||||
*/
|
||||
virtual a_util::result::Result onSampleReceived(const void* data, size_t size) = 0;
|
||||
};
|
||||
|
||||
/// Timer interface class
|
||||
class IPeriodicListener
|
||||
{
|
||||
public:
|
||||
/// DTOR
|
||||
virtual ~IPeriodicListener();
|
||||
|
||||
/**
|
||||
* \c onTimer is to be called by the mapping environment periodically.
|
||||
*
|
||||
* @param [in] now The current time
|
||||
* @returns Nothing
|
||||
*/
|
||||
virtual void onTimer(timestamp_t now) = 0;
|
||||
};
|
||||
|
||||
/// Mapping environment interface class
|
||||
/// This in combination with ISignalListener forms the functionality that
|
||||
/// the environment using the mapping package must provide.
|
||||
class IMappingEnvironment
|
||||
{
|
||||
public:
|
||||
/// DTOR
|
||||
virtual ~IMappingEnvironment();
|
||||
|
||||
/**
|
||||
* Method to register a source signal. \c registerSource is called for all
|
||||
* source signals inside a mapped target signal.
|
||||
*
|
||||
* @param [in] source_name The name of the source signal
|
||||
* @param [in] type_name The type of the source signal
|
||||
* @param [in] listener The signal listener instance
|
||||
* @param [in] handle The output parameter for the source handle
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result registerSource(const char* source_name,
|
||||
const char* type_name, ISignalListener* listener, handle_t& handle) = 0;
|
||||
|
||||
/**
|
||||
* Method to unregister a source signal. Used to unregister any source
|
||||
* signals upon unmapping of a target signal.
|
||||
*
|
||||
* @param [in] handle The handle of the source signal
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result unregisterSource(handle_t handle) = 0;
|
||||
|
||||
/**
|
||||
* Method to send a target signal. It is called upon
|
||||
*
|
||||
* @param [in] target The target handle
|
||||
* @param [in] data The pointer referencing the target buffer
|
||||
* @param [in] size The size of the target buffer
|
||||
* @param [in] time_stamp The timestamp of the target
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result sendTarget(handle_t target, const void* data,
|
||||
size_t size, timestamp_t time_stamp) = 0;
|
||||
|
||||
/**
|
||||
* \c targetMapped is invoked by the mapping engine upon the creation of a mapping.
|
||||
* The callback is supposed to give the mapping environment a chance to preallocate
|
||||
* any sample buffers to be used during runtime.
|
||||
*
|
||||
* @param [in] target_name The target name
|
||||
* @param [in] target_type The target type
|
||||
* @param [in] target The handle under which the target is refered to in \c sendTarget
|
||||
* @param [in] target_size The target type size (size of a sample in bytes)
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result targetMapped(const char* target_name, const char* target_type,
|
||||
handle_t target, size_t target_size) = 0;
|
||||
|
||||
/**
|
||||
* \c targetUnmapped is invoked by the mapping engine upon the destruction of a mapping.
|
||||
* The callback is supposed to give the mapping environment a chance to cleanup
|
||||
* any sample buffers associated with that target.
|
||||
*
|
||||
* @param [in] target_name The target name
|
||||
* @param [in] target The target handle
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result targetUnmapped(const char* target_name, handle_t target) = 0;
|
||||
|
||||
/**
|
||||
* Method to get the ddl description for a type
|
||||
* @param [in] type_name The name of the type to be resolved
|
||||
* @param [out] type_description Output paramter for the description for the type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result resolveType(const char* type_name, const char*& type_description) = 0;
|
||||
|
||||
/**
|
||||
* \c getTime is used by the mapping engine to get the current time. Since only the
|
||||
* application of mapping can now what time domain should be used, this method has to be
|
||||
* implementied by the environment.
|
||||
* @returns The current timestamp in microseconds
|
||||
*/
|
||||
virtual timestamp_t getTime() const = 0;
|
||||
|
||||
/**
|
||||
* \c registerPeriodicTimer is used by the mapping engine to register periodic timers
|
||||
* @param [in] period_us The period
|
||||
* @param [in] listener The listener to be called periodically
|
||||
* @returns Standard result
|
||||
*/
|
||||
virtual a_util::result::Result registerPeriodicTimer(timestamp_t period_us, IPeriodicListener* listener) = 0;
|
||||
|
||||
/**
|
||||
* \c registerPeriodicTimer is used by the mapping engine to unregister periodic timers
|
||||
* @param [in] period_us The period
|
||||
* @param [in] listener The listener
|
||||
* @returns Standard result
|
||||
*/
|
||||
virtual a_util::result::Result unregisterPeriodicTimer(timestamp_t period_us, IPeriodicListener* listener) = 0;
|
||||
};
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //MAPPINGENVIRONMENT_HEADER
|
69
mapping/engine/periodic_trigger.cpp
Normal file
69
mapping/engine/periodic_trigger.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* @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 "periodic_trigger.h"
|
||||
|
||||
using namespace mapping::rt;
|
||||
|
||||
PeriodicTrigger::PeriodicTrigger(IMappingEnvironment& oEnv,
|
||||
const std::string& strTriggerName, double fPeriod) : _env(oEnv),
|
||||
_name(strTriggerName), _period(fPeriod), _running(false)
|
||||
{
|
||||
}
|
||||
|
||||
PeriodicTrigger::~PeriodicTrigger()
|
||||
{
|
||||
_env.unregisterPeriodicTimer((timestamp_t)_period * 1000, this);
|
||||
}
|
||||
|
||||
a_util::result::Result PeriodicTrigger::create()
|
||||
{
|
||||
return _env.registerPeriodicTimer((timestamp_t)_period * 1000, this);
|
||||
}
|
||||
|
||||
a_util::result::Result PeriodicTrigger::start()
|
||||
{
|
||||
_running = true;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result PeriodicTrigger::stop()
|
||||
{
|
||||
_running = false;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
void PeriodicTrigger::onTimer(timestamp_t tmNow)
|
||||
{
|
||||
if (_running)
|
||||
{
|
||||
for(TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it)
|
||||
{
|
||||
const void* pBuffer = NULL;
|
||||
size_t szBuffer = 0;
|
||||
(*it)->aquireReadLock();
|
||||
(*it)->updateTriggerFunctionValues();
|
||||
if (isOk((*it)->getBufferRef(pBuffer, szBuffer)))
|
||||
{
|
||||
_env.sendTarget((handle_t)*it, pBuffer, szBuffer, tmNow);
|
||||
}
|
||||
(*it)->releaseReadLock();
|
||||
}
|
||||
}
|
||||
}
|
83
mapping/engine/periodic_trigger.h
Normal file
83
mapping/engine/periodic_trigger.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* @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 PERIODIC_TRIGGER_HEADER
|
||||
#define PERIODIC_TRIGGER_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "trigger.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
/// PeriodicTrigger implements a concrete periodic trigger in the runtime
|
||||
class PeriodicTrigger : public TriggerBase, private IPeriodicListener
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] env The mapping environment
|
||||
* @param [in] trigger_name The name of the trigger
|
||||
* @param [in] period The period of the trigger
|
||||
*/
|
||||
PeriodicTrigger(IMappingEnvironment& env, const std::string& trigger_name, double period);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~PeriodicTrigger();
|
||||
|
||||
/**
|
||||
* Creates and initializes the periodic trigger
|
||||
*/
|
||||
a_util::result::Result create();
|
||||
|
||||
/**
|
||||
* Method to start trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
a_util::result::Result start();
|
||||
|
||||
/**
|
||||
* Method to stop trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result stop();
|
||||
|
||||
private: // IPeriodicListener
|
||||
/// @cond nodoc
|
||||
void onTimer(timestamp_t now);
|
||||
|
||||
private:
|
||||
IMappingEnvironment& _env;
|
||||
std::string _name;
|
||||
double _period;
|
||||
bool _running;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //PERIODIC_TRIGGER_HEADER
|
66
mapping/engine/signal_trigger.cpp
Normal file
66
mapping/engine/signal_trigger.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* @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 "signal_trigger.h"
|
||||
|
||||
using namespace mapping::rt;
|
||||
|
||||
SignalTrigger::SignalTrigger(IMappingEnvironment& oEnv,
|
||||
const std::string& strTriggerName) : _env(oEnv),
|
||||
_name(strTriggerName), _is_running(false)
|
||||
{
|
||||
}
|
||||
|
||||
SignalTrigger::~SignalTrigger()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
a_util::result::Result SignalTrigger::start()
|
||||
{
|
||||
_is_running = true;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result SignalTrigger::stop()
|
||||
{
|
||||
_is_running = false;
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result SignalTrigger::transmit()
|
||||
{
|
||||
if(_is_running)
|
||||
{
|
||||
for(TargetSet::iterator it = _targets.begin(); it != _targets.end(); ++it)
|
||||
{
|
||||
const void* pBuffer = NULL;
|
||||
size_t szBuffer = 0;
|
||||
(*it)->aquireReadLock();
|
||||
(*it)->updateTriggerFunctionValues();
|
||||
if (isOk((*it)->getBufferRef(pBuffer, szBuffer)))
|
||||
{
|
||||
_env.sendTarget((handle_t)*it, pBuffer, szBuffer, 0);
|
||||
}
|
||||
(*it)->releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
81
mapping/engine/signal_trigger.h
Normal file
81
mapping/engine/signal_trigger.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* @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 SIGNAL_TRIGGER_HEADER
|
||||
#define SIGNAL_TRIGGER_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
#include "trigger.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
/// SignalTrigger implements a concrete periodic trigger in the runtime
|
||||
class SignalTrigger : public TriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] env The mapping environment
|
||||
* @param [in] trigger_name The name of the trigger
|
||||
* @param [in] fPeriod The period of the trigger
|
||||
*/
|
||||
SignalTrigger(IMappingEnvironment& env,
|
||||
const std::string& trigger_name);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~SignalTrigger();
|
||||
|
||||
/**
|
||||
* Method to start trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
a_util::result::Result start();
|
||||
|
||||
/**
|
||||
* Method to stop trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result stop();
|
||||
|
||||
/**
|
||||
* Method to transmit targets
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result transmit();
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
IMappingEnvironment& _env;
|
||||
std::string _name;
|
||||
bool _is_running;
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //SIGNAL_TRIGGER_HEADER
|
427
mapping/engine/source.cpp
Normal file
427
mapping/engine/source.cpp
Normal file
|
@ -0,0 +1,427 @@
|
|||
/**
|
||||
* @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 "source.h"
|
||||
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "codec/access_element.h"
|
||||
|
||||
#include "mapping/configuration/map_configuration.h"
|
||||
|
||||
#include "data_trigger.h"
|
||||
#include "signal_trigger.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-4, ERR_POINTER)
|
||||
_MAKE_RESULT(-42, ERR_INVALID_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping;
|
||||
using namespace mapping::rt;
|
||||
|
||||
Source::Source(IMappingEnvironment& oEnv) : _env(oEnv), _handle(0)
|
||||
{
|
||||
_type_map["tUInt8"] = e_uint8;
|
||||
_type_map["tUInt16"] = e_uint16;
|
||||
_type_map["tUInt32"] = e_uint32;
|
||||
_type_map["tUInt64"] = e_uint64;
|
||||
_type_map["tInt8"] = e_int8;
|
||||
_type_map["tInt16"] = e_int16;
|
||||
_type_map["tInt32"] = e_int32;
|
||||
_type_map["tInt64"] = e_int64;
|
||||
_type_map["tFloat32"] = e_float32;
|
||||
_type_map["tFloat64"] = e_float64;
|
||||
_type_map["tBool"] = e_bool;
|
||||
_type_map["tChar"] = e_char;
|
||||
}
|
||||
|
||||
Source::~Source()
|
||||
{
|
||||
if (_handle)
|
||||
{
|
||||
_env.unregisterSource(_handle);
|
||||
}
|
||||
}
|
||||
|
||||
a_util::result::Result Source::create(const oo::MapSource& oMapSource, const std::string& strTypeDescription)
|
||||
{
|
||||
_name = oMapSource.getName();
|
||||
_type = oMapSource.getType();
|
||||
_type_description = strTypeDescription;
|
||||
|
||||
_codec_factory.reset(new ddl::CodecFactory(_type.c_str(), _type_description.c_str()));
|
||||
if (isOk(_codec_factory->isValid()))
|
||||
{
|
||||
return _env.registerSource(_name.c_str(), _type.c_str(), this, _handle);
|
||||
}
|
||||
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
|
||||
a_util::result::Result Source::addTrigger(const oo::MapConfiguration& oMapConfig, TriggerBase* oTrigger)
|
||||
{
|
||||
Triggers::iterator it = _triggers.begin();
|
||||
for(; it != _triggers.end(); ++it)
|
||||
{
|
||||
if (it->first == oTrigger) break;
|
||||
}
|
||||
|
||||
if(it == _triggers.end())
|
||||
{
|
||||
AssignmentStruct oStruct;
|
||||
DataTrigger* pDataTrigger = dynamic_cast<DataTrigger*>(oTrigger);
|
||||
|
||||
if(pDataTrigger)
|
||||
{
|
||||
// Get structure from DDL
|
||||
const ddl::DDLDescription* pDescription = oMapConfig.getDescription();
|
||||
if (!pDescription) { return ERR_POINTER; }
|
||||
const ddl::DDLComplex* pStruct = pDescription->getStructByName(_type);
|
||||
if (!pStruct) { return ERR_POINTER; }
|
||||
|
||||
const ddl::IDDLDataType* pDataType = NULL;
|
||||
// Get Element from DDL Struct
|
||||
const ddl::DDLElement* pElem = NULL;
|
||||
bool bIsArrayElement = false;
|
||||
RETURN_IF_FAILED(DDLHelper::LookupElement(*pStruct, pDataTrigger->getVariable(),
|
||||
pElem, bIsArrayElement));
|
||||
|
||||
// Get ID in DDL
|
||||
ddl::CodecFactory oFac(pStruct);
|
||||
ddl::StaticDecoder oDecoder = _codec_factory->makeStaticDecoderFor(NULL, oFac.getStaticBufferSize());
|
||||
size_t nIdx = 0;
|
||||
RETURN_IF_FAILED(ddl::access_element::find_index(oDecoder, pDataTrigger->getVariable(), nIdx));
|
||||
|
||||
// Get element pointer offset
|
||||
oStruct.element_ptr_offset = (uintptr_t)oDecoder.getElementAddress(nIdx);
|
||||
|
||||
pDataType = pElem->getTypeObject();
|
||||
// Get Type from TypeMap
|
||||
TypeMap::const_iterator it = _type_map.find(pDataType->getName());
|
||||
if(it != _type_map.end())
|
||||
{
|
||||
oStruct.type32 = it->second;
|
||||
}
|
||||
|
||||
// find element size
|
||||
const ddl::DDLDataType* pSourceType = dynamic_cast<const ddl::DDLDataType*>(pDataType);
|
||||
if(pSourceType)
|
||||
{
|
||||
oStruct.buffer_size = pSourceType->getNumBits()/8;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
_triggers.push_back(std::make_pair(oTrigger, oStruct));
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
const std::string& Source::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
const Source::Assignments& Source::getAssigmentList() const
|
||||
{
|
||||
return _assignments;
|
||||
}
|
||||
|
||||
a_util::result::Result Source::addAssignment(const oo::MapConfiguration& oMapConfig,
|
||||
const std::string& strSourceElement, TargetElement* pTargetElement)
|
||||
{
|
||||
if(strSourceElement == "received()")
|
||||
{
|
||||
_received_elements.push_back(pTargetElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssignmentStruct oStruct;
|
||||
|
||||
// Get structure from DDL
|
||||
const ddl::DDLDescription* pDescription = oMapConfig.getDescription();
|
||||
if (!pDescription) { return ERR_POINTER; }
|
||||
const ddl::DDLComplex* pStruct = pDescription->getStructByName(_type);
|
||||
if (!pStruct) { return ERR_POINTER; }
|
||||
|
||||
unsigned int szArraySize = 1;
|
||||
|
||||
// If strSourceElement is empty, the whole Structure will be copied
|
||||
if(strSourceElement.empty())
|
||||
{
|
||||
oStruct.buffer_size = _codec_factory->getStaticBufferSize();
|
||||
oStruct.element_ptr_offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get Element from DDL Struct
|
||||
const ddl::DDLElement* pElem = NULL;
|
||||
bool bIsArrayElement = false;
|
||||
|
||||
RETURN_IF_FAILED(DDLHelper::LookupElement(*pStruct, strSourceElement,
|
||||
pElem, bIsArrayElement));
|
||||
|
||||
const ddl::IDDLDataType* pDataType = pElem->getTypeObject();
|
||||
|
||||
// Get ID in DDL Coder
|
||||
if(!bIsArrayElement)
|
||||
{
|
||||
szArraySize = pElem->getArraysize();
|
||||
}
|
||||
|
||||
// Get Type from TypeMap
|
||||
TypeMap::const_iterator it = _type_map.find(pDataType->getName());
|
||||
if(it != _type_map.end())
|
||||
{
|
||||
oStruct.type32 = it->second;
|
||||
}
|
||||
|
||||
// find element size
|
||||
const ddl::DDLDataType* pSourceType = dynamic_cast<const ddl::DDLDataType*>(pDataType);
|
||||
const ddl::DDLComplex* pSourceStruct = dynamic_cast<const ddl::DDLComplex*>(pDataType);
|
||||
const ddl::DDLEnum* pSourceEnum = dynamic_cast<const ddl::DDLEnum*>(pDataType);
|
||||
|
||||
if(pSourceType)
|
||||
{
|
||||
oStruct.buffer_size = pSourceType->getNumBits() * szArraySize/8;
|
||||
}
|
||||
else if(pSourceStruct)
|
||||
{
|
||||
// TODO: check if this struct can be a different one than the one in _codec_factory
|
||||
ddl::CodecFactory oFactory(pSourceStruct->getName().c_str(),
|
||||
_type_description.c_str());
|
||||
|
||||
oStruct.buffer_size = oFactory.getStaticBufferSize();
|
||||
}
|
||||
else if(pSourceEnum)
|
||||
{
|
||||
const ddl::DDLDataType* pEnumType = dynamic_cast<const ddl::DDLDataType*>(pSourceEnum->getTypeObject());
|
||||
oStruct.buffer_size = pEnumType->getNumBits() * szArraySize/8;
|
||||
|
||||
// we need to set the interpretation type to the underlying type here
|
||||
it = _type_map.find(pEnumType->getName());
|
||||
if(it != _type_map.end())
|
||||
{
|
||||
oStruct.type32 = it->second;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERR_INVALID_TYPE;
|
||||
}
|
||||
|
||||
std::string strPath = strSourceElement;
|
||||
if (szArraySize > 1)
|
||||
{
|
||||
strPath.append("[0]");
|
||||
}
|
||||
|
||||
ddl::CodecFactory oFac(pStruct);
|
||||
ddl::StaticDecoder oDecoder = _codec_factory->makeStaticDecoderFor(NULL, oFac.getStaticBufferSize());
|
||||
size_t nIdx = 0;
|
||||
RETURN_IF_FAILED(ddl::access_element::find_index(oDecoder, strPath, nIdx));
|
||||
|
||||
// Get element pointer offset
|
||||
oStruct.element_ptr_offset = (uintptr_t)oDecoder.getElementAddress(nIdx);
|
||||
}
|
||||
|
||||
Assignments::iterator itAssigns = _assignments.end();
|
||||
for (itAssigns = _assignments.begin(); itAssigns != _assignments.end(); ++itAssigns)
|
||||
{
|
||||
if (itAssigns->first == oStruct)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (itAssigns == _assignments.end())
|
||||
{
|
||||
_assignments.push_back(std::make_pair(oStruct, TargetElementList()));
|
||||
_assignments.back().second.push_back(pTargetElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
itAssigns->second.push_back(pTargetElement);
|
||||
}
|
||||
}
|
||||
|
||||
_targets.insert(pTargetElement->getTarget());
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Source::removeAssignmentsFor(const Target* pTarget)
|
||||
{
|
||||
for (Assignments::iterator itAssignments = _assignments.begin();
|
||||
itAssignments != _assignments.end();)
|
||||
{
|
||||
TargetElementList& oAssignedElements = itAssignments->second;
|
||||
for (TargetElementList::iterator itElements = oAssignedElements.begin();
|
||||
itElements != oAssignedElements.end();)
|
||||
{
|
||||
if ((*itElements)->getTarget() == pTarget)
|
||||
{
|
||||
// element is owned and deleted by target
|
||||
itElements = oAssignedElements.erase(itElements);
|
||||
}
|
||||
else
|
||||
{
|
||||
++itElements;
|
||||
}
|
||||
}
|
||||
|
||||
if (itAssignments->second.empty())
|
||||
{
|
||||
itAssignments = _assignments.erase(itAssignments);
|
||||
}
|
||||
else
|
||||
{
|
||||
++itAssignments;
|
||||
}
|
||||
}
|
||||
|
||||
_targets.erase(pTarget);
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Source::onSampleReceived(const void* pData, size_t szSize)
|
||||
{
|
||||
if (!pData) { return ERR_POINTER; }
|
||||
|
||||
// lock all currently mapped target buffers
|
||||
// note: theres some optimization potential here:
|
||||
// -- rework the assignment container to be able to sort the assignments by target
|
||||
// -- lock only the current target during iteration over all assignments
|
||||
// for now it is fast enough since the number of mapped targets isn't to high
|
||||
for (TargetRefList::const_iterator it = _targets.begin();
|
||||
it != _targets.end(); ++it)
|
||||
{
|
||||
(*it)->aquireWriteLock();
|
||||
}
|
||||
|
||||
// write true into all received(<this_signal>) assignments
|
||||
bool bValue = true;
|
||||
for(TargetElementList::iterator it = _received_elements.begin(); it != _received_elements.end(); it++)
|
||||
{
|
||||
(*it)->setValue(&bValue, e_bool, sizeof(bValue));
|
||||
}
|
||||
|
||||
// write all assignments that stem from this source
|
||||
for (Assignments::iterator itAssign = _assignments.begin();
|
||||
itAssign != _assignments.end(); ++itAssign)
|
||||
{
|
||||
void* pValue = (void*)((uintptr_t)pData + itAssign->first.element_ptr_offset);
|
||||
|
||||
const std::vector<TargetElement*>& vecElements = itAssign->second;
|
||||
uint32_t type32 = itAssign->first.type32;
|
||||
size_t buffer_size = itAssign->first.buffer_size;
|
||||
|
||||
for (size_t idx = 0; idx < vecElements.size(); ++idx)
|
||||
{
|
||||
vecElements[idx]->setValue(pValue, type32, buffer_size);
|
||||
}
|
||||
}
|
||||
|
||||
// unlock all currently mapped target buffers
|
||||
for (TargetRefList::const_iterator it = _targets.begin();
|
||||
it != _targets.end(); ++it)
|
||||
{
|
||||
(*it)->releaseWriteLock();
|
||||
}
|
||||
|
||||
// call signal triggers
|
||||
for(Triggers::iterator it = _triggers.begin();
|
||||
it != _triggers.end(); it++)
|
||||
{
|
||||
SignalTrigger* pSigTrigger = dynamic_cast<SignalTrigger*>(it->first);
|
||||
DataTrigger* pDataTrigger = dynamic_cast<DataTrigger*>(it->first);
|
||||
if(pSigTrigger)
|
||||
{
|
||||
pSigTrigger->transmit();
|
||||
}
|
||||
else if(pDataTrigger)
|
||||
{
|
||||
// read the current value and cast it into a float64
|
||||
double f64Val = 0;
|
||||
void* pValue = (void*)((uintptr_t)pData + it->second.element_ptr_offset);
|
||||
switch (it->second.type32)
|
||||
{
|
||||
case e_uint8:
|
||||
f64Val = *(static_cast<uint8_t*>(pValue));
|
||||
break;
|
||||
case e_uint16:
|
||||
f64Val = *(static_cast<uint16_t*>(pValue));
|
||||
break;
|
||||
case e_uint32:
|
||||
f64Val = *(static_cast<uint32_t*>(pValue));
|
||||
break;
|
||||
case e_uint64:
|
||||
f64Val = static_cast<double>(*(static_cast<uint64_t*>(pValue)));
|
||||
break;
|
||||
case e_int8:
|
||||
f64Val = *(static_cast<int8_t*>(pValue));
|
||||
break;
|
||||
case e_int16:
|
||||
f64Val = *(static_cast<int16_t*>(pValue));
|
||||
break;
|
||||
case e_int32:
|
||||
f64Val = *(static_cast<int32_t*>(pValue));
|
||||
break;
|
||||
case e_int64:
|
||||
f64Val = static_cast<double>(*(static_cast<int64_t*>(pValue)));
|
||||
break;
|
||||
case e_float32:
|
||||
f64Val = *(static_cast<float*>(pValue));
|
||||
break;
|
||||
case e_float64:
|
||||
f64Val = *(static_cast<double*>(pValue));
|
||||
break;
|
||||
case e_bool:
|
||||
f64Val = *(static_cast<bool*>(pValue));
|
||||
break;
|
||||
case e_char:
|
||||
f64Val = *(static_cast<char*>(pValue));
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
// compare/interpret the operator comparison
|
||||
if(pDataTrigger->compare(f64Val))
|
||||
{
|
||||
pDataTrigger->transmit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
177
mapping/engine/source.h
Normal file
177
mapping/engine/source.h
Normal file
|
@ -0,0 +1,177 @@
|
|||
/**
|
||||
* @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 MAPPING_SOURCE_HEADER
|
||||
#define MAPPING_SOURCE_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "mapping/configuration/map_source.h"
|
||||
#include "codec/codec_factory.h"
|
||||
|
||||
#include "mapping_environment_intf.h"
|
||||
#include "element.h"
|
||||
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
///@cond nodoc
|
||||
struct AssignmentStruct
|
||||
{
|
||||
size_t buffer_size;
|
||||
uint32_t type32;
|
||||
uintptr_t element_ptr_offset;
|
||||
|
||||
AssignmentStruct() :
|
||||
buffer_size(0), type32(0), element_ptr_offset(static_cast<uintptr_t>(-1)) {}
|
||||
|
||||
bool operator==(const AssignmentStruct &other) const
|
||||
{
|
||||
return (element_ptr_offset == other.element_ptr_offset);
|
||||
}
|
||||
};
|
||||
///nodoc
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
class TriggerBase;
|
||||
class Target;
|
||||
class TargetElement;
|
||||
|
||||
class Source : public ISignalListener
|
||||
{
|
||||
public: // types
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic ignored "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
// Map of source elements and a vector of target elements
|
||||
typedef std::vector<std::pair<AssignmentStruct, TargetElementList> > Assignments;
|
||||
typedef std::vector<std::pair<TriggerBase*, AssignmentStruct> > Triggers;
|
||||
typedef std::vector<uint8_t> MemoryBuffer;
|
||||
typedef std::set<const Target*> TargetRefList;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic warning "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] env The mapping environment
|
||||
*/
|
||||
Source(IMappingEnvironment& env);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~Source();
|
||||
|
||||
/**
|
||||
* Creation method to fill the object with data.
|
||||
* @param[in] oo::MapSource The soucre representation from mapping configuration
|
||||
* @param[in] type_description The description for the source type
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error while filing the object
|
||||
*/
|
||||
a_util::result::Result create(const mapping::oo::MapSource& map_source,
|
||||
const std::string& type_description);
|
||||
|
||||
/**
|
||||
* Method to add a new pair of source element and target element to the intern assignment list
|
||||
* @param[in] oConfig The Configuration instance
|
||||
* @param[in] source_element The name of the source element to map
|
||||
* @param[in] target_element The target element instance
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addAssignment(const mapping::oo::MapConfiguration& map_config,
|
||||
const std::string& source_element, TargetElement* target_element);
|
||||
|
||||
/**
|
||||
* Method to add a new trigger to the intern trigger list
|
||||
* @param[in] trigger The trigger
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTrigger(const oo::MapConfiguration& map_config, TriggerBase* trigger);
|
||||
|
||||
/**
|
||||
* Method to remove all elements of a target from the intern assignment list
|
||||
* @param[in] target The target to unmap
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeAssignmentsFor(const Target* target);
|
||||
|
||||
/**
|
||||
* Getter for the source type
|
||||
* @return the source type
|
||||
*/
|
||||
const std::string& getType() const;
|
||||
|
||||
/**
|
||||
* Getter for the assignment list
|
||||
* @return the assignment list
|
||||
*/
|
||||
const Assignments& getAssigmentList() const;
|
||||
|
||||
/**
|
||||
* Method to handle a sample when it is received.
|
||||
* @param[in] data The memory location of the received buffer
|
||||
* @param[in] size The memory size of the received buffer
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result onSampleReceived(const void* data, size_t size);
|
||||
|
||||
private:
|
||||
IMappingEnvironment& _env;
|
||||
handle_t _handle;
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
std::string _type_description;
|
||||
Assignments _assignments;
|
||||
TargetRefList _targets;
|
||||
a_util::memory::unique_ptr<ddl::CodecFactory> _codec_factory;
|
||||
TypeMap _type_map;
|
||||
TargetElementList _received_elements;
|
||||
Triggers _triggers;
|
||||
|
||||
Source(const Source&); // = delete;
|
||||
Source& operator=(const Source&); // = delete;
|
||||
};
|
||||
|
||||
/// Public composite types used in the mapping::rt namespace
|
||||
typedef std::map<std::string, Source*> SourceMap;
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
|
||||
|
||||
|
||||
#endif //MAPPING_SOURCE_HEADER
|
379
mapping/engine/target.cpp
Normal file
379
mapping/engine/target.cpp
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
|
||||
*/
|
||||
|
||||
#include "target.h"
|
||||
|
||||
#include <memory> //std::unique_ptr<>
|
||||
#include "a_util/result/error_def.h"
|
||||
#include "legacy_error_macros.h"
|
||||
|
||||
#include "codec/access_element.h"
|
||||
|
||||
#include "mapping/configuration/map_configuration.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
//define all needed error types and values locally
|
||||
_MAKE_RESULT(-3, ERR_UNEXPECTED)
|
||||
_MAKE_RESULT(-4, ERR_POINTER)
|
||||
_MAKE_RESULT(-12, ERR_MEMORY)
|
||||
}
|
||||
}
|
||||
|
||||
using namespace mapping;
|
||||
using namespace mapping::rt;
|
||||
|
||||
Target::Target(IMappingEnvironment& oEnv) :
|
||||
_counter(0), _env(oEnv)
|
||||
{
|
||||
}
|
||||
|
||||
Target::~Target()
|
||||
{
|
||||
for (TargetElementList::iterator it = _target_elements.begin();
|
||||
it != _target_elements.end(); ++it)
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
_target_elements.clear();
|
||||
_simulation_time_elements.clear();
|
||||
}
|
||||
|
||||
a_util::result::Result Target::create(const oo::MapConfiguration& oMapConfig,
|
||||
const oo::MapTarget& oMapTarget, const std::string& strTargetDescription,
|
||||
SourceMap& oSources)
|
||||
{
|
||||
_name = oMapTarget.getName();
|
||||
_type = oMapTarget.getType();
|
||||
ddl::CodecFactory oFactory(_type.c_str(), strTargetDescription.c_str());
|
||||
RETURN_IF_FAILED(oFactory.isValid());
|
||||
|
||||
// Alloc and zero memory
|
||||
_buffer.resize(oFactory.getStaticBufferSize(), 0);
|
||||
|
||||
// Begin here, end when target is destroyed or after reset
|
||||
_codec.reset(new ddl::StaticCodec(oFactory.makeStaticCodecFor(&_buffer[0], _buffer.size())));
|
||||
|
||||
// Get structure from DDL
|
||||
const ddl::DDLDescription* pDescription = oMapConfig.getDescription();
|
||||
if (!pDescription) { return ERR_POINTER; }
|
||||
const ddl::DDLComplex* pStruct = pDescription->getStructByName(_type);
|
||||
if (!pStruct) { return ERR_POINTER; }
|
||||
|
||||
// Create element for each assignment in mapping configuration
|
||||
const oo::MapAssignmentList& oAssignmentList = oMapTarget.getAssignmentList();
|
||||
for(oo::MapAssignmentList::const_iterator itAssignment = oAssignmentList.begin();
|
||||
itAssignment != oAssignmentList.end(); ++itAssignment)
|
||||
{
|
||||
const ddl::DDLElement* pElem = NULL;
|
||||
bool bIsArrayElement = false;
|
||||
RETURN_IF_FAILED(DDLHelper::LookupElement(*pStruct, itAssignment->getTo(),
|
||||
pElem, bIsArrayElement));
|
||||
|
||||
unsigned int szElement = pElem->getArraysize();
|
||||
if(bIsArrayElement)
|
||||
{
|
||||
szElement = 1;
|
||||
}
|
||||
|
||||
std::string strPath = itAssignment->getTo();
|
||||
if (szElement > 1)
|
||||
{
|
||||
strPath.append("[0]");
|
||||
}
|
||||
|
||||
ddl::DDLComplex* pComplex = dynamic_cast<ddl::DDLComplex*>(pElem->getTypeObject());
|
||||
if (pComplex)
|
||||
{
|
||||
// No StructElement is created for the actual struct, only for its elements. Therefore, if
|
||||
// the assignment is a struct, we need to amend the path by the first element of the struct
|
||||
if (pComplex->getElements().empty()) return ERR_UNEXPECTED;
|
||||
strPath.push_back('.');
|
||||
strPath.append(pComplex->getElements()[0]->getName());
|
||||
}
|
||||
|
||||
size_t nIdx = 0;
|
||||
RETURN_IF_FAILED(ddl::access_element::find_index(*_codec, strPath, nIdx));
|
||||
void* pTargetElementPtr = _codec->getElementAddress(nIdx);
|
||||
|
||||
// Create target element
|
||||
std::unique_ptr<TargetElement> pElement(new TargetElement(this));
|
||||
RETURN_IF_FAILED(pElement->create(pTargetElementPtr, pElem->getTypeObject(),
|
||||
szElement, itAssignment->getTo()));
|
||||
|
||||
// If a constant is given, there can be no transformation
|
||||
if(!itAssignment->getConstant().empty())
|
||||
{
|
||||
_constant_elements.push_back(make_pair(itAssignment->getConstant(), pElement.get()));
|
||||
|
||||
}
|
||||
else if(!itAssignment->getFunction().empty())
|
||||
{
|
||||
if(itAssignment->getFunction() == "simulation_time")
|
||||
{
|
||||
_simulation_time_elements.push_back(pElement.get());
|
||||
}
|
||||
else if(itAssignment->getFunction() == "trigger_counter")
|
||||
{
|
||||
uint64_t nMod = 0;
|
||||
if (!itAssignment->getModulo().empty())
|
||||
{
|
||||
nMod = a_util::strings::toUInt64(itAssignment->getModulo());
|
||||
}
|
||||
_counter_elements.push_back(std::make_pair(nMod, pElement.get()));
|
||||
}
|
||||
else if(itAssignment->getFunction() == "received")
|
||||
{
|
||||
// Add assignments to source
|
||||
SourceMap::iterator itSource = oSources.find(itAssignment->getSource());
|
||||
if (itSource == oSources.end())
|
||||
{
|
||||
return ERR_UNEXPECTED;
|
||||
}
|
||||
|
||||
RETURN_IF_FAILED(itSource->second->addAssignment(oMapConfig, "received()", pElement.get()));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add Transformation for Mapping configuration
|
||||
const std::string& strTransformation = itAssignment->getTransformation();
|
||||
if(!strTransformation.empty())
|
||||
{
|
||||
RETURN_IF_FAILED(pElement->setTransformation(
|
||||
oMapConfig.getTransformation(strTransformation)));
|
||||
}
|
||||
|
||||
// Add assignments to source
|
||||
SourceMap::iterator itSource = oSources.find(itAssignment->getSource());
|
||||
if (itSource == oSources.end())
|
||||
{
|
||||
return ERR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// getFrom() is empty when the source itself is referenced
|
||||
RETURN_IF_FAILED(itSource->second->addAssignment(oMapConfig, itAssignment->getFrom(), pElement.get()));
|
||||
}
|
||||
|
||||
_target_elements.push_back(pElement.release());
|
||||
}
|
||||
|
||||
// initialize memory
|
||||
RETURN_IF_FAILED(reset(oMapConfig));
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Target::reset(const oo::MapConfiguration& oMapConfig)
|
||||
{
|
||||
a_util::result::Result nResult = a_util::result::SUCCESS;
|
||||
// Reset Counter
|
||||
_counter = 0;
|
||||
|
||||
// Set default values from DDL
|
||||
const ddl::DDLDescription* pDescription = oMapConfig.getDescription();
|
||||
if (!pDescription) { return ERR_POINTER; }
|
||||
const ddl::DDLComplex* pStruct = pDescription->getStructByName(_type);
|
||||
if (!pStruct) { return ERR_POINTER; }
|
||||
|
||||
// Set default values from DDL in a newly created data sample
|
||||
for (size_t nIdx = 0; nIdx < _codec->getElementCount(); ++nIdx)
|
||||
{
|
||||
const ddl::StructElement* pElement = NULL;
|
||||
if (isFailed(_codec->getElement(nIdx, pElement)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const ddl::DDLElement* pElem = NULL;
|
||||
bool bIsArrayElement = false;
|
||||
a_util::result::Result nCurrentResult = DDLHelper::LookupElement(*pStruct,
|
||||
pElement->name, pElem, bIsArrayElement);
|
||||
|
||||
unsigned int nLastElementIndex = 1;
|
||||
std::string strDefaultValue;
|
||||
if (isOk(nCurrentResult))
|
||||
{
|
||||
nLastElementIndex = pElem->getArraysize();
|
||||
// Element Description was found ... check for a default value
|
||||
if (pElem->isDefaultValid())
|
||||
{
|
||||
strDefaultValue = pElem->getDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
// Set error if no error happend so far
|
||||
if (isOk(nResult))
|
||||
{
|
||||
nResult = nCurrentResult;
|
||||
}
|
||||
|
||||
if (strDefaultValue.empty())
|
||||
{
|
||||
// No default detected, just reset this entry
|
||||
ddl::access_element::reset(*_codec, pElement->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
a_util::variant::Variant var;
|
||||
switch (pElement->type)
|
||||
{
|
||||
case a_util::variant::VT_Bool:
|
||||
var.reset(a_util::strings::toBool(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Int8:
|
||||
var.reset(a_util::strings::toInt8(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_UInt8:
|
||||
var.reset(a_util::strings::toUInt8(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Int16:
|
||||
var.reset(a_util::strings::toInt16(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_UInt16:
|
||||
var.reset(a_util::strings::toUInt16(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Int32:
|
||||
var.reset(a_util::strings::toInt32(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_UInt32:
|
||||
var.reset(a_util::strings::toUInt32(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Int64:
|
||||
var.reset(a_util::strings::toInt64(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_UInt64:
|
||||
var.reset(a_util::strings::toUInt64(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Float:
|
||||
var.reset(a_util::strings::toFloat(strDefaultValue));
|
||||
break;
|
||||
case a_util::variant::VT_Double:
|
||||
var.reset(a_util::strings::toDouble(strDefaultValue));
|
||||
break;
|
||||
default:
|
||||
ddl::access_element::reset(*_codec, pElement->name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!var.isEmpty())
|
||||
{
|
||||
nCurrentResult = _codec->setElementValue(nIdx, var);
|
||||
}
|
||||
|
||||
// Set error if no error happend so far
|
||||
if (isOk(nResult))
|
||||
{
|
||||
nResult = nCurrentResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set constant elements
|
||||
if (isOk(nResult))
|
||||
{
|
||||
for(Constants::iterator it = _constant_elements.begin(); it != _constant_elements.end(); it++)
|
||||
{
|
||||
nResult = it->second->setDefaultValue(it->first);
|
||||
}
|
||||
}
|
||||
return nResult;
|
||||
}
|
||||
|
||||
const std::string& Target::getName() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
const std::string& Target::getType() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
const TargetElementList& Target::getElementList() const
|
||||
{
|
||||
return _target_elements;
|
||||
}
|
||||
|
||||
size_t Target::getSize() const
|
||||
{
|
||||
return _buffer.size();
|
||||
}
|
||||
|
||||
a_util::result::Result Target::updateAccessFunctionValues()
|
||||
{
|
||||
// set simulation time for simulation_time assignments
|
||||
timestamp_t tmTime = _env.getTime();
|
||||
for(std::vector<TargetElement*>::const_iterator it = _simulation_time_elements.begin();
|
||||
it != _simulation_time_elements.end(); it++)
|
||||
{
|
||||
(*it)->setValue(&tmTime, e_int64, sizeof(timestamp_t));
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Target::updateTriggerFunctionValues()
|
||||
{
|
||||
// increment counter
|
||||
_counter++;
|
||||
|
||||
// write counter into trigger_counter assignments
|
||||
for(TriggerCounters::const_iterator it = _counter_elements.begin(); it != _counter_elements.end(); it++)
|
||||
{
|
||||
uint64_t nValue = _counter;
|
||||
if (it->first != 0)
|
||||
{
|
||||
nValue %= it->first;
|
||||
}
|
||||
it->second->setValue(&nValue, e_uint64, sizeof(nValue));
|
||||
}
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Target::getCurrentBuffer(void* pTargetBuffer, size_t szTargetBuffer)
|
||||
{
|
||||
if(szTargetBuffer < _buffer.size())
|
||||
{
|
||||
return ERR_MEMORY;
|
||||
}
|
||||
|
||||
updateAccessFunctionValues();
|
||||
|
||||
aquireReadLock();
|
||||
a_util::memory::copy(pTargetBuffer, szTargetBuffer, &_buffer[0], _buffer.size());
|
||||
releaseReadLock();
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result Target::getBufferRef(const void*& pBuffer, size_t& szTargetBuffer)
|
||||
{
|
||||
updateAccessFunctionValues();
|
||||
|
||||
// synchronization is done by the caller!
|
||||
pBuffer = &_buffer[0];
|
||||
szTargetBuffer = _buffer.size();
|
||||
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
184
mapping/engine/target.h
Normal file
184
mapping/engine/target.h
Normal file
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* @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 TARGET_HEADER
|
||||
#define TARGET_HEADER
|
||||
|
||||
#include <vector>
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "codec/static_codec.h"
|
||||
|
||||
#include "element.h"
|
||||
#include "source.h"
|
||||
#include "mapping_environment_intf.h"
|
||||
#include "mapping/configuration/map_target.h"
|
||||
#include "mapping/configuration/map_source.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
/// Target represents a mapped target signal in the runtime api
|
||||
class Target
|
||||
{
|
||||
public: // types
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic ignored "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
/// Assignment container
|
||||
typedef std::vector<std::pair<std::string, TargetElement*> > Assignments;
|
||||
/// Trigger counter container
|
||||
typedef std::vector<std::pair<uint64_t, TargetElement*> > TriggerCounters;
|
||||
/// Constant container
|
||||
typedef std::vector<std::pair<std::string, TargetElement*> > Constants;
|
||||
/// Generic byte-buffer
|
||||
typedef std::vector<uint8_t> MemoryBuffer;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
|
||||
#pragma GCC diagnostic warning "-Wattributes" // standard type attributes are ignored when used in templates
|
||||
#endif
|
||||
|
||||
public:
|
||||
/**
|
||||
* CTOR
|
||||
* @param [in] env The environment
|
||||
*/
|
||||
Target(IMappingEnvironment& env);
|
||||
|
||||
/**
|
||||
* DTOR
|
||||
*/
|
||||
~Target();
|
||||
|
||||
/**
|
||||
* Creation method to fill the object with data.
|
||||
* @param[in] map_config - The Configuration instance
|
||||
* @param[in] oo::MapTarget - target representation from mapping configuration
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error while filing the object
|
||||
*/
|
||||
a_util::result::Result create(const oo::MapConfiguration& map_config, const oo::MapTarget& map_target,
|
||||
const std::string& target_description, SourceMap& sources);
|
||||
|
||||
/**
|
||||
* Reset target Buffers
|
||||
* @param[in] map_config - The Configuration instance
|
||||
* @return error code
|
||||
*/
|
||||
a_util::result::Result reset(const oo::MapConfiguration& map_config);
|
||||
|
||||
/**
|
||||
* Getter for the target name
|
||||
* @return the target name
|
||||
*/
|
||||
const std::string& getName() const;
|
||||
|
||||
/**
|
||||
* Getter for the target type
|
||||
* @return the target type
|
||||
*/
|
||||
const std::string& getType() const;
|
||||
|
||||
/**
|
||||
* Getter for the element list
|
||||
* @return the element list
|
||||
*/
|
||||
const TargetElementList& getElementList() const;
|
||||
|
||||
/**
|
||||
* Method to get buffer size
|
||||
*
|
||||
* @retval buffer size
|
||||
*/
|
||||
size_t getSize() const;
|
||||
|
||||
/**
|
||||
* Method to get a copy of the current target buffer
|
||||
*
|
||||
* @param [in] target_buffer Pointer referencing the target buffer
|
||||
* @param [in] target_buffer_size The size of the target buffer
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_MEMORY Target buffer size not large enough
|
||||
*/
|
||||
a_util::result::Result getCurrentBuffer(void* target_buffer, size_t target_buffer_size);
|
||||
|
||||
|
||||
/**
|
||||
* Method to get access to the current buffer without copying it
|
||||
*
|
||||
* @param [in] buffer Destination pointer
|
||||
* @param [out] target_buffer_size Destination parameter for the size of the buffer
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result getBufferRef(const void*& buffer, size_t& target_buffer_size);
|
||||
|
||||
/**
|
||||
* Method to update all dynamic values that are to be updates during buffer access
|
||||
* (i.e. simulation time)
|
||||
*/
|
||||
a_util::result::Result updateAccessFunctionValues();
|
||||
|
||||
/**
|
||||
* Method to update all dynamic values that are to be updates during a trigger
|
||||
* (i.e. trigger counters)
|
||||
*/
|
||||
a_util::result::Result updateTriggerFunctionValues();
|
||||
|
||||
private:
|
||||
/// @cond nodoc
|
||||
std::string _name;
|
||||
std::string _type;
|
||||
TargetElementList _target_elements;
|
||||
std::vector<TargetElement*> _simulation_time_elements;
|
||||
TriggerCounters _counter_elements;
|
||||
Constants _constant_elements;
|
||||
uint64_t _counter;
|
||||
a_util::memory::unique_ptr<ddl::StaticCodec> _codec;
|
||||
MemoryBuffer _buffer;
|
||||
mutable a_util::concurrency::shared_mutex _buffer_mutex;
|
||||
IMappingEnvironment& _env;
|
||||
/// @nodoc
|
||||
public:
|
||||
/// Lock the buffer for a source update
|
||||
inline void aquireWriteLock() const { _buffer_mutex.lock_shared(); }
|
||||
|
||||
/// Unlock the buffer after a source update
|
||||
inline void releaseWriteLock() const { _buffer_mutex.unlock_shared(); }
|
||||
|
||||
/// Lock the buffer for a buffer read
|
||||
inline void aquireReadLock() const { _buffer_mutex.lock(); }
|
||||
|
||||
/// Unlock the buffer after a buffer read
|
||||
inline void releaseReadLock() const { _buffer_mutex.unlock(); }
|
||||
};
|
||||
|
||||
/// Public composite types used in the mapping::rt namespace
|
||||
typedef std::map<std::string, Target*> TargetMap;
|
||||
typedef std::set<Target*> TargetSet;
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //TARGET_HEADER
|
41
mapping/engine/trigger.cpp
Normal file
41
mapping/engine/trigger.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* @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 "trigger.h"
|
||||
|
||||
|
||||
using namespace mapping::rt;
|
||||
|
||||
TriggerBase::~TriggerBase() {}
|
||||
|
||||
TargetSet& TriggerBase::getTargetList()
|
||||
{
|
||||
return _targets;
|
||||
}
|
||||
|
||||
a_util::result::Result TriggerBase::addTarget(Target* target)
|
||||
{
|
||||
_targets.insert(target);
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
||||
|
||||
a_util::result::Result TriggerBase::removeTarget(Target* target)
|
||||
{
|
||||
_targets.erase(target);
|
||||
return a_util::result::SUCCESS;
|
||||
}
|
86
mapping/engine/trigger.h
Normal file
86
mapping/engine/trigger.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* @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 TRIGGER_BASE_HEADER
|
||||
#define TRIGGER_BASE_HEADER
|
||||
|
||||
#include "a_util/result.h"
|
||||
|
||||
#include "target.h"
|
||||
|
||||
namespace mapping
|
||||
{
|
||||
namespace rt
|
||||
{
|
||||
|
||||
/// base class representing a trigger
|
||||
class TriggerBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Virtual DTOR
|
||||
*/
|
||||
virtual ~TriggerBase();
|
||||
|
||||
/**
|
||||
* Method to start trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
* @retval ERR_FAILED Error during runtime
|
||||
*/
|
||||
virtual a_util::result::Result start() = 0;
|
||||
|
||||
/**
|
||||
* Method to stop trigger
|
||||
*
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
virtual a_util::result::Result stop() = 0;
|
||||
|
||||
public: // Base implementations
|
||||
/**
|
||||
* Getter for the list of registered targets
|
||||
* @return the list of targets
|
||||
*/
|
||||
TargetSet& getTargetList();
|
||||
|
||||
/**
|
||||
* Method to register a new target
|
||||
* @param[in] target The target to add
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result addTarget(Target* target);
|
||||
|
||||
/**
|
||||
* Method to deregister a target
|
||||
* @param[in] target The target to remove
|
||||
* @retval a_util::result::SUCCESS Everything went fine
|
||||
*/
|
||||
a_util::result::Result removeTarget(Target* target);
|
||||
|
||||
protected:
|
||||
/// nodoc
|
||||
TargetSet _targets;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, TriggerBase*> TriggerMap;
|
||||
|
||||
} // namespace rt
|
||||
} // namespace mapping
|
||||
#endif //TRIGGER_BASE_HEADER
|
53
mapping/mapping.sources
Normal file
53
mapping/mapping.sources
Normal file
|
@ -0,0 +1,53 @@
|
|||
set(MAPPING_DIR mapping)
|
||||
|
||||
set(MAPPING_CONFIGURATION_H
|
||||
${MAPPING_DIR}/configuration/map_assignment.h
|
||||
${MAPPING_DIR}/configuration/map_configuration.h
|
||||
${MAPPING_DIR}/configuration/map_header.h
|
||||
${MAPPING_DIR}/configuration/map_source.h
|
||||
${MAPPING_DIR}/configuration/map_target.h
|
||||
${MAPPING_DIR}/configuration/map_transformation.h
|
||||
${MAPPING_DIR}/configuration/map_trigger.h
|
||||
)
|
||||
|
||||
set(MAPPING_ENGINE_H
|
||||
${MAPPING_DIR}/engine/data_trigger.h
|
||||
${MAPPING_DIR}/engine/element.h
|
||||
${MAPPING_DIR}/engine/mapping_engine.h
|
||||
${MAPPING_DIR}/engine/periodic_trigger.h
|
||||
${MAPPING_DIR}/engine/signal_trigger.h
|
||||
${MAPPING_DIR}/engine/source.h
|
||||
${MAPPING_DIR}/engine/target.h
|
||||
${MAPPING_DIR}/engine/trigger.h
|
||||
${MAPPING_DIR}/engine/mapping_environment_intf.h
|
||||
)
|
||||
|
||||
|
||||
set(MAPPING_H
|
||||
${MAPPING_DIR}/pkg_mapping.h
|
||||
${MAPPING_DIR}/ddl_helper.h
|
||||
)
|
||||
|
||||
set(MAPPING_CPP
|
||||
${MAPPING_DIR}/ddl_helper.cpp
|
||||
${MAPPING_DIR}/configuration/map_assignment.cpp
|
||||
${MAPPING_DIR}/configuration/map_configuration.cpp
|
||||
${MAPPING_DIR}/configuration/map_header.cpp
|
||||
${MAPPING_DIR}/configuration/map_source.cpp
|
||||
${MAPPING_DIR}/configuration/map_target.cpp
|
||||
${MAPPING_DIR}/configuration/map_transformation.cpp
|
||||
${MAPPING_DIR}/configuration/map_trigger.cpp
|
||||
${MAPPING_DIR}/engine/data_trigger.cpp
|
||||
${MAPPING_DIR}/engine/element.cpp
|
||||
${MAPPING_DIR}/engine/mapping_engine.cpp
|
||||
${MAPPING_DIR}/engine/periodic_trigger.cpp
|
||||
${MAPPING_DIR}/engine/signal_trigger.cpp
|
||||
${MAPPING_DIR}/engine/source.cpp
|
||||
${MAPPING_DIR}/engine/target.cpp
|
||||
${MAPPING_DIR}/engine/trigger.cpp
|
||||
)
|
||||
|
||||
set(MAPPING_CONFIGURATION_INSTALL ${MAPPING_CONFIGURATION_H})
|
||||
set(MAPPING_ENGINE_INSTALL ${MAPPING_ENGINE_H})
|
||||
set(MAPPING_INSTALL ${MAPPING_H})
|
||||
source_group(${MAPPING_DIR} FILES ${MAPPING_CONFIGURATION_H} ${MAPPING_ENGINE_H} ${MAPPING_H} ${MAPPING_CPP})
|
28
mapping/pkg_mapping.h
Normal file
28
mapping/pkg_mapping.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* @file
|
||||
* Description missing
|
||||
*
|
||||
* @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 MAPPING_MAPPING_HEADER_INCLUDED
|
||||
#define MAPPING_MAPPING_HEADER_INCLUDED
|
||||
|
||||
#include "ddl_helper.h"
|
||||
#include "configuration/map_configuration.h"
|
||||
#include "engine/mapping_engine.h"
|
||||
|
||||
#endif //MAPPING_MAPPING_HEADER_INCLUDED
|
Loading…
Add table
Add a link
Reference in a new issue