IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
BundleStorage.h
Go to the documentation of this file.
1
/*
2
* BundleStorage.h
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
#ifndef BUNDLESTORAGE_H_
23
#define BUNDLESTORAGE_H_
24
25
#include <
storage/BundleSeeker.h
>
26
#include <
storage/BundleResult.h
>
27
#include <
storage/BundleIndex.h
>
28
#include <
ibrdtn/data/Bundle.h
>
29
#include <
ibrdtn/data/BundleSet.h
>
30
#include <
ibrdtn/data/BundleID.h
>
31
#include <
ibrdtn/data/MetaBundle.h
>
32
#include <
ibrdtn/data/CustodySignalBlock.h
>
33
#include <
ibrcommon/data/BloomFilter.h
>
34
#include <
ibrcommon/thread/Mutex.h
>
35
36
#include <stdexcept>
37
#include <iterator>
38
#include <set>
39
40
namespace
dtn
41
{
42
namespace
storage
43
{
44
class
BundleStorage
:
public
BundleSeeker
45
{
46
public
:
47
class
BundleLoadException
:
public
NoBundleFoundException
48
{
49
public
:
50
BundleLoadException
(
string
what
=
"Error while loading bundle data."
) throw() :
NoBundleFoundException
(
what
)
51
{
52
};
53
};
54
55
class
StorageSizeExeededException
:
public
ibrcommon::Exception
56
{
57
public
:
58
StorageSizeExeededException
(
string
what
=
"No space left in the storage."
) throw() : ibrcommon::
Exception
(
what
)
59
{
60
};
61
};
62
66
virtual
~BundleStorage
() = 0;
67
72
virtual
void
store
(
const
dtn::data::Bundle
&bundle) = 0;
73
78
virtual
bool
contains
(
const
dtn::data::BundleID
&
id
) = 0;
79
83
virtual
dtn::data::MetaBundle
info
(
const
dtn::data::BundleID
&
id
) = 0;
84
90
virtual
dtn::data::Bundle
get
(
const
dtn::data::BundleID
&id) = 0;
91
95
virtual
void
get
(
const
BundleSelector
&cb,
BundleResult
&result)
throw
(
NoBundleFoundException
,
BundleSelectorException
) = 0;
96
100
virtual
const
eid_set
getDistinctDestinations
() = 0;
101
107
virtual
void
remove
(
const
dtn::data::BundleID
&id) = 0;
108
114
void
remove
(
const
dtn::data::Bundle
&b);
115
119
virtual
void
clear
() {};
120
124
virtual
bool
empty
() {
return
true
; };
125
129
virtual
dtn::data::Size
count
() {
return
0; };
130
134
dtn::data::Length
size
()
const
;
135
141
virtual
void
releaseCustody
(
const
dtn::data::EID
&custodian,
const
dtn::data::BundleID
&
id
) = 0;
142
149
const
dtn::data::EID
acceptCustody
(
const
dtn::data::MetaBundle
&meta);
150
156
void
rejectCustody
(
const
dtn::data::MetaBundle
&meta,
dtn::data::CustodySignalBlock::REASON_CODE
reason =
dtn::data::CustodySignalBlock::NO_ADDITIONAL_INFORMATION
);
157
161
void
attach
(
dtn::storage::BundleIndex
*index);
162
166
void
detach
(
dtn::storage::BundleIndex
*index);
167
168
/*** BEGIN: methods for unit-testing ***/
169
173
virtual
void
wait
() { };
174
179
virtual
void
setFaulty
(
bool
mode) {
_faulty
= mode; };
180
181
/*** END: methods for unit-testing ***/
182
183
protected
:
187
BundleStorage
(
const
dtn::data::Length
&maxsize);
188
189
void
allocSpace
(
const
dtn::data::Length
&
size
)
throw
(StorageSizeExeededException);
190
void
freeSpace
(
const
dtn::data::Length
&
size
)
throw
();
191
void
clearSpace
() throw ();
192
193
void
eventBundleAdded
(const dtn::data::MetaBundle &b) throw ();
194
void
eventBundleRemoved
(const dtn::data::BundleID &
id
) throw ();
195
196
bool
_faulty
;
197
198
private:
199
ibrcommon::Mutex _sizelock;
200
const dtn::data::
Length
_maxsize;
201
dtn::data::
Length
_currentsize;
202
203
ibrcommon::Mutex _index_lock;
204
typedef std::set<dtn::storage::
BundleIndex
*> index_list;
205
index_list _indexes;
206
};
207
}
208
}
209
210
#endif
/* BUNDLESTORAGE_H_ */
daemon
src
storage
BundleStorage.h
Generated on Thu Mar 27 2014 09:26:20 for IBR-DTNSuite by
1.8.4