facade.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "mtproto/type_utils.h"
  9. #include "mtproto/mtp_instance.h"
  10. namespace MTP {
  11. namespace details {
  12. [[nodiscard]] bool paused();
  13. void pause();
  14. void unpause();
  15. [[nodiscard]] rpl::producer<> unpaused();
  16. } // namespace details
  17. // send(MTPhelp_GetConfig(), MTP::configDcId(dc)) - for dc enumeration
  18. constexpr ShiftedDcId configDcId(DcId dcId) {
  19. return ShiftDcId(dcId, kConfigDcShift);
  20. }
  21. // send(MTPauth_LogOut(), MTP::logoutDcId(dc)) - for logout of guest dcs enumeration
  22. constexpr ShiftedDcId logoutDcId(DcId dcId) {
  23. return ShiftDcId(dcId, kLogoutDcShift);
  24. }
  25. // send(MTPupload_GetFile(), MTP::updaterDcId(dc)) - for autoupdater
  26. constexpr ShiftedDcId updaterDcId(DcId dcId) {
  27. return ShiftDcId(dcId, kUpdaterDcShift);
  28. }
  29. // send(MTPupload_GetFile(), MTP::groupCallStreamDcId(dc)) - for group call stream
  30. constexpr ShiftedDcId groupCallStreamDcId(DcId dcId) {
  31. return ShiftDcId(dcId, kGroupCallStreamDcShift);
  32. }
  33. namespace details {
  34. constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
  35. Expects(index < kMaxMediaDcCount);
  36. return ShiftDcId(dcId, kBaseDownloadDcShift + index);
  37. };
  38. } // namespace details
  39. // send(req, callbacks, MTP::downloadDcId(dc, index)) - for download shifted dc id
  40. inline ShiftedDcId downloadDcId(DcId dcId, int index) {
  41. return details::downloadDcId(dcId, index);
  42. }
  43. inline constexpr bool isDownloadDcId(ShiftedDcId shiftedDcId) {
  44. return (shiftedDcId >= details::downloadDcId(0, 0))
  45. && (shiftedDcId < details::downloadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
  46. }
  47. inline constexpr bool isMediaClusterDcId(ShiftedDcId shiftedDcId) {
  48. const auto shift = GetDcIdShift(shiftedDcId);
  49. return isDownloadDcId(shiftedDcId)
  50. || (shift == kGroupCallStreamDcShift)
  51. || (shift == kExportMediaDcShift)
  52. || (shift == kUpdaterDcShift);
  53. }
  54. inline bool isCdnDc(MTPDdcOption::Flags flags) {
  55. return (flags & MTPDdcOption::Flag::f_cdn);
  56. }
  57. inline bool isTemporaryDcId(ShiftedDcId shiftedDcId) {
  58. auto dcId = BareDcId(shiftedDcId);
  59. return (dcId >= Instance::Fields::kTemporaryMainDc);
  60. }
  61. inline DcId getRealIdFromTemporaryDcId(ShiftedDcId shiftedDcId) {
  62. auto dcId = BareDcId(shiftedDcId);
  63. return (dcId >= Instance::Fields::kTemporaryMainDc) ? (dcId - Instance::Fields::kTemporaryMainDc) : 0;
  64. }
  65. inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
  66. auto dcId = BareDcId(shiftedDcId);
  67. return (dcId < Instance::Fields::kTemporaryMainDc) ? (dcId + Instance::Fields::kTemporaryMainDc) : 0;
  68. }
  69. namespace details {
  70. constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
  71. return ShiftDcId(dcId, kBaseUploadDcShift + index);
  72. };
  73. } // namespace details
  74. // send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id
  75. // uploading always to the main dc so BareDcId(result) == 0
  76. inline ShiftedDcId uploadDcId(int index) {
  77. Expects(index >= 0 && index < kMaxMediaDcCount);
  78. return details::uploadDcId(0, index);
  79. };
  80. constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
  81. return (shiftedDcId >= details::uploadDcId(0, 0))
  82. && (shiftedDcId < details::uploadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
  83. }
  84. inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
  85. const auto shift = GetDcIdShift(shiftedDcId);
  86. return ShiftDcId(BareDcId(shiftedDcId), shift ? (shift + 1) : kDestroyKeyStartDcShift);
  87. }
  88. enum {
  89. DisconnectedState = 0,
  90. ConnectingState = 1,
  91. ConnectedState = 2,
  92. };
  93. enum {
  94. RequestSent = 0,
  95. RequestConnecting = 1,
  96. RequestSending = 2
  97. };
  98. } // namespace MTP