mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 17:23:40 +01:00
Allowed -> disallowed, at -> [], code cleanup
This commit is contained in:
1 parent
af8480683a
commit
3fbaea3b9a
3 files changed
+41
-48
No files matched your search
@@ -141,19 +141,13 @@ void HandleDebuggerRequest(const http::Request &request) {
|
||||
SetupDebuggerLock();
|
||||
|
||||
WebSocketClientInfo client_info;
|
||||
auto& allowed_config = client_info.allowed;
|
||||
auto& disallowed_config = client_info.disallowed;
|
||||
|
||||
GameBroadcaster game;
|
||||
LogBroadcaster logger;
|
||||
InputBroadcaster input;
|
||||
SteppingBroadcaster stepping;
|
||||
|
||||
// By default everything is on
|
||||
allowed_config.emplace("logger", true);
|
||||
allowed_config.emplace("game", true);
|
||||
allowed_config.emplace("stepping", true);
|
||||
allowed_config.emplace("input", true);
|
||||
|
||||
std::unordered_map<std::string, DebuggerEventHandler> eventHandlers;
|
||||
std::vector<DebuggerSubscriber *> subscriberData;
|
||||
for (auto init : subscribers) {
|
||||
@@ -200,13 +194,13 @@ void HandleDebuggerRequest(const http::Request &request) {
|
||||
|
||||
// The client can explicitly ask not to be notified about some events
|
||||
// so we check the client settings first
|
||||
if (allowed_config.at("logger"))
|
||||
if (!disallowed_config["logger"])
|
||||
logger.Broadcast(ws);
|
||||
if (allowed_config.at("game"))
|
||||
if (!disallowed_config["game"])
|
||||
game.Broadcast(ws);
|
||||
if (allowed_config.at("stepping"))
|
||||
if (!disallowed_config["stepping"])
|
||||
stepping.Broadcast(ws);
|
||||
if (allowed_config.at("input"))
|
||||
if (!disallowed_config["input"])
|
||||
input.Broadcast(ws);
|
||||
|
||||
for (size_t i = 0; i < subscribers.size(); ++i) {
|
||||
|
||||
@@ -32,21 +32,21 @@ DebuggerSubscriber *WebSocketClientConfigInit(DebuggerEventHandlerMap & map) {
|
||||
// No parameters.
|
||||
//
|
||||
// Response (same event name):
|
||||
// - allowed: object with boolean fields:
|
||||
// - logger: whether logger events are allowed
|
||||
// - game: whether game events are allowed
|
||||
// - stepping: whether stepping events are allowed
|
||||
// - input: whether input events are allowed
|
||||
// - disallowed: object with optional boolean fields:
|
||||
// - logger: whether logger events are disallowed
|
||||
// - game: whether game events are disallowed
|
||||
// - stepping: whether stepping events are disallowed
|
||||
// - input: whether input events are disallowed
|
||||
void WebSocketBroadcastConfigGet(DebuggerRequest & req) {
|
||||
JsonWriter &json = req.Respond();
|
||||
const auto& allowed_config = req.client->allowed;
|
||||
const auto& disallowed_config = req.client->disallowed;
|
||||
|
||||
json.pushDict("allowed");
|
||||
json.pushDict("disallowed");
|
||||
|
||||
json.writeBool("logger", allowed_config.at("logger"));
|
||||
json.writeBool("game", allowed_config.at("game"));
|
||||
json.writeBool("stepping", allowed_config.at("stepping"));
|
||||
json.writeBool("input", allowed_config.at("input"));
|
||||
for (const auto[name, status] : disallowed_config) {
|
||||
if (status)
|
||||
json.writeBool(name, true);
|
||||
}
|
||||
|
||||
json.end();
|
||||
}
|
||||
@@ -54,35 +54,34 @@ void WebSocketBroadcastConfigGet(DebuggerRequest & req) {
|
||||
// Update the current client broadcast configuration (broadcast.config.set)
|
||||
//
|
||||
// Parameters:
|
||||
// - allowed: object with boolean fields (all of them are optional):
|
||||
// - disallowed: object with boolean fields (all of them are optional):
|
||||
// - logger: new logger config state
|
||||
// - game: new game config state
|
||||
// - stepping: new stepping config state
|
||||
// - input: new input config state
|
||||
//
|
||||
// Response (same event name):
|
||||
// - allowed: object with boolean fields:
|
||||
// - logger: whether logger events are now allowed
|
||||
// - game: whether game events are now allowed
|
||||
// - stepping: whether stepping events are bow allowed
|
||||
// - input: whether input events are now allowed
|
||||
// - disallowed: object with optional boolean fields:
|
||||
// - logger: whether logger events are now disallowed
|
||||
// - game: whether game events are now disallowed
|
||||
// - stepping: whether stepping events are now disallowed
|
||||
// - input: whether input events are now disallowed
|
||||
void WebSocketBroadcastConfigSet(DebuggerRequest & req) {
|
||||
JsonWriter &json = req.Respond();
|
||||
// WebSocketClientInfo& client = req.client;
|
||||
auto& allowed_config = req.client->allowed;
|
||||
auto& disallowed_config = req.client->disallowed;
|
||||
|
||||
const JsonNode *jsonAllowed = req.data.get("allowed");
|
||||
if (!jsonAllowed) {
|
||||
return req.Fail("Missing 'allowed' parameter");
|
||||
const JsonNode *jsonDisallowed = req.data.get("disallowed");
|
||||
if (!jsonDisallowed) {
|
||||
return req.Fail("Missing 'disallowed' parameter");
|
||||
}
|
||||
if (jsonAllowed->value.getTag() != JSON_OBJECT) {
|
||||
return req.Fail("Invalid 'allowed' parameter type");
|
||||
if (jsonDisallowed->value.getTag() != JSON_OBJECT) {
|
||||
return req.Fail("Invalid 'disallowed' parameter type");
|
||||
}
|
||||
|
||||
for (const JsonNode *broadcaster : jsonAllowed->value) {
|
||||
auto it = allowed_config.find(broadcaster->key);
|
||||
if (it == allowed_config.end()) {
|
||||
return req.Fail(StringFromFormat("Unsupported 'allowed' object key '%s'", broadcaster->key));
|
||||
for (const JsonNode *broadcaster : jsonDisallowed->value) {
|
||||
auto it = disallowed_config.find(broadcaster->key);
|
||||
if (it == disallowed_config.end()) {
|
||||
return req.Fail(StringFromFormat("Unsupported 'disallowed' object key '%s'", broadcaster->key));
|
||||
}
|
||||
|
||||
if (broadcaster->value.getTag() == JSON_TRUE) {
|
||||
@@ -92,16 +91,16 @@ void WebSocketBroadcastConfigSet(DebuggerRequest & req) {
|
||||
it->second = false;
|
||||
}
|
||||
else if (broadcaster->value.getTag() != JSON_NULL) {
|
||||
return req.Fail(StringFromFormat("Unsupported 'allowed' object type for key '%s'", broadcaster->key));
|
||||
return req.Fail(StringFromFormat("Unsupported 'disallowed' object type for key '%s'", broadcaster->key));
|
||||
}
|
||||
}
|
||||
|
||||
json.pushDict("allowed");
|
||||
json.pushDict("disallowed");
|
||||
|
||||
json.writeBool("logger", allowed_config.at("logger"));
|
||||
json.writeBool("game", allowed_config.at("game"));
|
||||
json.writeBool("stepping", allowed_config.at("stepping"));
|
||||
json.writeBool("input", allowed_config.at("input"));
|
||||
for (const auto[name, status] : disallowed_config) {
|
||||
if (status)
|
||||
json.writeBool(name, true);
|
||||
}
|
||||
|
||||
json.end();
|
||||
}
|
||||
}
|
||||
@@ -34,13 +34,13 @@
|
||||
using namespace json;
|
||||
|
||||
struct WebSocketClientInfo {
|
||||
WebSocketClientInfo() : name(), version(), allowed() {
|
||||
WebSocketClientInfo() : name(), version(), disallowed() {
|
||||
|
||||
}
|
||||
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::map <std::string, bool> allowed;
|
||||
std::map <std::string, bool> disallowed;
|
||||
};
|
||||
|
||||
struct DebuggerErrorEvent {
|
||||
|
||||
Reference in new issue
Block a user