Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MQTTSNGWAggregater.cpp
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 #include "MQTTSNGWAggregater.h" 00017 #include "MQTTSNGateway.h" 00018 #include "MQTTSNGWClient.h" 00019 #include "MQTTSNGWAdapter.h" 00020 #include "MQTTSNGWAdapterManager.h" 00021 #include "MQTTSNGWMessageIdTable.h" 00022 #include "MQTTSNGWTopic.h" 00023 #include <stdio.h> 00024 #include <string.h> 00025 #include <string> 00026 00027 using namespace MQTTSNGW; 00028 00029 Aggregater::Aggregater(Gateway* gw) : Adapter(gw) 00030 { 00031 _gateway = gw; 00032 } 00033 00034 Aggregater::~Aggregater(void) 00035 { 00036 00037 } 00038 00039 void Aggregater::initialize(void) 00040 { 00041 char param[MQTTSNGW_PARAM_MAX]; 00042 00043 if (_gateway->getParam("AggregatingGateway", param) == 0 ) 00044 { 00045 if (!strcasecmp(param, "YES") ) 00046 { 00047 /* Create Aggregated Clients */ 00048 _gateway->getClientList()->setClientList(AGGREGATER_TYPE); 00049 00050 string name = _gateway->getGWParams()->gatewayName; 00051 setup(name.c_str(), Atype_Aggregater); 00052 _isActive = true; 00053 } 00054 } 00055 00056 //testMessageIdTable(); 00057 00058 } 00059 00060 bool Aggregater::isActive(void) 00061 { 00062 return _isActive; 00063 } 00064 00065 uint16_t Aggregater::msgId(void) 00066 { 00067 return Adapter::getSecureClient()->getNextPacketId(); 00068 } 00069 00070 Client* Aggregater::convertClient(uint16_t msgId, uint16_t* clientMsgId) 00071 { 00072 return _msgIdTable.getClientMsgId(msgId, clientMsgId); 00073 } 00074 00075 00076 uint16_t Aggregater::addMessageIdTable(Client* client, uint16_t msgId) 00077 { 00078 /* set Non secure client`s nextMsgId. otherwise Id is duplicated.*/ 00079 00080 MessageIdElement* elm = _msgIdTable.add(this, client, msgId); 00081 if ( elm == nullptr ) 00082 { 00083 return 0; 00084 } 00085 else 00086 { 00087 return elm->_msgId; 00088 } 00089 } 00090 00091 uint16_t Aggregater::getMsgId(Client* client, uint16_t clientMsgId) 00092 { 00093 return _msgIdTable.getMsgId(client, clientMsgId); 00094 } 00095 00096 void Aggregater::removeAggregateTopic(Topic* topic, Client* client) 00097 { 00098 // ToDo: AggregateGW this method called when the client disconnect and erase it`s Topics. this method call */ 00099 } 00100 00101 void Aggregater::removeAggregateTopicList(Topics* topics, Client* client) 00102 { 00103 // ToDo: AggregateGW this method called when the client disconnect and erase it`s Topics. this method call */ 00104 } 00105 00106 int Aggregater::addAggregateTopic(Topic* topic, Client* client) 00107 { 00108 // ToDo: AggregateGW */ 00109 return 0; 00110 } 00111 00112 AggregateTopicElement* Aggregater::createClientList(Topic* topic) 00113 { 00114 // ToDo: AggregateGW */ 00115 return 0; 00116 } 00117 00118 bool Aggregater::testMessageIdTable(void) 00119 { 00120 Client* client = new Client(); 00121 uint16_t msgId = 0; 00122 00123 printf("msgId=%d\n", addMessageIdTable(client,1)); 00124 printf("msgId=%d\n", addMessageIdTable(client,2)); 00125 printf("msgId=%d\n", addMessageIdTable(client,3)); 00126 printf("msgId=%d\n", addMessageIdTable(client,1)); 00127 printf("msgId=%d\n", addMessageIdTable(client,2)); 00128 printf("msgId=%d\n", addMessageIdTable(client,3)); 00129 printf("msgId=%d\n", addMessageIdTable(client,4)); 00130 printf("msgId=%d\n", addMessageIdTable(client,4)); 00131 printf("msgId=%d\n", addMessageIdTable(client,4)); 00132 00133 convertClient(1,&msgId); 00134 printf("msgId=%d\n",msgId); 00135 convertClient(2,&msgId); 00136 printf("msgId=%d\n",msgId); 00137 convertClient(5,&msgId); 00138 printf("msgId=%d\n",msgId); 00139 convertClient(4,&msgId); 00140 printf("msgId=%d\n",msgId); 00141 convertClient(3,&msgId); 00142 printf("msgId=%d\n",msgId); 00143 return true; 00144 } 00145
Generated on Wed Jul 13 2022 10:46:02 by
1.7.2