Menu

Fragmenter.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2009-2010 Philipp Werner <philipp.werner@st.ovgu.de>
00004  *                         Michael Schulze <mschulze@ivs.cs.uni-magdeburg.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 
00042 #ifndef __FRAGMENTER_H_248EC79C4F9347__
00043 #define __FRAGMENTER_H_248EC79C4F9347__
00044 
00045 
00046 #include "debug.h"
00047 
00048 #include "assert/staticerror.h"
00049 
00050 #include "mw/afp/Config.h"
00051 #include "mw/afp/FragPolicySelector.h"
00052 
00053 
00054 namespace famouso {
00055     namespace mw {
00056         namespace afp {
00057 
00058 
00070             template < class AFPFC, unsigned int mtu_compile_time = 0 >
00071             class Fragmenter {
00072 
00073                     typedef FragPolicySelector<AFPFC> FCP;
00074 
00075                     typedef class FCP::FragImplPolicy FragmenterImpl;
00076 
00077                 public:
00078 
00079                     typedef typename FCP::SizeProp::elen_t   elen_t;
00080                     typedef typename FCP::SizeProp::flen_t   flen_t;
00081                     typedef typename FCP::SizeProp::fcount_t fcount_t;
00082 
00083                 protected:
00084 
00086                     FragmenterImpl frag;
00087 
00088                 public:
00089 
00095                     Fragmenter(const uint8_t * event_data, elen_t event_length) {
00096                         // Compile time check if minimum header fits into MTU
00097                         FAMOUSO_STATIC_ASSERT_ERROR(mtu_compile_time > FragmenterImpl::min_header_length,
00098                                                     MTU_is_too_small_for_this_configuration, ());
00099                         frag.init(event_data, event_length, mtu_compile_time);
00100                     }
00101 
00108                     Fragmenter(const uint8_t * event_data, elen_t event_length, flen_t mtu) {
00109                         frag.init(event_data, event_length, mtu);
00110                     }
00111 
00117                     bool error() {
00118                         return frag.error();
00119                     }
00120 
00126                     flen_t get_fragment(uint8_t * fragment_data) {
00127                         return frag.get_fragment(fragment_data);
00128                     }
00129             };
00130 
00131 
00135             template < unsigned int mtu_compile_time >
00136             class Fragmenter<Disable, mtu_compile_time> {
00137 
00138                 public:
00139 
00140                     typedef uint16_t elen_t;
00141                     typedef uint16_t flen_t;
00142                     typedef uint16_t fcount_t;
00143 
00149                     Fragmenter(const uint8_t * event_data, elen_t event_length) {
00150                         ::logging::log::emit< ::logging::Warning>()
00151                             << PROGMEMSTRING("Event is to big to deliver at once and fragmentation is disabled.")
00152                             << ::logging::log::endl;
00153                     }
00154 
00161                     Fragmenter(const uint8_t * event_data, elen_t event_length, flen_t mtu) {
00162                         ::logging::log::emit< ::logging::Warning>()
00163                             << PROGMEMSTRING("Event is to big to deliver at once and fragmentation is disabled.")
00164                             << ::logging::log::endl;
00165                     }
00166 
00172                     bool error() {
00173                         return true;
00174                     }
00175 
00181                     flen_t get_fragment(uint8_t * fragment_data) {
00182                         return 0;
00183                     }
00184             };
00185 
00186         } // namespace afp
00187     } // namespace mw
00188 } // namespace famouso
00189 
00190 
00191 
00192 #endif // __FRAGMENTER_H_248EC79C4F9347__
00193