File indexing completed on 2024-12-01 13:09:18

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "serverinfo.h"
0008 
0009 ServerInfo::ServerInfo() = default;
0010 
0011 ServerInfo::~ServerInfo() = default;
0012 
0013 void ServerInfo::parseServerInfo(const QJsonObject &obj)
0014 {
0015     const QJsonObject infoObj = obj[QLatin1String("info")].toObject();
0016     mVersion = infoObj.value(QLatin1String("version")).toString();
0017     const QJsonObject commitObj = infoObj[QLatin1String("commit")].toObject();
0018     mCommitAuthor = commitObj.value(QLatin1String("author")).toString();
0019     mCommitBranch = commitObj.value(QLatin1String("branch")).toString();
0020     mCommitTag = commitObj.value(QLatin1String("tag")).toString();
0021     mCommitSubject = commitObj.value(QLatin1String("subject")).toString();
0022     mCommitHash = commitObj.value(QLatin1String("hash")).toString();
0023 
0024     const QJsonObject buildObj = infoObj[QLatin1String("build")].toObject();
0025     mArch = buildObj.value(QLatin1String("arch")).toString();
0026     mNumberOfCpu = buildObj.value(QLatin1String("cpus")).toInt();
0027     mPlatform = buildObj.value(QLatin1String("platform")).toString();
0028     mOsRelease = buildObj.value(QLatin1String("osRelease")).toString();
0029     mNodeVersion = buildObj.value(QLatin1String("nodeVersion")).toString();
0030 #if 0
0031     {
0032         "info" : {"build" : {"arch" : "x64", "cpus" : 2, "date" : "2020-12-29T04:59:35.728Z", "freeMemory" : 461508608, "nodeVersion" : "v12.18.4", "osRelease" : "5.4.0-1032-azure", "platform" : "linux", "totalMemory" : 7292207104},
0033                   "commit" : {"author" : "Diego Sampaio", "branch" : "HEAD", "date" : "Tue Dec 29 01:43:25 2020 -0300", "hash" : "3a13cead22bfc1100c5b89069498919473c84195", "subject" : "Merge pull request #19982 from RocketChat/release-3.10.0", "tag" : "3.10.0"},
0034                   "marketplaceApiVersion" : "1.21.0-alpha.4235", "version" : "3.10.0"}, "success" : true
0035     }
0036     //TODO
0037 #endif
0038 }
0039 
0040 QString ServerInfo::arch() const
0041 {
0042     return mArch;
0043 }
0044 
0045 void ServerInfo::setArch(const QString &arch)
0046 {
0047     mArch = arch;
0048 }
0049 
0050 int ServerInfo::numberOfCpu() const
0051 {
0052     return mNumberOfCpu;
0053 }
0054 
0055 void ServerInfo::setNumberOfCpu(int numberOfCpu)
0056 {
0057     mNumberOfCpu = numberOfCpu;
0058 }
0059 
0060 QString ServerInfo::platform() const
0061 {
0062     return mPlatform;
0063 }
0064 
0065 void ServerInfo::setPlatform(const QString &platform)
0066 {
0067     mPlatform = platform;
0068 }
0069 
0070 QString ServerInfo::version() const
0071 {
0072     return mVersion;
0073 }
0074 
0075 void ServerInfo::setVersion(const QString &version)
0076 {
0077     mVersion = version;
0078 }
0079 
0080 QString ServerInfo::commitAuthor() const
0081 {
0082     return mCommitAuthor;
0083 }
0084 
0085 void ServerInfo::setCommitAuthor(const QString &commitAuthor)
0086 {
0087     mCommitAuthor = commitAuthor;
0088 }
0089 
0090 QString ServerInfo::commitBranch() const
0091 {
0092     return mCommitBranch;
0093 }
0094 
0095 void ServerInfo::setCommitBranch(const QString &commitBranch)
0096 {
0097     mCommitBranch = commitBranch;
0098 }
0099 
0100 QString ServerInfo::commitTag() const
0101 {
0102     return mCommitTag;
0103 }
0104 
0105 void ServerInfo::setCommitTag(const QString &commitTag)
0106 {
0107     mCommitTag = commitTag;
0108 }
0109 
0110 QString ServerInfo::commitSubject() const
0111 {
0112     return mCommitSubject;
0113 }
0114 
0115 void ServerInfo::setCommitSubject(const QString &commitSubject)
0116 {
0117     mCommitSubject = commitSubject;
0118 }
0119 
0120 QString ServerInfo::commitHash() const
0121 {
0122     return mCommitHash;
0123 }
0124 
0125 void ServerInfo::setCommitHash(const QString &commitHash)
0126 {
0127     mCommitHash = commitHash;
0128 }
0129 
0130 bool ServerInfo::operator==(const ServerInfo &other) const
0131 {
0132     return mArch == other.arch() && mPlatform == other.platform() && mVersion == other.version() && mCommitAuthor == other.commitAuthor()
0133         && mCommitBranch == other.commitBranch() && mCommitTag == other.commitTag() && mCommitSubject == other.commitSubject()
0134         && mCommitHash == other.commitHash() && mNumberOfCpu == other.numberOfCpu() && mOsRelease == other.osRelease() && mNodeVersion == other.nodeVersion();
0135 }
0136 
0137 QString ServerInfo::osRelease() const
0138 {
0139     return mOsRelease;
0140 }
0141 
0142 void ServerInfo::setOsRelease(const QString &osRelease)
0143 {
0144     mOsRelease = osRelease;
0145 }
0146 
0147 QString ServerInfo::nodeVersion() const
0148 {
0149     return mNodeVersion;
0150 }
0151 
0152 void ServerInfo::setNodeVersion(const QString &nodeVersion)
0153 {
0154     mNodeVersion = nodeVersion;
0155 }
0156 
0157 QDebug operator<<(QDebug d, const ServerInfo &t)
0158 {
0159     d << "arch " << t.arch();
0160     d << "platform " << t.platform();
0161     d << "version " << t.version();
0162     d << "cpu number " << t.numberOfCpu();
0163     d << "commit author " << t.commitAuthor();
0164     d << "commit branch " << t.commitBranch();
0165     d << "commit tag " << t.commitTag();
0166     d << "commit subject " << t.commitSubject();
0167     d << "commit hash " << t.commitHash();
0168     d << "os release " << t.osRelease();
0169     d << "node version " << t.nodeVersion();
0170     return d;
0171 }