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:
tomoaki
2016-10-01 08:47:10 +09:00
parent e3dd9fa01a
commit 76f58a60a3
19 changed files with 415 additions and 57 deletions

View 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);
}

View 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_ */

View 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);
}
}

View 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_ */

View 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;
}