mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-06 04:40:35 +08:00
Fixed fatal error handing (exceptions); MethodBinder moved into a separate file
This commit is contained in:
@@ -5,12 +5,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <typeinfo>
|
||||
#include <bitset>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
#include <uavcan/data_type.hpp>
|
||||
#include <uavcan/internal/linked_list.hpp>
|
||||
#include <uavcan/internal/impl_constants.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
@@ -127,7 +129,7 @@ struct DefaultDataTypeRegistrator
|
||||
if (res != GlobalDataTypeRegistry::RegistResultOk)
|
||||
{
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
throw std::logic_error("Type registration failed");
|
||||
throw std::runtime_error("Type registration failed");
|
||||
#else
|
||||
assert(0);
|
||||
std::abort();
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <uavcan/internal/impl_constants.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
@@ -20,7 +22,7 @@ class LazyConstructor
|
||||
void failure() const
|
||||
{
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
throw std::logic_error(typeid(*this).name());
|
||||
throw std::runtime_error(typeid(*this).name());
|
||||
#else
|
||||
assert(0);
|
||||
std::abort();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <uavcan/internal/impl_constants.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
template <typename ObjectPtr, typename MemFunPtr>
|
||||
class MethodBinder
|
||||
{
|
||||
ObjectPtr obj_;
|
||||
MemFunPtr fun_;
|
||||
|
||||
public:
|
||||
MethodBinder(ObjectPtr o, MemFunPtr f)
|
||||
: obj_(o)
|
||||
, fun_(f)
|
||||
{
|
||||
if (!o || !f)
|
||||
{
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
throw std::runtime_error(typeid(*this).name());
|
||||
#else
|
||||
assert(0);
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void operator()() { (obj_->*fun_)(); }
|
||||
|
||||
template <typename Par1>
|
||||
void operator()(Par1 p1) { (obj_->*fun_)(p1); }
|
||||
|
||||
template <typename Par1, typename Par2>
|
||||
void operator()(Par1 p1, Par2 p2) { (obj_->*fun_)(p1, p2); }
|
||||
};
|
||||
|
||||
}
|
||||
@@ -74,27 +74,6 @@ template<bool> struct BooleanType { };
|
||||
typedef BooleanType<true> TrueType;
|
||||
typedef BooleanType<false> FalseType;
|
||||
|
||||
/**
|
||||
* Makeshift binder
|
||||
*/
|
||||
template <typename ObjectPtr, typename MemFunPtr>
|
||||
class MethodBinder
|
||||
{
|
||||
ObjectPtr obj_;
|
||||
MemFunPtr fun_;
|
||||
|
||||
public:
|
||||
MethodBinder(ObjectPtr o, MemFunPtr f) : obj_(o), fun_(f) { }
|
||||
|
||||
void operator()() { (obj_->*fun_)(); }
|
||||
|
||||
template <typename Par1>
|
||||
void operator()(Par1 p1) { (obj_->*fun_)(p1); }
|
||||
|
||||
template <typename Par1, typename Par2>
|
||||
void operator()(Par1 p1, Par2 p2) { (obj_->*fun_)(p1, p2); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/// Ensure that conditional comilation macros are present
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/timer.hpp>
|
||||
#include <uavcan/internal/method_binder.hpp>
|
||||
#include "common.hpp"
|
||||
#include "transport/can/iface_mock.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user