Skip to content

Commit

Permalink
Fix default init for safeMode
Browse files Browse the repository at this point in the history
  • Loading branch information
MPogotsky committed Sep 3, 2024
1 parent 74eb04d commit a5cab32
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion xapi/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace internals
Connection::Connection(boost::asio::io_context &ioContext)
: m_ioContext(ioContext), m_sslContext(boost::asio::ssl::context::tlsv13_client),
m_websocket(m_ioContext, m_sslContext), m_lastRequestTime(std::chrono::system_clock::now()),
m_connectionEstablished(false)
m_connectionEstablished(false), m_requestTimeout(200), m_websocketDefaultPort("443")
{
}

Expand Down
15 changes: 12 additions & 3 deletions xapi/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ namespace internals
class Connection
{
public:
Connection() = delete;

Connection(const Connection &) = delete;
Connection &operator=(const Connection &) = delete;

Connection(Connection &&other) = default;
// Move assignment operatopr not supported because of boost::beast::websocket::stream
Connection &operator=(Connection &&other) = delete;

Connection(boost::asio::io_context &ioContext);
~Connection() {};
virtual ~Connection() = default;

boost::asio::awaitable<void> connect(const std::string &url);

Expand All @@ -43,8 +52,8 @@ class Connection
std::chrono::time_point<std::chrono::system_clock> m_lastRequestTime;
bool m_connectionEstablished;

const std::chrono::milliseconds m_requestTimeout{200};
const std::string m_websocketDefaultPort{"443"};
const std::chrono::milliseconds m_requestTimeout;
const std::string m_websocketDefaultPort;
};

} // namespace internals
Expand Down
4 changes: 4 additions & 0 deletions xapi/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
namespace xapi
{

Socket::Socket(boost::asio::io_context &ioContext)
: Connection(ioContext), safeMode(true)
{}

boost::asio::awaitable<void> Socket::initSession(const std::string &host, const std::string &type)
{
const std::string socketUrl = urlWithValidHost(host).value_or(host) + "/" + type;
Expand Down
11 changes: 8 additions & 3 deletions xapi/Socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ namespace xapi
class Socket final : protected internals::Connection
{
public:

Socket() = delete;
~Socket() = default;

using Connection::Connection;
Socket(const Socket &) = delete;
Socket &operator=(const Socket &) = delete;

Socket(Socket &&other) = default;
Socket &operator=(Socket &&other) = delete;

Socket(boost::asio::io_context &ioContext);
~Socket() override = default;

bool safeMode;

Expand Down
5 changes: 5 additions & 0 deletions xapi/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

namespace xapi
{

Stream::Stream(boost::asio::io_context &ioContext)
: Connection(ioContext), m_streamSessionId("")
{}

boost::asio::awaitable<void> Stream::initSession(const std::string &host, const std::string &type, const std::string& streamSessionId)
{
const std::string streamUrl = urlWithValidHost(host).value_or(host) + "/" + type + "Stream";
Expand Down
16 changes: 11 additions & 5 deletions xapi/Stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ namespace xapi
class Stream final : protected internals::Connection
{
public:

Stream() = delete;
~Stream() = default;

using Connection::Connection;
Stream(const Stream &) = delete;
Stream &operator=(const Stream &) = delete;

Stream(Stream &&other) = default;
Stream &operator=(Stream &&other) = delete;

Stream(boost::asio::io_context &ioContext);
~Stream() override = default;

boost::asio::awaitable<void> initSession(const std::string &host, const std::string &type, const std::string& streamSessionId);
boost::asio::awaitable<void> initSession(const std::string &host, const std::string &type,
const std::string &streamSessionId);

boost::asio::awaitable<void> closeSession();

Expand Down Expand Up @@ -55,7 +61,7 @@ class Stream final : protected internals::Connection

boost::asio::awaitable<void> ping();

private:
private:
std::string m_streamSessionId;
};

Expand Down

0 comments on commit a5cab32

Please sign in to comment.