IBR-DTNSuite  0.10
BundleTransfer.cpp
Go to the documentation of this file.
1 /*
2  * BundleTransfer.cpp
3  *
4  * Copyright (C) 2013 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 "net/BundleTransfer.h"
24 #include "core/BundleEvent.h"
27 
28 namespace dtn
29 {
30  namespace net
31  {
33  : _slot(new Slot(neighbor, bundle))
34  {
35  }
36 
38  {
39  }
40 
41  BundleTransfer::Slot::Slot(const dtn::data::EID &n, const dtn::data::MetaBundle &b)
42  : neighbor(n), bundle(b), _completed(false), _aborted(false), _abort_reason(TransferAbortedEvent::REASON_UNDEFINED)
43  {
44  }
45 
46  BundleTransfer::Slot::~Slot()
47  {
48  if (_aborted) {
49  // fire TransferAbortedEvent
50  dtn::net::TransferAbortedEvent::raise(neighbor, bundle, _abort_reason);
51  } else if (_completed) {
54  } else {
56  }
57  }
58 
60  {
61  return _slot->neighbor;
62  }
63 
65  {
66  return _slot->bundle;
67  }
68 
69  void BundleTransfer::Slot::abort(const TransferAbortedEvent::AbortReason reason)
70  {
71  _abort_reason = reason;
72  _aborted = true;
73  }
74 
75  void BundleTransfer::Slot::complete()
76  {
77  _completed = true;
78  }
79 
81  {
82  _slot->abort(reason);
83  }
84 
86  {
87  _slot->complete();
88  }
89  } /* namespace net */
90 } /* namespace dtn */