2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
#include <netdb.h>
|
2019-02-18 23:11:41 +00:00
|
|
|
#include <iostream>
|
2015-06-01 15:28:29 +00:00
|
|
|
#include "trick/VariableServer.hh"
|
|
|
|
#include "trick/tc_proto.h"
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
Trick::VariableServer * the_vs ;
|
|
|
|
|
|
|
|
Trick::VariableServer::VariableServer() :
|
|
|
|
enabled(true) ,
|
|
|
|
info_msg(false),
|
|
|
|
log(false)
|
|
|
|
{
|
|
|
|
the_vs = this ;
|
|
|
|
pthread_mutex_init(&map_mutex, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Trick::VariableServer::~VariableServer() {
|
2023-03-20 22:53:01 +00:00
|
|
|
the_vs = NULL;
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 23:11:41 +00:00
|
|
|
std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServer& vs) {
|
2023-03-20 22:53:01 +00:00
|
|
|
std::map < pthread_t , VariableServerSessionThread * >::iterator it ;
|
2019-02-18 23:11:41 +00:00
|
|
|
|
2019-05-13 21:05:01 +00:00
|
|
|
s << "{\"variable_server_connections\":[\n";
|
2019-02-18 23:11:41 +00:00
|
|
|
int count = 0;
|
|
|
|
int n_connections = (int)vs.var_server_threads.size();
|
|
|
|
for ( it = vs.var_server_threads.begin() ; it != vs.var_server_threads.end() ; it++ ) {
|
2019-05-13 21:05:01 +00:00
|
|
|
s << "{\n";
|
2019-02-18 23:11:41 +00:00
|
|
|
s << *(*it).second;
|
|
|
|
s << "}";
|
|
|
|
if ((n_connections-count)>1) {
|
2019-03-07 16:43:40 +00:00
|
|
|
s << "," ;
|
2019-02-18 23:11:41 +00:00
|
|
|
}
|
2019-05-13 21:05:01 +00:00
|
|
|
s << "\n";
|
2019-02-18 23:11:41 +00:00
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
s << "]}" << std::endl;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
bool Trick::VariableServer::get_enabled() {
|
|
|
|
return enabled ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_enabled(bool on_off) {
|
|
|
|
enabled = on_off ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Trick::VariableServer::get_info_msg() {
|
|
|
|
return info_msg ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_var_server_info_msg_on() {
|
|
|
|
info_msg = true;
|
2023-04-18 21:27:32 +00:00
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
|
|
|
session_it.second->set_info_message(info_msg);
|
|
|
|
}
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_var_server_info_msg_off() {
|
|
|
|
info_msg = false;
|
2023-04-18 21:27:32 +00:00
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
|
|
|
session_it.second->set_info_message(info_msg);
|
|
|
|
}
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Trick::VariableServer::get_log() {
|
|
|
|
return log ;
|
|
|
|
}
|
|
|
|
|
2023-04-28 20:42:42 +00:00
|
|
|
bool Trick::VariableServer::get_session_log() {
|
|
|
|
return session_log ;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
void Trick::VariableServer::set_var_server_log_on() {
|
|
|
|
log = true;
|
|
|
|
// turn log on for all current vs clients
|
2023-03-20 22:53:01 +00:00
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
2023-04-28 20:42:42 +00:00
|
|
|
session_it.second->set_log(true);
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_var_server_log_off() {
|
|
|
|
log = false;
|
|
|
|
// turn log off for all current vs clients
|
2023-03-20 22:53:01 +00:00
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
2023-04-28 20:42:42 +00:00
|
|
|
session_it.second->set_log(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_var_server_session_log_on() {
|
|
|
|
session_log = true;
|
|
|
|
// turn log on for all current vs clients
|
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
|
|
|
session_it.second->set_session_log(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trick::VariableServer::set_var_server_session_log_off() {
|
|
|
|
session_log = false;
|
|
|
|
// turn log off for all current vs clients
|
|
|
|
for ( auto& session_it : var_server_sessions ) {
|
|
|
|
session_it.second->set_session_log(false);
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * Trick::VariableServer::get_hostname() {
|
2023-03-20 22:53:01 +00:00
|
|
|
return listen_thread.get_hostname();
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Trick::VariableServerListenThread & Trick::VariableServer::get_listen_thread() {
|
|
|
|
return listen_thread ;
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:53:01 +00:00
|
|
|
void Trick::VariableServer::add_vst(pthread_t in_thread_id, VariableServerSessionThread * in_vst) {
|
2015-02-26 15:02:31 +00:00
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
|
|
|
var_server_threads[in_thread_id] = in_vst ;
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:47:56 +00:00
|
|
|
void Trick::VariableServer::add_session(pthread_t in_thread_id, VariableServerSession * in_session) {
|
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
|
|
|
var_server_sessions[in_thread_id] = in_session ;
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:53:01 +00:00
|
|
|
Trick::VariableServerSessionThread * Trick::VariableServer::get_vst(pthread_t thread_id) {
|
|
|
|
std::map < pthread_t , Trick::VariableServerSessionThread * >::iterator it ;
|
|
|
|
Trick::VariableServerSessionThread * ret = NULL ;
|
2015-02-26 15:02:31 +00:00
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
|
|
|
it = var_server_threads.find(thread_id) ;
|
|
|
|
if ( it != var_server_threads.end() ) {
|
|
|
|
ret = (*it).second ;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
return ret ;
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:47:56 +00:00
|
|
|
Trick::VariableServerSession * Trick::VariableServer::get_session(pthread_t thread_id) {
|
|
|
|
Trick::VariableServerSession * ret = NULL ;
|
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
2023-03-20 22:53:01 +00:00
|
|
|
auto it = var_server_sessions.find(thread_id) ;
|
2022-08-23 18:47:56 +00:00
|
|
|
if ( it != var_server_sessions.end() ) {
|
|
|
|
ret = (*it).second ;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
return ret ;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
void Trick::VariableServer::delete_vst(pthread_t thread_id) {
|
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
|
|
|
var_server_threads.erase(thread_id) ;
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:47:56 +00:00
|
|
|
void Trick::VariableServer::delete_session(pthread_t thread_id) {
|
|
|
|
pthread_mutex_lock(&map_mutex) ;
|
|
|
|
var_server_sessions.erase(thread_id) ;
|
|
|
|
pthread_mutex_unlock(&map_mutex) ;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:02:31 +00:00
|
|
|
void Trick::VariableServer::set_copy_data_job( Trick::JobData * in_job ) {
|
|
|
|
copy_data_job = in_job ;
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:53:01 +00:00
|
|
|
void Trick::VariableServer::set_copy_and_write_freeze_job( Trick::JobData * in_job ) {
|
|
|
|
copy_and_write_freeze_job = in_job ;
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|