diff --git a/gui/gui.pro b/gui/gui.pro index 2711606..a82b6f3 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -17,6 +17,7 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ + view/DialogStartCaptur.cpp \ view/MainWindow.cpp \ viewmodel/displayString/FilePathDisplay.cpp \ viewmodel/displayString/FilenameDisplay.cpp \ @@ -39,6 +40,7 @@ SOURCES += \ viewmodel/tree/util/Log2TreeItemConverter.cpp HEADERS += \ + view/DialogStartCaptur.h \ view/MainWindow.h \ viewmodel/displayString/DisplayProviderCreator.h \ viewmodel/displayString/FilePathDisplay.h \ @@ -65,6 +67,7 @@ HEADERS += \ viewmodel/tree/util/Log2TreeItemConverter.h FORMS += \ + view/DialogStartCaptur.ui \ view/MainWindow.ui LIBS += -L$$OUT_PWD/../model/ -lmodel diff --git a/gui/main.cpp b/gui/main.cpp index 550ca18..c5229ba 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,35 +1,13 @@ #include "view/MainWindow.h" #include -#include -#include -#include -#include -#include - -#include "parser/JsonParser.h" -#include "viewmodel/table/LogTableModel.h" -#include "viewmodel/displayString/SimpleDisplayProviderCreator.h" -#include "provider/NetworkProvider.h" int main(int argc, char* argv[]) { QApplication a(argc, argv); - MainWindow w; - - DataProvider_ptr testProvider = - std::make_shared(QHostAddress::LocalHost, 12345); - auto warehouse = std::make_shared(); + qRegisterMetaType(); - QObject::connect(dynamic_cast(testProvider.get()), - SIGNAL(provided(const Log_ptr)), - warehouse.get(), - SLOT(addData(const Log_ptr)), - Qt::DirectConnection); - - auto model = new LogTableModel(warehouse); - model->setDisplayProviderCreator(std::make_shared()); - w.setTable(model); + MainWindow w; w.show(); return a.exec(); diff --git a/gui/view/DialogStartCaptur.cpp b/gui/view/DialogStartCaptur.cpp new file mode 100644 index 0000000..590d53e --- /dev/null +++ b/gui/view/DialogStartCaptur.cpp @@ -0,0 +1,26 @@ +#include "DialogStartCaptur.h" +#include "ui_DialogStartCaptur.h" + +DialogStartCaptur::DialogStartCaptur(QWidget* parent) : + QDialog(parent), + ui(new Ui::DialogStartCaptur) +{ + ui->setupUi(this); +} + +/*************************************************************************************************/ +quint16 DialogStartCaptur::getPort() +{ + return static_cast(ui->spinBox->value()); +} + +/*************************************************************************************************/ +QString DialogStartCaptur::getAddress() +{ + return ui->lineEdit->text(); +} + +DialogStartCaptur::~DialogStartCaptur() +{ + delete ui; +} diff --git a/gui/view/DialogStartCaptur.h b/gui/view/DialogStartCaptur.h new file mode 100644 index 0000000..46b7cdc --- /dev/null +++ b/gui/view/DialogStartCaptur.h @@ -0,0 +1,24 @@ +#ifndef DIALOGSTARTCAPTUR_H +#define DIALOGSTARTCAPTUR_H + +#include + +namespace Ui { +class DialogStartCaptur; +} + +class DialogStartCaptur : public QDialog +{ + Q_OBJECT + +public: + explicit DialogStartCaptur(QWidget* parent = nullptr); + quint16 getPort(); + QString getAddress(); + ~DialogStartCaptur(); + +private: + Ui::DialogStartCaptur* ui; +}; + +#endif //DIALOGSTARTCAPTUR_H diff --git a/gui/view/DialogStartCaptur.ui b/gui/view/DialogStartCaptur.ui new file mode 100644 index 0000000..637705f --- /dev/null +++ b/gui/view/DialogStartCaptur.ui @@ -0,0 +1,105 @@ + + + DialogStartCaptur + + + + 0 + 0 + 270 + 170 + + + + Dialog + + + + + + Address + + + + + + + + + Port: + + + + + + + 65535 + + + 12345 + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + DialogStartCaptur + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogStartCaptur + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/view/MainWindow.cpp b/gui/view/MainWindow.cpp index 0543152..923bae6 100644 --- a/gui/view/MainWindow.cpp +++ b/gui/view/MainWindow.cpp @@ -1,20 +1,27 @@ #include "MainWindow.h" #include "ui_MainWindow.h" +#include + +#include "view/DialogStartCaptur.h" + #include "viewmodel/table/ELogColumn.h" #include "viewmodel/tree/LogTreeModel.h" +#include "viewmodel/table/LogTableModel.h" +#include "viewmodel/displayString/SimpleDisplayProviderCreator.h" +#include "data/filter/PrefixFilterFormatCreator.h" +#include "provider/NetworkProvider.h" +#include "parser/JsonParser.h" /*************************************************************************************************/ MainWindow::MainWindow(QWidget* parent) - : QMainWindow(parent) + : QMainWindow(parent), _dataManager(std::make_shared()) , ui(new Ui::MainWindow) { ui->setupUi(this); prepareTableView(); prepareTreeView(); - auto tm = new TreeModel(); - tm->showSelectedLog(nullptr); - ui->treeView->setModel(tm); + createConnections(); } /*************************************************************************************************/ @@ -24,13 +31,59 @@ MainWindow::~MainWindow() } /*************************************************************************************************/ -void MainWindow::setTable(QAbstractTableModel* model) +void MainWindow::setTable(QAbstractItemModel* model) { ui->tableView->setModel(model); -//ui->tableView->setColumnHidden(ELogColumn::id, true); -//ui->tableView->setColumnHidden(ELogColumn::scope, true); - //ui->tableView->setColumnHidden(ELogColumn::lineno, true); + connect(ui->tableView->selectionModel(), + &QItemSelectionModel::currentChanged, + this, + &MainWindow::onTableRowClicked); +} + +/*************************************************************************************************/ +void MainWindow::onTableRowClicked(const QModelIndex& current, const QModelIndex& previous) +{ + Q_UNUSED(previous) + + QAbstractItemModel* abstractModel = ui->tableView->model(); + LogTableModel* tablemodel = dynamic_cast(abstractModel); + + if(current.isValid()) + { + auto log = tablemodel->data(current, Qt::UserRole).value(); + + QAbstractItemModel* treeAbstractModel = ui->treeView->model(); + TreeModel* treemodel = dynamic_cast(treeAbstractModel); + treemodel->showSelectedLog(log); + } +} + +/*************************************************************************************************/ +void MainWindow::onTableDeselected() +{ + QAbstractItemModel* treeAbstractModel = ui->treeView->model(); + TreeModel* treemodel = dynamic_cast(treeAbstractModel); + treemodel->clearView(); +} + +/*************************************************************************************************/ +void MainWindow::onActionStartCapture(bool trigered) +{ + Q_UNUSED(trigered) + + DialogStartCaptur capture; + + capture.setModal(true); + int isOk = capture.exec(); + + if(isOk) + { + auto port = capture.getPort(); + auto address = capture.getAddress(); + qDebug() << address << port; + useNetworkProvider(address, port); + } } /*************************************************************************************************/ @@ -39,11 +92,42 @@ void MainWindow::prepareTableView() ui->tableView->verticalHeader()->setVisible(false); ui->tableView->horizontalHeader()->setSectionResizeMode( QHeaderView::ResizeMode::ResizeToContents); + ui->tableView->horizontalHeader()->setStretchLastSection(true); ui->tableView->horizontalHeader()->setSectionsMovable(true); + ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + + LogTableModel* tableModel = new LogTableModel(); + tableModel->setDisplayProviderCreator(std::make_shared()); + setTable(tableModel); + + connect(&_dataManager, &DataManager::logAdded, tableModel, &LogTableModel::onLogAdded); + connect(&_dataManager, &DataManager::logsReseted, tableModel, &LogTableModel::onLogsChanged); } /*************************************************************************************************/ void MainWindow::prepareTreeView() { ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + + auto tm = new TreeModel(); + ui->treeView->setModel(tm); +} + +/*************************************************************************************************/ +void MainWindow::createConnections() +{ + connect(ui->actionStart_Capture, &QAction::triggered, this, &MainWindow::onActionStartCapture); +} + +/*************************************************************************************************/ +void MainWindow::useNetworkProvider(QString address, quint16 port) +{ + auto netProv = std::make_shared(QHostAddress(address), port); + netProv->setParser(std::make_shared()); + + _dataProvider = netProv; + connect(dynamic_cast(_dataProvider.get()), + SIGNAL(provided(const Log_ptr)), + &_dataManager, + SLOT(onLogProvided(const Log_ptr))); } diff --git a/gui/view/MainWindow.h b/gui/view/MainWindow.h index 38aeec0..37351c1 100644 --- a/gui/view/MainWindow.h +++ b/gui/view/MainWindow.h @@ -3,6 +3,8 @@ #include #include +#include +#include "provider/IProvider.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -16,12 +18,24 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget* parent = nullptr); ~MainWindow(); - void setTable(QAbstractTableModel* model); + void setTable(QAbstractItemModel* model); + +//uncrustify off +private slots: + void onTableRowClicked(const QModelIndex ¤t, const QModelIndex &previous); + void onTableDeselected(); + void onActionStartCapture(bool trigered); +//uncrustify on private: void prepareTableView(); void prepareTreeView(); + void createConnections(); + + void useNetworkProvider(QString address, quint16 port); + DataManager _dataManager; + DataProvider_ptr _dataProvider; Ui::MainWindow* ui; }; diff --git a/gui/viewmodel/table/LogTableModel.cpp b/gui/viewmodel/table/LogTableModel.cpp index 06acc58..5cf0fb0 100644 --- a/gui/viewmodel/table/LogTableModel.cpp +++ b/gui/viewmodel/table/LogTableModel.cpp @@ -3,11 +3,9 @@ #include "viewmodel/displayString/util/DisplayStringProviderMapGenerator.h" /*************************************************************************************************/ -LogTableModel::LogTableModel(LogWarehouse_ptr warehouse) : _warehouse(warehouse) +LogTableModel::LogTableModel() { initColumnMap(); - connect(warehouse.get(), &LogWarehouse::dataAdded, this, &LogTableModel::rowsAdded); - _lastModelSize = _warehouse->getLength(); } /*************************************************************************************************/ @@ -19,7 +17,7 @@ LogTableModel::~LogTableModel() int LogTableModel::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent) - auto size = _warehouse->getLength(); + auto size = _logs.size(); return size; } @@ -33,13 +31,23 @@ int LogTableModel::columnCount(const QModelIndex& parent) const { /*************************************************************************************************/ QVariant LogTableModel::data(const QModelIndex& index, int role) const { - if(!index.isValid() || role != Qt::DisplayRole) + if(!index.isValid() || (role != Qt::DisplayRole and role != Qt::UserRole)) { return QVariant(); } - return providerDisplayRepresentation(_warehouse->getItem(index.row()), - static_cast(index.column())); + if(role == Qt::DisplayRole) + { + return providerDisplayRepresentation(_logs[index.row()], + static_cast(index.column())); + } + + if(role == Qt::UserRole) + { + return QVariant::fromValue(_logs[index.row()]); + } + + return QVariant(); } /*************************************************************************************************/ @@ -62,15 +70,19 @@ void LogTableModel::setDisplayProviderCreator(DisplayProviderCreator_ptr creator } /*************************************************************************************************/ -void LogTableModel::rowsAdded() +void LogTableModel::onLogAdded(Log_ptr log) { - auto warehouseSize = _warehouse->getLength(); - if(_lastModelSize < warehouseSize) - { - beginInsertRows(QModelIndex(), _lastModelSize, warehouseSize - 1); - endInsertRows(); - _lastModelSize = warehouseSize; - } + beginInsertRows(QModelIndex(), _logs.size(), _logs.size()); + _logs.append(log); + endInsertRows(); +} + +/*************************************************************************************************/ +void LogTableModel::onLogsChanged(QList logs) +{ + beginResetModel(); + _logs = logs; + endResetModel(); } /*************************************************************************************************/ diff --git a/gui/viewmodel/table/LogTableModel.h b/gui/viewmodel/table/LogTableModel.h index 25e33df..4d71306 100644 --- a/gui/viewmodel/table/LogTableModel.h +++ b/gui/viewmodel/table/LogTableModel.h @@ -8,7 +8,6 @@ #include #include -#include "LogWarehouse.h" #include "viewmodel/table/ELogColumn.h" #include "viewmodel/displayString/DisplayProviderCreator.h" @@ -17,7 +16,7 @@ class LogTableModel : public QAbstractTableModel Q_OBJECT public: - LogTableModel(LogWarehouse_ptr warehouse); + LogTableModel(); ~LogTableModel() override; @@ -35,15 +34,15 @@ public: //uncrustify off public slots: //uncrustify on - void rowsAdded(); + void onLogAdded(Log_ptr log); + void onLogsChanged(QList logs); private: - int _lastModelSize; QMap _columnMap; - LogWarehouse_ptr _warehouse; + QList _logs; + QMap _textProviders; void initColumnMap(); - QMap _textProviders; QVariant providerDisplayRepresentation(const Log_ptr& log, ELogColumn column) const; }; diff --git a/gui/viewmodel/tree/LogTreeModel.cpp b/gui/viewmodel/tree/LogTreeModel.cpp index c079956..bd98890 100644 --- a/gui/viewmodel/tree/LogTreeModel.cpp +++ b/gui/viewmodel/tree/LogTreeModel.cpp @@ -10,6 +10,7 @@ TreeModel::TreeModel(QObject* parent) : QAbstractItemModel(parent) { + clearView(); } /*************************************************************************************************/ @@ -107,15 +108,9 @@ QVariant TreeModel::headerData(int section, Qt::Orientation orientation, /*************************************************************************************************/ void TreeModel::showSelectedLog(const Log_ptr log) { - QString jsonString = - R"( -{"id":"stderr","level":1,"location":{"file":"../../../host-projects/sono/logic/src/viewModel/factory/ApplicationStarter.cpp","func":"init","lineno":69},"msg":["Lanat", {"type": "int", "summary":"bish tar az bish", "content":{"a":"b", "arr" : ["a", "b", "c", {"a":"b"}], "c":{"a":44}}}],"scope":"global","threadId":124330260010752,"timestamp":1716911725703} -)"; - Log_ptr logf = JsonParser().parse(jsonString); - beginResetModel(); _rootItem = SimpleLog2TreeItemConverter().convert( - logf, + log, DisplayStringProviderMapGenerator::generate( std::make_shared())); endResetModel(); diff --git a/gui/viewmodel/tree/LogTreeModel.h b/gui/viewmodel/tree/LogTreeModel.h index 3999842..20e8b7e 100644 --- a/gui/viewmodel/tree/LogTreeModel.h +++ b/gui/viewmodel/tree/LogTreeModel.h @@ -32,6 +32,7 @@ public slots: //uncrustify on private: + bool _valid = false; std::unique_ptr _rootItem; }; diff --git a/model/include/LogWarehouse.h b/model/include/LogWarehouse.h index bb69e5d..6ed66a6 100644 --- a/model/include/LogWarehouse.h +++ b/model/include/LogWarehouse.h @@ -12,14 +12,8 @@ class LogWarehouse : public QObject public: Log_ptr getItem(int index); int getLength(); - -//uncrustify off -public slots: -//uncrustify on - void addData(const Log_ptr data); - -signals: - void dataAdded(); + int addData(const Log_ptr data); + void clear(); private: QList _data; diff --git a/model/include/data/DataManager.h b/model/include/data/DataManager.h new file mode 100644 index 0000000..7f49ece --- /dev/null +++ b/model/include/data/DataManager.h @@ -0,0 +1,38 @@ +#ifndef DATAMANAGER_H +#define DATAMANAGER_H + +#include + +#include "data/filter/FilterParser.h" +#include "data/filter/IFilter.h" +#include "LogWarehouse.h" + +class DataManager : public QObject +{ + Q_OBJECT + +public: + DataManager(FilterCreator_ptr filterCreator); + + void clearLogs(); + void setFilter(QString filter); + +signals: + void badFilterRequested(QString message); + void logAdded(const Log_ptr log); + void logsReseted(QList logs); + +//uncrustify off +public slots: +//uncrustify on + void onLogProvided(Log_ptr log); + +private: + void resetView(); + + LogWarehouse_ptr _warehouse; + std::shared_ptr > _filter; + FilterParser _parser; +}; + +#endif //DATAMANAGER_H diff --git a/model/include/data/filter/MessageFilter.h b/model/include/data/filter/MessageFilter.h new file mode 100644 index 0000000..4c3ec09 --- /dev/null +++ b/model/include/data/filter/MessageFilter.h @@ -0,0 +1,18 @@ +#ifndef MESSAGEFILTER +#define MESSAGEFILTER + +#include "type/Log.h" +#include "data/filter/IFilter.h" + +class MessageFilter : public IFilter +{ +public: + MessageFilter(QString filter); + + bool isAccepted(Log_ptr input) const override; + +private: + QString _filter; +}; + +#endif //MESSAGEFILTER diff --git a/model/include/data/filter/PrefixFilterFormatCreator.h b/model/include/data/filter/PrefixFilterFormatCreator.h index 658f3c2..f5ccc6a 100644 --- a/model/include/data/filter/PrefixFilterFormatCreator.h +++ b/model/include/data/filter/PrefixFilterFormatCreator.h @@ -8,6 +8,9 @@ class PrefixFilterFormatCreator : public IFilterCreator { public: std::shared_ptr > create(const QString& input) const override; + +private: + std::shared_ptr > createMessageFilter(const QString& input) const; }; #endif //PREFIXFILTERFORMATCREATOR diff --git a/model/include/type/Log.h b/model/include/type/Log.h index eff1b21..b3905d4 100644 --- a/model/include/type/Log.h +++ b/model/include/type/Log.h @@ -25,4 +25,6 @@ struct Log using Log_ptr = std::shared_ptr; +Q_DECLARE_METATYPE(Log_ptr); + #endif //LOG diff --git a/model/model.pro b/model/model.pro index cbf5c88..c153cc6 100644 --- a/model/model.pro +++ b/model/model.pro @@ -8,12 +8,14 @@ TARGET = model HEADERS += \ include/LogWarehouse.h \ include/conf/Strings.h \ + include/data/DataManager.h \ include/data/filter/BypassFilter.h \ include/data/filter/FilterAnd.h \ include/data/filter/FilterOr.h \ include/data/filter/FilterParser.h \ include/data/filter/IFilter.h \ include/data/filter/IFilterCreator.h \ + include/data/filter/MessageFilter.h \ include/data/filter/PrefixFilterFormatCreator.h \ include/parser/JsonParseConfig.h \ include/parser/JsonParser.h \ @@ -28,10 +30,12 @@ HEADERS += \ SOURCES += \ src/LogWarehouse.cpp \ + src/data/DataManager.cpp \ src/data/filter/BypassFilter.cpp \ src/data/filter/FilterAnd.cpp \ src/data/filter/FilterOr.cpp \ src/data/filter/FilterParser.cpp \ + src/data/filter/MessageFilter.cpp \ src/data/filter/PrefixFilterFormatCreator.cpp \ src/parser/JsonParser.cpp \ src/provider/NetworkProvider.cpp diff --git a/model/src/LogWarehouse.cpp b/model/src/LogWarehouse.cpp index 10b73a5..46b1613 100644 --- a/model/src/LogWarehouse.cpp +++ b/model/src/LogWarehouse.cpp @@ -1,6 +1,7 @@ #include "LogWarehouse.h" #include +#include /*************************************************************************************************/ Log_ptr LogWarehouse::getItem(int index) @@ -15,11 +16,15 @@ int LogWarehouse::getLength() } /*************************************************************************************************/ -void LogWarehouse::addData(const Log_ptr data) +int LogWarehouse::addData(const Log_ptr data) { _data.append(data); - qDebug() << data->scope.value(); + return _data.size() - 1; //index of where data is added +} - emit dataAdded(); +/*************************************************************************************************/ +void LogWarehouse::clear() +{ + _data.clear(); } diff --git a/model/src/data/DataManager.cpp b/model/src/data/DataManager.cpp new file mode 100644 index 0000000..c05123c --- /dev/null +++ b/model/src/data/DataManager.cpp @@ -0,0 +1,58 @@ +#include "data/DataManager.h" + +#include "data/filter/BypassFilter.h" +#include "data/filter/PrefixFilterFormatCreator.h" + +/*************************************************************************************************/ +DataManager::DataManager(FilterCreator_ptr filterCreator) : _parser(filterCreator) +{ + _filter = std::make_shared(); + _warehouse = std::make_shared(); +} + +/*************************************************************************************************/ +void DataManager::clearLogs() +{ + emit logsReseted({}); + _warehouse->clear(); +} + +/*************************************************************************************************/ +void DataManager::setFilter(QString filter) +{ + try { + _filter = _parser.parse(filter); + resetView(); + } + catch(std::runtime_error e) + { + _filter = std::make_shared(); + emit badFilterRequested(e.what()); + } +} + +/*************************************************************************************************/ +void DataManager::onLogProvided(const Log_ptr log) +{ + _warehouse->addData(log); + if(_filter->isAccepted(log)) + { + emit logAdded(log); + } +} + +/*************************************************************************************************/ +void DataManager::resetView() +{ + QList logs; + for(int i = 0; i < _warehouse->getLength(); i++) + { + auto log = _warehouse->getItem(i); + if(_filter->isAccepted(log)) + { + logs.append(logs); + } + } + + emit logsReseted(logs); +} diff --git a/model/src/data/filter/MessageFilter.cpp b/model/src/data/filter/MessageFilter.cpp new file mode 100644 index 0000000..80dd0f4 --- /dev/null +++ b/model/src/data/filter/MessageFilter.cpp @@ -0,0 +1,27 @@ +#include "data/filter/MessageFilter.h" + +/*************************************************************************************************/ +MessageFilter::MessageFilter(QString filter) +{ + _filter = filter; +} + +/*************************************************************************************************/ +bool MessageFilter::isAccepted(Log_ptr input) const +{ + if(input->msg.has_value()) + { + for(auto& part : input->msg.value()) + { + if(part.string.has_value()) + { + if(part.string.value().contains(_filter)) + { + return true; + } + } + } + } + + return false; +} diff --git a/model/src/data/filter/PrefixFilterFormatCreator.cpp b/model/src/data/filter/PrefixFilterFormatCreator.cpp index 7fc35a3..2f7d9df 100644 --- a/model/src/data/filter/PrefixFilterFormatCreator.cpp +++ b/model/src/data/filter/PrefixFilterFormatCreator.cpp @@ -1,5 +1,8 @@ #include "data/filter/PrefixFilterFormatCreator.h" +#include + +#include "data/filter/MessageFilter.h" #include "data/filter/BypassFilter.h" /*************************************************************************************************/ @@ -7,5 +10,28 @@ std::shared_ptr > PrefixFilterFormatCreator::create(const QStri { Q_UNUSED(input) - return std::make_shared(); + if(input.startsWith("[MSG")) + { + return createMessageFilter(input); + } + else + { + return std::make_shared(); + } +} + +/*************************************************************************************************/ +std::shared_ptr > PrefixFilterFormatCreator::createMessageFilter( + const QString& input) const +{ + QRegularExpression re(R"(\[MSG (.*)\])"); + auto match = re.match(input); + if(match.hasMatch()) + { + return std::make_shared(match.captured(1)); + } + else + { + return std::make_shared(); + } } diff --git a/model/src/provider/NetworkProvider.cpp b/model/src/provider/NetworkProvider.cpp index 6c3c588..2e723c6 100644 --- a/model/src/provider/NetworkProvider.cpp +++ b/model/src/provider/NetworkProvider.cpp @@ -3,6 +3,8 @@ #include #include #include "parser/JsonParser.h" +#include +#include /*************************************************************************************************/ NetworkProvider::NetworkProvider(QHostAddress hostAddress, quint16 port) @@ -12,20 +14,20 @@ NetworkProvider::NetworkProvider(QHostAddress hostAddress, quint16 port) _isRunning = false; initServer(); - connect(&_timer, &QTimer::timeout, - [this](){ - QString jsonString = - R"( -{"id":"stderr","level":1,"location":{"file":"../../../host-projects/sono/logic/src/viewModel/factory/ApplicationStarter.cpp","func":"init","lineno":69},"msg":["Lanat\n"],"scope":"global","threadId":124330260010752,"timestamp":1716911725703} -)"; - Log_ptr log = JsonParser().parse(jsonString); - static int a = 69; - log->src->lineNumner = a++; - - emit provided(log); - }); +//connect(&_timer, &QTimer::timeout, +//[this](){ +//QString jsonString = +//R"( +//{"id":"stderr","level":1,"location":{"file":"../../../host-projects/sono/logic/src/viewModel/factory/ApplicationStarter.cpp","func":"init","lineno":69},"msg":["Lanat\n"],"scope":"global","threadId":124330260010752,"timestamp":1716911725703} +//)"; +//Log_ptr log = JsonParser().parse(jsonString); +//static int a = 69; +//log->src->lineNumner = a++; + +//emit provided(log); +//}); - _timer.start(1000); +//_timer.start(1000); } /*************************************************************************************************/ @@ -64,14 +66,30 @@ void NetworkProvider::onErrorOccured(QAbstractSocket::SocketError error) /*************************************************************************************************/ void NetworkProvider::createNewConnection() { - //TODO + QTcpSocket* socket = _server.nextPendingConnection(); + QtConcurrent::run([this, socket](){ + while(socket->isOpen()) + { + if(socket->waitForReadyRead()) + { + auto bytes = socket->readLine(); + try { + auto log = _parser->parse(bytes); + emit provided(log); + } + catch(std::exception e) + { + } + } + } + }); } /*************************************************************************************************/ void NetworkProvider::initServer() { - QThread* thread = new QThread(); - _server.moveToThread(thread); +//QThread* thread = new QThread(); +//_server.moveToThread(thread); QObject::connect(&_server, &QTcpServer::newConnection,