TypelibMarshaller.hpp
Go to the documentation of this file.
00001 #ifndef OROGEN_TYPELIB_MARSHALLER_HPP
00002 #define OROGEN_TYPELIB_MARSHALLER_HPP
00003 
00004 #include <rtt/typelib/TypelibMarshallerBase.hpp>
00005 #include <rtt/typelib/TypelibMarshallerHandle.hpp>
00006 #include <rtt/internal/DataSources.hpp>
00007 
00008 namespace orogen_transports
00009 {
00010     template<typename T>
00011     struct TypelibMarshaller : public orogen_transports::TypelibMarshallerBase
00012     {
00013         typedef TypelibMarshallerBase::Handle Handle;
00014 
00015         TypelibMarshaller(std::string const& orocos_name, Typelib::Registry const& registry)
00016             : orogen_transports::TypelibMarshallerBase(true, orocos_name, orocos_name, registry) { }
00017 
00018         TypelibMarshallerBase::Handle* createSample() { return new Handle(this, new T); }
00019         void deleteOrocosSample(Handle* data)  { deleteSamples(data); }
00020         void deleteTypelibSample(Handle* data) { deleteSamples(data); }
00021         void deleteSamples(Handle* data)
00022         {
00023             delete reinterpret_cast<T*>(data->orocos_sample);
00024             data->reset();
00025         }
00026 
00027         void setTypelibSample(Handle* handle, uint8_t* data, bool refresh_orocos = true)
00028         {
00029             handle->orocos_sample = handle->typelib_sample = reinterpret_cast<uint8_t*>(data);
00030             handle->owns_orocos = handle->owns_typelib = false;
00031         }
00032 
00033         void setOrocosSample(Handle* handle, void* data, bool refresh_typelib = true)
00034         {
00035             handle->orocos_sample = handle->typelib_sample = reinterpret_cast<uint8_t*>(data);
00036             handle->owns_orocos = handle->owns_typelib = false;
00037         }
00038 
00039         uint8_t* releaseOrocosSample(Handle* handle)
00040         {
00041             if (!handle->orocos_sample)
00042                 return 0;
00043 
00044             if (handle->owns_orocos)
00045             {
00046                 return reinterpret_cast<uint8_t*>(new T(*reinterpret_cast<T*>(handle->orocos_sample)));
00047             }
00048             else
00049             {
00050                 handle->owns_orocos = false;
00051                 handle->owns_typelib = false;
00052                 return handle->orocos_sample;
00053             }
00054         }
00055 
00056         void refreshTypelibSample(Handle* handle)
00057         {
00058             // Nothing to do
00059         }
00060 
00061         void refreshOrocosSample(Handle* handle)
00062         {
00063             // Nothing to do
00064         }
00065 
00066         RTT::base::DataSourceBase::shared_ptr getDataSource(Handle* handle)
00067         {
00068             return new RTT::internal::ReferenceDataSource<T>(*reinterpret_cast<T*>(handle->orocos_sample));
00069         }
00070 
00071         bool readDataSource(RTT::base::DataSourceBase& source_base, Handle* handle)
00072         {
00073             RTT::internal::DataSource<T>& source = dynamic_cast<RTT::internal::DataSource<T>&>(source_base);
00074             if (source.evaluate())
00075             {
00076                 T& data = *reinterpret_cast<T*>(handle->orocos_sample);
00077                 data = dynamic_cast<RTT::internal::DataSource<T>&>(source_base).get();
00078                 return true;
00079             }
00080             return false;
00081         }
00082         void writeDataSource(RTT::base::DataSourceBase& source, Handle const* handle)
00083         {
00084             T const& data = *reinterpret_cast<T const*>(handle->orocos_sample);
00085             dynamic_cast<RTT::internal::AssignableDataSource<T>&>(source).set(data);
00086         }
00087     };
00088 }
00089 
00090 #endif
00091 


rtt_typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 18:49:39