1 #include <iostream> 2 #include <systemd/sd-event.h> 3 #include <phosphor-logging/log.hpp> 4 #include "argument.hpp" 5 #include "gpio_presence.hpp" 6 7 using namespace phosphor::logging; 8 using namespace phosphor::gpio; 9 using namespace phosphor::gpio::presence; 10 11 int main(int argc, char* argv[]) 12 { 13 auto options = ArgumentParser(argc, argv); 14 15 auto inventory = options["inventory"]; 16 auto key = options["key"]; 17 auto path = options["path"]; 18 if (argc < 4) 19 { 20 std::cerr << "Too few arguments\n"; 21 options.usage(argv); 22 } 23 24 if (inventory == ArgumentParser::emptyString) 25 { 26 std::cerr << "Inventory argument required\n"; 27 options.usage(argv); 28 } 29 30 if (key == ArgumentParser::emptyString) 31 { 32 std::cerr << "GPIO key argument required\n"; 33 options.usage(argv); 34 } 35 36 if (path == ArgumentParser::emptyString) 37 { 38 std::cerr << "Device path argument required\n"; 39 options.usage(argv); 40 } 41 42 auto bus = sdbusplus::bus::new_default(); 43 auto rc = 0; 44 sd_event* event = nullptr; 45 rc = sd_event_default(&event); 46 if (rc < 0) 47 { 48 log<level::ERR>("Error creating a default sd_event handler"); 49 return rc; 50 } 51 EventPtr eventP{event}; 52 event = nullptr; 53 54 auto name = options["name"]; 55 Presence presence(bus, inventory, path, std::stoul(key), name, eventP); 56 57 while (true) 58 { 59 // -1 denotes wait forever 60 rc = sd_event_run(eventP.get(), (uint64_t) - 1); 61 if (rc < 0) 62 { 63 log<level::ERR>("Failure in processing request", 64 entry("ERROR=%s", strerror(-rc))); 65 break; 66 } 67 } 68 return rc; 69 } 70 71