File indexing completed on 2024-04-28 05:41:26

0001 /*
0002     This file is part of KCachegrind.
0003 
0004     SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only
0007 */
0008 
0009 /*
0010  * Base class for loaders of profiling data.
0011  */
0012 
0013 #ifndef LOADER_H
0014 #define LOADER_H
0015 
0016 #include <QList>
0017 #include <QString>
0018 
0019 class QIODevice;
0020 class TraceData;
0021 class Loader;
0022 class Logger;
0023 
0024 /**
0025  * To implement a new loader, inherit from the Loader class and
0026  * and reimplement canLoad() and load().
0027  *
0028  * For registration, put into the static initLoaders() function
0029  * of this base class a _loaderList.append(new MyLoader()).
0030  *
0031  * matchingLoader() returns the first loader able to load a file.
0032  *
0033  * To show progress and warnings while loading,
0034  *   loadStatus(), loadError() and loadWarning() should be called.
0035  * These are just shown as status, warnings or errors to the
0036  * user, but do not show real failure, as even errors can be
0037  * recoverable. For inability to load a file, return 0 in
0038  * load().
0039  */
0040 
0041 class Loader
0042 {
0043 public:
0044     Loader(const QString& name, const QString& desc);
0045     virtual ~Loader();
0046 
0047     // reimplement for a specific Loader
0048     virtual bool canLoad(QIODevice* file);
0049     /* load a profile data file.
0050      * for every section (time span covered by profile), create a TracePart
0051      * return the number of sections loaded (0 on error)
0052      */
0053     virtual int load(TraceData*, QIODevice* file, const QString& filename);
0054 
0055     static Loader* matchingLoader(QIODevice* file);
0056     static Loader* loader(const QString& name);
0057     static void initLoaders();
0058     static void deleteLoaders();
0059 
0060     QString name() const { return _name; }
0061     QString description() const { return _description; }
0062 
0063     // consumer for notifications
0064     void setLogger(Logger*);
0065 
0066 protected:
0067     // notifications for the user
0068     void loadStart(const QString& filename);
0069     void loadProgress(int progress); // 0 - 100
0070     void loadError(int line, const QString& msg);
0071     void loadWarning(int line, const QString& msg);
0072     void loadFinished(const QString &msg = QString());
0073 
0074 protected:
0075     Logger* _logger;
0076 
0077 private:
0078     QString _name, _description;
0079 
0080     static QList<Loader*> _loaderList;
0081 };
0082 
0083 
0084 #endif