/**
 * Reads stdin looking for a string, and coalesces that buffer until stdin
 * is calm for the passed in number of seconds.
 */

#include <unistd.h>

#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/source/io.hpp>
#include <sdeventplus/utility/timer.hpp>

#include <array>
#include <chrono>
#include <cstdio>
#include <string>
#include <utility>

using sdeventplus::Clock;
using sdeventplus::ClockId;
using sdeventplus::Event;
using sdeventplus::source::IO;

constexpr auto clockId = ClockId::RealTime;
using Timer = sdeventplus::utility::Timer<clockId>;

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s [seconds]\n", argv[0]);
        return 1;
    }

    std::chrono::seconds delay(std::stoul(argv[1]));

    auto event = Event::get_default();

    std::string content;
    auto timerCb = [&](Timer&) {
        printf("%s", content.c_str());
        content.clear();
    };
    Timer timer(event, std::move(timerCb));

    auto ioCb = [&](IO&, int fd, uint32_t) {
        std::array<char, 4096> buffer;
        ssize_t bytes = read(fd, buffer.data(), 4096);
        if (bytes <= 0)
        {
            printf("%s", content.c_str());
            event.exit(bytes < 0);
            return;
        }
        content.append(buffer.data(), bytes);
        timer.restartOnce(delay);
    };
    IO ioSource(event, STDIN_FILENO, EPOLLIN, std::move(ioCb));

    return event.loop();
}
