MIDAS
|
Classes | |
struct | exptab_entry |
struct | exptab_struct |
class | bm_lock_buffer_guard |
struct | TrClient |
struct | TrState |
Functions | |
INT | cm_synchronize (DWORD *seconds) |
INT | cm_asctime (char *str, INT buf_size) |
std::string | cm_asctime () |
INT | cm_time (DWORD *t) |
const char * | cm_get_version () |
const char * | cm_get_revision () |
INT | cm_set_path (const char *path) |
INT | cm_get_path (char *path, int path_size) |
std::string | cm_get_path () |
INT EXPRT | cm_get_path_string (std::string *path) |
INT | cm_set_experiment_name (const char *name) |
INT | cm_get_experiment_name (char *name, int name_length) |
std::string | cm_get_experiment_name () |
INT | cm_read_exptab (exptab_struct *exptab) |
int | cm_get_exptab_filename (char *s, int size) |
std::string | cm_get_exptab_filename () |
int | cm_get_exptab (const char *expname, std::string *dir, std::string *user) |
int | cm_get_exptab (const char *expname, char *dir, int dir_size, char *user, int user_size) |
INT | cm_delete_client_info (HNDLE hDB, INT pid) |
INT | cm_check_client (HNDLE hDB, HNDLE hKeyClient) |
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) |
std::string | cm_get_client_name () |
INT | cm_get_environment (char *host_name, int host_name_size, char *exp_name, int exp_name_size) |
INT | cm_get_environment (std::string *host_name, std::string *exp_name) |
int | cm_set_experiment_local (const char *exp_name) |
void | cm_check_connect (void) |
INT | cm_connect_experiment (const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *)) |
INT | cm_connect_experiment1 (const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout) |
INT | cm_list_experiments_local (STRING_LIST *exp_names) |
INT | cm_list_experiments_remote (const char *host_name, STRING_LIST *exp_names) |
INT | cm_select_experiment_local (std::string *exp_name) |
INT | cm_select_experiment_remote (const char *host_name, std::string *exp_name) |
INT | cm_connect_client (const char *client_name, HNDLE *hConn) |
static void | rpc_client_shutdown () |
INT | cm_disconnect_client (HNDLE hConn, BOOL bShutdown) |
INT | cm_disconnect_experiment (void) |
INT | cm_set_experiment_database (HNDLE hDB, HNDLE hKeyClient) |
INT | cm_set_experiment_semaphore (INT semaphore_alarm, INT semaphore_elog, INT semaphore_history, INT semaphore_msg) |
INT | cm_get_experiment_database (HNDLE *hDB, HNDLE *hKeyClient) |
INT | cm_get_experiment_semaphore (INT *semaphore_alarm, INT *semaphore_elog, INT *semaphore_history, INT *semaphore_msg) |
static int | bm_validate_client_index (const BUFFER *buf, BOOL abort_if_invalid) |
static BUFFER_CLIENT * | bm_get_my_client (BUFFER *pbuf, BUFFER_HEADER *pheader) |
static BUFFER * | bm_get_buffer (const char *who, INT buffer_handle, int *pstatus) |
static int | bm_lock_buffer_read_cache (BUFFER *pbuf) |
static int | bm_lock_buffer_write_cache (BUFFER *pbuf) |
static int | bm_lock_buffer_mutex (BUFFER *pbuf) |
static int | xbm_lock_buffer (BUFFER *pbuf) |
static void | xbm_unlock_buffer (BUFFER *pbuf) |
static INT | bm_notify_client (const char *buffer_name, int s) |
static void | bm_defragment_event (HNDLE buffer_handle, HNDLE request_id, EVENT_HEADER *pevent, void *pdata, EVENT_HANDLER *dispatcher) |
INT | cm_set_watchdog_params_local (BOOL call_watchdog, DWORD timeout) |
INT | cm_set_watchdog_params (BOOL call_watchdog, DWORD timeout) |
INT | cm_get_watchdog_params (BOOL *call_watchdog, DWORD *timeout) |
INT | cm_get_watchdog_info (HNDLE hDB, const char *client_name, DWORD *timeout, DWORD *last) |
static void | load_rpc_hosts (HNDLE hDB, HNDLE hKey, int index, void *info) |
static void | init_rpc_hosts (HNDLE hDB) |
INT | cm_register_server (void) |
INT | cm_register_transition (INT transition, INT(*func)(INT, char *), INT sequence_number) |
INT | cm_deregister_transition (INT transition) |
INT | cm_set_transition_sequence (INT transition, INT sequence_number) |
INT | cm_set_client_run_state (INT state) |
INT | cm_register_deferred_transition (INT transition, BOOL(*func)(INT, BOOL)) |
INT | cm_check_deferred_transition () |
static bool | tr_compare (const std::unique_ptr< TrClient > &arg1, const std::unique_ptr< TrClient > &arg2) |
static int | tr_finish (HNDLE hDB, TrState *tr, int transition, int status, const char *errorstr) |
static void | write_tr_client_to_odb (HNDLE hDB, const TrClient *tr_client) |
static int | cm_transition_detach (INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag) |
static int | cm_transition_call (TrState *s, int idx) |
static int | cm_transition_call_direct (TrClient *tr_client) |
static INT | cm_transition2 (INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag) |
static INT | cm_transition1 (INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag) |
static INT | tr_main_thread (void *param) |
INT | cm_transition_cleanup () |
INT | cm_transition (INT transition, INT run_number, char *errstr, INT errstr_size, INT async_flag, INT debug_flag) |
INT | cm_dispatch_ipc (const char *message, int message_size, int client_socket) |
void | cm_ctrlc_handler (int sig) |
BOOL | cm_is_ctrlc_pressed () |
void | cm_ack_ctrlc_pressed () |
int | cm_exec_script (const char *odb_path_to_script) |
static void | bm_cleanup (const char *who, DWORD actual_time, BOOL wrong_interval) |
INT | cm_periodic_tasks () |
INT | cm_yield (INT millisec) |
INT | cm_execute (const char *command, char *result, INT bufsize) |
INT | cm_register_function (INT id, INT(*func)(INT, void **)) |
std::string | cm_get_history_path (const char *history_channel) |
INT | cm_watchdog_thread (void *unused) |
static void | xcm_watchdog_thread () |
INT | cm_start_watchdog_thread () |
INT | cm_stop_watchdog_thread () |
INT | cm_shutdown (const char *name, BOOL bUnique) |
INT | cm_exist (const char *name, BOOL bUnique) |
INT | cm_cleanup (const char *client_name, BOOL ignore_timeout) |
std::string | cm_expand_env (const char *str) |
static bool | test_cm_expand_env1 (const char *str, const char *expected) |
void | cm_test_expand_env () |
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 6115 of file midas.cxx.
|
static |
Definition at line 11251 of file midas.cxx.
|
static |
Definition at line 5962 of file midas.cxx.
|
static |
Definition at line 7911 of file midas.cxx.
|
static |
Definition at line 7869 of file midas.cxx.
|
static |
Definition at line 7890 of file midas.cxx.
|
static |
Definition at line 11015 of file midas.cxx.
dox
Definition at line 5918 of file midas.cxx.
void cm_ack_ctrlc_pressed | ( | void | ) |
std::string cm_asctime | ( | ) |
Get time from MIDAS server and set local time.
str | return time string |
buf_size | Maximum size of str |
Definition at line 1398 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 1871 of file midas.cxx.
void cm_check_connect | ( | void | ) |
INT cm_check_deferred_transition | ( | void | ) |
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 3885 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 7574 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 2760 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 2280 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 2299 of file midas.cxx.
void cm_ctrlc_handler | ( | int | sig | ) |
Definition at line 3665 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 2827 of file midas.cxx.
INT cm_disconnect_experiment | ( | void | ) |
Disconnect from a MIDAS experiment.
Definition at line 2840 of file midas.cxx.
INT cm_dispatch_ipc | ( | const char * | message, |
int | message_size, | ||
int | client_socket | ||
) |
dox
Definition at line 5381 of file midas.cxx.
int cm_exec_script | ( | const char * | odb_path_to_script | ) |
Definition at line 5457 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 5719 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 7484 of file midas.cxx.
std::string cm_expand_env | ( | const char * | str | ) |
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 7675 of file midas.cxx.
std::string cm_get_client_name | ( | ) |
INT cm_get_environment | ( | char * | host_name, |
int | host_name_size, | ||
char * | exp_name, | ||
int | exp_name_size | ||
) |
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 2136 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 3005 of file midas.cxx.
std::string cm_get_experiment_name | ( | ) |
INT cm_get_experiment_name | ( | char * | name, |
int | name_length | ||
) |
INT cm_get_experiment_semaphore | ( | INT * | semaphore_alarm, |
INT * | semaphore_elog, | ||
INT * | semaphore_history, | ||
INT * | semaphore_msg | ||
) |
int cm_get_exptab | ( | const char * | expname, |
char * | dir, | ||
int | dir_size, | ||
char * | user, | ||
int | user_size | ||
) |
Return exptab information for given experiment
s | Pointer to string buffer |
size | Size of string buffer |
Definition at line 1832 of file midas.cxx.
int cm_get_exptab | ( | const char * | expname, |
std::string * | dir, | ||
std::string * | user | ||
) |
int cm_get_exptab_filename | ( | char * | s, |
int | size | ||
) |
std::string cm_get_history_path | ( | const char * | history_channel | ) |
std::string cm_get_path | ( | ) |
INT cm_get_path | ( | char * | path, |
int | path_size | ||
) |
const char* cm_get_revision | ( | void | ) |
const char* cm_get_version | ( | void | ) |
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 3332 of file midas.cxx.
BOOL cm_is_ctrlc_pressed | ( | void | ) |
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 2580 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 2606 of file midas.cxx.
INT cm_periodic_tasks | ( | void | ) |
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 5575 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 1616 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 3833 of file midas.cxx.
dox
Definition at line 5786 of file midas.cxx.
INT cm_register_server | ( | void | ) |
Definition at line 3448 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 3589 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 2664 of file midas.cxx.
INT cm_select_experiment_remote | ( | const char * | host_name, |
std::string * | exp_name | ||
) |
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 2713 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 1895 of file midas.cxx.
Definition at line 3779 of file midas.cxx.
int cm_set_experiment_local | ( | const char * | exp_name | ) |
Definition at line 2168 of file midas.cxx.
INT cm_set_experiment_name | ( | const char * | name | ) |
INT cm_set_experiment_semaphore | ( | INT | semaphore_alarm, |
INT | semaphore_elog, | ||
INT | semaphore_history, | ||
INT | semaphore_msg | ||
) |
INT cm_set_path | ( | const char * | path | ) |
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 1499 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 3719 of file midas.cxx.
Definition at line 3279 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 3239 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 7364 of file midas.cxx.
INT cm_start_watchdog_thread | ( | void | ) |
INT cm_stop_watchdog_thread | ( | void | ) |
Definition at line 7334 of file midas.cxx.
void cm_test_expand_env | ( | ) |
Definition at line 7722 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 5282 of file midas.cxx.
|
static |
Definition at line 5234 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 4519 of file midas.cxx.
|
static |
Definition at line 4161 of file midas.cxx.
|
static |
Definition at line 4396 of file midas.cxx.
INT cm_transition_cleanup | ( | ) |
|
static |
Definition at line 4078 of file midas.cxx.
INT cm_watchdog_thread | ( | void * | unused | ) |
Watchdog thread to maintain the watchdog timeout timestamps for this client
Definition at line 7293 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 5638 of file midas.cxx.
|
static |
Definition at line 3400 of file midas.cxx.
dox
Definition at line 3349 of file midas.cxx.
|
static |
Definition at line 12599 of file midas.cxx.
|
static |
|
static |
Definition at line 3992 of file midas.cxx.
|
static |
Definition at line 5250 of file midas.cxx.
Definition at line 4025 of file midas.cxx.
|
static |
Definition at line 7940 of file midas.cxx.
|
static |
Definition at line 8002 of file midas.cxx.
|
static |
|
static |
|
static |
|
static |