Wiselib
wiselib.testing/algorithms/routing/greedy/greedy_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 __GREEDY_MSG_H__
00020 #define __GREEDY_MSG_H__
00021 
00022 namespace wiselib
00023 {
00024 
00025    template<typename OsModel_P,
00026          typename Node_P,
00027             typename Radio_P>
00028    class Greedy_Message
00029    {
00030    public:
00031       typedef OsModel_P OsModel;
00032      typedef Node_P Node;
00033       typedef Radio_P Radio;
00034       typedef typename Radio::block_data_t block_data_t;
00035       typedef typename Radio::size_t size_t;
00036       typedef typename Radio::message_id_t message_id_t;
00037       // --------------------------------------------------------------------
00038       inline Greedy_Message();
00039       // --------------------------------------------------------------------
00040       inline message_id_t msg_id()
00041       { return read<OsModel, block_data_t, message_id_t>( buffer ); };
00042       // --------------------------------------------------------------------
00043       inline void set_msg_id( message_id_t id )
00044       { write<OsModel, block_data_t, message_id_t>( buffer, id ); }
00045      // --------------------------------------------------------------------
00046       inline Node node()
00047       { return read<OsModel, block_data_t, Node>( buffer + NODE_POS ); };
00048       // --------------------------------------------------------------------
00049       inline void set_node( Node n )
00050       { write<OsModel, block_data_t, Node>( buffer + NODE_POS, n ); }
00051      // --------------------------------------------------------------------
00052       inline size_t payload_size()
00053       { return read<OsModel, block_data_t, size_t>(buffer + PAYLOAD_POS); }
00054       // --------------------------------------------------------------------
00055       inline block_data_t* payload()
00056       { return buffer + PAYLOAD_POS + sizeof(size_t); }
00057       // --------------------------------------------------------------------
00058       inline void set_payload( size_t len, block_data_t *buf )
00059       {
00060          write<OsModel, block_data_t, size_t>(buffer + PAYLOAD_POS, len);
00061          memcpy( buffer + PAYLOAD_POS + sizeof(size_t), buf, len);
00062       }
00063       // --------------------------------------------------------------------
00064       inline size_t buffer_size()
00065       { return PAYLOAD_POS + sizeof(size_t) + payload_size(); }
00066 
00067 
00068       enum data_positions
00069       {
00070         MESSAGE_ID_POS = 0,
00071         NODE_POS = MESSAGE_ID_POS + sizeof(message_id_t),
00072         PAYLOAD_POS = NODE_POS + sizeof(Node)
00073         
00074       };
00075    private:
00076       block_data_t buffer[Radio::MAX_MESSAGE_LENGTH];
00077    };
00078    // -----------------------------------------------------------------------
00079    template<typename OsModel_P,
00080            typename Node_P,
00081             typename Radio_P>
00082    Greedy_Message<OsModel_P, Node_P, Radio_P>::
00083    Greedy_Message()
00084    {
00085       set_msg_id( 0 );
00086       size_t len = 0;
00087       write<OsModel, block_data_t, size_t>(buffer + PAYLOAD_POS, len);
00088    }
00089 
00090 }
00091 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines