blob: 5808c34e6aa6453270074890aa287c69a0080e5b [file] [log] [blame]
Gunnar Mills72639152017-06-22 15:06:21 -05001#include <iostream>
Gunnar Mills765725e2017-07-06 14:17:44 -05002#include <systemd/sd-event.h>
Gunnar Mills72639152017-06-22 15:06:21 -05003#include <phosphor-logging/log.hpp>
4#include "argument.hpp"
5#include "gpio_presence.hpp"
6
7using namespace phosphor::logging;
8using namespace phosphor::gpio;
Gunnar Mills5f101102017-06-29 13:07:39 -05009using namespace phosphor::gpio::presence;
Gunnar Mills72639152017-06-22 15:06:21 -050010
11int 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 Mills80292bb2017-07-05 16:34:51 -050041
Matt Spinler902d1c32017-09-01 11:03:02 -050042 std::vector<Driver> driverList;
43
44 //TODO: next commit, fill in driverList
45
Gunnar Mills80292bb2017-07-05 16:34:51 -050046 auto bus = sdbusplus::bus::new_default();
Gunnar Mills765725e2017-07-06 14:17:44 -050047 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 Mills72639152017-06-22 15:06:21 -050057
Gunnar Mills765725e2017-07-06 14:17:44 -050058 auto name = options["name"];
Matt Spinler902d1c32017-09-01 11:03:02 -050059 Presence presence(
60 bus, inventory, path, std::stoul(key), name, eventP, driverList);
Gunnar Mills765725e2017-07-06 14:17:44 -050061
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 Mills72639152017-06-22 15:06:21 -050074}
75