Skip to content

Commit

Permalink
Remove the qjsonwrapper (qt4->qt5) bridge code.
Browse files Browse the repository at this point in the history
The only object that used this code for serialization/deserialization
was the LoggingItem object.  This was needed when the logging server
was built as a separate executable and the LoggingItem needed to be
passed from one program or machine to another.

The client/server part of the logging server code was removed in 2018
(commit 773ede8) so all the manipulation is done inside a single
program, but the serialization/deserialization code was left in place.
This commit doesn't remove that code, it just changes the
serialization/deserialization functions. These functions are not
compatible with the previous implementation, but they do not need to
be as the JSON produced is internal to a single program.

The serialization/deserialization is still unnecessary and should be
remove in a future commit.
  • Loading branch information
linuxdude42 committed Apr 12, 2023
1 parent bebceb5 commit df9093b
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 239 deletions.
21 changes: 0 additions & 21 deletions mythtv/external/qjsonwrapper/LICENSE

This file was deleted.

4 changes: 0 additions & 4 deletions mythtv/external/qjsonwrapper/README.md

This file was deleted.

121 changes: 0 additions & 121 deletions mythtv/external/qjsonwrapper/qjsonwrapper/Json.cpp

This file was deleted.

72 changes: 0 additions & 72 deletions mythtv/external/qjsonwrapper/qjsonwrapper/Json.h

This file was deleted.

4 changes: 1 addition & 3 deletions mythtv/libs/libmythbase/libmythbase.pro
Expand Up @@ -37,7 +37,6 @@ HEADERS += mythsystemlegacy.h mythtypes.h
HEADERS += threadedfilewriter.h mythsingledownload.h
HEADERS += ternarycompare.h
HEADERS += mythsession.h
HEADERS += ../../external/qjsonwrapper/qjsonwrapper/Json.h
HEADERS += cleanupguard.h portchecker.h
HEADERS += mythsorthelper.h mythdbcheck.h
HEADERS += mythpower.h
Expand Down Expand Up @@ -77,7 +76,6 @@ SOURCES += mythrandom.cpp
SOURCES += stringutil.cpp
SOURCES += threadedfilewriter.cpp mythsingledownload.cpp
SOURCES += mythsession.cpp
SOURCES += ../../external/qjsonwrapper/qjsonwrapper/Json.cpp
SOURCES += cleanupguard.cpp portchecker.cpp
SOURCES += mythsorthelper.cpp dbcheckcommon.cpp
SOURCES += mythpower.cpp
Expand Down Expand Up @@ -222,7 +220,7 @@ inc2.files += mythconfig.h mythconfig.mak

INSTALLS += inc inc2

INCLUDEPATH += ../../external/qjsonwrapper/ ..
INCLUDEPATH += ..
DEPENDPATH += ../../external/libudfread

DEFINES += RUNPREFIX=\\\"$${RUNPREFIX}\\\"
Expand Down
99 changes: 85 additions & 14 deletions mythtv/libs/libmythbase/logging.cpp
Expand Up @@ -7,6 +7,8 @@
#include <QQueue>
#include <QHash>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
#include <QMap>
#include <QRegularExpression>
Expand All @@ -30,6 +32,7 @@
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <stdexcept>
#include <sys/stat.h>
#include <sys/types.h>
#include <utility>
Expand All @@ -54,9 +57,6 @@ extern "C" {
#include <mach/mach.h>
#endif

// QJson
#include "qjsonwrapper/Json.h"

#ifdef Q_OS_ANDROID
#include <android/log.h>
#endif
Expand Down Expand Up @@ -136,14 +136,71 @@ LoggingItem::LoggingItem(const char *_file, const char *_function,
setThreadTid();
}

// Create the JSON description of this object using strings to work
// around limitations in the QJsonValue class. All numbers in that
// class are held as an IEEE 754 double precision value. That limits
// them to 2^53 (-9007199254740992 to +9007199254740992), which isn't
// enough to handle the 64-bit values in this class. Format all the
// numbers as strings for consistency.
QByteArray LoggingItem::toByteArray(void)
{
QVariantMap variant = QJsonWrapper::qobject2qvariant(this);
QByteArray json = QJsonWrapper::toJson(variant);
QJsonObject obj {
// numbers
{ "pid" , QString::number(m_pid) },
{ "tid" , QString::number(m_tid) },
{ "threadId" , QString::number(m_threadId) },
{ "line" , QString::number(m_line) },
{ "type" , QString::number(m_type) },
{ "level" , QString::number(m_level) },
{ "facility" , QString::number(m_facility) },
{ "epoch" , QString::number(m_epoch.count()) },
// strings
{ "file" , m_file },
{ "function" , m_function },
{ "threadName" , m_threadName },
{ "appName" , m_appName },
{ "table" , m_table },
{ "logFile" , m_logFile },
{ "message" , m_message }
};
QJsonDocument doc(obj);
return doc.toJson();
}

//cout << json.constData() << endl;
// Validate the existence of and parse one string from a QJsonObject.
// Throw an error if there is any problem.
static inline QString obj2str(const QJsonObject& obj, const QString& key)
{
if (obj.contains(key) && obj[key].isString())
return obj[key].toString();
throw std::runtime_error("Invalid or missing parameter");
}

return json;
// Create a LoggingItem object from a JSON string. Throw an error if
// there is any problem.
LoggingItem::LoggingItem(const QJsonDocument& doc) :
ReferenceCounter("LoggingItem", false)
{
if (!doc.isObject())
throw std::runtime_error("Invalid document");
QJsonObject obj = doc.object();

m_pid = obj2str(obj, "pid").toInt();
m_tid = obj2str(obj, "tid").toLongLong();
m_threadId = obj2str(obj, "threadId").toULongLong();
m_line = obj2str(obj, "line").toInt();
m_type = static_cast<LoggingType>(obj2str(obj, "type").toInt());
m_level = static_cast<LogLevel_t> (obj2str(obj, "level").toInt());
m_facility = obj2str(obj, "facility").toInt();
m_epoch = std::chrono::microseconds(obj2str(obj, "epoch").toLongLong());

m_file = obj2str(obj, "file");
m_function = obj2str(obj, "function");
m_threadName = obj2str(obj, "threadName");
m_appName = obj2str(obj, "appName");
m_table = obj2str(obj, "table");
m_logFile = obj2str(obj, "logFile");
m_message = obj2str(obj, "message");
}

/// \brief Get the name of the thread that produced the LoggingItem
Expand Down Expand Up @@ -543,15 +600,29 @@ LoggingItem *LoggingItem::create(const char *_file,
return item;
}

/// \brief Create a new LoggingItem from a JSON string
//
// The string provided to this function must have been created by the
// LoggingItem::toByteArray function. If there is a problem with the
// string, this function will print an error to the console and
// return nullptr.
LoggingItem *LoggingItem::create(QByteArray &buf)
{
// Deserialize buffer
QVariant variant = QJsonWrapper::parseJson(buf);

auto *item = new LoggingItem;
QJsonWrapper::qvariant2qobject(variant.toMap(), item);

return item;
try
{
// Deserialize buffer
QJsonDocument doc = QJsonDocument::fromJson(buf);
return new LoggingItem(doc);
}
catch(const std::exception& e)
{
std::cerr << "Exception ("
<< e.what()
<< ") creating logging item for: "
<< buf.data()
<< std::endl;
return nullptr;
}
}


Expand Down

0 comments on commit df9093b

Please sign in to comment.