Implement pause RPC

This commit is contained in:
Anaïs Betts 2022-01-09 22:25:54 +01:00
parent 53f828674a
commit 2557fe9732
2 changed files with 55 additions and 7 deletions

View File

@ -213,11 +213,13 @@ public:
// rpc.cpp
struct RpcCommandType { enum : uint {
SaveStateToFile = 1 << 1
SaveStateToFile = 1 << 1,
Pause = 1 << 2,
}; };
struct RpcCommand {
RpcCommandType type;
public:
uint type;
string arg;
};

View File

@ -2,16 +2,50 @@
auto Program::startRpcListener() -> void {
rpcServer.main([&](nall::HTTP::Request& rq) -> nall::HTTP::Response {
OutputDebugStringA("GOT REQUEST\n");
nall::HTTP::Response resp;
resp.setResponseType(200);
resp.setText("hooray!");
resp.header.append("Content-Type", "text/plain");
if (rq.requestType() != nall::HTTP::Request::RequestType::Post) {
resp.setResponseType(200);
resp.header.append("Content-Type", "text/plain");
resp.setText("no");
return resp;
}
rq.body([&](const uint8_t *data, nall::uint size) -> bool {
if (size > 16*1024) {
resp.setResponseType(400);
return true;
}
string content((char*)data);
auto idx = content.find("|");
if (!idx) {
resp.setResponseType(400);
resp.setText("Invalid Command!!\n");
resp.header.append("Content-Type", "text/plain");
return true;
}
auto cmd = content.slice(0, idx.get());
auto arg = content.slice(idx.get() + 1);
RpcCommand rpcCmd;
if (cmd == "pau") {
rpcCmd.type = RpcCommandType::Pause;
pendingRpcCommands.write(rpcCmd);
}
resp.setResponseType(200);
resp.setText("ok\n");
resp.header.append("Content-Type", "text/plain");
return true;
});
return resp;
});
OutputDebugStringA("SETTING UP SERVER\n");
rpcServer.open();
}
@ -21,4 +55,16 @@ auto Program::stopRpcListener() -> void {
auto Program::processRpcCommands() -> void {
rpcServer.scan();
RpcCommand cmd;
if (pendingRpcCommands.read(cmd)) {
if (cmd.type == RpcCommandType::Pause) {
if (presentation.runEmulation.checked()) {
presentation.pauseEmulation.setChecked().doActivate();
} else {
// unpausing can also cancel frame advance mode
presentation.runEmulation.setChecked().doActivate();
}
}
}
}