Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 1 | #include "config.h" |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 2 | #include "network_manager.hpp" |
| 3 | #include "rtnetlink_server.hpp" |
Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 4 | #include "timer.hpp" |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 5 | |
| 6 | #include <memory> |
| 7 | |
| 8 | #include <phosphor-logging/log.hpp> |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/server/manager.hpp> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace network |
| 15 | { |
| 16 | |
| 17 | std::unique_ptr<phosphor::network::Manager> manager = nullptr; |
Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 18 | std::unique_ptr<phosphor::network::Timer> refreshTimer = nullptr; |
| 19 | |
| 20 | void refreshObjects() |
| 21 | { |
| 22 | manager->createChildObjects(); |
| 23 | } |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 24 | |
| 25 | } //namespace network |
| 26 | } //namespace phosphor |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 27 | |
| 28 | int main(int argc, char *argv[]) |
| 29 | { |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 30 | using namespace phosphor::logging; |
| 31 | |
Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 32 | std::function<void()> func( |
| 33 | std::bind(&phosphor::network::refreshObjects)); |
| 34 | |
| 35 | phosphor::network::refreshTimer = |
| 36 | std::make_unique<phosphor::network::Timer>(func); |
| 37 | |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 38 | auto bus = sdbusplus::bus::new_default(); |
| 39 | |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 40 | // Need sd_event to watch for OCC device errors |
| 41 | sd_event* event = nullptr; |
| 42 | auto r = sd_event_default(&event); |
| 43 | if (r < 0) |
| 44 | { |
| 45 | log<level::ERR>("Error creating a default sd_event handler"); |
| 46 | return r; |
| 47 | } |
| 48 | |
| 49 | phosphor::network::EventPtr eventPtr{event}; |
| 50 | event = nullptr; |
| 51 | |
| 52 | // Attach the bus to sd_event to service user requests |
| 53 | bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); |
| 54 | |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 55 | // Add sdbusplus Object Manager for the 'root' path of the network manager. |
| 56 | sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK); |
Ratan Gupta | 26e87a0 | 2017-08-18 01:08:40 +0530 | [diff] [blame] | 57 | bus.request_name(BUSNAME_NETWORK); |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 58 | |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 59 | phosphor::network::manager = |
| 60 | std::make_unique<phosphor::network::Manager>(bus, |
| 61 | OBJ_NETWORK, |
| 62 | NETWORK_CONF_DIR); |
Ratan Gupta | cb7098d | 2017-04-14 17:46:05 +0530 | [diff] [blame] | 63 | |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 64 | phosphor::network::rtnetlink::Server svr(eventPtr); |
| 65 | |
| 66 | phosphor::network::manager->createChildObjects(); |
Ratan Gupta | 29b0e43 | 2017-05-25 12:51:40 +0530 | [diff] [blame] | 67 | |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 68 | return svr.run(); |
Ratan Gupta | 8c83493 | 2017-04-14 16:30:24 +0530 | [diff] [blame] | 69 | } |
Ratan Gupta | a54d8f8 | 2017-09-08 17:05:46 +0530 | [diff] [blame] | 70 | |