Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 1 | #include <iostream> |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 2 | #include <systemd/sd-event.h> |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 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; |
Gunnar Mills | 5f10110 | 2017-06-29 13:07:39 -0500 | [diff] [blame] | 9 | using namespace phosphor::gpio::presence; |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 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 | } |
Gunnar Mills | 80292bb | 2017-07-05 16:34:51 -0500 | [diff] [blame] | 41 | |
| 42 | auto bus = sdbusplus::bus::new_default(); |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 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; |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 53 | |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 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; |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 69 | } |
| 70 | |