File: TestPlugin.cc

package info (click to toggle)
drogon 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,096 kB
  • sloc: cpp: 52,222; sh: 249; xml: 20; makefile: 11
file content (34 lines) | stat: -rw-r--r-- 713 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 *
 *  TestPlugin.cc
 *
 */

#include "TestPlugin.h"
#include <thread>
#include <chrono>
using namespace std::chrono_literals;

using namespace drogon;

void TestPlugin::initAndStart(const Json::Value &config)
{
    /// Initialize and start the plugin
    if (config.isNull())
        LOG_DEBUG << "Configuration not defined";
    interval_ = config.get("heartbeat_interval", 1).asInt();
    workThread_ = std::thread([this]() {
        while (!stop_)
        {
            LOG_DEBUG << "TestPlugin heartbeat!";
            std::this_thread::sleep_for(std::chrono::seconds(interval_));
        }
    });
}

void TestPlugin::shutdown()
{
    /// Shutdown the plugin
    stop_ = true;
    workThread_.join();
}