Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
pending_interest.h
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <hicn/transport/config.h>
19 #include <hicn/transport/core/asio_wrapper.h>
20 #include <hicn/transport/core/content_object.h>
21 #include <hicn/transport/core/interest.h>
22 #include <hicn/transport/core/name.h>
23 #include <hicn/transport/interfaces/portal.h>
24 #include <hicn/transport/portability/portability.h>
25 #include <utils/deadline_timer.h>
26 
27 namespace transport {
28 
29 namespace core {
30 
31 class HicnForwarderInterface;
32 class VPPForwarderInterface;
33 class RawSocketInterface;
34 
35 class Portal;
36 
37 using OnContentObjectCallback = interface::Portal::OnContentObjectCallback;
38 using OnInterestTimeoutCallback = interface::Portal::OnInterestTimeoutCallback;
39 
41  friend class Portal;
42 
43  public:
44  using Ptr = utils::ObjectPool<PendingInterest>::Ptr;
45  // PendingInterest()
46  // : interest_(nullptr, nullptr),
47  // timer_(),
48  // on_content_object_callback_(),
49  // on_interest_timeout_callback_() {}
50 
51  PendingInterest(Interest::Ptr &&interest,
52  std::unique_ptr<asio::steady_timer> &&timer)
53  : interest_(std::move(interest)),
54  timer_(std::move(timer)),
55  on_content_object_callback_(),
56  on_interest_timeout_callback_() {}
57 
58  PendingInterest(Interest::Ptr &&interest,
59  OnContentObjectCallback &&on_content_object,
60  OnInterestTimeoutCallback &&on_interest_timeout,
61  std::unique_ptr<asio::steady_timer> &&timer)
62  : interest_(std::move(interest)),
63  timer_(std::move(timer)),
64  on_content_object_callback_(std::move(on_content_object)),
65  on_interest_timeout_callback_(std::move(on_interest_timeout)) {}
66 
67  ~PendingInterest() = default;
68 
69  template <typename Handler>
70  TRANSPORT_ALWAYS_INLINE void startCountdown(Handler &&cb) {
71  timer_->expires_from_now(
72  std::chrono::milliseconds(interest_->getLifetime()));
73  timer_->async_wait(std::forward<Handler &&>(cb));
74  }
75 
76  TRANSPORT_ALWAYS_INLINE void cancelTimer() { timer_->cancel(); }
77 
78  TRANSPORT_ALWAYS_INLINE Interest::Ptr &&getInterest() {
79  return std::move(interest_);
80  }
81 
82  TRANSPORT_ALWAYS_INLINE void setInterest(Interest::Ptr &interest) {
83  interest_ = interest;
84  }
85 
86  TRANSPORT_ALWAYS_INLINE const OnContentObjectCallback &getOnDataCallback()
87  const {
88  return on_content_object_callback_;
89  }
90 
91  TRANSPORT_ALWAYS_INLINE void setOnContentObjectCallback(
92  OnContentObjectCallback &&on_content_object) {
93  PendingInterest::on_content_object_callback_ = on_content_object;
94  }
95 
96  TRANSPORT_ALWAYS_INLINE const OnInterestTimeoutCallback &
97  getOnTimeoutCallback() const {
98  return on_interest_timeout_callback_;
99  }
100 
101  TRANSPORT_ALWAYS_INLINE void setOnTimeoutCallback(
102  OnInterestTimeoutCallback &&on_interest_timeout) {
103  PendingInterest::on_interest_timeout_callback_ = on_interest_timeout;
104  }
105 
106  private:
107  Interest::Ptr interest_;
108  std::unique_ptr<asio::steady_timer> timer_;
109  OnContentObjectCallback on_content_object_callback_;
110  OnInterestTimeoutCallback on_interest_timeout_callback_;
111 };
112 
113 } // end namespace core
114 
115 } // end namespace transport
transport::core::PendingInterest
Definition: pending_interest.h:40
transport
Definition: forwarder_config.h:32
transport::core::Portal
Definition: portal.h:213