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 | |
| 5 | #include <phosphor-logging/log.hpp> |
| 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 | { |
| 24 | using namespace phosphor::logging; |
| 25 | |
| 26 | auto bus = sdbusplus::bus::new_default(); |
| 27 | |
Patrick Williams | 1334b7b | 2021-02-22 17:15:12 -0600 | [diff] [blame] | 28 | sd_event* event = nullptr; |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 29 | auto r = sd_event_default(&event); |
| 30 | if (r < 0) |
| 31 | { |
| 32 | log<level::ERR>("Error creating a default sd_event handler"); |
| 33 | return r; |
| 34 | } |
| 35 | |
| 36 | EventPtr eventPtr{event}; |
| 37 | event = nullptr; |
| 38 | |
| 39 | // Attach the bus to sd_event to service user requests |
| 40 | bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); |
| 41 | |
| 42 | // Add sdbusplus Object Manager for the 'root' path of the snmp. |
| 43 | sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK_SNMP); |
| 44 | bus.request_name(BUSNAME_NETWORK_SNMP); |
| 45 | |
| 46 | auto manager = std::make_unique<phosphor::network::snmp::ConfManager>( |
| 47 | bus, OBJ_NETWORK_SNMP); |
| 48 | |
Ratan Gupta | 212f53e | 2018-04-30 17:28:05 +0530 | [diff] [blame] | 49 | manager->restoreClients(); |
| 50 | |
Ratan Gupta | 1dc9178 | 2018-04-19 16:47:12 +0530 | [diff] [blame] | 51 | return sd_event_loop(eventPtr.get()); |
| 52 | } |