Part of TI's mqtt
Dependents: mqtt_V1 cc3100_Test_mqtt_CM3
server_plug.h@0:547251f42a60, 2015-06-06 (annotated)
- Committer:
- dflet
- Date:
- Sat Jun 06 13:29:08 2015 +0000
- Revision:
- 0:547251f42a60
Part of mqtt_V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:547251f42a60 | 1 | /****************************************************************************** |
dflet | 0:547251f42a60 | 2 | * |
dflet | 0:547251f42a60 | 3 | * Copyright (C) 2014 Texas Instruments Incorporated |
dflet | 0:547251f42a60 | 4 | * |
dflet | 0:547251f42a60 | 5 | * All rights reserved. Property of Texas Instruments Incorporated. |
dflet | 0:547251f42a60 | 6 | * Restricted rights to use, duplicate or disclose this code are |
dflet | 0:547251f42a60 | 7 | * granted through contract. |
dflet | 0:547251f42a60 | 8 | * |
dflet | 0:547251f42a60 | 9 | * The program may not be used without the written permission of |
dflet | 0:547251f42a60 | 10 | * Texas Instruments Incorporated or against the terms and conditions |
dflet | 0:547251f42a60 | 11 | * stipulated in the agreement under which this program has been supplied, |
dflet | 0:547251f42a60 | 12 | * and under no circumstances can it be used with non-TI connectivity device. |
dflet | 0:547251f42a60 | 13 | * |
dflet | 0:547251f42a60 | 14 | ******************************************************************************/ |
dflet | 0:547251f42a60 | 15 | |
dflet | 0:547251f42a60 | 16 | #ifndef __SERVER_PLUG_H__ |
dflet | 0:547251f42a60 | 17 | #define __SERVER_PLUG_H__ |
dflet | 0:547251f42a60 | 18 | |
dflet | 0:547251f42a60 | 19 | #include "server_pkts.h" |
dflet | 0:547251f42a60 | 20 | |
dflet | 0:547251f42a60 | 21 | #ifdef __cplusplus |
dflet | 0:547251f42a60 | 22 | extern "C" |
dflet | 0:547251f42a60 | 23 | { |
dflet | 0:547251f42a60 | 24 | #endif |
dflet | 0:547251f42a60 | 25 | |
dflet | 0:547251f42a60 | 26 | namespace mbed_mqtt { |
dflet | 0:547251f42a60 | 27 | |
dflet | 0:547251f42a60 | 28 | /* Used by Server Core Logic */ |
dflet | 0:547251f42a60 | 29 | |
dflet | 0:547251f42a60 | 30 | #define PG_MAP_BITS_SIZE 2 |
dflet | 0:547251f42a60 | 31 | #define PG_MAP_BITS_MASK ((1 << PG_MAP_BITS_SIZE) - 1) |
dflet | 0:547251f42a60 | 32 | #define PG_MAP_MAX_ELEMS 4 /* should be able accomodate in 1 byte */ |
dflet | 0:547251f42a60 | 33 | #define PG_MAP_ALL_DFLTS ((1 << (PG_MAP_BITS_SIZE * PG_MAP_MAX_ELEMS)) - 1) |
dflet | 0:547251f42a60 | 34 | |
dflet | 0:547251f42a60 | 35 | #define PG_MAP_HAS_VALUE(pg_map, index) \ |
dflet | 0:547251f42a60 | 36 | (((~pg_map) >> (index * PG_MAP_BITS_SIZE)) & PG_MAP_BITS_MASK) |
dflet | 0:547251f42a60 | 37 | |
dflet | 0:547251f42a60 | 38 | #define PG_MAP_VAL_SETUP(pg_map, qid, index) \ |
dflet | 0:547251f42a60 | 39 | { \ |
dflet | 0:547251f42a60 | 40 | uint32_t ofst = index * PG_MAP_BITS_SIZE; \ |
dflet | 0:547251f42a60 | 41 | pg_map &= ~(PG_MAP_BITS_MASK << ofst); \ |
dflet | 0:547251f42a60 | 42 | pg_map |= qid << ofst; \ |
dflet | 0:547251f42a60 | 43 | } |
dflet | 0:547251f42a60 | 44 | |
dflet | 0:547251f42a60 | 45 | #define PG_MAP_VAL_RESET(pg_map, index) \ |
dflet | 0:547251f42a60 | 46 | pg_map |= PG_MAP_BITS_MASK << (index * PG_MAP_BITS_SIZE); |
dflet | 0:547251f42a60 | 47 | |
dflet | 0:547251f42a60 | 48 | #if (PG_MAP_BITS_MASK != QID_VMASK) |
dflet | 0:547251f42a60 | 49 | #error "PG_MAP_BITS_MASK must be same as 2bit QOS_VMASK" |
dflet | 0:547251f42a60 | 50 | #endif |
dflet | 0:547251f42a60 | 51 | |
dflet | 0:547251f42a60 | 52 | #if ((PG_MAP_MAX_ELEMS * PG_MAP_BITS_SIZE) > 8) |
dflet | 0:547251f42a60 | 53 | #error "Make size-of pg_map greate than 1 byte" |
dflet | 0:547251f42a60 | 54 | #endif |
dflet | 0:547251f42a60 | 55 | |
dflet | 0:547251f42a60 | 56 | struct plugin_core_msg_cbs { |
dflet | 0:547251f42a60 | 57 | |
dflet | 0:547251f42a60 | 58 | int32_t (*topic_enroll)(uint8_t pg_id, const struct utf8_string *topic, |
dflet | 0:547251f42a60 | 59 | enum mqtt_qos qos); |
dflet | 0:547251f42a60 | 60 | int32_t (*topic_cancel)(uint8_t pg_id, const struct utf8_string *topic); |
dflet | 0:547251f42a60 | 61 | int32_t (*publish)(const struct utf8_string *topic, const uint8_t *data_buf, |
dflet | 0:547251f42a60 | 62 | uint32_t data_len, enum mqtt_qos qos, bool retain); |
dflet | 0:547251f42a60 | 63 | }; |
dflet | 0:547251f42a60 | 64 | |
dflet | 0:547251f42a60 | 65 | int32_t plugin_init(const struct plugin_core_msg_cbs *cbs); |
dflet | 0:547251f42a60 | 66 | |
dflet | 0:547251f42a60 | 67 | /* uint16_t composition: MSB is CONNACK-Flags = 0, LSB is CONNACK-RC */ |
dflet | 0:547251f42a60 | 68 | uint16_t plugin_connect(const struct utf8_string *clientId, |
dflet | 0:547251f42a60 | 69 | const struct utf8_string *username, |
dflet | 0:547251f42a60 | 70 | const struct utf8_string *password, |
dflet | 0:547251f42a60 | 71 | void **app_usr); |
dflet | 0:547251f42a60 | 72 | |
dflet | 0:547251f42a60 | 73 | int32_t plugin_publish(uint8_t pg_map, const struct utf8_string *topic, |
dflet | 0:547251f42a60 | 74 | const uint8_t *payload, uint32_t pay_len, |
dflet | 0:547251f42a60 | 75 | bool dup, uint8_t qos, bool retain); |
dflet | 0:547251f42a60 | 76 | |
dflet | 0:547251f42a60 | 77 | int32_t plugin_disconn(const void *app_usr, bool due2err); |
dflet | 0:547251f42a60 | 78 | |
dflet | 0:547251f42a60 | 79 | }//namespace mbed_mqtt |
dflet | 0:547251f42a60 | 80 | |
dflet | 0:547251f42a60 | 81 | #ifdef __cplusplus |
dflet | 0:547251f42a60 | 82 | } |
dflet | 0:547251f42a60 | 83 | #endif |
dflet | 0:547251f42a60 | 84 | |
dflet | 0:547251f42a60 | 85 | #endif |
dflet | 0:547251f42a60 | 86 | |
dflet | 0:547251f42a60 | 87 |