WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZblLogReader.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2015 Bob Dinitto
4  *
5  * Filename: ZblLogReader.h
6  * Created on: 11/22/2015
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef ZBLLOGREADER_H
26 #define ZBLLOGREADER_H
27 
28 #include <QObject>
29 #include "zglobal.h"
30 #include <QFile>
31 #include <QMutex>
32 #include <QQueue>
33 #include <QJsonParseError>
34 #include <QUuid>
35 #include "ZblLogRecord.h"
36 #include "ZTableModel.h"
37 #include "ZSettings.h"
38 #include "ZblLogSearchParams.h"
39 
40 namespace Zbl {
41 
42 class ZTableModel;
43 class ZLogViewport;
44 class ZblLogBkSearch;
45 class ZblLogScanner;
46 //class ZblLogSearchParams;
47 
91 class ZblLogReader : public QObject
92 {
93  Q_OBJECT
94 
95  typedef QQueue<QByteArray> zRowBuffer;
96  typedef QList<qint64> zSeekBuffer;
97 public:
98 
99  //typedef QMap<quint64, ZblLogMark> zLogMarkMap;
100 
101  explicit ZblLogReader(QObject *parent = 0);
102 
103  virtual ~ZblLogReader();
104 
110  static void zInit(int logRecordRoleCount);
111 
120  static ZblLogReader* newLogReader();
121 
122 signals:
123 
135  void openComplete(bool success, QString errorMsg, QVariantMap contextMap);
136 
144  void loadRecordsComplete(QObject* viewport, QString errorMsg, QVariantMap contextMap);
145 
162  void loadComplete(
163  QObject* viewport,
164  ZblLogSearchParams searchParams,
165  bool endOfData,
166  QString errorMsg,
167  QVariantMap context);
168 
174  void linkMessageText(
175  QVariant linkList);
176 
177 
182  void notifyFileSize(qint64 fileSize);
183 
184 public slots:
185 
193  void openFile(const QString& filePath, QVariantMap contextMap = QVariantMap());
194 
195  void close();
196 
224  void loadViewport(
225  QObject* viewport,
226  qint64 seekPosition,
227  qint64 viewportSize,
228  ZblLogSearchParams searchParams,
229  bool loadMarkupColumn = false,
230  QVariantMap contextMap = QVariantMap());
231 
232 
256  void move(
257  QObject* viewport,
258  qint64 recordCount,
259  qint64 seekIndex,
260  bool forward,
261  ZblLogSearchParams searchParams,
262  bool loadMarkupColumn);
263 
285  QObject* searchmark,
286  QVariant links);
287 
288 protected:
289 
294  class ZblLogError {
295 
296  public:
297 
299 
301  NO_ERROR = 0,
305  };
306 
308 
309  QJsonParseError parseError;
310 
312  };
313 
314 
319  void timerEvent(QTimerEvent * event);
320 
321 
334  void parseNextFileRecord(
335  ZLogViewport* viewport,
336  const QByteArray& ba,
337  qint64 seekPos,
338  ZblLogScanner &logScanner,
339  ZDataRow& cellBuffer,
340  ZblLogError& logError
341  );
342 
352  void storeViewportData(
353  ZDataRow& cellData,
354  ZLogViewport* viewport,
355  bool truncate = false);
356 
368  zRowBuffer& logRecords,
369  zSeekBuffer &seekPositions,
370  qint64 rowCount,
371  ZLogViewport* viewport,
372  ZblLogScanner& logScanner);
373 
400  QString loadRowsAhead(
401  ZLogViewport* viewport,
402  qint64 seekPos,
403  qint64 rowCount,
404  bool truncate,
405  const ZblLogSearchParams* searchParams,
406  bool loadMarkupColumn,
407  qint64& foundCount,
408  qint64& storedCount,
409  bool& eof
410  );
411 
435  QString loadRowsBehind(
436  ZLogViewport* viewport,
437  qint64 seekPos,
438  qint64 rowCount,
439  const ZblLogSearchParams* searchParams,
440  bool loadMarkupColumn,
441  qint64& foundCount,
442  qint64& storedCount,
443  bool& bof);
444 
453  void initializeMetadata();
454 
456 
461  QFile m_inputFile;
462 
468 
474  //zLogRecordList m_recordBuffer;
475 
480  //zLogMarkMap m_pageMap;
481 
486  static QMutex m_lock;
487 
491  static QThread* m_readerThread;
492 
497  static int m_readerCount;
498 
502  static qint64 m_defaultPageSize;
503 
508  static int m_recordRoleCount;
509 
514  const static int m_updateBatchSize;
515 
520  static const qint64 m_maxLineSize;
521 
522 
528 
536  QVariantMap m_metadata;
537 
547  QUuid m_uuid;
548 
554 
560 
561 };
562 
563 } // Zbl
564 
565 #endif // ZBLLOGREADER_H
void initializeMetadata()
Reads the log file metadata contained in the first record of the log file.
void timerEvent(QTimerEvent *event)
Periodically sends notifyFileSize signal.
static QThread * m_readerThread
A single background thread services all ZblLogReader objects.
Definition: ZblLogReader.h:491
static QMutex m_lock
Histogram buffer caches bytes of file data for subsequent parsing into log records.
Definition: ZblLogReader.h:486
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
This class performs log file I/O operations and JSON parsing in a background thread on behalf of a ZL...
Definition: ZblLogReader.h:91
void linkMessageText(QVariant linkList)
Sent when loadRecordLinkMessageText has completed.
void move(QObject *viewport, qint64 recordCount, qint64 seekIndex, bool forward, ZblLogSearchParams searchParams, bool loadMarkupColumn)
Moves the viewport forward or backward a specific number of records.
This class allows Zuble log file viewer text search operations to pass parameters between threads...
ZSettings * m_notationFile
a file for storing metadata (bookmarks, notations, identification) about the log file.
Definition: ZblLogReader.h:527
QList< qint64 > zSeekBuffer
Definition: ZblLogReader.h:96
QString loadRowsBehind(ZLogViewport *viewport, qint64 seekPos, qint64 rowCount, const ZblLogSearchParams *searchParams, bool loadMarkupColumn, qint64 &foundCount, qint64 &storedCount, bool &bof)
Prepends log data records to the data model scanning backward in the file from the specified seek pos...
QString loadRowsAhead(ZLogViewport *viewport, qint64 seekPos, qint64 rowCount, bool truncate, const ZblLogSearchParams *searchParams, bool loadMarkupColumn, qint64 &foundCount, qint64 &storedCount, bool &eof)
Appends log records to the data model scanning foreward in the file from the specified seek position...
bool m_fileActive
true if input file is open and ready for reading, false otherwise.
Definition: ZblLogReader.h:467
void openFile(const QString &filePath, QVariantMap contextMap=QVariantMap())
Opens the log file in a concurrent background thread. Sends the openComplete signal when open is comp...
QVariantMap m_metadata
A QVariantMap containing meta information about the log file.
Definition: ZblLogReader.h:536
A log viewport encapsulates a ZTableModel containing a contiguous subset of log records from a Zuble ...
Definition: ZLogViewport.h:95
Definition: ZAndGate.cpp:6
static void zInit(int logRecordRoleCount)
Must be called only once before calling newLogReader();.
void storeViewportData(ZDataRow &cellData, ZLogViewport *viewport, bool truncate=false)
Appends data to the back of the viewport&#39;s data model.
void parseNextFileRecord(ZLogViewport *viewport, const QByteArray &ba, qint64 seekPos, ZblLogScanner &logScanner, ZDataRow &cellBuffer, ZblLogError &logError)
Picks the next file record off the input stream buffer, parses it and contatenates results to the dat...
void loadViewport(QObject *viewport, qint64 seekPosition, qint64 viewportSize, ZblLogSearchParams searchParams, bool loadMarkupColumn=false, QVariantMap contextMap=QVariantMap())
Loads a viewport&#39;s log record data model with the a set of records located by a file seek index...
static ZblLogReader * newLogReader()
creates a new ZblLogReader object and moves it to the shared background log reader thread...
void loadRecordLinkMessageText(QObject *searchmark, QVariant links)
Loads the message text from the log file for the specified ZLogSearch object.
int m_timerID
Timer ID for file size timer. Zero == timer inactive.
Definition: ZblLogReader.h:559
static int m_readerCount
Counts instances of ZblLogReader objects.
Definition: ZblLogReader.h:497
Wraps the QSettings class and implements a JSON-based backend for storing the settings data...
Definition: ZSettings.h:44
static qint64 m_defaultPageSize
number of rows in a default page.
Definition: ZblLogReader.h:502
void openComplete(bool success, QString errorMsg, QVariantMap contextMap)
Sent when the file open operation started by calling openFile() has completed.
static int m_recordRoleCount
Number of roles in a log record.
Definition: ZblLogReader.h:508
Log record scanner/highlighter object encapsulates logic for locating and marking up search text...
Definition: ZblLogScanner.h:34
QQueue< QByteArray > zRowBuffer
Definition: ZblLogReader.h:95
static const int m_updateBatchSize
The number of rows to accumulate before sending a row update to the data model. Batching rows reduces...
Definition: ZblLogReader.h:514
A class for passing log file input error information.
Definition: ZblLogReader.h:294
void loadRecordsComplete(QObject *viewport, QString errorMsg, QVariantMap contextMap)
DEPRECATED! Don&#39;t use!
void loadComplete(QObject *viewport, ZblLogSearchParams searchParams, bool endOfData, QString errorMsg, QVariantMap context)
Sent when loading log records into a viewport by calling ZblLogReader::loadViewport() has completed...
ZblLogReader(QObject *parent=0)
static const qint64 m_maxLineSize
The maximum number of bytes a log record can contain.
Definition: ZblLogReader.h:520
ZBL_DECLARE_LOGGED_OBJECT QFile m_inputFile
Input file object from which log records will be read.
Definition: ZblLogReader.h:461
QUuid m_uuid
A UUID that uniquely identifies this log file.
Definition: ZblLogReader.h:547
int parseAndStoreViewportData(zRowBuffer &logRecords, zSeekBuffer &seekPositions, qint64 rowCount, ZLogViewport *viewport, ZblLogScanner &logScanner)
Parses rows from a row buffer and prepends them to the front of the viewport&#39;s data model...
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
Definition: ZTableModel.h:57
virtual ~ZblLogReader()
qint64 m_firstRecordPos
File position of the first log record of the search operation.
Definition: ZblLogReader.h:553
void notifyFileSize(qint64 fileSize)
Periodically signals the current log file size.