acl/lib_acl_cpp/include/acl_cpp/mqtt/mqtt_connack.hpp

101 lines
1.9 KiB
C++
Raw Normal View History

2021-03-02 11:31:24 +08:00
#pragma once
#include "mqtt_message.hpp"
namespace acl {
/**
* the status of connection.
*/
2021-03-02 16:39:06 +08:00
enum {
MQTT_CONNACK_OK = 0x00,
MQTT_CONNACK_ERR_VER = 0x01,
MQTT_CONNACK_ERR_CID = 0x02,
MQTT_CONNACK_ERR_SVR = 0x03,
MQTT_CONNACK_ERR_AUTH = 0x04,
MQTT_CONNACK_ERR_DENY = 0x05,
};
/**
* mqtt message object for the MQTT_CONNACK type.
*/
2021-03-07 12:45:22 +08:00
class ACL_CPP_API mqtt_connack : public mqtt_message {
2021-03-02 11:31:24 +08:00
public:
/**
* constructor for creating MQTT_CONNACK mqtt message object.
* @see mqtt_message
*/
2021-03-02 11:31:24 +08:00
mqtt_connack(void);
/**
* constructor for creating MQTT_CONNACK mqtt message object.
* @see mqtt_message
*/
2021-03-08 15:03:32 +08:00
mqtt_connack(const mqtt_header& header);
2021-03-02 11:31:24 +08:00
~mqtt_connack(void);
/**
* set the session control for the connection
* @param on {bool}
* @return {mqtt_connack&}
*/
mqtt_connack& set_session(bool on);
/**
* set the connect return code
* @param code {unsigned char} defined as MQTT_CONNACK_XXX above.
* @return {mqtt_connack&}
*/
mqtt_connack& set_connack_code(unsigned char code);
2021-03-02 16:39:06 +08:00
/**
* get the session control status
* @return {bool}
*/
2021-03-02 11:31:24 +08:00
bool get_session(void) const {
return session_;
}
/**
* get the connect resturn code
* @return {unsigned char} defined as MQTT_CONNACK_XXX above.
*/
2021-03-02 16:39:06 +08:00
unsigned char get_connack_code(void) const {
return connack_code_;
}
protected:
// @override
2021-03-02 16:39:06 +08:00
bool to_string(string& out);
// @override
int update(const char* data, int dlen);
2021-03-02 11:31:24 +08:00
// @override
bool finished(void) const {
return finished_;
}
2021-03-02 11:31:24 +08:00
public:
/**
* (internal) update mqtt header data for parsing mqtt data.
* @param data {const char*} the data to be parsed.
* @param dlen {int} the length of data.
* @return {int} return the length of the left data.
*/
int update_header_var(const char* data, int dlen);
2021-03-02 11:31:24 +08:00
private:
2021-03-08 15:03:32 +08:00
unsigned status_;
2021-03-02 11:31:24 +08:00
bool finished_;
char buff_[2];
int dlen_;
2021-03-02 11:31:24 +08:00
bool session_;
unsigned char conn_flags_;
2021-03-02 16:39:06 +08:00
unsigned char connack_code_;
2021-03-02 11:31:24 +08:00
};
} // namespace acl