Skip to content
API Documentation
BastionGuard™
scan_worker.cpp
Go to the documentation of this file.
1#include "scan_worker.hpp"
2#include "scanner_engine.hpp"
3
4#include <iostream>
5
6ScanWorker::ScanWorker() = default;
7
13
14void ScanWorker::start(const std::string& path,
16 ProgressCallback progress_cb)
17{
18 if (running_)
19 return;
20
21 cancel_requested_ = false;
22 running_ = true;
23
24 thread_ = std::thread([this, path, cb, progress_cb]()
25 {
26 ScanReport report;
27
28 try
29 {
30 ScannerEngine engine;
31
32 report = engine.run_scan(
33 path,
34 [this, progress_cb](const ScanProgress& p)
35 {
37 return;
38
39 if (progress_cb)
40 progress_cb(p);
41 },
42 [this]()
43 {
44 return cancel_requested_.load();
45 }
46 );
47 }
48 catch (const std::exception& e)
49 {
50 report.logs.push_back(
51 std::string("ScanWorker exception: ") + e.what());
52 }
53 catch (...)
54 {
55 report.logs.push_back("ScanWorker unknown exception");
56 }
57
58 running_ = false;
59
60 if (!cancel_requested_ && cb)
61 cb(report);
62 });
63}
64
66{
67 return running_;
68}
69
71{
72 if (thread_.joinable())
73 thread_.join();
74}
75
80
82{
83 return cancel_requested_;
84}
std::atomic< bool > cancel_requested_
void request_cancel()
std::function< void(const ScanReport &)> CompletionCallback
bool cancel_requested() const
void start(const std::string &path, CompletionCallback cb, ProgressCallback progress_cb={})
std::atomic< bool > running_
std::thread thread_
std::function< void(const ScanProgress &)> ProgressCallback
bool running() const
ScanReport run_scan(const std::string &path, ProgressCallback progress_cb, std::function< bool()> cancel_cb)
std::vector< std::string > logs
Definition models.hpp:41