IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
ibrcommon
ibrdtn
ibrdtn
api
data
AdministrativeBlock.cpp
AdministrativeBlock.h
AgeBlock.cpp
AgeBlock.h
Block.cpp
Block.h
Bundle.cpp
Bundle.h
BundleBuilder.cpp
BundleBuilder.h
BundleFragment.cpp
BundleFragment.h
BundleID.cpp
BundleID.h
BundleList.cpp
BundleList.h
BundleMerger.cpp
BundleMerger.h
BundleSet.cpp
BundleSet.h
BundleSetImpl.cpp
BundleSetImpl.h
BundleString.cpp
BundleString.h
CompressedPayloadBlock.cpp
CompressedPayloadBlock.h
CustodySignalBlock.cpp
CustodySignalBlock.h
Dictionary.cpp
Dictionary.h
DTNTime.cpp
DTNTime.h
EID.cpp
EID.h
Endianess.cpp
Endianess.h
Exceptions.h
ExtensionBlock.cpp
ExtensionBlock.h
MemoryBundleSet.cpp
MemoryBundleSet.h
MetaBundle.cpp
MetaBundle.h
Number.h
PayloadBlock.cpp
PayloadBlock.h
PrimaryBlock.cpp
PrimaryBlock.h
SchedulingBlock.cpp
SchedulingBlock.h
ScopeControlHopLimitBlock.cpp
ScopeControlHopLimitBlock.h
SDNV.cpp
SDNV.h
Serializer.cpp
Serializer.h
StatusReportBlock.cpp
StatusReportBlock.h
StreamBlock.cpp
StreamBlock.h
TrackingBlock.cpp
TrackingBlock.h
security
streams
utils
config.h
dummy.cpp
ibrdtn.h
tools
File Members
PayloadBlock.cpp
Go to the documentation of this file.
1
/*
2
* PayloadBlock.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 "
ibrdtn/data/PayloadBlock.h
"
23
#include "
ibrdtn/data/Exceptions.h
"
24
#include <
ibrcommon/thread/MutexLock.h
>
25
#include <
ibrcommon/Logger.h
>
26
27
namespace
dtn
28
{
29
namespace
data
30
{
31
const
dtn::data::block_t
PayloadBlock::BLOCK_TYPE
= 1;
32
33
PayloadBlock::PayloadBlock
()
34
:
Block
(
PayloadBlock
::BLOCK_TYPE), _blobref(ibrcommon::BLOB::create())
35
{
36
}
37
38
PayloadBlock::PayloadBlock
(
ibrcommon::BLOB::Reference
ref)
39
:
Block
(
PayloadBlock
::BLOCK_TYPE), _blobref(ref)
40
{
41
}
42
43
PayloadBlock::~PayloadBlock
()
44
{
45
}
46
47
ibrcommon::BLOB::Reference
PayloadBlock::getBLOB
()
const
48
{
49
return
_blobref;
50
}
51
52
Length
PayloadBlock::getLength
()
const
53
{
54
return
_blobref.
size
();
55
}
56
57
std::ostream&
PayloadBlock::serialize
(std::ostream &stream,
Length
&length)
const
58
{
59
ibrcommon::BLOB::Reference
blobref = _blobref;
60
ibrcommon::BLOB::iostream
io = blobref.
iostream
();
61
62
try
{
63
ibrcommon::BLOB::copy
(stream, *io, io.
size
());
64
length += io.
size
();
65
}
catch
(
const
ibrcommon::IOException
&ex) {
66
throw
dtn::SerializationFailedException
(ex.
what
());
67
}
68
69
return
stream;
70
}
71
72
std::ostream&
PayloadBlock::serialize
(std::ostream &stream,
const
Length
&clip_offset,
const
Length
&clip_length)
const
73
{
74
ibrcommon::BLOB::Reference
blobref = _blobref;
75
ibrcommon::BLOB::iostream
io = blobref.
iostream
();
76
77
try
{
78
(*io).seekg(clip_offset, std::ios::beg);
79
ibrcommon::BLOB::copy
(stream, *io, clip_length);
80
}
catch
(
const
ibrcommon::IOException
&ex) {
81
throw
dtn::SerializationFailedException
(ex.
what
());
82
}
83
84
return
stream;
85
}
86
87
std::istream&
PayloadBlock::deserialize
(std::istream &stream,
const
Length
&length)
88
{
89
// lock the BLOB
90
ibrcommon::BLOB::iostream
io = _blobref.
iostream
();
91
92
// clear the blob
93
io.
clear
();
94
95
// check if the blob is ready
96
if
(!(*io).good())
throw
dtn::SerializationFailedException
(
"could not open BLOB for payload"
);
97
98
// set block not processed bit to false
99
set
(
dtn::data::Block::FORWARDED_WITHOUT_PROCESSED
,
false
);
100
101
try
{
102
ibrcommon::BLOB::copy
(*io, stream, length);
103
}
catch
(
const
ibrcommon::IOException
&ex) {
104
throw
dtn::PayloadReceptionInterrupted
(length, ex.
what
());
105
}
106
107
return
stream;
108
}
109
}
110
}
ibrdtn
ibrdtn
data
PayloadBlock.cpp
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4