UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37#ifndef UG_HOLE_PUNCH_CLIENT_HPP
38#define UG_HOLE_PUNCH_CLIENT_HPP
39
40#include <string>
41#include <vector>
42#include <queue>
43#include <functional>
44#include <memory>
45#include <asio.hpp>
46#include "message.hpp"
47#include "status_code.hpp"
48
49class Client : public std::enable_shared_from_this<Client>{
50public:
51 using CompletionCallback = std::function<void(Client&, CompletionStatus)>;
52
53 Client(asio::ip::tcp::socket&& socket);
54 Client(const Client&) = delete;
55 Client(Client&&) = delete;
56
57 Client& operator=(const Client&) = delete;
58 Client& operator=(Client&&) = delete;
59
60 void readDescription(CompletionCallback onComplete);
61 std::string getClientName() { return clientName; }
62 std::string getRoomName() { return roomName; }
63 std::string getSdpDesc() { return sdpDesc; }
64
65 void sendMsg(std::string_view msg);
66
67 void readCandidate(CompletionCallback onComplete);
68 const std::vector<std::string>& getCandidates() { return candidates; }
69
70 bool isSendCallbackPending() const;
71
72private:
73 void readNameComplete(asio::ip::tcp::socket& socket,
75
76 void readRoomComplete(asio::ip::tcp::socket& socket,
78
81
84
86
87 std::string clientName;
88 std::string roomName;
89 std::string sdpDesc;
90 std::vector<std::string> candidates;
91
92 std::queue<std::string> sendQueue;
93
96 asio::ip::tcp::socket socket;
97};
98
99
100#endif
asio::ip::tcp::socket socket
Definition client.hpp:96
void sendMsg(std::string_view msg)
Definition client.cpp:123
void readDescription(CompletionCallback onComplete)
Definition client.cpp:42
std::queue< std::string > sendQueue
Definition client.hpp:92
void readNameComplete(asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:49
std::string getRoomName()
Definition client.hpp:62
Client(asio::ip::tcp::socket &&socket)
Definition client.cpp:40
Message inMsg
Definition client.hpp:94
Client(Client &&)=delete
const std::vector< std::string > & getCandidates()
Definition client.hpp:68
Message outMsg
Definition client.hpp:95
Client(const Client &)=delete
void readCandidateComplete(CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:100
Client & operator=(const Client &)=delete
std::vector< std::string > candidates
Definition client.hpp:90
std::string roomName
Definition client.hpp:88
void readRoomComplete(asio::ip::tcp::socket &socket, CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:65
void readDescComplete(CompletionCallback onComplete, CompletionStatus status)
Definition client.cpp:80
std::function< void(Client &, CompletionStatus)> CompletionCallback
Definition client.hpp:51
std::string sdpDesc
Definition client.hpp:89
void readCandidate(CompletionCallback onComplete)
Definition client.cpp:93
bool isSendCallbackPending() const
Definition client.cpp:118
void onMsgSent(CompletionStatus status)
Definition client.cpp:134
std::string getSdpDesc()
Definition client.hpp:63
std::string clientName
Definition client.hpp:87
std::string getClientName()
Definition client.hpp:61
Client & operator=(Client &&)=delete
CompletionStatus