The VisAO Camera
VisAO::VisAOApp_base Class Reference

The base class for VisAO applications. More...

#include <VisAOApp_base.h>

+ Inheritance diagram for VisAO::VisAOApp_base:

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

Some generic error reporting and logging facilities

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::profilerprofile
 
std::string profile_path
 
int use_profiler
 
VisAO::profilerget_profile ()
 
int get_use_profiler ()
 
int start_profiler ()
 

statusboard facilities

manage the shared memory status board

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 ()
 

Detailed Description

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.

Member Function Documentation

int VisAO::VisAOApp_base::set_RT_priority ( int  prio)

Elevates the user id to uid_called.

Parameters
priothe desired priority
Return values
0on success
-1on 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.

int VisAO::VisAOApp_base::setup_baseApp ( bool  remfifo,
bool  locfifo,
bool  scrfifo,
bool  autfifo,
bool  usethreads = false 
)
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.

Parameters
remfifoif true the remote fifo is created and installed.
locfifoif true the local fifo is created and installed.
scrfifoif true the script fifo is created and installed.
autfifoif true the auto fifo is created and installed.
usethreadsif true the threaded versions of the handlers are installed.
Return values
0on success.
-1on 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().

int VisAO::VisAOApp_base::setup_fifo_list ( int  nfifos)

Calls setup_fifo_list(&fl, nfifos).

Parameters
nfifosis the number of fifos we need
Return values
0on success.
-1o 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 ( )
int VisAO::VisAOApp_base::connect_fifo_list_nolock ( )

Calls connect_fifo_list_nolock(&fl).

Return values
0on success.
-1on 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.

Return values
0on success.
-1on 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.

Return values
0on success.
-1on 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.

Parameters
chthe channel to write to.
comthe buffer to write
comlenthe length of the buffer to write, including the '\0' character
respis a string pointer to be filled in with the server_response. Set to 0 if no response is desired.
Return values
0on success
-1on 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.

Parameters
chthe channel to write to.
comthe buffer to write
comlenthe length of the buffer to write
respis a string pointer to be filled in with the server_response. Set to 0 if no response is desired.
smis the sequence message.
Return values
0on success
-1on 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().

int VisAO::VisAOApp_base::get_fifo_channel_response ( std::string *  resp,
int  ch 
)

Waits for wait_to seconds, then times out. Reports only the first in any series of timeouts on one channel.

Parameters
respa pointer to a std::string, on exit is a copy of server_response or "" on timeout
chis the fifo_list channel number to wait on.
Return values
0on success
-1on failure.
Todo:
get_fifo_channel_response is a busy wait. should select or poll instead, but with signal safety.

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)
Parameters
tothe desired timeout.
Return values
0on success.
-1on failure (if < 0)

Definition at line 532 of file VisAOApp_base.cpp.

References error_report(), log_msg(), logss, and wait_to.

double VisAO::VisAOApp_base::get_wait_to ( )
inline
Return values
wait_to

Definition at line 218 of file VisAOApp_base.h.

References wait_to.

int VisAO::VisAOApp_base::request_control ( int  cmode,
bool  override 
)
virtual
Parameters
cmodeThe requested control mode
See also
control_modes.
Parameters
overrideIf not true, forces the change no matter what current mode is.
Return values
control_modeif successful.
-1if unsuccessful.

Reimplemented in VisAO::FilterWheelLocal.

Definition at line 555 of file VisAOApp_base.cpp.

References control_mode.

std::string VisAO::VisAOApp_base::__remote_command ( std::string  com,
char *  seqmsg 
)
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.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::remote_command ( std::string  com)
virtual

This should be overriden by derived classes.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::__local_command ( std::string  com,
char *  seqmsg 
)
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.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::local_command ( std::string  com)
virtual

This should be overriden by derived classes.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::__script_command ( std::string  com,
char *  seqmsg 
)
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.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::script_command ( std::string  com)
virtual

This should be overriden by derived classes.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::auto_command ( std::string  com,
char *  seqmsg 
)
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.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

std::string VisAO::VisAOApp_base::post_auto_command ( std::string  com,
char *  seqmsg = 0 
)
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.

Parameters
comis the command string to be processed.
Returns
the application response.

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().

void VisAO::VisAOApp_base::error_report ( int  LogLevel,
std::string  emsg 
)
virtual
void VisAO::VisAOApp_base::log_msg ( int  LogLevel,
std::string  lmsg 
)
virtual
Parameters
lmsgthe message to log.
LogLevelis 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().

int VisAO::VisAOApp_base::create_statusboard ( size_t  sz)
protected
void* VisAO::VisAOApp_base::get_statusboard_shmemptr ( )
inline
Return values
theshared memory pointer void *

Definition at line 378 of file VisAOApp_base.h.

References statusboard_shmemptr.

int VisAO::VisAOApp_base::set_statusboard_shmemkey ( key_t  mkey)
Parameters
mkeyis the key
Return values
0on success (always)

Definition at line 905 of file VisAOApp_base.cpp.

References statusboard_shmemkey.

key_t VisAO::VisAOApp_base::get_statusboard_shmemkey ( )
inline
Return values
theshared memory key

Definition at line 389 of file VisAOApp_base.h.

References statusboard_shmemkey.

Member Data Documentation

int VisAO::VisAOApp_base::default_control_mode = -1
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().


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