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;
65 std::string mTarget;
67};
68
69struct WSDPLClient : public HTTPParser {
76 uv_stream_t* stream,
77 std::function<void()> handshake,
78 std::unique_ptr<WebSocketHandler> handler);
79
80 void replyVersion(std::string_view const& s) override;
81 void replyCode(std::string_view const& s) override;
82 void header(std::string_view const& k, std::string_view const& v) override;
83 void endHeaders() override;
85 void body(char* data, size_t s) override;
87 void write(char const*, size_t);
88
90 void write(std::vector<uv_buf_t>& outputs);
91
93 void dumpHeaders();
94 void sendHandshake();
95 bool isHandshaken() { return mHandshaken; }
96
97 std::string mNonce;
98 std::atomic<bool> mHandshaken = false;
99 std::function<void()> mHandshake;
100 std::unique_ptr<DriverClientContext> mContext;
101 std::unique_ptr<WebSocketHandler> mHandler;
102 uv_stream_t* mStream = nullptr;
103 std::map<std::string, std::string> mHeaders;
104};
105} // namespace o2::framework
106
107#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 Cartesian.h:288
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