Orocos Real-Time Toolkit  2.8.3
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) {}
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 serverProtocol() == 0; }
70 { return 0; }
71 
73 { return new LocalConnID(this); }
74 
76 {
77 #ifndef ORO_EMBEDDED
78  Service* to = new Service( this->getName(), iface->getOwner() );
79  to->addSynchronousOperation( "name",&PortInterface::getName, this).doc(
80  "Returns the port name.");
81  to->addSynchronousOperation("connected", &PortInterface::connected, this).doc("Check if this port is connected and ready for use.");
82 
83  typedef void (PortInterface::*disconnect_all)();
84  to->addSynchronousOperation("disconnect", static_cast<disconnect_all>(&PortInterface::disconnect), this).doc("Disconnects this port from any connection it is part of.");
85  return to;
86 #else
87  return 0;
88 #endif
89 }
90 
92  iface = dfi;
93 }
94 
96 {
97  return iface;
98 }
99 
The Interface of a TaskContext which exposes its data-flow ports.
virtual bool isLocal() const
Returns true if this port is located on this process, and false otherwise.
PortInterface(const std::string &name)
STL namespace.
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:63
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 Service * createPortObject()
Create accessor Object for this Port, for addition to a TaskContext Object interface.
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.
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:51
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.