Wiselib
|
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 ** Author: Christoph Knecht, University of Bern 2010 ** 00020 ***************************************************************************/ 00021 #ifndef DUMMY_APP_H 00022 #define DUMMY_APP_H 00023 00024 #include "algorithm/routing/dsdv_routing.h" 00025 #include <string.h> 00026 00027 namespace wiselib 00028 { 00029 template<typename OsModel_P, 00030 typename Encryption_P, 00031 typename Radio_P = typename OsModel_P::Radio, 00032 typename Debug_P = typename OsModel_P::Debug> 00033 class DummyApp 00034 : public RoutingBase<OsModel_P, Radio_P> 00035 { 00036 public: 00037 typedef OsModel_P OsModel; 00038 typedef Radio_P Radio; 00039 typedef Debug_P Debug; 00040 typedef Encryption_P EncryptionType; 00041 typedef DummyApp<OsModel, EncryptionType, Radio, Debug> self_type; 00042 typedef typename Radio::node_id_t node_id_t; 00043 typedef typename Radio::size_t size_t; 00044 typedef typename Radio::block_data_t block_data_t; 00045 typedef typename Radio::message_id_t message_id_t; 00046 00047 inline DummyApp(); 00048 inline void enable(); 00049 inline void disable(); 00050 inline void send( node_id_t, size_t, block_data_t* ); 00051 inline void receive( node_id_t, size_t, block_data_t* ); 00052 00053 inline void set_encryption( EncryptionType* encryption ) 00054 { encryption_ = encryption; }; 00055 00056 inline EncryptionType* encryption() 00057 { return encryption_; }; 00058 00059 private: 00060 EncryptionType *encryption_; 00061 00062 int callback_id_; 00063 uint16_t seq_nr_; 00064 }; 00065 // ----------------------------------------------------------------------- 00066 // ----------------------------------------------------------------------- 00067 // ----------------------------------------------------------------------- 00068 template<typename OsModel_P, 00069 typename Encryption_P, 00070 typename Radio_P, 00071 typename Debug_P> 00072 DummyApp<OsModel_P, Encryption_P, Radio_P, Debug_P>:: 00073 DummyApp() 00074 : callback_id_ ( 0 ), 00075 seq_nr_ ( 0 ) 00076 {} 00077 // ----------------------------------------------------------------------- 00078 template<typename OsModel_P, 00079 typename Encryption_P, 00080 typename Radio_P, 00081 typename Debug_P> 00082 void 00083 DummyApp<OsModel_P, Encryption_P, Radio_P, Debug_P>:: 00084 enable() 00085 { 00086 encryption_->template reg_recv_callback<self_type, &self_type::receive>( this ); 00087 } 00088 // ----------------------------------------------------------------------- 00089 template<typename OsModel_P, 00090 typename Encryption_P, 00091 typename Radio_P, 00092 typename Debug_P> 00093 void 00094 DummyApp<OsModel_P, Encryption_P, Radio_P, Debug_P>:: 00095 disable() 00096 { 00097 encryption_->unreg_recv_callback(); 00098 } 00099 // ----------------------------------------------------------------------- 00100 template<typename OsModel_P, 00101 typename Encryption_P, 00102 typename Radio_P, 00103 typename Debug_P> 00104 void 00105 DummyApp<OsModel_P, Encryption_P, Radio_P, Debug_P>:: 00106 receive( node_id_t from, size_t len, block_data_t *data ) 00107 { 00108 notify_receivers( from, len, data ); 00109 } 00110 // ----------------------------------------------------------------------- 00111 template<typename OsModel_P, 00112 typename Encryption_P, 00113 typename Radio_P, 00114 typename Debug_P> 00115 void 00116 DummyApp<OsModel_P, Encryption_P, Radio_P, Debug_P>:: 00117 send( node_id_t destination, size_t len, block_data_t *data ) 00118 { 00119 encryption_->send( destination, len, data ); 00120 } 00121 } 00122 #endif