diff --git a/include/actsim_agent/log_parser.hpp b/include/actsim_agent/log_parser.hpp new file mode 100644 index 0000000..1018ef2 --- /dev/null +++ b/include/actsim_agent/log_parser.hpp @@ -0,0 +1,50 @@ + +/************************************************************************* + * + * This file is part of the ACT library + * + * Copyright (c) 2024 Fabian Posch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ************************************************************************** + */ + +#ifndef __LOG_PARSER__ +#define __LOG_PARSER__ + +#include +#include "agent_artifact.hpp" + +class LogParser { + + public: + + LogParser(std::unique_ptr& artifact, std::shared_ptr reference); + LogParser(std::unique_ptr& artifact); + + void parse_log(const std::string& line); + void parse_error(const std::string& line); + + private: + + std::unique_ptr& artifact; + + std::shared_ptr reference; + bool has_reference; +}; + +#endif diff --git a/src/actsim_agent/log_parser.cpp b/src/actsim_agent/log_parser.cpp new file mode 100644 index 0000000..3df8eef --- /dev/null +++ b/src/actsim_agent/log_parser.cpp @@ -0,0 +1,43 @@ + +/************************************************************************* + * + * This file is part of the ACT library + * + * Copyright (c) 2024 Fabian Posch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + ************************************************************************** + */ + +#include "log_parser.hpp" + +LogParser::LogParser(std::unique_ptr& artifact, std::shared_ptr reference) : artifact(artifact) { + this->reference = reference; + this->has_reference = true; +} + +LogParser::LogParser(std::unique_ptr& artifact) : artifact(artifact) { + this->has_reference = false; +}; + +void LogParser::parse_log(const std::string& line) { + this->artifact->add_log_output(line); +} + +void LogParser::parse_error(const std::string& line) { + this->artifact->add_err_output(line); +} diff --git a/src/actsim_agent/worker.cpp b/src/actsim_agent/worker.cpp index 0ab9dbc..63f6302 100644 --- a/src/actsim_agent/worker.cpp +++ b/src/actsim_agent/worker.cpp @@ -30,6 +30,7 @@ #include #include #include "util.h" +#include "log_parser.hpp" #include "worker.hpp" Worker::Worker(TaskInterface& interface) : interface(interface) {} @@ -328,6 +329,14 @@ std::unique_ptr Worker::perform_task(std::unique_ptr& tas task->source_config ); + // create the output parser + std::unique_ptr parser; + if (task->reference == 0) { + parser = std::make_unique(result); + } else { + parser = std::make_unique(result, this->interface.get_reference(task->reference)); + } + std::vector& commands = task->get_content()[0].commands; size_t command_n = 0; size_t last_pos = 0; @@ -389,7 +398,7 @@ std::unique_ptr Worker::perform_task(std::unique_ptr& tas // make sure any remaining output is added to the log if (stdout_buf != "") { - result->add_log_output(stdout_buf); + parser->parse_log(stdout_buf); } DEBUG_PRINT("STDOUT was closed by child"); @@ -404,7 +413,7 @@ std::unique_ptr Worker::perform_task(std::unique_ptr& tas auto pos = stdout_buf.find('\n'); while (pos != std::string::npos) { DEBUG_PRINT("Log output line was added"); - result->add_log_output(stdout_buf.substr(0, pos)); + parser->parse_log(stdout_buf.substr(0, pos)); if ((pos + 1) < stdout_buf.length()) { stdout_buf = stdout_buf.substr(pos+1, stdout_buf.length()); @@ -439,7 +448,7 @@ std::unique_ptr Worker::perform_task(std::unique_ptr& tas // make sure any remaining output is added to the log if (stderr_buf != "") { - result->add_err_output(stderr_buf); + parser->parse_error(stderr_buf); } DEBUG_PRINT("STDERR was closed by child"); @@ -454,7 +463,7 @@ std::unique_ptr Worker::perform_task(std::unique_ptr& tas auto pos = stderr_buf.find('\n'); while (pos != std::string::npos) { DEBUG_PRINT("Error output line was added"); - result->add_err_output(stderr_buf.substr(0, pos)); + parser->parse_error(stderr_buf.substr(0, pos)); if ((pos + 1) < stderr_buf.length()) { stderr_buf = stderr_buf.substr(pos+1, stderr_buf.length());