blob: 611654083234b9c1db14b352cb9464f18cb4637d [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
42 auto bus = sdbusplus::bus::new_default();
Gunnar Mills765725e2017-07-06 14:17:44 -050043 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 Mills72639152017-06-22 15:06:21 -050053
Gunnar Mills765725e2017-07-06 14:17:44 -050054 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 Mills72639152017-06-22 15:06:21 -050069}
70