-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.h
93 lines (72 loc) · 2.26 KB
/
Client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Copyright 2018 - 2025 (C). Alex Robenko. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstdint>
#include <string>
#include <iterator>
#include <vector>
#include <boost/array.hpp>
#include "common/boost_wrap.h"
#include "cc_demo1/Message.h"
#include "cc_demo1/input/ClientInputMessages.h"
#include "cc_demo1/frame/Frame.h"
namespace cc_demo1
{
namespace client
{
class Client
{
public:
Client(common::boost_wrap::io& io, const std::string& server, std::uint16_t port);
bool start();
using InputMsg =
cc_demo1::Message<
comms::option::ReadIterator<const std::uint8_t*>,
comms::option::Handler<Client>
>;
CC_DEMO1_ALIASES_FOR_CLIENT_INPUT_MESSAGES_DEFAULT_OPTIONS(In,Msg,InputMsg);
void handle(InAckMsg& msg);
void handle(InputMsg&);
private:
using Socket = boost::asio::ip::tcp::socket;
using OutputMsg =
cc_demo1::Message<
comms::option::WriteIterator<std::back_insert_iterator<std::vector<std::uint8_t> > >,
comms::option::LengthInfoInterface,
comms::option::IdInfoInterface,
comms::option::NameInterface
>;
using AllInputMessages = cc_demo1::input::ClientInputMessages<InputMsg>;
using Frame = cc_demo1::frame::Frame<InputMsg, AllInputMessages>;
void readDataFromServer();
void readDataFromStdin();
void sendSimpleInts();
void sendScaledInts();
void sendFloats();
void sendEnums();
void sendSets();
void sendBitfields();
void sendStrings();
void sendDatas();
void sendLists();
void sendOptionals();
void sendVariants();
void sendMessage(const OutputMsg& msg);
void waitForAck();
void processInput();
common::boost_wrap::io& m_io;
Socket m_socket;
boost::asio::deadline_timer m_timer;
std::string m_server;
std::uint16_t m_port = 0U;
Frame m_frame;
cc_demo1::MsgId m_sentId = cc_demo1::MsgId_Ack;
boost::array<std::uint8_t, 32> m_readBuf;
std::vector<std::uint8_t> m_inputBuf;
};
} // namespace client
} // namespace cc_demo1