OperationInterface.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  OperationInterface.cpp
00003 
00004                         OperationInterface.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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 


rtt
Author(s): RTT Developers
autogenerated on Thu Jan 2 2014 11:35:22