Skip to content

Midas C++ API - ss_xxx functions

This page contains the full API reference for the ss_xxx system services functions. They hide the differences between operating systems, providing portable access to time, shared memory, semaphores and mutexes, threads, sockets, files and tape devices.

System Functions (ss_xxx)

Functions

recv_string

INT recv_string(int sock, char *buffer, DWORD buffer_size, INT flags)

Receive network data over TCP port. Since sockets are operated in stream mode, a single transmission via send may not transfer the full data. Therefore, one has to check at the receiver side if the full data is received. If not, one has to issue several recv() commands.

The length of the data is determined by a trailing zero.

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • buffer (char *) [out] –
    Network receive buffer.
  • buffer_size (DWORD) [in] –
    Size of the buffer in bytes.
  • flags (INT) [in] –
    Timeout in ms

Returns:

  • INT –
    String length

Declared in include/msystem.h:658, defined in src/system.cxx:5478

recv_tcp

INT recv_tcp(int sock, char *buffer, DWORD buffer_size, INT flags)

Receive network data over TCP port. Since sockets are operated in stream mode, a single transmission via send may not transfer the full data. Therefore, one has to check at the receiver side if the full data is received. If not, one has to issue several recv() commands.

The length of the data is determined by the data header, which consists of two DWORDs. The first is the command code (or function id), the second is the size of the following parameters in bytes. From that size recv_tcp() determines how much data to receive.

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • buffer (char *) [out] –
    Network receive buffer.
  • buffer_size (DWORD) [in] –
    Size of the buffer in bytes.
  • flags (INT) [in] –
    Flags passed to recv()
  • net_buffer [in] –
    Buffer to store data to

Returns:

  • INT –
    Same as recv()

Declared in include/msystem.h:656, defined in src/system.cxx:5533

recv_tcp2

INT recv_tcp2(int sock, char *buffer, int buffer_size, int timeout_ms)

Receive network data over TCP port. Since sockets are operated in stream mode, a single transmission via send may not transfer the full data. Therefore, one has to check at the receiver side if the full data is received. If not, one has to issue several recv() commands.

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened
  • buffer (char *) [in,out] –
    Buffer to store data
    Network receive buffer
  • buffer_size (int) [in] –
    Number of bytes to receive
  • timeout_ms (int) [in] –
    Timeout in milliseconds

Returns:

  • INT –
    number of bytes received (less than buffer_size if there was a timeout), or: 0 : timeout and nothing was received
  • -1 –
    socket error

Declared in include/msystem.h:657, defined in src/system.cxx:5641

rpc_flush_event_socket

int rpc_flush_event_socket(int timeout_msec)

Receive and en-buffer events from the mserver event socket

Returns:

Declared in include/msystem.h:663, defined in src/midas.cxx:17599

send_tcp

INT send_tcp(int sock, char *buffer, DWORD buffer_size, INT flags)

Send network data over TCP port. Break buffer in smaller parts if larger than maximum TCP buffer size (usually 64k).

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • buffer (char *) [out] –
    Network receive buffer.
  • buffer_size (DWORD) [in] –
    Size of the buffer in bytes.
  • flags (INT) [in] –
    Flags passed to send() 0x10000 : do not send error message

Returns:

  • INT –
    Same as send()

Declared in include/msystem.h:655, defined in src/system.cxx:5364

ss_alarm

INT ss_alarm(INT millitime, void (*func) (int))

Schedules an alarm. Call function referenced by *func after the specified seconds.

Parameters:

  • millitime (INT) [in] –
    Time in milliseconds
  • func (void (*) (int)) [in] –
    Function to be called after the spe-
    cified time.

Returns:

Declared in include/msystem.h:617, defined in src/system.cxx:3816

ss_asctime

std::string ss_asctime()

Returns the local actual time as a string

Returns:

  • std::string –
    char: * Time string

Declared in include/midas.h:2029, defined in src/system.cxx:3628

ss_clear_screen

void ss_clear_screen()

Clear the screen

Declared in include/midas.h:2038, defined in src/system.cxx:7384

ss_crypt

char *ss_crypt(const char *key, const char *salt)

Simple fake of UNIX crypt(3) function, until we get a better one

Parameters:

  • key (const char *) [in] –
    Plain password
  • salt (const char *)
  • slalt [in] –
    Two random characters events. Can be used to skip events

Returns:

  • char * –
    char*: Encrypted password

Declared in include/midas.h:2044, defined in src/system.cxx:7976

ss_ctrlc_handler

void *ss_ctrlc_handler(void (*func) (int))

Establish new exception handler which is called before the program is aborted due to a Ctrl-Break. This handler may clean up things which may otherwise left in an undefined state.

Parameters:

  • func (void (*) (int))
  • int [in] –
    Address of handler function, if NULL install default handler

Returns:

  • void * –
    same as signal()

Declared in include/midas.h:2047, defined in src/system.cxx:3978

ss_daemon_init

INT ss_daemon_init(BOOL keep_stdout)

Become a daemon

Returns:

  • SS_SUCCESS –
    Successful completeion
  • SS_ABORT –
    fork() was not successful, or other problem

Declared in include/msystem.h:599, defined in src/system.cxx:2073

ss_dir_exist

INT ss_dir_exist(const char *path)

Check if a directory exists

Parameters:

  • path (const char *) [in] –
    Name of a file in file to check

Returns:

  • INT –
    int: 1: file exists 0: file does not exist

Declared in include/midas.h:2074, defined in src/system.cxx:7271

ss_dir_find

Note: this function has 2 different signatures.

ss_dir_find
INT ss_dir_find(const char *path, const char *pattern, char **plist)

Declared in include/midas.h:2079, defined in src/system.cxx:6881

ss_dir_find
INT ss_dir_find(const char *path, const char *pattern, STRING_LIST *plist)

Return list of direcories matching 'pattern' from the 'path' location

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check
  • pattern (const char *) [in] –
    pattern string (wildcard allowed)
  • plist (STRING_LIST*) [out] –
    pointer to the lfile list

Returns:

  • INT –
    int: Number of files matching request

Declared in include/midas.h:2082, defined in src/system.cxx:6899

ss_directio_give_port

INT ss_directio_give_port(INT start, INT end)

direct io routines

Declared in include/midas.h:2052, defined in src/system.cxx:7896

ss_directio_lock_port

INT ss_directio_lock_port(INT start, INT end)

Declared in include/midas.h:2053, defined in src/system.cxx:7932

Note: this function has 2 different signatures.

INT ss_dirlink_find(const char *path, const char *pattern, char **plist)

Declared in include/midas.h:2080, defined in src/system.cxx:6957

INT ss_dirlink_find(const char *path, const char *pattern, STRING_LIST *plist)

Return list of direcories and links matching 'pattern' from the 'path' location

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check
  • pattern (const char *) [in] –
    pattern string (wildcard allowed)
  • plist (STRING_LIST*) [out] –
    pointer to the lfile list

Returns:

  • INT –
    int: Number of files matching request

Declared in include/midas.h:2083, defined in src/system.cxx:6975

ss_disk_free

double ss_disk_free(const char *path)

Return free disk space

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check

Returns:

  • double –
    doube: Number of bytes free on disk

Declared in include/midas.h:2071, defined in src/system.cxx:6705

ss_disk_size

double ss_disk_size(const char *path)

Return full disk space

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check

Returns:

  • double –
    doube: Number of bytes free on disk

Declared in include/midas.h:2084, defined in src/system.cxx:7133

ss_event_socket_has_data

bool ss_event_socket_has_data()

mserver event socket

Declared in include/msystem.h:662, defined in src/system.cxx:4599

ss_exception_handler

INT ss_exception_handler(void (*func) (void))

Establish new exception handler which is called before the program is aborted due to a Ctrl-Break or an access violation. This handler may clean up things which may otherwise left in an undefined state.

Parameters:

  • func (void (*) (void)) [in] –
    Address of handler function

Returns:

Declared in include/msystem.h:628, defined in src/system.cxx:3923

ss_exec

INT ss_exec(const char *cmd, INT * child_pid)

Execute command in a separate process, close all open file descriptors, return the pid of the child process.

Parameters:

  • cmd (const char *) [in] –
    Command to execute
  • child_pid (INT *) [in] –
    Returned PID of the spawned process.

Returns:

  • SS_SUCCESS –
    Successful completion
  • SS_ABORT –
    fork() was not successful, or other problem

Declared in include/msystem.h:601, defined in src/system.cxx:2204

ss_execs

std::string ss_execs(const char *cmd)

Execute shell command and return result in a string

Parameters:

  • cmd (const char *)
  • command [in] –
    Command to execute

Returns:

  • std::string –
    std::string: Result of shell commaand

Declared in include/msystem.h:603, defined in src/system.cxx:2309

ss_existpid

BOOL ss_existpid(INT pid)

Execute a Kill sig=0 which return success if pid found.

Parameters:

  • pid (INT) [in] –
    pid to check

Returns:

Declared in include/msystem.h:604, defined in src/system.cxx:2140

ss_file_copy

int ss_file_copy(const char *src, const char *dst, bool append = false)

Copy file "src" to file "dst"

Parameters:

  • src (const char *) [in] –
    Source file name
  • dst (const char *) [in] –
    Destination file name
  • append (bool, default: false)

Returns:

  • int –
    int: function error 0= ok, -1 check errno

Declared in include/midas.h:2085, defined in src/system.cxx:7304

ss_file_exist

INT ss_file_exist(const char *path)

Check if a file exists

Parameters:

  • path (const char *) [in] –
    Name of a file in file to check

Returns:

  • INT –
    int: 1: file exists 0: file does not exist

Declared in include/midas.h:2075, defined in src/system.cxx:7203

ss_file_find

Note: this function has 2 different signatures.

ss_file_find
INT ss_file_find(const char *path, const char *pattern, char **plist)

Declared in include/midas.h:2078, defined in src/system.cxx:6798

ss_file_find
INT ss_file_find(const char *path, const char *pattern, STRING_LIST *plist)

Return list of files matching 'pattern' from the 'path' location

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check
  • pattern (const char *) [in] –
    pattern string (wildcard allowed)
  • plist (STRING_LIST*) [out] –
    pointer to the lfile list

Returns:

  • INT –
    int: Number of files matching request

Declared in include/midas.h:2081, defined in src/system.cxx:6816

INT ss_file_link_exist(const char *path)

Check if a symbolic link file exists

Parameters:

  • path (const char *) [in] –
    Name of a file in file to check

Returns:

  • INT –
    int: 1: file exists 0: file does not exist

Declared in include/midas.h:2076, defined in src/system.cxx:7239

ss_file_remove

INT ss_file_remove(const char *path)

remove (delete) file given through the path

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check

Returns:

  • INT –
    int: function error 0= ok, -1 check errno

Declared in include/midas.h:2077, defined in src/system.cxx:7037

ss_file_size

double ss_file_size(const char *path)

Return file size in bytes for the given path

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check

Returns:

  • double –
    double: File size

Declared in include/midas.h:2072, defined in src/system.cxx:7057

ss_file_time

time_t ss_file_time(const char *path)

Return time of last file modification

Parameters:

  • path (const char *) [in] –
    Name of a file in file system to check

Returns:

  • time_t –
    time_t: File modification time

Declared in include/midas.h:2073, defined in src/system.cxx:7095

ss_get_cmdline

std::string ss_get_cmdline()

Return command line for current executable

Returns:

  • std::string –
    std::string: Command line

Declared in include/msystem.h:647, defined in src/system.cxx:1519

ss_get_executable

std::string ss_get_executable()

Return full path of current executable

Returns:

  • std::string –
    std::string: Name of executable

Declared in include/msystem.h:646, defined in src/system.cxx:1490

ss_get_struct_align

INT ss_get_struct_align()

Returns compiler alignment of structures. In C, structures can be byte aligned, word or even quadword aligned. This can usually be set with compiler switches. This routine tests this alignment during runtime and returns 1 for byte alignment, 2 for word alignment, 4 for dword alignment and 8 for quadword alignment.

Returns:

  • INT –
    Structure alignment

Declared in include/msystem.h:634, defined in src/system.cxx:1321

ss_get_struct_padding

INT ss_get_struct_padding()

Returns compiler padding of structures. Under some C compilers and architectures, C structures can be padded at the end to have a size of muliples of 4 or 8. This routine returns this number, like 8 if all structures are padded with 0-7 bytes to lie on an 8 byte boundary.

Returns:

  • INT –
    Structure alignment

Declared in include/msystem.h:635, defined in src/system.cxx:1347

ss_getchar

INT ss_getchar(BOOL reset)

Read a single character

Parameters:

  • reset (BOOL) [in] –
    Reset terminal to standard mode

Returns:

  • INT –
    int: 0 for no character available CH_xxs for special character n ASCII code for normal character -1 function not available on this OS

Declared in include/midas.h:2043, defined in src/system.cxx:7588

ss_getcwd

std::string ss_getcwd()

Declared in include/midas.h:2032, defined in src/system.cxx:5855

ss_gethostname

Note: this function has 2 different signatures.

ss_gethostname
INT ss_gethostname(char* buffer, int buffer_size)

Get name of local machine using gethostname() syscall

Parameters:

  • buffer (char*) [out] –
    receive buffer
  • buffer_size (int) [in] –
    Size of the buffer in bytes.

Returns:

Declared in include/msystem.h:642, defined in src/system.cxx:5825

ss_gethostname
std::string ss_gethostname()

Get name of local machine using gethostname() syscall

Parameters:

  • buffer_size [in] –
    Size of the buffer in bytes.
  • buffer [out] –
    receive buffer

Returns:

Declared in include/msystem.h:643, defined in src/system.cxx:5791

ss_getpass

char *ss_getpass(const char *prompt)

Read password without echoing it at the screen

Parameters:

  • prompt (const char *) [in] –
    Prompt string

Returns:

  • char * –
    char*: Pointer to password

Declared in include/midas.h:2042, defined in src/system.cxx:7525

ss_getpid

INT ss_getpid()

Return process ID of current process

Returns:

  • INT –
    Process ID

Declared in include/msystem.h:605, defined in src/system.cxx:1379

ss_gets

char *ss_gets(char *string, int size)

Read a line from standard input. Strip trailing new line character. Return in a loop so that it cannot be interrupted by an alarm() signal (like under Sun Solaris)

Parameters:

  • string (char *) [out] –
    Return string
  • size (int) [in] –
    Size of string

Returns:

  • char * –
    char: Return string

Declared in include/midas.h:2045, defined in src/system.cxx:7855

ss_gettid

midas_thread_t ss_gettid()

Return thread ID of current thread

Returns:

  • INT –
    thread ID

Declared in include/msystem.h:606, defined in src/system.cxx:1591

ss_is_valid_utf8

bool ss_is_valid_utf8(const char* s)

Method to check if a given string is valid UTF-8. Returns 1 if it is. This method was taken from stackoverflow user Christoph, specifically http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c

Declared in include/midas.h:2088, defined in src/system.cxx:8153

ss_isfin

int ss_isfin(double x)

old-style finite()

Declared in include/midas.h:2036, defined in src/system.cxx:8051

ss_isnan

int ss_isnan(double x)

Declared in include/midas.h:2035, defined in src/system.cxx:8046

ss_kbhit

BOOL ss_kbhit()

Returns TRUE if a key is pressed

Returns:

  • FALSE –
    No key has been pressed
  • TRUE –
    Key has been pressed

Declared in include/midas.h:2031, defined in src/system.cxx:3743

ss_kill

void ss_kill(int pid)

Kill given process, ensure it is not running anymore

Returns:

  • void - none

Declared in include/msystem.h:645, defined in src/system.cxx:1473

ss_millitime

DWORD ss_millitime()

Returns the actual time in milliseconds with an arbitrary origin. This time may only be used to calculate relative times.

Overruns in the 32 bit value don't hurt since in a subtraction calculated with 32 bit accuracy this overrun cancels (you may think about!)..

...
DWORD start, stop:
start = ss_millitime();
  < do operations >
stop = ss_millitime();
printf("Operation took %1.3lf seconds\n",(stop-start)/1000.0);
...

Returns:

  • DWORD –
    millisecond time stamp.

Declared in include/midas.h:2023, defined in src/system.cxx:3472

ss_mktime

time_t ss_mktime(struct tm* tms)

Declared in include/midas.h:2028, defined in src/system.cxx:3444

ss_mutex_create

INT ss_mutex_create(MUTEX_T **mutex, BOOL recursive)

Create a mutex for inter-thread locking

Parameters:

  • mutex (MUTEX_T **) [out] –
    Address of pointer to mutex
  • recursive (BOOL)

Returns:

Declared in include/msystem.h:612, defined in src/system.cxx:3020

ss_mutex_delete

INT ss_mutex_delete(MUTEX_T *mutex)

Delete a mutex

Parameters:

  • mutex (MUTEX_T *) [in] –
    Pointer to mutex

Returns:

Declared in include/msystem.h:615, defined in src/system.cxx:3290

ss_mutex_release

INT ss_mutex_release(MUTEX_T *mutex)

Release ownership of a mutex

Parameters:

  • mutex (MUTEX_T *) [in] –
    Pointer to mutex

Returns:

  • SS_SUCCESS –
    Successful completion
  • SS_NO_MUTES –
    Invalid mutes handle

Declared in include/msystem.h:614, defined in src/system.cxx:3236

ss_mutex_wait_for

INT ss_mutex_wait_for(MUTEX_T *mutex, INT timeout)

Wait for a mutex to get owned

Parameters:

  • mutex (MUTEX_T *) [in] –
    Pointer to mutex
  • timeout (INT) [in] –
    Timeout in ms, zero for no timeout

Returns:

Declared in include/msystem.h:613, defined in src/system.cxx:3116

ss_nan

double ss_nan()

Declared in include/midas.h:2034, defined in src/system.cxx:8025

ss_pid_exists

BOOL ss_pid_exists(int pid)

Check if given pid still exists

Returns:

  • BOOL –
    TRUE or FALSE

Declared in include/msystem.h:644, defined in src/system.cxx:1442

ss_printf

void ss_printf(INT x, INT y, const char *format, ...)

Print string at given cursor position

Parameters:

  • x (INT)
  • y (INT) [in] –
    Cursor position, starting from zero,
    x=0 and y=0 left upper corner
  • format (const char *) [in] –
    Format string for printf

Declared in include/midas.h:2039, defined in src/system.cxx:7467

ss_recv_net_command

INT ss_recv_net_command(int sock, DWORD* routine_id, DWORD* param_size, char **param_ptr, int timeout_ms)

Receive MIDAS data packet from a TCP port. MIDAS data packet is defined by NET_COMMAND_HEADER which consists of two DWORDs. The first is the command code (or function id), the second is the size of the following parameters in bytes. From that size recv_tcp() determines how much data to receive.

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • routine_id (DWORD*) [in] –
    routine_id from NET_COMMAND_HEADER
  • param_size (DWORD*) [in] –
    param_size from NET_COMMAND_HEADER, size of allocated data buffer
  • param_ptr (char **) [in] –
    pointer to allocated data buffer
  • timeout_ms (int) [in] –
    timeout in milliseconds

Returns:

Declared in include/msystem.h:659, defined in src/system.cxx:5714

ss_repair_utf8

Note: this function has 2 different signatures.

ss_repair_utf8
bool ss_repair_utf8(char* s)

Declared in include/midas.h:2089, defined in src/system.cxx:8236

ss_repair_utf8
bool ss_repair_utf8(std::string& s)

C++11 std::string data() is same as c_str(), NUL-terminated. C++17 std::string data() is not "const". https://en.cppreference.com/w/cpp/string/basic_string/data

Declared in include/midas.h:2090, defined in src/system.cxx:8332

ss_replace_env_variables

std::string ss_replace_env_variables(const std::string& inputPath)

Declared in include/msystem.h:602, defined in src/system.cxx:2284

ss_resume

INT ss_resume(INT port, const char *message)

Resume another thread or process which called ss_suspend. The port has to be transfered (shared memory or so) from the thread or process which should be resumed. In that process it can be obtained via ss_suspend_get_port.

Parameters:

  • port (INT) [in] –
    UDP port number
  • message (const char *)
  • msg [in] –
    Mesage id & parameter transferred to
  • param [in] –
    target process

Returns:

Declared in include/msystem.h:626, defined in src/system.cxx:4923

ss_semaphore_create

INT ss_semaphore_create(const char *semaphore_name, HNDLE * semaphore_handle)

Create a semaphore with a specific name

Parameters:

  • semaphore_name (const char *) [in] –
    Name of the semaphore to create. Special blank name "" creates a local semaphore for syncronization between threads in multithreaded applications.
  • semaphore_handle (HNDLE *) [out] –
    Handle of the created semaphore

Returns:

Remark

Under VxWorks the specific semaphore handling is different than other OS. But VxWorks provides the POSIX-compatible semaphore interface. Under POSIX, no timeout is supported. So for the time being, we keep the pure VxWorks The semaphore type is a Binary instead of mutex as the binary is an optimized mutex.

Declared in include/msystem.h:608, defined in src/system.cxx:2532

ss_semaphore_delete

INT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag)

Delete a semaphore

Parameters:

  • semaphore_handle (HNDLE) [in] –
    Handle of the semaphore
  • destroy_flag (INT)

Returns:

Declared in include/msystem.h:611, defined in src/system.cxx:2948

ss_semaphore_release

INT ss_semaphore_release(HNDLE semaphore_handle)

Release ownership of a semaphore

Parameters:

  • semaphore_handle (HNDLE) [in] –
    Handle of the semaphore

Returns:

Declared in include/msystem.h:610, defined in src/system.cxx:2860

ss_semaphore_wait_for

INT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec)

Wait for a semaphore to get owned

Parameters:

  • semaphore_handle (HNDLE) [in] –
    Handle of the semaphore
  • timeout_millisec (DWORD) [in] –
    Timeout in ms, zero for no timeout

Returns:

Declared in include/msystem.h:609, defined in src/system.cxx:2718

ss_set_screen_size

void ss_set_screen_size(int x, int y)

Set the screen size in character cells

Declared in include/midas.h:2040, defined in src/system.cxx:7434

ss_settime

DWORD ss_settime(DWORD seconds)

Set local time. Used to synchronize different computers

Parameters:

  • seconds (DWORD)
  • INT [in] –
    Time in seconds since 1.1.1970 UTC.

Declared in include/midas.h:2026, defined in src/system.cxx:3554

ss_shell

INT ss_shell(int sock)

Execute shell via socket (like telnetd)

Parameters:

  • sock (int) [in] –
    Socket

Returns:

Declared in include/msystem.h:598, defined in src/system.cxx:1832

ss_shm_close

INT ss_shm_close(const char *name, void *shm_adr, size_t shm_size, HNDLE handle, INT destroy_flag)

Close a shared memory region.

Parameters:

  • name (const char *) [in] –
    Name of the shared memory
  • shm_adr (void *) [in] –
    Base address of shared memory
  • shm_size (size_t) [in] –
    Size of shared memory shm_size returned by ss_shm_open()
  • handle (HNDLE) [in] –
    Handle of shared memeory
  • destroy_flag (INT)
  • destroy [in] –
    Shared memory has to be destroyd and
    flushed to the mapping file.

Returns:

Declared in include/msystem.h:592, defined in src/system.cxx:757

ss_shm_delete

INT ss_shm_delete(const char *name)

Delete shared memory segment from memory.

Parameters:

  • name (const char *) [in] –
    Name of the shared memory

Returns:

Declared in include/msystem.h:594, defined in src/system.cxx:911

ss_shm_flush

INT ss_shm_flush(const char *name, const void *shm_adr, size_t shm_size, HNDLE handle, bool wait_for_thread)

Flush a shared memory region to its disk file.

Parameters:

  • name (const char *) [in] –
    Name of the shared memory
  • shm_adr (const void *) [in] –
    Base address of shared memory
  • shm_size (size_t) [in] –
    Size of shared memeory
  • handle (HNDLE) [in] –
    Handle of shared memory
  • wait_for_thread (bool)

Returns:

Declared in include/msystem.h:593, defined in src/system.cxx:1178

ss_shm_open

INT ss_shm_open(const char *name, INT size, void **shm_adr, size_t *shm_size, HNDLE *handle, BOOL get_size)

Create a shared memory region which can be seen by several processes which know the name.

Parameters:

  • name (const char *) [in] –
    Name of the shared memory
  • size (INT) [in] –
    Initial size of the shared memory in bytes if .SHM file doesn't exist
  • shm_adr (void **) [out] –
    Address of opened shared memory
  • shm_size (size_t *) [out] –
    Size of shared memory to use with ss_shm_close() & co
  • handle (HNDLE *) [out] –
    Handle or key to the shared memory
  • get_size (BOOL) [in] –
    If TRUE and shared memory already exists, overwrite "size" parameter with existing memory size

Returns:

Declared in include/msystem.h:591, defined in src/system.cxx:326

ss_shm_protect

INT ss_shm_protect(HNDLE handle, void *shm_adr, size_t shm_size)

Protect a shared memory region, disallow read and write access to it by this process

Parameters:

  • handle (HNDLE) [in] –
    Handle of shared memeory
  • shm_adr (void *) [in] –
    Address of shared memory
  • shm_size (size_t) [in] –
    Size of shared memory

Returns:

Declared in include/msystem.h:595, defined in src/system.cxx:1005

ss_shm_unprotect

INT ss_shm_unprotect(HNDLE handle, void **shm_adr, size_t shm_size, BOOL read, BOOL write, const char* caller_name)

Unprotect a shared memory region so that it can be accessed by this process

Parameters:

  • handle (HNDLE) [in] –
    Handle or key to the shared memory, must be obtained with ss_shm_open
  • shm_adr (void **) [out] –
    Address of opened shared memory
  • shm_size (size_t) [in] –
    Size of shared memory shm_size returned by ss_shm_open()
  • read (BOOL)
  • write (BOOL)
  • caller_name (const char*)

Returns:

Declared in include/msystem.h:596, defined in src/system.cxx:1062

ss_sleep

INT ss_sleep(INT millisec)

Suspend the calling process for a certain time.

The function is similar to the sleep() function, but has a resolution of one milliseconds. Under VxWorks the resolution is 1/60 of a second. It uses the socket select() function with a time-out. See examples in ss_time()

Parameters:

  • millisec (INT) –
    Time in milliseconds to sleep. Zero means infinite (until another process calls ss_wake)

Returns:

Declared in include/midas.h:2030, defined in src/system.cxx:3707

ss_socket_close

INT ss_socket_close(int* sockp)

Declared in include/msystem.h:652, defined in src/system.cxx:5310

ss_socket_connect_tcp

INT ss_socket_connect_tcp(const char* hostname, int tcp_port, int* sockp, std::string* error_msg_p)

socket routines

Declared in include/msystem.h:650, defined in src/system.cxx:5046

ss_socket_get_peer_name

INT ss_socket_get_peer_name(int sock, std::string* host, int* port)

Declared in include/msystem.h:654, defined in src/system.cxx:5325

ss_socket_listen_tcp

INT ss_socket_listen_tcp(bool listen_localhost, int tcp_port, int* sockp, int* tcp_port_p, std::string* error_msg_p)

Declared in include/msystem.h:651, defined in src/system.cxx:5141

ss_socket_wait

INT ss_socket_wait(int sock, int millisec)

Wait for data available to read from a socket

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • millisec (int) [in] –
    Timeout in ms

Returns:

Declared in include/msystem.h:653, defined in src/system.cxx:4977

ss_spawnv

INT ss_spawnv(INT mode, const char *cmdname, const char* const argv[])

Spawn a subprocess or detached process

Parameters:

  • mode (INT) [in] –
    One of the following modes:
    P_WAIT Wait for the subprocess to compl.
    P_NOWAIT Don't wait for subprocess to compl.
    P_DETACH Create detached process.
  • cmdname (const char *) [in] –
    Program name to execute
  • argv (const char* const[]) [in] –
    Optional program arguments

Returns:

Declared in include/msystem.h:597, defined in src/system.cxx:1702

ss_stack_get

INT ss_stack_get(char ***string)

Declared in include/msystem.h:637, defined in src/system.cxx:8079

ss_stack_history_dump

void ss_stack_history_dump(char *filename)

Declared in include/msystem.h:640, defined in src/system.cxx:8129

ss_stack_history_entry

void ss_stack_history_entry(char *tag)

Declared in include/msystem.h:639, defined in src/system.cxx:8107

ss_stack_print

void ss_stack_print()

Declared in include/msystem.h:638, defined in src/system.cxx:8095

ss_suspend

INT ss_suspend(INT millisec, INT msg)

Suspend the calling thread for a specified time. If timeout (in millisec.) is negative, the thead is suspended indefinitely. It can only be resumed from another thread or process which calls ss_resume or by some data which arrives on the client or server sockets.

If msg equals to one of MSG_BM, MSG_ODB, the function return whenever such a message is received. This is needed to break recursive calls to the event handler and db_watch() handler:

Avoided recursion via ss_suspend(MSG_BM):

ss_suspend(0) ->
-> MSG_BM message arrives in the UDP socket
-> ss_suspend_process_ipc()
-> cm_dispatch_ipc()
-> bm_push_event()
-> bm_push_buffer()
-> bm_read_buffer()
-> bm_wait_for_more_events()
-> ss_suspend(MSG_BM) <- event buffer code calls ss_suspend() with MSG_BM set
-> MSG_BM arrives arrives in the UDP socket
-> ss_suspend_process_ipc(MSG_BM)
-> the newly arrived MSG_BM message is discarded,
   recursive call to cm_dispatch_ipc(), bm_push_buffer() & co avoided

Incorrect recursion via the event handler where user called ss_suspend() without MSG_BM:

analyzer -> -> cm_yield() in the main loop -> ss_suspend(0) -> MSG_BM message arrives in the UDP socket -> ss_suspend_process_ipc(0) -> cm_dispatch_ipc() -> bm_push_event() -> bm_push_buffer() -> bm_read_buffer() -> bm_dispatch_event() -> user event handler -> user event handler ROOT graphics main loop needs to sleep -> ss_suspend(0) <--- should be ss_suspend(MSG_BM)!!! -> MSG_BM message arrives in the UDP socket -> ss_suspend_process_ipc(0) <- should be ss_suspend_process_ipc(MSG_BM)!!! -> cm_dispatch_ipc() <- without MSG_BM, calling cm_dispatch_ipc() again -> bm_push_event() -> bm_push_buffer() -> bm_read_buffer() -> bm_dispatch_event() -> user event handler <---- called recursively, very bad!

Parameters:

  • millisec (INT) [in] –
    Timeout in milliseconds
  • msg (INT) [in] –
    Return from ss_suspend when msg (MSG_BM, MSG_ODB) is received.

Returns:

Declared in include/msystem.h:629, defined in src/system.cxx:4622

ss_suspend_exit

INT ss_suspend_exit()

Closes the sockets used in the suspend/resume mechanism. Should be called before a thread exits.

Returns:

Declared in include/msystem.h:627, defined in src/system.cxx:4305

ss_suspend_get_buffer_port

INT ss_suspend_get_buffer_port(midas_thread_t thread_id, INT * port)

Return the UDP port number which can be used to resume the calling thread inside a ss_suspend function. The port number can then be used by another process as a para- meter to the ss_resume function to resume the thread which called ss_suspend.

Parameters:

  • thread_id (midas_thread_t)
  • port (INT *) [out] –
    UDP port number

Returns:

Declared in include/msystem.h:620, defined in src/system.cxx:4432

ss_suspend_get_odb_port

INT ss_suspend_get_odb_port(INT * port)

Return the UDP port number for receiving ODB notifications (db_watch & co)

Parameters:

  • port (INT *) [out] –
    UDP port number

Returns:

Declared in include/msystem.h:619, defined in src/system.cxx:4406

ss_suspend_init_odb_port

INT ss_suspend_init_odb_port()

Setup UDP port to receive ODB notifications (db_watch & co)

Returns:

Declared in include/msystem.h:618, defined in src/system.cxx:4384

ss_suspend_set_client_connection

INT ss_suspend_set_client_connection(RPC_SERVER_CONNECTION* connection)

client side of the mserver connection

Declared in include/msystem.h:624, defined in src/system.cxx:4370

ss_suspend_set_client_listener

INT ss_suspend_set_client_listener(int listen_socket)

midas program rpc listener socket (run transitions, etc)

Declared in include/msystem.h:623, defined in src/system.cxx:4363

ss_suspend_set_rpc_thread

INT ss_suspend_set_rpc_thread(midas_thread_t thread_id)

Declared in include/msystem.h:621, defined in src/system.cxx:4081

ss_suspend_set_server_acceptions

INT ss_suspend_set_server_acceptions(RPC_SERVER_ACCEPTION_LIST* acceptions)

server side of the RPC connections (run transitions, etc)

Declared in include/msystem.h:625, defined in src/system.cxx:4377

ss_suspend_set_server_listener

INT ss_suspend_set_server_listener(int listen_socket)

mserver listener socket

Declared in include/msystem.h:622, defined in src/system.cxx:4356

ss_system

INT ss_system(const char *command)

Execute command in a separate process, close all open file descriptors invoke ss_exec() and ignore pid.

{ ...
  char cmd[256];
  sprintf(cmd,"%s %s %i %s/%s %1.3lf %d",lazy.commandAfter,
     lazy.backlabel, lazyst.nfiles, lazy.path, lazyst.backfile,
     lazyst.file_size/1000.0/1000.0, blockn);
  cm_msg(MINFO,"Lazy","Exec post file write script:%s",cmd);
  ss_system(cmd);
}
...

Parameters:

  • command (const char *) –
    Command to execute.

Returns:

Declared in include/msystem.h:600, defined in src/system.cxx:2188

ss_tape_close

INT ss_tape_close(INT channel)

Close tape channel

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Low level error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2057, defined in src/system.cxx:5987

ss_tape_fskip

INT ss_tape_fskip(INT channel, INT count)

Skip count number of files on a tape

Parameters:

  • channel (INT) [in] –
    Channel identifier
  • count (INT) [in] –
    Number of files to skip

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2062, defined in src/system.cxx:6317

ss_tape_get_blockn

INT ss_tape_get_blockn(INT channel)

Ask the tape channel for the present block number

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    blockn:: >0 = block number, =0 option not available, <0 errno

Declared in include/midas.h:2068, defined in src/system.cxx:6653

ss_tape_mount

INT ss_tape_mount(INT channel)

Mount tape

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2066, defined in src/system.cxx:6541

ss_tape_open

INT ss_tape_open(char *path, INT oflag, INT * channel)

Open tape channel

Parameters:

  • path (char *) [in] –
    Name of tape Under Windows NT, usually \.\tape0 Under UNIX, usually /dev/tape
  • oflag (INT) [in] –
    Open flags, same as open()
  • channel (INT *) [out] –
    Channel identifier

Returns:

Declared in include/midas.h:2056, defined in src/system.cxx:5896

ss_tape_read

INT ss_tape_read(INT channel, void *pdata, INT * count)

Read count bytes to tape channel

Parameters:

  • channel (INT) [in] –
    Channel identifier
  • pdata (void *) [in] –
    Address of data
  • count (INT *) [in,out] –
    Number of bytes to read
    Number of read

Returns:

  • INT –
    <errno>: Error code
  • SS_SUCCESS –
    Successful operation

Declared in include/midas.h:2059, defined in src/system.cxx:6177

ss_tape_rewind

INT ss_tape_rewind(INT channel)

Rewind tape

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2064, defined in src/system.cxx:6433

ss_tape_rskip

INT ss_tape_rskip(INT channel, INT count)

Skip count number of records on a tape

Parameters:

  • channel (INT) [in] –
    Channel identifier
  • count (INT) [in] –
    Number of records to skip

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2063, defined in src/system.cxx:6377

ss_tape_spool

INT ss_tape_spool(INT channel)

Spool tape forward to end of recorded data

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2065, defined in src/system.cxx:6485

ss_tape_status

INT ss_tape_status(char *path)

Print status information about tape

Parameters:

  • path (char *) [in] –
    Name of tape
  • print [out] –
    Tape information

Returns:

Declared in include/midas.h:2058, defined in src/system.cxx:6031

ss_tape_unmount

INT ss_tape_unmount(INT channel)

Unmount tape

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2067, defined in src/system.cxx:6597

ss_tape_write

INT ss_tape_write(INT channel, void *pdata, INT count)

Write count bytes to tape channel

Parameters:

  • channel (INT) [in] –
    Channel identifier
  • pdata (void *) [in] –
    Address of data to write
  • count (INT) [in] –
    number of bytes

Returns:

Declared in include/midas.h:2060, defined in src/system.cxx:6117

ss_tape_write_eof

INT ss_tape_write_eof(INT channel)

Write end-of-file to tape channel

Parameters:

  • channel (INT) [in] –
    Channel identifier

Returns:

  • INT –
    errno: Error number
  • SS_SUCCESS –
    Successful completion

Declared in include/midas.h:2061, defined in src/system.cxx:6251

ss_thread_create

midas_thread_t ss_thread_create(INT(*func) (void *), void *param)

Creates and returns a new thread of execution.

Note the difference when calling from vxWorks versus Linux and Windows. The parameter pointer for a vxWorks call is a VX_TASK_SPAWN structure, whereas for Linux and Windows it is a void pointer. Early versions returned SS_SUCCESS or SS_NO_THREAD instead of thread ID.

Example for VxWorks

...
VX_TASK_SPAWN tsWatch = {"Watchdog", 100, 0, 2000,  (int) pDevice, 0, 0, 0, 0, 0, 0, 0, 0 ,0};
midas_thread_t thread_id = ss_thread_create((void *) taskWatch, &tsWatch);
if (thread_id == 0) {
  printf("cannot spawn taskWatch\n");
}
...

Example for Linux

...
midas_thread_t thread_id = ss_thread_create((void *) taskWatch, pDevice);
if (thread_id == 0) {
  printf("cannot spawn taskWatch\n");
}
...

Parameters:

  • func (INT(*) (void *))
  • param (void *) –
    a pointer to a VX_TASK_SPAWN structure for vxWorks and a void pointer for Unix and Windows

Returns:

  • midas_thread_t –
    the new thread id or zero on error

Declared in include/msystem.h:630, defined in src/system.cxx:2382

ss_thread_get_name

std::string ss_thread_get_name()

Declared in include/msystem.h:633, defined in src/system.cxx:2516

ss_thread_kill

INT ss_thread_kill(midas_thread_t thread_id)

Destroys the thread identified by the passed thread id. The thread id is returned by ss_thread_create() on creation.

...
midas_thread_t thread_id = ss_thread_create((void *) taskWatch, pDevice);
if (thread_id == 0) {
  printf("cannot spawn taskWatch\n");
}
...
ss_thread_kill(thread_id);
...

Parameters:

  • thread_id (midas_thread_t) –
    the thread id of the thread to be killed.

Returns:

Declared in include/msystem.h:631, defined in src/system.cxx:2455

ss_thread_set_name

INT ss_thread_set_name(std::string name)

Declared in include/msystem.h:632, defined in src/system.cxx:2498

ss_tid_to_string

std::string ss_tid_to_string(midas_thread_t thread_id)

Declared in include/msystem.h:607, defined in src/system.cxx:1643

ss_time

DWORD ss_time()

Returns the actual time in seconds since 1.1.1970 UTC.

...
DWORD start, stop:
start = ss_time();
  ss_sleep(12000);
stop = ss_time();
printf("Operation took %1.3lf seconds\n",stop-start);
...

Returns:

  • DWORD –
    Time in seconds

Declared in include/midas.h:2024, defined in src/system.cxx:3541

ss_time_sec

double ss_time_sec()

Declared in include/midas.h:2025, defined in src/system.cxx:3546

ss_timed_mutex_wait_for_sec

bool ss_timed_mutex_wait_for_sec(std::timed_mutex& mutex, const char* mutex_name, double timeout_sec)

Lock C++11 timed mutex with a timeout

Parameters:

  • mutex (std::timed_mutex&) [in] –
    Pointer to mutex
  • mutex_name (const char*)
  • timeout_sec (double) [in] –
    Timeout in seconds, zero to wait forever

Returns:

  • bool –
    true: Successful completion
  • false: Timeout

Declared in include/msystem.h:616, defined in src/system.cxx:3344

ss_timezone

INT ss_timezone()

Returns difference in seconds between coordinated universal time and local time.

Returns:

  • INT –
    Time difference in seconds

Declared in include/msystem.h:636, defined in src/system.cxx:3659

ss_tzset

void ss_tzset()

Declared in include/midas.h:2027, defined in src/system.cxx:3434

ss_us_since

unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start)

Declared in include/msystem.h:700, defined in src/system.cxx:8345

ss_us_start

std::chrono::time_point<std::chrono::high_resolution_clock> ss_us_start()

stop watch

Declared in include/msystem.h:699, defined in src/system.cxx:8340

ss_write_tcp

INT ss_write_tcp(int sock, const char *buffer, size_t buffer_size)

Send network data over TCP port. Handle partial writes

Parameters:

  • sock (int) [in] –
    Socket which was previosly opened.
  • buffer (const char *) [out] –
    Network receive buffer.
  • buffer_size (size_t) [in] –
    Size of the buffer in bytes.
  • flags [in] –
    Flags passed to send() 0x10000 : do not send error message

Returns:

Declared in include/midas.h:2049, defined in src/system.cxx:5431