Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LTopicTable.h Source File

LTopicTable.h

00001 /**************************************************************************************
00002  * Copyright (c) 2016, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
00015  **************************************************************************************/
00016 
00017 #ifndef TOPICTABLE_H_
00018 #define TOPICTABLE_H_
00019 
00020 #include <stdio.h>
00021 
00022 #include "LMqttsnClientApp.h"
00023 #include "Payload.h"
00024 
00025 #define MQTTSN_TOPIC_MULTI_WILDCARD   1
00026 #define MQTTSN_TOPIC_SINGLE_WILDCARD  2
00027 
00028 namespace linuxAsyncClient {
00029 /*=====================================
00030         Class LTopic
00031  ======================================*/
00032 typedef int (*TopicCallback)(uint8_t*, uint16_t);
00033 
00034 class LTopic {
00035     friend class LTopicTable;
00036 public:
00037     LTopic();
00038     ~LTopic();
00039     int      execCallback(uint8_t* payload, uint16_t payloadlen);
00040     uint8_t  hasWildCard(uint8_t* pos);
00041     bool     isMatch(const char* topic);
00042     TopicCallback getCallback(void);
00043 private:
00044     uint16_t  _topicId;
00045     MQTTSN_topicTypes   _topicType;
00046     char*     _topicStr;
00047     TopicCallback  _callback;
00048     uint8_t  _malocFlg;
00049     LTopic*    _prev;
00050     LTopic*    _next;
00051 };
00052 
00053 /*=====================================
00054         Class LTopicTable
00055  ======================================*/
00056 class LTopicTable {
00057 public:
00058     LTopicTable();
00059       ~LTopicTable();
00060       uint16_t getTopicId(const char* topic);
00061       char*    getTopicName(LTopic* topic);
00062       LTopic*   getTopic(const char* topic);
00063       LTopic*   getTopic(uint16_t topicId, MQTTSN_topicTypes topicType);
00064       void     setTopicId(const char* topic, uint16_t id, MQTTSN_topicTypes topicType);
00065       bool     setCallback(const char* topic, TopicCallback callback);
00066       bool     setCallback(uint16_t topicId, MQTTSN_topicTypes type, TopicCallback callback);
00067       int      execCallback(uint16_t topicId, uint8_t* payload, uint16_t payloadlen, MQTTSN_topicTypes topicType);
00068       LTopic*  add(const char* topic, MQTTSN_topicTypes type, uint16_t id = 0, TopicCallback callback = 0, uint8_t alocFlg = 0);
00069       //LTopic*  add(uint16_t topicId, uint16_t id, MQTTSN_topicTypes type, TopicCallback callback, uint8_t alocFlg);
00070       LTopic*  match(const char* topic);
00071       void     clearTopic(void);
00072       void     remove(uint16_t topicId, MQTTSN_topicTypes type);
00073 
00074 private:
00075     LTopic*  _first;
00076     LTopic*  _last;
00077 
00078 };
00079 
00080 } /* end of namespace */
00081 
00082 #endif /* TOPICTABLE_H_ */