Loading...
Searching...
No Matches
mqtt::event Class Reference

`#include <event.h>`

## Public Types

using | event_type = std::variant< const_message_ptr, connected_event, connection_lost_event, disconnected_event, shutdown_event >

## Public Member Functions

| event ()
| event (event_type evt)
| event (message_ptr msg)
| event (const_message_ptr msg)
| event (connected_event evt)
| event (connection_lost_event evt)
| event (disconnected_event evt)
| event (shutdown_event evt)
| event (const event &evt)
| event (event &&evt)
event & | operator= (event_type evt)
event & | operator= (const event &rhs)
event & | operator= (event &&rhs)
bool | is_message () const
bool | is_connected () const
bool | is_connection_lost () const
bool | is_disconnected () const
bool | is_shutdown () const
bool | is_any_disconnect () const
const_message_ptr | get_message ()
disconnected_event | get_disconnected ()
constexpr std::add_pointer_t< const_message_ptr > | get_message_if () noexcept
constexpr std::add_pointer_t< disconnected_event > | get_disconnected_if () noexcept

## Detailed Description

An MQTT event.

This is used by the client consumer to pass events and state changes from the client to the application without the need for any additional callbacks or client queries.

Each instance carries the relevant data for specific event that caused it. For example an incoming message event contains a shared pointer to the message that arrived.

The supported event types are:

- message A message arrived from the server.
- connected The client connected. If the client was configured for automatic reconnects, this can be from a reconnection. (No data)
- connection lost The client lost the connection. (No data)
- disconnected (v5) The client received a DISCONNECT packet from the server. This includes the reason code and properties for the disconnect.

## Member Typedef Documentation

## event_type

using mqtt::event::event_type = std::variant< const_message_ptr, connected_event, connection_lost_event, disconnected_event, shutdown_event>

The variant type for any possible event.

## Constructor & Destructor Documentation

## event() [1/10]

mqtt::event::event | ( |  | ) |

inline

Constructs an empty event. This shows as a message, but the message pointer is null.

## event() [2/10]

mqtt::event::event | ( | event_type | evt | ) |

inline

Constructs an event from an event type variant.

Parameters

  evt | The event type variant.

## event() [3/10]

mqtt::event::event | ( | message_ptr | msg | ) |

inline

Constructs a message event.

Parameters

  msg | A shared message pointer.

## event() [4/10]

mqtt::event::event | ( | const_message_ptr | msg | ) |

inline

Constructs a message event.

Parameters

  msg | A shared const message pointer.

## event() [5/10]

mqtt::event::event | ( | connected_event | evt | ) |

inline

Constructs a 'connected' event.

Parameters

  evt | A connected event.

## event() [6/10]

mqtt::event::event | ( | connection_lost_event | evt | ) |

inline

Constructs a 'connection lost' event.

Parameters

  evt | A connection lost event.

## event() [7/10]

mqtt::event::event | ( | disconnected_event | evt | ) |

inline

Constructs a 'disconnected' event.

Parameters

  evt | A disconnected event.

## event() [8/10]

mqtt::event::event | ( | shutdown_event | evt | ) |

inline

Constructs a 'shutdown' event.

Parameters

  evt | A shutdown event.

## event() [9/10]

mqtt::event::event | ( | const event & | evt | ) |

inline

Copy constructor.

Parameters

  evt | The event to copy.

## event() [10/10]

mqtt::event::event | ( | event && | evt | ) |

inline

Move constructor.

Parameters

  evt | The event to move.

## Member Function Documentation

## operator=() [1/3]

event & mqtt::event::operator= | ( | event_type | evt | ) |

inline

Assignment from an event type variant.

Parameters

  evt | The event type variant.

Returns
  A reference to this object.

## operator=() [2/3]

event & mqtt::event::operator= | ( | const event & | rhs | ) |

inline

Copy assignment.

Parameters

  rhs | The event to copy.

Returns
  A reference to this object.

## operator=() [3/3]

event & mqtt::event::operator= | ( | event && | rhs | ) |

inline

Move assignment.

Parameters

  rhs | The event to move.

Returns
  A reference to this object.

## is_message()

bool mqtt::event::is_message | ( |  | ) | const

inline

Determines if this event is an incoming message.

Returns
  true if this event is an incoming message, false otherwise.

## is_connected()

bool mqtt::event::is_connected | ( |  | ) | const

inline

Determines if this event is a client (re)connection.

Returns
  true if this event is a client connection, false otherwise.

## is_connection_lost()

bool mqtt::event::is_connection_lost | ( |  | ) | const

inline

Determines if this event is a client connection lost.

Returns
  true if this event is a client connection lost, false otherwise.

## is_disconnected()

bool mqtt::event::is_disconnected | ( |  | ) | const

inline

Determines if this event is a client disconnected.

Returns
  true if this event is a client disconnected, false otherwise.

## is_shutdown()

bool mqtt::event::is_shutdown | ( |  | ) | const

inline

Determines if this event is an internal shutdown request.

Returns
  true if this event is a shutdown request, false otherwise.

## is_any_disconnect()

bool mqtt::event::is_any_disconnect | ( |  | ) | const

inline

Determines if this is any type of client disconnect or shutdown.

Returns
  true if this event is any type of client disconnect such as a 'connection lost', 'disconnected', or shutdown event.

## get_message()

const_message_ptr mqtt::event::get_message | ( |  | ) |

inline

Gets the message from the event, iff this is a message event.

Returns
  A message pointer, if this is a message event.

Exceptions

  std::bad_variant_access | if this is not a 'message' event.

## get_disconnected()

disconnected_event mqtt::event::get_disconnected | ( |  | ) |

inline

Gets the underlying information for a disconnected event iff this is a 'disconnected' event. This contains the reason code and properties that the server sent in the DISCONNECT packet.

Returns
  The disconnected event object containing information about why the server disconnected.

Exceptions

  std::bad_variant_access | if this is not a 'disconnected' event.

## get_message_if()

constexpr std::add_pointer_t< const_message_ptr > mqtt::event::get_message_if | ( |  | ) |

inline constexpr noexcept

Gets a pointer to the message in the event, iff this is a message event.

Returns
  A pointer to a message pointer, if this is a message event. Returns nulltr if this is not a message event.

## get_disconnected_if()

constexpr std::add_pointer_t< disconnected_event > mqtt::event::get_disconnected_if | ( |  | ) |

inline constexpr noexcept

Gets a pointer the underlying information for a disconnected event, iff this is a 'disconnected' event. This contains the reason code and properties that the server sent in the DISCONNECT packet.

Returns
  The disconnected event object containing information about why the server disconnected.

Exceptions

  std::bad_variant_access | if this is not a 'disconnected' event.

The documentation for this class was generated from the following file:

- event.h