Skip to content

Commit

Permalink
add c wrapper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amokfa committed Aug 13, 2022
1 parent 067abf5 commit bd2f6b7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions include/dbcppp/CApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ extern "C"
typedef struct {} dbcppp_Attribute;
typedef struct {} dbcppp_SignalType;
typedef struct {} dbcppp_Signal;
typedef struct {} dbcppp_SignalMultiplexerValue;
typedef struct {
size_t from;
size_t to;
} dbcppp_ValueRange;
typedef struct {} dbcppp_ValueEncodingDescription;

DBCPPP_API const dbcppp_Attribute* dbcppp_AttributeCreate(
Expand Down
2 changes: 1 addition & 1 deletion include/dbcppp/SignalMultiplexerValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace dbcppp
virtual std::unique_ptr<ISignalMultiplexerValue> Clone() const = 0;

virtual ~ISignalMultiplexerValue() = default;
virtual std::string SwitchName() const = 0;
virtual std::string& SwitchName() const = 0;
virtual const Range& ValueRanges_Get(std::size_t i) const = 0;
virtual uint64_t ValueRanges_Size() const = 0;

Expand Down
29 changes: 27 additions & 2 deletions src/libdbcppp/CApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern "C"
case IAttributeDefinition::EObjectType::Node: return dbcppp_EObjectType::dbcppp_ObjectType_Node;
case IAttributeDefinition::EObjectType::Message: return dbcppp_EObjectType::dbcppp_ObjectType_Message;
case IAttributeDefinition::EObjectType::Signal: return dbcppp_EObjectType::dbcppp_ObjectType_Signal;
default: return dbcppp_EObjectType::dbcppp_ObjectType_EnvironmentVariable;
default: return dbcppp_EObjectType::dbcppp_ObjectType_EnvironmentVariable;
}
}
DBCPPP_API dbcppp_EAttributeValueType dbcppp_AttributeValueType(const dbcppp_Attribute* attribute)
Expand Down Expand Up @@ -88,7 +88,7 @@ extern "C"
auto ai = reinterpret_cast<const AttributeImpl*>(attribute);
return std::get<std::string>(ai->Value()).c_str();
}

DBCPPP_API dbcppp_AttributeDefinition* dbcppp_AttributeDefinitionCreate(
const char* name
, dbcppp_EObjectType object_type
Expand Down Expand Up @@ -879,6 +879,31 @@ extern "C"
auto sigi = reinterpret_cast<const SignalImpl*>(sig);
return sigi->MultiplexerSwitchValue();
}
DBCPPP_API uint64_t dbcppp_SignalMultiplexerValues_Size(const dbcppp_Signal* sig)
{
auto sigi = reinterpret_cast<const SignalImpl*>(sig);
return sigi->SignalMultiplexerValues_Size();
}
DBCPPP_API const dbcppp_SignalMultiplexerValue* dbcppp_SignalMultiplexerValues_Get(const dbcppp_Signal* sig, uint64_t i)
{
auto sigi = reinterpret_cast<const SignalImpl*>(sig);
return reinterpret_cast<const dbcppp_SignalMultiplexerValue*>(&sigi->SignalMultiplexerValues_Get(i));
}
DBCPPP_API const char* dbcppp_SignalMultiplexerValue_SwitchName(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i)
{
auto sigi = reinterpret_cast<const ISignalMultiplexerValue*>(mux_val);
return sigi->SwitchName().c_str();
}
DBCPPP_API uint64_t dbcppp_ValueRanges_Size(const dbcppp_SignalMultiplexerValue* mux_val)
{
auto sigi = reinterpret_cast<const ISignalMultiplexerValue*>(mux_val);
return sigi->ValueRanges_Size();
}
DBCPPP_API const dbcppp_ValueRange* dbcppp_ValueRanges_Get(const dbcppp_SignalMultiplexerValue* mux_val, uint64_t i)
{
auto sigi = reinterpret_cast<const ISignalMultiplexerValue*>(mux_val);
return reinterpret_cast<const dbcppp_ValueRange*>(&sigi->ValueRanges_Get(i));
}
DBCPPP_API uint64_t dbcppp_SignalStartBit(const dbcppp_Signal* sig)
{
auto sigi = reinterpret_cast<const SignalImpl*>(sig);
Expand Down
2 changes: 1 addition & 1 deletion src/libdbcppp/SignalMultiplexerValueImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::unique_ptr<ISignalMultiplexerValue> SignalMultiplexerValueImpl::Clone() con
return std::make_unique<SignalMultiplexerValueImpl>(*this);
}

std::string SignalMultiplexerValueImpl::SwitchName() const
std::string& SignalMultiplexerValueImpl::SwitchName() const
{
return _switch_name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libdbcppp/SignalMultiplexerValueImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace dbcppp

virtual std::unique_ptr<ISignalMultiplexerValue> Clone() const override;

virtual std::string SwitchName() const override;
virtual std::string& SwitchName() const override;
virtual const Range& ValueRanges_Get(std::size_t i) const override;
virtual uint64_t ValueRanges_Size() const override;

Expand Down
4 changes: 2 additions & 2 deletions tests/Catch2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3751,7 +3751,7 @@ namespace Catch {

// 32kb for the alternate stack seems to be sufficient. However, this value
// is experimentally determined, so that's not guaranteed.
static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
static std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;

static SignalDefs signalDefs[] = {
{ SIGINT, "SIGINT - Terminal interrupt signal" },
Expand Down Expand Up @@ -3807,7 +3807,7 @@ namespace Catch {
bool FatalConditionHandler::isSet = false;
struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
stack_t FatalConditionHandler::oldSigStack = {};
char FatalConditionHandler::altStackMem[sigStackSize] = {};
char FatalConditionHandler::altStackMem[65536] = {};


} // namespace Catch
Expand Down

0 comments on commit bd2f6b7

Please sign in to comment.