mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
64 lines
2 KiB
C++
64 lines
2 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include <map>
|
|
#include <functional>
|
|
|
|
#include "Common/System/System.h"
|
|
|
|
typedef std::function<void(const char *responseString, int responseValue)> RequestCallback;
|
|
|
|
// Platforms often have to process requests asynchronously, on wildly different threads.
|
|
// (Especially Android...)
|
|
// This acts as bridge and buffer.
|
|
class RequestManager {
|
|
public:
|
|
// These requests are to be handled by platform implementations.
|
|
// The callback you pass in will be called on the main thread later.
|
|
bool MakeSystemRequest(SystemRequestType type, RequestCallback callback, const std::string ¶m1, const std::string ¶m2);
|
|
|
|
// Called by the platform implementation, when it's finished with a request.
|
|
void PostSystemSuccess(int requestId, const char *responseString, int responseValue = 0);
|
|
void PostSystemFailure(int requestId);
|
|
|
|
// This must be called every frame from the beginning of NativeUpdate().
|
|
// This will call the callback of any finished requests.
|
|
void ProcessRequests();
|
|
|
|
// Unclear if we need this...
|
|
void Clear();
|
|
|
|
private:
|
|
struct PendingRequest {
|
|
SystemRequestType type;
|
|
RequestCallback callback;
|
|
};
|
|
|
|
std::map<int, RequestCallback> callbackMap_;
|
|
std::mutex callbackMutex_;
|
|
|
|
struct PendingResponse {
|
|
std::string responseString;
|
|
int responseValue;
|
|
RequestCallback callback;
|
|
};
|
|
|
|
int idCounter_ = 0;
|
|
std::vector<PendingResponse> pendingResponses_;
|
|
std::mutex responseMutex_;
|
|
};
|
|
|
|
const char *RequestTypeAsString(SystemRequestType type);
|
|
|
|
extern RequestManager g_requestManager;
|
|
|
|
// Wrappers for easy requests.
|
|
// NOTE: Semantics have changed - this no longer calls the callback on cancellation.
|
|
inline void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, RequestCallback callback) {
|
|
g_requestManager.MakeSystemRequest(SystemRequestType::INPUT_TEXT_MODAL, callback, title, defaultValue);
|
|
}
|
|
|
|
inline void System_BrowseForImage(const std::string &title, RequestCallback callback) {
|
|
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_IMAGE, callback, title, "");
|
|
}
|