#include "bt.hpp"

#include <ipmiblob/blob_errors.hpp>

#include <cstdint>
#include <vector>

namespace host_tool
{

bool BtDataHandler::sendContents(const std::string& input,
                                 std::uint16_t session)
{
    int inputFd = sys->open(input.c_str(), 0);
    if (inputFd < 0)
    {
        return false;
    }

    std::int64_t fileSize = sys->getSize(input.c_str());
    if (fileSize == 0)
    {
        std::fprintf(stderr, "Zero-length file, or other file access error\n");
        return false;
    }

    progress->start(fileSize);

    try
    {
        static constexpr int btBufferLen = 50;
        std::uint8_t readBuffer[btBufferLen];
        int bytesRead;
        std::uint32_t offset = 0;

        do
        {
            bytesRead = sys->read(inputFd, readBuffer, sizeof(readBuffer));
            if (bytesRead > 0)
            {
                /* minorly awkward repackaging. */
                std::vector<std::uint8_t> buffer(&readBuffer[0],
                                                 &readBuffer[bytesRead]);
                blob->writeBytes(session, offset, buffer);
                offset += bytesRead;
                progress->updateProgress(bytesRead);
            }
        } while (bytesRead > 0);
    }
    catch (const ipmiblob::BlobException& b)
    {
        progress->abort();
        sys->close(inputFd);
        return false;
    }

    progress->finish();
    sys->close(inputFd);
    return true;
}

} // namespace host_tool
