Skip to content

Commit

Permalink
REFAC(client,server): removed boost
Browse files Browse the repository at this point in the history
This commit removes a dependancy on Boost library for client and server.

To implement boost::accumulators, a custom class Accumulator has been introduced. Changes, optimizations are welcomed. Also, all the foreach() loops have been replaced with ranged-based for as extra.

Build instructions are modified accordingly. No boost anymore.
  • Loading branch information
g-virus-dev committed Feb 19, 2025
1 parent 5b8c175 commit a225c58
Show file tree
Hide file tree
Showing 90 changed files with 748 additions and 758 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ indent.sh
*.vcxproj
*.vcxproj.*
*~
*.pro.user
*.user
ui_*.h
*.qm
*.pb.*
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/qqbonjour/BonjourServiceResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BonjourServiceResolver::BonjourServiceResolver(QObject *p) : QObject(p) {
}

BonjourServiceResolver::~BonjourServiceResolver() {
foreach(ResolveRecord *rr, qmResolvers)
for (ResolveRecord *rr : qmResolvers)
delete rr;
}

Expand Down
3 changes: 0 additions & 3 deletions docs/dev/build-instructions/build_linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sudo apt install \
libqt6svg6-dev \
qt6-l10n-tools \
libgl-dev \
libboost-dev \
libssl-dev \
libprotobuf-dev \
protobuf-compiler \
Expand Down Expand Up @@ -58,7 +57,6 @@ sudo apt install \
g++-multilib \
libasound2-dev \
libavahi-compat-libdnssd-dev \
libboost-dev \
libcap-dev \
libgl-dev \
libmsgsl-dev \
Expand Down Expand Up @@ -115,7 +113,6 @@ avahi-compat-libdns_sd-devel \
alsa-lib-devel \
libICE-devel \
libogg-devel \
boost-devel \
libcap-devel \
poco-devel \
gcc-toolset-9-gcc-c++
Expand Down
1 change: 0 additions & 1 deletion docs/dev/build-instructions/build_macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ brew update && brew install \
cmake \
pkg-config \
qt5 \
boost \
libogg \
libvorbis \
flac \
Expand Down
3 changes: 0 additions & 3 deletions docs/dev/build-instructions/build_static.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ package you want to install and `<triplet>` is the desired target triplet. We re
| Linux | x64-linux |
| macOS | x64-osx |

Therefore if you are on Windows, you'd install `boost` as `vcpkg install boost --triplet x64-windows-static-md`.


### Additional dependencies on Linux

Additional `dev` packages will need to be installed for some components in vcpkg on GNU/Linux (package names match Ubuntu packages):
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-ApplicationPalette-class.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
}
"""

variable_template = """ boost::optional<QBrush> m_%(prop)s;
variable_template = """ std::optional<QBrush> m_%(prop)s;
"""

reset_template = """ m_%(prop)s = boost::none;
reset_template = """ m_%(prop)s = {};
"""

def rolename(role):
Expand Down
6 changes: 1 addition & 5 deletions scripts/generateIceWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generateFunction(className, functionName, wrapArgs, callArgs):
function += "\t}\n"
function += "#endif // ACCESS_" + className + "_" + functionName + "_ALL\n"
function += "\n"
function += "\tExecEvent *ie = new ExecEvent(boost::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n"
function += "\tExecEvent *ie = new ExecEvent(std::bind(&impl_" + className + "_" + functionName + ", " + ", ".join(callArgs) + "));\n"
function += "\tQCoreApplication::instance()->postEvent(mi, ie);\n"
function += "}\n"

Expand Down Expand Up @@ -111,10 +111,6 @@ def main():

wrapperContent = create_disclaimerComment()

# Include boost-bind as we'll need it later
wrapperContent += "\n#include <boost/bind/bind.hpp>\n\n"


className = ""
for currentLine in generatedIceHeader.split("\n"):
currentLine = currentLine.strip()
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ target_link_libraries(shared
OpenSSL::SSL
Qt6::Core
Qt6::Network
Qt6::Xml
Qt6::Xml
)

if(WIN32)
Expand Down
16 changes: 8 additions & 8 deletions src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Channel::~Channel() {
if (cParent)
cParent->removeChannel(this);

foreach (Channel *c, qlChannels)
for (Channel *c : qlChannels)
delete c;

foreach (ChanACL *acl, qlACL)
for (ChanACL *acl : qlACL)
delete acl;
foreach (Group *g, qhGroups)
for (Group *g : qhGroups)
delete g;
foreach (Channel *l, qhLinks.keys())
for (Channel *l : qhLinks.keys())
unlink(l);

Q_ASSERT(qlChannels.count() == 0);
Expand Down Expand Up @@ -197,7 +197,7 @@ void Channel::unlink(Channel *l) {
l->qsPermLinks.remove(this);
l->qhLinks.remove(this);
} else {
foreach (Channel *c, qhLinks.keys())
for (Channel *c : qhLinks.keys())
unlink(c);
}
}
Expand All @@ -213,7 +213,7 @@ QSet< Channel * > Channel::allLinks() {

while (!stack.isEmpty()) {
Channel *lnk = stack.pop();
foreach (Channel *l, lnk->qhLinks.keys()) {
for (Channel *l : lnk->qhLinks.keys()) {
if (!seen.contains(l)) {
seen.insert(l);
stack.push(l);
Expand All @@ -231,7 +231,7 @@ QSet< Channel * > Channel::allChildren() {

while (!stack.isEmpty()) {
Channel *c = stack.pop();
foreach (Channel *chld, c->qlChannels) {
for (Channel *chld : c->qlChannels) {
seen.insert(chld);
if (!chld->qlChannels.isEmpty())
stack.append(chld);
Expand Down Expand Up @@ -294,7 +294,7 @@ size_t Channel::getDepth() const {
}

size_t result = 0;
foreach (Channel *child, qlChannels) { result = qMax(result, child->getDepth() + 1); }
for (Channel *child : qlChannels) { result = qMax(result, child->getDepth() + 1); }

return result;
}
Expand Down
12 changes: 5 additions & 7 deletions src/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ QSet< int > Group::members() {
QStack< Group * > s;
QSet< int > m;
Channel *p;
Group *g;
int i;
Group *g;

p = c;
while (p) {
Expand All @@ -48,9 +47,9 @@ QSet< int > Group::members() {

while (!s.isEmpty()) {
g = s.pop();
foreach (i, g->qsAdd)
for (int i : g->qsAdd)
m.insert(i);
foreach (i, g->qsRemove)
for (int i : g->qsRemove)
m.remove(i);
}

Expand All @@ -77,8 +76,7 @@ Group *Group::getGroup(Channel *chan, QString name) {
QSet< QString > Group::groupNames(Channel *chan) {
QStack< Channel * > s;
QSet< QString > m;
Channel *c = chan;
Group *g;
Channel *c = chan;

while (c) {
s.push(c);
Expand All @@ -87,7 +85,7 @@ QSet< QString > Group::groupNames(Channel *chan) {

while (!s.isEmpty()) {
c = s.pop();
foreach (g, c->qhGroups) {
for (Group* g : c->qhGroups) {
if ((chan != c) && (!g->bInheritable))
m.remove(g->qsName);
else
Expand Down
2 changes: 1 addition & 1 deletion src/License.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ QString License::printableThirdPartyLicenseInfo() {
QString output;

QList< LicenseInfo > thirdPartyLicenses = License::thirdPartyLicenses();
foreach (LicenseInfo li, thirdPartyLicenses) {
for (LicenseInfo li : thirdPartyLicenses) {
QString header = QString::fromLatin1("%1 (%2)\n").arg(li.name).arg(li.url);
QString headerHorizLine = QString::fromLatin1("-").repeated(header.size()) + QLatin1String("\n");

Expand Down
2 changes: 1 addition & 1 deletion src/ProcessResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ProcessResolver::doResolve() {

bool ok;

foreach (const QString &currentEntry, entries) {
for (const QString &currentEntry : entries) {
uint64_t pid = static_cast< unsigned long long int >(currentEntry.toLongLong(&ok, 10));

if (!ok) {
Expand Down
4 changes: 2 additions & 2 deletions src/SSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ void MumbleSSL::addSystemCA() {
QList< QSslCertificate > caList = sslCfg.caCertificates();

QList< QSslCertificate > filteredCaList;
foreach (QSslCertificate cert, caList) {
for (const QSslCertificate& cert : caList) {
QStringList orgs = cert.subjectInfo(QSslCertificate::Organization);
bool skip = false;
foreach (QString ou, orgs) {
for (const QString& ou : orgs) {
if (ou.contains(QLatin1String("Skype"), Qt::CaseInsensitive)) {
skip = true;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/ServerResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void ServerResolverPrivate::hostResolved(QHostInfo hostInfo) {

// Convert QHostAddress -> HostAddress.
QList< HostAddress > addresses;
foreach (QHostAddress ha, resolvedAddresses) { addresses << HostAddress(ha); }
for (const QHostAddress& ha : resolvedAddresses) { addresses << HostAddress(ha); }

qint64 priority = normalizeSrvPriority(record.priority(), record.weight());
m_resolved << ServerResolverRecord(record.target(), record.port(), priority, addresses);
Expand All @@ -106,7 +106,7 @@ void ServerResolverPrivate::hostFallbackResolved(QHostInfo hostInfo) {

// Convert QHostAddress -> HostAddress.
QList< HostAddress > addresses;
foreach (QHostAddress ha, resolvedAddresses) { addresses << HostAddress(ha); }
for (const QHostAddress& ha : resolvedAddresses) { addresses << HostAddress(ha); }

m_resolved << ServerResolverRecord(m_origHostname, m_origPort, 0, addresses);
}
Expand Down
21 changes: 14 additions & 7 deletions src/ServerResolverRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@

#include "ServerResolverRecord.h"

ServerResolverRecord::ServerResolverRecord() {
ServerResolverRecord::ServerResolverRecord()
{
}

ServerResolverRecord::ServerResolverRecord(QString hostname_, quint16 port_, qint64 priority_,
ServerResolverRecord::ServerResolverRecord(QString hostname_,
quint16 port_,
qint64 priority_,
QList< HostAddress > addresses_)
: m_hostname(hostname_), m_port(port_), m_priority(priority_), m_addresses(addresses_) {
: m_hostname(hostname_),
m_port(port_),
m_priority(priority_),
m_addresses(addresses_)
{
}

qint64 ServerResolverRecord::priority() {
qint64 ServerResolverRecord::priority() const {
return m_priority;
}

QString ServerResolverRecord::hostname() {
const QString& ServerResolverRecord::hostname() const {
return m_hostname;
}

quint16 ServerResolverRecord::port() {
quint16 ServerResolverRecord::port() const {
return m_port;
}

QList< HostAddress > ServerResolverRecord::addresses() {
const QList< HostAddress >& ServerResolverRecord::addresses() const {
return m_addresses;
}
8 changes: 4 additions & 4 deletions src/ServerResolverRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class ServerResolverRecord {
ServerResolverRecord();
ServerResolverRecord(QString hostname_, quint16 port_, qint64 priority_, QList< HostAddress > addresses_);

QString hostname();
quint16 port();
qint64 priority();
QList< HostAddress > addresses();
const QString& hostname() const;
quint16 port() const;
qint64 priority() const;
const QList< HostAddress >& addresses() const;

protected:
QString m_hostname;
Expand Down
82 changes: 2 additions & 80 deletions src/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,8 @@
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include <boost/version.hpp>

// Not all Boost versions can use a header-only
// boost_system without build failures.
//
// See mumble-voip/mumble#2366.
//
// This was fixed in Boost 1.56.0.
//
// See:
// https://github.com/boostorg/system/blob/boost-1.56.0/include/boost/system/error_code.hpp#L514-L516
// vs.
// https://github.com/boostorg/system/blob/boost-1.55.0/include/boost/system/error_code.hpp#L515-L517
#if BOOST_VERSION >= 105600 && !defined(__MINGW32__)
# define USE_BOOST_CHRONO
#endif

#include "Timer.h"
#include <chrono>

Timer::Timer(bool start) {
uiStart = start ? now() : 0;
Expand Down Expand Up @@ -59,68 +43,6 @@ bool Timer::operator>(const Timer &other) const {
return uiStart < other.uiStart;
}

#ifdef USE_BOOST_CHRONO
// Ensure boost_system is header only.
# define BOOST_ERROR_CODE_HEADER_ONLY
// Ensure boost_chrono is header only.
# define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
# define BOOST_CHRONO_HEADER_ONLY

# include <boost/chrono.hpp>

quint64 Timer::now() {
using namespace boost::chrono;
time_point< steady_clock > now = steady_clock::now();
time_point< steady_clock >::duration epochDuration = now.time_since_epoch();
microseconds epochDurationUsec = duration_cast< microseconds >(epochDuration);
return static_cast< quint64 >(epochDurationUsec.count());
}
#elif defined(Q_OS_WIN)
# include "win.h"

quint64 Timer::now() {
static double scale = 0;

if (scale == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
scale = 1000000. / freq.QuadPart;
}

LARGE_INTEGER li;
QueryPerformanceCounter(&li);
quint64 e = li.QuadPart;

return static_cast< quint64 >(e * scale);
}
#elif defined(Q_OS_UNIX)
# include <errno.h>
# include <string.h>
# include <time.h>
# include <unistd.h>
# if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK)
quint64 Timer::now() {
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
qFatal("Timer: clock_gettime() failed: (%i) %s", errno, strerror(errno));
}
quint64 e = ts.tv_sec * 1000000LL;
e += ts.tv_nsec / 1000LL;
return e;
}
# else
quint64 Timer::now() {
struct timeval tv;
gettimeofday(&tv, nullptr);
quint64 e = tv.tv_sec * 1000000LL;
e += tv.tv_usec;
return e;
}
# endif
#else
quint64 Timer::now() {
static QTime ticker;
quint64 elapsed = ticker.elapsed();
return elapsed * 1000LL;
return static_cast<quint64>(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
}
#endif
Loading

0 comments on commit a225c58

Please sign in to comment.