MIDAS
|
Classes | |
struct | exptab_entry |
struct | exptab_struct |
class | bm_lock_buffer_guard |
struct | TrClient |
struct | TrState |
Variables | |
static exptab_struct | _exptab |
static INT | _requested_transition |
static DWORD | _deferred_transition_mask |
static BOOL | _ctrlc_pressed = FALSE |
static std::atomic< bool > | _watchdog_thread_run {false} |
static std::atomic< bool > | _watchdog_thread_is_running {false} |
static std::atomic< std::thread * > | _watchdog_thread {NULL} |
dox dox
dox
dox
Check all clients on all buffers, remove invalid clients
Definition at line 6152 of file midas.cxx.
|
static |
Definition at line 11284 of file midas.cxx.
dox
Definition at line 6622 of file midas.cxx.
|
static |
Definition at line 5999 of file midas.cxx.
Definition at line 7946 of file midas.cxx.
Definition at line 7904 of file midas.cxx.
Definition at line 7925 of file midas.cxx.
Definition at line 11048 of file midas.cxx.
Check a buffer if an event is available and call the dispatch function if found.
buffer_name | Name of buffer |
Definition at line 10918 of file midas.cxx.
std::string cm_asctime | ( | ) |
Get time from MIDAS server and set local time.
Definition at line 1412 of file midas.cxx.
Get time from MIDAS server and set local time.
str | return time string |
buf_size | Maximum size of str |
Definition at line 1396 of file midas.cxx.
Check if a client with a /system/client/xxx entry has a valid entry in the ODB client table. If not, remove that client from the /system/client tree.
hDB | Handle to online database |
hKeyClient | Handle to client key |
Definition at line 1869 of file midas.cxx.
Definition at line 2201 of file midas.cxx.
Check for any deferred transition. If a deferred transition handler has been registered via the cm_register_deferred_transition function, this routine should be called regularly. It checks if a transition request is pending. If so, it calld the registered handler if the transition should be done and then actually does the transition.
Definition at line 3889 of file midas.cxx.
Remove hanging clients independent of their watchdog timeout.
Since this function does not obey the client watchdog timeout, it should be only called to remove clients which have their watchdog checking turned off or which are known to be dead. The normal client removement is done via cm_watchdog().
Currently (Sept. 02) there are two applications for that:
Added ignore_timeout on Nov.03. A logger might have an increased tiemout of up to 60 sec. because of tape operations. If ignore_timeout is FALSE, the logger is then not killed if its inactivity is less than 60 sec., while in the previous implementation it was always killed after 2*WATCHDOG_INTERVAL.
client_name | Client name, if zero check all clients |
ignore_timeout | If TRUE, ignore a possible increased timeout defined by each client. |
Definition at line 7610 of file midas.cxx.
Connect to a MIDAS client of the current experiment
client_name | Name of client to connect to. This name is set by the other client via the cm_connect_experiment call. |
hConn | Connection handle |
Definition at line 2766 of file midas.cxx.
INT cm_connect_experiment | ( | const char * | host_name, |
const char * | exp_name, | ||
const char * | client_name, | ||
void(*)(char *) | func | ||
) |
This function connects to an existing MIDAS experiment. This must be the first call in a MIDAS application. It opens three TCP connection to the remote host (one for RPC calls, one to send events and one for hot-link notifications from the remote host) and writes client information into the ODB under /System/Clients.
host_name | Specifies host to connect to. Must be a valid IP host name. The string can be empty ("") if to connect to the local computer. |
exp_name | Specifies the experiment to connect to. If this string is empty, the number of defined experiments in exptab is checked. If only one experiment is defined, the function automatically connects to this one. If more than one experiment is defined, a list is presented and the user can interactively select one experiment. |
client_name | Client name of the calling program as it can be seen by others (like the scl command in ODBEdit). |
func | Callback function to read in a password if security has been enabled. In all command line applications this function is NULL which invokes an internal ss_gets() function to read in a password. In windows environments (MS Windows, X Windows) a function can be supplied to open a dialog box and read in the password. The argument of this function must be the returned password. |
Definition at line 2278 of file midas.cxx.
INT cm_connect_experiment1 | ( | const char * | host_name, |
const char * | default_exp_name, | ||
const char * | client_name, | ||
void(*)(char *) | func, | ||
INT | odb_size, | ||
DWORD | watchdog_timeout | ||
) |
Connect to a MIDAS experiment (to the online database) on a specific host.
Definition at line 2297 of file midas.cxx.
Delete client info from database
hDB | Database handle |
pid | PID of entry to delete, zero for this process. |
Definition at line 1852 of file midas.cxx.
Definition at line 3669 of file midas.cxx.
Disconnect from a MIDAS client
hConn | Connection handle obtained via cm_connect_client() |
bShutdown | If TRUE, disconnect from client and shut it down (exit the client program) by sending a RPC_SHUTDOWN message |
Definition at line 2833 of file midas.cxx.
Disconnect from a MIDAS experiment.
Definition at line 2846 of file midas.cxx.
dox
Definition at line 5385 of file midas.cxx.
Definition at line 5461 of file midas.cxx.
Executes command via system() call
command | Command string to execute |
result | stdout of command |
bufsize | string size in byte |
Definition at line 5723 of file midas.cxx.
Check if a MIDAS client exists in current experiment
name | Client name |
bUnique | If true, look for the exact client name. If false, look for namexxx where xxx is a any number |
Definition at line 7520 of file midas.cxx.
Expand environment variables in filesystem file path names
Examples of expansion: $FOO=foo, $BAR=bar, $UNDEF is undefined (undefined, not empty)
ok &= test_cm_expand_env1("aaa", "aaa"); ok &= test_cm_expand_env1("$FOO", "foo"); ok &= test_cm_expand_env1("/$FOO", "/foo"); ok &= test_cm_expand_env1("/$FOO/", "/foo/"); ok &= test_cm_expand_env1("$FOO/$BAR", "foo/bar"); ok &= test_cm_expand_env1("$FOO1", "$FOO1"); ok &= test_cm_expand_env1("1$FOO", "1foo"); ok &= test_cm_expand_env1("$UNDEF", "$UNDEF"); ok &= test_cm_expand_env1("/$UNDEF/", "/$UNDEF/");
str | Input file path |
Definition at line 7710 of file midas.cxx.
std::string cm_get_client_name | ( | ) |
Get current client name
Definition at line 2059 of file midas.cxx.
Returns MIDAS environment variables.
host_name | Contents of MIDAS_SERVER_HOST environment variable. |
host_name_size | string length |
exp_name | Contents of MIDAS_EXPT_NAME environment variable. |
exp_name_size | string length |
Definition at line 2134 of file midas.cxx.
INT cm_get_environment | ( | std::string * | host_name, |
std::string * | exp_name | ||
) |
dox Get the handle to the ODB from the currently connected experiment.
hDB | Database handle. |
hKeyClient | Handle for key where search starts, zero for root. |
Definition at line 3011 of file midas.cxx.
std::string cm_get_experiment_name | ( | ) |
INT cm_get_experiment_semaphore | ( | INT * | semaphore_alarm, |
INT * | semaphore_elog, | ||
INT * | semaphore_history, | ||
INT * | semaphore_msg | ||
) |
dox
Definition at line 3033 of file midas.cxx.
Return exptab information for given experiment
s | Pointer to string buffer |
size | Size of string buffer |
Definition at line 1830 of file midas.cxx.
Return exptab information for given experiment
s | Pointer to string buffer |
size | Size of string buffer |
Definition at line 1799 of file midas.cxx.
std::string cm_get_exptab_filename | ( | ) |
dox
Definition at line 5843 of file midas.cxx.
std::string cm_get_path | ( | ) |
Return the path name previously set with cm_set_path.
path | Pathname |
Definition at line 1537 of file midas.cxx.
Return the path name previously set with cm_set_path.
path | Pathname |
Definition at line 1518 of file midas.cxx.
Definition at line 1545 of file midas.cxx.
Return watchdog information about specific client
hDB | ODB handle |
client_name | ODB client name |
timeout | Timeout for this application in seconds |
last | Last time watchdog was called in msec |
Definition at line 3336 of file midas.cxx.
Return the current watchdog parameters
call_watchdog | Call the cm_watchdog routine periodically |
timeout | Timeout for this application in seconds |
Definition at line 3317 of file midas.cxx.
INT cm_list_experiments_local | ( | STRING_LIST * | exp_names | ) |
Read exptab and return all defined experiments in *exp_name[MAX_EXPERIMENTS]
host_name | Internet host name. |
exp_name | list of experiment names |
Definition at line 2586 of file midas.cxx.
INT cm_list_experiments_remote | ( | const char * | host_name, |
STRING_LIST * | exp_names | ||
) |
Connect to a MIDAS server and return all defined experiments in *exp_name[MAX_EXPERIMENTS]
host_name | Internet host name. |
exp_name | list of experiment names |
Definition at line 2612 of file midas.cxx.
Perform midas periodic tasks - check alarms, update and check timeouts on odb and on event buffers, etc. Normally called by cm_yield(). Programs that do not use cm_yield(), i.e. the mserver, should call this function periodically, every 1 or 2 seconds.
Definition at line 5579 of file midas.cxx.
INT cm_read_exptab | ( | exptab_struct * | exptab | ) |
Scan the "exptab" file for MIDAS experiment names and save them for later use by rpc_server_accept(). The file is first searched under $MIDAS/exptab if present, then the directory from argv[0] is probed.
Definition at line 1614 of file midas.cxx.
dox Register a deferred transition handler. If a client is registered as a deferred transition handler, it may defer a requested transition by returning FALSE until a certain condition (like a motor reaches its end position) is reached.
transition | One of TR_xxx |
(*func) | Function which gets called whenever a transition is requested. If it returns FALSE, the transition is not performed. |
Definition at line 3837 of file midas.cxx.
dox
Definition at line 5790 of file midas.cxx.
Definition at line 3452 of file midas.cxx.
dox Registers a callback function for run transitions. This function internally registers the transition callback function and publishes its request for transition notification by writing a transition request to /System/Clients/<pid>/Transition XXX. Other clients making a transition scan the transition requests of all clients and call their transition callbacks via RPC.
Clients can register for transitions (Start/Stop/Pause/Resume) in a given sequence. All sequence numbers given in the registration are sorted on a transition and the clients are contacted in ascending order. By default, all programs register with a sequence number of 500. The logger however uses 200 for start, so that it can open files before the other clients are contacted, and 800 for stop, so that the files get closed when all other clients have gone already through the stop trantition.
The callback function returns CM_SUCCESS if it can perform the transition or a value larger than one in case of error. An error string can be copied into the error variable.
transition | Transition to register for (see state_transition) |
func | Callback function. |
sequence_number | Sequence number for that transition (1..1000) |
Definition at line 3593 of file midas.cxx.
INT cm_select_experiment_local | ( | std::string * | exp_name | ) |
Read exptab and select an experiment from the experiments available on this server
exp_name | selected experiment name |
Definition at line 2670 of file midas.cxx.
Connect to a MIDAS server and select an experiment from the experiments available on this server
host_name | Internet host name. |
exp_name | selected experiment name |
Definition at line 2719 of file midas.cxx.
INT cm_set_client_info | ( | HNDLE | hDB, |
HNDLE * | hKeyClient, | ||
const char * | host_name, | ||
char * | client_name, | ||
INT | hw_type, | ||
const char * | password, | ||
DWORD | watchdog_timeout | ||
) |
Set client information in online database and return handle
hDB | Handle to online database |
hKeyClient | returned key |
host_name | server name |
client_name | Name of this program as it will be seen by other clients. |
hw_type | Type of byte order |
password | MIDAS password |
watchdog_timeout | Default watchdog timeout, can be overwritten by ODB setting /programs/<name>/Watchdog timeout |
Definition at line 1893 of file midas.cxx.
Definition at line 3783 of file midas.cxx.
Set the handle to the ODB for the currently connected experiment
hDB | Database handle |
hKeyClient | Key handle of client structure |
Definition at line 2939 of file midas.cxx.
Definition at line 2166 of file midas.cxx.
INT cm_set_experiment_semaphore | ( | INT | semaphore_alarm, |
INT | semaphore_elog, | ||
INT | semaphore_history, | ||
INT | semaphore_msg | ||
) |
Set path to actual experiment. This function gets called by cm_connect_experiment if the connection is established to a local experiment (not through the TCP/IP server). The path is then used for all shared memory routines.
path | Pathname |
Definition at line 1497 of file midas.cxx.
Change the transition sequence for the calling program.
transition | TR_START, TR_PAUSE, TR_RESUME or TR_STOP. |
sequence_number | New sequence number, should be between 1 and 1000 |
Definition at line 3723 of file midas.cxx.
Definition at line 3283 of file midas.cxx.
Sets the internal watchdog flags and the own timeout. If call_watchdog is TRUE, the cm_watchdog routine is called periodically from the system to show other clients that this application is "alive". On UNIX systems, the alarm() timer is used which is then not available for user purposes.
The timeout specifies the time, after which the calling application should be considered "dead" by other clients. Normally, the cm_watchdog() routines is called periodically. If a client crashes, this does not occur any more. Then other clients can detect this and clear all buffer and database entries of this application so they are not blocked any more. If this application should not checked by others, the timeout can be specified as zero. It might be useful for debugging purposes to do so, because if a debugger comes to a breakpoint and stops the application, the periodic call of cm_watchdog is disabled and the client looks like dead.
If the timeout is not zero, but the watchdog is not called (call_watchdog == FALSE), the user must ensure to call cm_watchdog periodically with a period of WATCHDOG_INTERVAL milliseconds or less.
An application which calles system routines which block the alarm signal for some time, might increase the timeout to the maximum expected blocking time before issuing the calls. One example is the logger doing Exabyte tape IO, which can take up to one minute.
call_watchdog | Call the cm_watchdog routine periodically |
timeout | Timeout for this application in ms |
Definition at line 3244 of file midas.cxx.
Shutdown (exit) other MIDAS client
name | Client name or "all" for all clients |
bUnique | If true, look for the exact client name. If false, look for namexxx where xxx is a any number. |
Definition at line 7400 of file midas.cxx.
Definition at line 7355 of file midas.cxx.
Definition at line 7370 of file midas.cxx.
Get time from MIDAS server and set local time.
seconds | Time in seconds |
Definition at line 1369 of file midas.cxx.
void cm_test_expand_env | ( | ) |
Definition at line 7757 of file midas.cxx.
Get time from ss_time on server.
t | string |
Definition at line 1434 of file midas.cxx.
INT cm_transition | ( | INT | transition, |
INT | run_number, | ||
char * | errstr, | ||
INT | errstr_size, | ||
INT | async_flag, | ||
INT | debug_flag | ||
) |
Definition at line 5286 of file midas.cxx.
|
static |
Definition at line 5238 of file midas.cxx.
|
static |
Performs a run transition (Start/Stop/Pause/Resume).
Synchronous/Asynchronous flag. If set to TR_ASYNC, the transition is done asynchronously, meaning that clients are connected and told to execute their callback routine, but no result is awaited. The return value is specified by the transition callback function on the remote clients. If all callbacks can perform the transition, CM_SUCCESS is returned. If one callback cannot perform the transition, the return value of this callback is returned from cm_transition(). The async_flag is usually FALSE so that transition callbacks can block a run transition in case of problems and return an error string. The only exception are situations where a run transition is performed automatically by a program which cannot block in a transition. For example the logger can cause a run stop when a disk is nearly full but it cannot block in the cm_transition() function since it has its own run stop callback which must flush buffers and close disk files and tapes.
transition | TR_START, TR_PAUSE, TR_RESUME or TR_STOP. |
run_number | New run number. If zero, use current run number plus one. |
errstr | returned error string. |
errstr_size | Size of error string. |
async_flag | TR_SYNC: synchronization flag (TR_SYNC:wait completion, TR_ASYNC: retun immediately) |
debug_flag | If 1 output debugging information, if 2 output via cm_msg(). |
Definition at line 4523 of file midas.cxx.
Definition at line 4165 of file midas.cxx.
Definition at line 4400 of file midas.cxx.
INT cm_transition_cleanup | ( | ) |
|
static |
Definition at line 4082 of file midas.cxx.
Watchdog thread to maintain the watchdog timeout timestamps for this client
Definition at line 7329 of file midas.cxx.
Central yield functions for clients. This routine should be called in an infinite loop by a client in order to give the MIDAS system the opportunity to receive commands over RPC channels, update database records and receive events.
millisec | Timeout in millisec. If no message is received during the specified timeout, the routine returns. If millisec=-1, it only returns when receiving an RPC_SHUTDOWN message. |
Definition at line 5642 of file midas.cxx.
Definition at line 3404 of file midas.cxx.
dox
Definition at line 3353 of file midas.cxx.
Definition at line 12632 of file midas.cxx.
|
static |
Definition at line 3996 of file midas.cxx.
Definition at line 5254 of file midas.cxx.
Definition at line 4029 of file midas.cxx.
Definition at line 7975 of file midas.cxx.
Definition at line 8037 of file midas.cxx.
|
static |
|
static |