reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
util.c File Reference
#include "util.h"
#include <stdio.h>
#include "environment.h"
#include <errno.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include <stdbool.h>

Macros

#define NUMBER_OF_FEDERATES   1
 
#define SOCKET_READ_RETRY_INTERVAL   1000000
 

Functions

int lf_fed_id ()
 
void _lf_message_print (const char *prefix, const char *format, va_list args, int log_level) ATTRIBUTE_FORMAT_PRINTF(2
 
void lf_print (const char *format,...)
 
void lf_vprint (const char *format, va_list args)
 
void lf_print_log (const char *format,...)
 
void lf_vprint_log (const char *format, va_list args)
 
void lf_print_debug (const char *format,...)
 
void lf_vprint_debug (const char *format, va_list args)
 
void lf_print_error (const char *format,...)
 
void lf_vprint_error (const char *format, va_list args)
 
void lf_print_warning (const char *format,...)
 
void lf_vprint_warning (const char *format, va_list args)
 
void lf_print_error_and_exit (const char *format,...)
 
void lf_print_error_system_failure (const char *format,...)
 
void lf_register_print_function (print_message_function_t *function, int log_level)
 

Variables

int _lf_my_fed_id = -1
 
print_message_function_tprint_message_function = NULL
 
int print_message_level = -1
 

Detailed Description

Author
Edward A. Lee (eal@b.nosp@m.erke.nosp@m.ley.e.nosp@m.du)

LICENSE

Copyright (c) 2020, The University of California at Berkeley.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DESCRIPTION

Utility functions for managing output the user, error and warning messages, logging, and debug messages. Outputs are filtered based on the target "logging" parameter.

Macro Definition Documentation

◆ NUMBER_OF_FEDERATES

#define NUMBER_OF_FEDERATES   1

◆ SOCKET_READ_RETRY_INTERVAL

#define SOCKET_READ_RETRY_INTERVAL   1000000

Number of nanoseconds to sleep before retrying a socket read.

Function Documentation

◆ _lf_message_print()

void _lf_message_print ( const char * prefix,
const char * format,
va_list args,
int log_level )

Internal implementation of the next few reporting functions.

◆ lf_fed_id()

int lf_fed_id ( void )

Return the federate ID or -1 if this program is not part of a federation.

◆ lf_print()

void lf_print ( const char * format,
... )

◆ lf_print_debug()

void lf_print_debug ( const char * format,
... )

◆ lf_print_error()

void lf_print_error ( const char * format,
... )

◆ lf_print_error_and_exit()

void lf_print_error_and_exit ( const char * format,
... )

◆ lf_print_error_system_failure()

void lf_print_error_system_failure ( const char * format,
... )

Report an error and exit just like lf_print_error_and_exit(), but also print the system error message associated with the error.

◆ lf_print_log()

void lf_print_log ( const char * format,
... )

◆ lf_print_warning()

void lf_print_warning ( const char * format,
... )

◆ lf_register_print_function()

void lf_register_print_function ( print_message_function_t * function,
int log_level )

Register a function to display messages. After calling this, all messages passed to the above print functions will be printed using the specified function rather than printf if their log level is greater than the specified level. The level should be one of LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_LOG, or LOG_LEVEL_DEBUG.

Parameters
functionThe print message function or NULL to revert to using printf.
log_levelThe level of messages to redirect.

◆ lf_vprint()

void lf_vprint ( const char * format,
va_list args )

◆ lf_vprint_debug()

void lf_vprint_debug ( const char * format,
va_list args )

◆ lf_vprint_error()

void lf_vprint_error ( const char * format,
va_list args )

◆ lf_vprint_log()

void lf_vprint_log ( const char * format,
va_list args )

◆ lf_vprint_warning()

void lf_vprint_warning ( const char * format,
va_list args )

Variable Documentation

◆ _lf_my_fed_id

int _lf_my_fed_id = -1

The ID of this federate. For a non-federated execution, this will be -1. For a federated execution, it will be assigned in the generated code.

◆ print_message_function

print_message_function_t* print_message_function = NULL

If non-null, this function will be used instead of the printf to print messages.

◆ print_message_level

int print_message_level = -1

The level of messages to redirect to print_message_function.