Skip to content

Commit c603641

Browse files
Build without CPPRestSDK (#24)
1 parent da8059a commit c603641

26 files changed

+197
-136
lines changed

.azure/default-build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ parameters:
77
timeoutInMinutes: 60
88
cMakeRunArgs: ''
99
configuration: 'Release'
10+
useCppRestSDK: true
1011
gtestFlags: '--gtest_output=xml:$(Build.ArtifactStagingDirectory)/testOut/'
1112

1213
jobs:
1314
- template: /eng/common/templates/job/job.yml
1415
parameters:
1516
name: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
16-
displayName: ${{ coalesce(parameters.jobDisplayName, parameters.agentOs) }}
17+
displayName: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
1718
dependsOn: ${{ parameters.dependsOn }}
1819
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
1920
${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.agentOs, 'Windows')) }}:
@@ -38,12 +39,13 @@ jobs:
3839
path: ./submodules/vcpkg/installed
3940
cacheHitVar: CACHE_RESTORED
4041
displayName: Cache vcpkg packages
42+
condition: eq( '${{ parameters.useCppRestSDK }}', 'true' )
4143

4244
- ${{ parameters.beforeBuild }}
4345

4446
- task: CMake@1
4547
inputs:
46-
cmakeArgs: .. ${{ parameters.cMakeRunArgs }} -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DUSE_CPPRESTSDK=true
48+
cmakeArgs: .. ${{ parameters.cMakeRunArgs }} -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DUSE_CPPRESTSDK=${{ parameters.useCppRestSDK }}
4749
workingDirectory: 'build.${{ parameters.configuration }}'
4850
displayName: Create build files
4951
- task: CMake@1

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ include_directories (include)
3232
# We need this for testing, but we might just add all the files to the test project manually
3333
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
3434

35-
if(NOT WIN32)
36-
if(APPLE)
37-
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
38-
list(REVERSE OPENSSL_ROOT_DIR)
35+
if(USE_CPPRESTSDK)
36+
if(NOT WIN32)
37+
if(APPLE)
38+
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
39+
list(REVERSE OPENSSL_ROOT_DIR)
40+
endif()
41+
42+
find_package(OpenSSL 1.0.0 REQUIRED)
43+
find_package(Boost REQUIRED COMPONENTS system thread chrono)
3944
endif()
40-
41-
find_package(OpenSSL 1.0.0 REQUIRED)
42-
find_package(Boost REQUIRED COMPONENTS system thread chrono)
4345
endif()
4446

4547
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

azure-pipelines.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ stages:
3030
- template: .azure/default-build.yml
3131
parameters:
3232
agentOs: Windows
33-
jobName: Windows_Build_Test
33+
jobName: Windows_Build_Test_With_CppRestSDK
34+
useCppRestSDK: true
3435
cMakeRunArgs: '-A x64'
3536
beforeBuild:
3637
# check if vcpkg exists on the machine before trying to build it
@@ -57,12 +58,15 @@ stages:
5758
- template: .azure/default-build.yml
5859
parameters:
5960
agentOs: macOs
60-
jobName: Mac_Build_Test
61+
jobName: Mac_Build_Test_With_CppRestSDK
62+
useCppRestSDK: true
6163
beforeBuild:
6264
# XCode 11 doesn't play nicely with gcc, workaround by using XCode 10. We can try updating to a newer XCode in the future
6365
# Once the problem has been resolved
6466
- script: sudo xcode-select --switch /Applications/Xcode_10.3.app
67+
displayName: xcode-select
6568
- script: brew install gcc
69+
displayName: Install gcc
6670
- bash: "./submodules/vcpkg/bootstrap-vcpkg.sh"
6771
condition: ne(variables.CACHE_RESTORED, 'true')
6872
displayName: Bootstrap vcpkg
@@ -73,17 +77,47 @@ stages:
7377
- template: .azure/default-build.yml
7478
parameters:
7579
agentOs: Linux
76-
jobName: Linux_Build_Test
80+
jobName: Linux_Build_Test_With_CppRestSDK
81+
useCppRestSDK: true
7782
beforeBuild:
7883
- script: sudo vcpkg install cpprestsdk boost-system boost-chrono boost-thread --vcpkg-root ./submodules/vcpkg
7984
condition: ne(variables.CACHE_RESTORED, 'true')
8085
displayName: vcpkg install dependencies
8186

87+
- template: .azure/default-build.yml
88+
parameters:
89+
agentOs: Linux
90+
jobName: Linux_Build_Test
91+
useCppRestSDK: false
92+
93+
- template: .azure/default-build.yml
94+
parameters:
95+
agentOs: Windows
96+
jobName: Windows_Build_Test
97+
useCppRestSDK: false
98+
cMakeRunArgs: '-A x64'
99+
100+
- template: .azure/default-build.yml
101+
parameters:
102+
agentOs: macOs
103+
jobName: Mac_Build_Test
104+
useCppRestSDK: false
105+
beforeBuild:
106+
# XCode 11 doesn't play nicely with gcc, workaround by using XCode 10. We can try updating to a newer XCode in the future
107+
# Once the problem has been resolved
108+
- script: sudo xcode-select --switch /Applications/Xcode_10.3.app
109+
displayName: xcode-select
110+
- script: brew install gcc
111+
displayName: Install gcc
112+
82113
# Publish to the BAR
83114
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
84115
- template: /eng/common/templates/job/publish-build-assets.yml
85116
parameters:
86117
dependsOn:
118+
- Windows_Build_Test_With_CppRestSDK
119+
- Mac_Build_Test_With_CppRestSDK
120+
- Linux_Build_Test_With_CppRestSDK
87121
- Windows_Build_Test
88122
- Mac_Build_Test
89123
- Linux_Build_Test

include/signalrclient/_exports.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@
1111
#else
1212
#define SIGNALRCLIENT_API __declspec(dllimport)
1313
#endif // SIGNALRCLIENT_EXPORTS
14-
#endif // NO_SIGNALRCLIENT_EXPORTS
14+
#endif // NO_SIGNALRCLIENT_EXPORTS
15+
16+
#ifndef _WIN32
17+
#ifndef __cdecl
18+
#ifdef cdecl
19+
#define __cdecl __attribute__((cdecl))
20+
#else
21+
#define __cdecl
22+
#endif // cdecl
23+
#endif // !__cdecl
24+
#endif // _WIN32

include/signalrclient/hub_connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace signalr
5555

5656
explicit hub_connection(const std::string& url, trace_level trace_level = trace_level::all,
5757
std::shared_ptr<log_writer> log_writer = nullptr, std::shared_ptr<http_client> http_client = nullptr,
58-
std::function<std::shared_ptr<websocket_client>()> websocket_factory = nullptr);
58+
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory = nullptr);
5959

6060
std::shared_ptr<hub_connection_impl> m_pImpl;
6161
};

include/signalrclient/hub_connection_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace signalr
2828

2929
SIGNALRCLIENT_API hub_connection_builder& with_logging(std::shared_ptr<log_writer> logger, trace_level logLevel);
3030

31-
SIGNALRCLIENT_API hub_connection_builder& with_websocket_factory(std::function<std::shared_ptr<websocket_client>()> factory);
31+
SIGNALRCLIENT_API hub_connection_builder& with_websocket_factory(std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> factory);
3232

3333
SIGNALRCLIENT_API hub_connection_builder& with_http_client(std::shared_ptr<http_client> http_client);
3434

@@ -39,7 +39,7 @@ namespace signalr
3939
std::string m_url;
4040
std::shared_ptr<log_writer> m_logger;
4141
trace_level m_log_level;
42-
std::function<std::shared_ptr<websocket_client>()> m_websocket_factory;
42+
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> m_websocket_factory;
4343
std::shared_ptr<http_client> m_http_client;
4444
};
4545
}

include/signalrclient/signalr_client_config.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#endif
1010

1111
#include "_exports.h"
12+
#include <map>
13+
#include <string>
1214

1315
namespace signalr
1416
{
1517
class signalr_client_config
1618
{
17-
#ifdef USE_CPPRESTSDK
1819
public:
20+
#ifdef USE_CPPRESTSDK
1921
SIGNALRCLIENT_API void __cdecl set_proxy(const web::web_proxy &proxy);
2022
// Please note that setting credentials does not work in all cases.
2123
// For example, Basic Authentication fails under Win32.
@@ -28,14 +30,17 @@ namespace signalr
2830

2931
SIGNALRCLIENT_API web::websockets::client::websocket_client_config __cdecl get_websocket_client_config() const noexcept;
3032
SIGNALRCLIENT_API void __cdecl set_websocket_client_config(const web::websockets::client::websocket_client_config& websocket_client_config);
33+
#endif
3134

32-
SIGNALRCLIENT_API web::http::http_headers __cdecl get_http_headers() const noexcept;
33-
SIGNALRCLIENT_API void __cdecl set_http_headers(const web::http::http_headers& http_headers);
35+
SIGNALRCLIENT_API const std::map<std::string, std::string>& __cdecl get_http_headers() const noexcept;
36+
SIGNALRCLIENT_API std::map<std::string, std::string>& __cdecl get_http_headers() noexcept;
37+
SIGNALRCLIENT_API void __cdecl set_http_headers(const std::map<std::string, std::string>& http_headers);
3438

3539
private:
40+
#ifdef USE_CPPRESTSDK
3641
web::http::client::http_client_config m_http_client_config;
3742
web::websockets::client::websocket_client_config m_websocket_client_config;
38-
web::http::http_headers m_http_headers;
3943
#endif
44+
std::map<std::string, std::string> m_http_headers;
4045
};
4146
}

src/signalrclient/connection_impl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace signalr
3333
}
3434

3535
std::shared_ptr<connection_impl> connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
36-
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory)
36+
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
3737
{
3838
return std::shared_ptr<connection_impl>(new connection_impl(url, trace_level,
3939
log_writer ? log_writer : std::make_shared<trace_log_writer>(), http_client, websocket_factory));
@@ -50,12 +50,14 @@ namespace signalr
5050
}
5151
else
5252
{
53+
#ifdef USE_CPPRESTSDK
5354
m_http_client = std::unique_ptr<class http_client>(new default_http_client());
55+
#endif
5456
}
5557
}
5658

5759
connection_impl::connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
58-
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory)
60+
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
5961
: m_base_url(url), m_connection_state(connection_state::disconnected), m_logger(log_writer, trace_level), m_transport(nullptr),
6062
m_message_received([](const std::string&) noexcept {}), m_disconnected([]() noexcept {})
6163
{
@@ -73,7 +75,7 @@ namespace signalr
7375
if (websocket_factory == nullptr)
7476
{
7577
#ifdef USE_CPPRESTSDK
76-
websocket_factory = []() { return std::make_shared<default_websocket_client>(); };
78+
websocket_factory = [](const signalr_client_config& signalr_client_config) { return std::make_shared<default_websocket_client>(signalr_client_config); };
7779
#endif
7880
}
7981

@@ -198,9 +200,8 @@ namespace signalr
198200
{
199201
if (!response.accessToken.empty())
200202
{
201-
auto headers = connection->m_signalr_client_config.get_http_headers();
202-
headers[_XPLATSTR("Authorization")] = utility::conversions::to_string_t("Bearer " + response.accessToken);
203-
connection->m_signalr_client_config.set_http_headers(headers);
203+
auto& headers = connection->m_signalr_client_config.get_http_headers();
204+
headers["Authorization"] = "Bearer " + response.accessToken;
204205
}
205206
connection->start_negotiate(response.url, redirect_count + 1, callback);
206207
return;

src/signalrclient/connection_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace signalr
2929
static std::shared_ptr<connection_impl> create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer);
3030

3131
static std::shared_ptr<connection_impl> create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
32-
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory);
32+
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);
3333

3434
connection_impl(const connection_impl&) = delete;
3535

@@ -70,7 +70,7 @@ namespace signalr
7070
std::unique_ptr<http_client> http_client, std::unique_ptr<transport_factory> transport_factory);
7171

7272
connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
73-
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory);
73+
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);
7474

7575
void start_transport(const std::string& url, std::function<void(std::shared_ptr<transport>, std::exception_ptr)> callback);
7676
void send_connect_request(const std::shared_ptr<transport>& transport,

src/signalrclient/default_websocket_client.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ namespace signalr
1313
static web::websockets::client::websocket_client_config create_client_config(const signalr_client_config& signalr_client_config) noexcept
1414
{
1515
auto websocket_client_config = signalr_client_config.get_websocket_client_config();
16-
websocket_client_config.headers() = signalr_client_config.get_http_headers();
16+
auto& websocket_headers = websocket_client_config.headers();
17+
for (auto& header : signalr_client_config.get_http_headers())
18+
{
19+
websocket_headers.add(utility::conversions::to_string_t(header.first), utility::conversions::to_string_t(header.second));
20+
}
1721

1822
return websocket_client_config;
1923
}

0 commit comments

Comments
 (0)