IBR-DTN  1.0.0
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"
26 #include <ibrcommon/thread/MutexLock.h>
27 
28 namespace dtn
29 {
30  namespace net
31  {
33  : _slot(new Slot(neighbor, bundle, p))
34  {
35  }
36 
38  {
39  }
40 
41  BundleTransfer::Slot::Slot(const dtn::data::EID &n, const dtn::data::MetaBundle &b, dtn::core::Node::Protocol p)
42  : neighbor(n), bundle(b), protocol(p), _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 {
55  dtn::routing::RequeueBundleEvent::raise(neighbor, bundle, protocol);
56  }
57  }
58 
60  {
61  return _slot->neighbor;
62  }
63 
65  {
66  return _slot->bundle;
67  }
68 
70  return _slot->protocol;
71  }
72 
73  void BundleTransfer::Slot::abort(const TransferAbortedEvent::AbortReason reason)
74  {
75  _abort_reason = reason;
76  _aborted = true;
77  }
78 
79  void BundleTransfer::Slot::complete()
80  {
81  _completed = true;
82  }
83 
85  {
86  _slot->abort(reason);
87  }
88 
90  {
91  _slot->complete();
92  }
93  } /* namespace net */
94 } /* namespace dtn */
static void raise(const dtn::data::EID peer, const dtn::data::BundleID &id, dtn::core::Node::Protocol p)
static void raise(const dtn::data::EID &peer, const dtn::data::BundleID &id, const AbortReason reason=REASON_UNDEFINED)
static void raise(const dtn::data::EID peer, const dtn::data::MetaBundle &bundle)
const dtn::data::EID & getNeighbor() const
dtn::core::Node::Protocol getProtocol() const
BundleTransfer(const dtn::data::EID &neighbor, const dtn::data::MetaBundle &bundle, dtn::core::Node::Protocol p)
void abort(const TransferAbortedEvent::AbortReason reason)
const dtn::data::MetaBundle & getBundle() const
static void raise(const dtn::data::MetaBundle &bundle, EventBundleAction action, dtn::data::StatusReportBlock::REASON_CODE reason=dtn::data::StatusReportBlock::NO_ADDITIONAL_INFORMATION)
Definition: BundleEvent.cpp:78