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 #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;
00140 }
00141
00142 int DataSourceBase::serverProtocol() const
00143 {
00144 return 0;
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
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