blob: 7fa3b05180a76f3ba93551afaaca7dc7bbe21b0b [file] [log] [blame]
Ratan Guptaa54d8f82017-09-08 17:05:46 +05301#include "config.h"
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +05302#include "network_manager.hpp"
3#include "rtnetlink_server.hpp"
Ratan Guptaa54d8f82017-09-08 17:05:46 +05304#include "timer.hpp"
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +05305
6#include <memory>
7
8#include <phosphor-logging/log.hpp>
Ratan Guptacb7098d2017-04-14 17:46:05 +05309#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/manager.hpp>
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053011
12namespace phosphor
13{
14namespace network
15{
16
17std::unique_ptr<phosphor::network::Manager> manager = nullptr;
Ratan Guptaa54d8f82017-09-08 17:05:46 +053018std::unique_ptr<phosphor::network::Timer> refreshTimer = nullptr;
19
20void refreshObjects()
21{
22 manager->createChildObjects();
23}
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053024
25} //namespace network
26} //namespace phosphor
Ratan Gupta8c834932017-04-14 16:30:24 +053027
28int main(int argc, char *argv[])
29{
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053030 using namespace phosphor::logging;
31
Ratan Guptaa54d8f82017-09-08 17:05:46 +053032 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 Guptacb7098d2017-04-14 17:46:05 +053038 auto bus = sdbusplus::bus::new_default();
39
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053040 // 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 Guptacb7098d2017-04-14 17:46:05 +053055 // Add sdbusplus Object Manager for the 'root' path of the network manager.
56 sdbusplus::server::manager::manager objManager(bus, OBJ_NETWORK);
Ratan Gupta26e87a02017-08-18 01:08:40 +053057 bus.request_name(BUSNAME_NETWORK);
Ratan Guptacb7098d2017-04-14 17:46:05 +053058
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053059 phosphor::network::manager =
60 std::make_unique<phosphor::network::Manager>(bus,
61 OBJ_NETWORK,
62 NETWORK_CONF_DIR);
Ratan Guptacb7098d2017-04-14 17:46:05 +053063
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053064 phosphor::network::rtnetlink::Server svr(eventPtr);
65
66 phosphor::network::manager->createChildObjects();
Ratan Gupta29b0e432017-05-25 12:51:40 +053067
Ratan Gupta0f9dc1b2017-09-03 17:57:50 +053068 return svr.run();
Ratan Gupta8c834932017-04-14 16:30:24 +053069}
Ratan Guptaa54d8f82017-09-08 17:05:46 +053070