drogon/examples/simple_example/TestPlugin.cc

35 lines
713 B
C++
Raw Normal View History

2019-03-29 07:34:14 +00:00
/**
*
* TestPlugin.cc
*
*/
#include "TestPlugin.h"
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
2019-03-29 07:34:14 +00:00
using namespace drogon;
void TestPlugin::initAndStart(const Json::Value &config)
{
/// Initialize and start the plugin
2019-05-18 12:39:57 +00:00
if (config.isNull())
2019-03-29 07:34:14 +00:00
LOG_DEBUG << "Configuration not defined";
2019-11-21 03:27:47 +00:00
interval_ = config.get("heartbeat_interval", 1).asInt();
workThread_ = std::thread([this]() {
while (!stop_)
2019-03-29 07:34:14 +00:00
{
LOG_DEBUG << "TestPlugin heartbeat!";
std::this_thread::sleep_for(std::chrono::seconds(interval_));
2019-03-29 07:34:14 +00:00
}
});
}
2019-05-18 12:39:57 +00:00
void TestPlugin::shutdown()
2019-03-29 07:34:14 +00:00
{
/// Shutdown the plugin
2019-11-21 03:27:47 +00:00
stop_ = true;
workThread_.join();
2019-03-29 07:34:14 +00:00
}