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
+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));