diff --git a/include/signalrclient/connection.h b/include/signalrclient/connection.h index e8f7c95..de6a4ec 100644 --- a/include/signalrclient/connection.h +++ b/include/signalrclient/connection.h @@ -8,6 +8,7 @@ #include "transport_type.h" #include "web_request_factory.h" #include "transport_factory.h" +#include "connection_state.h" namespace signalr { @@ -26,6 +27,8 @@ namespace signalr SIGNALRCLIENT_API pplx::task start(); + SIGNALRCLIENT_API connection_state get_connection_state() const; + private: web_request_factory m_web_request_factory; transport_factory m_transport_factory; diff --git a/include/signalrclient/connection_state.h b/include/signalrclient/connection_state.h new file mode 100644 index 0000000..810a647 --- /dev/null +++ b/include/signalrclient/connection_state.h @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#pragma once + +namespace signalr +{ + enum class connection_state + { + connecting, + connected, + reconnecting, + disconnected + }; +} \ No newline at end of file diff --git a/src/signalrclient/Build/VS2013/signalrclient.vcxproj b/src/signalrclient/Build/VS2013/signalrclient.vcxproj index 696fb02..2ff5f4d 100644 --- a/src/signalrclient/Build/VS2013/signalrclient.vcxproj +++ b/src/signalrclient/Build/VS2013/signalrclient.vcxproj @@ -89,6 +89,7 @@ + diff --git a/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters b/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters index 341b593..68eee39 100644 --- a/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters +++ b/src/signalrclient/Build/VS2013/signalrclient.vcxproj.filters @@ -72,6 +72,9 @@ Header Files + + Header Files + diff --git a/src/signalrclient/connection.cpp b/src/signalrclient/connection.cpp index 1e7a138..86f6bf3 100644 --- a/src/signalrclient/connection.cpp +++ b/src/signalrclient/connection.cpp @@ -24,5 +24,10 @@ namespace signalr { return m_pImpl->start(); } + + connection_state connection::get_connection_state() const + { + return m_pImpl->get_connection_state(); + } } diff --git a/src/signalrclient/connection_impl.cpp b/src/signalrclient/connection_impl.cpp index 00b0291..88ec243 100644 --- a/src/signalrclient/connection_impl.cpp +++ b/src/signalrclient/connection_impl.cpp @@ -8,11 +8,17 @@ namespace signalr { 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_base_uri(url), m_querystring(querystring), m_web_request_factory(web_request_factory), + m_transport_factory(transport_factory), m_connection_state(connection_state::disconnected) { } pplx::task connection_impl::start() { return pplx::task_from_result(); } + + connection_state connection_impl::get_connection_state() const + { + return m_connection_state; + } } \ No newline at end of file diff --git a/src/signalrclient/connection_impl.h b/src/signalrclient/connection_impl.h index 0be2642..57efb70 100644 --- a/src/signalrclient/connection_impl.h +++ b/src/signalrclient/connection_impl.h @@ -6,6 +6,7 @@ #include #include "signalrclient\web_request_factory.h" #include "signalrclient\transport_factory.h" +#include "signalrclient\connection_state.h" namespace signalr { @@ -23,9 +24,12 @@ namespace signalr pplx::task start(); + connection_state get_connection_state() const; + private: web::uri m_base_uri; utility::string_t m_querystring; + connection_state m_connection_state; web_request_factory &m_web_request_factory; transport_factory& m_transport_factory; diff --git a/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj b/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj index 95a6baf..e896570 100644 --- a/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj +++ b/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj @@ -92,6 +92,7 @@ + diff --git a/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj.filters b/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj.filters index 461ade3..415ecf9 100644 --- a/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj.filters +++ b/test/signalrclienttests/Build/VS2013/signalrclienttests.vcxproj.filters @@ -62,6 +62,9 @@ Source Files + + Source Files + diff --git a/test/signalrclienttests/connection_impl_tests.cpp b/test/signalrclienttests/connection_impl_tests.cpp new file mode 100644 index 0000000..760b944 --- /dev/null +++ b/test/signalrclienttests/connection_impl_tests.cpp @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +#include "stdafx.h" +#include "connection_impl.h" +#include "signalrclient\web_request_factory.h" +#include "signalrclient\transport_factory.h" + +using namespace signalr; + +TEST(connection_impl_connection_state, initial_connection_state_is_disconnected) +{ + web_request_factory request_factory; + transport_factory transport_factory; + + ASSERT_EQ( + connection_state::disconnected, + connection_impl(_XPLATSTR("url"), _XPLATSTR(""), request_factory, transport_factory).get_connection_state()); +}