Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 1 | #include "config.h" |
Patrick Williams | 1334b7b | 2021-02-22 17:15:12 -0600 | [diff] [blame] | 2 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 3 | #include "snmp_conf_manager.hpp" |
| 4 | |
George Liu | 4caedfb | 2022-05-10 16:26:53 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdbusplus/server/manager.hpp> |
| 8 | |
| 9 | #include <memory> |
| 10 | |
| 11 | /* Need a custom deleter for freeing up sd_event */ |
| 12 | struct EventDeleter |
| 13 | { |
Patrick Williams | 1334b7b | 2021-02-22 17:15:12 -0600 | [diff] [blame] | 14 | void operator()(sd_event* event) const |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 15 | { |
Ratan Gupta | 34d129a | 2021-12-04 21:04:51 +0530 | [diff] [blame] | 16 | sd_event_unref(event); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 17 | } |
| 18 | }; |
| 19 | |
| 20 | using EventPtr = std::unique_ptr<sd_event, EventDeleter>; |
| 21 | |
Ratan Gupta | 34d129a | 2021-12-04 21:04:51 +0530 | [diff] [blame] | 22 | int main(int /*argc*/, char** /*argv[]*/) |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 23 | { |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 24 | auto bus = sdbusplus::bus::new_default(); |
| 25 | |
Patrick Williams | 1334b7b | 2021-02-22 17:15:12 -0600 | [diff] [blame] | 26 | sd_event* event = nullptr; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 27 | auto r = sd_event_default(&event); |
| 28 | if (r < 0) |
| 29 | { |
George Liu | 4caedfb | 2022-05-10 16:26:53 +0800 | [diff] [blame] | 30 | lg2::error("Error creating a default sd_event handler: {RC}", "RC", r); |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 31 | return r; |
| 32 | } |
| 33 | |
| 34 | EventPtr eventPtr{event}; |
| 35 | event = nullptr; |
| 36 | |
| 37 | // Attach the bus to sd_event to service user requests |
| 38 | bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); |
| 39 | |
| 40 | // Add sdbusplus Object Manager for the 'root' path of the snmp. |
| 41 | sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK_SNMP); |
| 42 | bus.request_name(BUSNAME_NETWORK_SNMP); |
| 43 | |
| 44 | auto manager = std::make_unique<phosphor::network::snmp::ConfManager>( |
| 45 | bus, OBJ_NETWORK_SNMP); |
| 46 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 47 | manager->restoreClients(); |
| 48 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 49 | return sd_event_loop(eventPtr.get()); |
| 50 | } |