Orocos Real-Time Toolkit  2.9.0
InputPortInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:07 CEST 2009 InputPortInterface.cpp
3 
4  InputPortInterface.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 "InputPortInterface.hpp"
41 #include "OutputPortInterface.hpp"
42 #include "DataFlowInterface.hpp"
43 #include "../internal/ConnInputEndPoint.hpp"
44 #include "../internal/ConnFactory.hpp"
45 #include "../Logger.hpp"
46 #include <exception>
47 #include <stdexcept>
48 
49 using namespace RTT;
50 using namespace RTT::detail;
51 using namespace std;
52 
53 
54 InputPortInterface::InputPortInterface(std::string const& name, ConnPolicy const& default_policy)
55 : PortInterface(name)
56  , default_policy( default_policy )
57 #ifdef ORO_SIGNALLING_PORTS
58  , new_data_on_port_event(0)
59 #else
60  , msignal_interface(false)
61 #endif
62 {}
63 
65 {
66  cmanager.disconnect();
67 #ifdef ORO_SIGNALLING_PORTS
68  if ( new_data_on_port_event) {
69  delete new_data_on_port_event;
70  }
71 #endif
72 }
73 
75 { return default_policy; }
76 
77 #ifdef ORO_SIGNALLING_PORTS
78 InputPortInterface::NewDataOnPortEvent* InputPortInterface::getNewDataOnPortEvent()
79 {
80  if (!new_data_on_port_event)
81  new_data_on_port_event = new NewDataOnPortEvent();
82  return new_data_on_port_event;
83 }
84 #endif
86 {
87  OutputPortInterface* output = dynamic_cast<OutputPortInterface*>(other);
88  if (! output) {
89  log(Error) << "InputPort "<< getName() <<" could not connect to "<< other->getName() << ": not an Output port." <<endlog();
90  return false;
91  }
92  return output->createConnection(*this, policy);
93 }
94 
96 {
97  return connectTo(other, default_policy);
98 }
99 
101 {
102  // input ports don't check the connection policy.
103  return cmanager.addConnection( cid, channel, policy);
104 }
105 
106 #ifndef ORO_SIGNALLING_PORTS
108 {
109  if (iface && msignal_interface)
110  iface->dataOnPort(this);
111 }
113 {
114  msignal_interface = true_false;
115 }
116 #endif
118 { throw std::runtime_error("calling default InputPortInterface::read(datasource) implementation"); }
121 { return cmanager.connected(); }
122 
124 {
125  cmanager.disconnect();
126 }
127 
129 {
130  return cmanager.disconnect(port);
131 }
132 
134 {
135  return internal::ConnFactory::createAndCheckSharedConnection(0, this, shared_connection, policy);
136 }
137 
139  base::OutputPortInterface& output_port,
140  types::TypeInfo const* type_info,
141  base::InputPortInterface& input, const ConnPolicy& policy)
142 {
144 }
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.
virtual bool createConnection(internal::SharedConnectionBase::shared_ptr shared_connection, ConnPolicy const &policy=ConnPolicy())
Connects the port to an existing shared connection instance.
virtual bool addConnection(internal::ConnID *port_id, ChannelElementBase::shared_ptr channel, ConnPolicy const &policy)
Adds a user created connection to this port.
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
InputPortInterface(const InputPortInterface &orig)
virtual FlowStatus read(DataSourceBase::shared_ptr source, bool copy_old_data=true)
Reads the port and updates the value hold by the given data source.
virtual void disconnect()
Removes any connection that either go to or come from this port and removes all callbacks and cleans ...
ConnPolicy getDefaultPolicy() const
FlowStatus
Returns the status of a data flow read operation.
Definition: FlowStatus.hpp:56
STL namespace.
const std::string & getName() const
Get the name of this Port.
void signalInterface(bool true_false)
When called with true, will signal the DataFlowInterface when new data is available.
A connection policy object describes how a given connection should behave.
Definition: ConnPolicy.hpp:107
The base class of each OutputPort.
Convenient short notation for every sub-namespace of RTT.
virtual base::ChannelElementBase::shared_ptr buildRemoteChannelOutput(base::OutputPortInterface &output_port, types::TypeInfo const *type_info, base::InputPortInterface &input, const ConnPolicy &policy)
This method is analoguous to the static ConnFactory::buildChannelOutput.
bool createConnection(InputPortInterface &sink)
Connects this write port to the given read port, using as policy the default policy of the sink port...
A class for representing a user type, and which can build instances of that type. ...
Definition: TypeInfo.hpp:67
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
Connects this port with other, using the given policy.
void signal()
The ConnOutputEndpoint signals that new data is available.
boost::intrusive_ptr< ChannelElementBase > shared_ptr
virtual bool connected() const
Returns true if this port is connected.
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
The base class of every data flow port.