Orocos Real-Time Toolkit  2.9.0
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 "../internal/ConnFactory.hpp"
43 #include <exception>
44 #include <stdexcept>
45 
46 using namespace RTT;
47 using namespace RTT::detail;
48 using namespace std;
49 
50 
52  : PortInterface(name) { }
53 
55 {
57 }
58 
61 { return cmanager.connected(); }
62 
64 {
65  return cmanager.disconnect(port);
66 }
67 
69 {
71 }
72 
74 {
75  if ( this->connectionAdded(channel_input, policy) ) {
76  return cmanager.addConnection(port_id, channel_input, policy);
77  }
78  return false;
79 }
80 
82 { throw std::runtime_error("calling default OutputPortInterface::write(datasource) implementation"); }
83 
85 { return createConnection( input, ConnPolicy::data(lock_policy) ); }
86 
87 bool OutputPortInterface::createBufferConnection( InputPortInterface& input, int size, int lock_policy )
88 { return createConnection( input, ConnPolicy::buffer(size, lock_policy) ); }
89 
91 { return createConnection(input, input.getDefaultPolicy()); }
92 
94 {
95  return internal::ConnFactory::createAndCheckSharedConnection(this, 0, shared_connection, policy);
96 }
97 
99 {
100  InputPortInterface* input = dynamic_cast<InputPortInterface*>(other);
101  if (! input)
102  return false;
103  return createConnection(*input, policy);
104 }
105 
107 {
108  InputPortInterface* input = dynamic_cast<InputPortInterface*>(other);
109  if (! input)
110  return false;
111  return createConnection(*input);
112 }
static bool createAndCheckSharedConnection(base::OutputPortInterface *output_port, base::InputPortInterface *input_port, SharedConnectionBase::shared_ptr shared_connection, ConnPolicy const &policy)
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...
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
void disconnect()
Disconnect all connections.
ConnPolicy getDefaultPolicy() const
STL namespace.
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
virtual WriteStatus write(DataSourceBase::shared_ptr source)
Write this port using the value stored in source.
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:77
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
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:99
internal::ConnectionManager cmanager
virtual void disconnect()
Removes any connection that either go to or come from this port.
bool addConnection(ConnID *port_id, base::ChannelElementBase::shared_ptr channel, ConnPolicy policy)
Helper method for port-to-port connection establishment.
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:52
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)
WriteStatus
Returns the status of a data flow write operation.
Definition: FlowStatus.hpp:66
bool connected() const
Returns true if there is at least one connection registered in this port&#39;s list of outputs...