initial commit for github
This commit is contained in:
commit
60968612de
370 changed files with 68427 additions and 0 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue