Cppgram  1.0.0
Easy and modern C++14 Telegram Bot API wrapper
polling.hpp
1 #ifndef CPPGRAM_POLLING_HPP
2 #define CPPGRAM_POLLING_HPP
3 
4 #include "concurrentqueue/blockingconcurrentqueue.h"
5 #include "cppgram/basic_bot.hpp"
6 
7 namespace cppgram
8 {
12 template <class T> class Polling
13 {
14  public:
24  Polling( T bot,
25  uint_fast8_t threads_number,
26  uint_fast32_t limit = 100,
27  uint_fast32_t timeout = 60 );
28 
37  Polling( std::vector<T> bots, uint_fast32_t limit = 100, uint_fast32_t timeout = 60 );
38 
42  void run();
43 
44  private:
49  uint_fast32_t firstUpdateID( T &poller );
50 
55  void runMultithread();
56 
61  void runSinglethread();
62 
67  void setThreadAffinity( std::vector<std::thread> &threads );
68 
76  void loopBot( T bot );
77 
82  void init();
83 
85  std::vector<T> bots;
86 
88  moodycamel::BlockingConcurrentQueue<types::Update> updates_queue;
89 
91  std::shared_ptr<spdlog::logger> console_stderr;
92 
94  std::shared_ptr<spdlog::logger> console_stdout;
95 
101  uint_fast32_t limit;
102 
108  uint_fast32_t timeout;
109 };
110 }
111 
112 #include "polling_impl.hpp"
113 
114 #endif
std::shared_ptr< spdlog::logger > console_stdout
Logger that will print messages to the console.
Definition: polling.hpp:94
moodycamel::BlockingConcurrentQueue< types::Update > updates_queue
Queue of the updates to process.
Definition: polling.hpp:88
void init()
Init logger for each bot.
Definition: polling_impl.hpp:161
uint_fast32_t firstUpdateID(T &poller)
Get the offset of the first update to process.
Definition: polling_impl.hpp:151
std::vector< T > bots
Vector of bots.
Definition: polling.hpp:85
Polling(T bot, uint_fast8_t threads_number, uint_fast32_t limit=100, uint_fast32_t timeout=60)
Create a polling object by passing a single bot, and the number of threads.
Definition: polling_impl.hpp:6
main namespace for Cppgram
std::shared_ptr< spdlog::logger > console_stderr
Logger that will print error messages to the console.
Definition: polling.hpp:91
void run()
Start the polling.
Definition: polling_impl.hpp:30
Handle long (or short) polling for a bot.
Definition: polling.hpp:12