IBR-DTNSuite  0.8
daemon/src/routing/StaticRouteChangeEvent.cpp
Go to the documentation of this file.
00001 /*
00002  * StaticRouteChangeEvent.cpp
00003  *
00004  *  Created on: 08.02.2012
00005  *      Author: morgenro
00006  */
00007 
00008 #include "routing/StaticRouteChangeEvent.h"
00009 #include <sstream>
00010 
00011 namespace dtn
00012 {
00013         namespace routing
00014         {
00015                 StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t)
00016                  : type(t)
00017                 {
00018                 }
00019 
00020                 StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t, const dtn::data::EID &n, const std::string p, size_t to)
00021                  : type(t), nexthop(n), pattern(p), timeout(to)
00022                 {
00023                 }
00024 
00025                 StaticRouteChangeEvent::StaticRouteChangeEvent(CHANGE_TYPE t, const dtn::data::EID &n, const dtn::data::EID &d, size_t to)
00026                  : type(t), nexthop(n), destination(d), timeout(to)
00027                 {
00028                 }
00029 
00030                 StaticRouteChangeEvent::~StaticRouteChangeEvent()
00031                 {
00032                 }
00033 
00034                 const std::string StaticRouteChangeEvent::getName() const
00035                 {
00036                         return StaticRouteChangeEvent::className;
00037                 }
00038 
00039                 std::string StaticRouteChangeEvent::toString() const
00040                 {
00041                         std::stringstream ss;
00042                         ss << getName() << ": ";
00043 
00044                         switch (type)
00045                         {
00046                         case ROUTE_ADD:
00047                                 ss << "add route ";
00048 
00049                                 if (pattern.length() > 0)
00050                                 {
00051                                         ss << pattern;
00052                                 }
00053                                 else
00054                                 {
00055                                         ss << destination.getString();
00056                                 }
00057 
00058                                 ss << " => " << nexthop.getString();
00059                                 if (timeout > 0) ss << "; timeout = " << timeout;
00060                                 break;
00061                         case ROUTE_DEL:
00062                                 ss << "del route ";
00063 
00064                                 if (pattern.length() > 0)
00065                                 {
00066                                         ss << pattern;
00067                                 }
00068                                 else
00069                                 {
00070                                         ss << destination.getString();
00071                                 }
00072 
00073                                 ss << " => " << nexthop.getString();
00074                                 break;
00075                         case ROUTE_EXPIRED:
00076                                 ss << "route expired";
00077                                 break;
00078                         case ROUTE_CLEAR:
00079                                 ss << "routes cleared";
00080                                 break;
00081                         default:
00082                                 ss << "unknown";
00083                                 break;
00084                         }
00085 
00086                         return ss.str();
00087                 }
00088 
00089                 void StaticRouteChangeEvent::raiseEvent(CHANGE_TYPE t)
00090                 {
00091                         dtn::core::Event::raiseEvent( new StaticRouteChangeEvent(t) );
00092                 }
00093 
00094                 void StaticRouteChangeEvent::raiseEvent(CHANGE_TYPE t, const dtn::data::EID &n, const std::string p, size_t to)
00095                 {
00096                         dtn::core::Event::raiseEvent( new StaticRouteChangeEvent(t, n, p, to) );
00097                 }
00098 
00099                 void StaticRouteChangeEvent::raiseEvent(CHANGE_TYPE t, const dtn::data::EID &n, const dtn::data::EID &d, size_t to)
00100                 {
00101                         dtn::core::Event::raiseEvent( new StaticRouteChangeEvent(t, n, d, to) );
00102                 }
00103 
00104                 const string StaticRouteChangeEvent::className = "StaticRouteChangeEvent";
00105         } /* namespace routing */
00106 } /* namespace dtn */