-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathhub_connection_builder.cpp
120 lines (96 loc) · 3.62 KB
/
hub_connection_builder.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#include "stdafx.h"
#include "signalrclient/hub_connection_builder.h"
#include <stdexcept>
#include "json_hub_protocol.h"
#include "messagepack_hub_protocol.h"
namespace signalr
{
hub_connection_builder hub_connection_builder::create(const std::string& url)
{
return hub_connection_builder(url);
}
hub_connection_builder::hub_connection_builder(const std::string& url)
: m_url(url), m_logger(nullptr), m_log_level(trace_level::info)
{
}
hub_connection_builder::hub_connection_builder(const hub_connection_builder& rhs)
: m_url(rhs.m_url), m_logger(rhs.m_logger), m_log_level(rhs.m_log_level)
{
}
hub_connection_builder::hub_connection_builder(hub_connection_builder&& rhs) noexcept
: m_url(std::move(rhs.m_url)), m_logger(std::move(rhs.m_logger)), m_log_level(rhs.m_log_level)
{
}
hub_connection_builder& hub_connection_builder::operator=(hub_connection_builder&& rhs) noexcept
{
m_url = std::move(rhs.m_url);
m_logger = std::move(rhs.m_logger);
m_log_level = rhs.m_log_level;
return *this;
}
hub_connection_builder& hub_connection_builder::operator=(const hub_connection_builder& rhs)
{
m_url = rhs.m_url;
m_logger = rhs.m_logger;
m_log_level = rhs.m_log_level;
return *this;
}
hub_connection_builder::~hub_connection_builder()
{}
hub_connection_builder& hub_connection_builder::with_logging(std::shared_ptr<log_writer> logger, trace_level logLevel)
{
m_logger = logger;
m_log_level = logLevel;
return *this;
}
hub_connection_builder& hub_connection_builder::with_websocket_factory(std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> factory)
{
m_websocket_factory = factory;
return *this;
}
hub_connection_builder& hub_connection_builder::with_http_client_factory(std::function<std::shared_ptr<http_client>(const signalr_client_config&)> http_client_factory)
{
m_http_client_factory = http_client_factory;
return *this;
}
hub_connection_builder& hub_connection_builder::skip_negotiation(const bool skip)
{
m_skip_negotiation = skip;
return *this;
}
#ifdef USE_MSGPACK
hub_connection_builder& hub_connection_builder::with_messagepack_hub_protocol()
{
m_use_messagepack = true;
return *this;
}
#endif
std::shared_ptr<hub_connection> hub_connection_builder::build()
{
#ifndef USE_CPPRESTSDK
if (m_http_client_factory == nullptr)
{
throw std::runtime_error("An http client must be provided using 'with_http_client_factory' on the builder.");
}
if (m_websocket_factory == nullptr)
{
throw std::runtime_error("A websocket factory must be provided using 'with_websocket_factory' on the builder.");
}
#endif
std::unique_ptr<hub_protocol> hub_protocol;
#ifdef USE_MSGPACK
if (m_use_messagepack)
{
hub_protocol = std::unique_ptr<messagepack_hub_protocol>(new messagepack_hub_protocol());
}
else
#endif
{
hub_protocol = std::unique_ptr<json_hub_protocol>(new json_hub_protocol());
}
return std::shared_ptr<hub_connection>(new hub_connection(m_url, std::move(hub_protocol), m_log_level, m_logger, m_http_client_factory, m_websocket_factory, m_skip_negotiation));
}
}