From 97649cc303608934fc609c9b6cdd8590e3cd0696 Mon Sep 17 00:00:00 2001 From: Peter Soetens Date: Mon, 12 Nov 2012 23:57:24 +0100 Subject: [PATCH 3/3] ports: no longer cache the InputPortSource This allows us to shorten the lifetime of the InputPortSource with respect to the port. Signed-off-by: Peter Soetens --- rtt/InputPort.hpp | 12 ++++-------- rtt/base/InputPortInterface.hpp | 3 +-- rtt/internal/InputPortSource.hpp | 10 ---------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/rtt/InputPort.hpp b/rtt/InputPort.hpp index edae637..d10c2ba 100644 --- a/rtt/InputPort.hpp +++ b/rtt/InputPort.hpp @@ -63,7 +63,6 @@ namespace RTT class InputPort : public base::InputPortInterface { friend class internal::ConnOutputEndpoint; - typename internal::InputPortSource::shared_ptr data_source; virtual bool connectionAdded( base::ChannelElementBase::shared_ptr channel_input, ConnPolicy const& policy ) { return true; } @@ -96,9 +95,9 @@ namespace RTT public: InputPort(std::string const& name = "unnamed", ConnPolicy const& default_policy = ConnPolicy()) : base::InputPortInterface(name, default_policy) - , data_source(0) {} + {} - virtual ~InputPort() { disconnect(); if (data_source) data_source->dropPort(); } + virtual ~InputPort() { disconnect(); } /** \overload */ FlowStatus read(base::DataSourceBase::shared_ptr source) @@ -209,14 +208,11 @@ namespace RTT { return new OutputPort(this->getName()); } /** Returns a base::DataSourceBase interface to read this port. The returned - * data source is always the same object and will be destroyed when the - * port is destroyed. + * data source is always a new object. */ base::DataSourceBase* getDataSource() { - if (data_source) return data_source.get(); - data_source = new internal::InputPortSource(*this); - return data_source.get(); + return new internal::InputPortSource(*this); } virtual bool createStream(ConnPolicy const& policy) diff --git a/rtt/base/InputPortInterface.hpp b/rtt/base/InputPortInterface.hpp index 0ce671d..b08fce4 100644 --- a/rtt/base/InputPortInterface.hpp +++ b/rtt/base/InputPortInterface.hpp @@ -105,8 +105,7 @@ namespace RTT virtual bool removeConnection(internal::ConnID* cid); /** Returns a DataSourceBase interface to read this port. The returned - * data source is always the same object and will be destroyed when the - * port is destroyed. + * data source is always a new object. */ virtual DataSourceBase* getDataSource() = 0; diff --git a/rtt/internal/InputPortSource.hpp b/rtt/internal/InputPortSource.hpp index 29ae77d..e073801 100644 --- a/rtt/internal/InputPortSource.hpp +++ b/rtt/internal/InputPortSource.hpp @@ -77,16 +77,6 @@ namespace RTT port.getDataSample( mvalue ); } - /** - * Called by owner port to notify that it is being - * destructed. Since this InputPortSource is refcounted, - * we need a way to tell it that the port no longer - * exists. - */ - void dropPort() { - port = 0; - } - void reset() { port->clear(); } bool evaluate() const { -- 1.7.5.4