Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSNGWAggregateTopicTable.h Source File

MQTTSNGWAggregateTopicTable.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_MQTTSNGWAGGREGATETOPICTABLE_H_
00018 #define MQTTSNGATEWAY_SRC_MQTTSNGWAGGREGATETOPICTABLE_H_
00019 
00020 #include "MQTTSNGWDefines.h"
00021 #include "MQTTSNGWProcess.h"
00022 #include <stdint.h>
00023 namespace MQTTSNGW
00024 {
00025 
00026 class Client;
00027 class Topic;
00028 class AggregateTopicElement;
00029 class ClientTopicElement;
00030 class Mutex;
00031 
00032 /*=====================================
00033  Class AggregateTopicTable
00034  ======================================*/
00035 class AggregateTopicTable
00036 {
00037 public:
00038     AggregateTopicTable();
00039     ~AggregateTopicTable();
00040 
00041     AggregateTopicElement* add(Topic* topic, Client* client);
00042     AggregateTopicElement* getClientList(Topic* client);
00043     void remove(Topic* topic, Client* client);
00044     void clear(void);
00045 private:
00046     AggregateTopicElement* _head {nullptr};
00047     AggregateTopicElement* _tail {nullptr};
00048     int _cnt {0};
00049     int _maxSize {MAX_MESSAGEID_TABLE_SIZE};
00050 };
00051 
00052 /*=====================================
00053  Class AggregateTopicElement
00054  =====================================*/
00055 class AggregateTopicElement
00056 {
00057     friend class AggregateTopicTable;
00058 public:
00059     AggregateTopicElement(void);
00060     AggregateTopicElement(Topic* topic, Client* client);
00061     ~AggregateTopicElement(void);
00062 
00063     ClientTopicElement* add(Client* client);
00064     ClientTopicElement* getFirstElement(void);
00065     ClientTopicElement* getNextElement(ClientTopicElement* elm);
00066     void erase(ClientTopicElement* elm);
00067     ClientTopicElement* find(Client* client);
00068 
00069 private:
00070     Mutex _mutex;
00071     Topic* _topic {nullptr};
00072     ClientTopicElement* _head {nullptr};
00073     ClientTopicElement* _tail {nullptr};
00074 };
00075 
00076 /*=====================================
00077  Class ClientTopicElement
00078  =====================================*/
00079 class ClientTopicElement
00080 {
00081     friend class AggregateTopicTable;
00082     friend class AggregateTopicElement;
00083 public:
00084     ClientTopicElement(Client* client);
00085     ~ClientTopicElement(void);
00086     Client* getClient(void);
00087 
00088 private:
00089     Client* _client {nullptr};
00090     ClientTopicElement* _next {nullptr};
00091     ClientTopicElement* _prev {nullptr};
00092 };
00093 
00094 }
00095 
00096 
00097 
00098 #endif /* MQTTSNGATEWAY_SRC_MQTTSNGWAGGREGATETOPICTABLE_H_ */