async_mqtt 9.0.1
Loading...
Searching...
No Matches
endpoint.hpp
1// Copyright Takatoshi Kondo 2022
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_ENDPOINT_HPP)
8#define ASYNC_MQTT_ENDPOINT_HPP
9
10#include <async_mqtt/detail/endpoint_impl.hpp>
11
21namespace async_mqtt {
22
27enum class filter {
28 match,
29 except
30};
31
32template <role Role, std::size_t PacketIdBytes, typename NextLayer>
33class basic_endpoint {
35 using impl_type = detail::basic_endpoint_impl<Role, PacketIdBytes, NextLayer>;
36 using stream_type =
37 stream<
38 NextLayer
39 >;
40public:
42 using next_layer_type = typename stream_type::next_layer_type;
43
45 using lowest_layer_type = typename stream_type::lowest_layer_type;
46
48 using executor_type = typename next_layer_type::executor_type;
49
52
65 template <typename... Args>
66 explicit
69 Args&&... args
70 );
71
78
82 basic_endpoint(this_type const&) = delete;
83
88
92 this_type& operator=(this_type const&) = delete;
93
98
103 as::any_io_executor get_executor();
104
110
116
122
128
134 void set_auto_pub_response(bool val);
135
142
151
160
171 void set_pingresp_recv_timeout(std::chrono::milliseconds duration);
172
182 void set_bulk_write(bool val);
183
194 void set_bulk_read_buffer_size(std::size_t val);
195
196
197 // async functions
198
214 template <
215 typename CompletionToken = as::default_completion_token_t<executor_type>
216 >
217#if !defined(GENERATING_DOCUMENTATION)
218 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
219 CompletionToken,
221 )
222#endif // !defined(GENERATING_DOCUMENTATION)
224 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
225 );
226
242 template <
243 typename CompletionToken = as::default_completion_token_t<executor_type>
244 >
245#if !defined(GENERATING_DOCUMENTATION)
246 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
247 CompletionToken,
249 )
250#endif // !defined(GENERATING_DOCUMENTATION)
252 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
253 );
254
271 template <
272 typename CompletionToken = as::default_completion_token_t<executor_type>
273 >
274#if !defined(GENERATING_DOCUMENTATION)
275 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
276 CompletionToken,
277 void(error_code)
278 )
279#endif // !defined(GENERATING_DOCUMENTATION)
282 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
283 );
284
300 template <
301 typename CompletionToken = as::default_completion_token_t<executor_type>
302 >
303#if !defined(GENERATING_DOCUMENTATION)
304 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
305 CompletionToken,
306 void()
307 )
308#endif // !defined(GENERATING_DOCUMENTATION)
311 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
312 );
313
331 template <
332 typename Packet,
333 typename CompletionToken = as::default_completion_token_t<executor_type>
334 >
335#if !defined(GENERATING_DOCUMENTATION)
336 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
337 CompletionToken,
338 void(error_code)
339 )
340#endif // !defined(GENERATING_DOCUMENTATION)
342 Packet packet,
343 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
344 );
345
361 template <
362 typename CompletionToken = as::default_completion_token_t<executor_type>
363 >
364#if !defined(GENERATING_DOCUMENTATION)
365 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
366 CompletionToken,
368 )
369#endif // !defined(GENERATING_DOCUMENTATION)
371 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
372 );
373
392 template <
393 typename CompletionToken = as::default_completion_token_t<executor_type>
394 >
395#if !defined(GENERATING_DOCUMENTATION)
396 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
397 CompletionToken,
399 )
400#endif // !defined(GENERATING_DOCUMENTATION)
402 std::set<control_packet_type> types,
403 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
404 );
405
425 template <
426 typename CompletionToken = as::default_completion_token_t<executor_type>
427 >
428#if !defined(GENERATING_DOCUMENTATION)
429 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
430 CompletionToken,
432 )
433#endif // !defined(GENERATING_DOCUMENTATION)
435 filter fil,
436 std::set<control_packet_type> types,
437 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
438 );
439
453 template <
454 typename CompletionToken = as::default_completion_token_t<executor_type>
455 >
456#if !defined(GENERATING_DOCUMENTATION)
457 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
458 CompletionToken,
459 void()
460 )
461#endif // !defined(GENERATING_DOCUMENTATION)
463 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
464 );
465
482 template <
483 typename CompletionToken = as::default_completion_token_t<executor_type>
484 >
485#if !defined(GENERATING_DOCUMENTATION)
486 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
487 CompletionToken,
488 void()
489 )
490#endif // !defined(GENERATING_DOCUMENTATION)
493 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
494 );
495
515 template <
516 typename CompletionToken = as::default_completion_token_t<executor_type>
517 >
518#if !defined(GENERATING_DOCUMENTATION)
519 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
520 CompletionToken,
522 )
523#endif // !defined(GENERATING_DOCUMENTATION)
525 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
526 );
527
544 template <
545 typename CompletionToken = as::default_completion_token_t<executor_type>
546 >
547#if !defined(GENERATING_DOCUMENTATION)
548 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(
549 CompletionToken,
551 )
552#endif // !defined(GENERATING_DOCUMENTATION)
555 CompletionToken&& token = as::default_completion_token_t<executor_type>{}
556 );
557
558 // sync APIs
559
565 std::optional<typename basic_packet_id_type<PacketIdBytes>::type> acquire_unique_packet_id();
566
573
579
585 std::set<typename basic_packet_id_type<PacketIdBytes>::type> get_qos2_publish_handled_pids() const;
586
593
601 );
602
611 std::vector<basic_store_packet_variant<PacketIdBytes>> get_stored_packets() const;
612
618
625
635 error_code& ec
636 ) const;
637
646 void set_pingreq_send_interval(std::chrono::milliseconds duration);
647
651 template <typename Executor1>
653 using other = basic_endpoint<
654 Role,
655 PacketIdBytes,
656 typename NextLayer::template rebind_executor<Executor1>::other
657 >;
658 };
659
660private: // compose operation impl
666 template <typename Other>
667 explicit
670 );
671
672private:
673 std::shared_ptr<impl_type> impl_;
674};
675
676} // namespace async_mqtt
677
678#include <async_mqtt/impl/endpoint_impl.hpp>
679#include <async_mqtt/impl/endpoint_acquire_unique_packet_id.hpp>
680#include <async_mqtt/impl/endpoint_acquire_unique_packet_id_wait_until.hpp>
681#include <async_mqtt/impl/endpoint_register_packet_id.hpp>
682#include <async_mqtt/impl/endpoint_release_packet_id.hpp>
683#include <async_mqtt/impl/endpoint_send.hpp>
684#include <async_mqtt/impl/endpoint_recv.hpp>
685#include <async_mqtt/impl/endpoint_close.hpp>
686#include <async_mqtt/impl/endpoint_restore_packets.hpp>
687#include <async_mqtt/impl/endpoint_get_stored_packets.hpp>
688#include <async_mqtt/impl/endpoint_regulate_for_store.hpp>
689#include <async_mqtt/impl/endpoint_add_retry.hpp>
690
691#endif // ASYNC_MQTT_ENDPOINT_HPP
MQTT endpoint corresponding to the connection.
Definition endpoint_fwd.hpp:32
async_recv(filter fil, std::set< control_packet_type > types, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
receive packet if packet is not filterd, then next recv() starts automatically. if receive error happ...
~basic_endpoint()
destructor This function destroys the basic_endpoint, cancelling any outstanding asynchronous operati...
void set_bulk_write(bool val)
Set bulk write mode. If true, then concatenate multiple packets' const buffer sequence when send() is...
this_type & operator=(this_type &&)=default
move assign operator
void set_pingresp_recv_timeout(std::chrono::milliseconds duration)
Set timeout for receiving PINGRESP packet after PINGREQ packet is sent. If the timer is fired,...
basic_endpoint(this_type &&)=default
move constructor
async_release_packet_id(typename basic_packet_id_type< PacketIdBytes >::type packet_id, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
release packet_id.
async_send(Packet packet, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
send packet users can call send() before the previous send()'s CompletionToken is invoked
async_acquire_unique_packet_id_wait_until(CompletionToken &&token=as::default_completion_token_t< executor_type >{})
acuire unique packet_id. If packet_id is fully acquired, then wait until released.
async_regulate_for_store(v5::basic_publish_packet< PacketIdBytes > packet, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
regulate publish packet for store remove topic alias from the packet and extract the topic name
lowest_layer_type & lowest_layer()
lowest_layer getter
basic_packet_variant< PacketIdBytes > packet_variant_type
Type of packet_variant.
Definition endpoint.hpp:51
void set_auto_map_topic_alias_send(bool val)
auto map (allocate) topic alias on send PUBLISH packet. If all topic aliases are used,...
async_recv(CompletionToken &&token=as::default_completion_token_t< executor_type >{})
receive packet
std::set< typename basic_packet_id_type< PacketIdBytes >::type > get_qos2_publish_handled_pids() const
Get processed but not released QoS2 packet ids This function should be called after disconnection.
void set_auto_ping_response(bool val)
auto pingreq response setter. Should be called before send()/recv() call.
void set_auto_pub_response(bool val)
auto publish response setter. Should be called before send()/recv() call.
std::vector< basic_store_packet_variant< PacketIdBytes > > get_stored_packets() const
get stored packets sotred packets mean inflight packets.
void regulate_for_store(v5::basic_publish_packet< PacketIdBytes > &packet, error_code &ec) const
Regulate publish packet for store If topic is empty, extract topic from topic alias,...
typename next_layer_type::executor_type executor_type
executor_type of the given NextLayer
Definition endpoint.hpp:48
void restore_packets(std::vector< basic_store_packet_variant< PacketIdBytes > > pvs)
restore packets the restored packets would automatically send when CONNACK packet is received
void set_auto_replace_topic_alias_send(bool val)
auto replace topic with corresponding topic alias on send PUBLISH packet. Registering topic alias nee...
async_acquire_unique_packet_id(CompletionToken &&token=as::default_completion_token_t< executor_type >{})
acuire unique packet_id.
async_close(CompletionToken &&token=as::default_completion_token_t< executor_type >{})
close the underlying connection
async_recv(std::set< control_packet_type > types, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
receive packet if packet is not filterd, then next recv() starts automatically. if receive error happ...
lowest_layer_type const & lowest_layer() const
lowest_layer getter
std::optional< typename basic_packet_id_type< PacketIdBytes >::type > acquire_unique_packet_id()
acuire unique packet_id.
protocol_version get_protocol_version() const
get MQTT protocol version
basic_endpoint(this_type const &)=delete
copy constructor deleted
async_restore_packets(std::vector< basic_store_packet_variant< PacketIdBytes > > pvs, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
restore packets the restored packets would automatically send when CONNACK packet is received
basic_endpoint(protocol_version ver, Args &&... args)
constructor
void restore_qos2_publish_handled_pids(std::set< typename basic_packet_id_type< PacketIdBytes >::type > pids)
Restore processed but not released QoS2 packet ids This function should be called before receive the ...
async_get_stored_packets(CompletionToken &&token=as::default_completion_token_t< executor_type >{})
get stored packets
typename stream_type::lowest_layer_type lowest_layer_type
lowest_layer_type of the given NextLayer
Definition endpoint.hpp:45
next_layer_type & next_layer()
next_layer getter
void set_bulk_read_buffer_size(std::size_t val)
Set the bulk read buffer size. If bulk read is enabled, the val parameter specifies the size of the i...
void set_pingreq_send_interval(std::chrono::milliseconds duration)
Set PINGREQ packet sending interval.
next_layer_type const & next_layer() const
next_layer getter
bool register_packet_id(typename basic_packet_id_type< PacketIdBytes >::type packet_id)
register packet_id.
this_type & operator=(this_type const &)=delete
copy assign operator deleted
void release_packet_id(typename basic_packet_id_type< PacketIdBytes >::type packet_id)
release packet_id.
as::any_io_executor get_executor()
executor getter
typename stream_type::next_layer_type next_layer_type
type of the given NextLayer
Definition endpoint.hpp:42
async_register_packet_id(typename basic_packet_id_type< PacketIdBytes >::type packet_id, CompletionToken &&token=as::default_completion_token_t< executor_type >{})
register packet_id.
bool is_publish_processing(typename basic_packet_id_type< PacketIdBytes >::type pid) const
Get MQTT PUBLISH packet processing status.
The varaint type of all packets and system_error.
Definition packet_variant_fwd.hpp:37
MQTT packet variant for store.
Definition store_packet_variant_fwd.hpp:35
MQTT PUBLISH packet (v5)
Definition v5_publish.hpp:63
filter
receive packet filter
Definition endpoint.hpp:27
@ except
no matched control_packet_type is target
@ match
matched control_packet_type is target
sys::error_code error_code
sys is a namespace alias of boost::sytem.
Definition error.hpp:56
protocol_version
MQTT protocol version.
Definition protocol_version.hpp:29
rebinds the basic_endpoint type to another executor
Definition endpoint.hpp:652
packet idenfitifer type class template
Definition packet_id_type.hpp:25