-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAgentService.h
More file actions
67 lines (50 loc) · 1.37 KB
/
Copy pathAgentService.h
File metadata and controls
67 lines (50 loc) · 1.37 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <atomic>
#include <condition_variable>
#include <chrono>
#include <mutex>
#include <thread>
#pragma once
enum class AgentStatus {
Waiting,
InventoryRunning,
InventoryScheduled,
RateLimited
};
class Agent;
class WebServer;
class AgentService {
public:
AgentService();
~AgentService();
void Run();
void RunOneShot();
void Stop();
AgentStatus Status() const;
std::string StatusString() const;
std::string LastInventoryTime() const;
std::string LastInventoryRequestedTime() const;
bool InventoryRequested() const;
bool InventoryRunning() const;
AgentStatus ScheduleInventory();
// disabled
AgentService(const AgentService&) = delete;
AgentService& operator=(const AgentService& other) = delete;
private:
void _InventoryLoop();
void _SchedulingLoop();
bool _ShouldRunScheduledInventory();
WebServer* fServer;
Agent* fAgent;
std::thread fInventoryThread;
std::thread fSchedulerThread;
std::condition_variable fCondition;
std::mutex fMutex;
std::chrono::system_clock::time_point fLastInventoryRequest;
std::chrono::system_clock::time_point fLastInventoryStart;
std::chrono::system_clock::time_point fLastInventoryEnd;
std::chrono::steady_clock::time_point fNextScheduledInventory;
std::chrono::steady_clock::time_point fLastScheduledInventoryRun;
std::atomic_bool fInventoryRequested;
std::atomic_bool fInventoryRunning;
std::atomic_bool fRunning;
};