Skip to content

Midas C++ API - cm_msg_xxx functions

This page contains the full API reference for the cm_msg_xxx message functions.

For the concepts and day-to-day use, see Messages: overview.

For explanations and examples of sending and reading messages from code, see Messages: programming.

Message Functions (cm_msg_xxx)

Functions

cm_get_error

std::string cm_get_error(INT code)

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

Parameters:

  • code (INT) –
    Error code as defined in midas.h
  • string –
    Error string

Returns:

Declared in include/midas.h:1681, defined in src/midas.cxx:473

cm_msg

INT cm_msg(INT message_type, const 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().

...
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 (INT) –
    (See midas_macro).
  • filename (const char *) –
    Name of source file where error occured
  • line (INT) –
    Line number where error occured
  • routine (const char *) –
    Routine name.
  • format (const char *) –
    message to printout, ... Parameters like for printf()

Returns:

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.

Declared in include/midas.h:1759, defined in src/midas.cxx:939

cm_msg1

INT cm_msg1(INT message_type, const 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

Declared in include/midas.h:1760, defined in src/midas.cxx:997

cm_msg_close_buffer

INT cm_msg_close_buffer()

printf("cm_msg_close_buffer!\n");

Declared in include/midas.h:1768, defined in src/midas.cxx:505

cm_msg_early_init

INT cm_msg_early_init()

Declared in include/midas.h:1769, defined in src/midas.cxx:485

cm_msg_facilities

INT cm_msg_facilities(STRING_LIST *list)

Retrieve list of message facilities by searching logfiles on disk

Parameters:

  • list (STRING_LIST *) –
    List of facilities

Returns:

  • INT –
    status SUCCESS

Declared in include/midas.h:1765, defined in src/midas.cxx:522

cm_msg_flush_buffer

INT cm_msg_flush_buffer()

This routine can be called to process messages buffered by cm_msg(). Normally it is called from cm_yield() and cm_disconnect_experiment() to make sure all accumulated messages are processed.

Declared in include/midas.h:1761, defined in src/midas.cxx:889

cm_msg_get_logfile

void cm_msg_get_logfile(const char *facility, time_t t, std::string* filename, std::string* linkname, std::string* linktarget)

Declared in include/midas.h:1766, defined in src/midas.cxx:557

cm_msg_log

INT cm_msg_log(INT message_type, const char *facility, const char *message)

Write message to logging file. Called by cm_msg.

Parameters:

  • message_type (INT) –
    Message type
  • facility (const char *) –
    Message facility, filename in which messages will be written
  • message (const char *) –
    Message string

Returns:

Attention

May burn your fingers

Declared in include/msystem.h:532, defined in src/midas.cxx:682

cm_msg_open_buffer

INT cm_msg_open_buffer()

printf("cm_msg_open_buffer!\n");

Declared in include/midas.h:1767, defined in src/midas.cxx:492

cm_msg_register

INT cm_msg_register(EVENT_HANDLER* 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 (EVENT_HANDLER*) –
    Dispatch function.

Returns:

  • INT –
    CM_SUCCESS or bm_open_buffer and bm_request_event return status

Declared in include/midas.h:1762, defined in src/midas.cxx:1075

cm_msg_retrieve

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

Retrieve newest messages from "midas" facility log file

Parameters:

  • n_message (INT) –
    Number of messages to retrieve
  • message (char *) –
    buf_size bytes of messages, separated by \n characters. The returned number of bytes is normally smaller than the initial buf_size, since only full lines are returned.
  • buf_size (INT)

Returns:

Declared in include/midas.h:1763, defined in src/midas.cxx:1381

cm_msg_retrieve2

INT cm_msg_retrieve2(const char *facility, time_t t, int min_messages, char** messages, int* num_messages)

Retrieve old messages from log file

Parameters:

  • facility (const char *) –
    Logging facility ("midas", "chat", "lazy", ...)
  • t (time_t) –
    Return messages logged before and including time t, value 0 means start with newest messages
  • min_messages (int) –
    Minimum number of messages to return
  • messages (char**) –
    messages, newest first, separated by \n characters. caller should free() this buffer at the end.
  • num_messages (int*) –
    Number of messages returned

Returns:

Declared in include/midas.h:1764, defined in src/midas.cxx:1311

cm_set_msg_print

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

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 (INT) –
    Bit masks for MERROR, MINFO etc. to send system messages.
  • user_mask (INT) –
    Bit masks for MERROR, MINFO etc. to send messages to the user callback.
  • func (int (*) (const char *)) –
    Function which receives all printout. By setting "puts", messages are just printed to the screen.

Returns:

Declared in include/midas.h:1758, defined in src/midas.cxx:665