/home/aherms/Code/git/awds-routing/src/awds/Metric.h

00001 #ifndef D__metric
00002 #define D__metric
00003 
00004 
00005 #include <awds/NodeId.h>
00006 #include <awds/NodeDescr.h>
00007 #include <awds/Topology.h>
00008 
00009 #include <limits>
00010 
00011 #include <iostream>
00012 
00013 namespace awds {
00014   
00015     class Routing;
00016     
00022     class Metric {
00023     protected:
00024         Routing *routing;
00025 
00026         virtual RTopology::link_quality_t my_get_quality(NodeDescr &ndescr) {
00027             return 10;
00028         }
00029     
00030         virtual unsigned long my_calculate( RTopology::link_quality_t forward, 
00031                                             RTopology::link_quality_t backward) {
00032             // no testing for "forward" and "backward" greater than 0 neccesary it 
00033             // is all done in calculate and get_qualities
00034             return 1;
00035         }
00036     public:
00037         Metric(Routing *r):routing(r) {
00038         }
00039 
00040         virtual ~Metric() {}
00041 
00042 
00045         virtual void addNode(const NodeId& nodeId) {}
00046       
00049         virtual void delNode(const NodeId& nodeId) {}
00050       
00054         virtual void begin_update() {}  
00055    
00059         virtual void end_update() {}
00060       
00064         virtual int update() {
00065             return 8;
00066         }
00067       
00071         RTopology::link_quality_t get_quality(NodeDescr &ndescr) {
00072         
00073             return std::max( std::min(my_get_quality(ndescr), RTopology::max_quality()),
00074                              (RTopology::link_quality_t)1);
00075         }
00076       
00080         unsigned long calculate(RTopology::LinkList::iterator &it) {
00081             RTopology::link_quality_t f,b;
00082             if (it->get_qualities(f,b)) {
00083                 unsigned long mw(my_calculate(f,b));
00084                 it->set_metric_weight(mw);
00085                 return mw;
00086             }
00087             return std::numeric_limits<unsigned long>::max();
00088         }
00089 
00090     };
00091 }
00092 
00093 #endif // D__metric
00094 
00095 /* This stuff is for emacs
00096  * Local variables:
00097  * mode:c++
00098  * c-basic-offset: 4
00099  * End:
00100  */

Generated on Tue Dec 11 17:58:48 2007 for AWDS by  doxygen 1.5.3-20071008