IBR-DTNSuite
0.8
|
00001 /* 00002 * EventDebugger.cpp 00003 * 00004 * Created on: 06.03.2009 00005 * Author: morgenro 00006 */ 00007 00008 #include "core/EventDebugger.h" 00009 #include "core/NodeEvent.h" 00010 #include "core/CustodyEvent.h" 00011 #include "core/BundleEvent.h" 00012 #include "core/TimeEvent.h" 00013 #include <ibrcommon/Logger.h> 00014 #include <iostream> 00015 00016 using namespace std; 00017 using namespace ibrcommon; 00018 00019 namespace dtn 00020 { 00021 namespace core 00022 { 00023 EventDebugger::EventDebugger() 00024 { 00025 } 00026 00027 EventDebugger::~EventDebugger() 00028 { 00029 } 00030 00031 void EventDebugger::raiseEvent(const Event *evt) 00032 { 00033 const NodeEvent *node = dynamic_cast<const NodeEvent*>(evt); 00034 const BundleEvent *bundle = dynamic_cast<const BundleEvent*>(evt); 00035 const CustodyEvent *custody = dynamic_cast<const CustodyEvent*>(evt); 00036 const TimeEvent *time = dynamic_cast<const TimeEvent*>(evt); 00037 00038 if (custody != NULL) 00039 { 00040 switch (custody->getAction()) 00041 { 00042 case CUSTODY_ACCEPT: 00043 if (custody->getBundle().procflags & dtn::data::Bundle::CUSTODY_REQUESTED) 00044 { 00045 IBRCOMMON_LOGGER(notice) << evt->getName() << ": custody acceptance" << IBRCOMMON_LOGGER_ENDL; 00046 } 00047 break; 00048 00049 case CUSTODY_REJECT: 00050 if (custody->getBundle().procflags & dtn::data::Bundle::CUSTODY_REQUESTED) 00051 { 00052 IBRCOMMON_LOGGER(notice) << evt->getName() << ": custody reject" << IBRCOMMON_LOGGER_ENDL; 00053 } 00054 break; 00055 }; 00056 } 00057 else if (bundle != NULL) 00058 { 00059 switch (bundle->getAction()) 00060 { 00061 case BUNDLE_DELETED: 00062 IBRCOMMON_LOGGER(notice) << evt->getName() << ": bundle " << bundle->getBundle().toString() << " deleted" << IBRCOMMON_LOGGER_ENDL; 00063 break; 00064 case BUNDLE_CUSTODY_ACCEPTED: 00065 IBRCOMMON_LOGGER(notice) << evt->getName() << ": custody accepted for " << bundle->getBundle().toString() << IBRCOMMON_LOGGER_ENDL; 00066 break; 00067 case BUNDLE_FORWARDED: 00068 IBRCOMMON_LOGGER(notice) << evt->getName() << ": bundle " << bundle->getBundle().toString() << " forwarded" << IBRCOMMON_LOGGER_ENDL; 00069 break; 00070 case BUNDLE_DELIVERED: 00071 IBRCOMMON_LOGGER(notice) << evt->getName() << ": bundle " << bundle->getBundle().toString() << " delivered" << IBRCOMMON_LOGGER_ENDL; 00072 break; 00073 case BUNDLE_RECEIVED: 00074 IBRCOMMON_LOGGER(notice) << evt->getName() << ": bundle " << bundle->getBundle().toString() << " received" << IBRCOMMON_LOGGER_ENDL; 00075 break; 00076 case BUNDLE_STORED: 00077 IBRCOMMON_LOGGER(notice) << evt->getName() << ": bundle " << bundle->getBundle().toString() << " stored" << IBRCOMMON_LOGGER_ENDL; 00078 break; 00079 default: 00080 IBRCOMMON_LOGGER(notice) << evt->getName() << ": unknown" << IBRCOMMON_LOGGER_ENDL; 00081 break; 00082 } 00083 } 00084 else if (node != NULL) 00085 { 00086 switch (node->getAction()) 00087 { 00088 case NODE_INFO_UPDATED: 00089 IBRCOMMON_LOGGER_DEBUG(10) << evt->getName() << ": Info updated for " << node->getNode().toString() << IBRCOMMON_LOGGER_ENDL; 00090 break; 00091 case NODE_AVAILABLE: 00092 IBRCOMMON_LOGGER(notice) << evt->getName() << ": Node " << node->getNode().toString() << " available " << IBRCOMMON_LOGGER_ENDL; 00093 break; 00094 case NODE_UNAVAILABLE: 00095 IBRCOMMON_LOGGER(notice) << evt->getName() << ": Node " << node->getNode().toString() << " unavailable" << IBRCOMMON_LOGGER_ENDL; 00096 break; 00097 default: 00098 IBRCOMMON_LOGGER(notice) << evt->getName() << ": unknown" << IBRCOMMON_LOGGER_ENDL; 00099 break; 00100 } 00101 } 00102 else if (time != NULL) 00103 { 00104 // do not debug print time events 00105 } 00106 else 00107 { 00108 // unknown event 00109 IBRCOMMON_LOGGER(notice) << evt->toString() << IBRCOMMON_LOGGER_ENDL; 00110 } 00111 } 00112 } 00113 }