reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
util.h File Reference
#include <stdarg.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  lf_stat_ll
 

Macros

#define ATTRIBUTE_FORMAT_PRINTF(f, s)
 
#define CONCATENATE_THREE_STRINGS(__string1, __string2, __string3)   __string1 __string2 __string3
 
#define LF_LEVEL(index)   (index & 0xffffLL)
 
#define LF_MAX(X, Y)   (((X) > (Y)) ? (X) : (Y))
 
#define LF_MIN(X, Y)   (((X) < (Y)) ? (X) : (Y))
 
#define LOG_LEVEL_ERROR   0
 
#define LOG_LEVEL_WARNING   1
 
#define LOG_LEVEL_INFO   2
 
#define LOG_LEVEL_LOG   3
 
#define LOG_LEVEL_DEBUG   4
 
#define LOG_LEVEL_ALL   255
 
#define LOG_LEVEL   LOG_LEVEL_INFO
 
#define LF_PRINT_LOG(format, ...)
 
#define LF_PRINT_DEBUG(format, ...)
 

Typedefs

typedef struct lf_stat_ll lf_stat_ll
 

Functions

int lf_fed_id (void)
 
void lf_print (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void lf_vprint (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void lf_print_log (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void lf_vprint_log (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void lf_print_debug (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void lf_vprint_debug (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void error (const char *msg)
 
void lf_print_error (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void lf_vprint_error (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void lf_print_warning (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void lf_vprint_warning (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void void lf_print_error_and_exit (const char *format,...) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void void void lf_assert (bool condition, const char *format,...) ATTRIBUTE_FORMAT_PRINTF(2
 
void void void void void void void lf_vprint_error_and_exit (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void void void void typedef void() print_message_function_t (const char *, va_list)
 
void lf_register_print_function (print_message_function_t *function, int log_level)
 

Variables

int _lf_my_fed_id
 

Detailed Description

Author
Edward A. Lee
Soroush Bateni

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.

Functions intitializing and freeing memory for environments.

Header file for utility types and functions for Lingua Franca programs.

Macro Definition Documentation

◆ ATTRIBUTE_FORMAT_PRINTF

#define ATTRIBUTE_FORMAT_PRINTF (   f,
  s 
)

◆ CONCATENATE_THREE_STRINGS

#define CONCATENATE_THREE_STRINGS (   __string1,
  __string2,
  __string3 
)    __string1 __string2 __string3

A handy macro that can concatenate three strings. Useful in the LF_PRINT_DEBUG macro and lf_print_error functions that want to concatenate a "DEBUG: " or "ERROR: " to the beginning of the message and a new line format
at the end.

◆ LF_LEVEL

#define LF_LEVEL (   index)    (index & 0xffffLL)

Macro for extracting the level from the index of a reaction. A reaction that has no upstream reactions has level 0. Other reactions have a level that is the length of the longest upstream chain to a reaction with level 0 (inclusive). This is used, along with the deadline, to sort reactions in the reaction queue. It ensures that reactions that are upstream in the dependence graph execute before reactions that are downstream.

◆ LF_MAX

#define LF_MAX (   X,
  Y 
)    (((X) > (Y)) ? (X) : (Y))

Utility for finding the maximum of two values.

◆ LF_MIN

#define LF_MIN (   X,
  Y 
)    (((X) < (Y)) ? (X) : (Y))

Utility for finding the minimum of two values.

◆ LF_PRINT_DEBUG

#define LF_PRINT_DEBUG (   format,
  ... 
)
Value:
do { if(LOG_LEVEL >= LOG_LEVEL_DEBUG) { \
} } while (0)
return address
Definition hashmap.h:74
#define LOG_LEVEL
Definition util.h:110
#define LOG_LEVEL_DEBUG
Definition util.h:105

A macro used to print useful debug information. It can be enabled by setting the target property 'logging' to 'DEBUG' or by defining LOG_LEVEL to 2 in the top-level preamble. The input to this macro is exactly like printf: (format, ...). "DEBUG: " is prepended to the beginning of the message and a newline is appended to the end of the message.

Note
This macro is non-empty even if LOG_LEVEL is not defined in user-code. This is to ensure that the compiler will still parse the predicate inside (...) to prevent LF_PRINT_DEBUG statements to fall out of sync with the rest of the code. This should have a negligible impact on performance if compiler optimization (e.g., -O2 for gcc) is used as long as the arguments passed to it do not themselves incur significant overhead to evaluate.

◆ LF_PRINT_LOG

#define LF_PRINT_LOG (   format,
  ... 
)
Value:
do { if(LOG_LEVEL >= LOG_LEVEL_LOG) { \
} } while (0)
#define LOG_LEVEL_LOG
Definition util.h:104

A macro used to print useful logging information. It can be enabled by setting the target property 'logging' to 'LOG' or by defining LOG_LEVEL to LOG_LEVEL_LOG or LOG_LEVEL_DEBUG in the top-level preamble. The input to this macro is exactly like printf: (format, ...). "LOG: " is prepended to the beginning of the message and a newline is appended to the end of the message.

Note
This macro is non-empty even if LOG_LEVEL is not defined in user-code. This is to ensure that the compiler will still parse the predicate inside (...) to prevent LF_PRINT_LOG statements to fall out of sync with the rest of the code. This should have a negligible impact on performance if compiler optimization (e.g., -O2 for gcc) is used as long as the arguments passed to it do not themselves incur significant overhead to evaluate.

◆ LOG_LEVEL

#define LOG_LEVEL   LOG_LEVEL_INFO

Default log level.

◆ LOG_LEVEL_ALL

#define LOG_LEVEL_ALL   255

◆ LOG_LEVEL_DEBUG

#define LOG_LEVEL_DEBUG   4

◆ LOG_LEVEL_ERROR

#define LOG_LEVEL_ERROR   0

LOG_LEVEL is set in generated code to 0 through 4 if the target logging property is error, warning, info, log, or debug. The default level is info (2). Currently, 0, 1, and 2 are treated identically and lf_print_error, lf_print_warning, and lf_print all result in printed output. If log is set (3), then LOG_DEBUG messages will be printed as well. If debug is set (4), the LF_PRINT_DEBUG messages will be printed as well.

◆ LOG_LEVEL_INFO

#define LOG_LEVEL_INFO   2

◆ LOG_LEVEL_LOG

#define LOG_LEVEL_LOG   3

◆ LOG_LEVEL_WARNING

#define LOG_LEVEL_WARNING   1

Typedef Documentation

◆ lf_stat_ll

Holds generic statistical data

Function Documentation

◆ error()

void error ( const char msg)

Print the error defined by the errno variable with the specified message as a prefix, then exit with error code 1.

Parameters
msgThe prefix to the message.

◆ lf_assert()

void void void void void void lf_assert ( bool  condition,
const char format,
  ... 
)

A shorthand for checking if a condition is true and if not, print an error and exit.

◆ 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,
  ... 
)

Report an informational message on stdout with a newline appended at the end. If this execution is federated, then the message will be prefaced by "Federate n: ", where n is the federate ID. The arguments are just like printf().

◆ lf_print_debug()

void lf_print_debug ( const char format,
  ... 
)

Report an debug message on stdout with the prefix "DEBUG: " and a newline appended at the end. If this execution is federated, then the message will be prefaced by "Federate n: ", where n is the federate ID. The arguments are just like printf().

◆ lf_print_error()

void lf_print_error ( const char format,
  ... 
)

Report an error with the prefix "ERROR: " and a newline appended at the end. The arguments are just like printf().

◆ lf_print_error_and_exit()

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

Report an error with the prefix "ERROR: " and a newline appended at the end, then exit with the failure code EXIT_FAILURE. The arguments are just like printf().

◆ lf_print_log()

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

Report an log message on stdout with the prefix "LOG: " and a newline appended at the end. If this execution is federated, then the message will be prefaced by "Federate n: ", where n is the federate ID. The arguments are just like printf().

◆ lf_print_warning()

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

Report a warning with the prefix "WARNING: " and a newline appended at the end. The arguments are just like printf().

◆ 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 void lf_vprint ( const char format,
va_list  args 
)

varargs alternative of "lf_print"

◆ lf_vprint_debug()

void void lf_vprint_debug ( const char format,
va_list  args 
)

varargs alternative of "lf_print_debug"

◆ lf_vprint_error()

void void lf_vprint_error ( const char format,
va_list  args 
)

varargs alternative of "lf_print_error"

◆ lf_vprint_error_and_exit()

void void void void void void void lf_vprint_error_and_exit ( const char format,
va_list  args 
)

varargs alternative of "lf_print_error_and_exit"

◆ lf_vprint_log()

void void void void lf_vprint_log ( const char format,
va_list  args 
)

varargs alternative of "lf_print_log"

◆ lf_vprint_warning()

void void void void lf_vprint_warning ( const char format,
va_list  args 
)

varargs alternative of "lf_print_warning"

◆ print_message_function_t()

void void void void void void void typedef void() print_message_function_t ( const char ,
va_list   
)

Message print function type. The arguments passed to one of these print functions are a printf-style format string followed by a printf-style argument list collected into a va_list (variable argument list).

Variable Documentation

◆ _lf_my_fed_id

int _lf_my_fed_id
extern

The ID of this federate. For a non-federated execution, this will be -1. For a federated execution, it will be assigned when the generated function _lf_initialize_trigger_objects() is called.

See also
xtext/org.icyphy.linguafranca/src/org/icyphy/generator/CGenerator.xtend.