Cadabra
Computer algebra system for field theory problems
|
Object representing a Cadabra server, capable of receiving messages on a websocket, running Python code, and sending output back to the client.
Contains the logic to intercept raw Python output but also provides functionality to the Python side which enables clients to send various objects in JSON encoded form. See Server::on_block_finished for the format of these messages.
Every block is run on the same Python scope. They run sequentially, one at a time, on a thread separate from the websocket++ main loop. When the Python code finishes (or when it is interrupted), this thread locks the socket_mutex and calls on_block_finished().
#include <Server.hh>
Classes | |
class | Block |
class | CatchOutput |
Python output catching. More... | |
class | Connection |
Public Member Functions | |
Server () | |
Server (const Server &)=delete | |
Server (const std::string &socket) | |
~Server () | |
void | run () |
The only user-visible part: just instantiate a server object and start it with run(). More... | |
Public Member Functions inherited from ProgressMonitor | |
ProgressMonitor () | |
virtual | ~ProgressMonitor () |
virtual void | group (std::string name="") |
virtual void | progress (int n, int total) |
void | print () const |
std::vector< Total > | totals () const |
Public Attributes | |
CatchOutput | catchOut |
CatchOutput | catchErr |
Stopwatch | server_stopwatch |
Stopwatch | sympy_stopwatch |
Private Types | |
typedef websocketpp::server < websocketpp::config::asio > | WebsocketServer |
typedef std::map < websocketpp::connection_hdl, Connection, std::owner_less < websocketpp::connection_hdl > > | ConnectionMap |
Private Member Functions | |
void | init () |
void | on_socket_init (websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket &s) |
void | on_message (websocketpp::connection_hdl hdl, WebsocketServer::message_ptr msg) |
void | on_open (websocketpp::connection_hdl hdl) |
void | on_close (websocketpp::connection_hdl hdl) |
void | wait_for_job () |
std::string | run_string (const std::string &, bool handle_output=true) |
void | on_block_finished (Block) |
Called by the run_block() thread upon completion of the task. More... | |
void | on_block_error (Block) |
void | on_kernel_fault (Block) |
std::string | architecture () const |
bool | handles (const std::string &otype) const |
uint64_t | send (const std::string &output, const std::string &msg_type, uint64_t parent_id=0, bool last_in_sequence=false) |
Raw code to send a string (which must be JSON formatted) as a message to the client. More... | |
void | send_json (const std::string &) |
void | stop_block () |
Halt the currently running block and prevent execution of any further blocks that may still be on the queue. More... | |
void | dispatch_message (websocketpp::connection_hdl, const std::string &json_string) |
Takes a JSON encoded message and performs the required action to process it. More... | |
Private Attributes | |
WebsocketServer | wserver |
std::string | socket_name |
ConnectionMap | connections |
std::mutex | ws_mutex |
std::thread | runner |
std::mutex | block_available_mutex |
std::condition_variable | block_available |
std::queue< Block > | block_queue |
websocketpp::connection_hdl | current_hdl |
uint64_t | current_id |
uint64_t | return_cell_id |
bool | started |
std::future< std::string > | job |
boost::python::object | main_module |
boost::python::object | main_namespace |
int | cells_ran |
|
private |
|
private |
Server::Server | ( | ) |
|
delete |
Server::Server | ( | const std::string & | socket | ) |
Server::~Server | ( | ) |
|
private |
|
private |
Takes a JSON encoded message and performs the required action to process it.
Where applicable these messages are compatible with IPython's message types, http://ipython.org/ipython-doc/dev/development/messaging.html
|
private |
|
private |
|
private |
|
private |
Called by the run_block() thread upon completion of the task.
This will send any output generated by printing directly to stdout or stderr from Python (so, output not generated by using the 'display' function). Indicates to the client that this block has finished executing. Will send an empty string if there has been no output 'print'ed.
|
private |
|
private |
|
private |
|
private |
|
private |
void Server::run | ( | ) |
The only user-visible part: just instantiate a server object and start it with run().
This will not return until the server has been shut down.
|
private |
|
private |
Raw code to send a string (which must be JSON formatted) as a message to the client.
Handles communication of the result back to the client in JSON format. This is always of the form
{ "header": { "parent_id": "...", "parent_origin": "client" | "server", "cell_id": "...", "cell_origin": "client" | "server"
}, "content": { "output": "..." }, "msg_type": "..." } msg_type can be "output", "latex", "image_png" and so on, corresponding to the possible values of DataCell::CellType.
Returns the serial number of the new cell sent.
|
private |
|
private |
Halt the currently running block and prevent execution of any further blocks that may still be on the queue.
|
private |
|
private |
|
private |
|
private |
CatchOutput Server::catchErr |
CatchOutput Server::catchOut |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Stopwatch Server::server_stopwatch |
|
private |
|
private |
Stopwatch Server::sympy_stopwatch |
|
private |
|
private |