Midas Message Functions (msg_xxx)
[The midas.h & midas.c]


Functions

INT cm_get_error (INT code, char *string)
INT cm_set_msg_print (INT system_mask, INT user_mask, int(*func)(const char *))
INT cm_msg_log (INT message_type, const char *message)
INT cm_msg_log1 (INT message_type, const char *message, const char *facility)
INT cm_msg (INT message_type, char *filename, INT line, const char *routine, const char *format,...)
INT cm_msg1 (INT message_type, char *filename, INT line, const char *facility, const char *routine, const char *format,...)
INT cm_msg_register (void(*func)(HNDLE, HNDLE, EVENT_HEADER *, void *))
INT cm_msg_retrieve (INT n_message, char *message, INT *buf_size)


Function Documentation

INT cm_get_error INT  code,
char *  string
 

Convert error code to string. Used after cm_connect_experiment to print error string in command line programs or windows programs.

Parameters:
code Error code as defined in midas.h
string Error string
Returns:
CM_SUCCESS

Definition at line 288 of file midas.c.

Referenced by cm_connect_experiment().

INT cm_msg INT  message_type,
char *  filename,
INT  line,
const char *  routine,
const char *  format,
  ...
 

This routine can be called whenever an internal error occurs or an informative message is produced. Different message types can be enabled or disabled by setting the type bits via cm_set_msg_print().

Attention:
Do not add the "\n" escape carriage control at the end of the formated line as it is already added by the client on the receiving side.
   ...
   cm_msg(MINFO, "my program", "This is a information message only);
   cm_msg(MERROR, "my program", "This is an error message with status:%d", my_status);
   cm_msg(MTALK, "my_program", My program is Done!");
   ...
Parameters:
message_type (See MIDAS Macros).
filename Name of source file where error occured
line Line number where error occured
routine Routine name.
format message to printout, ... Parameters like for printf()
Returns:
CM_SUCCESS

Definition at line 534 of file midas.c.

Referenced by al_trigger_alarm(), analyzer_init(), bk_list(), bm_close_buffer(), bm_flush_cache(), bm_open_buffer(), bm_push_event(), bm_receive_event(), bm_remove_event_request(), bm_request_event(), bm_send_event(), bm_set_cache_size(), bm_skip_event(), close_buffers(), cm_check_client(), cm_check_deferred_transition(), cm_cleanup(), cm_connect_experiment1(), cm_deregister_transition(), cm_disconnect_experiment(), cm_get_watchdog_info(), cm_list_experiments(), cm_register_deferred_transition(), cm_register_transition(), cm_set_client_info(), cm_set_transition_sequence(), cm_shutdown(), cm_transition(), db_check_record(), db_close_database(), db_copy(), db_copy_xml(), db_create_key(), db_create_link(), db_create_record(), db_delete_key1(), db_enum_key(), db_find_key(), db_get_data(), db_get_data_index(), db_get_key(), db_get_key_info(), db_get_key_time(), db_get_record(), db_get_value(), db_load(), db_lock_database(), db_open_database(), db_open_record(), db_paste(), db_paste_node(), db_protect_database(), db_save(), db_save_struct(), db_save_xml(), db_save_xml_key(), db_set_data(), db_set_data_index(), db_set_record(), db_set_value(), db_unlock_database(), dm_buffer_create(), el_submit(), handFlush(), interrupt_routine(), load_fragment(), main(), register_equipment(), rpc_flush_event(), rpc_register_functions(), rpc_send_event(), rpc_set_option(), scan_fragment(), scheduler(), send_event(), source_booking(), source_scan(), source_unbooking(), tr_start(), tr_stop(), update_odb(), and ybk_list().

INT cm_msg1 INT  message_type,
char *  filename,
INT  line,
const char *  facility,
const char *  routine,
const char *  format,
  ...
 

This routine is similar to cm_msg(). It differs from cm_msg() only by the logging destination being a file given through the argument list i.e:facility

For internal use only.

Attention:
Do not add the "\n" escape carriage control at the end of the formated line as it is already added by the client on the receiving side. The first arg in the following example uses the predefined macro MINFO which handles automatically the first 3 arguments of the function (see MIDAS Macros).
   ...
   cm_msg1(MINFO, "my_log_file", "my_program"," My message status:%d", status);
   ...
//----- File my_log_file.log
Thu Nov  8 17:59:28 2001 [my_program] My message status:1
Parameters:
message_type See MIDAS Macros.
filename Name of source file where error occured
line Line number where error occured
facility Logging file name
routine Routine name
format message to printout, ... Parameters like for printf()
Returns:
CM_SUCCESS

Definition at line 648 of file midas.c.

INT cm_msg_log INT  message_type,
const char *  message
 

Write message to logging file. Called by cm_msg.

Attention:
May burn your fingers
Parameters:
message_type Message type
message Message string
Returns:
CM_SUCCESS

Definition at line 350 of file midas.c.

Referenced by cm_msg().

INT cm_msg_log1 INT  message_type,
const char *  message,
const char *  facility
 

Write message to logging file. Called by cm_msg().

For internal use only.

Parameters:
message_type Message type
message Message string
facility Message facility, filename in which messages will be written
Returns:
CM_SUCCESS

Definition at line 419 of file midas.c.

Referenced by cm_msg1().

INT cm_msg_register void(*)(HNDLE, HNDLE, EVENT_HEADER *, void *)  func  ) 
 

Register a dispatch function for receiving system messages.

  • example code from mlxspeaker.c
    void receive_message(HNDLE hBuf, HNDLE id, EVENT_HEADER *header, void *message)
    {
      char str[256], *pc, *sp;
      // print message
      printf("%s\n", (char *)(message));
    
      printf("evID:%x Mask:%x Serial:%i Size:%d\n"
                     ,header->event_id
                     ,header->trigger_mask
                     ,header->serial_number
                     ,header->data_size);
      pc = strchr((char *)(message),']')+2;
      ...
      // skip none talking message
      if (header->trigger_mask == MT_TALK ||
          header->trigger_mask == MT_USER)
       ...
    }
    
    int main(int argc, char *argv[])
    {
      ...
      // now connect to server
      status = cm_connect_experiment(host_name, exp_name, "Speaker", NULL);
      if (status != CM_SUCCESS)
        return 1;
      // Register callback for messages
      cm_msg_register(receive_message);
      ...
    }
    
    Parameters:
    func Dispatch function.
    Returns:
    CM_SUCCESS or bm_open_buffer and bm_request_event return status

Definition at line 779 of file midas.c.

INT cm_msg_retrieve INT  n_message,
char *  message,
INT *  buf_size
 

Retrieve old messages from log file

Parameters:
n_message Number of messages to retrieve
message buf_size bytes of messages, separated by
characters. The returned number of bytes is normally smaller than the initial buf_size, since only full lines are returned.
*buf_size Size of message buffer to fill
Returns:
CM_SUCCESS

Definition at line 809 of file midas.c.

INT cm_set_msg_print INT  system_mask,
INT  user_mask,
int(*)(const char *)  func
 

Set message masks. When a message is generated by calling cm_msg(), it can got to two destinatinons. First a user defined callback routine and second to the "SYSMSG" buffer.

A user defined callback receives all messages which satisfy the user_mask.

int message_print(const char *msg)
{
  char str[160];

  memset(str, ' ', 159);
  str[159] = 0;
  if (msg[0] == '[')
    msg = strchr(msg, ']')+2;
  memcpy(str, msg, strlen(msg));
  ss_printf(0, 20, str);
  return 0;
}
...
  cm_set_msg_print(MT_ALL, MT_ALL, message_print);
...
Parameters:
system_mask Bit masks for MERROR, MINFO etc. to send system messages.
user_mask Bit masks for MERROR, MINFO etc. to send messages to the user callback.
func Function which receives all printout. By setting "puts", messages are just printed to the screen.
Returns:
CM_SUCCESS

Definition at line 333 of file midas.c.

Referenced by cm_connect_experiment1(), and main().


Midas DOC Version 1.9.5 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk