Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "OperationInterface.hpp"
00040 #include "FactoryExceptions.hpp"
00041 #include <algorithm>
00042 #include "internal/mystd.hpp"
00043 #include "internal/Exceptions.hpp"
00044 #include "Handle.hpp"
00045
00046 using namespace RTT;
00047 using namespace RTT::detail;
00048
00049 OperationInterfacePart::~OperationInterfacePart()
00050 {
00051 }
00052
00053 boost::shared_ptr<base::DisposableInterface> OperationInterfacePart::getLocalOperation() const
00054 {
00055 return boost::shared_ptr<base::DisposableInterface>();
00056 }
00057
00058 void OperationInterface::clear()
00059 {
00060 for (map_t::iterator i = data.begin(); i != data.end(); ++i)
00061 delete i->second;
00062 data.clear();
00063 }
00064
00065 std::vector<std::string> OperationInterface::getNames() const
00066 {
00067 std::vector<std::string> ret;
00068 std::transform(data.begin(), data.end(), std::back_inserter(ret), select1st<map_t::value_type> ());
00069 return ret;
00070 }
00071
00072 bool OperationInterface::hasMember(const std::string& name) const
00073 {
00074 return data.find(name) != data.end();
00075 }
00076
00077 int OperationInterface::getArity(const std::string& name) const
00078 {
00079 map_t::const_iterator i = data.find(name);
00080 if (i == data.end() || i->second == 0)
00081 return -1;
00082 return i->second->arity();
00083 }
00084
00085 int OperationInterface::getCollectArity(const std::string& name) const
00086 {
00087 map_t::const_iterator i = data.find(name);
00088 if (i == data.end() || i->second == 0)
00089 return -1;
00090 return i->second->collectArity();
00091 }
00092
00093 bool OperationInterface::isSynchronous(const std::string& name) const
00094 {
00095 if (!hasMember(name))
00096 return false;
00097 try {
00098 produceHandle(name);
00099 } catch(...) {
00100 return true;
00101 }
00102 return false;
00103 }
00104
00105 base::DataSourceBase::shared_ptr OperationInterface::produce(const std::string& name, const Arguments& args, ExecutionEngine* caller) const
00106 {
00107 map_t::const_iterator i = data.find(name);
00108 if (i == data.end() || i->second == 0)
00109 ORO_THROW_OR_RETURN(name_not_found_exception(), 0);
00110 return i->second->produce(args, caller);
00111 }
00112
00113 base::DataSourceBase::shared_ptr OperationInterface::produceSend(const std::string& name, const Arguments& args, ExecutionEngine* caller) const
00114 {
00115 map_t::const_iterator i = data.find(name);
00116 if (i == data.end() || i->second == 0)
00117 ORO_THROW_OR_RETURN(name_not_found_exception(), 0);
00118 return i->second->produceSend(args, caller);
00119 }
00120
00121 base::DataSourceBase::shared_ptr OperationInterface::produceHandle(const std::string& name) const
00122 {
00123 map_t::const_iterator i = data.find(name);
00124 if (i == data.end() || i->second == 0)
00125 ORO_THROW_OR_RETURN(name_not_found_exception(), 0);
00126 return i->second->produceHandle();
00127 }
00128
00129 base::DataSourceBase::shared_ptr OperationInterface::produceCollect(const std::string& name, const Arguments& args, DataSource<bool>::shared_ptr blocking) const
00130 {
00131 map_t::const_iterator i = data.find(name);
00132 if (i == data.end() || i->second == 0)
00133 ORO_THROW_OR_RETURN(name_not_found_exception(), 0);
00134 return i->second->produceCollect(args, blocking);
00135 }
00136
00137 #ifdef ORO_SIGNALLING_OPERATIONS
00138 Handle OperationInterface::produceSignal(const std::string& name, base::ActionInterface* act, const Arguments& args) const
00139 {
00140 map_t::const_iterator i = data.find(name);
00141 if (i == data.end() || i->second == 0)
00142 ORO_THROW_OR_RETURN(name_not_found_exception(), 0);
00143 return i->second->produceSignal(act, args);
00144 }
00145 #endif
00146 OperationInterface::Descriptions OperationInterface::getArgumentList(const std::string& name) const
00147 {
00148 map_t::const_iterator i = data.find(name);
00149 if (i == data.end() || i->second == 0)
00150 ORO_THROW_OR_RETURN(name_not_found_exception(), Descriptions());
00151 return i->second->getArgumentList();
00152 }
00153
00154 std::string OperationInterface::getResultType(const std::string& name) const
00155 {
00156 map_t::const_iterator i = data.find(name);
00157 if (i == data.end() || i->second == 0)
00158 ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
00159 return i->second->resultType();
00160 }
00161
00162 std::string OperationInterface::getDescription(const std::string& name) const
00163 {
00164 map_t::const_iterator i = data.find(name);
00165 if (i == data.end() || i->second == 0)
00166 ORO_THROW_OR_RETURN(name_not_found_exception(), std::string());
00167 return i->second->description();
00168 }
00169
00170 void OperationInterface::add(const std::string& name, OperationInterfacePart* part)
00171 {
00172 map_t::iterator i = data.find(name);
00173 if (i != data.end())
00174 delete i->second;
00175 data[name] = part;
00176 }
00177
00178 void OperationInterface::remove(const std::string& name)
00179 {
00180 map_t::iterator i = data.find(name);
00181 if (i != data.end())
00182 {
00183 delete i->second;
00184 data.erase(i);
00185 }
00186 }
00187
00188 OperationInterfacePart* OperationInterface::getPart(const std::string& name)
00189 {
00190 map_t::iterator i = data.find(name);
00191 if (i != data.end())
00192 {
00193 return i->second;
00194 }
00195 return 0;
00196 }
00197