David Fletcher / server

Dependents:   mqtt_V1 cc3100_Test_mqtt_CM3

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers server_plug.h Source File

server_plug.h

00001 /******************************************************************************
00002 *
00003 *   Copyright (C) 2014 Texas Instruments Incorporated
00004 *
00005 *   All rights reserved. Property of Texas Instruments Incorporated.
00006 *   Restricted rights to use, duplicate or disclose this code are
00007 *   granted through contract.
00008 *
00009 *   The program may not be used without the written permission of
00010 *   Texas Instruments Incorporated or against the terms and conditions
00011 *   stipulated in the agreement under which this program has been supplied,
00012 *   and under no circumstances can it be used with non-TI connectivity device.
00013 *
00014 ******************************************************************************/
00015 
00016 #ifndef __SERVER_PLUG_H__
00017 #define __SERVER_PLUG_H__
00018 
00019 #include "server_pkts.h"
00020 
00021 #ifdef __cplusplus
00022 extern "C"
00023 {
00024 #endif
00025 
00026 namespace mbed_mqtt {
00027 
00028 /* Used by Server Core Logic */
00029 
00030 #define PG_MAP_BITS_SIZE     2
00031 #define PG_MAP_BITS_MASK     ((1 << PG_MAP_BITS_SIZE) - 1)
00032 #define PG_MAP_MAX_ELEMS     4  /* should be able accomodate in 1 byte */
00033 #define PG_MAP_ALL_DFLTS     ((1 << (PG_MAP_BITS_SIZE * PG_MAP_MAX_ELEMS)) - 1)
00034 
00035 #define PG_MAP_HAS_VALUE(pg_map, index)                 \
00036         (((~pg_map) >> (index * PG_MAP_BITS_SIZE)) & PG_MAP_BITS_MASK)
00037 
00038 #define PG_MAP_VAL_SETUP(pg_map, qid, index)                            \
00039         {                                                               \
00040                 uint32_t ofst = index * PG_MAP_BITS_SIZE;                    \
00041                 pg_map  &= ~(PG_MAP_BITS_MASK << ofst);                 \
00042                 pg_map  |= qid << ofst;                                 \
00043         }
00044 
00045 #define PG_MAP_VAL_RESET(pg_map, index)                                 \
00046         pg_map |= PG_MAP_BITS_MASK << (index * PG_MAP_BITS_SIZE);
00047 
00048 #if (PG_MAP_BITS_MASK != QID_VMASK)
00049 #error "PG_MAP_BITS_MASK must be same as 2bit QOS_VMASK"
00050 #endif
00051 
00052 #if ((PG_MAP_MAX_ELEMS * PG_MAP_BITS_SIZE) > 8)
00053 #error "Make size-of pg_map greate than 1 byte"
00054 #endif
00055 
00056 struct plugin_core_msg_cbs {
00057 
00058         int32_t (*topic_enroll)(uint8_t pg_id, const struct utf8_string *topic,
00059                             enum mqtt_qos qos);
00060         int32_t (*topic_cancel)(uint8_t pg_id, const struct utf8_string *topic);
00061         int32_t (*publish)(const struct utf8_string *topic,    const uint8_t *data_buf,
00062                        uint32_t data_len, enum mqtt_qos qos, bool retain);
00063 };
00064 
00065 int32_t plugin_init(const struct plugin_core_msg_cbs *cbs);
00066 
00067 /* uint16_t composition: MSB is CONNACK-Flags = 0, LSB is CONNACK-RC */
00068 uint16_t plugin_connect(const struct utf8_string *clientId, 
00069                    const struct utf8_string *username,
00070                    const struct utf8_string *password,
00071                    void **app_usr);
00072 
00073 int32_t plugin_publish(uint8_t pg_map, const struct utf8_string *topic,
00074                    const uint8_t *payload, uint32_t pay_len,
00075                    bool dup, uint8_t qos, bool retain);
00076 
00077 int32_t plugin_disconn(const void *app_usr, bool due2err);
00078 
00079 }//namespace mbed_mqtt 
00080 
00081 #ifdef __cplusplus  
00082 }
00083 #endif 
00084 
00085 #endif
00086 
00087