Orocos Real-Time Toolkit  2.5.0
SendHandle.hpp
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:55:18 CEST 2010  SendHandle.hpp
00003 
00004                         SendHandle.hpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
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 
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             //impl->dispose();
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