PubSub system (#346)
* Add websocketpp dependency * Initial pubsub commit Renamed selection min and max variables to selectionMin and selectionMax to bypass windows min/max macros being stupid. TwitchAccount is now initialized with its User ID. It cannot be changed after it has been initialized. * Update openssl folder * Update installation instructions * Split up websocketpp dependency to its own code only and openssl.pri * Add missing include to asio steady_timer * Update dependencies for linux
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "debug/log.hpp"
|
||||
#include "providers/twitch/twitchaccount.hpp"
|
||||
#include "util/rapidjson-helpers.hpp"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
struct ActionUser;
|
||||
|
||||
const rapidjson::Value &getArgs(const rapidjson::Value &data);
|
||||
|
||||
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
|
||||
|
||||
bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
|
||||
|
||||
std::string Stringify(const rapidjson::Value &v);
|
||||
|
||||
rapidjson::Document CreateListenMessage(const std::vector<std::string> &topicsVec,
|
||||
std::shared_ptr<providers::twitch::TwitchAccount> account);
|
||||
rapidjson::Document CreateUnlistenMessage(const std::vector<std::string> &topicsVec);
|
||||
|
||||
// Create timer using given ioService
|
||||
template <typename Duration, typename Callback>
|
||||
void RunAfter(boost::asio::io_service &ioService, Duration duration, Callback cb)
|
||||
{
|
||||
auto timer = std::make_shared<boost::asio::steady_timer>(ioService);
|
||||
timer->expires_from_now(duration);
|
||||
|
||||
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
||||
if (ec) {
|
||||
debug::Log("Error in RunAfter: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
cb(timer);
|
||||
});
|
||||
}
|
||||
|
||||
// Use provided timer
|
||||
template <typename Duration, typename Callback>
|
||||
void RunAfter(std::shared_ptr<boost::asio::steady_timer> timer, Duration duration, Callback cb)
|
||||
{
|
||||
timer->expires_from_now(duration);
|
||||
|
||||
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
||||
if (ec) {
|
||||
debug::Log("Error in RunAfter: {}", ec.message());
|
||||
return;
|
||||
}
|
||||
|
||||
cb(timer);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user