Wiselib
wiselib.testing/algorithms/bgu_clustering/TopologyMessage.h
Go to the documentation of this file.
00001 #ifndef TOPOLOGYMESSAGE_H_
00002 #define TOPOLOGYMESSAGE_H_
00003 
00004 #include "algorithms/bgu_clustering/Message.h"
00005 
00006 //#include <list>
00007 #include "util/pstl/list_static.h"
00008 
00009 namespace wiselib {
00010 
00011 #define BGU_TOPOLOGY_MESSAGE_ID 50
00012 
00016 class TopologyMessage: public Message
00017 {
00018 public:
00019    typedef list_iterator<topology_record_t> iterator;
00020    
00025    TopologyMessage(nodeid_t sender);
00026 
00032    TopologyMessage(uint8_t* buffer, uint32_t buffer_length);
00033    ~TopologyMessage();
00034 
00042    error_code_t serialize(uint8_t *buffer, uint32_t buffer_size);
00043    
00046    size_t serializationBufferSize();
00047 
00056    error_code_t applyTo(wiselib::MessageDestination* dest);
00057 
00062    error_code_t addTopologyRecord(const topology_record_t& record);
00063 
00067    iterator begin();
00068    iterator end();
00069 
00070    nodeid_t senderId();
00071 
00072 private:
00073    typedef list_static<Os, topology_record_t, 10> topology_container_t;
00074 
00075    topology_container_t _topology;
00076    nodeid_t _sender;
00077 //we need a struct that has a known size so we can serialize it. We don't want to enforce 
00078 //size requirements on the general struct, and we can't be sure about sizeof(bool) or sizeof(nodeit_t)
00079 //anyway, so:
00080 public:
00081    struct serializable_topology_record_t
00082    {
00083       typedef Radio::node_id_t node_id_t;
00084 
00085       enum SizeInformation
00086       {
00087          RECORD_SIZE = 3*sizeof(node_id_t) + 2
00088       };
00089       
00090       nodeid_t nodeid;
00091       uint8_t distance;
00092       bool is_leader;
00093 //       uint8_t _padding[2];
00094 
00095      nodeid_t leader;
00096      nodeid_t parent;
00097      /*     
00098       uint32_t leader;
00099       uint32_t parent;
00100      */
00101    };
00102 //    __attribute__((packed));
00103    
00104    struct topology_message_header_t
00105    {
00106       typedef uint8_t message_id_t;
00107       typedef uint8_t num_rec_t;
00108       typedef Radio::node_id_t node_id_t;
00109 
00110       enum SizeInformation
00111       {
00112          RECORD_SIZE = sizeof(message_id_t) + sizeof(num_rec_t) + sizeof(node_id_t)
00113       };
00114 
00115       message_id_t msgid;
00116       num_rec_t num_records;
00117       node_id_t sender;
00118    };
00119    
00120    void convert(serializable_topology_record_t, topology_record_t*);
00121    void convert(topology_record_t, serializable_topology_record_t*);
00122 };
00123 
00124 }
00125 
00126 #endif /* TOPOLOGYMESSAGE_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines