00001 #ifndef TYPELIB_MARSHALLER_HANDLE_HPP 00002 #define TYPELIB_MARSHALLER_HANDLE_HPP 00003 00004 namespace orogen_transports 00005 { 00006 struct TypelibMarshallerBase::Handle 00007 { 00010 TypelibMarshallerBase* marshaller; 00014 uint8_t* typelib_sample; 00018 bool owns_typelib; 00022 uint8_t* orocos_sample; 00026 bool owns_orocos; 00027 00028 void reset() 00029 { 00030 typelib_sample = 0; 00031 orocos_sample = 0; 00032 } 00033 00034 Handle(TypelibMarshallerBase* marshaller) 00035 : marshaller(marshaller) 00036 , typelib_sample(0), owns_typelib(true) 00037 , orocos_sample(0), owns_orocos(true) {} 00038 00039 template<typename Type> 00040 Handle(TypelibMarshallerBase* marshaller, Type* data) 00041 : marshaller(marshaller) 00042 , typelib_sample(reinterpret_cast<uint8_t*>(data)) 00043 , owns_typelib(true) 00044 , orocos_sample(typelib_sample) 00045 , owns_orocos(true) {} 00046 00047 template<typename TypelibType, typename OrocosType> 00048 Handle(TypelibMarshallerBase* marshaller, TypelibType* typelib_data, OrocosType* orocos_data) 00049 : marshaller(marshaller) 00050 , typelib_sample(reinterpret_cast<uint8_t*>(typelib_data)) 00051 , owns_typelib(true) 00052 , orocos_sample(reinterpret_cast<uint8_t*>(orocos_data)) 00053 , owns_orocos(true) {} 00054 00055 ~Handle() 00056 { 00057 if (owns_typelib && typelib_sample) 00058 marshaller->deleteTypelibSample(this); 00059 if (owns_orocos && orocos_sample) 00060 marshaller->deleteOrocosSample(this); 00061 } 00062 }; 00063 } 00064 #endif 00065