#include "configuration.hpp" #include "logger.hpp" #include "system.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include class App { public: App(boost::asio::io_context& ioc, const Configuration& config, sd_bus* custom_bus = nullptr) : ioc(ioc), devMonitor(ioc), config(config) { if (!custom_bus) { bus = std::make_shared(ioc); } else { bus = std::make_shared(ioc, custom_bus); } objServer = std::make_shared(bus); bus->request_name("xyz.openbmc_project.VirtualMedia"); objManager = std::make_shared( *bus, "/xyz/openbmc_project/VirtualMedia"); devMonitor.run([](const NBDDevice& device, StateChange change) { // placeholder for some future actions }); } private: boost::asio::io_context& ioc; std::shared_ptr bus; std::shared_ptr objServer; std::shared_ptr objManager; DeviceMonitor devMonitor; const Configuration& config; }; int main() { Configuration config("/etc/virtual-media.json"); if (!config.valid) return -1; boost::asio::io_context ioc; boost::asio::signal_set signals(ioc, SIGINT, SIGTERM); signals.async_wait( [&ioc](const boost::system::error_code&, const int&) { ioc.stop(); }); sd_bus* b = nullptr; #if defined(CUSTOM_DBUS_PATH) #pragma message("You are using custom DBUS path set to " CUSTOM_DBUS_PATH) sd_bus_new(&b); sd_bus_set_bus_client(b, true); sd_bus_set_address(b, CUSTOM_DBUS_PATH); sd_bus_start(b); #endif sd_bus_default_system(&b); App app(ioc, config, b); ioc.run(); return 0; }