summaryrefslogtreecommitdiff
path: root/src/web_service/telemetry_json.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2017-07-09 13:48:47 -0400
committerGravatar bunnei2017-07-11 18:33:38 -0400
commitfd3b4451eccbf0dfdc2597f1a68e98763c17f207 (patch)
tree5870f17ca9daf8ccf2d514a44ed0a18a6e135af1 /src/web_service/telemetry_json.cpp
parentweb_backend: Add initial interface to POST data to Citra Web Services. (diff)
downloadyuzu-fd3b4451eccbf0dfdc2597f1a68e98763c17f207.tar.gz
yuzu-fd3b4451eccbf0dfdc2597f1a68e98763c17f207.tar.xz
yuzu-fd3b4451eccbf0dfdc2597f1a68e98763c17f207.zip
web_service: Implement JSON serialization of telemetry data.
Diffstat (limited to 'src/web_service/telemetry_json.cpp')
-rw-r--r--src/web_service/telemetry_json.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp
index 68e092699..c61522ff1 100644
--- a/src/web_service/telemetry_json.cpp
+++ b/src/web_service/telemetry_json.cpp
@@ -2,8 +2,88 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/assert.h"
6#include "core/settings.h"
5#include "web_service/telemetry_json.h" 7#include "web_service/telemetry_json.h"
8#include "web_service/web_backend.h"
6 9
7namespace WebService { 10namespace WebService {
8 11
12TelemetryJson::TelemetryJson() {}
13
14template <class T>
15void TelemetryJson::Serialize(Telemetry::FieldType type, const std::string& name, T value) {
16 sections[static_cast<u8>(type)][name] = value;
17}
18
19void TelemetryJson::SerializeSection(Telemetry::FieldType type, const std::string& name) {
20 TopSection()[name] = sections[static_cast<unsigned>(type)];
21}
22
23void TelemetryJson::Visit(const Telemetry::Field<bool>& field) {
24 Serialize(field.GetType(), field.GetName(), field.GetValue());
25}
26
27void TelemetryJson::Visit(const Telemetry::Field<double>& field) {
28 Serialize(field.GetType(), field.GetName(), field.GetValue());
29}
30
31void TelemetryJson::Visit(const Telemetry::Field<float>& field) {
32 Serialize(field.GetType(), field.GetName(), field.GetValue());
33}
34
35void TelemetryJson::Visit(const Telemetry::Field<u8>& field) {
36 Serialize(field.GetType(), field.GetName(), field.GetValue());
37}
38
39void TelemetryJson::Visit(const Telemetry::Field<u16>& field) {
40 Serialize(field.GetType(), field.GetName(), field.GetValue());
41}
42
43void TelemetryJson::Visit(const Telemetry::Field<u32>& field) {
44 Serialize(field.GetType(), field.GetName(), field.GetValue());
45}
46
47void TelemetryJson::Visit(const Telemetry::Field<u64>& field) {
48 Serialize(field.GetType(), field.GetName(), field.GetValue());
49}
50
51void TelemetryJson::Visit(const Telemetry::Field<s8>& field) {
52 Serialize(field.GetType(), field.GetName(), field.GetValue());
53}
54
55void TelemetryJson::Visit(const Telemetry::Field<s16>& field) {
56 Serialize(field.GetType(), field.GetName(), field.GetValue());
57}
58
59void TelemetryJson::Visit(const Telemetry::Field<s32>& field) {
60 Serialize(field.GetType(), field.GetName(), field.GetValue());
61}
62
63void TelemetryJson::Visit(const Telemetry::Field<s64>& field) {
64 Serialize(field.GetType(), field.GetName(), field.GetValue());
65}
66
67void TelemetryJson::Visit(const Telemetry::Field<std::string>& field) {
68 Serialize(field.GetType(), field.GetName(), field.GetValue());
69}
70
71void TelemetryJson::Visit(const Telemetry::Field<const char*>& field) {
72 Serialize(field.GetType(), field.GetName(), std::string(field.GetValue()));
73}
74
75void TelemetryJson::Visit(const Telemetry::Field<std::chrono::microseconds>& field) {
76 Serialize(field.GetType(), field.GetName(), field.GetValue().count());
77}
78
79void TelemetryJson::Complete() {
80 SerializeSection(Telemetry::FieldType::App, "App");
81 SerializeSection(Telemetry::FieldType::Session, "Session");
82 SerializeSection(Telemetry::FieldType::Performance, "Performance");
83 SerializeSection(Telemetry::FieldType::UserFeedback, "UserFeedback");
84 SerializeSection(Telemetry::FieldType::UserConfig, "UserConfig");
85 SerializeSection(Telemetry::FieldType::UserSystem, "UserSystem");
86 PostJson(Settings::values.telemetry_endpoint_url, TopSection().dump());
87}
88
9} // namespace WebService 89} // namespace WebService