diff --git a/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.cpp b/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.cpp deleted file mode 100644 index b73de6a..0000000 --- a/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#include "sc_component_manager_factory.hpp" -#include "sc_component_manager_impl.hpp" - -std::unique_ptr ScComponentManagerFactory::ConfigureScComponentManager( - ScParams const & scComponentManagerParams) -{ - std::string const KB_COMPONENT_PATH = "knowledge_base_components_path"; - std::string const PS_COMPONENT_PATH = "problem_solver_components_path"; - std::string const INTERFACE_COMPONENT_PATH = "interface_components_path"; - - try - { - std::map const & componentsPath = { - {{keynodes::ScComponentManagerKeynodes::concept_reusable_kb_component, - scComponentManagerParams.Get(KB_COMPONENT_PATH)}, - {keynodes::ScComponentManagerKeynodes::concept_reusable_ps_component, - scComponentManagerParams.Get(PS_COMPONENT_PATH)}, - {keynodes::ScComponentManagerKeynodes::concept_reusable_ui_component, - scComponentManagerParams.Get(INTERFACE_COMPONENT_PATH)}}}; - - std::unique_ptr scComponentManager = - std::unique_ptr(new ScComponentManagerImpl(componentsPath)); - return scComponentManager; - } - catch (utils::ScException const & exception) - { - SC_LOG_ERROR("ScComponentManagerFactory: ScComponentManager configuration error."); - } - - return {}; -} diff --git a/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.hpp b/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.hpp deleted file mode 100644 index 9cb5fdd..0000000 --- a/src/manager/console-interface/sc-component-manager-factory/sc_component_manager_factory.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#pragma once - -#include "sc_component_manager.hpp" -#include "sc-config-utils/sc_memory_config.hpp" - -class ScComponentManagerFactory -{ -public: - static std::unique_ptr ConfigureScComponentManager(ScParams const & scComponentManagerParams); -}; diff --git a/src/manager/console-interface/sc_component_manager.cpp b/src/manager/console-interface/sc_component_manager.cpp index 684b52b..81e6c8c 100644 --- a/src/manager/console-interface/sc_component_manager.cpp +++ b/src/manager/console-interface/sc_component_manager.cpp @@ -11,6 +11,7 @@ #include #include "sc_component_manager.hpp" +#include "command_parser/sc_component_manager_command_parser.hpp" static constexpr int STD_INPUT = 0; static constexpr suseconds_t WAIT_BETWEEN_SELECT_US = 250000L; @@ -21,14 +22,11 @@ void ScComponentManager::Run() m_instance = std::thread(&ScComponentManager::Start, this); } -sc_bool ScComponentManager::HasNewInput() +void ScComponentManager::Stop() { - struct timeval waitTime = {0L, WAIT_BETWEEN_SELECT_US}; - fd_set fds; - FD_ZERO(&fds); - FD_SET(STD_INPUT, &fds); - int ready = select(STD_INPUT + 1, &fds, nullptr, nullptr, &waitTime); - return ready > 0; + m_isRunning = SC_FALSE; + if (m_instance.joinable()) + m_instance.join(); } void ScComponentManager::Start() @@ -55,22 +53,25 @@ void ScComponentManager::Start() } } -void ScComponentManager::Stop() +sc_bool ScComponentManager::HasNewInput() { - m_isRunning = SC_FALSE; - if (m_instance.joinable()) - m_instance.join(); + struct timeval waitTime = {0L, WAIT_BETWEEN_SELECT_US}; + fd_set fds; + FD_ZERO(&fds); + FD_SET(STD_INPUT, &fds); + int ready = select(STD_INPUT + 1, &fds, nullptr, nullptr, &waitTime); + return ready > 0; } -void ScComponentManager::QuietInstall() +bool ScComponentManager::Emit(std::string const & command) { - try - { - Emit("components init"); - Emit("components install"); - } - catch (utils::ScException const & exception) - { - SC_LOG_ERROR(exception.Message()); - } + std::pair const parsedCommand = ScComponentManagerParser::Parse(command); + ScComponentManagerCommandHandler handler(m_componentsPath); + bool const executionResult = handler.Handle(parsedCommand.first, parsedCommand.second); + + std::string const logMessage = executionResult ? "successfully" : "unsuccessfully"; + + SC_LOG_DEBUG("ScComponentManagerImpl: command executed " << logMessage); + + return executionResult; } diff --git a/src/manager/console-interface/sc_component_manager.hpp b/src/manager/console-interface/sc_component_manager.hpp index 3b50377..a78f0a8 100644 --- a/src/manager/console-interface/sc_component_manager.hpp +++ b/src/manager/console-interface/sc_component_manager.hpp @@ -21,33 +21,24 @@ class ScComponentManager explicit ScComponentManager(std::map componentsPath) : m_componentsPath(std::move(componentsPath)) { - m_handler = new ScComponentManagerCommandHandler(m_componentsPath); } - void QuietInstall(); - void Run(); - virtual bool Emit(std::string const & command) = 0; - void Stop(); - virtual ~ScComponentManager() - { - delete m_handler; - m_handler = nullptr; - } + virtual ~ScComponentManager() = default; protected: std::map m_componentsPath; - sc_bool static HasNewInput(); - void Start(); - ScComponentManagerCommandHandler * m_handler; + sc_bool static HasNewInput(); + + bool Emit(std::string const & command); private: std::thread m_instance; - std::atomic m_isRunning; + std::atomic m_isRunning{}; }; diff --git a/src/manager/console-interface/sc_component_manager_command_handler.hpp b/src/manager/console-interface/sc_component_manager_command_handler.hpp index 11461b7..8549c96 100644 --- a/src/manager/console-interface/sc_component_manager_command_handler.hpp +++ b/src/manager/console-interface/sc_component_manager_command_handler.hpp @@ -11,8 +11,6 @@ #include "sc-agents-common/utils/CommonUtils.hpp" #include "sc-agents-common/utils/AgentUtils.hpp" -#include "sc_component_manager_handler.hpp" - #include "common-module/module/utils/common_utils.hpp" #include "common-module/module/keynodes/ScComponentManagerKeynodes.hpp" @@ -20,7 +18,7 @@ #include "search-module/utils/sc_component_manager_command_search.hpp" #include "install-module/utils/sc_component_manager_command_install.hpp" -class ScComponentManagerCommandHandler : public ScComponentManagerHandler +class ScComponentManagerCommandHandler { public: explicit ScComponentManagerCommandHandler(std::map componentsPath) @@ -35,7 +33,7 @@ class ScComponentManagerCommandHandler : public ScComponentManagerHandler {"install", new ScComponentManagerCommandInstall(m_componentsPath)}}; } - bool Handle(std::string const & commandType, CommandParameters const & commandParameters) override + bool Handle(std::string const & commandType, CommandParameters const & commandParameters) { bool executionResult; m_commandParameters = commandParameters; @@ -68,7 +66,7 @@ class ScComponentManagerCommandHandler : public ScComponentManagerHandler return executionResult; } - ~ScComponentManagerCommandHandler() override + ~ScComponentManagerCommandHandler() { m_context->Destroy(); delete m_context; diff --git a/src/manager/console-interface/sc_component_manager_handler.hpp b/src/manager/console-interface/sc_component_manager_handler.hpp deleted file mode 100644 index edf1257..0000000 --- a/src/manager/console-interface/sc_component_manager_handler.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#pragma once - -#include - -#include "common-module/commands/sc_component_manager_command.hpp" - -class ScComponentManagerHandler -{ -public: - virtual bool Handle(std::string const & commandType, CommandParameters const & commandParameters) = 0; - - virtual ~ScComponentManagerHandler() = default; -}; diff --git a/src/manager/console-interface/sc_component_manager_impl.cpp b/src/manager/console-interface/sc_component_manager_impl.cpp deleted file mode 100644 index 87afbca..0000000 --- a/src/manager/console-interface/sc_component_manager_impl.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#include "sc_component_manager_impl.hpp" -#include "command_parser/sc_component_manager_command_parser.hpp" - -bool ScComponentManagerImpl::Emit(std::string const & command) -{ - std::pair parsed = ScComponentManagerParser::Parse(command); - bool executionResult = m_handler->Handle(parsed.first, parsed.second); - - std::string log_message = executionResult ? "successfully" : "unsuccessfully"; - - SC_LOG_DEBUG("ScComponentManagerImpl: command executed " + log_message); - - return executionResult; -} diff --git a/src/manager/console-interface/sc_component_manager_impl.hpp b/src/manager/console-interface/sc_component_manager_impl.hpp deleted file mode 100644 index 36bb16f..0000000 --- a/src/manager/console-interface/sc_component_manager_impl.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This source file is part of an OSTIS project. For the latest info, see http://ostis.net - * Distributed under the MIT License - * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) - */ - -#pragma once - -#include - -#include "sc_component_manager.hpp" - -class ScComponentManagerImpl : public ScComponentManager -{ -public: - ScComponentManagerImpl(std::map componentsPath) - : ScComponentManager(std::move(componentsPath)) - { - } - - ~ScComponentManagerImpl() override = default; - -protected: - bool Emit(std::string const & command) override; -}; diff --git a/src/module/sc_component_manager_module.cpp b/src/module/sc_component_manager_module.cpp index 917501a..de2d323 100644 --- a/src/module/sc_component_manager_module.cpp +++ b/src/module/sc_component_manager_module.cpp @@ -6,29 +6,33 @@ #include "sc_component_manager_module.hpp" -#include "sc-component-manager-factory/sc_component_manager_factory.hpp" - SC_IMPLEMENT_MODULE(ScComponentManagerModule) sc_result ScComponentManagerModule::InitializeImpl() { - // It is backward compatible logic. When all platform-dependent components will be configured from kb it will be - // removed. + std::string const KB_COMPONENTS_PATH = "knowledge_base_components_path"; + std::string const PS_COMPONENTS_PATH = "problem_solver_components_path"; + std::string const INTERFACE_COMPONENTS_PATH = "interface_components_path"; + + // It is backward compatible logic. We should configure platform-dependent components from kb ScConfig config{ ScMemory::ms_configPath, - {"knowledge_base_components_path", - "problem_solver_components_path", - "interface_components_path", - "repo_path", - "extensions_path", - "log_file"}}; + {KB_COMPONENTS_PATH, PS_COMPONENTS_PATH, INTERFACE_COMPONENTS_PATH, "repo_path", "extensions_path", "log_file"}}; ScConfigGroup managerConfig = config["sc-component-manager"]; - for (auto const & key : *managerConfig) + for (std::string const & key : *managerConfig) m_params.Insert({key, managerConfig[key]}); + std::map const & componentsPath = { + {{keynodes::ScComponentManagerKeynodes::concept_reusable_kb_component, + m_params.Get(KB_COMPONENTS_PATH)}, + {keynodes::ScComponentManagerKeynodes::concept_reusable_ps_component, + m_params.Get(PS_COMPONENTS_PATH)}, + {keynodes::ScComponentManagerKeynodes::concept_reusable_ui_component, + m_params.Get(INTERFACE_COMPONENTS_PATH)}}}; + try { - m_scComponentManager = ScComponentManagerFactory::ConfigureScComponentManager(m_params); + m_scComponentManager = std::make_unique(componentsPath); if (!m_scComponentManager) return SC_RESULT_ERROR; diff --git a/src/module/sc_component_manager_module.hpp b/src/module/sc_component_manager_module.hpp index f476fb5..b1a9abd 100644 --- a/src/module/sc_component_manager_module.hpp +++ b/src/module/sc_component_manager_module.hpp @@ -18,11 +18,11 @@ class ScComponentManagerModule : public ScModule SC_CLASS(LoadOrder(200)) SC_GENERATED_BODY() - virtual sc_result InitializeImpl() override; + sc_result InitializeImpl() override; - virtual sc_result ShutdownImpl() override; + sc_result ShutdownImpl() override; -public: +protected: ScParams m_params; std::unique_ptr m_scComponentManager; };