File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / inc / Attic / aitmqtt.h
Revision 1.1.1.1.2.1: download - view: text, annotated - select for diffs - revision graph
Mon Nov 7 13:34:06 2011 UTC (12 years, 7 months ago) by misho
Branches: mqtt1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
commit

#ifndef __AITMQTT_H
#define __AITMQTT_H


struct mqtthdr {
	unsigned char	mqtt_retain : 1, 
			mqtt_qos : 2,
			mqtt_dup : 1,
			mqtt_type : 4;
	unsigned char	mqtt_len;
};

#define MQTT_TYPE_UNKNOWN	0	/* reserved */
#define MQTT_TYPE_CONNECT	1	/* client request to connect to server */
#define MQTT_TYPE_CONNACK	2	/* connect acknowledgment */
#define MQTT_TYPE_PUBLISH	3	/* publish message */
#define MQTT_TYPE_PUBACK	4	/* publish acknowledgment */
#define MQTT_TYPE_PUBREC	5	/* publish received (assured delivery part 1) */
#define MQTT_TYPE_PUBREL	6	/* publish release (assured delivery part 2) */
#define MQTT_TYPE_PUBCOMP	7	/* publish complete (assured delivery part 3) */
#define MQTT_TYPE_SUBSCRIBE	8	/* client subscribe request */
#define MQTT_TYPE_SUBACK	9	/* subscribe acknowledgment */
#define MQTT_TYPE_UNSUBSCRIBE	10	/* client unsubscribe request */
#define MQTT_TYPE_UNSUBACK	11	/* unsubscribe acknowledgment */
#define MQTT_TYPE_PINGREQ	12	/* PING request */
#define MQTT_TYPE_PINGRESP	13	/* PING response */
#define MQTT_TYPE_DISCONNECT	14	/* client is disconnecting */
#define MQTT_TYPE_RESERVED	15	/* reserved */

#define MQTT_FLAG_DUP		1	/* This flag is set when the client or server attempts to re-deliver 
					   a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message. 
					   This applies to messages where the value of QoS is greater than 
					   zero (0), and an acknowledgment is required. 
					   When the DUP bit is set, the variable header includes a Message ID.

					   The recipient should treat this flag as a hint as to whether 
					   the message may have been previously received. 
					   It should not be relied on to detect duplicates. */

#define MQTT_QOS_ONCE		0	/* At most once, Fire and Forget, <=1 */
#define MQTT_QOS_ACK		1	/* At least once, Acknowledged delivery, >=1 */
#define MQTT_QOS_EXACTLY	2	/* Exactly once, Assured delivery, =1 */
#define MQTT_QOS_RESERVED	3	/* reserved */

#define MQTT_FLAG_RETAIN	1	/* This flag is only used on PUBLISH messages.

					   When a client sends a PUBLISH to a server, 
					   if the Retain flag is set (1), 
					   the server should hold on to the message after it has been 
					   delivered to the current subscribers.
					   When a new subscription is established on a topic, 
					   the last retained message on that topic should be sent to 
					   the subscriber with the Retain flag set.
					   If there is no retained message, nothing is sent
					   This is useful where publishers send messages on a 
					   "report by exception" basis, where it might be some time between messages. 
					   This allows new subscribers to instantly receive data with the retained, 
					   or Last Known Good, value.

					   When a server sends a PUBLISH to a client as a result of 
					   a subscription that already existed when the original PUBLISH arrived, 
					   the Retain flag should not be set, regardless of the Retain flag 
					   of the original PUBLISH. This allows a client to distinguish messages 
					   that are being received because they were retained and those 
					   that are being received "live".

					   Retained messages should be kept over restarts of the server.
					   A server may delete a retained message if it receives a message 
					   with a zero-length payload and the Retain flag set on the same topic. */


// -------------------------------------------------------
// mqtt_GetErrno() Get error code of last operation
inline int mqtt_GetErrno();
// mqtt_GetError() Get error text of last operation
inline const char *mqtt_GetError();
// -------------------------------------------------------


/*
 * mqtt_encodeLen() Encode number to MQTT length field
 * @num = number for encode
 * return: -1 error or >-1 length
 */
inline unsigned int mqtt_encodeLen(unsigned int num);
/*
 * mqtt_decodeLen() Decode length from MQTT packet
 * @len = length
 * return: -1 error, >-1 length of message
 */
inline unsigned int mqtt_decodeLen(unsigned int len);


#endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>