FreeRTOS Tetris
Macros | Typedefs | Functions
TUM_Utils.h File Reference

Utilities required by other TUM_XXX files. More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for TUM_Utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PRINT_ERROR(msg, ...)
 

Typedefs

typedef void * rbuf_handle_t
 A handle to a ring buffer object, created using rbuf_init()
 

Functions

int tumUtilIsCurGLThread (void)
 Checks if the calling thread is the thread that currently holds the GL context. More...
 
void tumUtilSetGLThread (void)
 The calling thread is registered as holding the current GL context.
 
char * tumUtilPrependPath (char *path, char *file)
 Prepends a path string to a filename. More...
 
char * tumUtilGetBinFolderPath (char *bin_path)
 Gets the execution folder of the current program, assumes that program is executing from a folder "bin". More...
 
FILE * tumUtilFindResource (char *resource_name, const char *mode)
 Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found. More...
 
char * tumUtilFindResourcePath (char *resource_name)
 Similar to tumUtilFindResource() only returning the file's path instead of the opened FILE's reference. More...
 
rbuf_handle_t rbuf_init (size_t item_size, size_t item_count)
 Initialized a ring buffer object with a certain number of objects of a given size. More...
 
rbuf_handle_t rbuf_init_static (size_t item_size, size_t item_count, void *buffer)
 Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer. More...
 
void rbuf_free (rbuf_handle_t rbuf)
 Frees a ring buffer. More...
 
void rbuf_reset (rbuf_handle_t rbuf)
 Resets the ring buffer to it's initial state. More...
 
int rbuf_put_buffer (rbuf_handle_t rbuf)
 Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved. More...
 
int rbuf_put (rbuf_handle_t rbuf, void *data)
 Fills the next available buffer slot, if a slot is free. More...
 
int rbuf_fput (rbuf_handle_t rbuf, void *data)
 Fills the next available buffer, overwriting data if the ring buffer is full. More...
 
void * rbuf_get_buffer (rbuf_handle_t rbuf)
 Returns a reference to the data of the next ring buffer entry. More...
 
int rbuf_get (rbuf_handle_t rbuf, void *data)
 Returns a copy of the next buffer item's data. More...
 
unsigned char rbuf_empty (rbuf_handle_t rbuf)
 Checks if the buffer is empty or not. More...
 
unsigned char rbug_full (rbuf_handle_t rbuf)
 Checks if the buffer is full. More...
 
size_t rbuf_size (rbuf_handle_t rbuf)
 Returns the number of elements currently stored in the ring buffer. More...
 
size_t rbuf_capacity (rbuf_handle_t rbuf)
 Returns the maximum number of elements that the ring buffer can store. More...
 

Detailed Description

Utilities required by other TUM_XXX files.

Author
Alex Hoffman
Date
27 August 2019
----------------------------------------------------------------------
Copyright (C) Alexander Hoffman, 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------

Macro Definition Documentation

◆ PRINT_ERROR

#define PRINT_ERROR (   msg,
  ... 
)
Value:
fprintf(stderr, "[ERROR] " msg, ##__VA_ARGS__); \
fprintf(stderr, " @-> %s:%d, %s\n", __FILE__, __LINE__, __func__)

Function Documentation

◆ rbuf_capacity()

size_t rbuf_capacity ( rbuf_handle_t  rbuf)

Returns the maximum number of elements that the ring buffer can store.

Parameters
rbufHandle to the ring buffer
Returns
The maximum number of elements that the ring buffer can store

◆ rbuf_empty()

unsigned char rbuf_empty ( rbuf_handle_t  rbuf)

Checks if the buffer is empty or not.

Parameters
rbufHandle to the ring buffer
Returns
1 if the buffer is empty, 0 otherwise

◆ rbuf_fput()

int rbuf_fput ( rbuf_handle_t  rbuf,
void *  data 
)

Fills the next available buffer, overwriting data if the ring buffer is full.

Parameters
rbufHandle to the ring buffer
dataReference to the data to be copied into the buffer
Returns
0 on success

◆ rbuf_free()

void rbuf_free ( rbuf_handle_t  rbuf)

Frees a ring buffer.

Parameters
rbufHandle to the ring buffer

◆ rbuf_get()

int rbuf_get ( rbuf_handle_t  rbuf,
void *  data 
)

Returns a copy of the next buffer item's data.

Parameters
rbufHandle to the ring buffer
dataA reference to the allocated memory region into which the data should be copied
Returns
0 on success

◆ rbuf_get_buffer()

void* rbuf_get_buffer ( rbuf_handle_t  rbuf)

Returns a reference to the data of the next ring buffer entry.

Because only a reference is returned the contents of the buffer entry cannot be guarenteed

Parameters
rbufHandle to the ring buffer
Returns
A reference to the next item in the buffer's data

◆ rbuf_init()

rbuf_handle_t rbuf_init ( size_t  item_size,
size_t  item_count 
)

Initialized a ring buffer object with a certain number of objects of a given size.

Parameters
item_sizeThe size, in bytes, of each ring buffer item
item_countThe maximum number of items to be stored in the ring buffer
Returns
A handle to the created ring buffer, else NULL

◆ rbuf_init_static()

rbuf_handle_t rbuf_init_static ( size_t  item_size,
size_t  item_count,
void *  buffer 
)

Initialized a ring buffer object with a certain number of objects of a given size into a statically allocated buffer.

Parameters
item_sizeThe size, in bytes, of each ring buffer item
item_countThe maximum number of items to be stored in the ring buffer
bufferReference to the statically allocated memory region that is to be used for storing the ring buffer
Returns
A handle to the created ring buffer, else NULL

◆ rbuf_put()

int rbuf_put ( rbuf_handle_t  rbuf,
void *  data 
)

Fills the next available buffer slot, if a slot is free.

Parameters
rbufHandle to the ring buffer
dataReference to the data to be copied into the buffer
Returns
0 on success

◆ rbuf_put_buffer()

int rbuf_put_buffer ( rbuf_handle_t  rbuf)

Used when a reference to the next buffer item is already filled, incrementing the next buffer item should an item need to be retrieved.

Parameters
rbufHandle to the ring buffer
Returns
0 on success

◆ rbuf_reset()

void rbuf_reset ( rbuf_handle_t  rbuf)

Resets the ring buffer to it's initial state.

Parameters
rbufHandle to the ring buffer

◆ rbuf_size()

size_t rbuf_size ( rbuf_handle_t  rbuf)

Returns the number of elements currently stored in the ring buffer.

Parameters
rbufHandle to the ring buffer
Returns
Number of elements stored in the ring buffer

◆ rbug_full()

unsigned char rbug_full ( rbuf_handle_t  rbuf)

Checks if the buffer is full.

Parameters
rbufHandle to the ring buffer
Returns
1 if the buffer is full, 0 otherwise

◆ tumUtilFindResource()

FILE* tumUtilFindResource ( char *  resource_name,
const char *  mode 
)

Searches for a file in the RESOURCES_DIRECTORY and returns a FILE * if found.

Parameters
resource_nameName of the file to be found
modeThe reading mode to be used when opening the file, eg. "rw"
Returns
FILE reference if found, otherwise NULL

◆ tumUtilFindResourcePath()

char* tumUtilFindResourcePath ( char *  resource_name)

Similar to tumUtilFindResource() only returning the file's path instead of the opened FILE's reference.

The found filename is stored in a statically allocated buffer and can be overwritten by subsequent calls to the functions

Parameters
resource_nameName of the file to be found
Returns
Reference to the statically allocated filename, else NULL

◆ tumUtilGetBinFolderPath()

char* tumUtilGetBinFolderPath ( char *  bin_path)

Gets the execution folder of the current program, assumes that program is executing from a folder "bin".

Parameters
bin_pathThe program's binary's location, usually argv[0]
Returns
char * String of the folder's absolute location

◆ tumUtilIsCurGLThread()

int tumUtilIsCurGLThread ( void  )

Checks if the calling thread is the thread that currently holds the GL context.

Returns
0 if the current thread does hold the GL context, -1 otherwise.

◆ tumUtilPrependPath()

char* tumUtilPrependPath ( char *  path,
char *  file 
)

Prepends a path string to a filename.

Parameters
pathPath string to be prepended
fileFilename to which the path string should be prepended
Returns
char * to the complete compiled path