CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/Debugger/WebSocket/ClientConfigSubscriber.cpp
Views: 1401
// Copyright (c) 2023- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Core/Debugger/WebSocket/ClientConfigSubscriber.h"18#include "Core/Debugger/WebSocket/WebSocketUtils.h"19#include "Common/StringUtils.h"2021DebuggerSubscriber *WebSocketClientConfigInit(DebuggerEventHandlerMap & map) {22map["broadcast.config.get"] = &WebSocketBroadcastConfigGet;23map["broadcast.config.set"] = &WebSocketBroadcastConfigSet;2425return nullptr;26}272829// Request the current client broadcast configuration (broadcast.config.get)30//31// No parameters.32//33// Response (same event name):34// - disallowed: object with optional boolean fields:35// - logger: whether logger events are disallowed36// - game: whether game events are disallowed37// - stepping: whether stepping events are disallowed38// - input: whether input events are disallowed39void WebSocketBroadcastConfigGet(DebuggerRequest & req) {40JsonWriter &json = req.Respond();41const auto& disallowed_config = req.client->disallowed;4243json.pushDict("disallowed");4445for (const auto[name, status] : disallowed_config) {46if (status)47json.writeBool(name, true);48}4950json.end();51}5253// Update the current client broadcast configuration (broadcast.config.set)54//55// Parameters:56// - disallowed: object with boolean fields (all of them are optional):57// - logger: new logger config state58// - game: new game config state59// - stepping: new stepping config state60// - input: new input config state61//62// Response (same event name):63// - disallowed: object with optional boolean fields:64// - logger: whether logger events are now disallowed65// - game: whether game events are now disallowed66// - stepping: whether stepping events are now disallowed67// - input: whether input events are now disallowed68void WebSocketBroadcastConfigSet(DebuggerRequest & req) {69JsonWriter &json = req.Respond();70auto& disallowed_config = req.client->disallowed;7172const JsonNode *jsonDisallowed = req.data.get("disallowed");73if (!jsonDisallowed) {74return req.Fail("Missing 'disallowed' parameter");75}76if (jsonDisallowed->value.getTag() != JSON_OBJECT) {77return req.Fail("Invalid 'disallowed' parameter type");78}7980for (const JsonNode *broadcaster : jsonDisallowed->value) {81auto it = disallowed_config.find(broadcaster->key);82if (it == disallowed_config.end()) {83return req.Fail(StringFromFormat("Unsupported 'disallowed' object key '%s'", broadcaster->key));84}8586if (broadcaster->value.getTag() == JSON_TRUE) {87it->second = true;88}89else if (broadcaster->value.getTag() == JSON_FALSE) {90it->second = false;91}92else if (broadcaster->value.getTag() != JSON_NULL) {93return req.Fail(StringFromFormat("Unsupported 'disallowed' object type for key '%s'", broadcaster->key));94}95}9697json.pushDict("disallowed");9899for (const auto[name, status] : disallowed_config) {100if (status)101json.writeBool(name, true);102}103104json.end();105}106107108