tools/progress: Add finish and abort functions
We have external progress handlers which would like to implement these
functions, in order to update the screen upon completion or error.
Change-Id: I2df4654d5e2092407a83d2c8bbb020dcce84ac50
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/tools/bt.cpp b/tools/bt.cpp
index 26c333b..eeac686 100644
--- a/tools/bt.cpp
+++ b/tools/bt.cpp
@@ -49,10 +49,12 @@
}
catch (const ipmiblob::BlobException& b)
{
+ progress->abort();
sys->close(inputFd);
return false;
}
+ progress->finish();
sys->close(inputFd);
return true;
}
diff --git a/tools/lpc.cpp b/tools/lpc.cpp
index cd48844..d552b6a 100644
--- a/tools/lpc.cpp
+++ b/tools/lpc.cpp
@@ -117,6 +117,7 @@
auto readBuffer = std::make_unique<std::uint8_t[]>(host_lpc_buf.length);
if (nullptr == readBuffer)
{
+ progress->abort();
sys->close(inputFd);
std::fprintf(stderr, "Unable to allocate memory for read buffer.\n");
return false;
@@ -156,10 +157,12 @@
}
catch (const ipmiblob::BlobException& b)
{
+ progress->abort();
sys->close(inputFd);
return false;
}
+ progress->finish();
sys->close(inputFd);
return true;
}
diff --git a/tools/net.cpp b/tools/net.cpp
index 1c7a407..f6a44d8 100644
--- a/tools/net.cpp
+++ b/tools/net.cpp
@@ -91,6 +91,7 @@
{
std::fprintf(stderr, "Couldn't parse address %s with port %s: %s\n",
host.c_str(), port.c_str(), gai_strerror(ret));
+ progress->abort();
return false;
}
@@ -111,6 +112,7 @@
if (addr == nullptr)
{
std::fprintf(stderr, "Failed to connect\n");
+ progress->abort();
return false;
}
}
@@ -127,6 +129,7 @@
{
std::fprintf(stderr, "Failed to send data to BMC: %s\n",
strerror(errno));
+ progress->abort();
return false;
}
else if (bytesSent > 0)
@@ -147,9 +150,11 @@
}
catch (const ipmiblob::BlobException& b)
{
+ progress->abort();
return false;
}
+ progress->finish();
return true;
}
diff --git a/tools/p2a.cpp b/tools/p2a.cpp
index 090b9bd..b92887f 100644
--- a/tools/p2a.cpp
+++ b/tools/p2a.cpp
@@ -128,6 +128,7 @@
}
} while (bytesRead > 0);
+ progress->finish();
return true;
}
diff --git a/tools/progress.cpp b/tools/progress.cpp
index aafb1de..68b31cc 100644
--- a/tools/progress.cpp
+++ b/tools/progress.cpp
@@ -39,4 +39,10 @@
currentBytes = 0;
}
+void ProgressStdoutIndicator::finish()
+{}
+
+void ProgressStdoutIndicator::abort()
+{}
+
} // namespace host_tool
diff --git a/tools/progress.hpp b/tools/progress.hpp
index f884d62..2027faf 100644
--- a/tools/progress.hpp
+++ b/tools/progress.hpp
@@ -15,6 +15,8 @@
*/
virtual void updateProgress(std::int64_t bytes) = 0;
virtual void start(std::int64_t bytes) = 0;
+ virtual void finish() = 0;
+ virtual void abort() = 0;
};
/**
@@ -29,6 +31,8 @@
void updateProgress(std::int64_t bytes) override;
void start(std::int64_t bytes) override;
+ void finish() override;
+ void abort() override;
private:
std::int64_t totalBytes = 0;
diff --git a/tools/test/progress_mock.hpp b/tools/test/progress_mock.hpp
index 80c0af1..a43d9b3 100644
--- a/tools/test/progress_mock.hpp
+++ b/tools/test/progress_mock.hpp
@@ -12,8 +12,10 @@
class ProgressMock : public ProgressInterface
{
public:
- MOCK_METHOD1(updateProgress, void(std::int64_t));
- MOCK_METHOD1(start, void(std::int64_t));
+ MOCK_METHOD(void, updateProgress, (std::int64_t), (override));
+ MOCK_METHOD(void, start, (std::int64_t), (override));
+ MOCK_METHOD(void, finish, (), (override));
+ MOCK_METHOD(void, abort, (), (override));
};
} // namespace host_tool