Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
socket_consumer.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/auth/verifier.h>
19 #include <hicn/transport/config.h>
20 #include <hicn/transport/core/asio_wrapper.h>
21 #include <hicn/transport/core/name.h>
22 #include <hicn/transport/core/prefix.h>
23 #include <hicn/transport/interfaces/callbacks.h>
24 #include <hicn/transport/interfaces/socket_options_default_values.h>
25 #include <hicn/transport/interfaces/socket_options_keys.h>
26 
27 #define CONSUMER_FINISHED 0
28 #define CONSUMER_BUSY 1
29 #define CONSUMER_RUNNING 2
30 
31 namespace transport {
32 
33 namespace implementation {
34 class ConsumerSocket;
35 }
36 
37 namespace interface {
38 
39 using namespace core;
40 
49  public:
60  class ReadCallback {
61  public:
62  virtual ~ReadCallback() = default;
63 
76  virtual bool isBufferMovable() noexcept { return true; }
77 
90  virtual void getReadBuffer(uint8_t **application_buffer,
91  size_t *max_length) = 0;
92 
101  virtual void readDataAvailable(size_t length) noexcept = 0;
102 
109  virtual size_t maxBufferSize() const { return 64 * 1024; }
110 
118  virtual void readBufferAvailable(
119  std::unique_ptr<utils::MemBuf> &&buffer) noexcept {}
120 
127  virtual void readError(const std::error_code ec) noexcept = 0;
128 
135  virtual void readSuccess(std::size_t total_size) noexcept = 0;
136  };
137 
150  explicit ConsumerSocket(int protocol);
151 
169  explicit ConsumerSocket(int protocol, asio::io_service &io_service);
170 
174  ~ConsumerSocket();
175 
179  void connect();
180 
184  bool isRunning();
185 
203  int consume(const Name &name);
204  int asyncConsume(const Name &name);
205 
210  void stop();
211 
215  void resume();
216 
223  asio::io_service &getIoService();
224 
225  int setSocketOption(int socket_option_key, ReadCallback *socket_option_value);
226 
227  int getSocketOption(int socket_option_key,
228  ReadCallback **socket_option_value);
229 
230  int setSocketOption(int socket_option_key, double socket_option_value);
231 
232  int setSocketOption(int socket_option_key, uint32_t socket_option_value);
233 
234  int setSocketOption(int socket_option_key,
235  std::nullptr_t socket_option_value);
236 
237  int setSocketOption(int socket_option_key, bool socket_option_value);
238 
239  int setSocketOption(int socket_option_key,
240  ConsumerContentObjectCallback socket_option_value);
241 
242  int setSocketOption(int socket_option_key,
243  ConsumerInterestCallback socket_option_value);
244 
245  int setSocketOption(int socket_option_key,
246  interface::IcnObserver *socket_option_value);
247 
248  int setSocketOption(
249  int socket_option_key,
250  const std::shared_ptr<auth::Verifier> &socket_option_value);
251 
252  int setSocketOption(int socket_option_key,
253  const std::string &socket_option_value);
254 
255  int setSocketOption(int socket_option_key,
256  ConsumerTimerCallback socket_option_value);
257 
258  int getSocketOption(int socket_option_key, double &socket_option_value);
259 
260  int getSocketOption(int socket_option_key, uint32_t &socket_option_value);
261 
262  int getSocketOption(int socket_option_key, bool &socket_option_value);
263 
264  int getSocketOption(int socket_option_key, Name **socket_option_value);
265 
266  int getSocketOption(int socket_option_key,
267  ConsumerContentObjectCallback **socket_option_value);
268 
269  int getSocketOption(int socket_option_key,
270  ConsumerInterestCallback **socket_option_value);
271 
272  int getSocketOption(int socket_option_key, IcnObserver **socket_option_value);
273 
274  int getSocketOption(int socket_option_key,
275  std::shared_ptr<auth::Verifier> &socket_option_value);
276 
277  int getSocketOption(int socket_option_key, std::string &socket_option_value);
278 
279  int getSocketOption(int socket_option_key,
280  ConsumerTimerCallback **socket_option_value);
281 
282  int getSocketOption(int socket_option_key,
283  interface::TransportStatistics **socket_option_value);
284 
285  protected:
286  ConsumerSocket();
287  std::unique_ptr<implementation::ConsumerSocket> socket_;
288 };
289 
290 } // namespace interface
291 
292 } // end namespace transport
transport::interface::ConsumerSocket::ReadCallback::isBufferMovable
virtual bool isBufferMovable() noexcept
Definition: socket_consumer.h:76
transport::interface::ConsumerSocket
Main interface for consumer applications.
Definition: socket_consumer.h:48
transport::interface::ConsumerSocket::ReadCallback::readBufferAvailable
virtual void readBufferAvailable(std::unique_ptr< utils::MemBuf > &&buffer) noexcept
Definition: socket_consumer.h:118
transport::interface::TransportStatistics
Definition: statistics.h:36
transport::core::Name
Definition: name.h:45
transport::interface::ConsumerSocket::ReadCallback
Definition: socket_consumer.h:60
transport::interface::ConsumerSocket::ReadCallback::maxBufferSize
virtual size_t maxBufferSize() const
Definition: socket_consumer.h:109
transport
Definition: forwarder_config.h:32
transport::interface::IcnObserver
Definition: statistics.h:26