mirror of https://github.com/bsnes-emu/bsnes.git
Implement pause RPC
This commit is contained in:
parent
53f828674a
commit
2557fe9732
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue