Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
error-state.c File Reference

Go to the source code of this file.

Description

implementation of C-style error handling in Lumiera.

This implementation is based on a thread local error flag. C++ code uses a custom exception hierarchy, which automatically sets the error flag whenever an exception is thrown.

See also
error.h
error-exception.cpp

Definition in file error-state.c.

#include "lib/error.h"
#include <pthread.h>

Classes

struct  lumiera_errorcontext
 Holding error and some context data. More...
 

Typedefs

typedef lumiera_errorcontext * LumieraErrorcontext
 

Functions

lumiera_err lumiera_error (void)
 Get and clear current error state. More...
 
 LUMIERA_ERROR_DEFINE (ERRNO,"errno")
 
 LUMIERA_ERROR_DEFINE (EERROR,"could not initialise error system")
 
 LUMIERA_ERROR_DEFINE (UNKNOWN,"unknown error")
 
int lumiera_error_expect (lumiera_err expected)
 Expect some error Check that the current error state matches some expectation, if true then the error state is cleared and 1 is returned, otherwise 0 is returned and the error state remains set. More...
 
const char * lumiera_error_extra (void)
 Query the extra context for the last error. More...
 
LumieraErrorcontext lumiera_error_get (void)
 
lumiera_err lumiera_error_peek (void)
 Check current error state without clearing it Please avoid this function and use lumiera_error() if possible. More...
 
lumiera_err lumiera_error_set (lumiera_err nerr, const char *extra)
 Set error state for the current thread. More...
 
static void lumiera_error_tls_delete (void *err)
 
static void lumiera_error_tls_init (void)
 

Variables

static pthread_once_t lumiera_error_initialized
 
static pthread_key_t lumiera_error_tls
 

Typedef Documentation

typedef lumiera_errorcontext* LumieraErrorcontext

Definition at line 63 of file error-state.c.


Class Documentation

struct lumiera_errorcontext_struct
Class Members
lumiera_err err
char * extra
+ Collaboration diagram for lumiera_errorcontext:

Function Documentation

LUMIERA_ERROR_DEFINE ( ERRNO  ,
"errno"   
)
LUMIERA_ERROR_DEFINE ( EERROR  ,
"could not initialise error system"   
)
LUMIERA_ERROR_DEFINE ( UNKNOWN  ,
"unknown error"   
)
static void lumiera_error_tls_delete ( void *  err)
static

Definition at line 67 of file error-state.c.

References extra.

Referenced by lumiera_error_tls_init().

+ Here is the caller graph for this function:

static void lumiera_error_tls_init ( void  )
static

Definition at line 75 of file error-state.c.

References LUMIERA_DIE, lumiera_error_tls, and lumiera_error_tls_delete().

Referenced by lumiera_error_get().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

LumieraErrorcontext lumiera_error_get ( void  )

Definition at line 83 of file error-state.c.

References LUMIERA_DIE, lumiera_error_initialized, lumiera_error_tls, lumiera_error_tls_init(), and NULL.

Referenced by lumiera_error(), lumiera_error_expect(), lumiera_error_extra(), lumiera_error_peek(), lumiera_error_set(), and main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

lumiera_err lumiera_error_set ( lumiera_err  nerr,
const char *  extra 
)

Set error state for the current thread.

If the error state of the current thread was cleared, then set it, else preserve the old state.

Parameters
nerrname of the error with 'LUMIERA_ERROR_' prefix (example: LUMIERA_ERROR_NO_MEMORY)
extraa string (possibly a constructed tmpbuf) which adds some more context to the error, can be a temporary
Returns
old state, that is NULL for success, when the state was cleared and a pointer to a pending error when the error state was already set

Definition at line 105 of file error-state.c.

References lumiera_error_get(), and NULL.

Referenced by ExceptionError_test::checkErrorFlagPropagation(), lumiera_lockerror_set(), and main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

lumiera_err lumiera_error ( void  )

Get and clear current error state.

This function clears the error state, if it needs to be reused, one has to store it in a temporary variable.

Returns
pointer to any pending error of this thread, NULL if no error is pending

Definition at line 124 of file error-state.c.

References lumiera_errorcontext::err, lumiera_error_get(), and NULL.

Referenced by OutputDirector::bringDown(), ConfigFlags_test::check_ConfigSelector(), ExceptionError_test::checkErrorFlagPropagation(), ExceptionError_test::checkErrorIntegration(), CreateAsset_test::createMedia(), Suite::describe(), SimpleAllocator< TYPES, COUNTER >::destroy(), TypedAllocationManager::destroyElement(), Proxy< IHandle >::getHandle(), GuiRunner::GuiRunner(), HandlingPattern::invoke(), PlacementIndex::isValid(), Index< POA >::isValid(), Thread::launchThread(), lumiera_plugin_init(), lumiera::error::lumiera_unexpectedException(), main(), lumiera::maybeThrow(), PlaybackController::play(), DispatcherLoop::runSessionThread(), Proxy< IHandle >::start(), Provision< AD >::storeCopy(), TEST(), thread_loop(), lumiera::throwOnError(), MockElm::~MockElm(), and PlacementIndex::Table::~Table().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const char* lumiera_error_extra ( void  )

Query the extra context for the last error.

Returns
the extra string from the last error

Definition at line 135 of file error-state.c.

References lumiera_error_get().

Referenced by lumiera::error::detailInfo().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

lumiera_err lumiera_error_peek ( void  )

Check current error state without clearing it Please avoid this function and use lumiera_error() if possible.

Errors must be cleared else certain parts of the application refuse to cooperate with you. This shall only be used to decide if one wants to barf out of a loop or subroutine to deliver the error to a higher level.

Returns
pointer to any pending error of this thread, NULL if no error is pending

Definition at line 142 of file error-state.c.

References lumiera_error_get().

Referenced by CommandUse2_test::check_defaultHandlingPattern(), ExceptionError_test::checkErrorFlagPropagation(), Proxy< IHandle >::getHandle(), GuiRunner::GuiRunner(), gui::launchUI(), lumiera_plugin_discover(), lumiera_plugin_register(), Result< RES >::maybeThrow(), Result< void >::maybeThrow(), TEST(), and Thread::threadMain().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int lumiera_error_expect ( lumiera_err  expected)

Expect some error Check that the current error state matches some expectation, if true then the error state is cleared and 1 is returned, otherwise 0 is returned and the error state remains set.

Parameters
expectederror which is expected
Returns
1 if the current error state equals the expected state, else 0, the error state is cleared when the expectation is met

Definition at line 148 of file error-state.c.

References lumiera_errorcontext::err, lumiera_error_get(), and NULL.

Referenced by Condition< MTX >::wait().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

pthread_key_t lumiera_error_tls
static

Definition at line 50 of file error-state.c.

Referenced by lumiera_error_get(), and lumiera_error_tls_init().

pthread_once_t lumiera_error_initialized
static

Definition at line 51 of file error-state.c.

Referenced by lumiera_error_get().