-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.h
45 lines (34 loc) · 1.17 KB
/
connection.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
#pragma once
#if !defined(CONNECTION_H)
#define CONNECTION_H
#include <memory>
#include <optional>
#include <variant>
#include "util.h"
namespace trainlist8 {
namespace soap {
struct SimulationState;
struct TrainData;
}
class Connection final {
public:
// The type of a received message.
using Message = std::variant<const soap::SimulationState *, const soap::TrainData *>;
explicit Connection();
winrt::Windows::Foundation::IAsyncAction connect(winrt::hstring hostname);
winrt::Windows::Foundation::IAsyncAction receiveMessage();
std::optional<Message> lastMessage() const;
private:
// The Windows Web Services heap used for memory allocation related to the connection.
std::unique_ptr<WS_HEAP, ::trainlist8::util::HeapDeleter> heap;
// The duplex session TCP channel connected to Run 8.
std::unique_ptr<WS_CHANNEL, ::trainlist8::util::ChannelDeleter> channel;
// A message object used to decode incoming messages.
std::unique_ptr<WS_MESSAGE, ::trainlist8::util::MessageDeleter> message;
// An adapter used to run asynchronous operations on the channel.
util::AsyncWSAdapter adapter;
// The most recently received message.
std::optional<Message> lastMessage_;
};
}
#endif