Files

93 lines
2.4 KiB
C++
Raw Permalink Normal View History

2024-05-27 10:35:06 +02:00
//
2025-02-14 13:42:23 +01:00
// Copyright (c) 2023-2025 Ivica Siladic, Bruno Iljazovic, Korina Simicevic
2024-05-27 10:35:06 +02:00
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
2025-01-13 16:11:41 +01:00
#ifndef BOOST_MQTT5_TEST_TEST_SERVICE_HPP
#define BOOST_MQTT5_TEST_TEST_SERVICE_HPP
2025-01-13 16:11:41 +01:00
#include <boost/mqtt5/types.hpp>
#include <boost/mqtt5/impl/client_service.hpp>
2024-10-08 09:59:35 +02:00
#include <boost/asio/any_io_executor.hpp>
2024-10-08 09:59:35 +02:00
#include <boost/asio/async_result.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/prepend.hpp>
2024-10-08 09:59:35 +02:00
#include <boost/system/error_code.hpp>
2025-01-13 16:11:41 +01:00
#include <cstdint>
#include <variant> // std::monostate
2023-12-13 15:13:07 +01:00
2025-01-13 16:11:41 +01:00
namespace boost::mqtt5::test {
2023-10-06 11:51:04 +02:00
namespace asio = boost::asio;
template <
2025-01-13 16:11:41 +01:00
typename StreamType,
typename TlsContext = std::monostate
>
2025-01-13 16:11:41 +01:00
class test_service : public boost::mqtt5::detail::client_service<StreamType, TlsContext> {
using error_code = boost::system::error_code;
using base = boost::mqtt5::detail::client_service<StreamType, TlsContext>;
2025-01-13 16:11:41 +01:00
asio::any_io_executor _ex;
connack_props _test_props;
public:
2025-01-13 16:11:41 +01:00
explicit test_service(const asio::any_io_executor& ex)
: base(ex), _ex(ex)
{}
2025-01-13 16:11:41 +01:00
test_service(const asio::any_io_executor& ex, connack_props props)
: base(ex), _ex(ex), _test_props(std::move(props))
{}
2023-12-13 15:13:07 +01:00
2025-01-13 16:11:41 +01:00
template <typename BufferType, typename CompletionToken>
decltype(auto) async_send(
const BufferType&, uint32_t, unsigned,
CompletionToken&& token
) {
auto initiation = [this](auto handler) {
asio::post(_ex,
asio::prepend(std::move(handler), error_code {})
);
};
2025-01-13 16:11:41 +01:00
return asio::async_initiate<CompletionToken, void (error_code)>(
std::move(initiation), token
);
}
2023-12-13 15:13:07 +01:00
2025-01-13 16:11:41 +01:00
template <typename Prop>
const auto& connack_property(Prop p) const {
return _test_props[p];
}
2023-12-13 15:13:07 +01:00
2025-01-13 16:11:41 +01:00
const auto& connack_properties() {
return _test_props;
}
2023-12-13 15:13:07 +01:00
};
template <
2025-01-13 16:11:41 +01:00
typename StreamType,
typename TlsContext = std::monostate
>
2025-01-13 16:11:41 +01:00
class overrun_client : public boost::mqtt5::detail::client_service<StreamType, TlsContext> {
public:
2025-01-13 16:11:41 +01:00
explicit overrun_client(const asio::any_io_executor& ex) :
boost::mqtt5::detail::client_service<StreamType, TlsContext>(ex)
{}
2025-01-13 16:11:41 +01:00
uint16_t allocate_pid() {
return 0;
}
};
2025-01-13 16:11:41 +01:00
} // end namespace boost::mqtt5::test
2025-01-13 16:11:41 +01:00
#endif // BOOST_MQTT5_TEST_TEST_SERVICE_HPP