tgbot-cpp
Toggle main menu visibility
Loading...
Searching...
No Matches
TgLongPoll.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
tgbot/Types.h
"
4
#include "
tgbot/export.h
"
5
6
#include <atomic>
7
#include <csignal>
8
#include <cstdint>
9
#include <exception>
10
#include <functional>
11
#include <initializer_list>
12
#include <memory>
13
#include <string>
14
#include <vector>
15
16
namespace
TgBot
{
17
18
class
Api
;
19
class
Bot
;
20
class
EventHandler
;
21
27
class
TGBOT_API
TgLongPoll
{
28
public
:
29
using
ErrorHandler
= std::function<void(
const
std::exception&)>;
30
31
TgLongPoll
(
const
Api
* api,
const
EventHandler
* eventHandler, std::int32_t limit, std::int32_t timeout,
32
std::shared_ptr<std::vector<std::string>> allowUpdates);
33
TgLongPoll
(
const
Bot
& bot, std::int32_t limit = 100, std::int32_t timeout = 10,
34
const
std::shared_ptr<std::vector<std::string>>& allowUpdates =
nullptr
);
35
40
void
start
();
41
49
void
startLoop
(
const
ErrorHandler
& errorHandler = { }, std::initializer_list<int> signals = { SIGINT, SIGTERM });
50
54
void
stop
();
55
59
bool
isRunning
()
const
{
60
return
_isRunning.load();
61
}
62
63
private
:
64
const
Api
* _api;
65
const
EventHandler
* _eventHandler;
66
std::int32_t _lastUpdateId = 0;
67
std::int32_t _limit;
68
std::int32_t _timeout;
69
std::shared_ptr<std::vector<std::string>> _allowUpdates;
70
std::atomic<bool> _isRunning {
false
};
71
72
std::vector<std::shared_ptr<Update>> _updates;
73
};
74
75
}
// namespace TgBot
Types.h
TgBot::Api
Executes methods from the Telegram Bot API.
Definition
Api.h:30
TgBot::Bot
This object holds other objects specific for this bot instance.
Definition
Bot.h:20
TgBot::EventHandler
Definition
EventHandler.h:12
TgBot::TgLongPoll::TgLongPoll
TgLongPoll(const Bot &bot, std::int32_t limit=100, std::int32_t timeout=10, const std::shared_ptr< std::vector< std::string > > &allowUpdates=nullptr)
TgBot::TgLongPoll::stop
void stop()
Requests cancellation of the active HTTP request and stops startLoop().
TgBot::TgLongPoll::isRunning
bool isRunning() const
Returns true while startLoop() is active.
Definition
TgLongPoll.h:59
TgBot::TgLongPoll::ErrorHandler
std::function< void(const std::exception &)> ErrorHandler
Definition
TgLongPoll.h:29
TgBot::TgLongPoll::start
void start()
Performs one long-polling iteration and dispatches received updates. Parses received updates and pass...
TgBot::TgLongPoll::TgLongPoll
TgLongPoll(const Api *api, const EventHandler *eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr< std::vector< std::string > > allowUpdates)
TgBot::TgLongPoll::startLoop
void startLoop(const ErrorHandler &errorHandler={ }, std::initializer_list< int > signals={ SIGINT, SIGTERM })
Polls for updates until stop() is called, one of the configured signals is received,...
export.h
TGBOT_API
#define TGBOT_API
Definition
export.h:5
TgBot
Definition
Api.h:17
include
tgbot
TgLongPoll.h
Generated on
for tgbot-cpp by
1.17.0