Cadabra
Computer algebra system for field theory problems
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cadabra::ComputeThread Class Reference

Description

Base class which talks to the server and sends Action objects back to the DocumentThread.

ComputeThread is the base class which takes care of doing actual computations with the cells in a document. It handles talking to the server backend. It knows how to pass cells to the server and ask them to be executed. Results are reported back to the GUI by putting ActionBase objects onto its todo stack. ComputeThread never directly modifies the document tree.

#include <ComputeThread.hh>

Public Member Functions

 ComputeThread (int server_port=0, std::string token="", std::string ip_address="127.0.0.1")
 If the ComputeThread is constructed with a null pointer to the gui, there will be no gui updates, just DTree updates. More...
 
 ComputeThread (const ComputeThread &)=delete
 
 ~ComputeThread ()
 
void set_master (GUIBase *, DocumentThread *)
 Determine the objects that this compute thread should be talking to. More...
 
void run ()
 Main entry point, which will connect to the server and then start an event loop to handle communication with the server. More...
 
void execute_cell (DTree::iterator)
 In order to execute code on the server, call the following from the GUI thread. More...
 
void execute_interactive (uint64_t id, const std::string &code)
 
void stop ()
 Stop the current cell execution on the server and remove all other cells from the run queue as well. More...
 
void restart_kernel ()
 Restart the kernel. More...
 
bool complete (DTree::iterator, int pos, int alternative)
 Request completion of a string. More...
 
int number_of_cells_executing (void) const
 
void terminate ()
 Terminate the compute thread, in preparation for shutting down the client altogether. More...
 
bool kernel_is_connected () const
 Return the status of the connection to the kernel. More...
 

Private Member Functions

void init ()
 
void try_connect ()
 
void try_spawn_server ()
 
void on_open (websocketpp::connection_hdl hdl)
 
void on_fail (websocketpp::connection_hdl hdl)
 
void on_close (websocketpp::connection_hdl hdl)
 
void on_message (websocketpp::connection_hdl hdl, message_ptr msg)
 
void cell_finished_running (DataCell::id_t)
 
void all_cells_nonrunning ()
 Set all cells to be non-running (e.g. More...
 

Private Attributes

GUIBasegui
 
DocumentThreaddocthread
 
std::thread::id gui_thread_id
 
std::map< DataCell::id_t, DTree::iterator > running_cells
 
WSClient wsclient
 
bool connection_is_open
 
bool restarting_kernel
 
WSClient::connection_ptr connection
 
websocketpp::connection_hdl our_connection_hdl
 
std::set< uint64_t > interactive_cells
 
Glib::Pid server_pid
 
int server_stdout
 
int server_stderr
 
unsigned short port
 
std::string authentication_token
 
int forced_server_port
 
std::string forced_server_token
 
std::string forced_server_ip_address
 

Constructor & Destructor Documentation

◆ ComputeThread() [1/2]

ComputeThread::ComputeThread ( int  server_port = 0,
std::string  token = "",
std::string  ip_address = "127.0.0.1" 
)

If the ComputeThread is constructed with a null pointer to the gui, there will be no gui updates, just DTree updates.

◆ ComputeThread() [2/2]

cadabra::ComputeThread::ComputeThread ( const ComputeThread )
delete

◆ ~ComputeThread()

ComputeThread::~ComputeThread ( )

Member Function Documentation

◆ all_cells_nonrunning()

void ComputeThread::all_cells_nonrunning ( )
private

Set all cells to be non-running (e.g.

after a kernel failure) and report the status of each cell to the GUI.

◆ cell_finished_running()

void ComputeThread::cell_finished_running ( DataCell::id_t  id)
private

◆ complete()

bool ComputeThread::complete ( DTree::iterator  it,
int  pos,
int  alternative 
)

Request completion of a string.

Returns false if the current cell cannot be completed, in which case the TAB which led to the request should be interpreted literally and used for spacing. The alternative argument is the serial number of the requested completion, in case there is more than one possible completion.

◆ execute_cell()

void ComputeThread::execute_cell ( DTree::iterator  it)

In order to execute code on the server, call the following from the GUI thread.

This method returns as soon as the request has been put on the network queue. If no communication with the server is necessary, this returns immediately. The ComputeThread will report the result of the computation/processing by adding actions to the DocumentThread owned pending_actions stack, by calling queue_action. It will never modify the cell directly, and will also never modify any other cells in the document tree.

◆ execute_interactive()

void ComputeThread::execute_interactive ( uint64_t  id,
const std::string &  code 
)

◆ init()

void ComputeThread::init ( )
private

◆ kernel_is_connected()

bool ComputeThread::kernel_is_connected ( ) const

Return the status of the connection to the kernel.

◆ number_of_cells_executing()

int ComputeThread::number_of_cells_executing ( void  ) const

◆ on_close()

void ComputeThread::on_close ( websocketpp::connection_hdl  hdl)
private

◆ on_fail()

void ComputeThread::on_fail ( websocketpp::connection_hdl  hdl)
private

◆ on_message()

void ComputeThread::on_message ( websocketpp::connection_hdl  hdl,
message_ptr  msg 
)
private

◆ on_open()

void ComputeThread::on_open ( websocketpp::connection_hdl  hdl)
private

◆ restart_kernel()

void ComputeThread::restart_kernel ( )

Restart the kernel.

◆ run()

void ComputeThread::run ( )

Main entry point, which will connect to the server and then start an event loop to handle communication with the server.

Only terminates when the connection drops, so run your GUI on a different thread.

◆ set_master()

void ComputeThread::set_master ( GUIBase b,
DocumentThread d 
)

Determine the objects that this compute thread should be talking to.

◆ stop()

void ComputeThread::stop ( )

Stop the current cell execution on the server and remove all other cells from the run queue as well.

◆ terminate()

void ComputeThread::terminate ( )

Terminate the compute thread, in preparation for shutting down the client altogether.

◆ try_connect()

void ComputeThread::try_connect ( )
private

◆ try_spawn_server()

void ComputeThread::try_spawn_server ( )
private

Member Data Documentation

◆ authentication_token

std::string cadabra::ComputeThread::authentication_token
private

◆ connection

WSClient::connection_ptr cadabra::ComputeThread::connection
private

◆ connection_is_open

bool cadabra::ComputeThread::connection_is_open
private

◆ docthread

DocumentThread* cadabra::ComputeThread::docthread
private

◆ forced_server_ip_address

std::string cadabra::ComputeThread::forced_server_ip_address
private

◆ forced_server_port

int cadabra::ComputeThread::forced_server_port
private

◆ forced_server_token

std::string cadabra::ComputeThread::forced_server_token
private

◆ gui

GUIBase* cadabra::ComputeThread::gui
private

◆ gui_thread_id

std::thread::id cadabra::ComputeThread::gui_thread_id
private

◆ interactive_cells

std::set<uint64_t> cadabra::ComputeThread::interactive_cells
private

◆ our_connection_hdl

websocketpp::connection_hdl cadabra::ComputeThread::our_connection_hdl
private

◆ port

unsigned short cadabra::ComputeThread::port
private

◆ restarting_kernel

bool cadabra::ComputeThread::restarting_kernel
private

◆ running_cells

std::map<DataCell::id_t, DTree::iterator> cadabra::ComputeThread::running_cells
private

◆ server_pid

Glib::Pid cadabra::ComputeThread::server_pid
private

◆ server_stderr

int cadabra::ComputeThread::server_stderr
private

◆ server_stdout

int cadabra::ComputeThread::server_stdout
private

◆ wsclient

WSClient cadabra::ComputeThread::wsclient
private

The documentation for this class was generated from the following files: