Wiselib
wiselib.testing/algorithms/group-key/fake_clustering.h
Go to the documentation of this file.
00001 #ifndef _FAKECLUSTERING_H
00002 #define _FAKECLUSTERING_H
00003 
00004 #include "util/delegates/delegate.hpp"
00005 
00006 // 0x1b95 in UNIGE, 0x6666 in RACTI, ? Shawn,
00007 // 6999 in smlLuebeck, 25061 in largeLuebeck
00008 
00009 #ifdef SHAWN
00010   #define FAKE_LEADER_ID 0
00011 #else
00012   #define FAKE_LEADER_ID 0x9473
00013 #endif
00014 
00015 namespace wiselib {
00016     template<typename OsModel_P,
00017     typename Radio_P,
00018     typename Timer_P,
00019     typename Debug_P>
00020 
00021     class FakeClustering {
00022     public:
00023         typedef OsModel_P OsModel;
00024         typedef Radio_P Radio;
00025         typedef Timer_P Timer;
00026         typedef Debug_P Debug;
00027         typedef FakeClustering<OsModel_P, Radio_P, Timer_P, Debug_P> self_t;
00028 
00029 //        typedef int cluster_id_t;
00030         typedef int cluster_level_t;
00031 // typedef typename Radio::node_id_t cluster_id_t;
00032         typedef typename Radio::node_id_t node_id_t;
00033         typedef typename Radio::size_t size_t;
00034         typedef typename Radio::block_data_t block_data_t;
00035         typedef wiselib::vector_static<OsModel, node_id_t, 200 > vector_t;
00036 
00037         typedef delegate1<void, int> cluster_delegate_t;
00038 
00039         cluster_level_t cluster_level() {
00040             return 0;
00041         }
00042 
00043         node_id_t cluster_id() {
00044             return 0;
00045         }
00046 
00047         bool is_cluster_head() {
00048             if( radio_->id() == FAKE_LEADER_ID )
00049       return 1;
00050             return 0;
00051         }
00052 
00053         node_id_t parent() {
00054             return 0;
00055         }
00056 
00057         size_t hops() {
00058             return 1;
00059         }
00060 
00061         template<class T, void (T::*TMethod)(int) >
00062         inline int reg_changed_callback(T *obj_pnt) {
00063             state_changed_callback_ = cluster_delegate_t::from_method<T, TMethod > (obj_pnt);
00064             return state_changed_callback_;
00065         }
00066 
00067         void unreg_changed_callback(int idx) {
00068             state_changed_callback_ = cluster_delegate_t();
00069         }
00070 
00071         void init(Radio& radio, Timer& timer, Debug& debug) {
00072              radio_ = &radio;
00073              timer_ = &timer;
00074              debug_ = &debug;
00075         }
00076 
00077         void enable(void) { }
00078 
00079         void disable(){ }
00080 
00081     private:
00082 
00083         Radio *radio_;
00084         Timer *timer_;
00085         Debug *debug_;
00086 
00087         cluster_delegate_t state_changed_callback_;
00088     };
00089 }
00090 
00091 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines