mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-14 16:06:51 +01:00
BugFix: stop Process mechanism of ProcessFramework.
Update: DISCONNECT procedure for NonActive clients. Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <Timer.h>
|
||||
#include <exception>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include "MQTTSNGWProcess.h"
|
||||
#include "Threading.h"
|
||||
|
||||
@@ -118,6 +119,28 @@ void Process::initialize(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
void Process::putLog(const char* format, ...)
|
||||
{
|
||||
_mt.lock();
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vsprintf(_rbdata, format, arg);
|
||||
va_end(arg);
|
||||
if (strlen(_rbdata))
|
||||
{
|
||||
if ( _log > 0 )
|
||||
{
|
||||
_rb->put(_rbdata);
|
||||
_rbsem->post();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s", _rbdata);
|
||||
}
|
||||
}
|
||||
_mt.unlock();
|
||||
}
|
||||
|
||||
int Process::getArgc()
|
||||
{
|
||||
return _argc;
|
||||
@@ -183,28 +206,6 @@ int Process::getParam(const char* parameter, char* value)
|
||||
return -2;
|
||||
}
|
||||
|
||||
void Process::putLog(const char* format, ...)
|
||||
{
|
||||
_mt.lock();
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vsprintf(_rbdata, format, arg);
|
||||
va_end(arg);
|
||||
if (strlen(_rbdata))
|
||||
{
|
||||
if ( _log > 0 )
|
||||
{
|
||||
_rb->put(_rbdata);
|
||||
_rbsem->post();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s", _rbdata);
|
||||
}
|
||||
}
|
||||
_mt.unlock();
|
||||
}
|
||||
|
||||
const char* Process::getLog()
|
||||
{
|
||||
int len = 0;
|
||||
@@ -249,6 +250,7 @@ MultiTaskProcess::MultiTaskProcess()
|
||||
{
|
||||
theMultiTaskProcess = this;
|
||||
_threadCount = 0;
|
||||
_stopCount = 0;
|
||||
}
|
||||
|
||||
MultiTaskProcess::~MultiTaskProcess()
|
||||
@@ -275,28 +277,43 @@ void MultiTaskProcess::run(void)
|
||||
|
||||
try
|
||||
{
|
||||
_stopProcessEvent.wait();
|
||||
}
|
||||
catch (Exception* ex)
|
||||
{
|
||||
for (int i = 0; i < _threadCount; i++)
|
||||
while(true)
|
||||
{
|
||||
if ( _threadList[i] )
|
||||
if (theProcess->checkSignal() == SIGINT)
|
||||
{
|
||||
_threadList[i]->cancel();;
|
||||
return;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
catch(Exception* ex)
|
||||
{
|
||||
ex->writeMessage();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Semaphore* MultiTaskProcess::getStopProcessEvent(void)
|
||||
void MultiTaskProcess::waitStop(void)
|
||||
{
|
||||
return &_stopProcessEvent;
|
||||
while (_stopCount < _threadCount)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void MultiTaskProcess::threadStoped(void)
|
||||
{
|
||||
_mutex.lock();
|
||||
_stopCount++;
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void MultiTaskProcess::attach(Thread* thread)
|
||||
{
|
||||
_mutex.lock();
|
||||
if (_threadCount < MQTTSNGW_MAX_TASK)
|
||||
{
|
||||
_threadList[_threadCount] = thread;
|
||||
@@ -304,8 +321,10 @@ void MultiTaskProcess::attach(Thread* thread)
|
||||
}
|
||||
else
|
||||
{
|
||||
_mutex.unlock();
|
||||
throw Exception("Full of Threads");
|
||||
}
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
int MultiTaskProcess::getParam(const char* parameter, char* value)
|
||||
|
||||
Reference in New Issue
Block a user