main: Add verbose option
This makes it possible for the daemon to log each postcode it receives
so we can see the host making progress.
Change-Id: Ifc0c8de5c00a2871240f54cfd8dee5dc986d3c92
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/main.cpp b/main.cpp
index 1b65964..89f0224 100644
--- a/main.cpp
+++ b/main.cpp
@@ -41,7 +41,8 @@
"Usage: %s [-d <DEVICE>]\n"
" -b, --bytes <SIZE> set POST code length to <SIZE> bytes. "
"Default is %zu\n"
- " -d, --device <DEVICE> use <DEVICE> file. Default is '%s'\n\n",
+ " -d, --device <DEVICE> use <DEVICE> file. Default is '%s'\n"
+ " -v, --verbose Prints verbose information while running\n\n",
name, codeSize, snoopFilename);
}
@@ -50,13 +51,18 @@
* POST code available to read.
*/
void PostCodeEventHandler(sdeventplus::source::IO& s, int postFd,
- uint32_t revents, PostReporter* reporter)
+ uint32_t revents, PostReporter* reporter,
+ bool verbose)
{
uint64_t code = 0;
ssize_t readb;
while ((readb = read(postFd, &code, codeSize)) > 0)
{
code = le64toh(code);
+ if (verbose)
+ {
+ fprintf(stderr, "Code: 0x%" PRIx64 "\n", code);
+ }
// HACK: Always send property changed signal even for the same code
// since we are single threaded, external users will never see the
// first value.
@@ -109,16 +115,18 @@
const char* snoopDbus = SNOOP_BUSNAME;
bool deferSignals = true;
+ bool verbose = false;
// clang-format off
static const struct option long_options[] = {
{"bytes", required_argument, NULL, 'b'},
{"device", required_argument, NULL, 'd'},
+ {"verbose", no_argument, NULL, 'v'},
{0, 0, 0, 0}
};
// clang-format on
- while ((opt = getopt_long(argc, argv, "b:d:", long_options, NULL)) != -1)
+ while ((opt = getopt_long(argc, argv, "b:d:v", long_options, NULL)) != -1)
{
switch (opt)
{
@@ -139,6 +147,9 @@
case 'd':
snoopFilename = optarg;
break;
+ case 'v':
+ verbose = true;
+ break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
@@ -168,7 +179,8 @@
sdeventplus::source::IO reporterSource(
event, postFd, EPOLLIN | EPOLLET,
std::bind(PostCodeEventHandler, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, &reporter));
+ std::placeholders::_2, std::placeholders::_3, &reporter,
+ verbose));
// Enable bus to handle incoming IO and bus events
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
rc = event.loop();