Skip to content

Commit

Permalink
[refactor][interface] Remove abstract sc-component-manager and fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
MksmOrlov committed Jun 13, 2024
1 parent ca3f1bc commit 728c75f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 172 deletions.

This file was deleted.

This file was deleted.

43 changes: 22 additions & 21 deletions src/manager/console-interface/sc_component_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/select.h>

#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;
Expand All @@ -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()
Expand All @@ -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<std::string, CommandParameters> 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;
}
19 changes: 5 additions & 14 deletions src/manager/console-interface/sc_component_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,24 @@ class ScComponentManager
explicit ScComponentManager(std::map<ScAddr, std::string, ScAddrLessFunc> 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<ScAddr, std::string, ScAddrLessFunc> 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<sc_bool> m_isRunning;
std::atomic<sc_bool> m_isRunning{};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
#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"

#include "init-module/utils/sc_component_manager_command_init.hpp"
#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<ScAddr, std::string, ScAddrLessFunc> componentsPath)
Expand All @@ -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;
Expand Down Expand Up @@ -68,7 +66,7 @@ class ScComponentManagerCommandHandler : public ScComponentManagerHandler
return executionResult;
}

~ScComponentManagerCommandHandler() override
~ScComponentManagerCommandHandler()
{
m_context->Destroy();
delete m_context;
Expand Down
19 changes: 0 additions & 19 deletions src/manager/console-interface/sc_component_manager_handler.hpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/manager/console-interface/sc_component_manager_impl.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions src/manager/console-interface/sc_component_manager_impl.hpp

This file was deleted.

28 changes: 16 additions & 12 deletions src/module/sc_component_manager_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScAddr, std::string, ScAddrLessFunc> const & componentsPath = {
{{keynodes::ScComponentManagerKeynodes::concept_reusable_kb_component,
m_params.Get<std::string>(KB_COMPONENTS_PATH)},
{keynodes::ScComponentManagerKeynodes::concept_reusable_ps_component,
m_params.Get<std::string>(PS_COMPONENTS_PATH)},
{keynodes::ScComponentManagerKeynodes::concept_reusable_ui_component,
m_params.Get<std::string>(INTERFACE_COMPONENTS_PATH)}}};

try
{
m_scComponentManager = ScComponentManagerFactory::ConfigureScComponentManager(m_params);
m_scComponentManager = std::make_unique<ScComponentManager>(componentsPath);
if (!m_scComponentManager)
return SC_RESULT_ERROR;

Expand Down
6 changes: 3 additions & 3 deletions src/module/sc_component_manager_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScComponentManager> m_scComponentManager;
};

0 comments on commit 728c75f

Please sign in to comment.