NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
websocket-channel.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "websocketpp.hpp"
31 
32 namespace nfd {
33 
34 namespace websocket {
35 typedef boost::asio::ip::tcp::endpoint Endpoint;
36 } // namespace websocket
37 
41 class WebSocketChannel : public Channel
42 {
43 public:
51  explicit
52  WebSocketChannel(const websocket::Endpoint& localEndpoint);
53 
60  void
61  listen(const FaceCreatedCallback& onFaceCreated);
62 
66  size_t
67  size() const;
68 
69  bool
70  isListening() const;
71 
75  void
76  setPingInterval(time::milliseconds interval);
77 
80  void
81  setPongTimeout(time::milliseconds timeout);
82 
83  void
84  handlePong(websocketpp::connection_hdl hdl);
85 
86  void
87  handlePongTimeout(websocketpp::connection_hdl hdl);
88 
89 private:
90  void
91  handleMessage(websocketpp::connection_hdl hdl,
92  websocket::Server::message_ptr msg);
93 
94  void
95  handleOpen(websocketpp::connection_hdl hdl);
96 
97  void
98  handleClose(websocketpp::connection_hdl hdl);
99 
100 private:
101  websocket::Endpoint m_localEndpoint;
102  websocket::Server m_server;
103 
104  std::map<websocketpp::connection_hdl, shared_ptr<Face>,
105  std::owner_less<websocketpp::connection_hdl>> m_channelFaces;
106 
107  FaceCreatedCallback m_onFaceCreatedCallback;
108  time::milliseconds m_pingInterval;
109 };
110 
111 inline bool
113 {
114  return m_server.is_listening();
115 }
116 
117 } // namespace nfd
118 
119 #endif // NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
websocketpp::server< websocketpp::config::asio > Server
Definition: websocketpp.hpp:46
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Class implementing WebSocket-based channel to create faces.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
Definition: channel.hpp:38
boost::asio::ip::tcp::endpoint Endpoint