Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
portal.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/core/asio_wrapper.h>
19 #include <hicn/transport/core/content_object.h>
20 #include <hicn/transport/core/interest.h>
21 #include <hicn/transport/core/prefix.h>
22 
23 #include <functional>
24 
25 #define UNSET_CALLBACK 0
26 
27 namespace transport {
28 
29 namespace interface {
30 
31 template <typename PrefixType>
33  static_assert(std::is_same<core::Prefix, PrefixType>::value,
34  "Prefix must be a Prefix type.");
35 
36  const uint32_t standard_cs_reserved = 5000;
37 
38  public:
39  template <typename T>
40  BasicBindConfig(T &&prefix)
41  : prefix_(std::forward<T &&>(prefix)),
42  content_store_reserved_(standard_cs_reserved) {}
43 
44  template <typename T>
45  BasicBindConfig(T &&prefix, uint32_t cs_reserved)
46  : prefix_(std::forward<T &&>(prefix)),
47  content_store_reserved_(cs_reserved) {}
48 
49  TRANSPORT_ALWAYS_INLINE const PrefixType &prefix() const { return prefix_; }
50 
51  TRANSPORT_ALWAYS_INLINE uint32_t csReserved() const {
52  return content_store_reserved_;
53  }
54 
55  private:
56  PrefixType prefix_;
57  uint32_t content_store_reserved_;
58 };
59 
61 
62 class Portal {
63  public:
69  public:
70  virtual void onContentObject(core::Interest &i, core::ContentObject &c) = 0;
71  virtual void onTimeout(core::Interest::Ptr &i, const core::Name &n) = 0;
72  virtual void onError(std::error_code ec) = 0;
73  };
74 
80  public:
81  virtual void onInterest(core::Interest &i) = 0;
82  virtual void onError(std::error_code ec) = 0;
83  };
84 
85  using OnContentObjectCallback =
86  std::function<void(core::Interest &, core::ContentObject &)>;
87  using OnInterestTimeoutCallback =
88  std::function<void(core::Interest::Ptr &, const core::Name &)>;
89 
90  Portal();
91 
92  Portal(asio::io_service &io_service);
93 
99  void setConsumerCallback(ConsumerCallback *consumer_callback);
100 
106  void setProducerCallback(ProducerCallback *producer_callback);
107 
114  void connect(bool is_consumer = true);
115 
119  ~Portal();
120 
126  bool interestIsPending(const core::Name &name);
127 
142  void sendInterest(
143  core::Interest::Ptr &&interest,
144  OnContentObjectCallback &&on_content_object_callback = UNSET_CALLBACK,
145  OnInterestTimeoutCallback &&on_interest_timeout_callback =
146  UNSET_CALLBACK);
147 
154  void bind(const BindConfig &config);
155 
156  void runEventsLoop();
157 
161  void runOneEvent();
162 
169  void sendContentObject(core::ContentObject &content_object);
176  void stopEventsLoop();
177 
181  void killConnection();
182 
186  void clear();
187 
191  asio::io_service &getIoService();
192 
196  void registerRoute(core::Prefix &prefix);
197 
198  private:
199  void *implementation_;
200 };
201 
202 } // namespace interface
203 } // namespace transport
transport::interface::Portal::bind
void bind(const BindConfig &config)
transport::interface::Portal::getIoService
asio::io_service & getIoService()
transport::interface::Portal::interestIsPending
bool interestIsPending(const core::Name &name)
transport::core::Name
Definition: name.h:45
transport::interface::Portal::sendInterest
void sendInterest(core::Interest::Ptr &&interest, OnContentObjectCallback &&on_content_object_callback=UNSET_CALLBACK, OnInterestTimeoutCallback &&on_interest_timeout_callback=UNSET_CALLBACK)
transport::interface::Portal::connect
void connect(bool is_consumer=true)
transport::interface::Portal::registerRoute
void registerRoute(core::Prefix &prefix)
transport::core::ContentObject
Definition: content_object.h:29
transport::interface::BasicBindConfig
Definition: portal.h:32
transport::interface::Portal::setProducerCallback
void setProducerCallback(ProducerCallback *producer_callback)
transport::interface::Portal::sendContentObject
void sendContentObject(core::ContentObject &content_object)
transport::interface::Portal::setConsumerCallback
void setConsumerCallback(ConsumerCallback *consumer_callback)
transport::interface::Portal::stopEventsLoop
void stopEventsLoop()
transport::core::Interest
Definition: interest.h:30
transport::interface::Portal::runOneEvent
void runOneEvent()
transport::interface::Portal
Definition: portal.h:62
transport
Definition: forwarder_config.h:32
transport::interface::Portal::ProducerCallback
Definition: portal.h:79
transport::interface::Portal::clear
void clear()
transport::interface::Portal::~Portal
~Portal()
transport::core::Prefix
Definition: prefix.h:24
transport::interface::Portal::ConsumerCallback
Definition: portal.h:68
transport::interface::Portal::killConnection
void killConnection()