IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
StatusReportGenerator.cpp
Go to the documentation of this file.
1
/*
2
* StatusReportGenerator.cpp
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#include "
core/EventDispatcher.h
"
23
#include "
core/StatusReportGenerator.h
"
24
#include "
core/BundleEvent.h
"
25
#include "
core/BundleGeneratedEvent.h
"
26
#include "
core/BundleCore.h
"
27
#include <
ibrdtn/data/MetaBundle.h
>
28
29
namespace
dtn
30
{
31
namespace
core
32
{
33
using namespace
dtn::data;
34
35
StatusReportGenerator::StatusReportGenerator
()
36
{
37
dtn::core::EventDispatcher<BundleEvent>::add
(
this
);
38
}
39
40
StatusReportGenerator::~StatusReportGenerator
()
41
{
42
dtn::core::EventDispatcher<BundleEvent>::remove
(
this
);
43
}
44
45
void
StatusReportGenerator::createStatusReport(
const
dtn::data::MetaBundle
&b,
StatusReportBlock::TYPE
type,
StatusReportBlock::REASON_CODE
reason)
46
{
47
// create a new bundle
48
Bundle
bundle;
49
50
// create a new statusreport block
51
StatusReportBlock
report;
52
53
bundle.
set
(
dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD
,
true
);
54
55
// get the flags and set the status flag
56
report.
status
|=
static_cast<
char
>
(type);
57
58
// set the reason code
59
report.
reasoncode
|=
static_cast<
char
>
(reason);
60
61
switch
(type)
62
{
63
case
StatusReportBlock::RECEIPT_OF_BUNDLE
:
64
report.
timeof_receipt
.
set
();
65
break
;
66
67
case
StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE
:
68
report.
timeof_custodyaccept
.
set
();
69
break
;
70
71
case
StatusReportBlock::FORWARDING_OF_BUNDLE
:
72
report.
timeof_forwarding
.
set
();
73
break
;
74
75
case
StatusReportBlock::DELIVERY_OF_BUNDLE
:
76
report.
timeof_delivery
.
set
();
77
break
;
78
79
case
StatusReportBlock::DELETION_OF_BUNDLE
:
80
report.
timeof_deletion
.
set
();
81
break
;
82
83
default
:
84
85
break
;
86
}
87
88
// set source and destination
89
bundle.
source
=
dtn::core::BundleCore::local
;
90
bundle.
set
(
dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON
,
true
);
91
bundle.
destination
= b.
reportto
;
92
93
// set lifetime to the origin bundle lifetime
94
bundle.
lifetime
= b.
lifetime
;
95
96
// set bundle parameter
97
report.
bundleid
= b;
98
99
dtn::data::PayloadBlock
&payload = bundle.
push_back
<
dtn::data::PayloadBlock
>();
100
report.
write
(payload);
101
102
dtn::core::BundleGeneratedEvent::raise
(bundle);
103
}
104
105
void
StatusReportGenerator::raiseEvent
(
const
dtn::core::Event
*evt)
throw
()
106
{
107
try
{
108
const
BundleEvent
&bundleevent =
dynamic_cast<
const
BundleEvent
&
>
(*evt);
109
const
dtn::data::MetaBundle
&b = bundleevent.
getBundle
();
110
111
// do not generate status reports for other status reports or custody signals
112
if
(b.
get
(
dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD
))
return
;
113
114
switch
(bundleevent.
getAction
())
115
{
116
case
BUNDLE_RECEIVED
:
117
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_RECEPTION
))
118
{
119
createStatusReport(b,
StatusReportBlock::RECEIPT_OF_BUNDLE
, bundleevent.
getReason
());
120
}
121
break
;
122
case
BUNDLE_DELETED
:
123
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_DELETION
))
124
{
125
createStatusReport(b,
StatusReportBlock::DELETION_OF_BUNDLE
, bundleevent.
getReason
());
126
}
127
break
;
128
129
case
BUNDLE_FORWARDED
:
130
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_FORWARDING
))
131
{
132
createStatusReport(b,
StatusReportBlock::FORWARDING_OF_BUNDLE
, bundleevent.
getReason
());
133
}
134
break
;
135
136
case
BUNDLE_DELIVERED
:
137
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_DELIVERY
))
138
{
139
createStatusReport(b,
StatusReportBlock::DELIVERY_OF_BUNDLE
, bundleevent.
getReason
());
140
}
141
break
;
142
143
case
BUNDLE_CUSTODY_ACCEPTED
:
144
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_CUSTODY_ACCEPTANCE
))
145
{
146
createStatusReport(b,
StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE
, bundleevent.
getReason
());
147
}
148
break
;
149
150
default
:
151
break
;
152
}
153
}
catch
(
const
std::bad_cast&) { };
154
}
155
}
156
}
daemon
src
core
StatusReportGenerator.cpp
Generated on Thu Mar 27 2014 09:26:20 for IBR-DTNSuite by
1.8.4