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
00038
00039 #ifndef ORO_CORELIB_SEND_HANDLE_HPP
00040 #define ORO_CORELIB_SEND_HANDLE_HPP
00041
00042 #include "rtt-config.h"
00043 #include "Logger.hpp"
00044 #include "internal/CollectSignature.hpp"
00045 #include "internal/CollectBase.hpp"
00046 #include "internal/ReturnSignature.hpp"
00047 #include "internal/ReturnBase.hpp"
00048 #include <boost/type_traits.hpp>
00049
00050 namespace RTT
00051 {
00057 template<class Signature>
00058 class SendHandle
00059 : public internal::CollectSignature<boost::function_traits<typename internal::CollectType<Signature>::Ft>::arity,
00060 typename internal::CollectType<Signature>::Ft,
00061 internal::CollectBase<Signature>* >,
00062 public internal::ReturnSignature<boost::function_traits<Signature>::arity,
00063 Signature,
00064 typename internal::CollectBase<Signature>::shared_ptr >
00065 {
00066 public:
00067 typedef internal::CollectSignature<boost::function_traits<typename internal::CollectType<Signature>::Ft>::arity,
00068 typename internal::CollectType<Signature>::Ft,
00069 internal::CollectBase<Signature>* > CBase;
00070 typedef internal::ReturnSignature<boost::function_traits<Signature>::arity,
00071 Signature,
00072 typename internal::CollectBase<Signature>::shared_ptr > RBase;
00076 SendHandle() {}
00077
00078 SendHandle(typename internal::CollectBase<Signature>::shared_ptr coll) : CBase( coll.get() ), RBase(coll) {}
00079
00083 SendHandle(const SendHandle& hs) : CBase(hs.cimpl), RBase(hs.impl) {}
00084
00088 ~SendHandle() {
00089
00090 }
00091
00092 SendHandle& operator=(base::DisposableInterface* implementation)
00093 {
00094 if (this->RBase::impl && this->RBase::impl == implementation)
00095 return *this;
00096 this->RBase::impl.reset( boost::dynamic_pointer_cast< internal::ReturnBase<Signature> >(implementation) );
00097 if ( !this->RBase::impl && implementation ) {
00098 log(Error) << "Tried to assign SendHandle from incompatible type."<< endlog();
00099 }
00100 this->CBase::cimpl = dynamic_cast< internal::CollectBase<Signature>* >(implementation);
00101 if ( !this->CBase::cimpl && implementation ) {
00102 log(Error) << "Tried to assign SendHandle from incompatible type."<< endlog();
00103 }
00104 return *this;
00105 }
00106
00111 operator bool() const { return ready();}
00112
00117 bool ready() const { return this->CBase::cimpl && this->RBase::impl ;}
00118
00119 using CBase::collect;
00120
00124 SendStatus collect()
00125 {
00126 if (this->impl)
00127 return this->impl->collect();
00128 return SendFailure;
00129 }
00130 protected:
00131 };
00132 }
00133 #endif