Lazy initialization of TransferSender removed

This commit is contained in:
Pavel Kirienko
2015-05-29 23:30:02 +03:00
parent 3499db227b
commit 0ce23a4f34
10 changed files with 64 additions and 103 deletions
@@ -9,7 +9,6 @@
#include <uavcan/node/abstract_node.hpp>
#include <uavcan/data_type.hpp>
#include <uavcan/node/global_data_type_registry.hpp>
#include <uavcan/util/lazy_constructor.hpp>
#include <uavcan/debug.hpp>
#include <uavcan/transport/transfer_sender.hpp>
#include <uavcan/marshal/scalar_codec.hpp>
@@ -20,15 +19,14 @@ namespace uavcan
class GenericPublisherBase : Noncopyable
{
const MonotonicDuration max_transfer_interval_; // TODO: memory usage can be reduced
TransferSender sender_;
MonotonicDuration tx_timeout_;
INode& node_;
LazyConstructor<TransferSender> sender_;
protected:
GenericPublisherBase(INode& node, MonotonicDuration tx_timeout,
MonotonicDuration max_transfer_interval)
: max_transfer_interval_(max_transfer_interval)
: sender_(node.getDispatcher(), max_transfer_interval)
, tx_timeout_(tx_timeout)
, node_(node)
{
@@ -51,7 +49,8 @@ protected:
int genericPublish(const IMarshalBuffer& buffer, TransferType transfer_type, NodeID dst_node_id,
TransferID* tid, MonotonicTime blocking_deadline);
TransferSender* getTransferSender();
TransferSender& getTransferSender() { return sender_; }
const TransferSender& getTransferSender() const { return sender_; }
public:
static MonotonicDuration getMinTxTimeout() { return MonotonicDuration::fromUSec(200); }
@@ -66,7 +65,7 @@ public:
*/
void allowAnonymousTransfers()
{
sender_->allowAnonymousTransfers();
sender_.allowAnonymousTransfers();
}
INode& getNode() const { return node_; }
@@ -124,12 +123,6 @@ public:
{
return genericPublish(message, transfer_type, dst_node_id, &tid, blocking_deadline);
}
TransferSender* getTransferSender()
{
(void)checkInit();
return GenericPublisherBase::getTransferSender();
}
};
// ----------------------------------------------------------------------------
+5 -31
View File
@@ -81,46 +81,20 @@ public:
/**
* Returns priority of outgoing transfers.
* TODO: Make const.
*/
TransferPriority getPriority()
TransferPriority getPriority() const
{
// TODO probably TransferSender must be transformed into regular field?
TransferSender* const ts = getTransferSender();
if (ts != NULL)
{
return ts->getPriority();
}
else
{
return TransferPriorityNormal; // This is default
}
return BaseType::getTransferSender().getPriority();
}
/**
* Allows to change the priority of outgoing transfers.
* Note that only High, Normal and Low priorities can be used; Service priority is not available for messages.
* Returns negative error code if priority cannot be set, non-negative on success.
* If the priority value is invalid, an assertion failure will be generated, and the value will not be updated.
*/
int setPriority(const TransferPriority prio)
void setPriority(const TransferPriority prio)
{
if (prio < NumTransferPriorities && prio != TransferPriorityService)
{
TransferSender* const ts = getTransferSender(); // TODO: Static TransferSender?
if (ts != NULL)
{
ts->setPriority(prio);
return 0;
}
else
{
return -ErrLogic;
}
}
else
{
return -ErrInvalidParam;
}
BaseType::getTransferSender().setPriority(prio);
}
static MonotonicDuration getDefaultTxTimeout() { return MonotonicDuration::fromMSec(10); }