Migrate to C++ 20 & switch to websocketpp develop branch (#4252)

* feat: c++ 20

* fix: c++ 20 deprecations

* fix(msvc): warnings

* chore: add changelog entry

* fix: formatting

* Update websocketpp to the `develop` branch

* Specify other template type in FlagsEnum != operator

* Remove the user of simple template ids in our websocketpp template class

Also standardizes the file a bit by using nested namespaces, using
pragma once

* fix: turn `MAGIC_MESSAGE_SUFFIX` into a `QString`

* hacky unhacky hacky const char hack

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2022-12-24 12:56:11 +01:00
committed by GitHub
parent 99e038ce5e
commit 86e71c8bd9
31 changed files with 219 additions and 212 deletions
@@ -204,8 +204,8 @@ private:
this->clients_.emplace(hdl, client);
auto pendingSubsToTake = (std::min)(this->pendingSubscriptions_.size(),
client->maxSubscriptions);
auto pendingSubsToTake = std::min(this->pendingSubscriptions_.size(),
client->maxSubscriptions);
qCDebug(chatterinoLiveupdates)
<< "LiveUpdate connection opened, subscribing to"
@@ -25,8 +25,7 @@
*
*/
#ifndef CHATTERINOWEBSOCKETPPLOGGER_HPP
#define CHATTERINOWEBSOCKETPPLOGGER_HPP
#pragma once
#include "common/QLogging.hpp"
@@ -36,166 +35,160 @@
#include <string>
namespace websocketpp {
namespace log {
namespace websocketpp::log {
template <typename concurrency, typename names>
class chatterinowebsocketpplogger : public basic<concurrency, names>
template <typename concurrency, typename names>
class chatterinowebsocketpplogger : public basic<concurrency, names>
{
public:
using base = chatterinowebsocketpplogger<concurrency, names>;
chatterinowebsocketpplogger(channel_type_hint::value)
: m_static_channels(0xffffffff)
, m_dynamic_channels(0)
{
public:
typedef chatterinowebsocketpplogger<concurrency, names> base;
}
chatterinowebsocketpplogger<concurrency, names>(
channel_type_hint::value)
: m_static_channels(0xffffffff)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger(std::ostream *)
: m_static_channels(0xffffffff)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger<concurrency, names>(std::ostream *)
: m_static_channels(0xffffffff)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger(level c, channel_type_hint::value)
: m_static_channels(c)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger<concurrency, names>(
level c, channel_type_hint::value)
: m_static_channels(c)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger(level c, std::ostream *)
: m_static_channels(c)
, m_dynamic_channels(0)
{
}
chatterinowebsocketpplogger<concurrency, names>(level c, std::ostream *)
: m_static_channels(c)
, m_dynamic_channels(0)
{
}
~chatterinowebsocketpplogger()
{
}
~chatterinowebsocketpplogger<concurrency, names>()
{
}
chatterinowebsocketpplogger<concurrency, names>(
chatterinowebsocketpplogger<concurrency, names> const &other)
: m_static_channels(other.m_static_channels)
, m_dynamic_channels(other.m_dynamic_channels)
{
}
chatterinowebsocketpplogger(
chatterinowebsocketpplogger<concurrency, names> const &other)
: m_static_channels(other.m_static_channels)
, m_dynamic_channels(other.m_dynamic_channels)
{
}
#ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
chatterinowebsocketpplogger<concurrency, names> &operator=(
chatterinowebsocketpplogger<concurrency, names> const &) = delete;
chatterinowebsocketpplogger<concurrency, names> &operator=(
chatterinowebsocketpplogger<concurrency, names> const &) = delete;
#endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
#ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
/// Move constructor
chatterinowebsocketpplogger<concurrency, names>(
chatterinowebsocketpplogger<concurrency, names> &&other)
: m_static_channels(other.m_static_channels)
, m_dynamic_channels(other.m_dynamic_channels)
{
}
/// Move constructor
chatterinowebsocketpplogger(
chatterinowebsocketpplogger<concurrency, names> &&other)
: m_static_channels(other.m_static_channels)
, m_dynamic_channels(other.m_dynamic_channels)
{
}
# ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
// no move assignment operator because of const member variables
chatterinowebsocketpplogger<concurrency, names> &operator=(
chatterinowebsocketpplogger<concurrency, names> &&) = delete;
// no move assignment operator because of const member variables
chatterinowebsocketpplogger<concurrency, names> &operator=(
chatterinowebsocketpplogger<concurrency, names> &&) = delete;
# endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
#endif // _WEBSOCKETPP_MOVE_SEMANTICS_
/// Explicitly do nothing, this logger doesn't support changing ostream
void set_ostream(std::ostream *)
{
}
/// Explicitly do nothing, this logger doesn't support changing ostream
void set_ostream(std::ostream *)
{
}
/// Dynamically enable the given list of channels
/**
/// Dynamically enable the given list of channels
/**
* @param channels The package of channels to enable
*/
void set_channels(level channels)
void set_channels(level channels)
{
if (channels == names::none)
{
if (channels == names::none)
{
clear_channels(names::all);
return;
}
scoped_lock_type lock(m_lock);
m_dynamic_channels |= (channels & m_static_channels);
clear_channels(names::all);
return;
}
/// Dynamically disable the given list of channels
/**
scoped_lock_type lock(m_lock);
m_dynamic_channels |= (channels & m_static_channels);
}
/// Dynamically disable the given list of channels
/**
* @param channels The package of channels to disable
*/
void clear_channels(level channels)
{
scoped_lock_type lock(m_lock);
m_dynamic_channels &= ~channels;
}
void clear_channels(level channels)
{
scoped_lock_type lock(m_lock);
m_dynamic_channels &= ~channels;
}
/// Write a string message to the given channel
/**
/// Write a string message to the given channel
/**
* @param channel The channel to write to
* @param msg The message to write
*/
void write(level channel, std::string const &msg)
void write(level channel, std::string const &msg)
{
scoped_lock_type lock(m_lock);
if (!this->dynamic_test(channel))
{
scoped_lock_type lock(m_lock);
if (!this->dynamic_test(channel))
{
return;
}
qCDebug(chatterinoWebsocket).nospace()
<< names::channel_name(channel) << ": "
<< QString::fromStdString(msg);
return;
}
qCDebug(chatterinoWebsocket).nospace()
<< names::channel_name(channel) << ": "
<< QString::fromStdString(msg);
}
/// Write a cstring message to the given channel
/**
/// Write a cstring message to the given channel
/**
* @param channel The channel to write to
* @param msg The message to write
*/
void write(level channel, char const *msg)
void write(level channel, char const *msg)
{
scoped_lock_type lock(m_lock);
if (!this->dynamic_test(channel))
{
scoped_lock_type lock(m_lock);
if (!this->dynamic_test(channel))
{
return;
}
qCDebug(chatterinoWebsocket).nospace()
<< names::channel_name(channel) << ": " << msg;
return;
}
qCDebug(chatterinoWebsocket).nospace()
<< names::channel_name(channel) << ": " << msg;
}
/// Test whether a channel is statically enabled
/**
/// Test whether a channel is statically enabled
/**
* @param channel The package of channels to test
*/
_WEBSOCKETPP_CONSTEXPR_TOKEN_ bool static_test(level channel) const
{
return ((channel & m_static_channels) != 0);
}
_WEBSOCKETPP_CONSTEXPR_TOKEN_ bool static_test(level channel) const
{
return ((channel & m_static_channels) != 0);
}
/// Test whether a channel is dynamically enabled
/**
/// Test whether a channel is dynamically enabled
/**
* @param channel The package of channels to test
*/
bool dynamic_test(level channel)
{
return ((channel & m_dynamic_channels) != 0);
}
bool dynamic_test(level channel)
{
return ((channel & m_dynamic_channels) != 0);
}
protected:
typedef typename concurrency::scoped_lock_type scoped_lock_type;
typedef typename concurrency::mutex_type mutex_type;
mutex_type m_lock;
protected:
using scoped_lock_type = typename concurrency::scoped_lock_type;
using mutex_type = typename concurrency::mutex_type;
mutex_type m_lock;
private:
level const m_static_channels;
level m_dynamic_channels;
};
private:
level const m_static_channels;
level m_dynamic_channels;
};
} // namespace log
} // namespace websocketpp
#endif // CHATTERINOWEBSOCKETPPLOGGER_HPP
} // namespace websocketpp::log
+1 -1
View File
@@ -464,7 +464,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
"callback since reward is not known:"
<< rewardId;
channel->channelPointRewardAdded.connect(
[=, &server](ChannelPointReward reward) {
[=, this, &server](ChannelPointReward reward) {
qCDebug(chatterinoTwitch)
<< "TwitchChannel reward added callback:" << reward.id
<< "-" << rewardId;
+1 -1
View File
@@ -829,7 +829,7 @@ void PubSub::onConnectionOpen(WebsocketHandle hdl)
qCDebug(chatterinoPubSub) << "PubSub connection opened!";
const auto topicsToTake =
(std::min)(this->requests.size(), PubSubClient::MAX_LISTENS);
std::min(this->requests.size(), PubSubClient::MAX_LISTENS);
std::vector<QString> newTopics(
std::make_move_iterator(this->requests.begin()),
+8 -4
View File
@@ -38,7 +38,11 @@
namespace chatterino {
namespace {
constexpr char MAGIC_MESSAGE_SUFFIX[] = u8" \U000E0000";
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
const QString MAGIC_MESSAGE_SUFFIX = QString((const char *)u8" \U000E0000");
#else
const QString MAGIC_MESSAGE_SUFFIX = QString::fromUtf8(u8" \U000E0000");
#endif
constexpr int TITLE_REFRESH_PERIOD = 10000;
constexpr int CLIP_CREATION_COOLDOWN = 5000;
const QString CLIPS_LINK("https://clips.twitch.tv/%1");
@@ -72,7 +76,7 @@ TwitchChannel::TwitchChannel(const QString &name)
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([=] {
getApp()->accounts->twitch.currentUserChanged.connect([this] {
this->setMod(false);
this->refreshPubSub();
}));
@@ -124,13 +128,13 @@ TwitchChannel::TwitchChannel(const QString &name)
// timers
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, [=] {
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, [this] {
this->refreshChatters();
});
this->chattersListTimer_.start(5 * 60 * 1000);
QObject::connect(&this->threadClearTimer_, &QTimer::timeout, [=] {
QObject::connect(&this->threadClearTimer_, &QTimer::timeout, [this] {
// We periodically check for any dangling reply threads that missed
// being cleaned up on messageRemovedFromStart. This could occur if
// some other part of the program, like a user card, held a reference
+1 -1
View File
@@ -71,7 +71,7 @@ void TwitchIrcServer::initialize(Settings &settings, Paths &paths)
this->reloadSevenTVGlobalEmotes();
/* Refresh all twitch channel's live status in bulk every 30 seconds after starting chatterino */
QObject::connect(&this->bulkLiveStatusTimer_, &QTimer::timeout, [=] {
QObject::connect(&this->bulkLiveStatusTimer_, &QTimer::timeout, [this] {
this->bulkRefreshLiveStatus();
});
this->bulkLiveStatusTimer_.start(30 * 1000);
+4 -4
View File
@@ -1815,7 +1815,7 @@ void Helix::onFetchChattersSuccess(
this->fetchChatters(
broadcasterID, moderatorID, NUM_CHATTERS_TO_FETCH, chatters.cursor,
[=](auto chatters) {
[=, this](auto chatters) {
this->onFetchChattersSuccess(
finalChatters, broadcasterID, moderatorID, maxChattersToFetch,
successCallback, failureCallback, chatters);
@@ -1925,7 +1925,7 @@ void Helix::onFetchModeratorsSuccess(
this->fetchModerators(
broadcasterID, NUM_MODERATORS_TO_FETCH_PER_REQUEST, moderators.cursor,
[=](auto moderators) {
[=, this](auto moderators) {
this->onFetchModeratorsSuccess(
finalModerators, broadcasterID, maxModeratorsToFetch,
successCallback, failureCallback, moderators);
@@ -2236,7 +2236,7 @@ void Helix::getChatters(
// Initiate the recursive calls
this->fetchChatters(
broadcasterID, moderatorID, NUM_CHATTERS_TO_FETCH, "",
[=](auto chatters) {
[=, this](auto chatters) {
this->onFetchChattersSuccess(
finalChatters, broadcasterID, moderatorID, maxChattersToFetch,
successCallback, failureCallback, chatters);
@@ -2255,7 +2255,7 @@ void Helix::getModerators(
// Initiate the recursive calls
this->fetchModerators(
broadcasterID, NUM_MODERATORS_TO_FETCH_PER_REQUEST, "",
[=](auto moderators) {
[=, this](auto moderators) {
this->onFetchModeratorsSuccess(
finalModerators, broadcasterID, maxModeratorsToFetch,
successCallback, failureCallback, moderators);