Change TAB to 4spaces

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-02-16 15:51:54 +09:00
parent d05bf8eaf4
commit 69b229daae
60 changed files with 5973 additions and 5726 deletions

View File

@@ -30,7 +30,8 @@ MQTTGWConnectionHandler::~MQTTGWConnectionHandler()
}
void MQTTGWConnectionHandler::handleConnack(Client* client, MQTTGWPacket* packet)
void MQTTGWConnectionHandler::handleConnack(Client* client,
MQTTGWPacket* packet)
{
uint8_t rc = MQTT_SERVER_UNAVAILABLE;
Connack resp;
@@ -44,29 +45,35 @@ void MQTTGWConnectionHandler::handleConnack(Client* client, MQTTGWPacket* packet
else if (resp.rc == MQTT_UNACCEPTABLE_PROTOCOL_VERSION)
{
rc = MQTTSN_RC_NOT_SUPPORTED;
WRITELOG(" ClientID : %s Requested Protocol version is not supported.\n", client->getClientId());
WRITELOG(
" ClientID : %s Requested Protocol version is not supported.\n",
client->getClientId());
}
else if (resp.rc == MQTT_IDENTIFIER_REJECTED)
{
rc = MQTTSN_RC_NOT_SUPPORTED;
WRITELOG(" ClientID : %s ClientID is collect UTF-8 but not allowed by the Server.\n",
WRITELOG(
" ClientID : %s ClientID is collect UTF-8 but not allowed by the Server.\n",
client->getClientId());
}
else if (resp.rc == MQTT_SERVER_UNAVAILABLE)
{
rc = MQTTSN_RC_REJECTED_CONGESTED;
WRITELOG(" ClientID : %s The Network Connection has been made but the MQTT service is unavailable.\n",
WRITELOG(
" ClientID : %s The Network Connection has been made but the MQTT service is unavailable.\n",
client->getClientId());
}
else if (resp.rc == MQTT_BAD_USERNAME_OR_PASSWORD)
{
rc = MQTTSN_RC_NOT_SUPPORTED;
WRITELOG(" Gateway Configuration Error: The data in the user name or password is malformed.\n");
WRITELOG(
" Gateway Configuration Error: The data in the user name or password is malformed.\n");
}
else if (resp.rc == MQTT_NOT_AUTHORIZED)
{
rc = MQTTSN_RC_NOT_SUPPORTED;
WRITELOG(" Gateway Configuration Error: The Client is not authorized to connect.\n");
WRITELOG(
" Gateway Configuration Error: The Client is not authorized to connect.\n");
}
MQTTSNPacket* snPacket = new MQTTSNPacket();
@@ -78,7 +85,8 @@ void MQTTGWConnectionHandler::handleConnack(Client* client, MQTTGWPacket* packet
_gateway->getClientSendQue()->post(ev1);
}
void MQTTGWConnectionHandler::handlePingresp(Client* client, MQTTGWPacket* packet)
void MQTTGWConnectionHandler::handlePingresp(Client* client,
MQTTGWPacket* packet)
{
MQTTSNPacket* snPacket = new MQTTSNPacket();
snPacket->setPINGRESP();
@@ -88,7 +96,8 @@ void MQTTGWConnectionHandler::handlePingresp(Client* client, MQTTGWPacket* packe
_gateway->getClientSendQue()->post(ev1);
}
void MQTTGWConnectionHandler::handleDisconnect(Client* client, MQTTGWPacket* packet)
void MQTTGWConnectionHandler::handleDisconnect(Client* client,
MQTTGWPacket* packet)
{
MQTTSNPacket* snPacket = new MQTTSNPacket();
snPacket->setDISCONNECT(0);

View File

@@ -29,8 +29,9 @@ void writeInt(unsigned char** pptr, int msgId);
* List of the predefined MQTT v3 packet names.
*/
static const char* mqtt_packet_names[] =
{ "RESERVED", "CONNECT", "CONNACK", "PUBLISH", "PUBACK", "PUBREC", "PUBREL", "PUBCOMP", "SUBSCRIBE", "SUBACK",
"UNSUBSCRIBE", "UNSUBACK", "PINGREQ", "PINGRESP", "DISCONNECT" };
{ "RESERVED", "CONNECT", "CONNACK", "PUBLISH", "PUBACK", "PUBREC", "PUBREL",
"PUBCOMP", "SUBSCRIBE", "SUBACK", "UNSUBSCRIBE", "UNSUBACK", "PINGREQ",
"PINGRESP", "DISCONNECT" };
/**
* Encodes the message length according to the MQTT algorithm
@@ -242,8 +243,9 @@ int MQTTGWPacket::send(Network* network)
int MQTTGWPacket::getAck(Ack* ack)
{
if (PUBACK != _header.bits.type && PUBREC != _header.bits.type && PUBREL != _header.bits.type
&& PUBCOMP != _header.bits.type && UNSUBACK != _header.bits.type)
if (PUBACK != _header.bits.type && PUBREC != _header.bits.type
&& PUBREL != _header.bits.type && PUBCOMP != _header.bits.type
&& UNSUBACK != _header.bits.type)
{
return 0;
}
@@ -303,15 +305,18 @@ int MQTTGWPacket::getPUBLISH(Publish* pub)
return 1;
}
int MQTTGWPacket::setCONNECT(Connect* connect, unsigned char* username, unsigned char* password)
int MQTTGWPacket::setCONNECT(Connect* connect, unsigned char* username,
unsigned char* password)
{
clearData();
_header = connect->header;
_remainingLength = ((connect->version == 3) ? 12 : 10) + (int)strlen(connect->clientID) + 2;
_remainingLength = ((connect->version == 3) ? 12 : 10)
+ (int) strlen(connect->clientID) + 2;
if (connect->flags.bits.will)
{
_remainingLength += (int)strlen(connect->willTopic) + 2 + (int)strlen(connect->willMsg) + 2;
_remainingLength += (int) strlen(connect->willTopic) + 2
+ (int) strlen(connect->willMsg) + 2;
}
if (connect->flags.bits.username)
{
@@ -360,7 +365,8 @@ int MQTTGWPacket::setCONNECT(Connect* connect, unsigned char* username, unsigned
return 1;
}
int MQTTGWPacket::setSUBSCRIBE(const char* topic, unsigned char qos, unsigned short msgId)
int MQTTGWPacket::setSUBSCRIBE(const char* topic, unsigned char qos,
unsigned short msgId)
{
clearData();
_header.byte = 0;
@@ -634,7 +640,8 @@ MQTTGWPacket& MQTTGWPacket::operator =(MQTTGWPacket& packet)
UTF8String MQTTGWPacket::getTopic(void)
{
UTF8String str = {0, nullptr};
UTF8String str =
{ 0, nullptr };
if (_header.bits.type == SUBSCRIBE || _header.bits.type == UNSUBSCRIBE)
{
char* ptr = (char*) (_data + 2);

View File

@@ -31,18 +31,29 @@ typedef void* (*pf)(unsigned char, char*, size_t);
enum msgTypes
{
CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL,
PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK,
PINGREQ, PINGRESP, DISCONNECT
CONNECT = 1,
CONNACK,
PUBLISH,
PUBACK,
PUBREC,
PUBREL,
PUBCOMP,
SUBSCRIBE,
SUBACK,
UNSUBSCRIBE,
UNSUBACK,
PINGREQ,
PINGRESP,
DISCONNECT
};
/**
* Bitfields for the MQTT header byte.
*/
typedef union
{
/*unsigned*/ char byte; /**< the whole byte */
/*unsigned*/
char byte; /**< the whole byte */
#if defined(REVERSED)
struct
{
@@ -62,12 +73,12 @@ typedef union
#endif
} Header;
/**
* Data for a connect packet.
*/
enum MQTT_connackCodes{
enum MQTT_connackCodes
{
MQTT_CONNECTION_ACCEPTED,
MQTT_UNACCEPTABLE_PROTOCOL_VERSION,
MQTT_IDENTIFIER_REJECTED,
@@ -121,8 +132,6 @@ typedef struct
#define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
/**
* Data for a willMessage.
*/
@@ -160,7 +169,6 @@ typedef struct
char rc; /**< connack return code */
} Connack;
/**
* Data for a publish packet.
*/
@@ -214,11 +222,13 @@ public:
int getSUBACK(unsigned short* msgId, unsigned char* rc);
int getPUBLISH(Publish* pub);
int setCONNECT(Connect* conect, unsigned char* username, unsigned char* password);
int setCONNECT(Connect* conect, unsigned char* username,
unsigned char* password);
int setPUBLISH(Publish* pub);
int setAck(unsigned char msgType, unsigned short msgid);
int setHeader(unsigned char msgType);
int setSUBSCRIBE(const char* topic, unsigned char qos, unsigned short msgId);
int setSUBSCRIBE(const char* topic, unsigned char qos,
unsigned short msgId);
int setUNSUBSCRIBE(const char* topics, unsigned short msgid);
UTF8String getTopic(void);

View File

@@ -39,7 +39,8 @@ 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);
WRITELOG("%s The client is neither active nor sleep %s%s\n",
ERRMSG_HEADER, client->getStatus(), ERRMSG_FOOTER);
return;
}
@@ -65,7 +66,9 @@ 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;
}
@@ -145,23 +148,28 @@ 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.%s\n", ERRMSG_HEADER,ERRMSG_FOOTER);
WRITELOG("%sMQTTGWPublishHandler Can't create a Topic.%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);
@@ -181,7 +189,8 @@ 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();
@@ -193,10 +202,13 @@ 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);
@@ -234,13 +246,13 @@ void MQTTGWPublishHandler::handleAck(Client* client, MQTTGWPacket* packet, int t
}
}
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);
@@ -248,11 +260,13 @@ void MQTTGWPublishHandler::handleAggregatePuback(Client* client, MQTTGWPacket* p
}
}
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);
@@ -260,24 +274,27 @@ void MQTTGWPublishHandler::handleAggregateAck(Client* client, MQTTGWPacket* pack
}
}
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);
string* topicName = new string(pub.topic, pub.topiclen); // topic deletes topicName when the topic is deleted
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)
{
@@ -287,7 +304,9 @@ void MQTTGWPublishHandler::handleAggregatePublish(Client* client, MQTTGWPacket*
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;
}

View File

@@ -45,6 +45,4 @@ private:
}
#endif /* MQTTGWPUBLISHHANDLER_H_ */

View File

@@ -61,7 +61,8 @@ void MQTTGWSubscribeHandler::handleSuback(Client* client, MQTTGWPacket* packet)
}
}
void MQTTGWSubscribeHandler::handleUnsuback(Client* client, MQTTGWPacket* packet)
void MQTTGWSubscribeHandler::handleUnsuback(Client* client,
MQTTGWPacket* packet)
{
Ack ack;
packet->getAck(&ack);
@@ -72,11 +73,14 @@ void MQTTGWSubscribeHandler::handleUnsuback(Client* client, MQTTGWPacket* packet
_gateway->getClientSendQue()->post(evt);
}
void MQTTGWSubscribeHandler::handleAggregateSuback(Client* client, MQTTGWPacket* packet)
void MQTTGWSubscribeHandler::handleAggregateSuback(Client* client,
MQTTGWPacket* packet)
{
uint16_t msgId = packet->getMsgId();
uint16_t clientMsgId = 0;
Client* newClient = _gateway->getAdapterManager()->getAggregater()->convertClient(msgId, &clientMsgId);
Client* newClient =
_gateway->getAdapterManager()->getAggregater()->convertClient(msgId,
&clientMsgId);
if (newClient != nullptr)
{
packet->setMsgId((int) clientMsgId);
@@ -84,11 +88,14 @@ void MQTTGWSubscribeHandler::handleAggregateSuback(Client* client, MQTTGWPacket*
}
}
void MQTTGWSubscribeHandler::handleAggregateUnsuback(Client* client, MQTTGWPacket* packet)
void MQTTGWSubscribeHandler::handleAggregateUnsuback(Client* client,
MQTTGWPacket* packet)
{
uint16_t msgId = packet->getMsgId();
uint16_t clientMsgId = 0;
Client* newClient = _gateway->getAdapterManager()->getAggregater()->convertClient(msgId, &clientMsgId);
Client* newClient =
_gateway->getAdapterManager()->getAggregater()->convertClient(msgId,
&clientMsgId);
if (newClient != nullptr)
{
packet->setMsgId((int) clientMsgId);
@@ -96,4 +103,3 @@ void MQTTGWSubscribeHandler::handleAggregateUnsuback(Client* client, MQTTGWPacke
}
}

View File

@@ -26,7 +26,8 @@ using namespace MQTTSNGW;
/*=====================================
Class MQTTSNAggregateConnectionHandler
=====================================*/
MQTTSNAggregateConnectionHandler::MQTTSNAggregateConnectionHandler(Gateway* gateway)
MQTTSNAggregateConnectionHandler::MQTTSNAggregateConnectionHandler(
Gateway* gateway)
{
_gateway = gateway;
}
@@ -36,11 +37,11 @@ MQTTSNAggregateConnectionHandler::~MQTTSNAggregateConnectionHandler()
}
/*
* CONNECT
*/
void MQTTSNAggregateConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet)
void MQTTSNAggregateConnectionHandler::handleConnect(Client* client,
MQTTSNPacket* packet)
{
MQTTSNPacket_connectData data;
if (packet->getCONNECT(&data) == 0)
@@ -70,7 +71,6 @@ void MQTTSNAggregateConnectionHandler::handleConnect(Client* client, MQTTSNPacke
/* CONNECT was not sent yet. prepare Connect data */
client->setSessionStatus(false);
if (data.cleansession)
{
@@ -86,7 +86,8 @@ void MQTTSNAggregateConnectionHandler::handleConnect(Client* client, MQTTSNPacke
{
if (tp->getType() == MQTTSN_TOPIC_TYPE_NORMAL)
{
_gateway->getAdapterManager()->getAggregater()->removeAggregateTopic(tp, client);
_gateway->getAdapterManager()->getAggregater()->removeAggregateTopic(
tp, client);
}
tp = topics->getNextTopic(tp);
}
@@ -120,11 +121,11 @@ void MQTTSNAggregateConnectionHandler::handleConnect(Client* client, MQTTSNPacke
}
}
/*
* WILLMSG
*/
void MQTTSNAggregateConnectionHandler::handleWillmsg(Client* client, MQTTSNPacket* packet)
void MQTTSNAggregateConnectionHandler::handleWillmsg(Client* client,
MQTTSNPacket* packet)
{
if (!client->isWaitWillMsg())
{
@@ -159,7 +160,8 @@ void MQTTSNAggregateConnectionHandler::handleWillmsg(Client* client, MQTTSNPacke
/*
* DISCONNECT
*/
void MQTTSNAggregateConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* packet)
void MQTTSNAggregateConnectionHandler::handleDisconnect(Client* client,
MQTTSNPacket* packet)
{
MQTTSNPacket* snMsg = new MQTTSNPacket();
snMsg->setDISCONNECT(0);
@@ -171,9 +173,11 @@ void MQTTSNAggregateConnectionHandler::handleDisconnect(Client* client, MQTTSNPa
/*
* PINGREQ
*/
void MQTTSNAggregateConnectionHandler::handlePingreq(Client* client, MQTTSNPacket* packet)
void MQTTSNAggregateConnectionHandler::handlePingreq(Client* client,
MQTTSNPacket* packet)
{
if ( ( client->isSleep() || client->isAwake() ) && client->getClientSleepPacket() )
if ((client->isSleep() || client->isAwake())
&& client->getClientSleepPacket())
{
sendStoredPublish(client);
client->holdPingRequest();

View File

@@ -24,7 +24,6 @@
#include <string.h>
using namespace MQTTSNGW;
/*=====================================
Class Adapter
=====================================*/
@@ -48,7 +47,6 @@ Adapter::~Adapter(void)
}
}
void Adapter::setup(const char* adpterName, AdapterType adapterType)
{
_isSecure = false;
@@ -65,16 +63,17 @@ void Adapter::setup(const char* adpterName, AdapterType adapterType)
string nameSecure = string(adpterName) + "-S";
idSecure.cstring = const_cast<char*>(nameSecure.c_str());
Client* client = _gateway->getClientList()->createClient(0, &id, true, false, TRANSPEARENT_TYPE);
Client* client = _gateway->getClientList()->createClient(0, &id, true,
false, TRANSPEARENT_TYPE);
setClient(client, false);
client->setAdapterType(adapterType);
client = _gateway->getClientList()->createClient(0, &idSecure, true, true, TRANSPEARENT_TYPE);
client = _gateway->getClientList()->createClient(0, &idSecure, true, true,
TRANSPEARENT_TYPE);
setClient(client, true);
client->setAdapterType(adapterType);
}
Client* Adapter::getClient(SensorNetAddress* addr)
{
Client* client = _gateway->getClientList()->getClient(addr);
@@ -174,7 +173,9 @@ void Adapter::send(MQTTSNPacket* packet, Client* client)
}
else
{
WRITELOG("%s %s No Secure connections %s 's packet is discarded.%s\n", ERRMSG_HEADER, client->getClientId() , ERRMSG_FOOTER);
WRITELOG(
"%s %s No Secure connections %s 's packet is discarded.%s\n",
ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
return;
}
}
@@ -212,7 +213,6 @@ void Adapter::savePacket(Client* client, MQTTSNPacket* packet)
}
}
Client* Adapter::getAdapterClient(Client* client)
{
if (client->isSecureNetwork())
@@ -243,7 +243,8 @@ Proxy::~Proxy(void)
void Proxy::checkConnection(Client* client)
{
if ( client->isDisconnect() || ( client->isConnecting() && _responseTimer.isTimeup()) )
if (client->isDisconnect()
|| (client->isConnecting() && _responseTimer.isTimeup()))
{
client->connectSended();
_responseTimer.start(PROXY_RESPONSE_DURATION * 1000UL);
@@ -257,7 +258,8 @@ void Proxy::checkConnection(Client* client)
ev->setClientRecvEvent(client, packet);
_gateway->getPacketEventQue()->post(ev);
}
else if ( (client->isActive() && _keepAliveTimer.isTimeup() ) || (_isWaitingResp && _responseTimer.isTimeup() ) )
else if ((client->isActive() && _keepAliveTimer.isTimeup())
|| (_isWaitingResp && _responseTimer.isTimeup()))
{
MQTTSNPacket* packet = new MQTTSNPacket();
MQTTSNString clientId = MQTTSNString_initializer;
@@ -276,7 +278,6 @@ void Proxy::checkConnection(Client* client)
}
}
void Proxy::resetPingTimer(void)
{
_keepAliveTimer.start(PROXY_KEEPALIVE_DURATION * 1000UL);

View File

@@ -31,7 +31,8 @@ class EventQue;
class Timer;
/* When you add a new type, Client::setAdapterType() and Client::isAdapter() functions must be modified. */
typedef enum{
typedef enum
{
Atype_QoSm1Proxy, Atype_Aggregater
} AdapterType;
@@ -69,7 +70,6 @@ private:
bool _isSecure { false };
};
/*=====================================
Class Proxy
=====================================*/
@@ -88,7 +88,8 @@ public:
private:
void sendSuspendedPacket(void);
Gateway* _gateway;
EventQue* _suspendedPacketEventQue {nullptr};
EventQue* _suspendedPacketEventQue
{ nullptr };
Timer _keepAliveTimer;
Timer _responseTimer;
bool _isWaitingResp { false };

View File

@@ -39,8 +39,8 @@ AdapterManager::AdapterManager(Gateway* gw)
_aggregater = new Aggregater(gw);
}
void AdapterManager::initialize(char* gwName, bool aggregate, bool forwarder, bool qosM1)
void AdapterManager::initialize(char* gwName, bool aggregate, bool forwarder,
bool qosM1)
{
if (aggregate)
{
@@ -91,7 +91,8 @@ Aggregater* AdapterManager::getAggregater(void)
bool AdapterManager::isAggregatedClient(Client* client)
{
if ( !_aggregater->isActive() || client->isQoSm1() || client->isAggregater() || client->isQoSm1Proxy())
if (!_aggregater->isActive() || client->isQoSm1() || client->isAggregater()
|| client->isQoSm1Proxy())
{
return false;
}
@@ -127,7 +128,8 @@ Client* AdapterManager::getClient(Client* client)
return newClient;
}
int AdapterManager::unicastToClient(Client* client, MQTTSNPacket* packet, ClientSendTask* task)
int AdapterManager::unicastToClient(Client* client, MQTTSNPacket* packet,
ClientSendTask* task)
{
char pbuf[SIZE_OF_LOG_PACKET * 3];
Forwarder* fwd = client->getForwarder();
@@ -139,8 +141,10 @@ int AdapterManager::unicastToClient(Client* client, MQTTSNPacket* packet, Client
WirelessNodeId* wnId = fwd->getWirelessNodeId(client);
encap.setWirelessNodeId(wnId);
task->log(client, packet);
WRITELOG(FORMAT_Y_W_G, currentDateTime(), encap.getName(), RIGHTARROW, fwd->getId(), encap.print(pbuf));
rc = encap.unicast(_gateway->getSensorNetwork(),fwd->getSensorNetAddr());
WRITELOG(FORMAT_Y_W_G, currentDateTime(), encap.getName(), RIGHTARROW,
fwd->getId(), encap.print(pbuf));
rc = encap.unicast(_gateway->getSensorNetwork(),
fwd->getSensorNetAddr());
}
else
{
@@ -155,7 +159,8 @@ int AdapterManager::unicastToClient(Client* client, MQTTSNPacket* packet, Client
}
else
{
rc = packet->unicast(_gateway->getSensorNetwork(), client->getSensorNetAddress());
rc = packet->unicast(_gateway->getSensorNetwork(),
client->getSensorNetAddress());
}
}
return rc;

View File

@@ -49,7 +49,8 @@ public:
bool isAggregatedClient(Client* client);
Client* getClient(Client* client);
Client* convertClient(uint16_t msgId, uint16_t* clientMsgId);
int unicastToClient(Client* client, MQTTSNPacket* packet, ClientSendTask* task);
int unicastToClient(Client* client, MQTTSNPacket* packet,
ClientSendTask* task);
bool isAggregaterActive(void);
private:
@@ -59,8 +60,5 @@ private:
Aggregater* _aggregater { nullptr };
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWADAPTERMANAGER_H_ */

View File

@@ -129,7 +129,8 @@ ClientTopicElement* AggregateTopicElement::getFirstClientTopicElement(void)
return _head;
}
ClientTopicElement* AggregateTopicElement::getNextClientTopicElement(ClientTopicElement* elmClient)
ClientTopicElement* AggregateTopicElement::getNextClientTopicElement(
ClientTopicElement* elmClient)
{
return elmClient->_next;
}
@@ -261,7 +262,8 @@ void AggregateTopicTable::erase(AggregateTopicElement* elmTopic)
}
}
AggregateTopicElement* AggregateTopicTable::getAggregateTopicElement(Topic* topic)
AggregateTopicElement* AggregateTopicTable::getAggregateTopicElement(
Topic* topic)
{
AggregateTopicElement* elm = _head;

View File

@@ -68,7 +68,8 @@ public:
ClientTopicElement* add(Client* client);
ClientTopicElement* getFirstClientTopicElement(void);
ClientTopicElement* getNextClientTopicElement(ClientTopicElement* elmClient);
ClientTopicElement* getNextClientTopicElement(
ClientTopicElement* elmClient);
void eraseClient(Client* client);
ClientTopicElement* find(Client* client);
@@ -103,6 +104,4 @@ private:
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWAGGREGATETOPICTABLE_H_ */

View File

@@ -26,7 +26,8 @@
using namespace MQTTSNGW;
Aggregater::Aggregater(Gateway* gw) : Adapter(gw)
Aggregater::Aggregater(Gateway* gw) :
Adapter(gw)
{
_gateway = gw;
}
@@ -63,7 +64,6 @@ Client* Aggregater::convertClient(uint16_t msgId, uint16_t* clientMsgId)
return _msgIdTable.getClientMsgId(msgId, clientMsgId);
}
uint16_t Aggregater::addMessageIdTable(Client* client, uint16_t msgId)
{
/* set Non secure client`s nextMsgId. otherwise Id is duplicated.*/
@@ -84,12 +84,12 @@ uint16_t Aggregater::getMsgId(Client* client, uint16_t clientMsgId)
return _msgIdTable.getMsgId(client, clientMsgId);
}
AggregateTopicElement* Aggregater::addAggregateTopic(Topic* topic, Client* client)
AggregateTopicElement* Aggregater::addAggregateTopic(Topic* topic,
Client* client)
{
return _topicTable.add(topic, client);
}
void Aggregater::removeAggregateTopic(Topic* topic, Client* client)
{
_topicTable.erase(topic, client);

View File

@@ -73,10 +73,6 @@ private:
bool _isSecure { false };
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWAGGREGATER_H_ */

View File

@@ -148,20 +148,35 @@ void BrokerRecvTask::run(void)
}
else if (rc == -1)
{
WRITELOG("%s BrokerRecvTask can't receive a packet from the broker errno=%d %s%s\n", ERRMSG_HEADER, errno, client->getClientId(), ERRMSG_FOOTER);
WRITELOG(
"%s BrokerRecvTask can't receive a packet from the broker errno=%d %s%s\n",
ERRMSG_HEADER, errno,
client->getClientId(),
ERRMSG_FOOTER);
}
else if (rc == -2)
{
WRITELOG("%s BrokerRecvTask receive invalid length of packet from the broker. DISCONNECT %s %s\n", ERRMSG_HEADER, client->getClientId(),ERRMSG_FOOTER);
WRITELOG(
"%s BrokerRecvTask receive invalid length of packet from the broker. DISCONNECT %s %s\n",
ERRMSG_HEADER,
client->getClientId(),
ERRMSG_FOOTER);
}
else if (rc == -3)
{
WRITELOG("%s BrokerRecvTask can't get memories for the packet %s%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG(
"%s BrokerRecvTask can't get memories for the packet %s%s\n",
ERRMSG_HEADER,
client->getClientId(),
ERRMSG_FOOTER);
}
delete packet;
if ( (rc == -1 || rc == -2) && ( client->isActive() || client->isSleep() || client->isAwake() ))
if ((rc == -1 || rc == -2)
&& (client->isActive()
|| client->isSleep()
|| client->isAwake()))
{
/* disconnect the client */
packet = new MQTTGWPacket();
@@ -173,8 +188,7 @@ void BrokerRecvTask::run(void)
}
}
}
nextClient:
client = client->getNextClient();
nextClient: client = client->getNextClient();
}
}
}
@@ -193,23 +207,31 @@ int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
switch (packet->getType())
{
case CONNACK:
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), LEFTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), LEFTARROWB,
client->getClientId(), packet->print(pbuf));
break;
case PUBLISH:
WRITELOG(FORMAT_W_MSGID_Y_W_NL, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_Y_W_NL, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), LEFTARROWB, client->getClientId(),
packet->print(pbuf));
break;
case PUBACK:
case PUBREC:
case PUBREL:
case PUBCOMP:
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), LEFTARROWB, client->getClientId(),
packet->print(pbuf));
break;
case SUBACK:
case UNSUBACK:
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), LEFTARROWB, client->getClientId(),
packet->print(pbuf));
break;
case PINGRESP:
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), LEFTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), LEFTARROWB,
client->getClientId(), packet->print(pbuf));
break;
default:
WRITELOG("Type=%x\n", packet->getType());

View File

@@ -28,7 +28,7 @@ namespace MQTTSNGW
class BrokerRecvTask: public Thread
{
MAGIC_WORD_FOR_THREAD;
;
public:
BrokerRecvTask(Gateway* gateway);
~BrokerRecvTask();
@@ -44,5 +44,4 @@ private:
}
#endif /* MQTTSNGWBROKERRECVTASK_H_ */

View File

@@ -94,19 +94,28 @@ void BrokerSendTask::run()
if (client->isSecureNetwork())
{
rc = client->getNetwork()->connect((const char*)_gwparams->brokerName, (const char*)_gwparams->portSecure, (const char*)_gwparams->rootCApath,
(const char*)_gwparams->rootCAfile, (const char*)_gwparams->certKey, (const char*)_gwparams->privateKey);
rc = client->getNetwork()->connect(
(const char*) _gwparams->brokerName,
(const char*) _gwparams->portSecure,
(const char*) _gwparams->rootCApath,
(const char*) _gwparams->rootCAfile,
(const char*) _gwparams->certKey,
(const char*) _gwparams->privateKey);
}
else
{
rc = client->getNetwork()->connect((const char*)_gwparams->brokerName, (const char*)_gwparams->port);
rc = client->getNetwork()->connect(
(const char*) _gwparams->brokerName,
(const char*) _gwparams->port);
}
if (!rc)
{
/* disconnect the broker and the client */
WRITELOG("%s BrokerSendTask: %s can't connect to the broker. errno=%d %s %s\n",
ERRMSG_HEADER, client->getClientId(), errno, strerror(errno), ERRMSG_FOOTER);
WRITELOG(
"%s BrokerSendTask: %s can't connect to the broker. errno=%d %s %s\n",
ERRMSG_HEADER, client->getClientId(), errno,
strerror(errno), ERRMSG_FOOTER);
delete ev;
client->getNetwork()->close();
continue;
@@ -130,8 +139,10 @@ void BrokerSendTask::run()
}
else
{
WRITELOG("%s BrokerSendTask: %s can't send a packet to the broker. errno=%d %s %s\n",
ERRMSG_HEADER, client->getClientId(), rc == -1 ? errno : 0, strerror(errno), ERRMSG_FOOTER);
WRITELOG(
"%s BrokerSendTask: %s can't send a packet to the broker. errno=%d %s %s\n",
ERRMSG_HEADER, client->getClientId(),
rc == -1 ? errno : 0, strerror(errno), ERRMSG_FOOTER);
if ( errno != EBADF)
{
client->getNetwork()->close();
@@ -151,7 +162,6 @@ void BrokerSendTask::run()
}
}
/**
* write message content into stdout or Ringbuffer
*/
@@ -163,10 +173,13 @@ void BrokerSendTask::log(Client* client, MQTTGWPacket* packet)
switch (packet->getType())
{
case CONNECT:
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), RIGHTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(),
RIGHTARROWB, client->getClientId(), packet->print(pbuf));
break;
case PUBLISH:
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(), packet->getMsgId(msgId), RIGHTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), RIGHTARROWB, client->getClientId(),
packet->print(pbuf));
break;
case SUBSCRIBE:
case UNSUBSCRIBE:
@@ -174,13 +187,17 @@ void BrokerSendTask::log(Client* client, MQTTGWPacket* packet)
case PUBREC:
case PUBREL:
case PUBCOMP:
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(), packet->getMsgId(msgId), RIGHTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_Y_W, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), RIGHTARROWB, client->getClientId(),
packet->print(pbuf));
break;
case PINGREQ:
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), RIGHTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(),
RIGHTARROWB, client->getClientId(), packet->print(pbuf));
break;
case DISCONNECT:
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(), RIGHTARROWB, client->getClientId(), packet->print(pbuf));
WRITELOG(FORMAT_Y_Y_W, currentDateTime(), packet->getName(),
RIGHTARROWB, client->getClientId(), packet->print(pbuf));
break;
default:
break;

View File

@@ -28,11 +28,12 @@
using namespace MQTTSNGW;
char* currentDateTime(void);
/*=====================================
Class Client
=====================================*/
static const char* theClientStatus[] = { "Disconnected", "TryConnecting", "Connecting", "Active", "Asleep", "Awake", "Lost" };
static const char* theClientStatus[] =
{ "Disconnected", "TryConnecting", "Connecting", "Active", "Asleep", "Awake",
"Lost" };
Client::Client(bool secure)
{
@@ -119,11 +120,13 @@ int Client::setClientSleepPacket(MQTTGWPacket* packet)
int rc = _clientSleepPacketQue.post(packet);
if (rc)
{
WRITELOG("%s %s is sleeping. the packet was saved.\n", currentDateTime(), _clientId);
WRITELOG("%s %s is sleeping. the packet was saved.\n",
currentDateTime(), _clientId);
}
else
{
WRITELOG("%s %s is sleeping but discard the packet.\n", currentDateTime(), _clientId);
WRITELOG("%s %s is sleeping but discard the packet.\n",
currentDateTime(), _clientId);
}
return rc;
}
@@ -143,11 +146,13 @@ int Client::setProxyPacket(MQTTSNPacket* packet)
int rc = _proxyPacketQue.post(packet);
if (rc)
{
WRITELOG("%s %s is Disconnected. the packet was saved.\n", currentDateTime(), _clientId);
WRITELOG("%s %s is Disconnected. the packet was saved.\n",
currentDateTime(), _clientId);
}
else
{
WRITELOG("%s %s is Disconnected and discard the packet.\n", currentDateTime(), _clientId);
WRITELOG("%s %s is Disconnected and discard the packet.\n",
currentDateTime(), _clientId);
}
return rc;
}
@@ -177,11 +182,13 @@ 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_topicTypes type)
{
_waitedPubTopicIdMap.add(msgId, topicId, type);
}
void Client::setWaitedSubTopicId(uint16_t msgId, uint16_t topicId, MQTTSN_topicTypes type)
void Client::setWaitedSubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type)
{
_waitedSubTopicIdMap.add(msgId, topicId, type);
}
@@ -224,7 +231,8 @@ bool Client::erasable(void)
void Client::updateStatus(MQTTSNPacket* packet)
{
if (((_status == Cstat_Disconnected) || (_status == Cstat_Lost)) && packet->getType() == MQTTSN_CONNECT)
if (((_status == Cstat_Disconnected) || (_status == Cstat_Lost))
&& packet->getType() == MQTTSN_CONNECT)
{
setKeepAlive(packet);
}
@@ -280,8 +288,7 @@ void Client::updateStatus(MQTTSNPacket* packet)
default:
break;
}
}
DEBUGLOG("Client Status = %s\n", theClientStatus[_status]);
} DEBUGLOG("Client Status = %s\n", theClientStatus[_status]);
}
void Client::updateStatus(ClientStatus stat)
@@ -577,8 +584,6 @@ bool Client::isHoldPingReqest(void)
return _holdPingRequest;
}
/*=====================================
Class WaitREGACKPacket
=====================================*/
@@ -691,4 +696,3 @@ uint8_t WaitREGACKPacketList::getCount(void)
return _cnt;
}

View File

@@ -49,7 +49,6 @@ public:
_que = new Que<T>;
}
~PacketQue()
{
clear();
@@ -72,8 +71,7 @@ public:
}
}
int
post(T* packet)
int post(T* packet)
{
int rc;
_mutex.lock();
@@ -113,8 +111,6 @@ private:
Mutex _mutex;
};
/*=====================================
Class WaitREGACKPacket
=====================================*/
@@ -151,19 +147,28 @@ private:
waitREGACKPacket* _end;
};
/*=====================================
Class Client
=====================================*/
typedef enum
{
Cstat_Disconnected = 0, Cstat_TryConnecting, Cstat_Connecting, Cstat_Active, Cstat_Asleep, Cstat_Awake, Cstat_Lost
Cstat_Disconnected = 0,
Cstat_TryConnecting,
Cstat_Connecting,
Cstat_Active,
Cstat_Asleep,
Cstat_Awake,
Cstat_Lost
} ClientStatus;
typedef enum
{
Ctype_Regular = 0, Ctype_Forwarded, Ctype_QoS_1, Ctype_Aggregated, Ctype_Proxy, Ctype_Aggregater
Ctype_Regular = 0,
Ctype_Forwarded,
Ctype_QoS_1,
Ctype_Aggregated,
Ctype_Proxy,
Ctype_Aggregater
} ClientType;
class Forwarder;
@@ -193,8 +198,10 @@ 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_topicTypes type);
void setWaitedSubTopicId(uint16_t msgId, uint16_t topicId,
MQTTSN_topicTypes type);
bool checkTimeover(void);
void updateStatus(MQTTSNPacket*);
@@ -299,7 +306,5 @@ private:
Client* _prevClient;
};
}
#endif /* MQTTSNGWCLIENT_H_ */

View File

@@ -72,15 +72,18 @@ void ClientList::setClientList(int type)
{
if (!createList(theGateway->getGWParams()->clientListName, type))
{
throw Exception("ClientList::setClientList No client list defined by config file.");
throw Exception(
"ClientList::setClientList No client list defined by config file.");
}
}
void ClientList::setPredefinedTopics(bool aggrecate)
{
if ( !readPredefinedList(theGateway->getGWParams()->predefinedTopicFileName, aggrecate) )
if (!readPredefinedList(theGateway->getGWParams()->predefinedTopicFileName,
aggrecate))
{
throw Exception("ClientList::setPredefinedTopics No predefindTopi list defined by config file.");
throw Exception(
"ClientList::setPredefinedTopics No predefindTopi list defined by config file.");
}
}
@@ -148,13 +151,15 @@ bool ClientList::createList(const char* fileName, int type)
forwarder = (data.find("forwarder") != string::npos);
secure = (data.find("secureConnection") != string::npos);
stable = !(data.find("unstableLine") != string::npos);
if ( (qos_1 && type == QOSM1PROXY_TYPE) || (!qos_1 && type == AGGREGATER_TYPE) )
if ((qos_1 && type == QOSM1PROXY_TYPE)
|| (!qos_1 && type == AGGREGATER_TYPE))
{
createClient(&netAddr, &clientId, stable, secure, type);
}
else if (forwarder && type == FORWARDER_TYPE)
{
theGateway->getAdapterManager()->getForwarderList()->addForwarder(&netAddr, &clientId);
theGateway->getAdapterManager()->getForwarderList()->addForwarder(
&netAddr, &clientId);
}
else if (type == TRANSPEARENT_TYPE)
{
@@ -179,7 +184,8 @@ bool ClientList::readPredefinedList(const char* fileName, bool aggregate)
FILE* fp;
char buf[MAX_CLIENTID_LENGTH + 256];
size_t pos0, pos1;
MQTTSNString clientId = MQTTSNString_initializer;;
MQTTSNString clientId = MQTTSNString_initializer;
;
bool rc = false;
if ((fp = fopen(fileName, "r")) != 0)
@@ -214,7 +220,8 @@ bool ClientList::readPredefinedList(const char* fileName, bool aggregate)
}
else
{
WRITELOG("ClientList can not open the Predefined Topic List. %s\n", fileName);
WRITELOG("ClientList can not open the Predefined Topic List. %s\n",
fileName);
return false;
}
return rc;
@@ -297,7 +304,6 @@ Client* ClientList::getClient(int index)
return nullptr;
}
Client* ClientList::getClient(MQTTSNString* clientId)
{
_mutex.lock();
@@ -311,7 +317,8 @@ Client* ClientList::getClient(MQTTSNString* clientId)
while (client != nullptr)
{
if (strncmp((const char*)client->getClientId(), clID, MQTTSNstrlen(*clientId)) == 0 )
if (strncmp((const char*) client->getClientId(), clID,
MQTTSNstrlen(*clientId)) == 0)
{
_mutex.unlock();
return client;
@@ -322,12 +329,14 @@ Client* ClientList::getClient(MQTTSNString* clientId)
return 0;
}
Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId, int type)
Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
int type)
{
return createClient(addr, clientId, false, false, type);
}
Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId, bool unstableLine, bool secure, int type)
Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
bool unstableLine, bool secure, int type)
{
Client* client = nullptr;
@@ -390,11 +399,13 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
return client;
}
Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t topicId, bool aggregate)
Client* ClientList::createPredefinedTopic(MQTTSNString* clientId,
string topicName, uint16_t topicId, bool aggregate)
{
if (topicId == 0)
{
WRITELOG("Invalid TopicId. Predefined Topic %s, TopicId is 0. \n", topicName.c_str());
WRITELOG("Invalid TopicId. Predefined Topic %s, TopicId is 0. \n",
topicName.c_str());
return nullptr;
}
@@ -462,4 +473,3 @@ bool ClientList::isAuthorized()
return _authorize;
}

View File

@@ -43,8 +43,10 @@ public:
void setClientList(int type);
void setPredefinedTopics(bool aggregate);
void erase(Client*&);
Client* createClient(SensorNetAddress* addr, MQTTSNString* clientId,int type);
Client* createClient(SensorNetAddress* addr, MQTTSNString* clientId, bool unstableLine, bool secure, int type);
Client* createClient(SensorNetAddress* addr, MQTTSNString* clientId,
int type);
Client* createClient(SensorNetAddress* addr, MQTTSNString* clientId,
bool unstableLine, bool secure, int type);
bool createList(const char* fileName, int type);
Client* getClient(SensorNetAddress* addr);
Client* getClient(MQTTSNString* clientId);
@@ -56,7 +58,8 @@ public:
private:
bool readPredefinedList(const char* fileName, bool _aggregate);
Gateway* _gateway { nullptr };
Client* createPredefinedTopic( MQTTSNString* clientId, string topicName, uint16_t toipcId, bool _aggregate);
Client* createPredefinedTopic(MQTTSNString* clientId, string topicName,
uint16_t toipcId, bool _aggregate);
Client* _firstClient;
Client* _endClient;
Mutex _mutex;
@@ -64,9 +67,6 @@ private:
bool _authorize { false };
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWCLIENTLIST_H_ */

View File

@@ -60,7 +60,8 @@ void ClientRecvTask::run()
Event* ev = nullptr;
AdapterManager* adpMgr = _gateway->getAdapterManager();
QoSm1Proxy* qosm1Proxy = adpMgr->getQoSm1Proxy();
int clientType = adpMgr->isAggregaterActive() ? AGGREGATER_TYPE : TRANSPEARENT_TYPE;
int clientType =
adpMgr->isAggregaterActive() ? AGGREGATER_TYPE : TRANSPEARENT_TYPE;
ClientList* clientList = _gateway->getClientList();
EventQue* packetEventQue = _gateway->getPacketEventQue();
@@ -88,7 +89,8 @@ void ClientRecvTask::run()
continue;
}
if ( packet->getType() <= MQTTSN_ADVERTISE || packet->getType() == MQTTSN_GWINFO )
if (packet->getType() <= MQTTSN_ADVERTISE
|| packet->getType() == MQTTSN_GWINFO)
{
delete packet;
continue;
@@ -104,12 +106,14 @@ void ClientRecvTask::run()
continue;
}
SensorNetAddress* senderAddr = _gateway->getSensorNetwork()->getSenderAddress();
SensorNetAddress* senderAddr =
_gateway->getSensorNetwork()->getSenderAddress();
if (packet->getType() == MQTTSN_ENCAPSULATED)
{
fwd = _gateway->getAdapterManager()->getForwarderList()->getForwarder(senderAddr);
fwd =
_gateway->getAdapterManager()->getForwarderList()->getForwarder(
senderAddr);
if (fwd != nullptr)
{
@@ -119,7 +123,8 @@ void ClientRecvTask::run()
/* get the packet from the encapsulation message */
MQTTSNGWEncapsulatedPacket encap;
encap.desirialize(packet->getPacketData(), packet->getPacketLength());
encap.desirialize(packet->getPacketData(),
packet->getPacketLength());
nodeId.setId(encap.getWirelessNodeId());
client = fwd->getClient(&nodeId);
packet = encap.getMQTTSNPacket();
@@ -140,7 +145,10 @@ void ClientRecvTask::run()
if (!packet->isQoSMinusPUBLISH())
{
log(clientName, packet);
WRITELOG("%s %s %s can send only PUBLISH with QoS-1.%s\n", ERRMSG_HEADER, clientName, senderAddr->sprint(buf), ERRMSG_FOOTER);
WRITELOG(
"%s %s %s can send only PUBLISH with QoS-1.%s\n",
ERRMSG_HEADER, clientName,
senderAddr->sprint(buf), ERRMSG_FOOTER);
delete packet;
continue;
}
@@ -171,7 +179,9 @@ void ClientRecvTask::run()
if (!packet->getCONNECT(&data))
{
log(0, packet, &data.clientID);
WRITELOG("%s CONNECT message form %s is incorrect.%s\n", ERRMSG_HEADER, senderAddr->sprint(buf), ERRMSG_FOOTER);
WRITELOG("%s CONNECT message form %s is incorrect.%s\n",
ERRMSG_HEADER, senderAddr->sprint(buf),
ERRMSG_FOOTER);
delete packet;
continue;
}
@@ -183,7 +193,8 @@ void ClientRecvTask::run()
if (client == nullptr)
{
/* create a new client */
client = clientList->createClient(0, &data.clientID, clientType);
client = clientList->createClient(0, &data.clientID,
clientType);
}
/* Add to a forwarded client list of forwarder. */
fwd->addClient(client, &nodeId);
@@ -193,7 +204,8 @@ void ClientRecvTask::run()
if (client)
{
/* Authentication is not required */
if ( _gateway->getGWParams()->clientAuthentication == false)
if (_gateway->getGWParams()->clientAuthentication
== false)
{
client->setClientAddress(senderAddr);
}
@@ -201,7 +213,8 @@ void ClientRecvTask::run()
else
{
/* create a new client */
client = clientList->createClient(senderAddr, &data.clientID, clientType);
client = clientList->createClient(senderAddr,
&data.clientID, clientType);
}
}
@@ -209,7 +222,10 @@ void ClientRecvTask::run()
if (client == nullptr)
{
WRITELOG("%s Client(%s) was rejected. CONNECT message has been discarded.%s\n", ERRMSG_HEADER, senderAddr->sprint(buf), ERRMSG_FOOTER);
WRITELOG(
"%s Client(%s) was rejected. CONNECT message has been discarded.%s\n",
ERRMSG_HEADER, senderAddr->sprint(buf),
ERRMSG_FOOTER);
delete packet;
continue;
}
@@ -224,11 +240,18 @@ void ClientRecvTask::run()
log(client, packet, 0);
if (packet->getType() == MQTTSN_ENCAPSULATED)
{
WRITELOG("%s MQTTSNGWClientRecvTask Forwarder(%s) is not declared by ClientList file. message has been discarded.%s\n", ERRMSG_HEADER, _sensorNetwork->getSenderAddress()->sprint(buf), ERRMSG_FOOTER);
WRITELOG(
"%s MQTTSNGWClientRecvTask Forwarder(%s) is not declared by ClientList file. message has been discarded.%s\n",
ERRMSG_HEADER,
_sensorNetwork->getSenderAddress()->sprint(buf),
ERRMSG_FOOTER);
}
else
{
WRITELOG("%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n", ERRMSG_HEADER, senderAddr->sprint(buf), ERRMSG_FOOTER);
WRITELOG(
"%s MQTTSNGWClientRecvTask Client(%s) is not connecting. message has been discarded.%s\n",
ERRMSG_HEADER, senderAddr->sprint(buf),
ERRMSG_FOOTER);
}
delete packet;
}
@@ -275,37 +298,46 @@ void ClientRecvTask::log(const char* clientId, MQTTSNPacket* packet)
switch (packet->getType())
{
case MQTTSN_SEARCHGW:
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(), LEFTARROW, CLIENT, packet->print(pbuf));
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
LEFTARROW, CLIENT, packet->print(pbuf));
break;
case MQTTSN_CONNECT:
case MQTTSN_PINGREQ:
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_Y_G_G_NL, currentDateTime(), packet->getName(),
LEFTARROW, clientId, packet->print(pbuf));
break;
case MQTTSN_DISCONNECT:
case MQTTSN_WILLTOPICUPD:
case MQTTSN_WILLMSGUPD:
case MQTTSN_WILLTOPIC:
case MQTTSN_WILLMSG:
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
clientId, packet->print(pbuf));
break;
case MQTTSN_PUBLISH:
case MQTTSN_REGISTER:
case MQTTSN_SUBSCRIBE:
case MQTTSN_UNSUBSCRIBE:
WRITELOG(FORMAT_G_MSGID_G_G_NL, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_G_MSGID_G_G_NL, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), LEFTARROW, clientId,
packet->print(pbuf));
break;
case MQTTSN_REGACK:
case MQTTSN_PUBACK:
case MQTTSN_PUBREC:
case MQTTSN_PUBREL:
case MQTTSN_PUBCOMP:
WRITELOG(FORMAT_G_MSGID_G_G, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_G_MSGID_G_G, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), LEFTARROW, clientId,
packet->print(pbuf));
break;
case MQTTSN_ENCAPSULATED:
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_Y_G_G, currentDateTime(), packet->getName(), LEFTARROW,
clientId, packet->print(pbuf));
break;
default:
WRITELOG(FORMAT_W_NL, currentDateTime(), packet->getName(), LEFTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_W_NL, currentDateTime(), packet->getName(), LEFTARROW,
clientId, packet->print(pbuf));
break;
}
}

View File

@@ -63,7 +63,8 @@ void ClientSendTask::run()
if (packet->broadcast(_sensorNetwork) < 0)
{
WRITELOG("%s ClientSendTask can't multicast a packet Error=%d%s\n",
WRITELOG(
"%s ClientSendTask can't multicast a packet Error=%d%s\n",
ERRMSG_HEADER, errno, ERRMSG_FOOTER);
}
}
@@ -84,8 +85,12 @@ void ClientSendTask::run()
if (rc < 0)
{
WRITELOG("%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n",
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), errno, ERRMSG_FOOTER);
WRITELOG(
"%s ClientSendTask can't send a packet to the client %s. Error=%d%s\n",
ERRMSG_HEADER,
(client ?
(const char*) client->getClientId() : UNKNOWNCL),
errno, ERRMSG_FOOTER);
}
}
delete ev;
@@ -96,13 +101,15 @@ void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
{
char pbuf[SIZE_OF_LOG_PACKET * 3 + 1];
char msgId[6];
const char* clientId = client ? (const char*)client->getClientId() : UNKNOWNCL ;
const char* clientId =
client ? (const char*) client->getClientId() : UNKNOWNCL;
switch (packet->getType())
{
case MQTTSN_ADVERTISE:
case MQTTSN_GWINFO:
WRITELOG(FORMAT_Y_W_G, currentDateTime(), packet->getName(), RIGHTARROW, CLIENTS, packet->print(pbuf));
WRITELOG(FORMAT_Y_W_G, currentDateTime(), packet->getName(), RIGHTARROW,
CLIENTS, packet->print(pbuf));
break;
case MQTTSN_CONNACK:
case MQTTSN_DISCONNECT:
@@ -111,11 +118,14 @@ void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
case MQTTSN_WILLTOPICRESP:
case MQTTSN_WILLMSGRESP:
case MQTTSN_PINGRESP:
WRITELOG(FORMAT_Y_W_G, currentDateTime(), packet->getName(), RIGHTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_Y_W_G, currentDateTime(), packet->getName(), RIGHTARROW,
clientId, packet->print(pbuf));
break;
case MQTTSN_REGISTER:
case MQTTSN_PUBLISH:
WRITELOG(FORMAT_W_MSGID_W_G, currentDateTime(), packet->getName(), packet->getMsgId(msgId), RIGHTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_W_G, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), RIGHTARROW, clientId,
packet->print(pbuf));
break;
case MQTTSN_REGACK:
case MQTTSN_PUBACK:
@@ -124,7 +134,9 @@ void ClientSendTask::log(Client* client, MQTTSNPacket* packet)
case MQTTSN_PUBCOMP:
case MQTTSN_SUBACK:
case MQTTSN_UNSUBACK:
WRITELOG(FORMAT_W_MSGID_W_G, currentDateTime(), packet->getName(), packet->getMsgId(msgId), RIGHTARROW, clientId, packet->print(pbuf));
WRITELOG(FORMAT_W_MSGID_W_G, currentDateTime(), packet->getName(),
packet->getMsgId(msgId), RIGHTARROW, clientId,
packet->print(pbuf));
break;
default:
break;

View File

@@ -42,7 +42,8 @@ MQTTSNConnectionHandler::~MQTTSNConnectionHandler()
void MQTTSNConnectionHandler::sendADVERTISE()
{
MQTTSNPacket* adv = new MQTTSNPacket();
adv->setADVERTISE(_gateway->getGWParams()->gatewayId, _gateway->getGWParams()->keepAlive);
adv->setADVERTISE(_gateway->getGWParams()->gatewayId,
_gateway->getGWParams()->keepAlive);
Event* ev1 = new Event();
ev1->setBrodcastEvent(adv); //broadcast
_gateway->getClientSendQue()->post(ev1);
@@ -66,7 +67,8 @@ void MQTTSNConnectionHandler::handleSearchgw(MQTTSNPacket* packet)
/*
* CONNECT
*/
void MQTTSNConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleConnect(Client* client,
MQTTSNPacket* packet)
{
MQTTSNPacket_connectData data;
if (packet->getCONNECT(&data) == 0)
@@ -125,7 +127,8 @@ void MQTTSNConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet
/* renew the TopicList */
if (topics)
{
topics->eraseNormal();;
topics->eraseNormal();
;
}
client->setSessionStatus(true);
}
@@ -146,7 +149,9 @@ void MQTTSNConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet
/* CONNECT message was not qued in.
* create CONNECT message & send it to the broker */
MQTTGWPacket* mqMsg = new MQTTGWPacket();
mqMsg->setCONNECT(client->getConnectData(), (unsigned char*)_gateway->getGWParams()->loginId, (unsigned char*)_gateway->getGWParams()->password);
mqMsg->setCONNECT(client->getConnectData(),
(unsigned char*) _gateway->getGWParams()->loginId,
(unsigned char*) _gateway->getGWParams()->password);
Event* ev1 = new Event();
ev1->setBrokerSendEvent(client, mqMsg);
_gateway->getBrokerSendQue()->post(ev1);
@@ -156,7 +161,8 @@ void MQTTSNConnectionHandler::handleConnect(Client* client, MQTTSNPacket* packet
/*
* WILLTOPIC
*/
void MQTTSNConnectionHandler::handleWilltopic(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleWilltopic(Client* client,
MQTTSNPacket* packet)
{
int willQos;
uint8_t willRetain;
@@ -186,7 +192,8 @@ void MQTTSNConnectionHandler::handleWilltopic(Client* client, MQTTSNPacket* pack
/*
* WILLMSG
*/
void MQTTSNConnectionHandler::handleWillmsg(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleWillmsg(Client* client,
MQTTSNPacket* packet)
{
if (!client->isWaitWillMsg())
{
@@ -209,7 +216,9 @@ void MQTTSNConnectionHandler::handleWillmsg(Client* client, MQTTSNPacket* packet
/* create CONNECT message */
MQTTGWPacket* mqttPacket = new MQTTGWPacket();
connectData->willMsg = client->getWillMsg();
mqttPacket->setCONNECT(connectData, (unsigned char*)_gateway->getGWParams()->loginId, (unsigned char*)_gateway->getGWParams()->password);
mqttPacket->setCONNECT(connectData,
(unsigned char*) _gateway->getGWParams()->loginId,
(unsigned char*) _gateway->getGWParams()->password);
/* Send CONNECT to the broker */
Event* evt = new Event();
@@ -222,7 +231,8 @@ void MQTTSNConnectionHandler::handleWillmsg(Client* client, MQTTSNPacket* packet
/*
* DISCONNECT
*/
void MQTTSNConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleDisconnect(Client* client,
MQTTSNPacket* packet)
{
uint16_t duration = 0;
@@ -248,7 +258,8 @@ void MQTTSNConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* pac
/*
* WILLTOPICUPD
*/
void MQTTSNConnectionHandler::handleWilltopicupd(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleWilltopicupd(Client* client,
MQTTSNPacket* packet)
{
/* send NOT_SUPPORTED responce to the client */
MQTTSNPacket* respMsg = new MQTTSNPacket();
@@ -261,7 +272,8 @@ void MQTTSNConnectionHandler::handleWilltopicupd(Client* client, MQTTSNPacket* p
/*
* WILLMSGUPD
*/
void MQTTSNConnectionHandler::handleWillmsgupd(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handleWillmsgupd(Client* client,
MQTTSNPacket* packet)
{
/* send NOT_SUPPORTED responce to the client */
MQTTSNPacket* respMsg = new MQTTSNPacket();
@@ -274,9 +286,11 @@ void MQTTSNConnectionHandler::handleWillmsgupd(Client* client, MQTTSNPacket* pac
/*
* PINGREQ
*/
void MQTTSNConnectionHandler::handlePingreq(Client* client, MQTTSNPacket* packet)
void MQTTSNConnectionHandler::handlePingreq(Client* client,
MQTTSNPacket* packet)
{
if ( ( client->isSleep() || client->isAwake() ) && client->getClientSleepPacket() )
if ((client->isSleep() || client->isAwake())
&& client->getClientSleepPacket())
{
sendStoredPublish(client);
client->holdPingRequest();

View File

@@ -62,7 +62,6 @@ typedef unsigned int uint32_t;
==================================*/
//#define DEBUG // print out log for debug
//#define DEBUG_NWSTACK // print out SensorNetwork log
#ifdef DEBUG
#define DEBUGLOG(...) printf(__VA_ARGS__)
#else

View File

@@ -21,10 +21,10 @@
using namespace MQTTSNGW;
using namespace std;
WirelessNodeId::WirelessNodeId()
:
_len{0},
_nodeId{0}
WirelessNodeId::WirelessNodeId() :
_len
{ 0 }, _nodeId
{ 0 }
{
}
@@ -77,16 +77,18 @@ bool WirelessNodeId::operator ==(WirelessNodeId& id)
/*
* Class MQTTSNGWEncapsulatedPacket
*/
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket()
: _mqttsn{0},
_ctrl{0}
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket() :
_mqttsn
{ 0 }, _ctrl
{ 0 }
{
}
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket(MQTTSNPacket* packet)
: _mqttsn{packet},
_ctrl{0}
MQTTSNGWEncapsulatedPacket::MQTTSNGWEncapsulatedPacket(MQTTSNPacket* packet) :
_mqttsn
{ packet }, _ctrl
{ 0 }
{
}
@@ -96,7 +98,8 @@ MQTTSNGWEncapsulatedPacket::~MQTTSNGWEncapsulatedPacket()
/* Do not delete the MQTTSNPacket. MQTTSNPacket is deleted by delete Event */
}
int MQTTSNGWEncapsulatedPacket::unicast(SensorNetwork* network, SensorNetAddress* sendTo)
int MQTTSNGWEncapsulatedPacket::unicast(SensorNetwork* network,
SensorNetAddress* sendTo)
{
uint8_t buf[MQTTSNGW_MAX_PACKET_SIZE];
int len = serialize(buf);
@@ -118,7 +121,8 @@ int MQTTSNGWEncapsulatedPacket::serialize(uint8_t* buf)
return buf[0] + len;
}
int MQTTSNGWEncapsulatedPacket::desirialize(unsigned char* buf, unsigned short len)
int MQTTSNGWEncapsulatedPacket::desirialize(unsigned char* buf,
unsigned short len)
{
if (_mqttsn)
{

View File

@@ -60,6 +60,4 @@ private:
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWENCAPSULATEDPACKET_H_ */

View File

@@ -44,14 +44,12 @@ ForwarderList::~ForwarderList()
}
}
void ForwarderList::initialize(Gateway* gw)
{
/* Create Fowarders from clients.conf */
gw->getClientList()->setClientList(FORWARDER_TYPE);
}
Forwarder* ForwarderList::getForwarder(SensorNetAddress* addr)
{
Forwarder* p = _head;
@@ -66,7 +64,8 @@ Forwarder* ForwarderList::getForwarder(SensorNetAddress* addr)
return p;
}
Forwarder* ForwarderList::addForwarder(SensorNetAddress* addr, MQTTSNString* forwarderId)
Forwarder* ForwarderList::addForwarder(SensorNetAddress* addr,
MQTTSNString* forwarderId)
{
Forwarder* fdr = new Forwarder(addr, forwarderId);
if (_head == nullptr)
@@ -251,10 +250,11 @@ SensorNetAddress* Forwarder::getSensorNetAddr(void)
* Class ForwardedClient
*/
ForwarderElement::ForwarderElement()
: _client{0}
, _wirelessNodeId{0}
, _next{0}
ForwarderElement::ForwarderElement() :
_client
{ 0 }, _wirelessNodeId
{ 0 }, _next
{ 0 }
{
}

View File

@@ -22,7 +22,6 @@
#include "MQTTSNGWEncapsulatedPacket.h"
#include "SensorNetwork.h"
namespace MQTTSNGW
{
class Gateway;
@@ -94,6 +93,4 @@ private:
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWFORWARDER_H_ */

View File

@@ -45,7 +45,8 @@ MessageIdTable::~MessageIdTable()
_mutex.unlock();
}
MessageIdElement* MessageIdTable::add(Aggregater* aggregater, Client* client, uint16_t clientMsgId)
MessageIdElement* MessageIdTable::add(Aggregater* aggregater, Client* client,
uint16_t clientMsgId)
{
if (_cnt > _maxSize)
{
@@ -115,7 +116,6 @@ MessageIdElement* MessageIdTable::find(Client* client, uint16_t clientMsgId)
return p;
}
Client* MessageIdTable::getClientMsgId(uint16_t msgId, uint16_t* clientMsgId)
{
Client* clt = nullptr;
@@ -179,7 +179,6 @@ void MessageIdTable::clear(MessageIdElement* elm)
}
}
uint16_t MessageIdTable::getMsgId(Client* client, uint16_t clientMsgId)
{
uint16_t msgId = 0;
@@ -194,18 +193,20 @@ uint16_t MessageIdTable::getMsgId(Client* client, uint16_t clientMsgId)
/*===============================
* Class MessageIdElement
===============================*/
MessageIdElement::MessageIdElement(void)
: _msgId{0}
, _clientMsgId {0}
, _client {nullptr}
, _next {nullptr}
, _prev {nullptr}
MessageIdElement::MessageIdElement(void) :
_msgId
{ 0 }, _clientMsgId
{ 0 }, _client
{ nullptr }, _next
{ nullptr }, _prev
{ nullptr }
{
}
MessageIdElement::MessageIdElement(uint16_t msgId, Client* client, uint16_t clientMsgId)
: MessageIdElement()
MessageIdElement::MessageIdElement(uint16_t msgId, Client* client,
uint16_t clientMsgId) :
MessageIdElement()
{
_msgId = msgId;
_client = client;

View File

@@ -37,7 +37,8 @@ public:
MessageIdTable();
~MessageIdTable();
MessageIdElement* add(Aggregater* aggregater, Client* client, uint16_t clientMsgId);
MessageIdElement* add(Aggregater* aggregater, Client* client,
uint16_t clientMsgId);
Client* getClientMsgId(uint16_t msgId, uint16_t* clientMsgId);
uint16_t getMsgId(Client* client, uint16_t clientMsgId);
void erase(uint16_t msgId);
@@ -72,7 +73,6 @@ private:
MessageIdElement* _prev;
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWMESSAGEIDTABLE_H_ */

View File

@@ -158,7 +158,8 @@ int MQTTSNPacket::setGWINFO(uint8_t gatewayId)
{
unsigned char buf[3];
int buflen = sizeof(buf);
int len = MQTTSNSerialize_gwinfo(buf, buflen, (unsigned char) gatewayId, 0, 0);
int len = MQTTSNSerialize_gwinfo(buf, buflen, (unsigned char) gatewayId, 0,
0);
return desirialize(buf, len);
}
@@ -201,40 +202,45 @@ int MQTTSNPacket::setWILLMSGREQ(void)
return desirialize(buf, len);
}
int MQTTSNPacket::setREGISTER(uint16_t topicId, uint16_t msgId, MQTTSNString* topicName)
int MQTTSNPacket::setREGISTER(uint16_t topicId, uint16_t msgId,
MQTTSNString* topicName)
{
unsigned char buf[MQTTSNGW_MAX_PACKET_SIZE];
int buflen = sizeof(buf);
int len = MQTTSNSerialize_register(buf, buflen, (unsigned short) topicId, (unsigned short) msgId,
topicName);
int len = MQTTSNSerialize_register(buf, buflen, (unsigned short) topicId,
(unsigned short) msgId, topicName);
return desirialize(buf, len);
}
int MQTTSNPacket::setREGACK(uint16_t topicId, uint16_t msgId, uint8_t returnCode)
int MQTTSNPacket::setREGACK(uint16_t topicId, uint16_t msgId,
uint8_t returnCode)
{
unsigned char buf[7];
int buflen = sizeof(buf);
int len = MQTTSNSerialize_regack(buf, buflen, (unsigned short) topicId, (unsigned short) msgId,
(unsigned char) returnCode);
int len = MQTTSNSerialize_regack(buf, buflen, (unsigned short) topicId,
(unsigned short) msgId, (unsigned char) returnCode);
return desirialize(buf, len);
}
int MQTTSNPacket::setPUBLISH(uint8_t dup, int qos, uint8_t retained, uint16_t msgId, MQTTSN_topicid topic,
uint8_t* payload, uint16_t payloadlen)
int MQTTSNPacket::setPUBLISH(uint8_t dup, int qos, uint8_t retained,
uint16_t msgId, MQTTSN_topicid topic, uint8_t* payload,
uint16_t payloadlen)
{
unsigned char buf[MQTTSNGW_MAX_PACKET_SIZE];
int buflen = sizeof(buf);
int len = MQTTSNSerialize_publish(buf, buflen, (unsigned char) dup, qos, (unsigned char) retained,
(unsigned short) msgId, topic, (unsigned char*) payload, (int) payloadlen);
int len = MQTTSNSerialize_publish(buf, buflen, (unsigned char) dup, qos,
(unsigned char) retained, (unsigned short) msgId, topic,
(unsigned char*) payload, (int) payloadlen);
return desirialize(buf, len);
}
int MQTTSNPacket::setPUBACK(uint16_t topicId, uint16_t msgId, uint8_t returnCode)
int MQTTSNPacket::setPUBACK(uint16_t topicId, uint16_t msgId,
uint8_t returnCode)
{
unsigned char buf[7];
int buflen = sizeof(buf);
int len = MQTTSNSerialize_puback(buf, buflen, (unsigned short) topicId, (unsigned short) msgId,
(unsigned char) returnCode);
int len = MQTTSNSerialize_puback(buf, buflen, (unsigned short) topicId,
(unsigned short) msgId, (unsigned char) returnCode);
return desirialize(buf, len);
}
@@ -262,7 +268,8 @@ int MQTTSNPacket::setPUBCOMP(uint16_t msgId)
return desirialize(buf, len);
}
int MQTTSNPacket::setSUBACK(int qos, uint16_t topicId, uint16_t msgId, uint8_t returnCode)
int MQTTSNPacket::setSUBACK(int qos, uint16_t topicId, uint16_t msgId,
uint8_t returnCode)
{
unsigned char buf[8];
int buflen = sizeof(buf);
@@ -329,7 +336,8 @@ int MQTTSNPacket::setPINGREQ(MQTTSNString* clientId)
int MQTTSNPacket::getSERCHGW(uint8_t* radius)
{
return MQTTSNDeserialize_searchgw((unsigned char*) radius, (unsigned char*) _buf, _bufLen);
return MQTTSNDeserialize_searchgw((unsigned char*) radius,
(unsigned char*) _buf, _bufLen);
}
int MQTTSNPacket::getCONNECT(MQTTSNPacket_connectData* data)
@@ -342,9 +350,11 @@ int MQTTSNPacket::getCONNACK(uint8_t* returnCode)
return MQTTSNSerialize_connack(_buf, _bufLen, (int) *returnCode);
}
int MQTTSNPacket::getWILLTOPIC(int* willQoS, uint8_t* willRetain, MQTTSNString* willTopic)
int MQTTSNPacket::getWILLTOPIC(int* willQoS, uint8_t* willRetain,
MQTTSNString* willTopic)
{
return MQTTSNDeserialize_willtopic((int*) willQoS, (unsigned char*) willRetain, willTopic, _buf, _bufLen);
return MQTTSNDeserialize_willtopic((int*) willQoS,
(unsigned char*) willRetain, willTopic, _buf, _bufLen);
}
int MQTTSNPacket::getWILLMSG(MQTTSNString* willmsg)
@@ -352,28 +362,34 @@ int MQTTSNPacket::getWILLMSG(MQTTSNString* willmsg)
return MQTTSNDeserialize_willmsg(willmsg, _buf, _bufLen);
}
int MQTTSNPacket::getREGISTER(uint16_t* topicId, uint16_t* msgId, MQTTSNString* topicName)
int MQTTSNPacket::getREGISTER(uint16_t* topicId, uint16_t* msgId,
MQTTSNString* topicName)
{
return MQTTSNDeserialize_register((unsigned short*) topicId, (unsigned short*) msgId, topicName,
_buf, _bufLen);
return MQTTSNDeserialize_register((unsigned short*) topicId,
(unsigned short*) msgId, topicName, _buf, _bufLen);
}
int MQTTSNPacket::getREGACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode)
int MQTTSNPacket::getREGACK(uint16_t* topicId, uint16_t* msgId,
uint8_t* returnCode)
{
return MQTTSNDeserialize_regack((unsigned short*) topicId, (unsigned short*) msgId, (unsigned char*) returnCode, _buf, _bufLen);
return MQTTSNDeserialize_regack((unsigned short*) topicId,
(unsigned short*) msgId, (unsigned char*) returnCode, _buf, _bufLen);
}
int MQTTSNPacket::getPUBLISH(uint8_t* dup, int* qos, uint8_t* retained, uint16_t* msgId, MQTTSN_topicid* topic,
uint8_t** payload, int* payloadlen)
int MQTTSNPacket::getPUBLISH(uint8_t* dup, int* qos, uint8_t* retained,
uint16_t* msgId, MQTTSN_topicid* topic, uint8_t** payload,
int* payloadlen)
{
return MQTTSNDeserialize_publish((unsigned char*) dup, qos, (unsigned char*) retained, (unsigned short*) msgId,
topic, (unsigned char**) payload, (int*) payloadlen, _buf, _bufLen);
return MQTTSNDeserialize_publish((unsigned char*) dup, qos,
(unsigned char*) retained, (unsigned short*) msgId, topic,
(unsigned char**) payload, (int*) payloadlen, _buf, _bufLen);
}
int MQTTSNPacket::getPUBACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode)
int MQTTSNPacket::getPUBACK(uint16_t* topicId, uint16_t* msgId,
uint8_t* returnCode)
{
return MQTTSNDeserialize_puback((unsigned short*) topicId, (unsigned short*) msgId, (unsigned char*) returnCode,
_buf, _bufLen);
return MQTTSNDeserialize_puback((unsigned short*) topicId,
(unsigned short*) msgId, (unsigned char*) returnCode, _buf, _bufLen);
}
int MQTTSNPacket::getACK(uint16_t* msgId)
@@ -382,14 +398,17 @@ int MQTTSNPacket::getACK(uint16_t* msgId)
return MQTTSNDeserialize_ack(&type, (unsigned short*) msgId, _buf, _bufLen);
}
int MQTTSNPacket::getSUBSCRIBE(uint8_t* dup, int* qos, uint16_t* msgId, MQTTSN_topicid* topicFilter)
int MQTTSNPacket::getSUBSCRIBE(uint8_t* dup, int* qos, uint16_t* msgId,
MQTTSN_topicid* topicFilter)
{
return MQTTSNDeserialize_subscribe((unsigned char*) dup, qos, (unsigned short*) msgId, topicFilter, _buf, _bufLen);
return MQTTSNDeserialize_subscribe((unsigned char*) dup, qos,
(unsigned short*) msgId, topicFilter, _buf, _bufLen);
}
int MQTTSNPacket::getUNSUBSCRIBE(uint16_t* msgId, MQTTSN_topicid* topicFilter)
{
return MQTTSNDeserialize_unsubscribe((unsigned short*) msgId, topicFilter, _buf, _bufLen);
return MQTTSNDeserialize_unsubscribe((unsigned short*) msgId, topicFilter,
_buf, _bufLen);
}
int MQTTSNPacket::getPINGREQ(void)
@@ -409,9 +428,11 @@ int MQTTSNPacket::getDISCONNECT(uint16_t* duration)
return rc;
}
int MQTTSNPacket::getWILLTOPICUPD(uint8_t* willQoS, uint8_t* willRetain, MQTTSNString* willTopic)
int MQTTSNPacket::getWILLTOPICUPD(uint8_t* willQoS, uint8_t* willRetain,
MQTTSNString* willTopic)
{
return MQTTSNDeserialize_willtopicupd((int*) willQoS, (unsigned char*) willRetain, willTopic, _buf, _bufLen);
return MQTTSNDeserialize_willtopicupd((int*) willQoS,
(unsigned char*) willRetain, willTopic, _buf, _bufLen);
}
int MQTTSNPacket::getWILLMSGUPD(MQTTSNString* willMsg)

View File

@@ -53,7 +53,8 @@ public:
int setPUBREC(uint16_t msgId);
int setPUBREL(uint16_t msgId);
int setPUBCOMP(uint16_t msgId);
int setSUBACK(int qos, uint16_t topicId, uint16_t msgId, uint8_t returnCode);
int setSUBACK(int qos, uint16_t topicId, uint16_t msgId,
uint8_t returnCode);
int setUNSUBACK(uint16_t msgId);
int setPINGRESP(void);
int setDISCONNECT(uint16_t duration);
@@ -66,19 +67,23 @@ public:
int getSERCHGW(uint8_t* radius);
int getCONNECT(MQTTSNPacket_connectData* option);
int getCONNACK(uint8_t* returnCode);
int getWILLTOPIC(int* willQoS, uint8_t* willRetain, MQTTSNString* willTopic);
int getWILLTOPIC(int* willQoS, uint8_t* willRetain,
MQTTSNString* willTopic);
int getWILLMSG(MQTTSNString* willmsg);
int getREGISTER(uint16_t* topicId, uint16_t* msgId, MQTTSNString* topicName);
int getREGISTER(uint16_t* topicId, uint16_t* msgId,
MQTTSNString* topicName);
int getREGACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode);
int getPUBLISH(uint8_t* dup, int* qos, uint8_t* retained, uint16_t* msgId,
MQTTSN_topicid* topic, unsigned char** payload, int* payloadlen);
int getPUBACK(uint16_t* topicId, uint16_t* msgId, uint8_t* returnCode);
int getACK(uint16_t* msgId);
int getSUBSCRIBE(uint8_t* dup, int* qos, uint16_t* msgId, MQTTSN_topicid* topicFilter);
int getSUBSCRIBE(uint8_t* dup, int* qos, uint16_t* msgId,
MQTTSN_topicid* topicFilter);
int getUNSUBSCRIBE(uint16_t* msgId, MQTTSN_topicid* topicFilter);
int getPINGREQ(void);
int getDISCONNECT(uint16_t* duration);
int getWILLTOPICUPD(uint8_t* willQoS, uint8_t* willRetain, MQTTSNString* willTopic);
int getWILLTOPICUPD(uint8_t* willQoS, uint8_t* willRetain,
MQTTSNString* willTopic);
int getWILLMSGUPD(MQTTSNString* willMsg);
bool isAccepted(void);

View File

@@ -124,7 +124,8 @@ void PacketHandleTask::run()
if (_advertiseTimer.isTimeup())
{
_mqttsnConnection->sendADVERTISE();
_advertiseTimer.start(_gateway->getGWParams()->keepAlive * 1000UL);
_advertiseTimer.start(
_gateway->getGWParams()->keepAlive * 1000UL);
}
/*------ Check Adapters Connect or PINGREQ ------*/
@@ -155,7 +156,6 @@ void PacketHandleTask::run()
transparentPacketHandler(client, snPacket);
}
/* Reset the Timer for PINGREQ. */
client->updateStatus(snPacket);
}
@@ -166,7 +166,6 @@ void PacketHandleTask::run()
brPacket = ev->getMQTTGWPacket();
DEBUGLOG(" PacketHandleTask gets %s %s from the broker.\n", brPacket->getName(), brPacket->getMsgId(msgId));
if (client->isAggregater())
{
aggregatePacketHandler(client, brPacket);
@@ -180,9 +179,8 @@ void PacketHandleTask::run()
}
}
void PacketHandleTask::aggregatePacketHandler(Client*client, MQTTSNPacket* packet)
void PacketHandleTask::aggregatePacketHandler(Client*client,
MQTTSNPacket* packet)
{
switch (packet->getType())
{
@@ -239,8 +237,8 @@ void PacketHandleTask::aggregatePacketHandler(Client*client, MQTTSNPacket* packe
}
}
void PacketHandleTask::aggregatePacketHandler(Client*client, MQTTGWPacket* packet)
void PacketHandleTask::aggregatePacketHandler(Client*client,
MQTTGWPacket* packet)
{
switch (packet->getType())
{
@@ -276,7 +274,8 @@ void PacketHandleTask::aggregatePacketHandler(Client*client, MQTTGWPacket* packe
}
}
void PacketHandleTask::transparentPacketHandler(Client*client, MQTTSNPacket* packet)
void PacketHandleTask::transparentPacketHandler(Client*client,
MQTTSNPacket* packet)
{
switch (packet->getType())
{
@@ -333,8 +332,8 @@ void PacketHandleTask::transparentPacketHandler(Client*client, MQTTSNPacket* pac
}
}
void PacketHandleTask::transparentPacketHandler(Client*client, MQTTGWPacket* packet)
void PacketHandleTask::transparentPacketHandler(Client*client,
MQTTGWPacket* packet)
{
switch (packet->getType())
{

View File

@@ -60,7 +60,8 @@ private:
void transparentPacketHandler(Client*client, MQTTSNPacket* packet);
void transparentPacketHandler(Client*client, MQTTGWPacket* packet);
Gateway* _gateway {nullptr};
Gateway* _gateway
{ nullptr };
Timer _advertiseTimer;
Timer _sendUnixTimer;
MQTTGWConnectionHandler* _mqttConnection { nullptr };
@@ -69,11 +70,9 @@ private:
MQTTSNConnectionHandler* _mqttsnConnection { nullptr };
MQTTSNPublishHandler* _mqttsnPublish { nullptr };
MQTTSNSubscribeHandler* _mqttsnSubscribe { nullptr };
MQTTSNAggregateConnectionHandler* _mqttsnAggrConnection { nullptr };
};
}
#endif /* MQTTSNGWPACKETHANDLETASK_H_ */

View File

@@ -98,7 +98,8 @@ void Process::initialize(int argc, char** argv)
}
else
{
_configFile = config.substr(pos + 1, config.size() - pos - 1);;
_configFile = config.substr(pos + 1, config.size() - pos - 1);
;
_configDir = config.substr(0, pos + 1);
}
}
@@ -287,12 +288,10 @@ void MultiTaskProcess::run(void)
}
sleep(1);
}
}
catch(Exception* ex)
} catch (Exception* ex)
{
ex->writeMessage();
}
catch(...)
} catch (...)
{
throw;
}
@@ -411,7 +410,8 @@ void Exception::writeMessage()
}
else
{
WRITELOG("%s:%-6d %s line %-4d %s() : %s\n", currentDateTime(), getExceptionNo(),
getFileName(), getLineNo(), getFunctionName(), what());
WRITELOG("%s:%-6d %s line %-4d %s() : %s\n", currentDateTime(),
getExceptionNo(), getFileName(), getLineNo(), getFunctionName(),
what());
}
}

View File

@@ -102,8 +102,8 @@ class Exception: public exception
public:
Exception(const string& message);
Exception(const int exNo, const string& message);
Exception(const int exNo, const string& message,
const char* file, const char* func, const int line);
Exception(const int exNo, const string& message, const char* file,
const char* func, const int line);
virtual ~Exception() throw ();
const char* getFileName();
const char* getFunctionName();
@@ -120,7 +120,6 @@ private:
int _line;
};
/*=====================================
Class QueElement
====================================*/
@@ -263,7 +262,8 @@ private:
#define TREE23_TRI_NODE (3)
template<typename K, typename V>
class Tree23Elm{
class Tree23Elm
{
template<typename T, typename U> friend class Tree23;
public:
Tree23Elm()
@@ -292,9 +292,9 @@ private:
V* _val;
};
template<typename K, typename V>
class Tree23Node{
class Tree23Node
{
template<typename S, typename W> friend class Tree23;
public:
Tree23Node(const int type)
@@ -320,7 +320,8 @@ public:
_left = _midle = _right = NULL;
}
Tree23Node(const int type, Tree23Elm<K, V>* telm, Tree23Node<K, V>* left, Tree23Node<K, V>* right)
Tree23Node(const int type, Tree23Elm<K, V>* telm, Tree23Node<K, V>* left,
Tree23Node<K, V>* right)
{
_type = type;
_telm0 = telm;
@@ -330,7 +331,9 @@ public:
_right = right;
}
Tree23Node(const int type, Tree23Elm<K, V>* telm0, Tree23Elm<K, V>* telm1, Tree23Node<K, V>* left, Tree23Node<K, V>* midle, Tree23Node<K, V>* right)
Tree23Node(const int type, Tree23Elm<K, V>* telm0, Tree23Elm<K, V>* telm1,
Tree23Node<K, V>* left, Tree23Node<K, V>* midle,
Tree23Node<K, V>* right)
{
_type = type;
_telm0 = telm0;
@@ -355,7 +358,8 @@ private:
};
template<typename K, typename V>
class Tree23{
class Tree23
{
public:
Tree23()
{
@@ -534,7 +538,8 @@ public:
switch (node->_type)
{
case 2:
if ( cmp0 < 0 ) node = node->_left;
if (cmp0 < 0)
node = node->_left;
else if (cmp0 == 0)
{
return true;
@@ -574,7 +579,6 @@ public:
return false;
}
V* getVal(K* key)
{
Tree23Node<K, V>* node = _root;
@@ -634,7 +638,8 @@ private:
Tree23Node<K, V>* n = node->_left;
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE)
{
return new Tree23Node<K, V>(TREE23_TRI_NODE, n->_telm0, node->_telm0, n->_left, n->_right, node->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, n->_telm0,
node->_telm0, n->_left, n->_right, node->_right);
}
return node;
}
@@ -645,8 +650,10 @@ private:
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE)
{
n->_type = TREE23_BI_NODE;
Tree23Node<K, V>* nn = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, node->_midle, node->_right);
return new Tree23Node<K, V>(TREE23_INSERT_ACTIVE, node->_telm0, n, nn);
Tree23Node<K, V>* nn = new Tree23Node<K, V>(TREE23_BI_NODE,
node->_telm1, node->_midle, node->_right);
return new Tree23Node<K, V>(TREE23_INSERT_ACTIVE, node->_telm0, n,
nn);
}
return node;
}
@@ -656,7 +663,8 @@ private:
Tree23Node<K, V>* n = node->_right;
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE)
{
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0, n->_telm0, node->_left, n->_left, n->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0,
n->_telm0, node->_left, n->_left, n->_right);
}
return node;
}
@@ -664,10 +672,13 @@ private:
Tree23Node<K, V>* addRight3(Tree23Node<K, V>* node)
{
Tree23Node<K, V>* n = node->_right;
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE) {
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE)
{
n->_type = TREE23_BI_NODE;
Tree23Node<K, V>* nn = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, node->_left, node->_midle);
return new Tree23Node<K, V>(TREE23_INSERT_ACTIVE, node->_telm1, nn, n);
Tree23Node<K, V>* nn = new Tree23Node<K, V>(TREE23_BI_NODE,
node->_telm0, node->_left, node->_midle);
return new Tree23Node<K, V>(TREE23_INSERT_ACTIVE, node->_telm1, nn,
n);
}
return node;
}
@@ -677,14 +688,15 @@ private:
Tree23Node<K, V>* n = node->_midle;
if (n != NULL && n->_type == TREE23_INSERT_ACTIVE)
{
n->_left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, node->_left, n->_left);
n->_right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, n->_right, node->_right);
n->_left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0,
node->_left, n->_left);
n->_right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1,
n->_right, node->_right);
return n;
}
return node;
}
Tree23Node<K, V>* removeMax(Tree23Node<K, V>* node, Tree23Elm<K, V>* elm)
{
if (node->_right == NULL)
@@ -719,7 +731,6 @@ private:
return NULL;
}
Tree23Node<K, V>* removeLeft2(Tree23Node<K, V>* node)
{
Tree23Node<K, V>* n = node->_left;
@@ -733,12 +744,16 @@ private:
switch (r->_type)
{
case 2:
midle = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0, r->_telm0, n->_midle, r->_left, r->_right);
midle = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0,
r->_telm0, n->_midle, r->_left, r->_right);
return new Tree23Node<K, V>(TREE23_DELETE_ACTIVE, midle);
case 3:
left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, n->_midle, r->_left);
right = new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm1, r->_midle, r->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm0, left, right);
left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0,
n->_midle, r->_left);
right = new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm1,
r->_midle, r->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm0, left,
right);
default:
break;
}
@@ -759,12 +774,16 @@ private:
switch (l->_type)
{
case 2:
midle = new Tree23Node<K, V>(TREE23_TRI_NODE, l->_telm0, node->_telm0, l->_left, l->_right, n->_midle);
midle = new Tree23Node<K, V>(TREE23_TRI_NODE, l->_telm0,
node->_telm0, l->_left, l->_right, n->_midle);
return new Tree23Node<K, V>(-1, midle);
case 3:
right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, l->_right, n->_midle);
left = new Tree23Node<K, V>(TREE23_BI_NODE, l->_telm0, l->_left, l->_midle);
return new Tree23Node<K, V>(TREE23_BI_NODE, l->_telm1, left, right);
right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0,
l->_right, n->_midle);
left = new Tree23Node<K, V>(TREE23_BI_NODE, l->_telm0, l->_left,
l->_midle);
return new Tree23Node<K, V>(TREE23_BI_NODE, l->_telm1, left,
right);
default:
break;
}
@@ -782,14 +801,20 @@ private:
Tree23Node<K, V>* left;
Tree23Node<K, V>* midle;
switch (m->_type) {
switch (m->_type)
{
case 2:
left = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0, m->_telm0, n->_midle, m->_left, m->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, left, r);
left = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0,
m->_telm0, n->_midle, m->_left, m->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, left,
r);
case 3:
left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, n->_midle, m->_left);
midle = new Tree23Node<K, V>(TREE23_BI_NODE, m->_telm1, m->_midle, m->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, m->_telm0, node->_telm1, left, midle, r);
left = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0,
n->_midle, m->_left);
midle = new Tree23Node<K, V>(TREE23_BI_NODE, m->_telm1,
m->_midle, m->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, m->_telm0,
node->_telm1, left, midle, r);
default:
break;
}
@@ -809,12 +834,17 @@ private:
switch (r->_type)
{
case 2:
right = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm1, r->_telm0, n->_midle, r->_left, r->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, l, right);
right = new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm1,
r->_telm0, n->_midle, r->_left, r->_right);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, l,
right);
case 3:
midle = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, n->_midle, r->_left);
right = new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm1, r->_midle, r->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0, r->_telm0, l, midle, right);
midle = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1,
n->_midle, r->_left);
right = new Tree23Node<K, V>(TREE23_BI_NODE, r->_telm1,
r->_midle, r->_right);
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0,
r->_telm0, l, midle, right);
default:
break;
}
@@ -834,12 +864,17 @@ private:
switch (m->_type)
{
case 2:
right = new Tree23Node<K, V>(TREE23_TRI_NODE, m->_telm0, node->_telm1, m->_left, m->_right, n->_midle);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, l, right);
right = new Tree23Node<K, V>(TREE23_TRI_NODE, m->_telm0,
node->_telm1, m->_left, m->_right, n->_midle);
return new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm0, l,
right);
case 3:
right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1, m->_right, n->_midle);
midle = new Tree23Node<K, V>(TREE23_BI_NODE, m->_telm0, m->_left, m->_midle);
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0, m->_telm1, l, midle, right);
right = new Tree23Node<K, V>(TREE23_BI_NODE, node->_telm1,
m->_right, n->_midle);
midle = new Tree23Node<K, V>(TREE23_BI_NODE, m->_telm0,
m->_left, m->_midle);
return new Tree23Node<K, V>(TREE23_TRI_NODE, node->_telm0,
m->_telm1, l, midle, right);
default:
break;
}
@@ -847,7 +882,6 @@ private:
return node;
}
Tree23Node<K, V>* _root;
};
@@ -873,18 +907,23 @@ public:
{
return _elm;
}
~ListElm(){}
~ListElm()
{
}
private:
ListElm<T>* getNext(void){return _next;}
ListElm<T>* getNext(void)
{
return _next;
}
T* _elm;
ListElm<T>* _prev;
ListElm<T>* _next;
};
template<typename T>
class List{
class List
{
public:
List()
{
@@ -970,14 +1009,12 @@ public:
return _size;
}
private:
ListElm<T>* _head;
ListElm<T>* _tail;
int _size;
};
extern Process* theProcess;
extern MultiTaskProcess* theMultiTaskProcess;

View File

@@ -35,7 +35,8 @@ MQTTSNPublishHandler::~MQTTSNPublishHandler()
}
MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket* packet)
MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client,
MQTTSNPacket* packet)
{
uint8_t dup;
int qos;
@@ -52,13 +53,15 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket*
{
if (client->isQoSm1())
{
_gateway->getAdapterManager()->getQoSm1Proxy()->savePacket(client, packet);
_gateway->getAdapterManager()->getQoSm1Proxy()->savePacket(client,
packet);
return nullptr;
}
}
if ( packet->getPUBLISH(&dup, &qos, &retained, &msgId, &topicid, &payload, &payloadlen) ==0 )
if (packet->getPUBLISH(&dup, &qos, &retained, &msgId, &topicid, &payload,
&payloadlen) == 0)
{
return nullptr;
}
@@ -84,19 +87,22 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket*
topic = _gateway->getTopics()->getTopicById(&topicid);
if (topic)
{
topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId());
topic = client->getTopics()->add(topic->getTopicName()->c_str(),
topic->getTopicId());
}
}
if (!topic && qos == 3)
{
WRITELOG("%s Invalid TopicId.%s %s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG("%s Invalid TopicId.%s %s\n", ERRMSG_HEADER,
client->getClientId(), ERRMSG_FOOTER);
return nullptr;
}
if ((qos == 0 || qos == 3) && msgId > 0)
{
WRITELOG("%s Invalid MsgId.%s %s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG("%s Invalid MsgId.%s %s\n", ERRMSG_HEADER,
client->getClientId(), ERRMSG_FOOTER);
return nullptr;
}
@@ -104,7 +110,8 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket*
{
/* Reply PubAck with INVALID_TOPIC_ID to the client */
MQTTSNPacket* pubAck = new MQTTSNPacket();
pubAck->setPUBACK( topicid.data.id, msgId, MQTTSN_RC_REJECTED_INVALID_TOPIC_ID);
pubAck->setPUBACK(topicid.data.id, msgId,
MQTTSN_RC_REJECTED_INVALID_TOPIC_ID);
Event* ev1 = new Event();
ev1->setClientSendEvent(client, pubAck);
_gateway->getClientSendQue()->post(ev1);
@@ -128,7 +135,8 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket*
MQTTGWPacket* publish = new MQTTGWPacket();
publish->setPUBLISH(&pub);
if ( _gateway->getAdapterManager()->isAggregaterActive() && client->isAggregated() )
if (_gateway->getAdapterManager()->isAggregaterActive()
&& client->isAggregated())
{
return publish;
}
@@ -172,7 +180,8 @@ void MQTTSNPublishHandler::handlePuback(Client* client, MQTTSNPacket* packet)
}
}
void MQTTSNPublishHandler::handleAck(Client* client, MQTTSNPacket* packet, uint8_t packetType)
void MQTTSNPublishHandler::handleAck(Client* client, MQTTSNPacket* packet,
uint8_t packetType)
{
uint16_t msgId;
@@ -194,7 +203,8 @@ void MQTTSNPublishHandler::handleRegister(Client* client, MQTTSNPacket* packet)
{
uint16_t id;
uint16_t msgId;
MQTTSNString topicName = MQTTSNString_initializer;;
MQTTSNString topicName = MQTTSNString_initializer;
;
MQTTSN_topicid topicid;
if (client->isActive() || client->isAwake())
@@ -230,7 +240,8 @@ void MQTTSNPublishHandler::handleRegAck( Client* client, MQTTSNPacket* packet)
return;
}
MQTTSNPacket* regAck = client->getWaitREGACKPacketList()->getPacket(msgId);
MQTTSNPacket* regAck = client->getWaitREGACKPacketList()->getPacket(
msgId);
if (regAck != nullptr)
{
@@ -239,7 +250,8 @@ void MQTTSNPublishHandler::handleRegAck( Client* client, MQTTSNPacket* packet)
ev->setClientSendEvent(client, regAck);
_gateway->getClientSendQue()->post(ev);
}
if (client->isHoldPingReqest() && client->getWaitREGACKPacketList()->getCount() == 0 )
if (client->isHoldPingReqest()
&& client->getWaitREGACKPacketList()->getCount() == 0)
{
/* send PINGREQ to the broker */
client->resetPingRequest();
@@ -253,10 +265,8 @@ void MQTTSNPublishHandler::handleRegAck( Client* client, MQTTSNPacket* packet)
}
void MQTTSNPublishHandler::handleAggregatePublish(Client* client, MQTTSNPacket* packet)
void MQTTSNPublishHandler::handleAggregatePublish(Client* client,
MQTTSNPacket* packet)
{
int msgId = 0;
MQTTGWPacket* publish = handlePublish(client, packet);
@@ -266,11 +276,15 @@ void MQTTSNPublishHandler::handleAggregatePublish(Client* client, MQTTSNPacket*
{
if (packet->isDuplicate())
{
msgId = _gateway->getAdapterManager()->getAggregater()->getMsgId(client, packet->getMsgId());
msgId =
_gateway->getAdapterManager()->getAggregater()->getMsgId(
client, packet->getMsgId());
}
else
{
msgId = _gateway->getAdapterManager()->getAggregater()->addMessageIdTable(client, packet->getMsgId());
msgId =
_gateway->getAdapterManager()->getAggregater()->addMessageIdTable(
client, packet->getMsgId());
}
publish->setMsgId(msgId);
}
@@ -280,7 +294,8 @@ void MQTTSNPublishHandler::handleAggregatePublish(Client* client, MQTTSNPacket*
}
}
void MQTTSNPublishHandler::handleAggregateAck(Client* client, MQTTSNPacket* packet, int type)
void MQTTSNPublishHandler::handleAggregateAck(Client* client,
MQTTSNPacket* packet, int type)
{
if (type == MQTTSN_PUBREC)
{

View File

@@ -21,13 +21,13 @@
#include <string>
#include <string.h>
using namespace MQTTSNGW;
/*=====================================
Class QoSm1Proxy
=====================================*/
QoSm1Proxy:: QoSm1Proxy(Gateway* gw) : Adapter(gw)
QoSm1Proxy::QoSm1Proxy(Gateway* gw) :
Adapter(gw)
{
_gateway = gw;
}
@@ -37,7 +37,6 @@ QoSm1Proxy::~QoSm1Proxy(void)
}
void QoSm1Proxy::initialize(char* gwName)
{
if (_gateway->hasSecureConnection())
@@ -54,7 +53,6 @@ void QoSm1Proxy::initialize(char* gwName)
_isActive = true;
}
bool QoSm1Proxy::isActive(void)
{
return _isActive;

View File

@@ -45,9 +45,6 @@ private:
bool _isSecure { false };
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWQOSM1PROXY_H_ */

View File

@@ -34,7 +34,8 @@ MQTTSNSubscribeHandler::~MQTTSNSubscribeHandler()
}
MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPacket* packet)
MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client,
MQTTSNPacket* packet)
{
uint8_t dup;
int qos;
@@ -65,7 +66,8 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
topic = _gateway->getTopics()->getTopicById(&topicFilter);
if (topic)
{
topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId());
topic = client->getTopics()->add(topic->getTopicName()->c_str(),
topic->getTopicId());
}
else
{
@@ -74,7 +76,8 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
}
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
subscribe->setSUBSCRIBE((char*) topic->getTopicName()->c_str(),
(uint8_t) qos, (uint16_t) msgId);
}
else if (topicFilter.type == MQTTSN_TOPIC_TYPE_NORMAL)
@@ -85,14 +88,16 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
topic = client->getTopics()->add(&topicFilter);
if (topic == nullptr)
{
WRITELOG("%s Client(%s) can't add the Topic.%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG("%s Client(%s) can't add the Topic.%s\n",
ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
return nullptr;
}
}
topicId = topic->getTopicId();
subscribe = new MQTTGWPacket();
subscribe->setSUBSCRIBE((char*)topic->getTopicName()->c_str(), (uint8_t)qos, (uint16_t)msgId);
subscribe->setSUBSCRIBE((char*) topic->getTopicName()->c_str(),
(uint8_t) qos, (uint16_t) msgId);
}
else //MQTTSN_TOPIC_TYPE_SHORT
{
@@ -120,17 +125,17 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleSubscribe(Client* client, MQTTSNPack
return subscribe;
}
RespExit:
MQTTSNPacket* sSuback = new MQTTSNPacket();
sSuback->setSUBACK(qos, topicFilter.data.id, msgId, MQTTSN_RC_NOT_SUPPORTED);
RespExit: MQTTSNPacket* sSuback = new MQTTSNPacket();
sSuback->setSUBACK(qos, topicFilter.data.id, msgId,
MQTTSN_RC_NOT_SUPPORTED);
evsuback = new Event();
evsuback->setClientSendEvent(client, sSuback);
_gateway->getClientSendQue()->post(evsuback);
return nullptr;
}
MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPacket* packet)
MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client,
MQTTSNPacket* packet)
{
uint16_t msgId;
MQTTSN_topicid topicFilter;
@@ -146,7 +151,6 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
return nullptr;
}
if (topicFilter.type == MQTTSN_TOPIC_TYPE_SHORT)
{
char shortTopic[3];
@@ -198,7 +202,8 @@ MQTTGWPacket* MQTTSNSubscribeHandler::handleUnsubscribe(Client* client, MQTTSNPa
}
}
void MQTTSNSubscribeHandler::handleAggregateSubscribe(Client* client, MQTTSNPacket* packet)
void MQTTSNSubscribeHandler::handleAggregateSubscribe(Client* client,
MQTTSNPacket* packet)
{
MQTTGWPacket* subscribe = handleSubscribe(client, packet);
@@ -207,16 +212,21 @@ void MQTTSNSubscribeHandler::handleAggregateSubscribe(Client* client, MQTTSNPack
int msgId = 0;
if (packet->isDuplicate())
{
msgId = _gateway->getAdapterManager()->getAggregater()->getMsgId(client, packet->getMsgId());
msgId = _gateway->getAdapterManager()->getAggregater()->getMsgId(
client, packet->getMsgId());
}
else
{
msgId = _gateway->getAdapterManager()->getAggregater()->addMessageIdTable(client, packet->getMsgId());
msgId =
_gateway->getAdapterManager()->getAggregater()->addMessageIdTable(
client, packet->getMsgId());
}
if (msgId == 0)
{
WRITELOG("%s MQTTSNSubscribeHandler can't create MessageIdTableElement %s%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG(
"%s MQTTSNSubscribeHandler can't create MessageIdTableElement %s%s\n",
ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
return;
}
@@ -224,7 +234,8 @@ void MQTTSNSubscribeHandler::handleAggregateSubscribe(Client* client, MQTTSNPack
string* topicName = new string(str.data, str.len); // topicName is delete by topic
Topic topic = Topic(topicName, MQTTSN_TOPIC_TYPE_NORMAL);
_gateway->getAdapterManager()->getAggregater()->addAggregateTopic(&topic, client);
_gateway->getAdapterManager()->getAggregater()->addAggregateTopic(
&topic, client);
subscribe->setMsgId(msgId);
Event* ev = new Event();
@@ -233,7 +244,8 @@ void MQTTSNSubscribeHandler::handleAggregateSubscribe(Client* client, MQTTSNPack
}
}
void MQTTSNSubscribeHandler::handleAggregateUnsubscribe(Client* client, MQTTSNPacket* packet)
void MQTTSNSubscribeHandler::handleAggregateUnsubscribe(Client* client,
MQTTSNPacket* packet)
{
MQTTGWPacket* unsubscribe = handleUnsubscribe(client, packet);
if (unsubscribe != nullptr)
@@ -241,23 +253,29 @@ void MQTTSNSubscribeHandler::handleAggregateUnsubscribe(Client* client, MQTTSNPa
int msgId = 0;
if (packet->isDuplicate())
{
msgId = _gateway->getAdapterManager()->getAggregater()->getMsgId(client, packet->getMsgId());
msgId = _gateway->getAdapterManager()->getAggregater()->getMsgId(
client, packet->getMsgId());
}
else
{
msgId = _gateway->getAdapterManager()->getAggregater()->addMessageIdTable(client, packet->getMsgId());
msgId =
_gateway->getAdapterManager()->getAggregater()->addMessageIdTable(
client, packet->getMsgId());
}
if (msgId == 0)
{
WRITELOG("%s MQTTSNUnsubscribeHandler can't create MessageIdTableElement %s%s\n", ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
WRITELOG(
"%s MQTTSNUnsubscribeHandler can't create MessageIdTableElement %s%s\n",
ERRMSG_HEADER, client->getClientId(), ERRMSG_FOOTER);
return;
}
UTF8String str = unsubscribe->getTopic();
string* topicName = new string(str.data, str.len); // topicName is delete by topic
Topic topic = Topic(topicName, MQTTSN_TOPIC_TYPE_NORMAL);
_gateway->getAdapterManager()->getAggregater()->removeAggregateTopic(&topic, client);
_gateway->getAdapterManager()->getAggregater()->removeAggregateTopic(
&topic, client);
unsubscribe->setMsgId(msgId);
Event* ev = new Event();

View File

@@ -42,5 +42,4 @@ private:
}
#endif /* MQTTSNGWSUBSCRIBEHANDLER_H_ */

View File

@@ -166,7 +166,8 @@ bool Topic::isMatch(string* topicName)
void Topic::print(void)
{
WRITELOG("TopicName=%s ID=%d Type=%d\n", _topicName->c_str(), _topicId, _type);
WRITELOG("TopicName=%s ID=%d Type=%d\n", _topicName->c_str(), _topicId,
_type);
}
/*=====================================
@@ -252,7 +253,6 @@ Topic* Topics::add(const char* topicName, uint16_t id)
topicId.data.long_.name = (char*) const_cast<char*>(topicName);
topicId.data.long_.len = strlen(topicName);
Topic* topic = getTopicByName(&topicId);
if (topic)
@@ -331,7 +331,6 @@ Topic* Topics::match(const MQTTSN_topicid* topicid)
return 0;
}
void Topics::eraseNormal(void)
{
Topic* topic = _first;
@@ -398,7 +397,8 @@ 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_topicTypes type)
{
_msgId = msgId;
_topicId = topicId;
@@ -456,9 +456,11 @@ 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_topicTypes type)
{
if ( _cnt > _maxInflight * 2 || ( topicId == 0 && type != MQTTSN_TOPIC_TYPE_SHORT ) )
if (_cnt > _maxInflight * 2
|| (topicId == 0 && type != MQTTSN_TOPIC_TYPE_SHORT))
{
return 0;
}
@@ -534,5 +536,3 @@ void TopicIdMap::clear(void)
_cnt = 0;
}

View File

@@ -24,7 +24,6 @@
namespace MQTTSNGW
{
/*=====================================
Class Topic
======================================*/
@@ -101,7 +100,8 @@ 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_topicTypes type);
void erase(uint16_t msgId);
void clear(void);
private:
@@ -112,9 +112,6 @@ private:
int _maxInflight;
};
}
#endif /* MQTTSNGATEWAY_SRC_MQTTSNGWTOPIC_H_ */

View File

@@ -17,6 +17,6 @@
#ifndef MQTTSNGWVERSION_H_IN_
#define MQTTSNGWVERSION_H_IN_
#define PAHO_GATEWAY_VERSION "1.4.0"
#define PAHO_GATEWAY_VERSION "1.5.0"
#endif /* MQTTSNGWVERSION_H_IN_ */

View File

@@ -272,9 +272,9 @@ void Gateway::initialize(int argc, char** argv)
}
}
/* Initialize adapters */
_adapterManager->initialize( _params.gatewayName, _params.aggregatingGw, _params.forwarder, _params.qosMinus1);
_adapterManager->initialize(_params.gatewayName, _params.aggregatingGw,
_params.forwarder, _params.qosMinus1);
/* Setup ClientList and Predefined topics */
_clientList->initialize(_params.aggregatingGw);
@@ -291,7 +291,8 @@ void Gateway::run(void)
WRITELOG(" *\n%s\n", PAHO_COPYRIGHT3);
WRITELOG(" * Version: %s\n", PAHO_GATEWAY_VERSION);
WRITELOG("%s\n", PAHO_COPYRIGHT4);
WRITELOG("\n%s %s has been started.\n\n", currentDateTime(), _params.gatewayName);
WRITELOG("\n%s %s has been started.\n\n", currentDateTime(),
_params.gatewayName);
WRITELOG(" ConfigFile: %s\n", _params.configName);
if (_params.clientListName)
@@ -305,7 +306,8 @@ void Gateway::run(void)
}
WRITELOG(" SensorN/W: %s\n", _sensorNetwork.getDescription());
WRITELOG(" Broker: %s : %s, %s\n", _params.brokerName, _params.port, _params.portSecure);
WRITELOG(" Broker: %s : %s, %s\n", _params.brokerName, _params.port,
_params.portSecure);
WRITELOG(" RootCApath: %s\n", _params.rootCApath);
WRITELOG(" RootCAfile: %s\n", _params.rootCAfile);
WRITELOG(" CertKey: %s\n", _params.certKey);
@@ -388,9 +390,7 @@ Topics* Gateway::getTopics(void)
bool Gateway::hasSecureConnection(void)
{
return ( _params.certKey
&& _params.privateKey
&& _params.rootCApath
return (_params.certKey && _params.privateKey && _params.rootCApath
&& _params.rootCAfile);
}
/*=====================================
@@ -483,7 +483,6 @@ int EventQue::size()
return sz;
}
/*=====================================
Class Event
=====================================*/
@@ -586,4 +585,3 @@ MQTTGWPacket* Event::getMQTTGWPacket(void)
return _mqttGWPacket;
}

View File

@@ -76,7 +76,8 @@ namespace MQTTSNGW
====================================*/
class Client;
enum EventType{
enum EventType
{
Et_NA = 0,
EtStop,
EtTimeout,
@@ -88,8 +89,8 @@ enum EventType{
EtSensornetSend
};
class Event{
class Event
{
public:
Event();
~Event();
@@ -115,7 +116,6 @@ private:
MQTTGWPacket* _mqttGWPacket { nullptr };
};
/*=====================================
Class EventQue
====================================*/
@@ -136,8 +136,6 @@ private:
Semaphore _sem;
};
/*=====================================
Class GatewayParams
====================================*/
@@ -170,15 +168,14 @@ public:
bool forwarder { false };
};
/*=====================================
Class Gateway
=====================================*/
class AdapterManager;
class ClientList;
class Gateway: public MultiTaskProcess{
class Gateway: public MultiTaskProcess
{
public:
Gateway(void);
~Gateway();

View File

@@ -40,8 +40,7 @@ int main(int argc, char** argv)
{
gateway.initialize(argc, argv);
gateway.run();
}
catch (const std::exception &ex)
} catch (const std::exception &ex)
{
WRITELOG("\nEclipse Paho MQTT-SN Gateway exception: %s\n", ex.what());
WRITELOG("MQTT-SNGateway [-f Config file name]\n");

View File

@@ -19,7 +19,6 @@
using namespace MQTTSNGW;
/*
* Logmonitor process
*/