2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// AsyncHandle.h
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Asynchronous operations used by GuiScraperSearch and Scraper.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_ASYNC_HANDLE_H
|
|
|
|
#define ES_CORE_ASYNC_HANDLE_H
|
2014-03-19 00:55:37 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <string>
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
enum AsyncHandleStatus {
|
2021-07-07 18:31:46 +00:00
|
|
|
ASYNC_IN_PROGRESS, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-21 12:25:28 +00:00
|
|
|
ASYNC_ERROR,
|
|
|
|
ASYNC_DONE
|
2014-03-19 00:55:37 +00:00
|
|
|
};
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Handle for some asynchronous operations.
|
2014-03-19 00:55:37 +00:00
|
|
|
class AsyncHandle
|
|
|
|
{
|
|
|
|
public:
|
2021-07-07 18:31:46 +00:00
|
|
|
AsyncHandle()
|
|
|
|
: mStatus(ASYNC_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~AsyncHandle() {}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
|
|
|
// Update and return the latest status.
|
2021-07-07 18:31:46 +00:00
|
|
|
AsyncHandleStatus status()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
return mStatus;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// User-friendly string of our current status.
|
|
|
|
// Will return error message if status() == SEARCH_ERROR.
|
2021-07-07 18:31:46 +00:00
|
|
|
std::string getStatusString()
|
2020-06-21 12:25:28 +00:00
|
|
|
{
|
|
|
|
switch (mStatus) {
|
2020-07-13 18:58:25 +00:00
|
|
|
case ASYNC_IN_PROGRESS:
|
|
|
|
return "in progress";
|
|
|
|
case ASYNC_ERROR:
|
|
|
|
return mError;
|
|
|
|
case ASYNC_DONE:
|
|
|
|
return "done";
|
|
|
|
default:
|
|
|
|
return "something impossible has occured; row, row, fight the power";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-19 00:55:37 +00:00
|
|
|
|
|
|
|
protected:
|
2021-07-07 18:31:46 +00:00
|
|
|
void setStatus(AsyncHandleStatus status) { mStatus = status; }
|
|
|
|
void setError(const std::string& error)
|
|
|
|
{
|
|
|
|
setStatus(ASYNC_ERROR);
|
|
|
|
mError = error;
|
|
|
|
}
|
2014-03-19 00:55:37 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string mError;
|
|
|
|
AsyncHandleStatus mStatus;
|
2014-03-19 00:55:37 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_ASYNC_HANDLE_H
|