-
Notifications
You must be signed in to change notification settings - Fork 40
/
agent.cpp
119 lines (91 loc) · 2.51 KB
/
agent.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2013 Arista Networks, Inc. All rights reserved.
// Arista Networks, Inc. Confidential and Proprietary.
#include <cstdlib> // for abort()
#include <functional> // For dummy agent_id impl
#include "eos/agent.h"
#include "impl.h"
namespace eos {
agent_handler::agent_handler(agent_mgr * mgr) :
base_handler<agent_mgr, agent_handler>(mgr) {
mgr_->add_handler(this);
}
void agent_handler::on_initialized() {
// Default implementation: do nothing.
}
void agent_handler::on_agent_enabled(bool enabled) {
// Default implementation calls agent_shutdown_complete_is
// automatically when the agent is disabled
if(!enabled) {
get_agent_mgr()->agent_shutdown_complete_is(true);
}
}
void agent_handler::on_agent_option(std::string const & name,
std::string const & value) {
// Default implementation: do nothing.
}
std::string
agent_handler::on_agent_rpc(std::string const & command) {
// Default implementation: do nothing.
return "";
}
static void call_on_initialized(agent_handler* handler) {
handler->on_initialized();
}
class agent_mgr_impl : public agent_mgr {
public:
agent_mgr_impl() {
}
void on_initialized() {
handler_foreach(call_on_initialized);
}
bool enabled() const {
return true;
}
void exit() {
impl.stop_loop();
}
void agent_shutdown_complete_is(bool complete) {
}
std::string agent_option(std::string const & name) const {
return "";
}
bool agent_option_exists(std::string const & name) const {
return false;
}
agent_option_iter_t agent_option_iter() const {
agent_option_iter_t * nop = 0;
return *nop; // TODO: No op impl.
}
std::string
status(std::string const & key) const {
return "";
}
agent_status_iter_t status_iter() const {
agent_status_iter_t * nop = 0;
return *nop; // TODO: No op impl.
}
void
status_set(std::string const & key, std::string const & value) {
}
void
status_del(std::string const & key) {
}
seconds_t
agent_uptime() {
return 0;
}
};
void handle_agent_initialize(agent_mgr * mgr) {
static_cast<agent_mgr_impl*>(mgr)->on_initialized();
}
DEFINE_STUB_MGR_CTOR(agent_mgr)
void delete_agent_mgr(agent_mgr * mgr) {
delete mgr;
}
uint32_t agent_mgr::id(const char * agent_name) {
// Dummy implementation. Eventually we should base this of
// /proc/run or some other universal lookup.
std::hash<const char *> h;
return h(agent_name);
}
}