Skip to content

Commit

Permalink
text search using dltmessagematcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vifactor committed Jul 23, 2024
1 parent d570bcd commit 74378a6
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 153 deletions.
156 changes: 16 additions & 140 deletions src/searchdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg

QDltMsg msg;
QByteArray buf;
QString text;
QString headerText;
int ctr = 0;
Qt::CaseSensitivity is_Case_Sensitive = Qt::CaseInsensitive;

Expand All @@ -403,9 +401,6 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg
is_Case_Sensitive = Qt::CaseSensitive;
}


QString tempPayLoad;

is_PayloadStartFound = false;
is_PayloadEndFound = false;
is_PayLoadRangeValid = false;
Expand All @@ -427,13 +422,16 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg
if (is_TimeStampSearchSelected) {
matcher.setTimestapmRange(dTimeStampStart, dTimeStampStop);
}
if (msgIdEnabled) {
matcher.setMessageIdFormat(msgIdFormat);
}
matcher.setHeaderSearchEnabled(getHeader());
matcher.setPayloadSearchEnabled(getPayload());

do
{
ctr++; // for file progress indication

text.clear();

if(getNextClicked() || searchtoIndex())
{
searchLine++;
Expand Down Expand Up @@ -474,143 +472,21 @@ void SearchDialog::findMessages(long int searchLine, long int searchBorder, QReg
pluginManager->decodeMsg(msg, fSilentMode);
}

headerText.clear();

/* search header */
if( text.isEmpty() )
const bool matchFound = getRegExp() ? matcher.match(msg, searchTextRegExp) : matcher.match(msg, getText());
if (!matchFound)
{
text += msg.toStringHeader();
if ( msgIdEnabled==true )
{
text += " "+QString::asprintf(msgIdFormat.toUtf8(),msg.getMessageId());
}
tempPayLoad = msg.toStringPayload();

} // get the header text in case not empty
if (!matcher.match(msg))
{
continue; // because if APID or CTID doesn not fit there is no need to search in any payload or header
match = false;
continue;
}

headerText = text;

if(getHeader() == true) // header is search enabled
{
if (getRegExp() == true) // regular expressions are selected
{
if(text.contains(searchTextRegExp))
{
if ( foundLine(searchLine) )
break;
else
continue;
}
else
{
//setMatch(false);
match = false;
}
}
else // no regular expressions search was requested
{
if(true == getText().isEmpty())
{
if ( foundLine(searchLine) ) // so no pattern always fits
{
//qDebug() << "Header search hit in"<< __LINE__;
break;
}
else
continue;
}
else if(true == headerText.contains(getText(),is_Case_Sensitive)) // header search
{
{
if(true == timeStampPayloadValidityCheck(searchLine))
break;
else
continue;
}
}
else // no fit, no display
{
match = false;
}
}
} // end header search

/* search payload */
text.clear();
// TODO: implement functionality about payload start and end
// Note: This feature has been broken for some time before this refactoring:
// See https://github.com/COVESA/dlt-viewer/issues/502

if(getPayload() == true) // if payload is selected in the search box
{
if ( true == is_payLoadSearchSelected )
{
if (payLoadStartpatternCheck(tempPayLoad) ) // if payload pattern search range is set we try to detect the ranges
{
//qDebug() << "Found start payload pattern in " << searchLine << __LINE__;
}
}

if( text.isEmpty())
{
text += msg.toStringPayload();
}

if (getRegExp() == true)
{
if(tempPayLoad.contains(searchTextRegExp))
{
if ( foundLine(searchLine) )
{
//qDebug() << "Search hit in"<< __LINE__;
break;
}
else
{
payLoadStoppatternCheck(tempPayLoad);
continue;
}
}
else
{
//setMatch(false);
match = false;
}
}
else // search option without regular expressions
{
if(getText().isEmpty() == true) // no search text for payload given
{
if(timeStampPayloadValidityCheck(searchLine))
{
break;
}
else
{
payLoadStoppatternCheck(tempPayLoad);
continue;
}

}
else if(tempPayLoad.contains(getText(),is_Case_Sensitive))
{
if(timeStampPayloadValidityCheck(searchLine))
{
break;
}
else
{
payLoadStoppatternCheck(tempPayLoad);
continue;
}
}
else
{
match = false;
}
}
}
if (foundLine(searchLine))
break;
else
continue;
}
while( searchBorder != searchLine );
stoptime();
Expand Down
30 changes: 27 additions & 3 deletions tools/dltmessagematcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DltMessageMatcher::DltMessageMatcher() {}

bool DltMessageMatcher::match(const QDltMsg &msg) const
bool DltMessageMatcher::match(const QDltMsg &msg, const Pattern& pattern) const
{
if (!matchAppId(msg.getApid()) || !matchCtxId(msg.getCtid()))
return false;
Expand All @@ -13,9 +13,33 @@ bool DltMessageMatcher::match(const QDltMsg &msg) const
return false;
}

// TODO: implement
bool matchFound = false;
if (m_headerSearchEnabled) {
auto header = msg.toStringHeader();
if (m_messageIdFormat)
header += ' ' + QString::asprintf(m_messageIdFormat->toUtf8(), msg.getMessageId());
if (std::holds_alternative<QRegularExpression>(pattern)) {
matchFound = header.contains(std::get<QRegularExpression>(pattern));
} else {
const auto& searchText = std::get<QString>(pattern);
matchFound = searchText.isEmpty() || header.contains(searchText, m_caseSensitivity);
}
}

if (matchFound)
return true;

if (m_payloadSearchEnabled) {
const auto payload = msg.toStringPayload();
if (std::holds_alternative<QRegularExpression>(pattern)) {
matchFound = payload.contains(std::get<QRegularExpression>(pattern));
} else {
const auto& searchText = std::get<QString>(pattern);
matchFound = payload.isEmpty() || payload.contains(searchText, m_caseSensitivity);
}
}

return true;
return matchFound;
}

bool DltMessageMatcher::matchAppId(const QString& appId) const
Expand Down
22 changes: 21 additions & 1 deletion tools/dltmessagematcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#define DLTMESSAGEMATCHER_H

#include <QString>
#include <QRegularExpression>

class QDltMsg;

class DltMessageMatcher
{
public:
using Pattern = std::variant<QString, QRegularExpression>;

DltMessageMatcher();

void setCaseSentivity(Qt::CaseSensitivity caseSensitivity) {
Expand All @@ -26,7 +29,19 @@ class DltMessageMatcher
m_timestampRange = {start, end};
}

bool match(const QDltMsg& message) const;
void setHeaderSearchEnabled(bool enabled) {
m_headerSearchEnabled = enabled;
}

void setPayloadSearchEnabled(bool enabled) {
m_payloadSearchEnabled = enabled;
}

void setMessageIdFormat(const QString& msgIdFormat) {
m_messageIdFormat = msgIdFormat;
}

bool match(const QDltMsg& message, const Pattern& pattern) const;
private:
bool matchAppId(const QString& appId) const;
bool matchCtxId(const QString& ctxId) const;
Expand All @@ -42,6 +57,11 @@ class DltMessageMatcher
std::optional<TimestampRange> m_timestampRange;

Qt::CaseSensitivity m_caseSensitivity{Qt::CaseInsensitive};

bool m_headerSearchEnabled{true};
bool m_payloadSearchEnabled{true};

std::optional<QString> m_messageIdFormat;
};

#endif // DLTMESSAGEMATCHER_H
Loading

0 comments on commit 74378a6

Please sign in to comment.