Project
Loading...
Searching...
No Matches
DPLWebSocket.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_DPLWEBSOCKET_H_
12#define O2_FRAMEWORK_DPLWEBSOCKET_H_
13
15#include <uv.h>
16#include "HTTPParser.h"
17#include <memory>
18#include <string>
19#include <map>
20#include <functional>
21#include <atomic>
22
23class uv_stream_s;
24
25namespace o2::framework
26{
27
28struct DeviceSpec;
29struct DriverServerContext;
30struct DriverClientContext;
31
32struct WSError {
33 int code;
34 std::string message;
35};
36
37struct WSDPLHandler : public HTTPParser {
44 WSDPLHandler(uv_stream_t* stream, DriverServerContext* context);
45 virtual ~WSDPLHandler() = default;
46 void method(std::string_view const& s) override;
47 void target(std::string_view const& s) override;
48 void header(std::string_view const& k, std::string_view const& v) override;
49 void endHeaders() override;
51 void body(char* data, size_t s) override;
53 void write(char const*, size_t);
54
56 void write(std::vector<uv_buf_t>& outputs);
57
59 void error(int code, char const* message);
60
61 std::unique_ptr<WebSocketHandler> mHandler;
62 bool mHandshaken = false;
63 uv_stream_t* mStream = nullptr;
64 std::map<std::string, std::string> mHeaders;
66};
67
68struct WSDPLClient : public HTTPParser {
75 uv_stream_t* stream,
76 std::function<void()> handshake,
77 std::unique_ptr<WebSocketHandler> handler);
78
79 void replyVersion(std::string_view const& s) override;
80 void replyCode(std::string_view const& s) override;
81 void header(std::string_view const& k, std::string_view const& v) override;
82 void endHeaders() override;
84 void body(char* data, size_t s) override;
86 void write(char const*, size_t);
87
89 void write(std::vector<uv_buf_t>& outputs);
90
92 void dumpHeaders();
93 void sendHandshake();
94 bool isHandshaken() { return mHandshaken; }
95
96 std::string mNonce;
97 std::atomic<bool> mHandshaken = false;
98 std::function<void()> mHandshake;
99 std::unique_ptr<DriverClientContext> mContext;
100 std::unique_ptr<WebSocketHandler> mHandler;
101 uv_stream_t* mStream = nullptr;
102 std::map<std::string, std::string> mHeaders;
103};
104} // namespace o2::framework
105
106#endif // O2_FRAMEWORK_DPL_WEBSOCKET_H_
const GLdouble * v
Definition glcorearb.h:832
GLenum target
Definition glcorearb.h:1641
GLboolean * data
Definition glcorearb.h:298
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLuint GLuint stream
Definition glcorearb.h:1806
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::unique_ptr< WebSocketHandler > mHandler
void replyVersion(std::string_view const &s) override
std::function< void()> mHandshake
std::atomic< bool > mHandshaken
void connect(ServiceRegistryRef ref, uv_stream_t *stream, std::function< void()> handshake, std::unique_ptr< WebSocketHandler > handler)
std::unique_ptr< DriverClientContext > mContext
void body(char *data, size_t s) override
Actual handling of WS frames happens inside here.
void replyCode(std::string_view const &s) override
void dumpHeaders()
Dump headers.
void write(char const *, size_t)
Helper to write a message to the server.
void header(std::string_view const &k, std::string_view const &v) override
std::map< std::string, std::string > mHeaders
void method(std::string_view const &s) override
void body(char *data, size_t s) override
Actual handling of WS frames happens inside here.
void header(std::string_view const &k, std::string_view const &v) override
virtual ~WSDPLHandler()=default
DriverServerContext * mServerContext
std::unique_ptr< WebSocketHandler > mHandler
void write(char const *, size_t)
Helper to write a message to the associated client.
std::map< std::string, std::string > mHeaders