Warning, file /system/kjournald/lib/journaldhelper.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-or-later OR MIT
0003     SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
0004 */
0005 
0006 #ifndef JOURNALDHELPER_H
0007 #define JOURNALDHELPER_H
0008 
0009 #include "kjournald_export.h"
0010 #include "localjournal.h"
0011 #include <QDateTime>
0012 #include <QDebugStateSaver>
0013 #include <QObject>
0014 #include <QVector>
0015 
0016 class KJOURNALD_EXPORT JournaldHelper
0017 {
0018     Q_GADGET
0019 public:
0020     /**
0021      * @brief Basic information of a boot
0022      */
0023     struct BootInfo {
0024         QString mBootId; //!< unique identifier of the boot
0025         QDateTime mSince; //!< time of oldest log entry for the specific boot
0026         QDateTime mUntil; //!< time of newest log entry for the specific boot
0027     };
0028 
0029     /**
0030      * @brief Enumeration of most prominent field contents
0031      *
0032      * Names of these fields are identitical to their actual names with the only difference
0033      * that the "_" is removed from the reserved fields for Q_ENUM compatability.
0034      */
0035     enum class Field {
0036         // user fields
0037         MESSAGE,
0038         MESSAGE_ID,
0039         PRIORITY,
0040         CODE_FILE,
0041         CODE_LINE,
0042         CODE_FUNC,
0043         // trusted fields
0044         _BOOT_ID,
0045         _EXE,
0046         _SYSTEMD_CGROUP,
0047         _SYSTEMD_SLICE,
0048         _SYSTEMD_UNIT,
0049         _SYSTEMD_USER_UNIT,
0050         _SYSTEMD_USER_SLICE,
0051         _SYSTEMD_SESSION,
0052         _SYSTEMD_OWNER_UID,
0053         _TRANSPORT,
0054     };
0055     Q_ENUM(Field)
0056 
0057     /**
0058      * @brief Query unique field values fro given field
0059      *
0060      * This method returns all unique values provided by a defined journald database
0061      * field, e.g. the list of all boot-ids or the list of all services.
0062      *
0063      * This method wraps sd_journal_query_unique, which according to its documentation
0064      * ignores any add_match settings of the used @a journal. Yet this may change in the
0065      * future and it is encouraged to use a separate journal object to request unique valus.
0066      *
0067      * @param journal the wrapper object for an sd_journal instance
0068      * @param field the requested field
0069      * @return the list of unique field contents
0070      */
0071     static QVector<QString> queryUnique(const IJournal &journal, Field field);
0072 
0073     /**
0074      * @copydoc JournaldHelper::queryUnique
0075      */
0076     static QVector<QString> queryUnique(std::shared_ptr<IJournal> journal, Field field);
0077 
0078     /**
0079      * @brief Query boot information for @p journal
0080      *
0081      * @return ordered list of boots (first is earliest boot in time)
0082      */
0083     static QVector<BootInfo> queryOrderedBootIds(const IJournal &journal);
0084 
0085     /**
0086      * @brief Mapper method that maps from field enum to textual representation
0087      *
0088      * @param field the field enum for which the textual repesentation is requested
0089      * @return string representation of enum
0090      */
0091     static QString mapField(Field field);
0092 
0093     /**
0094      * @brief Cleanup typical decorations from strings as found in journald databases
0095      * @param string the string to process
0096      * @return cleaned string
0097      */
0098     static QString cleanupString(const QString &string);
0099 };
0100 
0101 QDebug operator<<(QDebug debug, const JournaldHelper::BootInfo &bootInfo);
0102 
0103 #endif // JOURNALDHELPER_H