EventChannel.h
Go to the documentation of this file.00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2008-2010 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de> 00004 * 2010 Philipp Werner <philipp.werner@st.ovgu.de> 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * * Neither the name of the copyright holders nor the names of 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00028 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00029 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00030 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00031 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00032 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00033 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * 00037 * $Id$ 00038 * 00039 ******************************************************************************/ 00040 00041 #ifndef __EventChannel_h__ 00042 #define __EventChannel_h__ 00043 00044 #include "mw/common/Subject.h" 00045 #include "mw/common/Event.h" 00046 #include "mw/el/EventChannelHandler.h" 00047 #include "mw/attributes/AttributeSet.h" 00048 00049 #include "object/Chain.h" 00050 #include "case/Delegate.h" 00051 00052 namespace famouso { 00053 namespace mw { 00054 namespace api { 00055 00068 template < class ECH > 00069 class EventChannel : public Chain { 00070 // the 64Bit subject 00071 Subject _subj; 00072 // definition of the short network names of a subjectes 00073 typename ECH::SNN _snn; 00074 00075 protected: 00076 struct MWAction { 00077 enum { 00085 get_requirements, 00086 00093 start_real_time_delivery 00094 } action; 00095 uint8_t * buffer; 00096 }; 00097 00108 util::Delegate<MWAction &, uint16_t> mw_action_trampoline; 00109 00110 uint16_t dummy_mw_action_impl(MWAction & mw_action) { 00111 if (mw_action.action == MWAction::get_requirements) { 00112 // Return empty requirement attribute set 00113 typedef attributes::AttributeSet<> ReqAttr; 00114 if (mw_action.buffer) { 00115 new (mw_action.buffer) ReqAttr; 00116 } 00117 return ReqAttr::overallSize; 00118 } 00119 return 0; 00120 } 00121 00122 template <class LL, class EL> friend class ManagementLayer; 00123 00124 public: 00125 typedef ECH eventChannelHandler; 00126 00129 ECH& ech() const { 00130 return famouso::mw::el::EventChannelHandler<ECH>::ech(); 00131 } 00132 00136 typename ECH::SNN& snn() { 00137 return _snn; 00138 } 00139 00144 const typename ECH::SNN& snn() const { 00145 return _snn; 00146 } 00147 00150 const Subject &subject() const { 00151 return _subj; 00152 } 00153 00165 uint16_t get_requirements(uint8_t * buffer) const { 00166 MWAction mwa; 00167 mwa.action = MWAction::get_requirements; 00168 mwa.buffer = buffer; 00169 return mw_action_trampoline(mwa); 00170 } 00171 00172 protected: 00176 EventChannel(const Subject& s) : _subj(s) { 00177 mw_action_trampoline.template bind< 00178 EventChannel, 00179 &EventChannel::dummy_mw_action_impl>(this); 00180 } 00181 00182 00183 private: 00184 // Private copy constructor and copy ensure that event channels 00185 // cannot be copied 00186 EventChannel(const EventChannel<ECH> & e); 00187 const EventChannel<ECH> & operator=(const EventChannel<ECH> &); 00188 }; 00189 00190 } // namespace api 00191 } // namespace mw 00192 } // namespace famouso 00193 00194 00195 #endif /* __EventChannel_h__ */