EventBinding.hh

Go to the documentation of this file.
00001 // $Id: EventBinding.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_PPI_detail_EventBinding_
00027 #define HH_SENF_PPI_detail_EventBinding_ 1
00028 
00029 // Custom includes
00030 #include <senf/Scheduler/ClockService.hh>
00031 #include <senf/PPI/predecl.hh>
00032 #include "Callback.hh"
00033 
00034 //#include "EventBinding.mpp"
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 namespace senf {
00038 namespace ppi {
00039 namespace detail {
00040 
00042     class EventBindingBase
00043     {
00044     public:
00045         ~EventBindingBase();
00046 
00047         EventManager & manager() const;
00048         module::Module & module() const;
00049 
00050     protected:
00051         EventBindingBase(EventManager & manager, module::Module & module,
00052                          EventDescriptor & descriptor);
00053 
00054         void eventTime(ClockService::clock_type time);
00055 
00056     private:
00057         EventManager * manager_;
00058         module::Module * module_;
00059         EventDescriptor * descriptor_;
00060 
00061         friend class senf::ppi::EventManager;
00062         friend class senf::ppi::EventDescriptor;
00063     };
00064 
00067     template <class EventType, class Self>
00068     class EventBindingHelper
00069     {
00070     public:
00071         typedef typename detail::EventArgType<EventType>::type EventArg;
00072 
00073         void callback(EventArg event, ClockService::clock_type time);
00074         void callback(EventArg event);
00075 
00076     private:
00077         Self & self();
00078     };
00079 
00080 #ifndef DOXYGEN
00081 
00082     template <class Self>
00083     class EventBindingHelper<void,Self>
00084     {
00085     public:
00086         void callback(ClockService::clock_type time);
00087         void callback();
00088 
00089     private:
00090         Self & self();
00091     };
00092 
00093 #endif
00094 
00096     template <class EventType>
00097     class EventBinding
00098         : public EventBindingBase,
00099           public EventBindingHelper<EventType, EventBinding<EventType> >
00100     {
00101     public:
00102         typedef EventType Event;
00103         typedef typename detail::EventArgType<Event>::type EventArg;
00104         typedef typename detail::Callback<EventArg>::type Callback;
00105 
00106         EventBinding(EventManager & manager, module::Module & module, Callback callback,
00107                      EventDescriptor & descriptor);
00108 
00109     private:
00110         Callback callback_;
00111 
00112         friend class EventBindingHelper<EventType, EventBinding<EventType> >;
00113     };
00114 
00115 }}}
00116 
00117 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00118 #include "EventBinding.cci"
00119 //#include "EventBinding.ct"
00120 #include "EventBinding.cti"
00121 #endif
00122 
00123 
00124 // Local Variables:
00125 // mode: c++
00126 // fill-column: 100
00127 // comment-column: 40
00128 // c-file-style: "senf"
00129 // indent-tabs-mode: nil
00130 // ispell-local-dictionary: "american"
00131 // compile-command: "scons -u ../test"
00132 // End: