telemetry_session.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <future>
  6. #include <memory>
  7. #include "common/telemetry.h"
  8. namespace Core {
  9. /**
  10. * Instruments telemetry for this emulation session. Creates a new set of telemetry fields on each
  11. * session, logging any one-time fields. Interfaces with the telemetry backend used for submitting
  12. * data to the web service. Submits session data on close.
  13. */
  14. class TelemetrySession : NonCopyable {
  15. public:
  16. TelemetrySession();
  17. ~TelemetrySession();
  18. /**
  19. * Wrapper around the Telemetry::FieldCollection::AddField method.
  20. * @param type Type of the field to add.
  21. * @param name Name of the field to add.
  22. * @param value Value for the field to add.
  23. */
  24. template <typename T>
  25. void AddField(Telemetry::FieldType type, const char* name, T value) {
  26. field_collection.AddField(type, name, std::move(value));
  27. }
  28. private:
  29. Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
  30. std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
  31. };
  32. /**
  33. * Gets TelemetryId, a unique identifier used for the user's telemetry sessions.
  34. * @returns The current TelemetryId for the session.
  35. */
  36. u64 GetTelemetryId();
  37. /**
  38. * Regenerates TelemetryId, a unique identifier used for the user's telemetry sessions.
  39. * @returns The new TelemetryId that was generated.
  40. */
  41. u64 RegenerateTelemetryId();
  42. /**
  43. * Verifies the username and token.
  44. * @param username yuzu username to use for authentication.
  45. * @param token yuzu token to use for authentication.
  46. * @param func A function that gets exectued when the verification is finished
  47. * @returns Future with bool indicating whether the verification succeeded
  48. */
  49. std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func);
  50. } // namespace Core