mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-17 01:16:52 +01:00
I think the architecture of the ble sensor network, which does not use threads per socket, can be applied to DTLS. Known bug: Occasionally a timeout error occurs when connecting to RFCOMM. BLE is not supported yet. I need help to do it. Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -40,7 +40,7 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
if (!client->isActive() && !client->isSleep() && !client->isAwake())
|
||||
{
|
||||
WRITELOG("%s The client is neither active nor sleep %s%s\n",
|
||||
ERRMSG_HEADER, client->getStatus(), ERRMSG_FOOTER);
|
||||
ERRMSG_HEADER, client->getStatus(), ERRMSG_FOOTER);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,9 +66,8 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
*msg = *packet;
|
||||
if (msg->getType() == 0)
|
||||
{
|
||||
WRITELOG(
|
||||
"%s MQTTGWPublishHandler::handlePublish can't allocate memories for Packet.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
WRITELOG("%s MQTTGWPublishHandler::handlePublish can't allocate memories for Packet.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
delete msg;
|
||||
return;
|
||||
}
|
||||
@@ -105,15 +104,14 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This message might be subscribed with wild card or not cleanSession*/
|
||||
/* This message might be subscribed with wild card or not cleanSession*/
|
||||
topicId.type = MQTTSN_TOPIC_TYPE_NORMAL;
|
||||
Topic* topic = client->getTopics()->match(&topicId);
|
||||
|
||||
if (topic == nullptr && client->isCleanSession())
|
||||
if (topic == nullptr && client->isCleanSession())
|
||||
{
|
||||
WRITELOG(
|
||||
"%sMQTTGWPublishHandler Invalid Topic. PUBLISH message is discarded.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
WRITELOG("%sMQTTGWPublishHandler Invalid Topic. PUBLISH message is discarded.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
if (pub.header.bits.qos == 1)
|
||||
{
|
||||
replyACK(client, &pub, PUBACK);
|
||||
@@ -127,20 +125,20 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
return;
|
||||
}
|
||||
|
||||
if (topic == nullptr)
|
||||
{
|
||||
topicId.type = MQTTSN_TOPIC_TYPE_NORMAL;
|
||||
topicId.data.long_.len = pub.topiclen;
|
||||
topicId.data.long_.name = pub.topic;
|
||||
topicId.data.id = 0;
|
||||
}
|
||||
if (topic == nullptr)
|
||||
{
|
||||
topicId.type = MQTTSN_TOPIC_TYPE_NORMAL;
|
||||
topicId.data.long_.len = pub.topiclen;
|
||||
topicId.data.long_.name = pub.topic;
|
||||
topicId.data.id = 0;
|
||||
}
|
||||
|
||||
/* add the Topic and get a TopicId */
|
||||
topic = client->getTopics()->add(&topicId);
|
||||
if (topic == nullptr)
|
||||
{
|
||||
WRITELOG(
|
||||
"%sMQTTGWPublishHandler Can't Add a Topic. MAX_TOPIC_PAR_CLIENT is exceeded. PUBLISH message is discarded.%s\n",
|
||||
WRITELOG(
|
||||
"%sMQTTGWPublishHandler Can't Add a Topic. MAX_TOPIC_PAR_CLIENT is exceeded. PUBLISH message is discarded.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
delete snPacket;
|
||||
return;
|
||||
@@ -165,29 +163,23 @@ void MQTTGWPublishHandler::handlePublish(Client* client, MQTTGWPacket* packet)
|
||||
|
||||
/* send PUBLISH */
|
||||
topicId.data.id = id;
|
||||
snPacket->setPUBLISH((uint8_t) pub.header.bits.dup,
|
||||
(int) pub.header.bits.qos,
|
||||
(uint8_t) pub.header.bits.retain, (uint16_t) pub.msgId,
|
||||
topicId, (uint8_t*) pub.payload, pub.payloadlen);
|
||||
client->getWaitREGACKPacketList()->setPacket(snPacket,
|
||||
regackMsgId);
|
||||
snPacket->setPUBLISH((uint8_t) pub.header.bits.dup, (int) pub.header.bits.qos, (uint8_t) pub.header.bits.retain,
|
||||
(uint16_t) pub.msgId, topicId, (uint8_t*) pub.payload, pub.payloadlen);
|
||||
client->getWaitREGACKPacketList()->setPacket(snPacket, regackMsgId);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITELOG(
|
||||
"%sMQTTGWPublishHandler Can't create a Topic. PUBLISH message is discarded.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
WRITELOG("%sMQTTGWPublishHandler Can't create a Topic. PUBLISH message is discarded.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
delete snPacket;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
snPacket->setPUBLISH((uint8_t) pub.header.bits.dup,
|
||||
(int) pub.header.bits.qos, (uint8_t) pub.header.bits.retain,
|
||||
(uint16_t) pub.msgId, topicId, (uint8_t*) pub.payload,
|
||||
pub.payloadlen);
|
||||
snPacket->setPUBLISH((uint8_t) pub.header.bits.dup, (int) pub.header.bits.qos, (uint8_t) pub.header.bits.retain,
|
||||
(uint16_t) pub.msgId, topicId, (uint8_t*) pub.payload, pub.payloadlen);
|
||||
Event* ev1 = new Event();
|
||||
ev1->setClientSendEvent(client, snPacket);
|
||||
_gateway->getClientSendQue()->post(ev1);
|
||||
@@ -207,8 +199,7 @@ void MQTTGWPublishHandler::handlePuback(Client* client, MQTTGWPacket* packet)
|
||||
{
|
||||
Ack ack;
|
||||
packet->getAck(&ack);
|
||||
TopicIdMapElement* topicId = client->getWaitedPubTopicId(
|
||||
(uint16_t) ack.msgId);
|
||||
TopicIdMapElement* topicId = client->getWaitedPubTopicId((uint16_t) ack.msgId);
|
||||
if (topicId)
|
||||
{
|
||||
MQTTSNPacket* mqttsnPacket = new MQTTSNPacket();
|
||||
@@ -220,13 +211,11 @@ void MQTTGWPublishHandler::handlePuback(Client* client, MQTTGWPacket* packet)
|
||||
_gateway->getClientSendQue()->post(ev1);
|
||||
return;
|
||||
}
|
||||
WRITELOG(
|
||||
" PUBACK from the Broker is invalid. PacketID : %04X ClientID : %s \n",
|
||||
(uint16_t) ack.msgId, client->getClientId());
|
||||
WRITELOG(" PUBACK from the Broker is invalid. PacketID : %04X ClientID : %s \n", (uint16_t) ack.msgId,
|
||||
client->getClientId());
|
||||
}
|
||||
|
||||
void MQTTGWPublishHandler::handleAck(Client* client, MQTTGWPacket* packet,
|
||||
int type)
|
||||
void MQTTGWPublishHandler::handleAck(Client* client, MQTTGWPacket* packet, int type)
|
||||
{
|
||||
Ack ack;
|
||||
packet->getAck(&ack);
|
||||
@@ -264,13 +253,11 @@ void MQTTGWPublishHandler::handleAck(Client* client, MQTTGWPacket* packet,
|
||||
}
|
||||
}
|
||||
|
||||
void MQTTGWPublishHandler::handleAggregatePuback(Client* client,
|
||||
MQTTGWPacket* packet)
|
||||
void MQTTGWPublishHandler::handleAggregatePuback(Client* client, MQTTGWPacket* packet)
|
||||
{
|
||||
uint16_t msgId = packet->getMsgId();
|
||||
uint16_t clientMsgId = 0;
|
||||
Client* newClient = _gateway->getAdapterManager()->convertClient(msgId,
|
||||
&clientMsgId);
|
||||
Client* newClient = _gateway->getAdapterManager()->convertClient(msgId, &clientMsgId);
|
||||
if (newClient != nullptr)
|
||||
{
|
||||
packet->setMsgId((int) clientMsgId);
|
||||
@@ -278,13 +265,11 @@ void MQTTGWPublishHandler::handleAggregatePuback(Client* client,
|
||||
}
|
||||
}
|
||||
|
||||
void MQTTGWPublishHandler::handleAggregateAck(Client* client,
|
||||
MQTTGWPacket* packet, int type)
|
||||
void MQTTGWPublishHandler::handleAggregateAck(Client* client, MQTTGWPacket* packet, int type)
|
||||
{
|
||||
uint16_t msgId = packet->getMsgId();
|
||||
uint16_t clientMsgId = 0;
|
||||
Client* newClient = _gateway->getAdapterManager()->convertClient(msgId,
|
||||
&clientMsgId);
|
||||
Client* newClient = _gateway->getAdapterManager()->convertClient(msgId, &clientMsgId);
|
||||
if (newClient != nullptr)
|
||||
{
|
||||
packet->setMsgId((int) clientMsgId);
|
||||
@@ -292,16 +277,14 @@ void MQTTGWPublishHandler::handleAggregateAck(Client* client,
|
||||
}
|
||||
}
|
||||
|
||||
void MQTTGWPublishHandler::handleAggregatePubrel(Client* client,
|
||||
MQTTGWPacket* packet)
|
||||
void MQTTGWPublishHandler::handleAggregatePubrel(Client* client, MQTTGWPacket* packet)
|
||||
{
|
||||
Publish pub;
|
||||
packet->getPUBLISH(&pub);
|
||||
replyACK(client, &pub, PUBCOMP);
|
||||
}
|
||||
|
||||
void MQTTGWPublishHandler::handleAggregatePublish(Client* client,
|
||||
MQTTGWPacket* packet)
|
||||
void MQTTGWPublishHandler::handleAggregatePublish(Client* client, MQTTGWPacket* packet)
|
||||
{
|
||||
Publish pub;
|
||||
packet->getPUBLISH(&pub);
|
||||
@@ -310,9 +293,7 @@ void MQTTGWPublishHandler::handleAggregatePublish(Client* client,
|
||||
Topic topic = Topic(topicName, MQTTSN_TOPIC_TYPE_NORMAL);
|
||||
|
||||
// ToDo: need to refactor
|
||||
ClientTopicElement* elm =
|
||||
_gateway->getAdapterManager()->getAggregater()->getClientElement(
|
||||
&topic);
|
||||
ClientTopicElement* elm = _gateway->getAdapterManager()->getAggregater()->getClientElement(&topic);
|
||||
|
||||
while (elm != nullptr)
|
||||
{
|
||||
@@ -322,9 +303,8 @@ void MQTTGWPublishHandler::handleAggregatePublish(Client* client,
|
||||
|
||||
if (msg->getType() == 0)
|
||||
{
|
||||
WRITELOG(
|
||||
"%s MQTTGWPublishHandler::handleAggregatePublish can't allocate memories for Packet.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
WRITELOG("%s MQTTGWPublishHandler::handleAggregatePublish can't allocate memories for Packet.%s\n",
|
||||
ERRMSG_HEADER, ERRMSG_FOOTER);
|
||||
delete msg;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user