CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Debugger/WebSocket/ClientConfigSubscriber.cpp
Views: 1401
1
// Copyright (c) 2023- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Core/Debugger/WebSocket/ClientConfigSubscriber.h"
19
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
20
#include "Common/StringUtils.h"
21
22
DebuggerSubscriber *WebSocketClientConfigInit(DebuggerEventHandlerMap & map) {
23
map["broadcast.config.get"] = &WebSocketBroadcastConfigGet;
24
map["broadcast.config.set"] = &WebSocketBroadcastConfigSet;
25
26
return nullptr;
27
}
28
29
30
// Request the current client broadcast configuration (broadcast.config.get)
31
//
32
// No parameters.
33
//
34
// Response (same event name):
35
// - disallowed: object with optional boolean fields:
36
// - logger: whether logger events are disallowed
37
// - game: whether game events are disallowed
38
// - stepping: whether stepping events are disallowed
39
// - input: whether input events are disallowed
40
void WebSocketBroadcastConfigGet(DebuggerRequest & req) {
41
JsonWriter &json = req.Respond();
42
const auto& disallowed_config = req.client->disallowed;
43
44
json.pushDict("disallowed");
45
46
for (const auto[name, status] : disallowed_config) {
47
if (status)
48
json.writeBool(name, true);
49
}
50
51
json.end();
52
}
53
54
// Update the current client broadcast configuration (broadcast.config.set)
55
//
56
// Parameters:
57
// - disallowed: object with boolean fields (all of them are optional):
58
// - logger: new logger config state
59
// - game: new game config state
60
// - stepping: new stepping config state
61
// - input: new input config state
62
//
63
// Response (same event name):
64
// - disallowed: object with optional boolean fields:
65
// - logger: whether logger events are now disallowed
66
// - game: whether game events are now disallowed
67
// - stepping: whether stepping events are now disallowed
68
// - input: whether input events are now disallowed
69
void WebSocketBroadcastConfigSet(DebuggerRequest & req) {
70
JsonWriter &json = req.Respond();
71
auto& disallowed_config = req.client->disallowed;
72
73
const JsonNode *jsonDisallowed = req.data.get("disallowed");
74
if (!jsonDisallowed) {
75
return req.Fail("Missing 'disallowed' parameter");
76
}
77
if (jsonDisallowed->value.getTag() != JSON_OBJECT) {
78
return req.Fail("Invalid 'disallowed' parameter type");
79
}
80
81
for (const JsonNode *broadcaster : jsonDisallowed->value) {
82
auto it = disallowed_config.find(broadcaster->key);
83
if (it == disallowed_config.end()) {
84
return req.Fail(StringFromFormat("Unsupported 'disallowed' object key '%s'", broadcaster->key));
85
}
86
87
if (broadcaster->value.getTag() == JSON_TRUE) {
88
it->second = true;
89
}
90
else if (broadcaster->value.getTag() == JSON_FALSE) {
91
it->second = false;
92
}
93
else if (broadcaster->value.getTag() != JSON_NULL) {
94
return req.Fail(StringFromFormat("Unsupported 'disallowed' object type for key '%s'", broadcaster->key));
95
}
96
}
97
98
json.pushDict("disallowed");
99
100
for (const auto[name, status] : disallowed_config) {
101
if (status)
102
json.writeBool(name, true);
103
}
104
105
json.end();
106
}
107
108