DataSource.cpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon May 10 19:10:37 CEST 2004  DataSource.cxx 
00003 
00004                         DataSource.cxx -  description
00005                            -------------------
00006     begin                : Mon May 10 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
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 #include "DataSource.hpp"
00038 #include "TypeInfoName.hpp"
00039 
00040 #include "rtt-config.h"
00041 #include "Types.hpp"
00042 #include "TypeTransporter.hpp"
00043 
00044 namespace RTT
00045 {
00046 
00047     DataSourceBase::DataSourceBase() { oro_atomic_set(&refcount,0); }
00048     void DataSourceBase::ref() const { oro_atomic_inc(&refcount); }
00049     void DataSourceBase::deref() const { if ( oro_atomic_dec_and_test(&refcount) ) delete this; }
00050 
00051     DataSourceBase::~DataSourceBase()
00052     {
00053     }
00054     
00055     void DataSourceBase::reset()
00056     {
00057     }
00058 
00059     std::ostream& DataSourceBase::write(std::ostream& os)
00060     {
00061         DataSourceBase::shared_ptr mobj(this);
00062         return mobj->getTypeInfo()->write( os, mobj );
00063     }
00064 
00065 
00066     std::ostream& operator<<(std::ostream& os, DataSourceBase::shared_ptr mobj)
00067     {
00068         return mobj->getTypeInfo()->write( os, mobj );
00069     }
00070 
00071     std::string DataSourceBase::toString()
00072     {
00073         DataSourceBase::shared_ptr mobj(this);
00074         return mobj->getTypeInfo()->toString( mobj );
00075     }
00076 
00077     bool DataSourceBase::decomposeType( PropertyBag& targetbag )
00078     {
00079         DataSourceBase::shared_ptr mobj(this);
00080         return mobj->getTypeInfo()->decomposeType( mobj, targetbag );
00081     }
00082             
00083     bool DataSourceBase::composeType( DataSourceBase::shared_ptr source)
00084     {
00085         DataSourceBase::shared_ptr mobj(this);
00086         return mobj->getTypeInfo()->composeType( source, mobj );
00087     }
00088 
00089     bool DataSourceBase::update( DataSourceBase* ) {
00090         return false;
00091     }
00092 
00093     void DataSourceBase::updated()
00094     {}
00095 
00096 
00097     CommandInterface* DataSourceBase::updateCommand( DataSourceBase* ) {
00098         return 0;
00099     }
00100 
00101     bool DataSourceBase::updatePart( DataSourceBase*, DataSourceBase* ) {
00102         return false;
00103     }
00104 
00105     CommandInterface* DataSourceBase::updatePartCommand( DataSourceBase*, DataSourceBase* ) {
00106         return 0;
00107     }
00108 
00109     template<>
00110     bool DataSource<bool>::evaluate() const
00111     {
00112         this->get();
00113         return true;
00114     }
00115 
00116     void* DataSourceBase::createBlob(int protocol)
00117     {
00118 #ifndef ORO_EMBEDDED
00119         detail::TypeTransporter* tt = getTypeInfo()->getProtocol(protocol);
00120         if ( tt )
00121             return tt->createBlob( DataSourceBase::shared_ptr(this) );
00122 #endif
00123         return 0;
00124     }
00125     
00126     void* DataSourceBase::getBlob(int protocol)
00127     {
00128         this->evaluate();
00129 #ifndef ORO_EMBEDDED
00130         detail::TypeTransporter* tt = getTypeInfo()->getProtocol(protocol);
00131         if ( tt )
00132             return tt->createBlob( DataSourceBase::shared_ptr(this) );
00133 #endif
00134         return 0;
00135     }
00136     
00137     bool DataSourceBase::updateBlob(int protocol, const void* data)
00138     {
00139         return false; // overridden in AssignableDataSource<T>
00140     }
00141 
00142     int DataSourceBase::serverProtocol() const
00143     {
00144         return 0; // default to local DataSource.
00145     }
00146 
00147     void* DataSourceBase::server( int protocol, void* arg )
00148     {
00149 #ifndef ORO_EMBEDDED
00150         detail::TypeTransporter* tt = getTypeInfo()->getProtocol(protocol);
00151         if ( tt )
00152             return tt->server( DataSourceBase::shared_ptr(this), false, arg );
00153 #endif
00154         return 0;
00155     }
00156 
00157     void* DataSourceBase::method( int protocol, MethodC* orig, void* arg )
00158     {
00159 #ifndef ORO_EMBEDDED
00160         detail::TypeTransporter* tt = getTypeInfo()->getProtocol(protocol);
00161         if ( tt )
00162             return tt->method( DataSourceBase::shared_ptr(this), orig, arg );
00163 #endif
00164         return 0;
00165     }
00166 
00167     namespace detail {
00168 
00169         TypeInfo* DataSourceTypeInfo<detail::UnknownType>::TypeInfoObject = 0;
00170 
00171         const std::string& DataSourceTypeInfo<UnknownType>::getType() { return getTypeInfo()->getTypeName(); }
00172         const std::string& DataSourceTypeInfo<UnknownType>::getQualifier() { return noqual; }
00173         TypeInfo* DataSourceTypeInfo<UnknownType>::getTypeInfo() { 
00174             if (!TypeInfoObject)
00175                 TypeInfoObject = new TypeInfoName<UnknownType>("unknown_t");
00176             return TypeInfoObject; 
00177         }
00178 
00179         const std::string DataSourceTypeInfo<UnknownType>::noqual("");
00180         const std::string DataSourceTypeInfo<UnknownType>::cqual(" const");
00181         const std::string DataSourceTypeInfo<UnknownType>::refqual(" &");
00182         const std::string DataSourceTypeInfo<UnknownType>::crefqual(" const&");
00183         const std::string DataSourceTypeInfo<UnknownType>::ptrqual(" *");
00184         const std::string DataSourceTypeInfo<UnknownType>::cptrqual(" const*");
00185 
00186         // (void) type info
00187         TypeInfo* DataSourceTypeInfo<void>::TypeInfoObject = 0;
00188         const std::string DataSourceTypeInfo<void>::tname("void");
00189 
00190         const std::string& DataSourceTypeInfo<void>::getType() { return tname; }
00191         const std::string& DataSourceTypeInfo<void>::getQualifier() { return DataSourceTypeInfo<UnknownType>::noqual; }
00192         const TypeInfo* DataSourceTypeInfo<void>::getTypeInfo() { 
00193             return DataSourceTypeInfo<UnknownType>::getTypeInfo();
00194         }
00195 
00196     }
00197 }
00198 
00199 void intrusive_ptr_add_ref(const RTT::DataSourceBase* p )
00200 {
00201   p->ref();
00202 }
00203 
00204 void intrusive_ptr_release(const RTT::DataSourceBase* p )
00205 {
00206   p->deref();
00207 };
00208 

Generated on Tue Mar 25 17:41:42 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3