Wiselib
wiselib.testing/util/glab_rest_connector/swap_request_message.h
Go to the documentation of this file.
00001 /* 
00002  * File:   rest_request.h
00003  * Author: maxpagel
00004  *
00005  * Created on 27. Dezember 2010, 16:02
00006  */
00007 
00008 #ifndef _REST_REQUEST_H
00009 #define  _REST_REQUEST_H
00010 #include "util/serialization/simple_types.h"
00011 
00012 namespace wiselib
00013 {
00014 
00015    template<typename OsModel_P,
00016             typename Radio_P = typename OsModel_P::Radio>
00017    class SwapRequestMessage
00018    {
00019    public:
00020       typedef OsModel_P OsModel;
00021       typedef Radio_P Radio;
00022       typedef typename Radio::block_data_t block_data_t;
00023       typedef typename Radio::size_t size_t;
00024       // --------------------------------------------------------------------
00025       inline uint8_t command_type()
00026       { return read<OsModel, block_data_t, uint8_t>( buffer ); }
00027       // --------------------------------------------------------------------
00028       inline void set_command_type( uint8_t type )
00029       { write<OsModel, block_data_t, uint8_t>( buffer, type ); }
00030       // --------------------------------------------------------------------
00031       inline uint8_t request_id()
00032       { return read<OsModel, block_data_t, uint8_t>( buffer + REQUEST_ID_POS ); }
00033       // --------------------------------------------------------------------
00034       inline void set_request_id( uint8_t id )
00035       { write<OsModel, block_data_t, uint8_t>( buffer + REQUEST_ID_POS, id ); }
00036       // --------------------------------------------------------------------
00037       inline uint8_t request_opts_length()
00038       { return read<OsModel, block_data_t, uint8_t>( buffer + REQUEST_OPTS_SIZE_POS ); }
00039       // --------------------------------------------------------------------
00040       inline uint8_t request_type()
00041       { return read<OsModel, block_data_t, uint8_t>( buffer + REQUEST_TYPE ); }
00042       // --------------------------------------------------------------------
00043       inline void set_request_type( uint8_t dst )
00044       { write<OsModel, block_data_t, uint8_t>( buffer + REQUEST_TYPE, dst ); }
00045       // --------------------------------------------------------------------
00046       inline block_data_t* request_opts()
00047       { return buffer + REQUEST_OPTS_POS; }
00048       // --------------------------------------------------------------------
00049       inline void set_request_opts( size_t len, block_data_t *buf )
00050       {
00051          set_request_opts_length( len );
00052          memcpy( buffer + REQUEST_OPTS_POS, buf, len);
00053       }
00054       // --------------------------------------------------------------------
00055       inline size_t buffer_size()
00056       { return REQUEST_OPTS_POS + request_opts_length(); }
00057 
00058 
00059    private:
00060 
00061       inline void set_request_opts_length( uint8_t len )
00062       { write<OsModel, block_data_t, uint8_t>( buffer + REQUEST_OPTS_SIZE_POS, len ); }
00063       // --------------------------------------------------------------------
00064       enum data_in_positions
00065       {
00066          COMMAND_TYPE     = 0,
00067          REQUEST_ID_POS   = 1,
00068          REQUEST_TYPE     = 2,
00069          REQUEST_OPTS_SIZE_POS = 3,
00070          REQUEST_OPTS_POS      = 4
00071       };
00072       // --------------------------------------------------------------------
00073       block_data_t buffer[Radio_P::MAX_MESSAGE_LENGTH];
00074    };
00075 
00076 }
00077 
00078 
00079 #endif   /* _REST_REQUEST_H */
00080 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines