27 int VisAOApp_standalone::CONFIG_LOADER_LOG_LEVEL = Logger::LOG_LEV_INFO;
28 int VisAOApp_standalone::DEFAULT_LOG_LEVEL = Logger::LOG_LEV_INFO;
30 Logger* VisAOApp_standalone::_logger = NULL;
32 Config_File* VisAOApp_standalone::_cfg = NULL;
34 std::string VisAOApp_standalone::_configFile;
35 std::string VisAOApp_standalone::_logFile;
36 std::string VisAOApp_standalone::_myName;
37 int VisAOApp_standalone::_ID;
38 std::string VisAOApp_standalone::_myFullName;
53 CreateVisAOApp_standalone(Logger::LOG_LEV_INFO);
68 CreateVisAOApp_standalone(logLevel);
71 void VisAOApp_standalone::set_conffile( std::string name)
throw (AOException)
73 std::string conffile = getConffile(name);
75 set_conffile(name, conffile);
80 set_conffile(name, conffile);
83 void VisAOApp_standalone::set_conffile(std::string name,
const std::string& conffile)
throw (AOException)
86 set_app_name(_myName);
97 std::cerr <<
"=====> " << conffile <<
"\n";
98 SetConfigFile(conffile);
100 catch(Config_File_Exception &e)
103 throw AOException(
"config File Exception in AOApp c'tor");
114 logLevel = Logger::stringToLevel((*_cfg)[
"LogLevel"]);
117 catch(Config_File_Exception& e)
120 logLevel=Logger::LOG_LEV_INFO;
124 CreateVisAOApp_standalone(logLevel);
132 std::string conffile =
"";
133 int log_modifier = 0;
136 while ((c = getopt (argc, argv,
"i:f:hvq")) != -1)
172 conffile = getConffile(_myName);
175 SetConfigFile(conffile);
177 set_app_name(_myName);
179 catch(Config_File_Exception &e)
182 throw AOException(
"config File Exception in VisAOApp constructor");
186 int llevel=Logger::LOG_LEV_INFO;
187 if(log_modifier > 0) llevel=Logger::LOG_LEV_INFO + log_modifier;
191 CreateVisAOApp_standalone(llevel);
194 VisAOApp_standalone::~VisAOApp_standalone()
196 Logger::get()->log(Logger::LOG_LEV_FATAL,
"VisAOApp terminated.");
197 std::cerr <<
app_name <<
": VisAOApp terminated." << std::endl;
204 std::cerr <<
"Conf. file: " << Utils::getConffile(identity) << std::endl;
206 return Utils::getConffile(identity);
209 void VisAOApp_standalone::usage()
213 cout << endl <<
"VisAOApp: " << _myName <<
" " << vId << endl << endl;
214 cout << endl <<
"Standard options:" << endl << endl;
215 cout <<
" -i <identity>: identity, used for config lookup etc." << endl;
216 cout <<
" -f <file> : configuration file (if not specified, takes the identity as prefix)" << endl;
217 cout <<
" -v : increase verbosity over default level (can appear multiple times)" << endl;
218 cout <<
" -q : decrease verbosity from default level (can appear multiple times)" << endl;
219 cout <<
" -h : prints this message and exits" << endl;
224 void VisAOApp_standalone::CreateVisAOApp_standalone(
int logLevel)
throw (AOException)
229 _myFullName = _myName +
"." + Utils::getAdoptSide();
231 Logger::setParentName(_myFullName);
234 _logFile = _myFullName;
241 setLogFile(_logFile);
245 _logger->setGlobalLevel(logLevel);
252 set_RT_priority((
int)(*_cfg)[
"RT_priority"]);
259 catch(Config_File_Exception& e)
270 set_wait_to((
double)(*_cfg)[
"wait_to"]);
273 catch(Config_File_Exception& e)
283 pathtmp = (std::string)(*_cfg)[
"com_path"];
285 else pathtmp =
"fifos";
287 catch(Config_File_Exception)
291 com_path = std::string(getenv(
"VISAO_ROOT")) +
"/" + pathtmp +
"/" + _myName;
298 std::string dfc = (std::string)(*_cfg)[
"default_control_mode"];
299 if(dfc[0] ==
'N') default_control_mode = CMODE_NONE;
300 else if(dfc[0] ==
'R') default_control_mode = CMODE_REMOTE;
301 else if(dfc[0] ==
'L') default_control_mode = CMODE_LOCAL;
302 else if(dfc[0] ==
'S') default_control_mode = CMODE_SCRIPT;
303 else if(dfc[0] ==
'A') default_control_mode = CMODE_AUTO;
306 Logger::get()->log(Logger::LOG_LEV_ERROR,
"Uknown control mode in config default_control_mode");
310 if(default_control_mode > -1) request_control(default_control_mode,1);
312 catch(Config_File_Exception)
322 pathtmp = (std::string)(*_cfg)[
"profile_path"];
324 else pathtmp =
"profile";
326 catch(Config_File_Exception)
330 profile_path = std::string(getenv(
"VISAO_ROOT")) +
"/" + pathtmp +
"/" + MyFullName();
332 profile->set_base_path(profile_path);
340 use_profiler = (
int)(*_cfg)[
"use_profiler"];
342 else use_profiler = 0;
344 catch(Config_File_Exception)
348 if(use_profiler != 0) use_profiler = 1;
355 pause_time = (double)(*_cfg)[
"pause_time"];
357 else pause_time = 1.0;
359 catch(Config_File_Exception)
370 init_file = (std::string)(*_cfg)[
"init_path"];
372 else init_file =
"init";
374 catch(Config_File_Exception)
379 init_file = init_file +
"/"+ _myName+
".init";
383 init_vars =
new Config_File(init_file);
385 catch(Config_File_Exception)
391 pthread_cond_init(&signal_cond, NULL);
392 pthread_mutex_init(&signal_mutex, NULL);
399 data_save_path = (std::string)(*_cfg)[
"data_save_path"];
401 catch(Config_File_Exception)
403 data_save_path =
"data/syslogs";
408 data_log_time_length = (double)(*_cfg)[
"data_log_time_length"];
410 catch(Config_File_Exception)
412 data_log_time_length = 120.;
417 data_file_prefix = (std::string)(*_cfg)[
"data_file_prefix"];
419 catch(Config_File_Exception)
421 data_file_prefix = _myFullName;
426 data_save_path =
"data/syslogs";
427 data_log_time_length = 120.;
428 data_file_prefix = _myFullName;
434 signalth_sleeptime = 1000.;
441 signalth_sleeptime = (double)(*_cfg)[
"signalth_sleeptime"];
445 signalth_sleeptime = 1000.;
448 catch(Config_File_Exception)
450 signalth_sleeptime = 1000.;
458 void VisAOApp_standalone::setLogFile(
string fileName)
460 _logger->rename( fileName);
463 void VisAOApp_standalone::initTempLog()
465 Logger::enableFileLog();
471 _logger = Logger::get();
472 setLogFile(Utils::uniqueFileName(
"aoapp_"));
475 void VisAOApp_standalone::SetConfigFile(
const std::string& conffile)
throw (Config_File_Exception)
478 Config_File::setLogLevel(CONFIG_LOADER_LOG_LEVEL);
480 _configFile = conffile;
485 _cfg =
new Config_File(_configFile);
488 catch (Config_File_Exception &e)
490 Logger::get()->log(Logger::LOG_LEV_ERROR, e.what().c_str());
498 Logger::get()->log(LogLevel, lmsg);
504 struct sigaction act;
507 act.sa_sigaction = &sigterm_handler;
508 act.sa_flags = SA_SIGINFO;
512 sigaction(SIGTERM, &act, 0);
513 sigaction(SIGQUIT, &act, 0);
514 sigaction(SIGINT, &act, 0);
522 logss <<
"Run() not yet reimplemented. No main loop to execute.";
536 logss <<
"fifo_list connected.";
542 error_report(Logger::LOG_LEV_FATAL,
"Error connecting the fifo list.");
564 usleep((
int) signalth_sleeptime);
585 struct sched_param schedpar;
588 pthread_attr_init(&attr);
594 schedpar.sched_priority = 0;
596 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
597 pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
598 pthread_attr_setschedparam(&attr, &schedpar);
603 pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
614 struct sigaction act;
619 act.sa_sigaction = &sig_mainthread_catcher;
620 act.sa_flags = SA_SIGINFO;
624 return sigaction(SIG_MAINTHREAD, &act, 0);
633 sigaddset(&set, signum);
636 if(pthread_sigmask(SIG_BLOCK, &set, 0) == 0)
return 0;
639 perror(
"block_signal");
672 void sig_mainthread_catcher(
int signum __attribute__((unused)), siginfo_t *siginf __attribute__((unused)),
void *ucont __attribute__((unused)))
678 void sigterm_handler(
int signum, siginfo_t *siginf __attribute__((unused)),
void *ucont __attribute__((unused)))
698 Logger::get()->log(Logger::LOG_LEV_FATAL,
"Caught signal %s. TimeToDie is set.", signame.c_str());
699 std::cerr <<
"Caught signal " << signame <<
" TimeToDie is set." << std::endl;
709 Logger::get()->log(Logger::LOG_LEV_ERROR,
"%s. File: %s Line: %i", er, file, lno);
710 std::cerr << er <<
" File: " << file <<
" Line: " << lno << std::endl;
717 Logger::get()->log(Logger::LOG_LEV_INFO,
"%s", li);
718 std::cout << li <<
"\n";
#define set_global_log_info(li)
Macro for declaring and setting the info logging global.
VisAOApp_standalone()
Default constructor.
void log_msg(int LogLevel, std::string lmsg)
Report an error. Also calls log_msg. Overloaded from VisAOApp_base.
virtual int Run()
The application main loop, to be re-implemented in derived classes.
fifo_list * global_fifo_list
The global fifo_list, for signal handling.
double get_curr_time(void)
Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
void error_report(const char *er, const char *file, int lno)
Error reporting function for global_error_report.
virtual int start_signal_catcher(bool inherit_sched=true)
Starts the signal catching loop.
The standalone VisAO application, does not interface with the AO Supervisor.
std::ostringstream logss
Conveninence string stream for building log messages.
virtual void error_report(int LogLevel, std::string emsg)
Report an error. Also calls log_msg.
void signal_catcher()
Signal loop, normally won't need to be overridden.
Declarations for the standalone VisAO application.
virtual int update_statusboard()
Update the status board.
int check_fifo_list_RTpending()
Check for pending reads for the fifo list while using the RT signals.
std::string app_name
The name of the application.
void * __start_signal_catcher(void *ptr)
Thread starter for the signal catcher.
pthread_cond_t signal_cond
Condition for telling main thread that something changed.
virtual int block_signal(int signum)
Sets the signal mask to block signal signum.
pthread_t signal_thread
Identifier for the separate signal handling thread.
virtual int block_sigio()
Sets the signal mask to block SIGIO and RTSIGIO.
int TimeToDie
Global set by SIGTERM.
static string getConffile(string identity)
Return configuration file path based on identity.
fifo_list fl
The list of named-pipe fifos used for inter-process comms.
The base class for VisAO applications.
double pause_time
Time to pause during application main loop.
int connect_fifo_list()
Connect the fifo_list with exclusive locking.
int setup_RTsigio()
Setup SIGIO signal handling using realtime signals.
virtual int install_sig_mainthread_catcher()
Install the SIG_MAINTHREAD signal catcher.
virtual int Exec()
Installs the term and XXXX signal handlers, and calls Run().
The namespace of VisAO software.
pthread_t main_thread
Identifier for the main thread.
virtual int kill_me()
Handle a timetodie condition upon exiting the signal catcher thread (e.g. tell main thread it is abou...
#define set_global_error_report(er)
Macro for declaring and setting the error reporting global.
void log_info(const char *li)
Info logging function for global_log_info.