Request.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This is the source code of tgnet library v. 1.1
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2015-2018.
  7. */
  8. #ifndef REQUEST_H
  9. #define REQUEST_H
  10. #include <stdint.h>
  11. #include <vector>
  12. #include "Defines.h"
  13. #ifdef ANDROID
  14. #include <jni.h>
  15. #endif
  16. class TLObject;
  17. class TL_error;
  18. class Datacenter;
  19. class Request {
  20. public:
  21. Request(int32_t instance, int32_t token, ConnectionType type, uint32_t flags, uint32_t datacenter, onCompleteFunc completeFunc, onQuickAckFunc quickAckFunc, onWriteToSocketFunc writeToSocketFunc);
  22. ~Request();
  23. int64_t messageId = 0;
  24. int32_t messageSeqNo = 0;
  25. uint32_t datacenterId = 0;
  26. uint32_t connectionToken = 0;
  27. int32_t requestToken = 0;
  28. uint32_t retryCount = 0;
  29. bool failedBySalt = false;
  30. int32_t failedByFloodWait = 0;
  31. ConnectionType connectionType;
  32. uint32_t requestFlags;
  33. bool completed = false;
  34. bool cancelled = false;
  35. bool isInitRequest = false;
  36. bool isInitMediaRequest = false;
  37. uint8_t dataType = 0;
  38. int32_t serializedLength = 0;
  39. int32_t startTime = 0;
  40. int64_t startTimeMillis = 0;
  41. int32_t minStartTime = 0;
  42. int32_t lastResendTime = 0;
  43. bool isResending = false;
  44. int32_t instanceNum = 0;
  45. uint32_t serverFailureCount = 0;
  46. TLObject *rawRequest;
  47. std::unique_ptr<TLObject> rpcRequest;
  48. onCompleteFunc onCompleteRequestCallback;
  49. onQuickAckFunc onQuickAckCallback;
  50. onWriteToSocketFunc onWriteToSocketCallback;
  51. void addRespondMessageId(int64_t id);
  52. bool respondsToMessageId(int64_t id);
  53. void clear(bool time);
  54. void onComplete(TLObject *result, TL_error *error, int32_t networkType, int64_t responseTime);
  55. void onQuickAck();
  56. void onWriteToSocket();
  57. bool isMediaRequest();
  58. bool hasInitFlag();
  59. bool needInitRequest(Datacenter *datacenter, uint32_t currentVersion);
  60. TLObject *getRpcRequest();
  61. #ifdef ANDROID
  62. jobject ptr1 = nullptr;
  63. jobject ptr2 = nullptr;
  64. jobject ptr3 = nullptr;
  65. #endif
  66. private:
  67. std::vector<int64_t> respondsToMessageIds;
  68. };
  69. #endif