telemetry_session.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-FileCopyrightText: 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string>
  5. #include "common/telemetry.h"
  6. namespace FileSys {
  7. class ContentProvider;
  8. }
  9. namespace Loader {
  10. class AppLoader;
  11. }
  12. namespace Service::FileSystem {
  13. class FileSystemController;
  14. }
  15. namespace Core {
  16. /**
  17. * Instruments telemetry for this emulation session. Creates a new set of telemetry fields on each
  18. * session, logging any one-time fields. Interfaces with the telemetry backend used for submitting
  19. * data to the web service. Submits session data on close.
  20. */
  21. class TelemetrySession {
  22. public:
  23. explicit TelemetrySession();
  24. ~TelemetrySession();
  25. TelemetrySession(const TelemetrySession&) = delete;
  26. TelemetrySession& operator=(const TelemetrySession&) = delete;
  27. TelemetrySession(TelemetrySession&&) = delete;
  28. TelemetrySession& operator=(TelemetrySession&&) = delete;
  29. /**
  30. * Adds the initial telemetry info necessary when starting up a title.
  31. *
  32. * This includes information such as:
  33. * - Telemetry ID
  34. * - Initialization time
  35. * - Title ID
  36. * - Title name
  37. * - Title file format
  38. * - Miscellaneous settings values.
  39. *
  40. * @param app_loader The application loader to use to retrieve
  41. * title-specific information.
  42. * @param fsc Filesystem controller to use to retrieve info.
  43. * @param content_provider Content provider to use to retrieve info.
  44. */
  45. void AddInitialInfo(Loader::AppLoader& app_loader,
  46. const Service::FileSystem::FileSystemController& fsc,
  47. const FileSys::ContentProvider& content_provider);
  48. /**
  49. * Wrapper around the Telemetry::FieldCollection::AddField method.
  50. * @param type Type of the field to add.
  51. * @param name Name of the field to add.
  52. * @param value Value for the field to add.
  53. */
  54. template <typename T>
  55. void AddField(Common::Telemetry::FieldType type, const char* name, T value) {
  56. field_collection.AddField(type, name, std::move(value));
  57. }
  58. /**
  59. * Submits a Testcase.
  60. * @returns A bool indicating whether the submission succeeded
  61. */
  62. bool SubmitTestcase();
  63. private:
  64. /// Tracks all added fields for the session
  65. Common::Telemetry::FieldCollection field_collection;
  66. };
  67. /**
  68. * Gets TelemetryId, a unique identifier used for the user's telemetry sessions.
  69. * @returns The current TelemetryId for the session.
  70. */
  71. u64 GetTelemetryId();
  72. /**
  73. * Regenerates TelemetryId, a unique identifier used for the user's telemetry sessions.
  74. * @returns The new TelemetryId that was generated.
  75. */
  76. u64 RegenerateTelemetryId();
  77. /**
  78. * Verifies the username and token.
  79. * @param username suyu username to use for authentication.
  80. * @param token suyu token to use for authentication.
  81. * @returns Future with bool indicating whether the verification succeeded
  82. */
  83. bool VerifyLogin(const std::string& username, const std::string& token);
  84. } // namespace Core