Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSNGWMessageIdTable.h Source File

MQTTSNGWMessageIdTable.h

00001 /**************************************************************************************
00002  * Copyright (c) 2018, 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 MQTTSNGATEWAY_SRC_MQTTSNGWMESSAGEIDTABLE_H_
00018 #define MQTTSNGATEWAY_SRC_MQTTSNGWMESSAGEIDTABLE_H_
00019 
00020 #include "MQTTSNGWDefines.h"
00021 #include "MQTTSNGWProcess.h"
00022 
00023 #include <stdint.h>
00024 namespace MQTTSNGW
00025 {
00026 
00027 class Client;
00028 class MessageIdElement;
00029 class Meutex;
00030 class Aggregater;
00031 /*=====================================
00032  Class MessageIdTable
00033  ======================================*/
00034 class MessageIdTable
00035 {
00036 public:
00037     MessageIdTable();
00038     ~MessageIdTable();
00039 
00040     MessageIdElement* add(Aggregater* aggregater, Client* client, uint16_t clientMsgId);
00041     Client* getClientMsgId(uint16_t msgId, uint16_t* clientMsgId);
00042     uint16_t getMsgId(Client* client, uint16_t clientMsgId);
00043     void erase(uint16_t msgId);
00044     void clear(MessageIdElement* elm);
00045 private:
00046     MessageIdElement* find(uint16_t msgId);
00047     MessageIdElement* find(Client* client, uint16_t clientMsgId);
00048     MessageIdElement* _head {nullptr};
00049     MessageIdElement* _tail {nullptr};
00050     int _cnt {0};
00051     int _maxSize {MAX_MESSAGEID_TABLE_SIZE};
00052     Mutex _mutex;
00053 };
00054 
00055 /*=====================================
00056  Class MessageIdElement
00057  =====================================*/
00058 class MessageIdElement
00059 {
00060     friend class MessageIdTable;
00061     friend class Aggregater;
00062 public:
00063     MessageIdElement(void);
00064     MessageIdElement(uint16_t msgId, Client* client, uint16_t clientMsgId);
00065     ~MessageIdElement(void);
00066 
00067 private:
00068     uint16_t _msgId;
00069     uint16_t _clientMsgId;
00070     Client*  _client;
00071     MessageIdElement* _next;
00072     MessageIdElement* _prev;
00073 };
00074 
00075 
00076 }
00077 
00078 #endif /* MQTTSNGATEWAY_SRC_MQTTSNGWMESSAGEIDTABLE_H_ */