Style fixes

This commit is contained in:
Pavel Kirienko
2014-02-19 17:55:18 +04:00
parent 195dca3696
commit 4f49d61de6
21 changed files with 120 additions and 142 deletions
+6 -9
View File
@@ -46,22 +46,20 @@ class Map : Noncopyable
IsDynamicallyAllocatable<KVGroup>::check();
}
static KVGroup* instantiate(IAllocator* allocator)
static KVGroup* instantiate(IAllocator& allocator)
{
assert(allocator);
void* const praw = allocator->allocate(sizeof(KVGroup));
void* const praw = allocator.allocate(sizeof(KVGroup));
if (praw == NULL)
return NULL;
return new (praw) KVGroup();
}
static void destroy(KVGroup*& obj, IAllocator* allocator)
static void destroy(KVGroup*& obj, IAllocator& allocator)
{
assert(allocator);
if (obj != NULL)
{
obj->~KVGroup();
allocator->deallocate(obj);
allocator.deallocate(obj);
obj = NULL;
}
}
@@ -77,7 +75,7 @@ class Map : Noncopyable
#pragma pack(pop)
LinkedListRoot<KVGroup> list_;
IAllocator* const allocator_;
IAllocator& allocator_;
KVPair static_[NUM_STATIC_ENTRIES];
KVPair* find(const Key& key)
@@ -176,10 +174,9 @@ class Map : Noncopyable
bool operator=(const Map&);
public:
Map(IAllocator* allocator)
Map(IAllocator& allocator)
: allocator_(allocator)
{
assert(allocator);
assert(Key() == Key());
}
@@ -53,7 +53,7 @@ public:
IsDynamicallyAllocatable<Entry>::check();
}
static void destroy(Entry*& obj, IAllocator* allocator);
static void destroy(Entry*& obj, IAllocator& allocator);
bool isExpired(uint64_t monotonic_timestamp) const { return monotonic_timestamp > monotonic_deadline; }
@@ -96,10 +96,7 @@ public:
: allocator_(allocator)
, sysclock_(sysclock)
, rejected_frames_cnt_(0)
{
assert(allocator);
assert(sysclock);
}
{ }
~CanTxQueue();
@@ -122,8 +119,8 @@ public:
enum { MAX_IFACES = 3 };
private:
ICanDriver* const driver_;
ISystemClock* const sysclock_;
ICanDriver& driver_;
ISystemClock& sysclock_;
CanTxQueue tx_queues_[MAX_IFACES];
@@ -137,19 +134,16 @@ private:
uint64_t getTimeUntilMonotonicDeadline(uint64_t monotonic_deadline) const;
public:
CanIOManager(ICanDriver* driver, IAllocator* allocator, ISystemClock* sysclock)
CanIOManager(ICanDriver& driver, IAllocator& allocator, ISystemClock& sysclock)
: driver_(driver)
, sysclock_(sysclock)
{
assert(driver);
assert(allocator);
assert(sysclock);
assert(driver->getNumIfaces() <= MAX_IFACES);
assert(driver.getNumIfaces() <= MAX_IFACES);
// We can't initialize member array with non-default constructors in C++03
for (int i = 0; i < MAX_IFACES; i++)
{
tx_queues_[i].~CanTxQueue();
new (tx_queues_ + i) CanTxQueue(allocator, sysclock);
new (tx_queues_ + i) CanTxQueue(&allocator, &sysclock);
}
}
@@ -17,8 +17,8 @@ namespace uavcan
class Dispatcher : Noncopyable
{
CanIOManager canio_;
ISystemClock* const sysclock_;
IOutgoingTransferRegistry* const outgoing_transfer_reg_;
ISystemClock& sysclock_;
IOutgoingTransferRegistry& outgoing_transfer_reg_;
class ListenerRegister
{
@@ -32,7 +32,7 @@ class Dispatcher : Noncopyable
bool operator()(const TransferListenerBase* listener) const
{
assert(listener);
return id_ > listener->getDataTypeDescriptor()->id;
return id_ > listener->getDataTypeDescriptor().id;
}
};
@@ -56,18 +56,13 @@ class Dispatcher : Noncopyable
void handleFrame(const CanRxFrame& can_frame);
public:
Dispatcher(ICanDriver* driver, IAllocator* allocator, ISystemClock* sysclock, IOutgoingTransferRegistry* otr,
Dispatcher(ICanDriver& driver, IAllocator& allocator, ISystemClock& sysclock, IOutgoingTransferRegistry& otr,
NodeID self_node_id)
: canio_(driver, allocator, sysclock)
, sysclock_(sysclock)
, outgoing_transfer_reg_(otr)
, self_node_id_(self_node_id)
{
assert(driver);
assert(allocator);
assert(sysclock);
assert(otr);
}
{ }
int spin(uint64_t monotonic_deadline);
@@ -91,7 +86,7 @@ public:
int getNumServiceRequestListeners() const { return lsrv_req_.getNumEntries(); }
int getNumServiceResponseListeners() const { return lsrv_resp_.getNumEntries(); }
IOutgoingTransferRegistry* getOutgoingTransferRegistry() { return outgoing_transfer_reg_; }
IOutgoingTransferRegistry& getOutgoingTransferRegistry() { return outgoing_transfer_reg_; }
NodeID getSelfNodeID() const { return self_node_id_; }
};
@@ -91,7 +91,7 @@ class OutgoingTransferRegistry : public IOutgoingTransferRegistry, Noncopyable
Map<OutgoingTransferRegistryKey, Value, NUM_STATIC_ENTRIES> map_;
public:
OutgoingTransferRegistry(IAllocator* allocator)
OutgoingTransferRegistry(IAllocator& allocator)
: map_(allocator)
{ }
@@ -101,8 +101,8 @@ class DynamicTransferBuffer : public TransferBufferManagerEntry, public LinkedLi
enum { SIZE = MEM_POOL_BLOCK_SIZE - sizeof(LinkedListNode<Block>) };
uint8_t data[SIZE];
static Block* instantiate(IAllocator* allocator);
static void destroy(Block*& obj, IAllocator* allocator);
static Block* instantiate(IAllocator& allocator);
static void destroy(Block*& obj, IAllocator& allocator);
void read(uint8_t*& outptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_read);
@@ -110,7 +110,7 @@ class DynamicTransferBuffer : public TransferBufferManagerEntry, public LinkedLi
unsigned int& total_offset, unsigned int& left_to_write);
};
IAllocator* allocator_;
IAllocator& allocator_;
LinkedListRoot<Block> blocks_; // Blocks are ordered from lower to higher buffer offset
unsigned int max_write_pos_;
const unsigned int max_size_;
@@ -118,7 +118,7 @@ class DynamicTransferBuffer : public TransferBufferManagerEntry, public LinkedLi
void resetImpl();
public:
DynamicTransferBuffer(IAllocator* allocator, unsigned int max_size)
DynamicTransferBuffer(IAllocator& allocator, unsigned int max_size)
: allocator_(allocator)
, max_write_pos_(0)
, max_size_(max_size)
@@ -133,8 +133,8 @@ public:
resetImpl();
}
static DynamicTransferBuffer* instantiate(IAllocator* allocator, unsigned int max_size);
static void destroy(DynamicTransferBuffer*& obj, IAllocator* allocator);
static DynamicTransferBuffer* instantiate(IAllocator& allocator, unsigned int max_size);
static void destroy(DynamicTransferBuffer*& obj, IAllocator& allocator);
int read(unsigned int offset, uint8_t* data, unsigned int len) const;
int write(unsigned int offset, const uint8_t* data, unsigned int len);
@@ -247,20 +247,19 @@ public:
*/
class TransferBufferAccessor
{
ITransferBufferManager* const bufmgr_;
ITransferBufferManager& bufmgr_;
const TransferBufferManagerKey key_;
public:
TransferBufferAccessor(ITransferBufferManager* bufmgr, TransferBufferManagerKey key)
TransferBufferAccessor(ITransferBufferManager& bufmgr, TransferBufferManagerKey key)
: bufmgr_(bufmgr)
, key_(key)
{
assert(bufmgr);
assert(!key.isEmpty());
}
ITransferBuffer* access() { return bufmgr_->access(key_); }
ITransferBuffer* create() { return bufmgr_->create(key_); }
void remove() { bufmgr_->remove(key_); }
ITransferBuffer* access() { return bufmgr_.access(key_); }
ITransferBuffer* create() { return bufmgr_.create(key_); }
void remove() { bufmgr_.remove(key_); }
};
/**
@@ -273,7 +272,7 @@ class TransferBufferManager : public ITransferBufferManager, Noncopyable
StaticBufferType static_buffers_[NUM_STATIC_BUFS];
LinkedListRoot<DynamicTransferBuffer> dynamic_buffers_;
IAllocator* const allocator_;
IAllocator& allocator_;
StaticBufferType* findFirstStatic(const TransferBufferManagerKey& key)
{
@@ -331,10 +330,9 @@ class TransferBufferManager : public ITransferBufferManager, Noncopyable
}
public:
TransferBufferManager(IAllocator* allocator)
TransferBufferManager(IAllocator& allocator)
: allocator_(allocator)
{
assert(allocator);
StaticAssert<(MAX_BUF_SIZE > 0)>::check();
StaticAssert<(NUM_STATIC_BUFS > 0)>::check();
}
@@ -440,7 +438,8 @@ template <>
class TransferBufferManager<0, 0> : public ITransferBufferManager
{
public:
TransferBufferManager(IAllocator* allocator)
TransferBufferManager() { }
TransferBufferManager(IAllocator& allocator)
{
(void)allocator;
}
@@ -87,18 +87,16 @@ public:
*/
class TransferListenerBase : public LinkedListNode<TransferListenerBase>
{
const DataTypeDescriptor* const data_type_;
const DataTypeDescriptor& data_type_;
const Crc16 crc_base_; ///< Pre-initialized with data type hash, thus constant
bool checkPayloadCrc(const uint16_t compare_with, const ITransferBuffer& tbb) const;
protected:
TransferListenerBase(const DataTypeDescriptor* data_type)
TransferListenerBase(const DataTypeDescriptor& data_type)
: data_type_(data_type)
, crc_base_(data_type->hash.value, DataTypeHash::NUM_BYTES)
{
assert(data_type);
}
, crc_base_(data_type.hash.value, DataTypeHash::NUM_BYTES)
{ }
virtual ~TransferListenerBase() { }
@@ -107,7 +105,7 @@ protected:
virtual void handleIncomingTransfer(IncomingTransfer& transfer) = 0;
public:
const DataTypeDescriptor* getDataTypeDescriptor() const { return data_type_; }
const DataTypeDescriptor& getDataTypeDescriptor() const { return data_type_; }
virtual void handleFrame(const RxFrame& frame) = 0;
virtual void cleanup(uint64_t ts_monotonic) = 0;
@@ -141,7 +139,7 @@ class TransferListener : public TransferListenerBase, Noncopyable
return;
}
}
TransferBufferAccessor tba(&bufmgr_, key);
TransferBufferAccessor tba(bufmgr_, key);
handleReception(*recv, frame, tba);
}
@@ -182,7 +180,7 @@ class TransferListener : public TransferListenerBase, Noncopyable
}
public:
TransferListener(const DataTypeDescriptor* data_type, IAllocator* allocator)
TransferListener(const DataTypeDescriptor& data_type, IAllocator& allocator)
: TransferListenerBase(data_type)
, bufmgr_(allocator)
, receivers_(allocator)
+12 -13
View File
@@ -26,13 +26,12 @@ std::string CanRxFrame::toString(StringRepresentation mode) const
/*
* CanTxQueue::Entry
*/
void CanTxQueue::Entry::destroy(Entry*& obj, IAllocator* allocator)
void CanTxQueue::Entry::destroy(Entry*& obj, IAllocator& allocator)
{
assert(allocator);
if (obj != NULL)
{
obj->~Entry();
allocator->deallocate(obj);
allocator.deallocate(obj);
obj = NULL;
}
}
@@ -181,7 +180,7 @@ void CanTxQueue::remove(Entry*& entry)
return;
}
queue_.remove(entry);
Entry::destroy(entry, allocator_);
Entry::destroy(entry, *allocator_);
}
bool CanTxQueue::topPriorityHigherOrEqual(const CanFrame& rhs_frame) const
@@ -198,13 +197,13 @@ bool CanTxQueue::topPriorityHigherOrEqual(const CanFrame& rhs_frame) const
int CanIOManager::sendToIface(int iface_index, const CanFrame& frame, uint64_t monotonic_tx_deadline)
{
assert(iface_index >= 0 && iface_index < MAX_IFACES);
ICanIface* const iface = driver_->getIface(iface_index);
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL)
{
assert(0); // Nonexistent interface
return -1;
}
const uint64_t timestamp = sysclock_->getMonotonicMicroseconds();
const uint64_t timestamp = sysclock_.getMonotonicMicroseconds();
const uint64_t timeout = (timestamp >= monotonic_tx_deadline) ? 0 : (monotonic_tx_deadline - timestamp);
const int res = iface->send(frame, timeout);
if (res != 1)
@@ -240,20 +239,20 @@ int CanIOManager::makePendingTxMask() const
uint64_t CanIOManager::getTimeUntilMonotonicDeadline(uint64_t monotonic_deadline) const
{
const uint64_t timestamp = sysclock_->getMonotonicMicroseconds();
const uint64_t timestamp = sysclock_.getMonotonicMicroseconds();
return (timestamp >= monotonic_deadline) ? 0 : (monotonic_deadline - timestamp);
}
int CanIOManager::getNumIfaces() const
{
const int num = driver_->getNumIfaces();
const int num = driver_.getNumIfaces();
assert(num > 0 && num <= MAX_IFACES);
return std::min(std::max(num, 0), (int)MAX_IFACES);
}
uint64_t CanIOManager::getNumErrors(int iface_index) const
{
ICanIface* const iface = driver_->getIface(iface_index);
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL || iface_index >= MAX_IFACES || iface_index < 0)
{
assert(0);
@@ -285,7 +284,7 @@ int CanIOManager::send(const CanFrame& frame, uint64_t monotonic_tx_deadline, ui
const uint64_t timeout = getTimeUntilMonotonicDeadline(monotonic_blocking_deadline);
{
int read_mask = 0;
const int select_res = driver_->select(write_mask, read_mask, timeout);
const int select_res = driver_.select(write_mask, read_mask, timeout);
if (select_res < 0)
return select_res;
}
@@ -321,7 +320,7 @@ int CanIOManager::send(const CanFrame& frame, uint64_t monotonic_tx_deadline, ui
// Timeout. Enqueue the frame if wasn't transmitted and leave.
if (write_mask == 0 || timeout == 0)
{
if ((timeout > 0) && (sysclock_->getMonotonicMicroseconds() < monotonic_blocking_deadline))
if ((timeout > 0) && (sysclock_.getMonotonicMicroseconds() < monotonic_blocking_deadline))
{
UAVCAN_TRACE("CanIOManager", "Send: Premature timeout in select(), will try again");
continue;
@@ -347,7 +346,7 @@ int CanIOManager::receive(CanRxFrame& frame, uint64_t monotonic_deadline)
int read_mask = (1 << num_ifaces) - 1;
const uint64_t timeout = getTimeUntilMonotonicDeadline(monotonic_deadline);
{
const int select_res = driver_->select(write_mask, read_mask, timeout);
const int select_res = driver_.select(write_mask, read_mask, timeout);
if (select_res < 0)
return select_res;
}
@@ -364,7 +363,7 @@ int CanIOManager::receive(CanRxFrame& frame, uint64_t monotonic_deadline)
{
if (read_mask & (1 << i))
{
ICanIface* const iface = driver_->getIface(i);
ICanIface* const iface = driver_.getIface(i);
if (iface == NULL)
{
assert(0); // Nonexistent interface
+9 -9
View File
@@ -18,13 +18,13 @@ bool Dispatcher::ListenerRegister::add(TransferListenerBase* listener, Mode mode
TransferListenerBase* p = list_.get();
while (p)
{
if (p->getDataTypeDescriptor()->id == listener->getDataTypeDescriptor()->id)
if (p->getDataTypeDescriptor().id == listener->getDataTypeDescriptor().id)
return false;
p = p->getNextListNode();
}
}
// Objective is to arrange entries by Data Type ID in ascending order from root.
list_.insertBefore(listener, DataTypeIDInsertionComparator(listener->getDataTypeDescriptor()->id));
list_.insertBefore(listener, DataTypeIDInsertionComparator(listener->getDataTypeDescriptor().id));
return true;
}
@@ -48,9 +48,9 @@ void Dispatcher::ListenerRegister::handleFrame(const RxFrame& frame)
TransferListenerBase* p = list_.get();
while (p)
{
if (p->getDataTypeDescriptor()->id == frame.getDataTypeID())
if (p->getDataTypeDescriptor().id == frame.getDataTypeID())
p->handleFrame(frame);
else if (p->getDataTypeDescriptor()->id < frame.getDataTypeID()) // Listeners are ordered by data type id!
else if (p->getDataTypeDescriptor().id < frame.getDataTypeID()) // Listeners are ordered by data type id!
break;
p = p->getNextListNode();
}
@@ -109,7 +109,7 @@ int Dispatcher::spin(uint64_t monotonic_deadline)
handleFrame(frame);
}
}
while (sysclock_->getMonotonicMicroseconds() < monotonic_deadline);
while (sysclock_.getMonotonicMicroseconds() < monotonic_deadline);
return num_frames_processed;
}
@@ -137,7 +137,7 @@ int Dispatcher::send(const Frame& frame, uint64_t monotonic_tx_deadline, uint64_
void Dispatcher::cleanup(uint64_t ts_monotonic)
{
outgoing_transfer_reg_->cleanup(ts_monotonic);
outgoing_transfer_reg_.cleanup(ts_monotonic);
lmsg_.cleanup(ts_monotonic);
lsrv_req_.cleanup(ts_monotonic);
lsrv_resp_.cleanup(ts_monotonic);
@@ -145,7 +145,7 @@ void Dispatcher::cleanup(uint64_t ts_monotonic)
bool Dispatcher::registerMessageListener(TransferListenerBase* listener)
{
if (listener->getDataTypeDescriptor()->kind != DATA_TYPE_KIND_MESSAGE)
if (listener->getDataTypeDescriptor().kind != DATA_TYPE_KIND_MESSAGE)
{
assert(0);
return false;
@@ -155,7 +155,7 @@ bool Dispatcher::registerMessageListener(TransferListenerBase* listener)
bool Dispatcher::registerServiceRequestListener(TransferListenerBase* listener)
{
if (listener->getDataTypeDescriptor()->kind != DATA_TYPE_KIND_SERVICE)
if (listener->getDataTypeDescriptor().kind != DATA_TYPE_KIND_SERVICE)
{
assert(0);
return false;
@@ -165,7 +165,7 @@ bool Dispatcher::registerServiceRequestListener(TransferListenerBase* listener)
bool Dispatcher::registerServiceResponseListener(TransferListenerBase* listener)
{
if (listener->getDataTypeDescriptor()->kind != DATA_TYPE_KIND_SERVICE)
if (listener->getDataTypeDescriptor().kind != DATA_TYPE_KIND_SERVICE)
{
assert(0);
return false;
+8 -12
View File
@@ -23,22 +23,20 @@ std::string TransferBufferManagerKey::toString() const
/*
* DynamicTransferBuffer::Block
*/
DynamicTransferBuffer::Block* DynamicTransferBuffer::Block::instantiate(IAllocator* allocator)
DynamicTransferBuffer::Block* DynamicTransferBuffer::Block::instantiate(IAllocator& allocator)
{
assert(allocator);
void* const praw = allocator->allocate(sizeof(Block));
void* const praw = allocator.allocate(sizeof(Block));
if (praw == NULL)
return NULL;
return new (praw) Block;
}
void DynamicTransferBuffer::Block::destroy(Block*& obj, IAllocator* allocator)
void DynamicTransferBuffer::Block::destroy(Block*& obj, IAllocator& allocator)
{
assert(allocator);
if (obj != NULL)
{
obj->~Block();
allocator->deallocate(obj);
allocator.deallocate(obj);
obj = NULL;
}
}
@@ -74,22 +72,20 @@ void DynamicTransferBuffer::Block::write(const uint8_t*& inptr, unsigned int tar
/*
* DynamicTransferBuffer
*/
DynamicTransferBuffer* DynamicTransferBuffer::instantiate(IAllocator* allocator, unsigned int max_size)
DynamicTransferBuffer* DynamicTransferBuffer::instantiate(IAllocator& allocator, unsigned int max_size)
{
assert(allocator);
void* const praw = allocator->allocate(sizeof(DynamicTransferBuffer));
void* const praw = allocator.allocate(sizeof(DynamicTransferBuffer));
if (praw == NULL)
return NULL;
return new (praw) DynamicTransferBuffer(allocator, max_size);
}
void DynamicTransferBuffer::destroy(DynamicTransferBuffer*& obj, IAllocator* allocator)
void DynamicTransferBuffer::destroy(DynamicTransferBuffer*& obj, IAllocator& allocator)
{
assert(allocator);
if (obj != NULL)
{
obj->~DynamicTransferBuffer();
allocator->deallocate(obj);
allocator.deallocate(obj);
obj = NULL;
}
}
+1 -1
View File
@@ -92,7 +92,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, uint64_t monot
assert(monotonic_tx_deadline > 0);
const uint64_t otr_deadline = monotonic_tx_deadline + max_transfer_interval_;
TransferID* const tid = dispatcher_.getOutgoingTransferRegistry()->accessOrCreate(otr_key, otr_deadline);
TransferID* const tid = dispatcher_.getOutgoingTransferRegistry().accessOrCreate(otr_key, otr_deadline);
if (tid == NULL)
{
UAVCAN_TRACE("TransferSender", "OTR access failure, dtid=%i tt=%i", int(data_type_.id), int(transfer_type));
+1 -1
View File
@@ -35,7 +35,7 @@ TEST(Map, Basic)
poolmgr.addPool(&pool);
typedef Map<std::string, std::string, 2> MapType;
std::auto_ptr<MapType> map(new MapType(&poolmgr));
std::auto_ptr<MapType> map(new MapType(poolmgr));
// Empty
ASSERT_FALSE(map->access("hi"));
+2 -2
View File
@@ -31,7 +31,7 @@ TEST(CanIOManager, Reception)
CanDriverMock driver(2, clockmock);
// IO Manager
uavcan::CanIOManager iomgr(&driver, &poolmgr, &clockmock);
uavcan::CanIOManager iomgr(driver, poolmgr, clockmock);
ASSERT_EQ(2, iomgr.getNumIfaces());
/*
@@ -115,7 +115,7 @@ TEST(CanIOManager, Transmission)
CanDriverMock driver(2, clockmock);
// IO Manager
CanIOManager iomgr(&driver, &poolmgr, &clockmock);
CanIOManager iomgr(driver, poolmgr, clockmock);
ASSERT_EQ(2, iomgr.getNumIfaces());
const int ALL_IFACES_MASK = 3;
+12 -12
View File
@@ -41,9 +41,9 @@ TEST(Dispatcher, Reception)
SystemClockMock clockmock(100);
CanDriverMock driver(2, clockmock);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(&poolmgr);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
uavcan::Dispatcher dispatcher(&driver, &poolmgr, &clockmock, &out_trans_reg, SELF_NODE_ID);
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg, SELF_NODE_ID);
DispatcherTransferEmulator emulator(driver, SELF_NODE_ID);
@@ -63,12 +63,12 @@ TEST(Dispatcher, Reception)
static const int NUM_SUBSCRIBERS = 6;
SubscriberPtr subscribers[NUM_SUBSCRIBERS] =
{
SubscriberPtr(new Subscriber(TYPES + 0, &poolmgr)), // msg
SubscriberPtr(new Subscriber(TYPES + 0, &poolmgr)), // msg // Two similar, yes
SubscriberPtr(new Subscriber(TYPES + 1, &poolmgr)), // msg
SubscriberPtr(new Subscriber(TYPES + 2, &poolmgr)), // srv
SubscriberPtr(new Subscriber(TYPES + 3, &poolmgr)), // srv
SubscriberPtr(new Subscriber(TYPES + 3, &poolmgr)) // srv // Repeat again
SubscriberPtr(new Subscriber(TYPES[0], poolmgr)), // msg
SubscriberPtr(new Subscriber(TYPES[0], poolmgr)), // msg // Two similar, yes
SubscriberPtr(new Subscriber(TYPES[1], poolmgr)), // msg
SubscriberPtr(new Subscriber(TYPES[2], poolmgr)), // srv
SubscriberPtr(new Subscriber(TYPES[3], poolmgr)), // srv
SubscriberPtr(new Subscriber(TYPES[3], poolmgr)) // srv // Repeat again
};
static const std::string DATA[6] =
@@ -190,9 +190,9 @@ TEST(Dispatcher, Transmission)
SystemClockMock clockmock(100);
CanDriverMock driver(2, clockmock);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(&poolmgr);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
uavcan::Dispatcher dispatcher(&driver, &poolmgr, &clockmock, &out_trans_reg, SELF_NODE_ID);
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg, SELF_NODE_ID);
/*
* Transmission
@@ -227,9 +227,9 @@ TEST(Dispatcher, Spin)
SystemClockMock clockmock(100);
CanDriverMock driver(2, clockmock);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(&poolmgr);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
uavcan::Dispatcher dispatcher(&driver, &poolmgr, &clockmock, &out_trans_reg, SELF_NODE_ID);
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg, SELF_NODE_ID);
clockmock.monotonic_auto_advance = 100;
@@ -69,11 +69,11 @@ TEST(MultiFrameIncomingTransfer, Basic)
using uavcan::MultiFrameIncomingTransfer;
uavcan::PoolManager<1> poolmgr; // We don't need dynamic memory
uavcan::TransferBufferManager<256, 1> bufmgr(&poolmgr);
uavcan::TransferBufferManager<256, 1> bufmgr(poolmgr);
const RxFrame frame = makeFrame();
uavcan::TransferBufferManagerKey bufmgr_key(frame.getSrcNodeID(), frame.getTransferType());
uavcan::TransferBufferAccessor tba(&bufmgr, bufmgr_key);
uavcan::TransferBufferAccessor tba(bufmgr, bufmgr_key);
MultiFrameIncomingTransfer it(frame.getMonotonicTimestamp(), frame.getUtcTimestamp(), frame, tba);
@@ -11,7 +11,7 @@ TEST(OutgoingTransferRegistry, Basic)
{
using uavcan::OutgoingTransferRegistryKey;
uavcan::PoolManager<1> poolmgr; // Empty
uavcan::OutgoingTransferRegistry<4> otr(&poolmgr);
uavcan::OutgoingTransferRegistry<4> otr(poolmgr);
otr.cleanup(1000);
+3 -3
View File
@@ -138,7 +138,7 @@ TEST(DynamicTransferBuffer, Basic)
uavcan::PoolManager<2> poolmgr;
poolmgr.addPool(&pool);
DynamicTransferBuffer buf(&poolmgr, MAX_SIZE);
DynamicTransferBuffer buf(poolmgr, MAX_SIZE);
uint8_t local_buffer[TEST_BUFFER_SIZE * 2];
const uint8_t* const test_data_ptr = reinterpret_cast<const uint8_t*>(TEST_DATA.c_str());
@@ -239,7 +239,7 @@ TEST(TransferBufferManager, Basic)
poolmgr.addPool(&pool);
typedef TransferBufferManager<MGR_MAX_BUFFER_SIZE, 2> TransferBufferManagerType;
std::auto_ptr<TransferBufferManagerType> mgr(new TransferBufferManagerType(&poolmgr));
std::auto_ptr<TransferBufferManagerType> mgr(new TransferBufferManagerType(poolmgr));
// Empty
ASSERT_FALSE(mgr->access(TransferBufferManagerKey(0, uavcan::TRANSFER_TYPE_MESSAGE_UNICAST)));
@@ -342,7 +342,7 @@ TEST(TransferBufferManager, Basic)
TEST(TransferBufferManager, EmptySpecialization)
{
uavcan::TransferBufferManager<0, 0> mgr(NULL);
uavcan::TransferBufferManager<0, 0> mgr;
(void)mgr;
ASSERT_GE(sizeof(void*), sizeof(mgr));
}
@@ -39,7 +39,7 @@ TEST(TransferListener, BasicMFT)
uavcan::PoolManager<1> poolmgr;
poolmgr.addPool(&pool);
TestSubscriber<256, 1, 1> subscriber(&type, &poolmgr);
TestSubscriber<256, 1, 1> subscriber(type, poolmgr);
/*
* Test data
@@ -92,7 +92,7 @@ TEST(TransferListener, CrcFailure)
type.hash.value[i] = i | (i << 4);
uavcan::PoolManager<1> poolmgr; // No dynamic memory
TestSubscriber<256, 2, 2> subscriber(&type, &poolmgr); // Static buffer only, 2 entries
TestSubscriber<256, 2, 2> subscriber(type, poolmgr); // Static buffer only, 2 entries
/*
* Generating transfers with damaged payload (CRC is not valid)
@@ -137,7 +137,7 @@ TEST(TransferListener, BasicSFT)
type.hash.value[i] = i | (i << 4);
uavcan::PoolManager<1> poolmgr; // No dynamic memory. At all.
TestSubscriber<0, 0, 5> subscriber(&type, &poolmgr); // Max buf size is 0, i.e. SFT-only
TestSubscriber<0, 0, 5> subscriber(type, poolmgr); // Max buf size is 0, i.e. SFT-only
TransferListenerEmulator emulator(subscriber, type);
const Transfer transfers[] =
@@ -174,7 +174,7 @@ TEST(TransferListener, Cleanup)
type.hash.value[i] = i | (i << 4);
uavcan::PoolManager<1> poolmgr; // No dynamic memory
TestSubscriber<256, 1, 2> subscriber(&type, &poolmgr); // Static buffer only, 1 entry
TestSubscriber<256, 1, 2> subscriber(type, poolmgr); // Static buffer only, 1 entry
/*
* Generating transfers
@@ -230,7 +230,7 @@ TEST(TransferListener, MaximumTransferLength)
type.hash.value[i] = i | (i << 4);
uavcan::PoolManager<1> poolmgr;
TestSubscriber<uavcan::MAX_TRANSFER_PAYLOAD_LEN * 2, 2, 2> subscriber(&type, &poolmgr);
TestSubscriber<uavcan::MAX_TRANSFER_PAYLOAD_LEN * 2, 2, 2> subscriber(type, poolmgr);
static const std::string DATA_OK(uavcan::MAX_TRANSFER_PAYLOAD_LEN, 'z');
+12 -12
View File
@@ -52,7 +52,7 @@ struct Context
uavcan::TransferBufferManager<BUFSIZE, 1> bufmgr;
Context()
: bufmgr(&poolmgr)
: bufmgr(poolmgr)
{
assert(poolmgr.allocate(1) == NULL);
}
@@ -96,7 +96,7 @@ TEST(TransferReceiver, Basic)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
/*
* Empty
@@ -216,7 +216,7 @@ TEST(TransferReceiver, OutOfBufferSpace_32bytes)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
/*
* Simple transfer, maximum buffer length
@@ -251,7 +251,7 @@ TEST(TransferReceiver, UnterminatedTransfer)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
std::string content;
for (int i = 0; i <= uavcan::Frame::INDEX_MAX; i++)
@@ -272,7 +272,7 @@ TEST(TransferReceiver, OutOfOrderFrames)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "12345678", 0, false, 7, 100000000), bk));
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "--------", 3, false, 7, 100000100), bk)); // Out of order
@@ -293,7 +293,7 @@ TEST(TransferReceiver, IntervalMeasurement)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
static const int INTERVAL = 1000;
uavcan::TransferID tid;
@@ -323,7 +323,7 @@ TEST(TransferReceiver, Restart)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
/*
* This transfer looks complete, but must be ignored because of large delay after the first frame
@@ -365,7 +365,7 @@ TEST(TransferReceiver, UtcTransferTimestamping)
RxFrameGenerator gen(789, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferReceiver& rcv = context.receiver;
uavcan::ITransferBufferManager& bufmgr = context.bufmgr;
uavcan::TransferBufferAccessor bk(&context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
uavcan::TransferBufferAccessor bk(context.bufmgr, RxFrameGenerator::DEFAULT_KEY);
/*
* Zero UTC timestamp must be preserved
@@ -431,7 +431,7 @@ TEST(TransferReceiver, HeaderParsing)
{
gen.bufmgr_key =
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferBufferAccessor bk1(&context.bufmgr, gen.bufmgr_key);
uavcan::TransferBufferAccessor bk1(context.bufmgr, gen.bufmgr_key);
CHECK_NOT_COMPLETE(rcv.addFrame(gen(0, "12345678", 0, false, tid.get(), 1), bk1));
CHECK_COMPLETE( rcv.addFrame(gen(0, "abcd", 1, true, tid.get(), 2), bk1));
@@ -450,7 +450,7 @@ TEST(TransferReceiver, HeaderParsing)
{
gen.bufmgr_key =
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), ADDRESSED_TRANSFER_TYPES[i]);
uavcan::TransferBufferAccessor bk2(&context.bufmgr, gen.bufmgr_key);
uavcan::TransferBufferAccessor bk2(context.bufmgr, gen.bufmgr_key);
const uint64_t ts_monotonic = i + 10;
@@ -473,7 +473,7 @@ TEST(TransferReceiver, HeaderParsing)
{
gen.bufmgr_key =
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST);
uavcan::TransferBufferAccessor bk(&context.bufmgr, gen.bufmgr_key);
uavcan::TransferBufferAccessor bk(context.bufmgr, gen.bufmgr_key);
const uavcan::RxFrame frame = gen(0, SFT_PAYLOAD_BROADCAST, 0, true, tid.get(), 1000);
@@ -493,7 +493,7 @@ TEST(TransferReceiver, HeaderParsing)
{
gen.bufmgr_key =
uavcan::TransferBufferManagerKey(gen.bufmgr_key.getNodeID(), ADDRESSED_TRANSFER_TYPES[i]);
uavcan::TransferBufferAccessor bk(&context.bufmgr, gen.bufmgr_key);
uavcan::TransferBufferAccessor bk(context.bufmgr, gen.bufmgr_key);
const uavcan::RxFrame frame = gen(0, SFT_PAYLOAD_UNICAST, 0, true, tid.get(), i + 10000);
+6 -6
View File
@@ -33,12 +33,12 @@ TEST(TransferSender, Basic)
SystemClockMock clockmock(100);
CanDriverMock driver(2, clockmock);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(&poolmgr);
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
static const uavcan::NodeID TX_NODE_ID(64);
static const uavcan::NodeID RX_NODE_ID(65);
uavcan::Dispatcher dispatcher_tx(&driver, &poolmgr, &clockmock, &out_trans_reg, TX_NODE_ID);
uavcan::Dispatcher dispatcher_rx(&driver, &poolmgr, &clockmock, &out_trans_reg, RX_NODE_ID);
uavcan::Dispatcher dispatcher_tx(driver, poolmgr, clockmock, out_trans_reg, TX_NODE_ID);
uavcan::Dispatcher dispatcher_rx(driver, poolmgr, clockmock, out_trans_reg, RX_NODE_ID);
/*
* Test environment
@@ -109,9 +109,9 @@ TEST(TransferSender, Basic)
}
}
TestSubscriber<512, 2, 2> sub_msg(TYPES + 0, &poolmgr);
TestSubscriber<512, 2, 2> sub_srv_req(TYPES + 1, &poolmgr);
TestSubscriber<512, 2, 2> sub_srv_resp(TYPES + 1, &poolmgr);
TestSubscriber<512, 2, 2> sub_msg(TYPES[0], poolmgr);
TestSubscriber<512, 2, 2> sub_srv_req(TYPES[1], poolmgr);
TestSubscriber<512, 2, 2> sub_srv_resp(TYPES[1], poolmgr);
dispatcher_rx.registerMessageListener(&sub_msg);
dispatcher_rx.registerServiceRequestListener(&sub_srv_req);
@@ -12,8 +12,8 @@ TEST(TransferTestHelpers, Transfer)
uavcan::PoolManager<1> poolmgr;
poolmgr.addPool(&pool);
uavcan::TransferBufferManager<128, 1> mgr(&poolmgr);
uavcan::TransferBufferAccessor tba(&mgr, uavcan::TransferBufferManagerKey(0, uavcan::TRANSFER_TYPE_MESSAGE_UNICAST));
uavcan::TransferBufferManager<128, 1> mgr(poolmgr);
uavcan::TransferBufferAccessor tba(mgr, uavcan::TransferBufferManagerKey(0, uavcan::TRANSFER_TYPE_MESSAGE_UNICAST));
uavcan::RxFrame frame(uavcan::Frame(123, uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST, 1, 0, 0, 0, true), 0, 0, 0);
uavcan::MultiFrameIncomingTransfer mfit(10, 1000, frame, tba);
@@ -104,13 +104,13 @@ class TestSubscriber : public uavcan::TransferListener<MAX_BUF_SIZE, NUM_STATIC_
std::queue<Transfer> transfers_;
public:
TestSubscriber(const uavcan::DataTypeDescriptor* data_type, uavcan::IAllocator* allocator)
TestSubscriber(const uavcan::DataTypeDescriptor& data_type, uavcan::IAllocator& allocator)
: Base(data_type, allocator)
{ }
void handleIncomingTransfer(uavcan::IncomingTransfer& transfer)
{
const Transfer rx(transfer, *Base::getDataTypeDescriptor());
const Transfer rx(transfer, Base::getDataTypeDescriptor());
transfers_.push(rx);
std::cout << "Received transfer: " << rx.toString() << std::endl;
}