telemetry_session.h 3.0 KB

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