mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 06:33:33 +08:00
Style fixes
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user