Wiselib
wiselib.testing/algorithms/cluster/reform_message.h
Go to the documentation of this file.
00001 /*
00002  * File:   reform_message.h
00003  * Author: Amaxilatis
00004  *
00005  */
00006 
00007 #ifndef RESUMECLUSTERMSG_H
00008 #define  RESUMECLUSTERMSG_H
00009 
00010 namespace wiselib {
00011 
00012 template<typename OsModel_P, typename Radio_P>
00013 class ResumeClusterMsg {
00014 public:
00015    typedef OsModel_P OsModel;
00016    typedef Radio_P Radio;
00017 
00018    typedef typename Radio::node_id_t node_id_t;
00019    typedef typename Radio::size_t size_t;
00020    typedef typename Radio::block_data_t block_data_t;
00021    typedef typename Radio::message_id_t message_id_t;
00022    typedef node_id_t cluster_id_t;
00023 
00024    enum data_positions {
00025       MSG_ID_POS = 0, // message id position inside the message [uint8]
00026       NODE_ID_POS = sizeof(message_id_t)
00027    };
00028 
00029    // --------------------------------------------------------------------
00030 
00031    ResumeClusterMsg() {
00032       set_msg_id(RESUME);
00033       set_node_id(0);
00034    }
00035    // --------------------------------------------------------------------
00036 
00037    ~ResumeClusterMsg() {
00038    }
00039 
00040    // get the message id
00041    inline message_id_t msg_id() {
00042       return read<OsModel, block_data_t, uint8_t> (buffer + MSG_ID_POS);
00043    }
00044    // --------------------------------------------------------------------
00045 
00046    // set the message id
00047    inline void set_msg_id(message_id_t id) {
00048       write<OsModel, block_data_t, uint8_t> (buffer + MSG_ID_POS, id);
00049    }
00050 
00051    inline node_id_t node_id() {
00052       return read<OsModel, block_data_t, node_id_t> (buffer + NODE_ID_POS);
00053    }
00054 
00055    inline void set_node_id(node_id_t node_id) {
00056       write<OsModel, block_data_t, node_id_t> (buffer + NODE_ID_POS, node_id);
00057    }
00058 
00059    inline size_t length() {
00060       return sizeof(uint8_t) + sizeof(node_id_t);
00061    }
00062 
00063 private:
00064    block_data_t buffer[Radio::MAX_MESSAGE_LENGTH]; // buffer for the message data
00065 };
00066 }
00067 #endif   /* RESUMECLUSTERMSG_H */
00068 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines