Skip to content

Commit

Permalink
Moved server factory functions to dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Sep 10, 2021
1 parent 61206af commit f73b978
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -139,6 +139,7 @@ set(XEUS_HEADERS
${XEUS_INCLUDE_DIR}/xeus/xserver_control_main.hpp
${XEUS_INCLUDE_DIR}/xeus/xserver_shell_main.hpp
${XEUS_INCLUDE_DIR}/xeus/xserver_zmq.hpp
${XEUS_INCLUDE_DIR}/xeus/xserver_zmq_factory.hpp
${XEUS_INCLUDE_DIR}/xeus/xserver_zmq_split.hpp
${XEUS_INCLUDE_DIR}/xeus/xsystem.hpp
${XEUS_INCLUDE_DIR}/xeus/xzmq_serializer.hpp
Expand Down Expand Up @@ -178,6 +179,7 @@ set(XEUS_SOURCES
${XEUS_SOURCE_DIR}/xserver_control_main.cpp
${XEUS_SOURCE_DIR}/xserver_shell_main.cpp
${XEUS_SOURCE_DIR}/xserver_zmq.cpp
${XEUS_SOURCE_DIR}/xserver_zmq_factory.cpp
${XEUS_SOURCE_DIR}/xserver_zmq_split.cpp
${XEUS_SOURCE_DIR}/xshell.hpp
${XEUS_SOURCE_DIR}/xshell.cpp
Expand Down
7 changes: 3 additions & 4 deletions include/xeus/xkernel.hpp
Expand Up @@ -49,18 +49,18 @@ namespace xeus
xkernel(const xconfiguration& config,
const std::string& user_name,
interpreter_ptr interpreter,
server_builder sbuilder,
history_manager_ptr history_manager = make_in_memory_history_manager(),
logger_ptr logger = nullptr,
server_builder sbuilder = make_xserver,
debugger_builder dbuilder = make_null_debugger,
nl::json debugger_config = nl::json::object(),
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

xkernel(const std::string& user_name,
interpreter_ptr interpreter,
server_builder sbuilder,
history_manager_ptr history_manager = make_in_memory_history_manager(),
logger_ptr logger = nullptr,
server_builder sbuilder = make_xserver,
debugger_builder dbuilder = make_null_debugger,
nl::json debugger_config = nl::json::object(),
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);
Expand All @@ -74,7 +74,7 @@ namespace xeus

private:

void init();
void init(server_builder sbuilder);

xconfiguration m_config;
std::string m_kernel_id;
Expand All @@ -83,7 +83,6 @@ namespace xeus
interpreter_ptr p_interpreter;
history_manager_ptr p_history_manager;
logger_ptr p_logger;
server_builder m_server_builder;
server_ptr p_server;
debugger_builder m_debugger_builder;
debugger_ptr p_debugger;
Expand Down
19 changes: 0 additions & 19 deletions include/xeus/xserver.hpp
Expand Up @@ -11,10 +11,6 @@
#define XEUS_SERVER_HPP

#include <functional>
#include <memory>

#include "zmq.hpp"
#include "zmq_addon.hpp"

#include "xeus.hpp"
#include "xkernel_configuration.hpp"
Expand Down Expand Up @@ -89,21 +85,6 @@ namespace xeus
listener m_stdin_listener;
internal_listener m_internal_listener;
};

XEUS_API
std::unique_ptr<xserver> make_xserver(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

XEUS_API
std::unique_ptr<xserver> make_xserver_control_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

XEUS_API
std::unique_ptr<xserver> make_xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);
}

#endif
38 changes: 38 additions & 0 deletions include/xeus/xserver_zmq_factory.hpp
@@ -0,0 +1,38 @@
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay, Martin Renou *
* Copyright (c) 2016, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XEUS_SERVER_ZMQ_FACTORY_HPP
#define XEUS_SERVER_ZMQ_FACTORY_HPP

#include <memory>

#include "zmq.hpp"

#include "xserver.hpp"

namespace xeus
{
XEUS_API
std::unique_ptr<xserver> make_xserver(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

XEUS_API
std::unique_ptr<xserver> make_xserver_control_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);

XEUS_API
std::unique_ptr<xserver> make_xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh = nl::json::error_handler_t::strict);
}

#endif

14 changes: 6 additions & 8 deletions src/xkernel.cpp
Expand Up @@ -73,9 +73,9 @@ namespace xeus
xkernel::xkernel(const xconfiguration& config,
const std::string& user_name,
interpreter_ptr interpreter,
server_builder sbuilder,
history_manager_ptr history_manager,
logger_ptr logger,
server_builder sbuilder,
debugger_builder dbuilder,
nl::json debugger_config,
nl::json::error_handler_t eh)
Expand All @@ -84,39 +84,37 @@ namespace xeus
, p_interpreter(std::move(interpreter))
, p_history_manager(std::move(history_manager))
, p_logger(std::move(logger))
, m_server_builder(sbuilder)
, m_debugger_builder(dbuilder)
, m_debugger_config(debugger_config)
, m_error_handler(eh)
{
init();
init(sbuilder);
}

xkernel::xkernel(const std::string& user_name,
interpreter_ptr interpreter,
server_builder sbuilder,
history_manager_ptr history_manager,
logger_ptr logger,
server_builder sbuilder,
debugger_builder dbuilder,
nl::json debugger_config,
nl::json::error_handler_t eh)
: m_user_name(user_name)
, p_interpreter(std::move(interpreter))
, p_history_manager(std::move(history_manager))
, p_logger(std::move(logger))
, m_server_builder(sbuilder)
, m_debugger_builder(dbuilder)
, m_debugger_config(debugger_config)
, m_error_handler(eh)
{
init();
init(sbuilder);
}

xkernel::~xkernel()
{
}

void xkernel::init()
void xkernel::init(server_builder sbuilder)
{
m_kernel_id = new_xguid();
m_session_id = new_xguid();
Expand All @@ -134,7 +132,7 @@ namespace xeus
p_logger = std::make_unique<xlogger_nolog>();
}

p_server = m_server_builder(m_context, m_config, m_error_handler);
p_server = sbuilder(m_context, m_config, m_error_handler);
p_server->update_config(m_config);

p_debugger = m_debugger_builder(m_context, m_config, m_user_name, m_session_id, m_debugger_config);
Expand Down
25 changes: 0 additions & 25 deletions src/xserver.cpp
Expand Up @@ -7,13 +7,9 @@
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include <memory>
#include <iostream>

#include "xeus/xserver.hpp"
#include "xeus/xserver_zmq.hpp"
#include "xeus/xserver_control_main.hpp"
#include "xeus/xserver_shell_main.hpp"

namespace xeus
{
Expand Down Expand Up @@ -104,25 +100,4 @@ namespace xeus
{
return m_internal_listener(std::move(msg));
}

std::unique_ptr<xserver> make_xserver(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_zmq>(context, config, eh);
}

std::unique_ptr<xserver> make_xserver_control_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_control_main>(context, config, eh);
}

std::unique_ptr<xserver> make_xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_shell_main>(context, config, eh);
}
}
29 changes: 29 additions & 0 deletions src/xserver_zmq_factory.cpp
@@ -0,0 +1,29 @@
#include "xeus/xserver_zmq_factory.hpp"
#include "xeus/xserver_zmq.hpp"
#include "xeus/xserver_control_main.hpp"
#include "xeus/xserver_shell_main.hpp"

namespace xeus
{
std::unique_ptr<xserver> make_xserver(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_zmq>(context, config, eh);
}

std::unique_ptr<xserver> make_xserver_control_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_control_main>(context, config, eh);
}

std::unique_ptr<xserver> make_xserver_shell_main(zmq::context_t& context,
const xconfiguration& config,
nl::json::error_handler_t eh)
{
return std::make_unique<xserver_shell_main>(context, config, eh);
}
}

0 comments on commit f73b978

Please sign in to comment.