6#include <boost/uuid/uuid.hpp>
8#include <pybind11/pybind11.h>
9#include <pybind11/embed.h>
10#include "nlohmann/json.hpp"
35 Server(
const std::string& socket);
58 void write(
const std::string& txt);
60 std::string
str()
const;
92 virtual uint64_t
send(
const std::string& output,
const std::string& msg_type,
93 uint64_t parent_id=0, uint64_t cell_id=0,
bool last_in_sequence=
false);
99 bool handles(
const std::string& otype)
const;
175 std::string
run_string(
const std::string&,
bool handle_output=
true);
194 std::future<std::string>
job;
std::string input
Definition Server.hh:160
uint64_t cell_id
Definition Server.hh:163
websocket_server::id_type ws_id
Definition Server.hh:158
std::string output
Definition Server.hh:161
std::string msg_type
Definition Server.hh:159
std::string error
Definition Server.hh:162
nlohmann::json response
Definition Server.hh:167
Python output catching.
Definition Server.hh:53
void clear()
Definition Server.cc:66
std::string str() const
Definition Server.cc:72
CatchOutput()
Definition Server.cc:52
std::string collect
Definition Server.hh:62
void write(const std::string &txt)
Definition Server.cc:60
boost::uuids::uuid uuid
Definition Server.hh:132
Connection()
Definition Server.cc:285
websocket_server::id_type ws_id
Definition Server.hh:131
Object representing a Cadabra server, capable of receiving messages on a websocket,...
Definition Server.hh:31
void on_message(websocket_server::id_type id, const std::string &msg, const websocket_server::request_type &req, const std::string &ip_address)
Definition Server.cc:448
void send_progress_update(const std::string &msg, int n, int total)
Definition Server.cc:620
void init()
Definition Server.cc:135
CatchOutput catchErr
Definition Server.hh:65
virtual void on_block_error(Block)
Definition Server.cc:650
virtual void on_block_finished(Block)
Called by the run_block() thread upon completion of the task.
Definition Server.cc:543
pybind11::object main_namespace
Definition Server.hh:205
std::thread runner
Definition Server.hh:147
std::string authentication_token
Definition Server.hh:139
pybind11::module main_module
Definition Server.hh:204
virtual void on_kernel_fault(Block)
Definition Server.cc:679
ConnectionMap connections
Definition Server.hh:135
std::future< std::string > job
Definition Server.hh:194
void on_open(websocket_server::id_type id)
Definition Server.cc:290
virtual ~Server()
Definition Server.cc:47
Stopwatch sympy_stopwatch
Definition Server.hh:68
std::mutex ws_mutex
Definition Server.hh:143
CatchOutput catchOut
Definition Server.hh:65
virtual uint64_t send(const std::string &output, const std::string &msg_type, uint64_t parent_id=0, uint64_t cell_id=0, bool last_in_sequence=false)
Raw code to send a string (which must be JSON formatted) as a message to the client.
Definition Server.cc:579
unsigned long main_thread_id
Definition Server.hh:152
websocket_server wserver
Definition Server.hh:119
std::map< websocket_server::id_type, Connection > ConnectionMap
Definition Server.hh:134
void wait_for_job()
Thread entry point for the code that waits for blocks to appear on the block queue,...
Definition Server.cc:339
bool handles(const std::string &otype) const
Definition Server.cc:573
int run_on_port
Definition Server.hh:151
void dispatch_message(websocket_server::id_type, const std::string &json_string)
Takes a JSON encoded message and performs the required action to process it.
Definition Server.cc:466
void run(int port=0, bool exit_on_disconnect=true)
The only user-visible part: just instantiate a server object and start it with run().
Definition Server.cc:708
Server(const Server &)=delete
std::string architecture() const
Definition Server.cc:77
std::mutex block_available_mutex
Definition Server.hh:148
pybind11::scoped_interpreter guard
Definition Server.hh:203
std::string run_string(const std::string &, bool handle_output=true)
Definition Server.cc:212
std::queue< Block > block_queue
Definition Server.hh:169
void on_close(websocket_server::id_type id)
Definition Server.cc:299
Server()
Definition Server.cc:32
bool exit_on_disconnect
Definition Server.hh:150
std::condition_variable block_available
Definition Server.hh:149
void stop_block()
Halt the currently running block and prevent execution of any further blocks that may still be on the...
Definition Server.cc:422
void send_json(const std::string &)
Definition Server.cc:643
websocket_server::id_type current_ws_id
Definition Server.hh:170
Stopwatch server_stopwatch
Definition Server.hh:67
void wait_for_websocket()
Thread entry point for code that sets up and runs the websocket listener.
Definition Server.cc:318
uint64_t current_id
Definition Server.hh:171
bool started
Definition Server.hh:193
The Stopwach class provides a simple interace to allow timing function calls etc.....
Definition Stopwatch.hh:107
Definition websocket_server.hh:16
boost::beast::http::request< boost::beast::http::string_body > request_type
Definition websocket_server.hh:19
std::size_t id_type
Definition websocket_server.hh:18