diff --git a/include/signalrclient/connection.h b/include/signalrclient/connection.h index de6a4ec..d75182e 100644 --- a/include/signalrclient/connection.h +++ b/include/signalrclient/connection.h @@ -6,8 +6,6 @@ #include #include "_exports.h" #include "transport_type.h" -#include "web_request_factory.h" -#include "transport_factory.h" #include "connection_state.h" namespace signalr @@ -30,9 +28,6 @@ namespace signalr SIGNALRCLIENT_API connection_state get_connection_state() const; private: - web_request_factory m_web_request_factory; - transport_factory m_transport_factory; - connection_impl *m_pImpl; }; } \ No newline at end of file diff --git a/src/signalrclient/Build/VS2013/signalrclient.vcxproj b/src/signalrclient/Build/VS2013/signalrclient.vcxproj index 1d644cd..4ac30e5 100644 --- a/src/signalrclient/Build/VS2013/signalrclient.vcxproj +++ b/src/signalrclient/Build/VS2013/signalrclient.vcxproj @@ -93,13 +93,8 @@ - - - - - @@ -110,9 +105,14 @@ + + + + + diff --git a/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters b/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters index ec5db13..b569cdb 100644 --- a/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters +++ b/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters @@ -57,21 +57,6 @@ Header Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files @@ -90,6 +75,21 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + diff --git a/src/signalrclient/connection.cpp b/src/signalrclient/connection.cpp index 86f6bf3..285160c 100644 --- a/src/signalrclient/connection.cpp +++ b/src/signalrclient/connection.cpp @@ -4,15 +4,13 @@ #include "stdafx.h" #include "signalrclient\connection.h" #include "signalrclient\transport_type.h" -#include "signalrclient\web_request_factory.h" -#include "signalrclient\transport_factory.h" #include "connection_impl.h" namespace signalr { connection::connection(const utility::string_t& url, const utility::string_t& querystring) { - m_pImpl = new connection_impl(url, querystring, m_web_request_factory, m_transport_factory); + m_pImpl = new connection_impl(url, querystring); } connection::~connection() diff --git a/src/signalrclient/connection_impl.cpp b/src/signalrclient/connection_impl.cpp index 745df14..0d51f3b 100644 --- a/src/signalrclient/connection_impl.cpp +++ b/src/signalrclient/connection_impl.cpp @@ -8,10 +8,14 @@ namespace signalr { + connection_impl::connection_impl(const utility::string_t& url, const utility::string_t& querystring) + : connection_impl(url, querystring, std::make_unique(), std::make_unique()) + { } + connection_impl::connection_impl(const utility::string_t& url, const utility::string_t& querystring, - web_request_factory& web_request_factory, transport_factory& transport_factory) - : m_base_uri(url), m_querystring(querystring), m_web_request_factory(web_request_factory), - m_transport_factory(transport_factory), m_connection_state(connection_state::disconnected) + std::unique_ptr web_request_factory, std::unique_ptr transport_factory) + : m_base_uri(url), m_querystring(querystring), m_web_request_factory(std::move(web_request_factory)), + m_transport_factory(std::move(transport_factory)), m_connection_state(std::move(connection_state::disconnected)) { } pplx::task connection_impl::start() diff --git a/src/signalrclient/connection_impl.h b/src/signalrclient/connection_impl.h index 870c8d9..0c6341d 100644 --- a/src/signalrclient/connection_impl.h +++ b/src/signalrclient/connection_impl.h @@ -5,19 +5,21 @@ #include #include -#include "signalrclient\web_request_factory.h" -#include "signalrclient\transport_factory.h" +#include "signalrclient\trace_level.h" #include "signalrclient\connection_state.h" +#include "web_request_factory.h" +#include "transport_factory.h" +#include "logger.h" namespace signalr { class connection_impl { public: - // taking references to be able to inject factories for test purposes. The caller must - // make sure that actual instances outlive connection_impl + connection_impl(const utility::string_t& url, const utility::string_t& querystring); + connection_impl(const utility::string_t& url, const utility::string_t& querystring, - web_request_factory& web_request_factory, transport_factory& transport_factory); + std::unique_ptr web_request_factory, std::unique_ptr transport_factory); connection_impl(const connection_impl&) = delete; @@ -32,8 +34,8 @@ namespace signalr utility::string_t m_querystring; std::atomic m_connection_state; - web_request_factory &m_web_request_factory; - transport_factory& m_transport_factory; + std::unique_ptr m_web_request_factory; + std::unique_ptr m_transport_factory; bool change_state(connection_state old_state, connection_state new_state); }; diff --git a/src/signalrclient/http_sender.cpp b/src/signalrclient/http_sender.cpp index 0e93fdf..be5455b 100644 --- a/src/signalrclient/http_sender.cpp +++ b/src/signalrclient/http_sender.cpp @@ -4,7 +4,7 @@ #include "stdafx.h" #include #include "signalrclient\web_exception.h" -#include "signalrclient\web_request.h" +#include "web_request.h" #include "constants.h" namespace signalr diff --git a/src/signalrclient/http_sender.h b/src/signalrclient/http_sender.h index 6ca251f..a2d5147 100644 --- a/src/signalrclient/http_sender.h +++ b/src/signalrclient/http_sender.h @@ -6,7 +6,7 @@ #include #include -#include "signalrclient\web_request.h" +#include "web_request.h" namespace pplx = concurrency; diff --git a/src/signalrclient/request_sender.h b/src/signalrclient/request_sender.h index eb5b2d9..74538e6 100644 --- a/src/signalrclient/request_sender.h +++ b/src/signalrclient/request_sender.h @@ -4,7 +4,7 @@ #pragma once #include -#include "signalrclient\web_request_factory.h" +#include "web_request_factory.h" #include "negotiation_response.h" namespace signalr diff --git a/include/signalrclient/transport.h b/src/signalrclient/transport.h similarity index 100% rename from include/signalrclient/transport.h rename to src/signalrclient/transport.h diff --git a/src/signalrclient/transport_factory.cpp b/src/signalrclient/transport_factory.cpp index 7728107..9a8713b 100644 --- a/src/signalrclient/transport_factory.cpp +++ b/src/signalrclient/transport_factory.cpp @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #include "stdafx.h" -#include "signalrclient\transport_factory.h" +#include "transport_factory.h" #include "websocket_transport.h" namespace signalr diff --git a/include/signalrclient/transport_factory.h b/src/signalrclient/transport_factory.h similarity index 100% rename from include/signalrclient/transport_factory.h rename to src/signalrclient/transport_factory.h diff --git a/src/signalrclient/web_request.cpp b/src/signalrclient/web_request.cpp index 8b0adbb..96929c6 100644 --- a/src/signalrclient/web_request.cpp +++ b/src/signalrclient/web_request.cpp @@ -3,7 +3,7 @@ #include "stdafx.h" #include -#include "signalrclient\web_request.h" +#include "web_request.h" namespace signalr { diff --git a/include/signalrclient/web_request.h b/src/signalrclient/web_request.h similarity index 100% rename from include/signalrclient/web_request.h rename to src/signalrclient/web_request.h diff --git a/src/signalrclient/web_request_factory.cpp b/src/signalrclient/web_request_factory.cpp index d37c0da..6497743 100644 --- a/src/signalrclient/web_request_factory.cpp +++ b/src/signalrclient/web_request_factory.cpp @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #include "stdafx.h" -#include "signalrclient\web_request_factory.h" +#include "web_request_factory.h" namespace signalr { diff --git a/include/signalrclient/web_request_factory.h b/src/signalrclient/web_request_factory.h similarity index 100% rename from include/signalrclient/web_request_factory.h rename to src/signalrclient/web_request_factory.h diff --git a/include/signalrclient/web_response.h b/src/signalrclient/web_response.h similarity index 100% rename from include/signalrclient/web_response.h rename to src/signalrclient/web_response.h diff --git a/src/signalrclient/websocket_transport.cpp b/src/signalrclient/websocket_transport.cpp index 0f33c7b..b6c5a79 100644 --- a/src/signalrclient/websocket_transport.cpp +++ b/src/signalrclient/websocket_transport.cpp @@ -111,7 +111,6 @@ namespace signalr return; } - // TODO: log, report error, close websocket (when appropriate) catch (const web_sockets::client::websocket_exception&) { diff --git a/src/signalrclient/websocket_transport.h b/src/signalrclient/websocket_transport.h index a9d57f1..d6f7100 100644 --- a/src/signalrclient/websocket_transport.h +++ b/src/signalrclient/websocket_transport.h @@ -5,7 +5,8 @@ #include #include "url_builder.h" -#include "signalrclient\transport.h" +#include "transport.h" +#include "logger.h" #include "default_websocket_client.h" namespace signalr diff --git a/test/signalrclienttests/connection_impl_tests.cpp b/test/signalrclienttests/connection_impl_tests.cpp index 61de300..048cf53 100644 --- a/test/signalrclienttests/connection_impl_tests.cpp +++ b/test/signalrclienttests/connection_impl_tests.cpp @@ -3,28 +3,23 @@ #include "stdafx.h" #include "connection_impl.h" -#include "signalrclient\web_request_factory.h" -#include "signalrclient\transport_factory.h" +#include "signalrclient\trace_level.h" +#include "signalrclient\trace_log_writer.h" +#include "web_request_factory.h" +#include "transport_factory.h" +#include "memory_log_writer.h" using namespace signalr; TEST(connection_impl_connection_state, initial_connection_state_is_disconnected) { - web_request_factory request_factory; - transport_factory transport_factory; - - connection_impl connection{ _XPLATSTR("url"), _XPLATSTR(""), request_factory, transport_factory }; - + connection_impl connection{ _XPLATSTR("url"), _XPLATSTR("") }; ASSERT_EQ(connection_state::disconnected, connection.get_connection_state()); } TEST(connection_impl_start, cannot_start_non_disconnected_exception) { - web_request_factory request_factory; - transport_factory transport_factory; - - connection_impl connection{ _XPLATSTR("url"), _XPLATSTR(""), request_factory, transport_factory }; - + connection_impl connection{ _XPLATSTR("url"), _XPLATSTR("") }; connection.start().wait(); try @@ -42,12 +37,8 @@ TEST(connection_impl_start, cannot_start_non_disconnected_exception) TEST(connection_impl_start, connection_state_is_connecting_when_connection_is_being_started) { - web_request_factory request_factory; - transport_factory transport_factory; - - connection_impl connection{ _XPLATSTR("url"), _XPLATSTR(""), request_factory, transport_factory }; + connection_impl connection{ _XPLATSTR("url"), _XPLATSTR(""), }; connection.start().wait(); ASSERT_EQ(connection.get_connection_state(), connection_state::connecting); } - diff --git a/test/signalrclienttests/test_web_request_factory.h b/test/signalrclienttests/test_web_request_factory.h index c57344b..d6925d6 100644 --- a/test/signalrclienttests/test_web_request_factory.h +++ b/test/signalrclienttests/test_web_request_factory.h @@ -3,7 +3,7 @@ #pragma once -#include "signalrclient\web_request_factory.h" +#include "web_request_factory.h" #include "web_request_stub.h" using namespace signalr; diff --git a/test/signalrclienttests/web_request_stub.h b/test/signalrclienttests/web_request_stub.h index c37a6bd..12980d4 100644 --- a/test/signalrclienttests/web_request_stub.h +++ b/test/signalrclienttests/web_request_stub.h @@ -3,8 +3,8 @@ #pragma once -#include "signalrclient\web_request.h" -#include "signalrclient\web_response.h" +#include "web_request.h" +#include "web_response.h" using namespace signalr; diff --git a/test/signalrclienttests/web_request_tests.cpp b/test/signalrclienttests/web_request_tests.cpp index 70d498a..68234d2 100644 --- a/test/signalrclienttests/web_request_tests.cpp +++ b/test/signalrclienttests/web_request_tests.cpp @@ -3,7 +3,7 @@ #include "stdafx.h" #include -#include "signalrclient\web_request.h" +#include "web_request.h" using namespace web; using namespace signalr;