Orocos Real-Time Toolkit  2.9.0
PortInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Oct 22 11:59:07 CEST 2009 PortInterface.cpp
3 
4  PortInterface.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 "../Service.hpp"
41 #include "../OperationCaller.hpp"
42 #include "../internal/ConnFactory.hpp"
43 
44 using namespace RTT;
45 using namespace RTT::detail;
46 using namespace std;
47 
48 PortInterface::PortInterface(const std::string& name)
49  : name(name), iface(0), cmanager(this) {}
50 
51 bool PortInterface::setName(const std::string& name)
52 {
53  if ( !connected() ) {
54  this->name = name;
55  return true;
56  }
57  return false;
58 }
59 
60 PortInterface& PortInterface::doc(const std::string& desc) {
61  mdesc = desc;
62  if (iface)
63  iface->setPortDescription(name, desc);
64  return *this;
65 }
66 
68  return cmanager.connectedTo(port);
69 }
70 
72 { return serverProtocol() == 0; }
74 { return 0; }
75 
77 { return new LocalConnID(this); }
78 
80 {
81 #ifndef ORO_EMBEDDED
82  Service* to = new Service( this->getName(), iface->getOwner() );
83  to->addSynchronousOperation( "name",&PortInterface::getName, this).doc(
84  "Returns the port name.");
85  to->addSynchronousOperation("connected", &PortInterface::connected, this).doc("Check if this port is connected and ready for use.");
86 
87  typedef void (PortInterface::*disconnect_all)();
88  to->addSynchronousOperation("disconnect", static_cast<disconnect_all>(&PortInterface::disconnect), this).doc("Disconnects this port from any connection it is part of.");
89  return to;
90 #else
91  return 0;
92 #endif
93 }
94 
96 {
97  return cmanager.removeConnection(conn);
98 }
99 
101  iface = dfi;
102 }
103 
105 {
106  return iface;
107 }
108 
110 {
111  return cmanager.getSharedConnection();
112 }
The Interface of a TaskContext which exposes its data-flow ports.
boost::intrusive_ptr< SharedConnectionBase > shared_ptr
virtual bool isLocal() const
Returns true if this port is located on this process, and false otherwise.
bool removeConnection(ConnID *port_id, bool disconnect=true)
virtual internal::SharedConnectionBase::shared_ptr getSharedConnection() const
Returns a pointer to the shared connection element this port may be connected to. ...
PortInterface(const std::string &name)
STL namespace.
bool connectedTo(base::PortInterface *port)
Returns true if there exists a connection to the given port.
const std::string & getName() const
Get the name of this Port.
DataFlowInterface * getInterface() const
Returns the DataFlowInterface this port belongs to or null if it was not added to such an interface...
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
Definition: Service.hpp:93
Represents a local connection created by the ConnFactory.
Definition: ConnFactory.hpp:66
virtual void disconnect()=0
Removes any connection that either go to or come from this port.
Convenient short notation for every sub-namespace of RTT.
Operation< Signature > & addSynchronousOperation(Operation< Signature > &op)
Add an operation object to the interface.
Definition: Service.hpp:379
virtual bool removeConnection(internal::ConnID *cid)
Removes a user created connection from this port.
virtual Service * createPortObject()
Create accessor Object for this Port, for addition to a TaskContext Object interface.
virtual bool connectedTo(PortInterface *port)
Returns true if this port is connected to the given port.
bool setName(const std::string &name)
Change the name of this unconnected Port.
virtual int serverProtocol() const
Returns the protocol over which this port can be accessed.
bool setPortDescription(const std::string &name, const std::string description)
Sets the description for the service of an added port.
internal::ConnectionManager cmanager
void setInterface(DataFlowInterface *iface)
Once a port is added to a DataFlowInterface, it gets a pointer to that interface. ...
DataFlowInterface * iface
virtual internal::ConnID * getPortID() const
Returns the identity of this port in a ConnID object.
This class is used in places where a permanent representation of a reference to a connection is neede...
Definition: ConnID.hpp:58
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
PortInterface & doc(const std::string &desc)
Set the documentation of this port.
virtual bool connected() const =0
Returns true if this port is connected.
The base class of every data flow port.
TaskContext * getOwner() const
Returns the component this interface belongs to.
internal::SharedConnectionBase::shared_ptr getSharedConnection() const
Returns a pointer to the shared connection element this port may be connected to. ...