Update for Issue #132

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2018-08-25 08:38:21 +09:00
parent 7fae038296
commit 42125d173b
5 changed files with 76 additions and 55 deletions

View File

@@ -16,14 +16,13 @@
# #
# ClientID, TopicName, TopicID # ClientID, TopicName, TopicID
# #
# This file is consist from two sections. # Topics is common to all clients, ClientID should be COMMON.
# One for QoS-1 PUBLISH Clients, the other for another clients.
# #
# pre-defined-topics for Clients # pre-defined-topics for Clients
# #
GatewayTestClient,ty4tw/predefinedTopic1, 1 COMMON,ty4tw/predefinedTopic1, 1
GatewayTestClient,ty4tw/predefinedTopic2, 2 GatewayTestClient,ty4tw/predefinedTopic2, 2
GatewayTestClient,ty4tw/predefinedTopic3, 3 GatewayTestClient,ty4tw/predefinedTopic3, 3
@@ -31,16 +30,7 @@ GatewayTestClient,ty4tw/predefinedTopic3, 3
# pre-defined-topics for QoS-1 clients. # pre-defined-topics for QoS-1 clients.
# #
QoS-1_Client01,ty4tw/proxy/predefTopic1, 1
QoS-1_Client01,ty4tw/proxy/predefTopic2, 2
QoS-1_Client01,ty4tw/proxy/predefTopic3, 3
QoS-1_Client02,ty4tw/proxy/predefTopic1, 1
QoS-1_Client02,ty4tw/proxy/predefTopic3, 2
QoS-1_Client02,ty4tw/proxy/predefTopic3, 3
QoS-1_Client03,ty4tw/proxy/predefTopic1, 1
QoS-1_Client03,ty4tw/proxy/predefTopic2, 2
QoS-1_Client03,ty4tw/proxy/predefTopic3, 3
QoS-1_Client03,ty4tw/proxy/predefTopic4, 1
QoS-1_Client03,ty4tw/proxy/predefTopic5, 2
QoS-1_Client03,ty4tw/proxy/predefTopic6, 3

View File

@@ -24,6 +24,8 @@ extern Gateway* theGateway;
/*===================================== /*=====================================
Class ClientList Class ClientList
=====================================*/ =====================================*/
const char* common_topic = "COMMON";
ClientList::ClientList() ClientList::ClientList()
{ {
_clientCnt = 0; _clientCnt = 0;
@@ -413,6 +415,13 @@ Client* ClientList::createClient(SensorNetAddress* addr, MQTTSNString* clientId,
} }
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 ( clientId->cstring == common_topic )
{
_gateway->getTopics()->add((const char*)topicName.c_str(), topicId);
return 0;
}
else
{ {
Client* client = getClient(clientId); Client* client = getClient(clientId);
@@ -459,6 +468,7 @@ Client* ClientList::createPredefinedTopic( MQTTSNString* clientId, string topicN
client->_hasPredefTopic = true; client->_hasPredefTopic = true;
return client; return client;
} }
}
uint16_t ClientList::getClientCount() uint16_t ClientList::getClientCount()
{ {

View File

@@ -79,10 +79,18 @@ MQTTGWPacket* MQTTSNPublishHandler::handlePublish(Client* client, MQTTSNPacket*
else else
{ {
topic = client->getTopics()->getTopicById(&topicid); topic = client->getTopics()->getTopicById(&topicid);
if ( !topic )
{
topic = _gateway->getTopics()->getTopicById(&topicid);
if ( topic )
{
topic = client->getTopics()->add(topic->getTopicName()->c_str(), topic->getTopicId());
}
}
if( !topic && qos == 3 ) if( !topic && qos == 3 )
{ {
WRITELOG("%s Invali 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; return nullptr;
} }

View File

@@ -37,6 +37,7 @@ Gateway::Gateway(void)
_packetEventQue.setMaxSize(MAX_INFLIGHTMESSAGES * MAX_CLIENTS); _packetEventQue.setMaxSize(MAX_INFLIGHTMESSAGES * MAX_CLIENTS);
_clientList = new ClientList(); _clientList = new ClientList();
_adapterManager = new AdapterManager(this); _adapterManager = new AdapterManager(this);
_topics = new Topics();
} }
Gateway::~Gateway() Gateway::~Gateway()
@@ -103,6 +104,11 @@ Gateway::~Gateway()
{ {
delete _clientList; delete _clientList;
} }
if ( _topics )
{
delete _topics;
}
} }
int Gateway::getParam(const char* parameter, char* value) int Gateway::getParam(const char* parameter, char* value)
@@ -312,6 +318,11 @@ AdapterManager* Gateway::getAdapterManager(void)
return _adapterManager; return _adapterManager;
} }
Topics* Gateway::getTopics(void)
{
return _topics;
}
bool Gateway::hasSecureConnection(void) bool Gateway::hasSecureConnection(void)
{ {
return ( _params.certKey return ( _params.certKey

View File

@@ -191,6 +191,7 @@ public:
AdapterManager* getAdapterManager(void); AdapterManager* getAdapterManager(void);
int getParam(const char* parameter, char* value); int getParam(const char* parameter, char* value);
bool hasSecureConnection(void); bool hasSecureConnection(void);
Topics* getTopics(void);
private: private:
GatewayParams _params; GatewayParams _params;
@@ -201,6 +202,7 @@ private:
LightIndicator _lightIndicator; LightIndicator _lightIndicator;
SensorNetwork _sensorNetwork; SensorNetwork _sensorNetwork;
AdapterManager* _adapterManager {nullptr}; AdapterManager* _adapterManager {nullptr};
Topics* _topics;
}; };
} }