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
ZblLogBkSearch.cpp
Go to the documentation of this file.
1 #include "ZblLogBkSearch.h"
2 #include <QtQml>
3 #include "ZLogViewport.h"
4 #include "ZblLogSearch.h"
5 #include "ZblLogManager.h"
6 #include "ZblLogReader.h"
7 #include "ZLogReader.h"
8 #include "ZblLogSearchParams.h"
9 #include "ZblLogScanner.h"
10 #include <QVariantMap>
11 #include <QVariant>
12 
13 namespace Zbl
14 {
16 
18  qint64 startPosition,
19  ZblLogSearchParams params,
20  ZblLogReader* reader)
21  : m_params(params), m_reader(reader), m_startPosition(startPosition), m_upPosition(-1), m_downPosition(-1)
22 {
23  zDebug() << "ZblLogBkSearch::ZblLogBkSearch";
24 
25  // create input viewports for background scanning
26 
27  static const int vpSize = 100; // TBD - arbitrary choice - experiment to determine optimal size
28 
29  m_vpUp = new ZLogViewport(m_reader, vpSize, this, true);
30 
32 
33  m_vpDown = new ZLogViewport(m_reader, vpSize, this, true);
34 
36 }
37 
39 {
40  zDebug() << "ZblLogBkSearch::~ZblLogBkSearch";
41 }
42 
43 
44 
46 {
48 
49  qmlRegisterUncreatableType<ZblLogBkSearch>("org.zuble.qml", 1, 0,
50  "ZblLogBkSearch", "ZblLogBkSearch is an internal Zuble type. Use ZLogReader instead.");
51 
52 }
53 
54 void ZblLogBkSearch::markupViewport(QObject* viewport)
55 {
56  markupViewport(viewport, &m_params);
57 }
58 
59 void ZblLogBkSearch::markupViewport(QObject* viewport, ZblLogSearchParams params)
60 {
61  markupViewport(viewport, &params);
62 }
63 
64 void ZblLogBkSearch::markupViewport(QObject* viewport, ZblLogSearchParams* params)
65 {
66  zDebug() << "ZblLogBkSearch::markupViewport called";
67 
68  const int chunkSize = 500;
69 
70  ZLogViewport* signalVp = qobject_cast<ZLogViewport*>(viewport);
71 
72  if(!signalVp)
73  throw ZblException("Error - viewport must be a ZLogViewport object.");
74 
75  ZTableModel* model = signalVp->getZModel();
76 
77  //zblLogSearchPtr search = signalVp->getZSearch();
78 
81  //| ZblLogScanner::SendRowsMatchedSignal // TBD: NEED THIS NO SIGNALS NOW?
82  //| ZblLogScanner::SendFindCompleteSignal;
83 
84  ZblLogScanner scanner(params, flags, true);
85 
86  ZblLogSearchList searchList = scanner.scanModelColumnRows(model, chunkSize, signalVp);
87 
88  emit markupUpdated(signalVp, searchList);
89 
90  zDebug() << "markupViewport returned";
91 }
92 
94 {
95 
96  zDebug() << "startSearch function entered";
97 
98  // set up initial parameters
99 
100  m_upPosition = 0;
101 
102  // dispatch call to scanForward
103 
104 
105  zDebug() << "invoking initial scanForward...";
106 
107  QMetaObject::invokeMethod(this, "scanForward",
108  Qt::QueuedConnection);
109 
110 
111  zDebug() << "invoked initial scanForward...";
112 
113 }
114 
115 
117 {
118  zDebug() << "scanForward called for seek position: " << m_downPosition;
119 
120  QVariantMap context;
121  //context.insert("zbl-search-scan", QVariant(true));
122 
123  qint64 vpSize = m_vpDown->getMaxRecordCount();
124 
125  const bool loadMarkupColumn = false;
126 
127 
128  // load input viewport which will signal onLoadViewportComplete
129 
130  QMetaObject::invokeMethod(m_reader, "loadViewport",
131  Qt::QueuedConnection,
132  Q_ARG(QObject*, m_vpDown),
133  Q_ARG(qint64, m_downPosition),
134  Q_ARG(qint64, vpSize),
136  Q_ARG(bool, loadMarkupColumn),
137  Q_ARG(QVariantMap, context));
138 
139 }
140 
142  bool eof,
143  QString errorMsg,
144  QVariantMap context)
145 {
146 
147  zDebug() << "onLoadComplete called";
148 
149  if(!errorMsg.isEmpty())
150  {
151  zWarning() << "Scanning file error encountered:" << errorMsg;
152  }
153 
154  ZTableModel* model = m_vpDown->getZModel();
155 
157 
158  const int chunkSize = 27; // arbitrary size for testing
159 
160  ZblLogScanner scanner(&m_params, flags, false);
161 
162  scanner.scanModelColumnRows(model, chunkSize);
163 
164 
165  if(!eof)
166  {
167  const int rowCount = model->modelRowCount();
168 
169  m_downPosition = model->getValue(m_vpDown->getSeekIndexRole(), rowCount-1, 0).toInt();
170 
171  zDebug() << "invoking continued scanForward...";
172 
173  QMetaObject::invokeMethod(this, "scanForward",
174  Qt::QueuedConnection);
175 
176  zDebug() << "invoked continued scanForward...";
177  }
178 }
179 
180 
181 
182 
184  qint64 rowsFound,
185  qint64 rowsStored,
186  bool endOfData,
187  QString errorMsg)
188 {
189 
190 }
191 
192 
193 #if 0
194 void ZblLogBkSearch::searchViewport(
195  ZLogViewport* viewport,
196  bool forward,
197  qint64 startRow,
198  const QList<int> roles,
199  int type,
200  const QString& searchPhrase,
201  bool signalFirstFind,
202  qint64 endRow
203  )
204 {
205  zDebug() << "searchViewport called";
206 
207 
208 
209 }
210 #endif
211 
213 {
214 
215 
216  return 0;
217 }
218 
219 } // Zbl
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 markupUpdated(ZLogViewport *viewport, ZblLogSearchList rowsFound)
Sent when a viewport&#39;s markeup data (model column 1) has been updated.
This class allows Zuble log file viewer text search operations to pass parameters between threads...
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
ZLogViewport * m_vpDown
A viewport for scanning the file in the forward direction.
Q_INVOKABLE QVariant getValue(int role, int row)
Obtains the value of the specified data cell.
ZTableModel * getZModel()
Returns the data model containing the viewport&#39;s log records.
ZblLogReader * m_reader
Background log reader object.
A log viewport encapsulates a ZTableModel containing a contiguous subset of log records from a Zuble ...
Definition: ZLogViewport.h:95
Performs log file searches in a background thread.
void scanForward()
Scans a viewport for strings matching the search parameters.
qint64 m_upPosition
The current file position of the reverse scan;.
Definition: ZAndGate.cpp:6
static void zInit()
Initializes search engine. Must be called only once before calling newLogSearcher() the first time...
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
ZBL_DECLARE_LOGGED_OBJECT ZblLogSearchParams m_params
Search parameters for this search object.
#define zWarning()
Definition: zglobal.h:111
This two dimensional table model is used to store and manipulate data.
Definition: ZTableModel.h:96
qint64 getMaxRecordCount()
Returns the number of log records the viewport data model will attempt to hold.
void markupViewport(QObject *viewport)
Updates the markup column (1) of the specified viewport&#39;s data model by scanning the data column (0) ...
#define zDebug()
Definition: zglobal.h:113
void loadComplete(bool endOfData, QString errorMsg, QVariantMap context)
Signals that loading of the viewport requested by a call to loadRecordByIndex() has completed...
void moveComplete(qint64 rowsFound, qint64 rowsStored, bool endOfData, QString errorMsg)
Signals that moving of the viewport requested by a call to move() has completed.
void onMoveComplete(qint64 rowsFound, qint64 rowsStored, bool endOfData, QString errorMsg)
Called when the backward scanning viewport has been moved and is ready.
Log record scanner/highlighter object encapsulates logic for locating and marking up search text...
Definition: ZblLogScanner.h:34
static ZblLogBkSearch * newLogSearcher()
Constructs a ZblLogBkSearch object and moves it to the search thread.
Q_INVOKABLE int modelRowCount() const
Returns the number of rows in the data set. This method may block the current thread.
This class allows Zuble log file viewer text search operations to pass search results between threads...
static int getSeekIndexRole()
Obtain the role number for the file seek position of a log record in the viewport&#39;s log record data m...
Zuble&#39;s Qt Exception Object.
Definition: ZblException.h:45
~ZblLogBkSearch()
destructor
qint64 m_downPosition
The current file position of the forward scan;.
void onLoadComplete(bool eof, QString errorMsg, QVariantMap context)
Called when the forward scanning viewport has been loaded and is ready.
ZblLogSearchList scanModelColumnRows(ZTableModel *model, int chunkSize, ZLogViewport *viewport=NULL, qint64 currentRecordID=-1)
scanModelColumnRows
void startSearch()
Starts a text search of the log file for log records that satisfiy the search criteria. Search direction can be forward or backward or both.