The base class for VisAO applications. More...
#include <VisAOApp_base.h>
Public Types | |
enum | control_modes { CMODE_NONE, CMODE_REMOTE, CMODE_LOCAL, CMODE_SCRIPT, CMODE_AUTO, CMODE_max } |
The control modes. | |
Public Member Functions | |
VisAOApp_base () | |
Default constructor. | |
virtual | ~VisAOApp_base () |
Virtual destructor. | |
int | set_euid_called () |
Changes the user id of the process to euid_called. | |
int | set_euid_real () |
Changes the user id fo the process to the real user id. | |
int | set_RT_priority (int prio) |
Set the real-time priority of the current process. More... | |
int | get_RT_priority () |
Get the real-time priority of the current process. | |
int | set_app_name (std::string an) |
Set the application name. | |
virtual std::string | get_app_name () |
Get the application name. | |
virtual int | setup_baseApp (bool usethreads=false) |
Install fifo channels. More... | |
virtual int | setup_baseApp (bool remfifo, bool locfifo, bool scrfifo, bool autfifo, bool usethreads=false) |
Create fifo names, then installs the fifo channels. More... | |
int | setup_fifo_list (int nfifos) |
Allocate the fifo_list. More... | |
int | connect_fifo_list () |
Connect the fifo_list with exclusive locking. More... | |
int | connect_fifo_list_nolock () |
Connect the fifo_list without exclusive locking. More... | |
int | setup_sigio () |
Setup the SIGIO signal handling. More... | |
int | setup_RTsigio () |
Setup SIGIO signal handling using realtime signals. More... | |
int | check_fifo_list_RTpending () |
Check for pending reads for the fifo list while using the RT signals. | |
int | write_fifo_channel (int ch, const char *com, int comlen, std::string *resp) |
Write data to a fifo_channel, and get a response if desired. More... | |
int | write_fifo_channel (int ch, const char *com, int comlen, std::string *resp, char *sm) |
Write data to a fifo_channel, with a sequence message attached, and get a response if desired. More... | |
int | get_fifo_channel_response (std::string *resp, int ch) |
Check, and wait if neccessary, for data on a fifo channel. More... | |
int | set_wait_to (double to) |
Set the wait timeout for fifo channel responses. More... | |
double | get_wait_to () |
Get the wait timeout for fifo channel responses. More... | |
virtual int | request_control (int cmode) |
Calls request_control(cmode, 0). | |
virtual int | request_control (int cmode, bool override) |
Attempts to change the control type. More... | |
virtual std::string | __remote_command (std::string com, char *seqmsg) |
Processing for remote commands. More... | |
virtual std::string | remote_command (std::string com) |
Called by __remote_command after control state logic. More... | |
virtual std::string | remote_command (std::string com, char *seqmsg) |
virtual std::string | __local_command (std::string com, char *seqmsg) |
Processing for local commands. More... | |
virtual std::string | local_command (std::string com) |
Called by __local_command after control state logic. More... | |
virtual std::string | local_command (std::string com, char *seqmsg) |
virtual std::string | __script_command (std::string com, char *seqmsg) |
Processing for script commands - not normally overriden. More... | |
virtual std::string | script_command (std::string com) |
Called by __script_command after control state logic. More... | |
virtual std::string | script_command (std::string com, char *seqmsg) |
virtual std::string | auto_command (std::string com, char *seqmsg) |
Processing for auto commands - to be overriden. More... | |
virtual std::string | post_auto_command (std::string com, char *seqmsg=0) |
Processing for auto commands - not normally overriden. More... | |
std::string | control_mode_string () |
Convenience function to return the control type string, e.g. "REMOTE". | |
std::string | control_mode_response () |
Convenience function to return the control type response string, e.g. "A\n". | |
Public Attributes | |
pthread_mutex_t | my_mutex |
Mutex used by the threaded versions of the standard command handlers. | |
Protected Attributes | |
std::string | app_name |
The name of the application. | |
double | pause_time |
Time to pause during application main loop. | |
fifo_list | fl |
The list of named-pipe fifos used for inter-process comms. | |
std::string | com_path |
The control fifo path base name. | |
std::string | com_path_remote |
The path for the remote control fifos. | |
std::string | com_path_local |
The path for the local control fifos. | |
std::string | com_path_script |
The path for the script control fifos. | |
std::string | com_path_auto |
The path for the auto control fifos. | |
double | wait_to |
The timeout for waiting on responses from FIFOs in seconds. | |
Static Protected Attributes | |
static int | control_mode = VisAOApp_base::CMODE_NONE |
The current control mode. More... | |
static int | default_control_mode = -1 |
The default control mode. More... | |
Private Attributes | |
uid_t | euid_real |
The real user id of the proces. | |
uid_t | euid_called |
The user id of the process as called (that is when the constructor gets called). | |
uid_t | suid |
The save-set user id of the process. | |
int | RT_priority |
The real-time scheduling priority. Default is 0. | |
Error reporting and logging | |
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. More... | |
virtual void | log_msg (int LogLevel, std::string lmsg) |
Log a message. More... | |
profiler | |
interface to the VisAO profiler | |
VisAO::profiler * | profile |
std::string | profile_path |
int | use_profiler |
VisAO::profiler * | get_profile () |
int | get_use_profiler () |
int | start_profiler () |
statusboard facilities | |
void * | statusboard_shmemptr |
The pointer to the shared memory block for the statusboard. | |
key_t | statusboard_shmemkey |
The key used to lookup the shared memory. | |
int | statusboard_shmemid |
The ID of the shared memory block. | |
void * | get_statusboard_shmemptr () |
Get the status board shared memory pointer. More... | |
int | set_statusboard_shmemkey (key_t mkey) |
Set the status board shared memory key. Does nothing else. More... | |
key_t | get_statusboard_shmemkey () |
Get the status board shared memory key. More... | |
virtual int | update_statusboard () |
Update the status board. More... | |
int | create_statusboard (size_t sz) |
Creates and attaches to the statusboard shared memory. More... | |
Data Logging | |
Provides logging of process data at intervals, or upon a change in state. | |
std::ofstream | dataof |
bool | dataFileOpen |
double | dataFileOpenTime |
double | data_log_time_length |
std::string | data_save_path |
std::string | data_file_prefix |
virtual void | dataLogger (timeval tv) |
Log data at intervals. | |
std::string | getDataFileName () |
int | checkDataFileOpen () |
Provides the fifo management and SIGIO handling. Essentially a wrapper to the fifo utilities of the VisAO library. Does not provide config file or logger facilities. These are added by instead using VisAOApp_standalone or deriving from Arcetri::AOApp
Definition at line 48 of file VisAOApp_base.h.
Elevates the user id to uid_called.
prio | the desired priority |
0 | on success |
-1 | on failure |
Definition at line 108 of file VisAOApp_base.cpp.
References error_report(), log_msg(), logss, RT_priority, set_euid_called(), set_euid_real(), and VISAO_SCHED_POLICY.
|
virtual |
Call this after paths set, but before connect_fifo_list.
usethreads | if true the threaded versions of the handlers are installed. |
0 | on success. |
-1 | on failure. |
Definition at line 151 of file VisAOApp_base.cpp.
References VisAO::com_auto_handler(), VisAO::com_auto_thread_handler(), VisAO::com_local_handler(), VisAO::com_local_thread_handler(), com_path_auto, com_path_local, com_path_remote, com_path_script, VisAO::com_remote_handler(), VisAO::com_remote_thread_handler(), VisAO::com_script_handler(), VisAO::com_script_thread_handler(), error_report(), fl, fifo_list::nchan, RWBUFF_SZ, and set_fifo_list_channel().
Referenced by VisAO::reconstructor::Create(), VisAO::GimbalMotorCtrl::Create(), VisAO::CCD47Ctrl::init_VisAOApp(), VisAO::WollastonStatus::initApp(), VisAO::FocusMotorCtrl::initapp(), setup_baseApp(), VisAO::dioserver::setup_dioserver(), and VisAO::FilterWheelLocal::setupVisAOApp().
|
virtual |
Bools provide control over which fifo channels are used. assumes com_path is the base path of the fifos. adds _com_remote_in (for example) is added.
remfifo | if true the remote fifo is created and installed. |
locfifo | if true the local fifo is created and installed. |
scrfifo | if true the script fifo is created and installed. |
autfifo | if true the auto fifo is created and installed. |
usethreads | if true the threaded versions of the handlers are installed. |
0 | on success. |
-1 | on failure. |
Definition at line 220 of file VisAOApp_base.cpp.
References com_path, com_path_auto, com_path_local, com_path_remote, com_path_script, log_msg(), logss, and setup_baseApp().
Calls setup_fifo_list(&fl, nfifos).
nfifos | is the number of fifos we need |
0 | on success. |
-1 | o failure. |
Definition at line 256 of file VisAOApp_base.cpp.
References fl, and setup_fifo_list().
Referenced by VisAO::reconstructor::Create(), VisAO::GimbalMotorCtrl::Create(), VisAO::JoeCtrl::Create(), VisAO::CCD47Ctrl::init_VisAOApp(), VisAO::WollastonStatus::initApp(), VisAO::FocusMotorCtrl::initapp(), VisAO::dioserver::setup_dioserver(), and VisAO::FilterWheelLocal::setupVisAOApp().
int VisAO::VisAOApp_base::connect_fifo_list | ( | ) |
Calls connect_fifo_list(&fl).
0 | on success. |
-1 | on failure. |
Definition at line 261 of file VisAOApp_base.cpp.
References connect_fifo_list(), and fl.
Referenced by VisAO::JoeCtrl::Create(), VisAO::WollastonStatus::Run(), VisAO::FilterWheelLocal::signal_catcher(), and VisAO::VisAOApp_standalone::signal_catcher().
int VisAO::VisAOApp_base::connect_fifo_list_nolock | ( | ) |
Calls connect_fifo_list_nolock(&fl).
0 | on success. |
-1 | on failure. |
Definition at line 267 of file VisAOApp_base.cpp.
References connect_fifo_list_nolock(), and fl.
Referenced by VisAO::dioserver::Run().
int VisAO::VisAOApp_base::setup_sigio | ( | ) |
Uses the sigaction facilities.
0 | on success. |
-1 | on failure. |
Definition at line 272 of file VisAOApp_base.cpp.
References catch_fifo_response_list(), error_report(), log_msg(), and logss.
int VisAO::VisAOApp_base::setup_RTsigio | ( | ) |
Uses the sigaction facilities. Also installs the backup handler for standard SIGIO.
0 | on success. |
-1 | on failure. |
Definition at line 297 of file VisAOApp_base.cpp.
References catch_fifo_pending_reads(), catch_fifo_standard_sigio(), error_report(), fl, log_msg(), logss, and set_fifo_list_rtsig().
Referenced by VisAO::WollastonStatus::Run(), VisAO::dioserver::Run(), VisAO::FilterWheelLocal::signal_catcher(), and VisAO::VisAOApp_standalone::signal_catcher().
int VisAO::VisAOApp_base::write_fifo_channel | ( | int | ch, |
const char * | com, | ||
int | comlen, | ||
std::string * | resp | ||
) |
Calls write_fifo_channel(&fl.fifo_ch[ch], str, len) If the fifo_channel is timedout, this will not write to that channel again until the file is opened on the other end as detected by fstat access time.
ch | the channel to write to. |
com | the buffer to write |
comlen | the length of the buffer to write, including the '\0' character |
resp | is a string pointer to be filled in with the server_response. Set to 0 if no response is desired. |
0 | on success |
-1 | on failure |
Definition at line 362 of file VisAOApp_base.cpp.
References error_report(), fifo_list::fifo_ch, fl, get_fifo_channel_response(), logss, and wopen_nonblock().
Referenced by VisAO::FocusMotorCtrl::check_limits(), VisAO::frameselector::common_command(), VisAO::CCD47Ctrl::common_command(), VisAO::CCD47Ctrl::DoFSM(), VisAO::FocusMotorCtrl::get_power_state(), VisAO::CCD47Ctrl::GetFramegrabberStatus(), VisAO::ShutterControlDioclient::init_shutter_open(), VisAO::FocusMotorCtrl::Run(), VisAO::JoeCtrl::send_ccd47_command(), VisAO::FocusMotorCtrl::set_direction(), VisAO::FocusMotorCtrl::set_enable(), VisAO::JoeCtrl::Start(), VisAO::CCD47Ctrl::Start(), VisAO::FocusMotorCtrl::step(), VisAO::JoeCtrl::Stop(), VisAO::CCD47Ctrl::Stop(), and VisAO::JoeCtrl::TestCCD47CtrlLink().
int VisAO::VisAOApp_base::write_fifo_channel | ( | int | ch, |
const char * | com, | ||
int | comlen, | ||
std::string * | resp, | ||
char * | sm | ||
) |
Calls write_fifo_channel(&fl.fifo_ch[ch], str, len) If the fifo_channel is timedout, this will not write to that channel again until the file is opened on the other end as detected by fstat access time.
ch | the channel to write to. |
com | the buffer to write |
comlen | the length of the buffer to write |
resp | is a string pointer to be filled in with the server_response. Set to 0 if no response is desired. |
sm | is the sequence message. |
0 | on success |
-1 | on failure |
Definition at line 409 of file VisAOApp_base.cpp.
References error_report(), fifo_list::fifo_ch, fl, get_fifo_channel_response(), logss, and write_fifo_channel_seqmsg().
Waits for wait_to seconds, then times out. Reports only the first in any series of timeouts on one channel.
resp | a pointer to a std::string, on exit is a copy of server_response or "" on timeout |
ch | is the fifo_list channel number to wait on. |
0 | on success |
-1 | on failure. |
Definition at line 446 of file VisAOApp_base.cpp.
References error_report(), fifo_list::fifo_ch, fl, get_curr_time(), logss, read_fifo_channel(), TimeToDie, and wait_to.
Referenced by write_fifo_channel().
int VisAO::VisAOApp_base::set_wait_to | ( | double | to | ) |
to | the desired timeout. |
0 | on success. |
-1 | on failure (if < 0) |
Definition at line 532 of file VisAOApp_base.cpp.
References error_report(), log_msg(), logss, and wait_to.
|
inline |
cmode | The requested control mode |
override | If not true, forces the change no matter what current mode is. |
control_mode | if successful. |
-1 | if unsuccessful. |
Reimplemented in VisAO::FilterWheelLocal.
Definition at line 555 of file VisAOApp_base.cpp.
References control_mode.
|
virtual |
The handler calls __remote_command, which in turn calls remote_command, which is where the app specific processing should be done. This contains the control_mode logic for the remote control state, which is processed before the call to remote_command.
com | is the command string to be processed. |
Definition at line 565 of file VisAOApp_base.cpp.
References control_mode, control_mode_string(), default_control_mode, remote_command(), and request_control().
Referenced by VisAO::com_remote_handler().
|
virtual |
This should be overriden by derived classes.
com | is the command string to be processed. |
Reimplemented in VisAO::CCD47Ctrl, VisAO::FocusMotorCtrl, VisAO::GimbalMotorCtrl, VisAO::FilterWheelLocal, VisAO::coronguide, VisAO::framewriter< dataT >, VisAO::dioserver, VisAO::frameselector, and VisAO::WollastonStatus.
Definition at line 622 of file VisAOApp_base.cpp.
Referenced by __remote_command().
|
virtual |
The handler calls __local_command, which in turn calls local_command, which is where the app specific processing should be done. This contains the control_mode logic for the local control state, which is processed before the call to local_command.
com | is the command string to be processed. |
Definition at line 633 of file VisAOApp_base.cpp.
References control_mode, control_mode_string(), default_control_mode, local_command(), and request_control().
Referenced by VisAO::com_local_handler().
|
virtual |
This should be overriden by derived classes.
com | is the command string to be processed. |
Reimplemented in VisAO::CCD47Ctrl, VisAO::FocusMotorCtrl, VisAO::GimbalMotorCtrl, VisAO::reconstructor, VisAO::FilterWheelLocal, VisAO::framegrabber< dataT >, VisAO::framegrabber< short >, VisAO::framegrabber< unsigned char >, VisAO::coronguide, VisAO::framewriter< dataT >, VisAO::dioserver, VisAO::frameselector, and VisAO::WollastonStatus.
Definition at line 692 of file VisAOApp_base.cpp.
Referenced by __local_command().
|
virtual |
The handler calls __script_command, which in turn calls script_command, which is where the app specific processing should be done. This contains the control_mode logic for the script control state, which is processed before the call to script_command.
com | is the command string to be processed. |
Definition at line 703 of file VisAOApp_base.cpp.
References control_mode, control_mode_string(), default_control_mode, request_control(), and script_command().
Referenced by VisAO::com_script_handler().
|
virtual |
This should be overriden by derived classes.
com | is the command string to be processed. |
Reimplemented in VisAO::CCD47Ctrl, VisAO::FocusMotorCtrl, VisAO::GimbalMotorCtrl, VisAO::reconstructor, VisAO::FilterWheelLocal, VisAO::framegrabber< dataT >, VisAO::framegrabber< short >, VisAO::framegrabber< unsigned char >, VisAO::coronguide, VisAO::framewriter< dataT >, and VisAO::frameselector.
Definition at line 762 of file VisAOApp_base.cpp.
Referenced by __script_command().
|
virtual |
The handler always calls auto_command, which after app specific processing should call post_auto_command. This is so app specific processing happens first in auto mode, for speed.
com | is the command string to be processed. |
Reimplemented in VisAO::framegrabber< dataT >, VisAO::framegrabber< short >, VisAO::framegrabber< unsigned char >, VisAO::coronguide, VisAO::framewriter< dataT >, VisAO::ShutterControlDioclient, and VisAO::frameselector.
Definition at line 773 of file VisAOApp_base.cpp.
References post_auto_command().
Referenced by VisAO::com_auto_handler().
|
virtual |
The handler calls auto_command, which in turn should call post_auto_command, which contains the control_mode logic for the auto control state, which is processed after the call to auto_command for speed.
com | is the command string to be processed. |
Definition at line 779 of file VisAOApp_base.cpp.
References control_mode, control_mode_string(), default_control_mode, and request_control().
Referenced by VisAO::frameselector::auto_command(), VisAO::ShutterControlDioclient::auto_command(), VisAO::coronguide::auto_command(), and auto_command().
|
virtual |
emsg | the message to report. |
LogLevel | is the logger level for the error report. For errors this is usually Logger::LOG_LEVEL_ERROR or Logger::LOG_LEVEL_FATAL |
Definition at line 858 of file VisAOApp_base.cpp.
References get_app_name(), and log_msg().
Referenced by check_fifo_list_RTpending(), get_fifo_channel_response(), VisAO::frameselector::Run(), VisAO::frameserver::Run(), VisAO::VisAOApp_standalone::Run(), VisAO::reconstructor::Run(), VisAO::CCD47Ctrl::Run(), set_euid_called(), set_euid_real(), set_RT_priority(), set_wait_to(), setup_baseApp(), setup_RTsigio(), setup_sigio(), VisAO::FilterWheelLocal::signal_catcher(), VisAO::VisAOApp_standalone::signal_catcher(), and write_fifo_channel().
|
virtual |
lmsg | the message to log. |
LogLevel | is the logger level for the message. |
Reimplemented in VisAO::VisAOApp_standalone.
Definition at line 864 of file VisAOApp_base.cpp.
References get_app_name().
Referenced by error_report(), set_RT_priority(), set_wait_to(), setup_baseApp(), setup_RTsigio(), setup_sigio(), and VisAO::FilterWheelLocal::signal_catcher().
sz | is the desired size (should be sizeof(xxxxx_status_board)) |
0 | on success |
-1 | on failure |
Definition at line 887 of file VisAOApp_base.cpp.
References attach_shm(), create_shmem(), statusboard_shmemid, statusboard_shmemkey, and statusboard_shmemptr.
Referenced by VisAO::reconstructor::Create(), VisAO::GimbalMotorCtrl::Create(), VisAO::CCD47Ctrl::Create(), VisAO::dioserver::init_dioserver(), VisAO::WollastonStatus::initApp(), VisAO::FocusMotorCtrl::initapp(), VisAO::PwrMon::setupVisAOApp(), and VisAO::FilterWheelLocal::setupVisAOApp().
|
inline |
the | shared memory pointer void * |
Definition at line 378 of file VisAOApp_base.h.
References statusboard_shmemptr.
mkey | is the key |
0 | on success (always) |
Definition at line 905 of file VisAOApp_base.cpp.
References statusboard_shmemkey.
|
inline |
the | shared memory key |
Definition at line 389 of file VisAOApp_base.h.
References statusboard_shmemkey.
|
virtual |
Overridden versions should call this as VisAOApp_bas::update_statusboard so the basics are taken care of.
0 | on success |
-1 | on failure |
Reimplemented in VisAO::CCD47Ctrl, VisAO::FocusMotorCtrl, VisAO::GimbalMotorCtrl, VisAO::FilterWheelLocal, VisAO::reconstructor, VisAO::coronguide, VisAO::sysmonD, VisAO::VisAOIClient, VisAO::framegrabber39, VisAO::ShutterControlDioclient, VisAO::WollastonStatus, VisAO::PwrMon, and VisAO::frameselector.
Definition at line 911 of file VisAOApp_base.cpp.
References control_mode, and statusboard_shmemptr.
Referenced by VisAO::dioserver::Run(), VisAO::VisAOApp_standalone::signal_catcher(), VisAO::frameselector::update_statusboard(), VisAO::PwrMon::update_statusboard(), VisAO::WollastonStatus::update_statusboard(), VisAO::ShutterControlDioclient::update_statusboard(), VisAO::framegrabber39::update_statusboard(), VisAO::VisAOIClient::update_statusboard(), VisAO::sysmonD::update_statusboard(), VisAO::coronguide::update_statusboard(), VisAO::reconstructor::update_statusboard(), VisAO::FilterWheelLocal::update_statusboard(), VisAO::GimbalMotorCtrl::update_statusboard(), VisAO::FocusMotorCtrl::update_statusboard(), and VisAO::CCD47Ctrl::update_statusboard().
|
staticprotected |
Is static so it can be used by static RTDB handlers.
Definition at line 224 of file VisAOApp_base.h.
Referenced by __local_command(), __remote_command(), __script_command(), VisAO::ShutterControlDioclient::auto_command(), VisAO::FilterWheelLocal::ChangePos(), VisAO::WollastonStatus::common_command(), VisAO::frameselector::common_command(), VisAO::coronguide::common_command(), VisAO::FilterWheelLocal::common_command(), VisAO::GimbalMotorCtrl::common_command(), VisAO::FocusMotorCtrl::common_command(), VisAO::CCD47Ctrl::common_command(), control_mode_response(), control_mode_string(), post_auto_command(), request_control(), VisAO::FilterWheelLocal::SetupVars(), VisAO::ShutterControlDioclient::update_statusboard(), and update_statusboard().
|
staticprotected |
If not -1, then this mode is always returned to, instead of NONE.
Definition at line 229 of file VisAOApp_base.h.
Referenced by __local_command(), __remote_command(), __script_command(), and post_auto_command().