CSpotContext.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <memory>
  3. #include "LoginBlob.h"
  4. #include "MercurySession.h"
  5. #include "TimeProvider.h"
  6. #include "protobuf/metadata.pb.h"
  7. namespace cspot {
  8. struct Context {
  9. struct ConfigState {
  10. // Setup default bitrate to 160
  11. AudioFormat audioFormat = AudioFormat::AudioFormat_OGG_VORBIS_160;
  12. std::string deviceId;
  13. std::string deviceName;
  14. int volume;
  15. std::string username;
  16. std::string countryCode;
  17. };
  18. ConfigState config;
  19. std::shared_ptr<TimeProvider> timeProvider;
  20. std::shared_ptr<cspot::MercurySession> session;
  21. static std::shared_ptr<Context> createFromBlob(
  22. std::shared_ptr<LoginBlob> blob) {
  23. auto ctx = std::make_shared<Context>();
  24. ctx->timeProvider = std::make_shared<TimeProvider>();
  25. ctx->session = std::make_shared<MercurySession>(ctx->timeProvider);
  26. ctx->config.deviceId = blob->getDeviceId();
  27. ctx->config.deviceName = blob->getDeviceName();
  28. ctx->config.volume = 0;
  29. ctx->config.username = blob->getUserName();
  30. return ctx;
  31. }
  32. };
  33. } // namespace cspot