Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-05-13 13:09:28 +09:00
parent ceaa3ab592
commit bb72c590c6
6 changed files with 34 additions and 23 deletions

View File

@@ -182,15 +182,14 @@ void Client::clearWaitedSubTopicId(void)
_waitedSubTopicIdMap.clear();
}
void Client::setWaitedPubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type)
void Client::setWaitedPubTopicId(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic)
{
_waitedPubTopicIdMap.add(msgId, topicId, type);
_waitedPubTopicIdMap.add(msgId, topicId, topic);
}
void Client::setWaitedSubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type)
void Client::setWaitedSubTopicId(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic)
{
_waitedSubTopicIdMap.add(msgId, topicId, type);
_waitedSubTopicIdMap.add(msgId, topicId, topic);
}
bool Client::checkTimeover(void)

View File

@@ -198,10 +198,8 @@ public:
int setClientSleepPacket(MQTTGWPacket*);
int setProxyPacket(MQTTSNPacket* packet);
void setWaitedPubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type);
void setWaitedSubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type);
void setWaitedPubTopicId(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic);
void setWaitedSubTopicId(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic);
bool checkTimeover(void);
void updateStatus(MQTTSNPacket*);

View File

@@ -126,7 +126,7 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client,
/* Save a msgId & a TopicId pare for PUBACK */
if (msgId && qos > 0 && qos < 3)
{
client->setWaitedPubTopicId(msgId, topicid.data.id, topicid.type);
client->setWaitedPubTopicId(msgId, topicid.data.id, &topicid);
}
pub.payload = (char*) payload;

View File

@@ -111,7 +111,7 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client,
subscribe->setSUBSCRIBE(topicstr, (uint8_t) qos, (uint16_t) msgId);
}
client->setWaitedSubTopicId(msgId, topicId, topicFilter.type);
client->setWaitedSubTopicId(msgId, topicId, &topicFilter);
if (!client->isAggregated())
{

View File

@@ -397,14 +397,22 @@ uint8_t Topics::getCount(void)
/*=====================================
Class TopicIdMap
=====================================*/
TopicIdMapElement::TopicIdMapElement(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type)
TopicIdMapElement::TopicIdMapElement(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic)
{
_msgId = msgId;
_topicId = topicId;
_type = type;
_type = topic->type;
_wildcard = 0;
_next = nullptr;
_prev = nullptr;
if (_type == MQTTSN_TOPIC_TYPE_NORMAL)
{
if ( strchr(topic->data.long_.name, '*') != 0 || strchr(topic->data.long_.name, '+') != 0 )
{
_wildcard = 1;
}
}
}
TopicIdMapElement::~TopicIdMapElement()
@@ -419,7 +427,14 @@ MQTTSN_topicTypes TopicIdMapElement::getTopicType(void)
uint16_t TopicIdMapElement::getTopicId(void)
{
return _topicId;
if (_wildcard > 0)
{
return 0;
}
else
{
return _topicId;
}
}
TopicIdMap::TopicIdMap()
@@ -456,11 +471,10 @@ TopicIdMapElement* TopicIdMap::getElement(uint16_t msgId)
return 0;
}
TopicIdMapElement* TopicIdMap::add(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type)
TopicIdMapElement* TopicIdMap::add(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic)
{
if (_cnt > _maxInflight * 2
|| (topicId == 0 && type != MQTTSN_TOPIC_TYPE_SHORT))
|| (topicId == 0 && topic->type != MQTTSN_TOPIC_TYPE_SHORT))
{
return 0;
}
@@ -469,7 +483,7 @@ TopicIdMapElement* TopicIdMap::add(uint16_t msgId, uint16_t topicId,
erase(msgId);
}
TopicIdMapElement* elm = new TopicIdMapElement(msgId, topicId, type);
TopicIdMapElement* elm = new TopicIdMapElement(msgId, topicId, topic);
if (elm == 0)
{
return 0;

View File

@@ -81,7 +81,7 @@ class TopicIdMapElement
{
friend class TopicIdMap;
public:
TopicIdMapElement(uint16_t msgId, uint16_t topicId, MQTTSN_topicTypes type);
TopicIdMapElement(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic);
~TopicIdMapElement();
MQTTSN_topicTypes getTopicType(void);
uint16_t getTopicId(void);
@@ -89,6 +89,7 @@ public:
private:
uint16_t _msgId;
uint16_t _topicId;
uint8_t _wildcard;
MQTTSN_topicTypes _type;
TopicIdMapElement* _next;
TopicIdMapElement* _prev;
@@ -100,8 +101,7 @@ public:
TopicIdMap();
~TopicIdMap();
TopicIdMapElement* getElement(uint16_t msgId);
TopicIdMapElement* add(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type);
TopicIdMapElement* add(uint16_t msgId, uint16_t topicId, MQTTSN_topicid* topic);
void erase(uint16_t msgId);
void clear(void);
private: