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.
MQTTGWSubscribeHandler.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 00017 #include "MQTTGWSubscribeHandler.h" 00018 #include "MQTTGWPacket.h" 00019 00020 using namespace std; 00021 using namespace MQTTSNGW; 00022 00023 MQTTGWSubscribeHandler::MQTTGWSubscribeHandler(Gateway* gateway) 00024 { 00025 _gateway = gateway; 00026 } 00027 00028 MQTTGWSubscribeHandler::~MQTTGWSubscribeHandler() 00029 { 00030 00031 } 00032 00033 void MQTTGWSubscribeHandler::handleSuback(Client* client, MQTTGWPacket* packet) 00034 { 00035 uint16_t msgId; 00036 uint8_t rc; 00037 uint8_t returnCode; 00038 int qos = 0; 00039 00040 packet->getSUBACK(&msgId, &rc); 00041 TopicIdMapElement* topicId = client->getWaitedSubTopicId(msgId); 00042 00043 if (topicId) 00044 { 00045 MQTTSNPacket* snPacket = new MQTTSNPacket(); 00046 00047 if (rc == 0x80) 00048 { 00049 returnCode = MQTTSN_RC_REJECTED_INVALID_TOPIC_ID; 00050 } 00051 else 00052 { 00053 returnCode = MQTTSN_RC_ACCEPTED; 00054 qos = rc; 00055 } 00056 snPacket->setSUBACK(qos, topicId->getTopicId(), msgId, returnCode); 00057 Event* evt = new Event(); 00058 evt->setClientSendEvent(client, snPacket); 00059 _gateway->getClientSendQue()->post(evt); 00060 client->eraseWaitedSubTopicId(msgId); 00061 } 00062 } 00063 00064 void MQTTGWSubscribeHandler::handleUnsuback(Client* client, MQTTGWPacket* packet) 00065 { 00066 Ack ack; 00067 packet->getAck(&ack); 00068 MQTTSNPacket* snPacket = new MQTTSNPacket(); 00069 snPacket->setUNSUBACK(ack.msgId); 00070 Event* evt = new Event(); 00071 evt->setClientSendEvent(client, snPacket); 00072 _gateway->getClientSendQue()->post(evt); 00073 } 00074 00075 void MQTTGWSubscribeHandler::handleAggregateSuback(Client* client, MQTTGWPacket* packet) 00076 { 00077 uint16_t msgId = packet->getMsgId(); 00078 uint16_t clientMsgId = 0; 00079 Client* newClient = _gateway->getAdapterManager()->getAggregater()->convertClient(msgId, &clientMsgId); 00080 if ( newClient != nullptr ) 00081 { 00082 packet->setMsgId((int)clientMsgId); 00083 handleSuback(newClient, packet); 00084 } 00085 } 00086 00087 void MQTTGWSubscribeHandler::handleAggregateUnsuback(Client* client, MQTTGWPacket* packet) 00088 { 00089 uint16_t msgId = packet->getMsgId(); 00090 uint16_t clientMsgId = 0; 00091 Client* newClient = _gateway->getAdapterManager()->getAggregater()->convertClient(msgId, &clientMsgId); 00092 if ( newClient != nullptr ) 00093 { 00094 packet->setMsgId((int)clientMsgId); 00095 handleUnsuback(newClient, packet); 00096 } 00097 } 00098 00099
Generated on Wed Jul 13 2022 10:46:02 by
1.7.2