Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ( Snoop s)
SnoopImpl::~SnoopImpl ( )

Member Function Documentation

void SnoopImpl::create_tables ( )

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

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.

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.

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.

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.

void SnoopImpl::on_client_close ( websocketpp::connection_hdl  hdl)
void SnoopImpl::on_client_fail ( websocketpp::connection_hdl  hdl)
void SnoopImpl::on_client_message ( websocketpp::connection_hdl  hdl,
message_ptr  msg 
)
void SnoopImpl::on_client_open ( websocketpp::connection_hdl  hdl)
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.

Snoop & SnoopImpl::operator<< ( const Flush )
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).

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

Store an app entry in the database.

Will update the 'id' field in the AppEntry.

bool SnoopImpl::store_app_entry_without_lock ( Snoop::AppEntry app)
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).

void SnoopImpl::sync_logs_with_server ( bool  from_wsthread = false)

As above, but only for log entries.

void SnoopImpl::sync_runs_with_server ( bool  from_wsthread = false)

As above, but only for run entries.

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

std::mutex snoop::SnoopImpl::call_mutex
private
WebsocketClient::connection_ptr snoop::SnoopImpl::connection
bool snoop::SnoopImpl::connection_attempt_failed
std::condition_variable snoop::SnoopImpl::connection_cv
bool snoop::SnoopImpl::connection_is_open
std::mutex snoop::SnoopImpl::connection_mutex
sqlite3* snoop::SnoopImpl::db
sqlite3_stmt * snoop::SnoopImpl::id_for_uuid_statement
sqlite3_stmt* snoop::SnoopImpl::insert_statement

Prepared statements (only need to prepare these once).

websocketpp::connection_hdl snoop::SnoopImpl::our_connection_hdl
std::string snoop::SnoopImpl::server_
Snoop* snoop::SnoopImpl::snoop_
std::mutex snoop::SnoopImpl::sqlite_mutex
Snoop::AppEntry snoop::SnoopImpl::this_app_
Snoop::LogEntry snoop::SnoopImpl::this_log_
WebsocketClient snoop::SnoopImpl::wsclient

Websocket client to talk to a remote logging server.

std::thread snoop::SnoopImpl::wsclient_thread

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