| 6 |
| * Copyright Nikolai Kudashov, 2015. |
| 7 | */ |
| 8 |
| 9 | #ifndef DEFINES_H |
| 10 | #define DEFINES_H |
| 11 |
| 12 | #include <functional> |
| 13 | #include <list> |
| 14 | #include <limits.h> |
| 15 | #include <bits/unique_ptr.h> |
| 16 | #include <sstream> |
| 17 |
| 18 | #define USE_DEBUG_SESSION false |
| 19 | #define READ_BUFFER_SIZE 1024 * 128 |
| 20 | //#define DEBUG_VERSION |
| 21 | #define DEFAULT_DATACENTER_ID INT_MAX |
| 22 | #define DC_UPDATE_TIME 60 * 60 |
| 23 | #define DOWNLOAD_CONNECTIONS_COUNT 2 |
| 24 | #define CONNECTION_BACKGROUND_KEEP_TIME 10000 |
| 25 |
| 26 | class TLObject; |
| 27 | class TL_error; |
| 28 | class Request; |
| 29 | class TL_message; |
| 30 | class TL_config; |
| 31 | class NativeByteBuffer; |
| 32 |
| 33 | typedef std::function<void(TLObject *response, TL_error *error)> onCompleteFunc; |
| 34 | typedef std::function<void()> onQuickAckFunc; |
| 35 | typedef std::list<std::unique_ptr<Request>> requestsList; |
| 36 | typedef requestsList::iterator requestsIter; |
| 37 |
| 38 | typedef struct NetworkMessage { |
| 39 | std::unique_ptr<TL_message> message; |
| 40 | bool invokeAfter = false; |
| 41 | bool needQuickAck = false; |
| 42 | int32_t requestId; |
| 43 | } NetworkMessage; |
| 44 |
| 45 | enum ConnectionType { |
| 46 | ConnectionTypeGeneric = 1, |
| 47 | ConnectionTypeDownload = 2, |
| 48 | ConnectionTypeUpload = 4, |
| 49 | ConnectionTypePush = 8, |
| 50 | }; |
| 51 |
| 52 | enum ConnectionState { |
| 53 | ConnectionStateConnecting = 1, |
| 54 | ConnectionStateWaitingForNetwork = 2, |
| 55 | ConnectionStateConnected = 3 |
| 56 | }; |
| 57 |
| 58 | enum EventObjectType { |
| 59 | EventObjectTypeConnection, |
| 60 | EventObjectTypeTimer, |
| 61 | EventObjectPipe |
| 62 | }; |
| 63 |
| 64 | typedef struct ConnectiosManagerDelegate { |
| 65 | virtual void onUpdate() = 0; |
| 66 | virtual void onSessionCreated() = 0; |
| 67 | virtual void onConnectionStateChanged(ConnectionState state) = 0; |
| 68 | virtual void onUnparsedMessageReceived(int64_t reqMessageId, NativeByteBuffer *buffer, ConnectionType connectionType) = 0; |
| 69 | virtual void onLogout() = 0; |
| 70 | virtual void onUpdateConfig(TL_config *config) = 0; |
| 71 | virtual void onInternalPushReceived() = 0; |
| 72 | } ConnectiosManagerDelegate; |
| 73 |
| 74 | #define AllConnectionTypes ConnectionTypeGeneric | ConnectionTypeDownload | ConnectionTypeUpload |
| 75 |
| 76 | enum RequestFlag { |
| 77 | RequestFlagEnableUnauthorized = 1, |
| 78 | RequestFlagFailOnServerErrors = 2, |
| 79 | RequestFlagCanCompress = 4, |
| 80 | RequestFlagWithoutLogin = 8, |
| 81 | RequestFlagTryDifferentDc = 16, |
| 82 | RequestFlagForceDownload = 32, |
| 83 | RequestFlagInvokeAfter = 64, |
| 84 | RequestFlagNeedQuickAck = 128 |
| 85 | }; |
| 86 |
| 87 | inline std::string to_string_int32(int32_t value) { |
| 88 | char buf[30]; |
| 89 | int len = sprintf(buf, "%d", value); |
| 90 | return std::string(buf, len); |
| 91 | } |
| 92 |
| 93 | inline std::string to_string_uint64(uint64_t value) { |
| 94 | char buf[30]; |
| 95 | int len = sprintf(buf, "%llu", value); |
| 96 | return std::string(buf, len); |
| 97 | } |
| 98 |
| 99 | #endif |
| 100 |