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 | |
Matt Spinler | 902d1c3 | 2017-09-01 11:03:02 -0500 | [diff] [blame^] | 42 | std::vector<Driver> driverList; |
| 43 | |
| 44 | //TODO: next commit, fill in driverList |
| 45 | |
Gunnar Mills | 80292bb | 2017-07-05 16:34:51 -0500 | [diff] [blame] | 46 | auto bus = sdbusplus::bus::new_default(); |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 47 | auto rc = 0; |
| 48 | sd_event* event = nullptr; |
| 49 | rc = sd_event_default(&event); |
| 50 | if (rc < 0) |
| 51 | { |
| 52 | log<level::ERR>("Error creating a default sd_event handler"); |
| 53 | return rc; |
| 54 | } |
| 55 | EventPtr eventP{event}; |
| 56 | event = nullptr; |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 57 | |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 58 | auto name = options["name"]; |
Matt Spinler | 902d1c3 | 2017-09-01 11:03:02 -0500 | [diff] [blame^] | 59 | Presence presence( |
| 60 | bus, inventory, path, std::stoul(key), name, eventP, driverList); |
Gunnar Mills | 765725e | 2017-07-06 14:17:44 -0500 | [diff] [blame] | 61 | |
| 62 | while (true) |
| 63 | { |
| 64 | // -1 denotes wait forever |
| 65 | rc = sd_event_run(eventP.get(), (uint64_t) - 1); |
| 66 | if (rc < 0) |
| 67 | { |
| 68 | log<level::ERR>("Failure in processing request", |
| 69 | entry("ERROR=%s", strerror(-rc))); |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | return rc; |
Gunnar Mills | 7263915 | 2017-06-22 15:06:21 -0500 | [diff] [blame] | 74 | } |
| 75 | |