Orocos Real-Time Toolkit  2.8.3
OutputPortInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:07 CEST 2009 OutputPortInterface.cpp
3 
4  OutputPortInterface.cpp - description
5  -------------------
6  begin : Thu October 22 2009
7  copyright : (C) 2009 Sylvain Joyeux
8  email : sylvain.joyeux@m4x.org
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #include "PortInterface.hpp"
40 #include "OutputPortInterface.hpp"
41 #include "InputPortInterface.hpp"
42 #include <exception>
43 #include <stdexcept>
44 
45 using namespace RTT;
46 using namespace RTT::detail;
47 using namespace std;
48 
49 
51  : PortInterface(name), cmanager(this) { }
52 
54 {
56 }
57 
60 { return cmanager.connected(); }
61 
63 {
64  return cmanager.disconnect(port);
65 }
66 
68 {
70 }
71 
73 {
74  if ( this->connectionAdded(channel_input, policy) ) {
75  cmanager.addConnection(port_id, channel_input, policy);
76  return true;
77  }
78  return false;
79 }
80 
81 // This is called by our input endpoint.
83 {
84  return cmanager.removeConnection(conn);
85 }
86 
87 
89 { throw std::runtime_error("calling default OutputPortInterface::write(datasource) implementation"); }
90 
92 { return createConnection( input, ConnPolicy::data(lock_policy) ); }
93 
94 bool OutputPortInterface::createBufferConnection( InputPortInterface& input, int size, int lock_policy )
95 { return createConnection( input, ConnPolicy::buffer(size, lock_policy) ); }
96 
98 { return createConnection(input, input.getDefaultPolicy()); }
99 
101 {
102  InputPortInterface* input = dynamic_cast<InputPortInterface*>(other);
103  if (! input)
104  return false;
105  return createConnection(*input, policy);
106 }
107 
109 {
110  InputPortInterface* input = dynamic_cast<InputPortInterface*>(other);
111  if (! input)
112  return false;
113  return createConnection(*input);
114 }
The base class of the InputPort.
bool createDataConnection(InputPortInterface &sink, int lock_policy=ConnPolicy::LOCK_FREE)
Connects this write port to the given read port, using a single-data policy with the given locking me...
void addConnection(ConnID *port_id, base::ChannelElementBase::shared_ptr channel_input, ConnPolicy policy)
Helper method for port-to-port connection establishment.
void disconnect()
Disconnect all connections.
ConnPolicy getDefaultPolicy() const
bool removeConnection(ConnID *port_id)
virtual void write(DataSourceBase::shared_ptr source)
Write this port using the value stored in source.
STL namespace.
internal::ConnectionManager cmanager
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:92
static ConnPolicy buffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
Create a policy for a (lock-free) fifo buffer connection of a given size.
Definition: ConnPolicy.cpp:54
Convenient short notation for every sub-namespace of RTT.
bool createConnection(InputPortInterface &sink)
Connects this write port to the given read port, using as policy the default policy of the sink port...
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
Connects this port with other, using the given policy.
virtual bool addConnection(internal::ConnID *port_id, ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy)
Adds a new connection to this output port and initializes the connection if required by policy...
virtual bool connected() const
Returns true if there is at least one channel registered in this port&#39;s list of outputs.
boost::intrusive_ptr< ChannelElementBase > shared_ptr
virtual bool removeConnection(internal::ConnID *cid)
Removes the connection associated with this channel, and the channel as well.
static ConnPolicy data(int lock_policy=LOCK_FREE, bool init_connection=true, bool pull=false)
Create a policy for a (lock-free) shared data connection of a given size.
Definition: ConnPolicy.cpp:72
virtual void disconnect()
Removes any connection that either go to or come from this port.
This class is used in places where a permanent representation of a reference to a connection is neede...
Definition: ConnID.hpp:58
boost::intrusive_ptr< DataSourceBase > shared_ptr
Use this type to store a pointer to a DataSourceBase.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
virtual bool connectionAdded(ChannelElementBase::shared_ptr channel_input, ConnPolicy const &policy)=0
Upcall to OutputPort.
The base class of every data flow port.
bool createBufferConnection(InputPortInterface &sink, int size, int lock_policy=ConnPolicy::LOCK_FREE)
Connects this write port to the given read port, using a buffered policy, with the buffer of the give...
OutputPortInterface(OutputPortInterface const &orig)
bool connected() const
Returns true if there is at least one channel registered in this port&#39;s list of outputs.