• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/core/StatusReportGenerator.cpp

Go to the documentation of this file.
00001 /*
00002  * StatusReportGenerator.cpp
00003  *
00004  *  Created on: 17.02.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #include "core/StatusReportGenerator.h"
00009 #include "core/BundleEvent.h"
00010 #include "core/BundleGeneratedEvent.h"
00011 #include "core/BundleCore.h"
00012 #include <ibrdtn/data/MetaBundle.h>
00013 
00014 namespace dtn
00015 {
00016         namespace core
00017         {
00018                 using namespace dtn::data;
00019 
00020                 StatusReportGenerator::StatusReportGenerator()
00021                 {
00022                         bindEvent(BundleEvent::className);
00023                 }
00024 
00025                 StatusReportGenerator::~StatusReportGenerator()
00026                 {
00027                         unbindEvent(BundleEvent::className);
00028                 }
00029 
00030                 void StatusReportGenerator::createStatusReport(const dtn::data::MetaBundle &b, StatusReportBlock::TYPE type, StatusReportBlock::REASON_CODE reason)
00031                 {
00032                         // create a new bundle
00033                         Bundle bundle;
00034 
00035                         // create a new statusreport block
00036                         StatusReportBlock &report = bundle.push_back<StatusReportBlock>();
00037 
00038                         bundle.set(dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD, true);
00039 
00040                         // get the flags and set the status flag
00041                         report._status |= type;
00042 
00043                         // set the reason code
00044                         report._reasoncode |= reason;
00045 
00046                         switch (type)
00047                         {
00048                                 case StatusReportBlock::RECEIPT_OF_BUNDLE:
00049                                         report._timeof_receipt.set();
00050                                 break;
00051 
00052                                 case StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE:
00053                                         report._timeof_custodyaccept.set();
00054                                 break;
00055 
00056                                 case StatusReportBlock::FORWARDING_OF_BUNDLE:
00057                                         report._timeof_forwarding.set();
00058                                 break;
00059 
00060                                 case StatusReportBlock::DELIVERY_OF_BUNDLE:
00061                                         report._timeof_delivery.set();
00062                                 break;
00063 
00064                                 case StatusReportBlock::DELETION_OF_BUNDLE:
00065                                         report._timeof_deletion.set();
00066                                 break;
00067 
00068                                 default:
00069 
00070                                 break;
00071                         }
00072 
00073                         // set source and destination
00074                         bundle._source = dtn::core::BundleCore::local;
00075                         bundle.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true);
00076                         bundle._destination = b.reportto;
00077 
00078                         // set bundle parameter
00079                         if (b.get(Bundle::FRAGMENT))
00080                         {
00081                                 report._fragment_offset = b.offset;
00082                                 report._fragment_length = b.appdatalength;
00083                                 report._admfield |= 1;
00084                         }
00085 
00086                         report._bundle_timestamp = b.timestamp;
00087                         report._bundle_sequence = b.sequencenumber;
00088                         report._source = b.source;
00089 
00090                         dtn::core::BundleGeneratedEvent::raise(bundle);
00091                 }
00092 
00093                 void StatusReportGenerator::raiseEvent(const Event *evt)
00094                 {
00095                         const BundleEvent *bundleevent = dynamic_cast<const BundleEvent*>(evt);
00096 
00097                         if (bundleevent != NULL)
00098                         {
00099                                 const dtn::data::MetaBundle &b = bundleevent->getBundle();
00100 
00101                                 switch (bundleevent->getAction())
00102                                 {
00103                                 case BUNDLE_RECEIVED:
00104                                         if ( b.get(Bundle::REQUEST_REPORT_OF_BUNDLE_RECEPTION))
00105                                         {
00106                                                 createStatusReport(b, StatusReportBlock::RECEIPT_OF_BUNDLE, bundleevent->getReason());
00107                                         }
00108                                         break;
00109                                 case BUNDLE_DELETED:
00110                                         if ( b.get(Bundle::REQUEST_REPORT_OF_BUNDLE_DELETION))
00111                                         {
00112                                                 createStatusReport(b, StatusReportBlock::DELETION_OF_BUNDLE, bundleevent->getReason());
00113                                         }
00114                                         break;
00115 
00116                                 case BUNDLE_FORWARDED:
00117                                         if ( b.get(Bundle::REQUEST_REPORT_OF_BUNDLE_FORWARDING))
00118                                         {
00119                                                 createStatusReport(b, StatusReportBlock::FORWARDING_OF_BUNDLE, bundleevent->getReason());
00120                                         }
00121                                         break;
00122 
00123                                 case BUNDLE_DELIVERED:
00124                                         if ( b.get(Bundle::REQUEST_REPORT_OF_BUNDLE_DELIVERY))
00125                                         {
00126                                                 createStatusReport(b, StatusReportBlock::DELIVERY_OF_BUNDLE, bundleevent->getReason());
00127                                         }
00128                                         break;
00129 
00130                                 case BUNDLE_CUSTODY_ACCEPTED:
00131                                         if ( b.get(Bundle::REQUEST_REPORT_OF_CUSTODY_ACCEPTANCE))
00132                                         {
00133                                                 createStatusReport(b, StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE, bundleevent->getReason());
00134                                         }
00135                                         break;
00136 
00137                                 default:
00138                                         break;
00139                                 }
00140                         }
00141                 }
00142         }
00143 }

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1