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

#include <SnoopPrivate.hh>

Public Member Functions

 SnoopImpl (Snoop *)
 
 ~SnoopImpl ()
 
Snoopoperator<< (const Flush &)
 
void init (const std::string &app_name, const std::string &app_version, std::string server="", std::string local_log_file="")
 Initialise the logging stream. More...
 
std::string get_user_uuid (const std::string &app_name)
 Get a string which uniquely identifies the current user. More...
 
Snoopoperator() (const std::string &type, std::string fl="", int loc=-1, std::string method="")
 Operator to initialise a logging entry with the type of the log message as well as (optionally) the file, line number and method. More...
 
void sync_with_server (bool from_wsthread=false)
 Ensure that the local database is synchronised with the server (this sends multiple app or log entries in one websocket message). More...
 
void sync_runs_with_server (bool from_wsthread=false)
 As above, but only for run entries. More...
 
void sync_logs_with_server (bool from_wsthread=false)
 As above, but only for log entries. More...
 
void start_websocket_client ()
 Start the websocket client. More...
 
void create_tables ()
 Ensure that the required tables are present in the database file. More...
 
void obtain_uuid ()
 Obtain a uuid by finding the last AppEntry stored in the local database. More...
 
bool store_app_entry (Snoop::AppEntry &)
 Store an app entry in the database. More...
 
bool store_app_entry_without_lock (Snoop::AppEntry &)
 
bool store_log_entry (Snoop::LogEntry &, bool avoid_server_duplicates)
 Store a log entry in the local database. More...
 
std::vector< Snoop::AppEntryget_app_registrations (std::string uuid_filter="")
 Return a vector of all aps registered in the database. More...
 
void on_client_open (websocketpp::connection_hdl hdl)
 
void on_client_fail (websocketpp::connection_hdl hdl)
 
void on_client_close (websocketpp::connection_hdl hdl)
 
void on_client_message (websocketpp::connection_hdl hdl, message_ptr msg)
 

Public Attributes

Snoopsnoop_
 
sqlite3 * db
 
Snoop::AppEntry this_app_
 
Snoop::LogEntry this_log_
 
std::string server_
 
sqlite3_stmt * insert_statement
 Prepared statements (only need to prepare these once). More...
 
sqlite3_stmt * id_for_uuid_statement
 
std::mutex sqlite_mutex
 
WebsocketClient wsclient
 Websocket client to talk to a remote logging server. More...
 
std::thread wsclient_thread
 
std::mutex connection_mutex
 
std::condition_variable connection_cv
 
bool connection_is_open
 
bool connection_attempt_failed
 
WebsocketClient::connection_ptr connection
 
websocketpp::connection_hdl our_connection_hdl
 

Private Attributes

std::mutex call_mutex
 

Constructor & Destructor Documentation

◆ SnoopImpl()

SnoopImpl::SnoopImpl ( Snoop s)

◆ ~SnoopImpl()

SnoopImpl::~SnoopImpl ( )

Member Function Documentation

◆ create_tables()

void SnoopImpl::create_tables ( )

Ensure that the required tables are present in the database file.

◆ get_app_registrations()

std::vector< Snoop::AppEntry > SnoopImpl::get_app_registrations ( std::string  uuid_filter = "")

Return a vector of all aps registered in the database.

If the uuid filter is non-empty, will filter on the given uuid.

◆ get_user_uuid()

std::string SnoopImpl::get_user_uuid ( const std::string &  app_name)

Get a string which uniquely identifies the current user.

This is stored in ~/.config/snoop/appname.conf.

◆ init()

void SnoopImpl::init ( const std::string &  app_name,
const std::string &  app_version,
std::string  server = "",
std::string  local_log_file = "" 
)

Initialise the logging stream.

Should be called once at program startup, but can be called multiple times without causing problems.

◆ obtain_uuid()

void SnoopImpl::obtain_uuid ( )

Obtain a uuid by finding the last AppEntry stored in the local database.

Will attempt to re-turn a previously generated uuid but will do so only if one is stored for the current pid; if no entry with the current pid is stored then a new one will always be generated.

◆ on_client_close()

void SnoopImpl::on_client_close ( websocketpp::connection_hdl  hdl)

◆ on_client_fail()

void SnoopImpl::on_client_fail ( websocketpp::connection_hdl  hdl)

◆ on_client_message()

void SnoopImpl::on_client_message ( websocketpp::connection_hdl  hdl,
message_ptr  msg 
)

◆ on_client_open()

void SnoopImpl::on_client_open ( websocketpp::connection_hdl  hdl)

◆ operator()()

Snoop & SnoopImpl::operator() ( const std::string &  type,
std::string  fl = "",
int  loc = -1,
std::string  method = "" 
)

Operator to initialise a logging entry with the type of the log message as well as (optionally) the file, line number and method.

Thread-safe: can be called from different threads at the same time.

◆ operator<<()

Snoop & SnoopImpl::operator<< ( const Flush )

◆ start_websocket_client()

void SnoopImpl::start_websocket_client ( )

Start the websocket client.

This tries to connect to the server and then waits in a separate thread until the server sends us something (typically in response to something the main thread makes by calling wsclient.send).

◆ store_app_entry()

bool SnoopImpl::store_app_entry ( Snoop::AppEntry app)

Store an app entry in the database.

Will update the 'id' field in the AppEntry.

◆ store_app_entry_without_lock()

bool SnoopImpl::store_app_entry_without_lock ( Snoop::AppEntry app)

◆ store_log_entry()

bool SnoopImpl::store_log_entry ( Snoop::LogEntry log_entry,
bool  avoid_server_duplicates 
)

Store a log entry in the local database.

Generates its own receive_millis field (the one given gets overwritten). Will update the 'id' field in the LogEntry. Returns 'true' if the entry was stored, or 'false' if an entry with this client_log_id was already present (except when it is 0).

◆ sync_logs_with_server()

void SnoopImpl::sync_logs_with_server ( bool  from_wsthread = false)

As above, but only for log entries.

◆ sync_runs_with_server()

void SnoopImpl::sync_runs_with_server ( bool  from_wsthread = false)

As above, but only for run entries.

◆ sync_with_server()

void SnoopImpl::sync_with_server ( bool  from_wsthread = false)

Ensure that the local database is synchronised with the server (this sends multiple app or log entries in one websocket message).

Leave the bool argument at its default argument under all normal circumstances.

Member Data Documentation

◆ call_mutex

std::mutex snoop::SnoopImpl::call_mutex
private

◆ connection

WebsocketClient::connection_ptr snoop::SnoopImpl::connection

◆ connection_attempt_failed

bool snoop::SnoopImpl::connection_attempt_failed

◆ connection_cv

std::condition_variable snoop::SnoopImpl::connection_cv

◆ connection_is_open

bool snoop::SnoopImpl::connection_is_open

◆ connection_mutex

std::mutex snoop::SnoopImpl::connection_mutex

◆ db

sqlite3* snoop::SnoopImpl::db

◆ id_for_uuid_statement

sqlite3_stmt * snoop::SnoopImpl::id_for_uuid_statement

◆ insert_statement

sqlite3_stmt* snoop::SnoopImpl::insert_statement

Prepared statements (only need to prepare these once).

◆ our_connection_hdl

websocketpp::connection_hdl snoop::SnoopImpl::our_connection_hdl

◆ server_

std::string snoop::SnoopImpl::server_

◆ snoop_

Snoop* snoop::SnoopImpl::snoop_

◆ sqlite_mutex

std::mutex snoop::SnoopImpl::sqlite_mutex

◆ this_app_

Snoop::AppEntry snoop::SnoopImpl::this_app_

◆ this_log_

Snoop::LogEntry snoop::SnoopImpl::this_log_

◆ wsclient

WebsocketClient snoop::SnoopImpl::wsclient

Websocket client to talk to a remote logging server.

◆ wsclient_thread

std::thread snoop::SnoopImpl::wsclient_thread

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