mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 15:36:51 +01:00
BugFix: Que template
Update: Add ProcessFramework test and change Makefile for it. Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -33,14 +33,15 @@ BrokerSecurePortNo=8883
|
|||||||
ClientAuthentication=NO
|
ClientAuthentication=NO
|
||||||
#ClientsList=/path/to/your_clients.conf
|
#ClientsList=/path/to/your_clients.conf
|
||||||
|
|
||||||
RootCAfile=/path/to/your_Root_CA.crt
|
#RootCAfile=/path/to/your_Root_CA.crt
|
||||||
RootCApath=/path/to/your_certs_directory/
|
#RootCApath=/path/to/your_certs_directory/
|
||||||
|
#CertsDirectory=/path/to/your_client_certs_directory/
|
||||||
|
|
||||||
GatewayID=1
|
GatewayID=1
|
||||||
GatewayName=PahoGateway-01
|
GatewayName=PahoGateway-01
|
||||||
KeepAlive=900
|
KeepAlive=900
|
||||||
#LoginID=
|
#LoginID=your_ID
|
||||||
#Password=
|
#Password=your_Password
|
||||||
|
|
||||||
# UDP
|
# UDP
|
||||||
GatewayPortNo=10000
|
GatewayPortNo=10000
|
||||||
@@ -50,6 +51,7 @@ MulticastPortNo=1883
|
|||||||
# XBee
|
# XBee
|
||||||
Baudrate=38400
|
Baudrate=38400
|
||||||
SerialDevice=/dev/ttyUSB0
|
SerialDevice=/dev/ttyUSB0
|
||||||
|
ApiMode=2
|
||||||
```
|
```
|
||||||
|
|
||||||
**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection.
|
**BrokerName** to specify a domain name of the Broker, and **BrokerPortNo** is a port No of the Broker. **BrokerSecurePortNo** is for TLS connection.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ BrokerSecurePortNo=8883
|
|||||||
ClientAuthentication=NO
|
ClientAuthentication=NO
|
||||||
#ClientsList=/path/to/your_clients.conf
|
#ClientsList=/path/to/your_clients.conf
|
||||||
|
|
||||||
RootCAfile=/etc/ssl/certs/ca-certificates.crt
|
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
|
||||||
#RootCApath=/etc/ssl/certs/
|
#RootCApath=/etc/ssl/certs/
|
||||||
#CertsDirectory=/usr/share/GW/IoTcerts/
|
#CertsDirectory=/usr/share/GW/IoTcerts/
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ void BrokerRecvTask::run(void)
|
|||||||
/* post a BrokerRecvEvent */
|
/* post a BrokerRecvEvent */
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrokerRecvEvent(client, packet);
|
ev->setBrokerRecvEvent(client, packet);
|
||||||
if ( _gateway->getPacketEventQue()->post(ev) == 1 )
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
{
|
{
|
||||||
delete ev;
|
delete ev;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
|
|
||||||
#define ERRNO_APL_03 13 // Task Initialize Error
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
Class BrokerRecvTask
|
Class BrokerRecvTask
|
||||||
=====================================*/
|
=====================================*/
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
#define ERRNO_APL_04 14 // Task Initialize Error
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
Class BrokerSendTask
|
Class BrokerSendTask
|
||||||
=====================================*/
|
=====================================*/
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void ClientRecvTask::run()
|
|||||||
log(0, packet);
|
log(0, packet);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setBrodcastEvent(packet);
|
ev->setBrodcastEvent(packet);
|
||||||
if ( _gateway->getPacketEventQue()->post(ev) == 1 )
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
{
|
{
|
||||||
delete ev;
|
delete ev;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ void ClientRecvTask::run()
|
|||||||
log(client, packet);
|
log(client, packet);
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setClientRecvEvent(client,packet);
|
ev->setClientRecvEvent(client,packet);
|
||||||
if ( _gateway->getPacketEventQue()->post(ev) == 1 )
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
{
|
{
|
||||||
delete ev;
|
delete ev;
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ void ClientRecvTask::run()
|
|||||||
client->setClientAddress(_sensorNetwork->getSenderAddress());
|
client->setClientAddress(_sensorNetwork->getSenderAddress());
|
||||||
ev = new Event();
|
ev = new Event();
|
||||||
ev->setClientRecvEvent(client, packet);
|
ev->setClientRecvEvent(client, packet);
|
||||||
if ( _gateway->getPacketEventQue()->post(ev) == 1 )
|
if ( _gateway->getPacketEventQue()->post(ev) == 0 )
|
||||||
{
|
{
|
||||||
delete ev;
|
delete ev;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <signal.h>
|
||||||
#include "MQTTSNGWDefines.h"
|
#include "MQTTSNGWDefines.h"
|
||||||
#include "Threading.h"
|
#include "Threading.h"
|
||||||
|
|
||||||
@@ -164,6 +165,7 @@ public:
|
|||||||
_head = 0;
|
_head = 0;
|
||||||
_tail = 0;
|
_tail = 0;
|
||||||
_cnt = 0;
|
_cnt = 0;
|
||||||
|
_maxSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Que()
|
~Que()
|
||||||
@@ -213,28 +215,33 @@ public:
|
|||||||
|
|
||||||
int post(T* t)
|
int post(T* t)
|
||||||
{
|
{
|
||||||
QueElement<T>* elm = new QueElement<T>(t);
|
if ( t && ( _maxSize == 0 || size() < _maxSize ))
|
||||||
if ( _head )
|
|
||||||
{
|
{
|
||||||
if ( _tail == _head )
|
QueElement<T>* elm = new QueElement<T>(t);
|
||||||
|
if ( _head )
|
||||||
{
|
{
|
||||||
|
if ( _tail == _head )
|
||||||
|
{
|
||||||
|
elm->_prev = _tail;
|
||||||
|
_tail = elm;
|
||||||
|
_head->_next = elm;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tail->_next = elm;
|
||||||
elm->_prev = _tail;
|
elm->_prev = _tail;
|
||||||
_tail = elm;
|
_tail = elm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tail->_next = elm;
|
_head = elm;
|
||||||
elm->_prev = _tail;
|
_tail = elm;
|
||||||
_tail = elm;
|
|
||||||
}
|
}
|
||||||
|
_cnt++;
|
||||||
|
return _cnt;
|
||||||
}
|
}
|
||||||
else
|
return 0;
|
||||||
{
|
|
||||||
_head = elm;
|
|
||||||
_tail = elm;
|
|
||||||
}
|
|
||||||
_cnt++;
|
|
||||||
return _cnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int size(void)
|
int size(void)
|
||||||
@@ -242,8 +249,14 @@ public:
|
|||||||
return _cnt;
|
return _cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMaxSize(int maxSize)
|
||||||
|
{
|
||||||
|
_maxSize = maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _cnt;
|
int _cnt;
|
||||||
|
int _maxSize;
|
||||||
QueElement<T>* _head;
|
QueElement<T>* _head;
|
||||||
QueElement<T>* _tail;
|
QueElement<T>* _tail;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ GatewayParams* Gateway::getGWParams(void)
|
|||||||
=====================================*/
|
=====================================*/
|
||||||
EventQue::EventQue()
|
EventQue::EventQue()
|
||||||
{
|
{
|
||||||
_maxSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventQue::~EventQue()
|
EventQue::~EventQue()
|
||||||
@@ -198,7 +198,7 @@ EventQue::~EventQue()
|
|||||||
|
|
||||||
void EventQue::setMaxSize(uint16_t maxSize)
|
void EventQue::setMaxSize(uint16_t maxSize)
|
||||||
{
|
{
|
||||||
_maxSize = maxSize;
|
_que.setMaxSize((int)maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event* EventQue::wait(void)
|
Event* EventQue::wait(void)
|
||||||
@@ -245,15 +245,12 @@ Event* EventQue::timedwait(uint16_t millsec)
|
|||||||
|
|
||||||
int EventQue::post(Event* ev)
|
int EventQue::post(Event* ev)
|
||||||
{
|
{
|
||||||
if ( ev && ( _maxSize == 0 || size() < _maxSize ) )
|
int rc = 0;
|
||||||
{
|
_mutex.lock();
|
||||||
_mutex.lock();
|
rc = _que.post(ev);
|
||||||
_que.post(ev);
|
_sem.post();
|
||||||
_sem.post();
|
_mutex.unlock();
|
||||||
_mutex.unlock();
|
return rc;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int EventQue::size()
|
int EventQue::size()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace MQTTSNGW
|
|||||||
/*=================================
|
/*=================================
|
||||||
* Starting prompt
|
* Starting prompt
|
||||||
==================================*/
|
==================================*/
|
||||||
#define GATEWAY_VERSION " * Version: 0.5.0"
|
#define GATEWAY_VERSION " * Version: 0.6.0"
|
||||||
|
|
||||||
#define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway"
|
#define PAHO_COPYRIGHT0 " * MQTT-SN Transparent Gateway"
|
||||||
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
#define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
|
||||||
@@ -138,7 +138,6 @@ private:
|
|||||||
Que<Event> _que;
|
Que<Event> _que;
|
||||||
Mutex _mutex;
|
Mutex _mutex;
|
||||||
Semaphore _sem;
|
Semaphore _sem;
|
||||||
uint16_t _maxSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ bool Thread::equals(pthread_t *t1, pthread_t *t2)
|
|||||||
|
|
||||||
int Thread::start(void)
|
int Thread::start(void)
|
||||||
{
|
{
|
||||||
Runnable *runnable = this;
|
Runnable* runnable = this;
|
||||||
return pthread_create(&_threadID, 0, _run, runnable);
|
return pthread_create(&_threadID, 0, _run, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#include "MQTTSNGWDefines.h"
|
||||||
|
|
||||||
namespace MQTTSNGW
|
namespace MQTTSNGW
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
|||||||
XBee::XBee(){
|
XBee::XBee(){
|
||||||
_serialPort = new SerialPort();
|
_serialPort = new SerialPort();
|
||||||
_respCd = 0;
|
_respCd = 0;
|
||||||
|
_respId = 0;
|
||||||
_dataLen = 0;
|
_dataLen = 0;
|
||||||
_frameId = 0;
|
_frameId = 0;
|
||||||
_apiMode = 2;
|
_apiMode = 2;
|
||||||
|
|||||||
@@ -25,18 +25,17 @@ using namespace MQTTSNGW;
|
|||||||
/*
|
/*
|
||||||
* Gateway Process
|
* Gateway Process
|
||||||
*/
|
*/
|
||||||
Gateway* gateway = new Gateway();
|
Gateway* gw = new Gateway();
|
||||||
PacketHandleTask* t0 = new PacketHandleTask(gateway);
|
PacketHandleTask task1(gw);
|
||||||
ClientRecvTask* t1 = new ClientRecvTask(gateway);
|
ClientRecvTask task2(gw);
|
||||||
ClientSendTask* t2 = new ClientSendTask(gateway);
|
ClientSendTask task3(gw);
|
||||||
BrokerRecvTask* t3 = new BrokerRecvTask(gateway);
|
BrokerRecvTask task4(gw);
|
||||||
BrokerSendTask* t4 = new BrokerSendTask(gateway);
|
BrokerSendTask task5(gw);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
gateway->initialize(argc, argv);
|
gw->initialize(argc, argv);
|
||||||
gateway->run();
|
gw->run();
|
||||||
delete gateway;
|
delete gw;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
151
MQTTSNGateway/src/tests/TestProcessFramework.cpp
Normal file
151
MQTTSNGateway/src/tests/TestProcessFramework.cpp
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <cassert>
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
#define ARGV "./testPFW"
|
||||||
|
#define CONFDIR "./"
|
||||||
|
#define CONF "gateway.conf"
|
||||||
|
|
||||||
|
const char* currentDateTime(void);
|
||||||
|
|
||||||
|
TestProcessFramework::TestProcessFramework()
|
||||||
|
{
|
||||||
|
theMultiTaskProcess = this;
|
||||||
|
theProcess = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestProcessFramework::~TestProcessFramework()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessFramework::initialize(int argc, char** argv)
|
||||||
|
{
|
||||||
|
MultiTaskProcess::initialize(argc, argv);
|
||||||
|
assert(0 == strcmp(CONFDIR, getConfigDirName()->c_str()));
|
||||||
|
assert(0 == strcmp(CONF, getConfigFileName()->c_str()));
|
||||||
|
resetRingBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessFramework::run(void)
|
||||||
|
{
|
||||||
|
char value[256];
|
||||||
|
int* v = 0;
|
||||||
|
int i = 0;
|
||||||
|
Timer tm;
|
||||||
|
TestQue que;
|
||||||
|
|
||||||
|
assert(1 == getArgc() || 3 == getArgc() );
|
||||||
|
assert(0 == strcmp(ARGV, *getArgv()));
|
||||||
|
getParam("BrokerName", value);
|
||||||
|
assert(0 == strcmp("iot.eclipse.org", value));
|
||||||
|
|
||||||
|
for ( i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
putLog("Test RingBuffer %d ", 1234567890);
|
||||||
|
}
|
||||||
|
putLog("\n\nRingBuffer Test complieted. Enter CTRL+C\n");
|
||||||
|
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
v = new int(i);
|
||||||
|
que.post(v);
|
||||||
|
}
|
||||||
|
assert( 10 == que.size());
|
||||||
|
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
assert(i == *que.front());
|
||||||
|
int* p = que.front();
|
||||||
|
if ( p )
|
||||||
|
{
|
||||||
|
assert(i == *p);
|
||||||
|
que.pop();
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(0 == que.front());
|
||||||
|
assert(0 == que.size());
|
||||||
|
|
||||||
|
que.setMaxSize(5);
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
v = new int(i);
|
||||||
|
que.post(v);
|
||||||
|
assert( 5 >= que.size());
|
||||||
|
}
|
||||||
|
for ( i = 0; i < 10; i++ )
|
||||||
|
{
|
||||||
|
int* p = que.front();
|
||||||
|
if ( p )
|
||||||
|
{
|
||||||
|
que.pop();
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s Timer start\n", currentDateTime());
|
||||||
|
tm.start(1000);
|
||||||
|
while (!tm.isTimeup());
|
||||||
|
printf("%s Timer 1sec\n", currentDateTime());
|
||||||
|
|
||||||
|
tm.start();
|
||||||
|
while (!tm.isTimeup(1000));
|
||||||
|
printf("%s Timer 1sec\n", currentDateTime());
|
||||||
|
|
||||||
|
MultiTaskProcess::run();
|
||||||
|
printf("ProcessFramework test complited.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestQue::TestQue()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TestQue::~TestQue()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int* TestQue::front(void)
|
||||||
|
{
|
||||||
|
return _que.front();
|
||||||
|
}
|
||||||
|
void TestQue::pop(void)
|
||||||
|
{
|
||||||
|
_que.pop();
|
||||||
|
}
|
||||||
|
int TestQue::size(void)
|
||||||
|
{
|
||||||
|
return _que.size();
|
||||||
|
}
|
||||||
|
void TestQue::setMaxSize(int maxsize)
|
||||||
|
{
|
||||||
|
_que.setMaxSize(maxsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestQue::post(int* val)
|
||||||
|
{
|
||||||
|
_que.post(val);
|
||||||
|
}
|
||||||
50
MQTTSNGateway/src/tests/TestProcessFramework.h
Normal file
50
MQTTSNGateway/src/tests/TestProcessFramework.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#ifndef TESTPROCESSFRAMEWORK_H_
|
||||||
|
#define TESTPROCESSFRAMEWORK_H_
|
||||||
|
|
||||||
|
#include "MQTTSNGWProcess.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace MQTTSNGW
|
||||||
|
{
|
||||||
|
class TestProcessFramework: public MultiTaskProcess{
|
||||||
|
public:
|
||||||
|
TestProcessFramework();
|
||||||
|
~TestProcessFramework();
|
||||||
|
virtual void initialize(int argc, char** argv);
|
||||||
|
void run(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestQue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestQue();
|
||||||
|
~TestQue();
|
||||||
|
void post(int*);
|
||||||
|
int* front(void);
|
||||||
|
void pop(void);
|
||||||
|
int size(void);
|
||||||
|
void setMaxSize(int maxsize);
|
||||||
|
private:
|
||||||
|
Que<int> _que;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TESTPROCESSFRAMEWORK_H_ */
|
||||||
49
MQTTSNGateway/src/tests/TestTask.cpp
Normal file
49
MQTTSNGateway/src/tests/TestTask.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "TestTask.h"
|
||||||
|
#include "Threading.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
TestTask::TestTask(TestProcessFramework* proc)
|
||||||
|
{
|
||||||
|
proc->attach((Thread*)this);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestTask::~TestTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTask::initialize(int argc, char** argv)
|
||||||
|
{
|
||||||
|
printf("Task initialize complite.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTask::run(void)
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
printf("Task is running. Enter CTRL+C \n");
|
||||||
|
if (theProcess->checkSignal() == SIGINT)
|
||||||
|
{
|
||||||
|
throw Exception("Terminated by CTL-C");
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
MQTTSNGateway/src/tests/TestTask.h
Normal file
42
MQTTSNGateway/src/tests/TestTask.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#ifndef TESTTASK_H_
|
||||||
|
#define TESTTASK_H_
|
||||||
|
|
||||||
|
#include "Threading.h"
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
|
||||||
|
namespace MQTTSNGW
|
||||||
|
{
|
||||||
|
|
||||||
|
class TestTask: public Thread
|
||||||
|
{
|
||||||
|
MAGIC_WORD_FOR_THREAD;
|
||||||
|
;
|
||||||
|
public:
|
||||||
|
TestTask(TestProcessFramework* proc);
|
||||||
|
~TestTask();
|
||||||
|
void initialize(int argc, char** argv);
|
||||||
|
void run(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* TESTTASK_H_ */
|
||||||
31
MQTTSNGateway/src/tests/mainTestProcessFramework.cpp
Normal file
31
MQTTSNGateway/src/tests/mainTestProcessFramework.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/**************************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
**************************************************************************************/
|
||||||
|
#include "TestProcessFramework.h"
|
||||||
|
#include "TestTask.h"
|
||||||
|
|
||||||
|
using namespace MQTTSNGW;
|
||||||
|
|
||||||
|
TestProcessFramework* proc = new TestProcessFramework();
|
||||||
|
TestTask* task = new TestTask(proc);
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
proc->initialize(argc, argv);
|
||||||
|
proc->run();
|
||||||
|
delete proc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
43
Makefile
43
Makefile
@@ -4,6 +4,9 @@ APPL := mainGateway
|
|||||||
LPROGNAME := MQTT-SNLogmonitor
|
LPROGNAME := MQTT-SNLogmonitor
|
||||||
LAPPL := mainLogmonitor
|
LAPPL := mainLogmonitor
|
||||||
|
|
||||||
|
TESTPROGNAME := testPFW
|
||||||
|
TESTAPPL := mainTestProcessFramework
|
||||||
|
|
||||||
CONFIG := MQTTSNGateway/gateway.conf
|
CONFIG := MQTTSNGateway/gateway.conf
|
||||||
CLIENTS := MQTTSNGateway/clients.conf
|
CLIENTS := MQTTSNGateway/clients.conf
|
||||||
|
|
||||||
@@ -12,6 +15,7 @@ SUBDIR := MQTTSNPacket/src
|
|||||||
|
|
||||||
OS := linux
|
OS := linux
|
||||||
SENSORNET := udp
|
SENSORNET := udp
|
||||||
|
TEST := tests
|
||||||
|
|
||||||
CPPSRCS := \
|
CPPSRCS := \
|
||||||
$(SRCDIR)/MQTTGWConnectionHandler.cpp \
|
$(SRCDIR)/MQTTGWConnectionHandler.cpp \
|
||||||
@@ -34,7 +38,10 @@ $(SRCDIR)/MQTTSNGWSubscribeHandler.cpp \
|
|||||||
$(SRCDIR)/$(OS)/$(SENSORNET)/SensorNetwork.cpp \
|
$(SRCDIR)/$(OS)/$(SENSORNET)/SensorNetwork.cpp \
|
||||||
$(SRCDIR)/$(OS)/Timer.cpp \
|
$(SRCDIR)/$(OS)/Timer.cpp \
|
||||||
$(SRCDIR)/$(OS)/Network.cpp \
|
$(SRCDIR)/$(OS)/Network.cpp \
|
||||||
$(SRCDIR)/$(OS)/Threading.cpp
|
$(SRCDIR)/$(OS)/Threading.cpp \
|
||||||
|
$(SRCDIR)/$(TEST)/TestProcessFramework.cpp \
|
||||||
|
$(SRCDIR)/$(TEST)/TestTask.cpp
|
||||||
|
|
||||||
|
|
||||||
CSRCS := $(SUBDIR)/MQTTSNConnectClient.c \
|
CSRCS := $(SUBDIR)/MQTTSNConnectClient.c \
|
||||||
$(SUBDIR)/MQTTSNConnectServer.c \
|
$(SUBDIR)/MQTTSNConnectServer.c \
|
||||||
@@ -51,13 +58,14 @@ $(SUBDIR)/MQTTSNUnsubscribeServer.c
|
|||||||
CXX := g++
|
CXX := g++
|
||||||
CPPFLAGS +=
|
CPPFLAGS +=
|
||||||
|
|
||||||
INCLUDES += -IMQTTSNGateway/src \
|
INCLUDES += -I$(SRCDIR) \
|
||||||
-IMQTTSNGateway/src/$(OS) \
|
-I$(SRCDIR)/$(OS) \
|
||||||
-IMQTTSNGateway/src/$(OS)/$(SENSORNET) \
|
-I$(SRCDIR)/$(OS)/$(SENSORNET) \
|
||||||
-IMQTTSNPacket/src
|
-I$(SUBDIR) \
|
||||||
|
-I$(SRCDIR)/$(TEST)
|
||||||
|
|
||||||
DEFS :=
|
DEFS :=
|
||||||
LIBS +=
|
LIBS += -L/usr/local/lib
|
||||||
LDFLAGS :=
|
LDFLAGS :=
|
||||||
CXXFLAGS := -Wall -O3 -std=c++11
|
CXXFLAGS := -Wall -O3 -std=c++11
|
||||||
LDADD := -lpthread -lssl -lcrypto
|
LDADD := -lpthread -lssl -lcrypto
|
||||||
@@ -65,17 +73,22 @@ OUTDIR := Build
|
|||||||
|
|
||||||
PROG := $(OUTDIR)/$(PROGNAME)
|
PROG := $(OUTDIR)/$(PROGNAME)
|
||||||
LPROG := $(OUTDIR)/$(LPROGNAME)
|
LPROG := $(OUTDIR)/$(LPROGNAME)
|
||||||
|
TPROG := $(OUTDIR)/$(TESTPROGNAME)
|
||||||
|
|
||||||
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
||||||
OBJS += $(CSRCS:%.c=$(OUTDIR)/%.o)
|
OBJS += $(CSRCS:%.c=$(OUTDIR)/%.o)
|
||||||
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
||||||
DEPS += $(CSRCS:%.c=$(OUTDIR)/%.d)
|
DEPS += $(CSRCS:%.c=$(OUTDIR)/%.d)
|
||||||
|
|
||||||
.PHONY: install clean
|
.PHONY: install clean exectest
|
||||||
|
|
||||||
all: $(PROG) $(LPROG)
|
all: $(PROG) $(LPROG) $(TPROG)
|
||||||
|
|
||||||
monitor: $(LPROG)
|
monitor: $(LPROG)
|
||||||
|
|
||||||
|
test: $(TPROG) $(LPROG) exectest
|
||||||
|
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
||||||
@@ -84,6 +97,10 @@ $(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
|||||||
$(LPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(LAPPL).o
|
$(LPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(LAPPL).o
|
||||||
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
$(TPROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(TEST)/$(TESTAPPL).o
|
||||||
|
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
|
||||||
$(OUTDIR)/$(SRCDIR)/%.o:$(SRCDIR)/%.cpp
|
$(OUTDIR)/$(SRCDIR)/%.o:$(SRCDIR)/%.cpp
|
||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
@@ -92,6 +109,10 @@ $(OUTDIR)/$(SRCDIR)/$(APPL).o:$(SRCDIR)/$(APPL).cpp
|
|||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
|
$(OUTDIR)/$(SRCDIR)/$(TEST)/$(TESTAPPL).o:$(SRCDIR)/$(TEST)/$(TESTAPPL).cpp
|
||||||
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
$(OUTDIR)/$(SRCDIR)/$(LAPPL).o:$(SRCDIR)/$(LAPPL).cpp
|
$(OUTDIR)/$(SRCDIR)/$(LAPPL).o:$(SRCDIR)/$(LAPPL).cpp
|
||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
@@ -108,5 +129,9 @@ install:
|
|||||||
cp -pf $(LPROG) ../
|
cp -pf $(LPROG) ../
|
||||||
cp -pf $(CONFIG) ../
|
cp -pf $(CONFIG) ../
|
||||||
cp -pf $(CLIENTS) ../
|
cp -pf $(CLIENTS) ../
|
||||||
|
|
||||||
|
exectest:
|
||||||
|
cp -pf $(CONFIG) $(OUTDIR)
|
||||||
|
cd $(OUTDIR); ./$(TESTPROGNAME) -f ./gateway.conf
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user