NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 "websocket-face.hpp"
31 
32 namespace nfd {
33 
37 class WebSocketChannel : public Channel
38 {
39 public:
49  explicit
50  WebSocketChannel(const websocket::Endpoint& localEndpoint);
51 
59  void
60  listen(const FaceCreatedCallback& onFaceCreated);
61 
65  size_t
66  size() const;
67 
68  bool
69  isListening() const;
70 
72  void
73  setPingInterval(time::milliseconds interval);
74 
75  void
76  setPongTimeout(time::milliseconds timeout);
77 
78 private:
79  void
80  sendPing(websocketpp::connection_hdl hdl);
81 
82  void
83  handlePong(websocketpp::connection_hdl hdl, std::string msg);
84 
85  void
86  handlePongTimeout(websocketpp::connection_hdl hdl, std::string msg);
87 
88  void
89  handleMessage(websocketpp::connection_hdl hdl, websocket::Server::message_ptr msg);
90 
91  void
92  handleOpen(websocketpp::connection_hdl hdl);
93 
94  void
95  handleClose(websocketpp::connection_hdl hdl);
96 
97 private:
98  websocket::Endpoint m_localEndpoint;
99  websocket::Server m_server;
100 
101  std::map<websocketpp::connection_hdl, shared_ptr<WebSocketFace>,
102  std::owner_less<websocketpp::connection_hdl>> m_channelFaces;
103 
107  FaceCreatedCallback m_onFaceCreatedCallback;
108 
112  bool m_isListening;
113 
114  time::milliseconds m_pingInterval;
115 };
116 
117 inline bool
119 {
120  return m_isListening;
121 }
122 
123 } // namespace nfd
124 
125 #endif // NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
websocketpp::server< websocketpp::config::asio > Server
WebSocketChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket channel for the local endpoint.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
size_t size() const
Get number of faces in the channel.
void listen(const FaceCreatedCallback &onFaceCreated)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
Class implementing WebSocket-based channel to create faces.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
boost::asio::ip::tcp::endpoint Endpoint
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
Definition: channel.hpp:41