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

    1: #ifndef __AITMQTT_H
    2: #define __AITMQTT_H
    3: 
    4: 
    5: #define MQTT_DATA_MAX		268435455
    6: 
    7: struct mqtthdr {
    8: 	unsigned char	mqtt_retain : 1, 
    9: 			mqtt_qos : 2,
   10: 			mqtt_dup : 1,
   11: 			mqtt_type : 4;
   12: 	unsigned char	mqtt_len;
   13: };
   14: 
   15: #define MQTT_TYPE_UNKNOWN	0	/* reserved */
   16: #define MQTT_TYPE_CONNECT	1	/* client request to connect to server */
   17: #define MQTT_TYPE_CONNACK	2	/* connect acknowledgment */
   18: #define MQTT_TYPE_PUBLISH	3	/* publish message */
   19: #define MQTT_TYPE_PUBACK	4	/* publish acknowledgment */
   20: #define MQTT_TYPE_PUBREC	5	/* publish received (assured delivery part 1) */
   21: #define MQTT_TYPE_PUBREL	6	/* publish release (assured delivery part 2) */
   22: #define MQTT_TYPE_PUBCOMP	7	/* publish complete (assured delivery part 3) */
   23: #define MQTT_TYPE_SUBSCRIBE	8	/* client subscribe request */
   24: #define MQTT_TYPE_SUBACK	9	/* subscribe acknowledgment */
   25: #define MQTT_TYPE_UNSUBSCRIBE	10	/* client unsubscribe request */
   26: #define MQTT_TYPE_UNSUBACK	11	/* unsubscribe acknowledgment */
   27: #define MQTT_TYPE_PINGREQ	12	/* PING request */
   28: #define MQTT_TYPE_PINGRESP	13	/* PING response */
   29: #define MQTT_TYPE_DISCONNECT	14	/* client is disconnecting */
   30: #define MQTT_TYPE_RESERVED	15	/* reserved */
   31: 
   32: #define MQTT_FLAG_DUP		1	/* This flag is set when the client or server attempts to re-deliver 
   33: 					   a PUBLISH, PUBREL, SUBSCRIBE or UNSUBSCRIBE message. 
   34: 					   This applies to messages where the value of QoS is greater than 
   35: 					   zero (0), and an acknowledgment is required. 
   36: 					   When the DUP bit is set, the variable header includes a Message ID.
   37: 
   38: 					   The recipient should treat this flag as a hint as to whether 
   39: 					   the message may have been previously received. 
   40: 					   It should not be relied on to detect duplicates. */
   41: 
   42: #define MQTT_QOS_ONCE		0	/* At most once, Fire and Forget, <=1 */
   43: #define MQTT_QOS_ACK		1	/* At least once, Acknowledged delivery, >=1 */
   44: #define MQTT_QOS_EXACTLY	2	/* Exactly once, Assured delivery, =1 */
   45: #define MQTT_QOS_RESERVED	3	/* reserved */
   46: 
   47: #define MQTT_FLAG_RETAIN	1	/* This flag is only used on PUBLISH messages.
   48: 
   49: 					   When a client sends a PUBLISH to a server, 
   50: 					   if the Retain flag is set (1), 
   51: 					   the server should hold on to the message after it has been 
   52: 					   delivered to the current subscribers.
   53: 					   When a new subscription is established on a topic, 
   54: 					   the last retained message on that topic should be sent to 
   55: 					   the subscriber with the Retain flag set.
   56: 					   If there is no retained message, nothing is sent
   57: 					   This is useful where publishers send messages on a 
   58: 					   "report by exception" basis, where it might be some time between messages. 
   59: 					   This allows new subscribers to instantly receive data with the retained, 
   60: 					   or Last Known Good, value.
   61: 
   62: 					   When a server sends a PUBLISH to a client as a result of 
   63: 					   a subscription that already existed when the original PUBLISH arrived, 
   64: 					   the Retain flag should not be set, regardless of the Retain flag 
   65: 					   of the original PUBLISH. This allows a client to distinguish messages 
   66: 					   that are being received because they were retained and those 
   67: 					   that are being received "live".
   68: 
   69: 					   Retained messages should be kept over restarts of the server.
   70: 					   A server may delete a retained message if it receives a message 
   71: 					   with a zero-length payload and the Retain flag set on the same topic. */
   72: 
   73: 
   74: // -------------------------------------------------------
   75: // mqtt_GetErrno() Get error code of last operation
   76: inline int mqtt_GetErrno();
   77: // mqtt_GetError() Get error text of last operation
   78: inline const char *mqtt_GetError();
   79: // -------------------------------------------------------
   80: 
   81: 
   82: /*
   83:  * mqtt_encodeLen() Encode number to MQTT length field
   84:  * @num = number for encode
   85:  * return: -1 error or >-1 length
   86:  */
   87: inline unsigned int mqtt_encodeLen(unsigned int num);
   88: /*
   89:  * mqtt_decodeLen() Decode length from MQTT packet
   90:  * @len = length
   91:  * @n = sizeof bytes, if !=NULL
   92:  * return: -1 error, >-1 length of message
   93:  */
   94: inline unsigned int mqtt_decodeLen(unsigned int len, char *n);
   95: /*
   96:  * mqtt_sizeLen Return sizeof len field
   97:  * @len = length
   98:  * return: -1 error, >-1 sizeof len in bytes
   99:  */
  100: inline char mqtt_sizeLen(unsigned int len);
  101: 
  102: 
  103: #endif

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