Wiselib
wiselib.testing/algorithms/privacy/privacy_message.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef __PRIVACY_MSG_H__
00020 #define __PRIVACY_MSG_H__
00021 
00022 namespace wiselib
00023 {
00024    template<   typename Os_P,
00025             typename Radio_P>
00026    class PrivacyMessageType
00027    {
00028    public:
00029       typedef Os_P Os;
00030       typedef Radio_P Radio;
00031       typedef typename Radio::block_data_t block_data_t;
00032       typedef typename Radio::size_t size_t;
00033       typedef typename Radio::message_id_t message_id_t;
00034       // --------------------------------------------------------------------
00035       inline PrivacyMessageType()
00036       {
00037          set_msg_id( 0 );
00038          size_t len = 0;
00039          write<Os, block_data_t, size_t>( buff + PAYLOAD_LEN_POS, len );
00040       }
00041       // --------------------------------------------------------------------
00042       inline message_id_t msg_id()
00043       {
00044          return read<Os, block_data_t, message_id_t>( buff + MSG_ID_POS );
00045       };
00046       // --------------------------------------------------------------------
00047       inline void set_msg_id( message_id_t msg_id )
00048       {
00049          write<Os, block_data_t, message_id_t>( buff + MSG_ID_POS, msg_id );
00050       }
00051       // --------------------------------------------------------------------
00052       inline uint16_t request_id()
00053       {
00054          return read<Os, block_data_t, uint16_t>( buff + REQ_ID_POS );
00055       }
00056       // --------------------------------------------------------------------
00057       inline void set_request_id( uint16_t req_id )
00058       {
00059          write<Os, block_data_t, uint16_t>( buff + REQ_ID_POS, req_id );
00060       }
00061       // --------------------------------------------------------------------
00062       inline size_t payload_size()
00063       {
00064          return read<Os, block_data_t, size_t>( buff + PAYLOAD_LEN_POS );
00065       }
00066       // --------------------------------------------------------------------
00067       inline block_data_t* payload()
00068       { 
00069          return buff + PAYLOAD_POS;
00070       }
00071       // --------------------------------------------------------------------
00072       inline void set_payload( size_t len, block_data_t *buf )
00073       {
00074          write<Os, block_data_t, size_t>( buff + PAYLOAD_LEN_POS, len );
00075          memcpy( buff + PAYLOAD_POS, buf, len );
00076       }
00077       // --------------------------------------------------------------------
00078       inline size_t buffer_size()
00079       {
00080          return PAYLOAD_POS + payload_size();
00081       }
00082       // --------------------------------------------------------------------
00083       inline block_data_t* buffer()
00084       {
00085          return buff;
00086       }
00087       // --------------------------------------------------------------------
00088    private:
00089       enum data_positions
00090       {
00091          MSG_ID_POS = 0,
00092          REQ_ID_POS = MSG_ID_POS + sizeof( message_id_t),
00093          PAYLOAD_LEN_POS = REQ_ID_POS + sizeof( uint16_t ),
00094          PAYLOAD_POS = PAYLOAD_LEN_POS + sizeof( size_t )
00095       };
00096       block_data_t buff[Radio::MAX_MESSAGE_LENGTH];
00097    };
00098 }
00099 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines