diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 13:56:23 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 13:56:23 -0400 |
| commit | 69fc8d805396b889b5e8c1c88e8129d93db77d29 (patch) | |
| tree | 6b807bd9332c65b65066e247d4d00fd5e4118d2e /src/stream.h | |
| parent | 442f1ee071152be04c4184473ddfee5040795b76 (diff) | |
| download | libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.gz libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.bz2 libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.zip | |
Updated API to use exceptions and make tweet/user objects more helpful
Diffstat (limited to 'src/stream.h')
| -rw-r--r-- | src/stream.h | 67 |
1 files changed, 67 insertions, 0 deletions
| diff --git a/src/stream.h b/src/stream.h new file mode 100644 index 0000000..3391912 --- /dev/null +++ b/src/stream.h | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | #ifndef STREAM_H_E9146952 | ||
| 2 | #define STREAM_H_E9146952 | ||
| 3 | |||
| 4 | #include <functional> | ||
| 5 | #include <list> | ||
| 6 | #include <string> | ||
| 7 | #include <chrono> | ||
| 8 | #include <thread> | ||
| 9 | #include "bounding_box.h" | ||
| 10 | |||
| 11 | namespace twitter { | ||
| 12 | |||
| 13 | class client; | ||
| 14 | class notification; | ||
| 15 | |||
| 16 | class stream { | ||
| 17 | public: | ||
| 18 | |||
| 19 | typedef std::function<void(const notification& _notification)> notify_callback; | ||
| 20 | |||
| 21 | stream( | ||
| 22 | const client& tclient, | ||
| 23 | notify_callback callback, | ||
| 24 | bool with_followings = true, | ||
| 25 | bool receive_all_replies = false, | ||
| 26 | std::list<std::string> track = {}, | ||
| 27 | std::list<bounding_box> locations = {}); | ||
| 28 | |||
| 29 | ~stream(); | ||
| 30 | |||
| 31 | stream(const stream& other) = delete; | ||
| 32 | stream(stream&& other) = delete; | ||
| 33 | stream& operator=(const stream& other) = delete; | ||
| 34 | stream& operator=(stream&& other) = delete; | ||
| 35 | |||
| 36 | private: | ||
| 37 | enum class backoff { | ||
| 38 | none, | ||
| 39 | network, | ||
| 40 | http, | ||
| 41 | rate_limit | ||
| 42 | }; | ||
| 43 | |||
| 44 | static std::string generateUrl( | ||
| 45 | bool with_followings, | ||
| 46 | bool receive_all_replies, | ||
| 47 | std::list<std::string> track, | ||
| 48 | std::list<bounding_box> locations); | ||
| 49 | |||
| 50 | void run(std::string url); | ||
| 51 | int progress(); | ||
| 52 | size_t write(char* ptr, size_t size, size_t nmemb); | ||
| 53 | |||
| 54 | const client& _client; | ||
| 55 | notify_callback _notify; | ||
| 56 | bool _stop = false; | ||
| 57 | std::string _buffer; | ||
| 58 | time_t _last_write; | ||
| 59 | bool _established = false; | ||
| 60 | backoff _backoff_type = backoff::none; | ||
| 61 | std::chrono::milliseconds _backoff_amount; | ||
| 62 | std::thread _thread; | ||
| 63 | }; | ||
| 64 | |||
| 65 | } | ||
| 66 | |||
| 67 | #endif /* end of include guard: STREAM_H_E9146952 */ | ||
