54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "Service.h"
|
|
#include <iostream>
|
|
|
|
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
namespace Util
|
|
{
|
|
|
|
void Service::start()
|
|
{
|
|
if (isRunning())
|
|
return;
|
|
|
|
_pThread = new Poco::Thread();
|
|
try
|
|
{
|
|
_pThread->start(*this);
|
|
}
|
|
catch (Poco::Exception& e)
|
|
{
|
|
std::cout << " --> Service: Poco::Exception: " << e.displayText() << "(" << e.what() << ")" << std::endl;
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
std::cout << " --> Service: std::exception: " << e.what() << std::endl;
|
|
}
|
|
}
|
|
|
|
void Service::stop()
|
|
{
|
|
if (isRunning())
|
|
{
|
|
cancel();
|
|
_pThread->join();
|
|
_pThread.reset();
|
|
reset();
|
|
}
|
|
}
|
|
|
|
bool Service::isRunning() const
|
|
{
|
|
return !_pThread.isNull() && _pThread->isRunning();
|
|
}
|
|
|
|
}
|