Apollo 10.0
自动驾驶开放平台
|
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles different types of websocket related events. 更多...
#include <websocket_handler.h>
Public 类型 | |
using | Json = nlohmann::json |
using | Connection = mg_connection |
using | MessageHandler = std::function< void(const Json &, Connection *)> |
using | ConnectionReadyHandler = std::function< void(Connection *)> |
Public 成员函数 | |
WebSocketHandler (const std::string &name) | |
bool | handleConnection (CivetServer *server, const Connection *conn) override |
Callback method for when the client intends to establish a websocket connection, before websocket handshake. | |
void | handleReadyState (CivetServer *server, Connection *conn) override |
Callback method for when websocket handshake is successfully completed, and connection is ready for data exchange. | |
bool | handleData (CivetServer *server, Connection *conn, int bits, char *data, size_t data_len) override |
Callback method for when a data frame has been received from the client. | |
bool | handleJsonData (Connection *conn, const std::string &data) |
bool | handleBinaryData (Connection *conn, const std::string &data) |
void | handleClose (CivetServer *server, const Connection *conn) override |
Callback method for when the connection is closed. | |
bool | BroadcastData (const std::string &data, bool skippable=false) |
Sends the provided data to all the connected clients. | |
bool | BroadcastBinaryData (const std::string &data, bool skippable=false) |
Sends the provided binary data to all the connected clients. | |
bool | SendData (Connection *conn, const std::string &data, bool skippable=false, int op_code=MG_WEBSOCKET_OPCODE_TEXT) |
Sends the provided data to a specific connected client. | |
bool | SendBinaryData (Connection *conn, const std::string &data, bool skippable=false) |
void | RegisterMessageHandler (std::string type, MessageHandler handler) |
Add a new message handler for a message type. | |
void | RegisterConnectionReadyHandler (ConnectionReadyHandler handler) |
Add a new handler for new connections. | |
The WebSocketHandler, built on top of CivetWebSocketHandler, is a websocket handler that handles different types of websocket related events.
在文件 websocket_handler.h 第 46 行定义.
using apollo::dreamview::WebSocketHandler::Connection = mg_connection |
在文件 websocket_handler.h 第 54 行定义.
using apollo::dreamview::WebSocketHandler::ConnectionReadyHandler = std::function<void(Connection *)> |
在文件 websocket_handler.h 第 56 行定义.
using apollo::dreamview::WebSocketHandler::Json = nlohmann::json |
在文件 websocket_handler.h 第 53 行定义.
using apollo::dreamview::WebSocketHandler::MessageHandler = std::function<void(const Json &, Connection *)> |
在文件 websocket_handler.h 第 55 行定义.
|
inlineexplicit |
在文件 websocket_handler.h 第 58 行定义.
bool apollo::dreamview::WebSocketHandler::BroadcastBinaryData | ( | const std::string & | data, |
bool | skippable = false |
||
) |
Sends the provided binary data to all the connected clients.
data | The message string to be sent. |
在文件 websocket_handler.cc 第 98 行定义.
bool apollo::dreamview::WebSocketHandler::BroadcastData | ( | const std::string & | data, |
bool | skippable = false |
||
) |
Sends the provided data to all the connected clients.
data | The message string to be sent. |
在文件 websocket_handler.cc 第 75 行定义.
bool apollo::dreamview::WebSocketHandler::handleBinaryData | ( | Connection * | conn, |
const std::string & | data | ||
) |
在文件 websocket_handler.cc 第 254 行定义.
|
override |
Callback method for when the connection is closed.
server | the calling server |
conn | the connection information |
在文件 websocket_handler.cc 第 41 行定义.
|
inlineoverride |
Callback method for when the client intends to establish a websocket connection, before websocket handshake.
server | the calling server |
conn | the connection information |
在文件 websocket_handler.h 第 68 行定义.
|
override |
Callback method for when a data frame has been received from the client.
In the websocket protocol, data is transmitted using a sequence of frames, and each frame received invokes this callback method. Since the type of opcode (text, binary, etc) is given in the first frame, this method stores the opcode in a thread_local variable named current_opcode_. And data from each frame is accumulated to data_ until the final fragment is detected. See websocket RFC at http://tools.ietf.org/html/rfc6455, section 5.4 for more protocol and fragmentation details.
server | the calling server |
conn | the connection information |
bits | first byte of the websocket frame, see websocket RFC at http://tools.ietf.org/html/rfc6455, section 5.2 |
data | payload, with mask (if any) already applied. |
data_len | length of data |
在文件 websocket_handler.cc 第 189 行定义.
bool apollo::dreamview::WebSocketHandler::handleJsonData | ( | Connection * | conn, |
const std::string & | data | ||
) |
在文件 websocket_handler.cc 第 229 行定义.
|
override |
Callback method for when websocket handshake is successfully completed, and connection is ready for data exchange.
server | the calling server |
conn | the connection information |
在文件 websocket_handler.cc 第 27 行定义.
|
inline |
Add a new handler for new connections.
handler | The function to handle the new connection in ReadyState. |
在文件 websocket_handler.h 第 154 行定义.
|
inline |
Add a new message handler for a message type.
type | The name/key to identify the message type. |
handler | The function to handle the received message. |
在文件 websocket_handler.h 第 146 行定义.
bool apollo::dreamview::WebSocketHandler::SendBinaryData | ( | Connection * | conn, |
const std::string & | data, | ||
bool | skippable = false |
||
) |
在文件 websocket_handler.cc 第 122 行定义.
bool apollo::dreamview::WebSocketHandler::SendData | ( | Connection * | conn, |
const std::string & | data, | ||
bool | skippable = false , |
||
int | op_code = MG_WEBSOCKET_OPCODE_TEXT |
||
) |
Sends the provided data to a specific connected client.
conn | The connection to send to. |
data | The message string to be sent. |
skippable | whether the data is allowed to be skipped if some other is being sent to this connection. |
在文件 websocket_handler.cc 第 127 行定义.