| 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 | |
| 9 | #ifndef CONNECTIONSESSION_H |
| 10 | #define CONNECTIONSESSION_H |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <vector> |
| 14 | #include "Defines.h" |
| 15 | |
| 16 | class ConnectionSession { |
| 17 | |
| 18 | public: |
| 19 | ConnectionSession(int32_t instance); |
| 20 | void recreateSession(); |
| 21 | void genereateNewSessionId(); |
| 22 | void setSessionId(int64_t id); |
| 23 | int64_t getSessionId(); |
| 24 | uint32_t generateMessageSeqNo(bool increment); |
| 25 | int32_t isMessageIdProcessed(int64_t messageId); |
| 26 | void addProcessedMessageId(int64_t messageId); |
| 27 | bool hasMessagesToConfirm(); |
| 28 | void addMessageToConfirm(int64_t messageId); |
| 29 | NetworkMessage *generateConfirmationRequest(); |
| 30 | bool isSessionProcessed(int64_t sessionId); |
| 31 | void addProcessedSession(int64_t sessionId); |
| 32 | |
| 33 | private: |
| 34 | int32_t instanceNum; |
| 35 | int64_t sessionId; |
| 36 | uint32_t nextSeqNo = 0; |
| 37 | int64_t minProcessedMessageId = 0; |
| 38 | |
| 39 | std::vector<int64_t> processedMessageIds; |
| 40 | std::vector<int64_t> messagesIdsForConfirmation; |
| 41 | std::vector<int64_t> processedSessionChanges; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | #endif |
| 46 | |