Orocos Real-Time Toolkit  2.8.3
OperationInterface.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 OperationInterface.cpp
3 
4  OperationInterface.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
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 "OperationInterface.hpp"
40 #include "FactoryExceptions.hpp"
41 #include <algorithm>
42 #include "internal/mystd.hpp"
43 #include "internal/Exceptions.hpp"
44 #include "Handle.hpp"
45 
46 using namespace RTT;
47 using namespace RTT::detail;
48 
50 {
51 }
52 
53 boost::shared_ptr<base::DisposableInterface> OperationInterfacePart::getLocalOperation() const
54 {
55  return boost::shared_ptr<base::DisposableInterface>();
56 }
57 
59 {
60  for (map_t::iterator i = data.begin(); i != data.end(); ++i)
61  delete i->second;
62  data.clear();
63 }
64 
65 std::vector<std::string> OperationInterface::getNames() const
66 {
67  std::vector<std::string> ret;
68  std::transform(data.begin(), data.end(), std::back_inserter(ret), select1st<map_t::value_type> ());
69  return ret;
70 }
71 
72 bool OperationInterface::hasMember(const std::string& name) const
73 {
74  return data.find(name) != data.end();
75 }
76 
77 int OperationInterface::getArity(const std::string& name) const
78 {
79  map_t::const_iterator i = data.find(name);
80  if (i == data.end() || i->second == 0)
81  return -1;
82  return i->second->arity();
83 }
84 
85 int OperationInterface::getCollectArity(const std::string& name) const
86 {
87  map_t::const_iterator i = data.find(name);
88  if (i == data.end() || i->second == 0)
89  return -1;
90  return i->second->collectArity();
91 }
92 
93 bool OperationInterface::isSynchronous(const std::string& name) const
94 {
95  if (!hasMember(name))
96  return false;
97  try {
98  produceHandle(name);
99  } catch(...) {
100  return true;
101  }
102  return false;
103 }
104 
105 base::DataSourceBase::shared_ptr OperationInterface::produce(const std::string& name, const Arguments& args, ExecutionEngine* caller) const
106 {
107  map_t::const_iterator i = data.find(name);
108  if (i == data.end() || i->second == 0)
110  return i->second->produce(args, caller);
111 }
112 
114 {
115  map_t::const_iterator i = data.find(name);
116  if (i == data.end() || i->second == 0)
118  return i->second->produceSend(args, caller);
119 }
120 
122 {
123  map_t::const_iterator i = data.find(name);
124  if (i == data.end() || i->second == 0)
126  return i->second->produceHandle();
127 }
128 
130 {
131  map_t::const_iterator i = data.find(name);
132  if (i == data.end() || i->second == 0)
134  return i->second->produceCollect(args, blocking);
135 }
136 
137 #ifdef ORO_SIGNALLING_OPERATIONS
138 Handle OperationInterface::produceSignal(const std::string& name, base::ActionInterface* act, const Arguments& args, ExecutionEngine* subscriber) const
139 {
140  map_t::const_iterator i = data.find(name);
141  if (i == data.end() || i->second == 0)
143  return i->second->produceSignal(act, args, subscriber);
144 }
145 #endif
147 {
148  map_t::const_iterator i = data.find(name);
149  if (i == data.end() || i->second == 0)
151  return i->second->getArgumentList();
152 }
153 
154 std::string OperationInterface::getResultType(const std::string& name) const
155 {
156  map_t::const_iterator i = data.find(name);
157  if (i == data.end() || i->second == 0)
159  return i->second->resultType();
160 }
161 
162 std::string OperationInterface::getDescription(const std::string& name) const
163 {
164  map_t::const_iterator i = data.find(name);
165  if (i == data.end() || i->second == 0)
167  return i->second->description();
168 }
169 
170 void OperationInterface::add(const std::string& name, OperationInterfacePart* part)
171 {
172  map_t::iterator i = data.find(name);
173  if (i != data.end())
174  delete i->second;
175  data[name] = part;
176 }
177 
178 void OperationInterface::remove(const std::string& name)
179 {
180  map_t::iterator i = data.find(name);
181  if (i != data.end())
182  {
183  delete i->second;
184  data.erase(i);
185  }
186 }
187 
189 {
190  map_t::iterator i = data.find(name);
191  if (i != data.end())
192  {
193  return i->second;
194  }
195  return 0;
196 }
197 
DataSource is a base class representing a generic way to read data of type T.
Definition: DataSource.hpp:94
base::DataSourceBase::shared_ptr produceSend(const std::string &name, const Arguments &args, ExecutionEngine *caller) const
Produce a DataSource that send()s an operation.
void add(const std::string &name, OperationInterfacePart *part)
Add a new operation to the interface or replace an existing one.
std::string getDescription(const std::string &name) const
Get the description of an operation.
#define ORO_THROW_OR_RETURN(x, rv)
Definition: Exceptions.hpp:53
Exception thrown when a factory is requested to create an object with an unknown name.
When Orocos is compiled without exceptions (define ORO_EMBEDDED), the functions which would throw an ...
bool hasMember(const std::string &name) const
Query if an operation is present.
bool isSynchronous(const std::string &name) const
Query if a given operation is limited to sychronous invocation (own component thread) only...
An execution engine serialises (executes one after the other) the execution of all commands...
int getCollectArity(const std::string &name) const
Query the collectable number of arguments of an operation.
OperationInterfacePart * getPart(const std::string &name)
Get a previously added part of this factory.
std::vector< ArgumentDescription > Descriptions
The descriptions of an argumentlist.
Convenient short notation for every sub-namespace of RTT.
int getArity(const std::string &name) const
Query the number of arguments of an operation.
base::DataSourceBase::shared_ptr produceCollect(const std::string &name, const Arguments &args, internal::DataSource< bool >::shared_ptr blocking) const
Produce a DataSource that collects a sent operation, The DataSource will return the SendStatus and st...
Based on the software pattern &#39;command&#39;, this interface allows execution of action objects...
This class defines the interface for creating operation objects without using C++ templates...
virtual RTT_API boost::shared_ptr< base::DisposableInterface > getLocalOperation() const
Returns any local operation associated with this operation.
This file contains some structs that can be thrown by both DataSourceFactory&#39;s and CommandFactory&#39;s...
void clear()
Remove and delete all added operations.
std::vector< std::string > getNames() const
Get a list of all the names of the added operations.
virtual RTT_API ~OperationInterfacePart()
Descriptions getArgumentList(const std::string &name) const
Get the names and descriptions of all arguments of an operation.
std::vector< base::DataSourceBase::shared_ptr > Arguments
The arguments for an operation.
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
base::DataSourceBase::shared_ptr produceHandle(const std::string &name) const
Produce an AssignableDataSource that contains a SendHandle, fit for the operation.
The Handle holds the information, and allows manipulation, of a connection between a internal::Signal...
Definition: Handle.hpp:66
void remove(const std::string &name)
Remove an added operation from the interface.
std::string getResultType(const std::string &name) const
Get the type name of the result type of an operation.
base::DataSourceBase::shared_ptr produce(const std::string &name, const Arguments &args, ExecutionEngine *caller) const
Produce a DataSource that call()s an operation.