Support library for TESLA instrumentation.
Classes | |
struct | tesla_transition |
A single allowable transition in a TESLA automaton. More... | |
struct | tesla_transitions |
A set of permissible state transitions for an automata instance. More... | |
struct | tesla_key |
A TESLA instance can be identified by a tesla_class and a tesla_key. More... | |
struct | tesla_instance |
A single instance of an automaton: a name (ti_key) and a state. More... | |
struct | tesla_event_handlers |
A vector of event handlers. More... | |
struct | tesla_event_metahandler |
A 'meta-handler' that wraps a number of event handling vectors. More... | |
struct | tesla_class |
struct | tesla_store |
Macros | |
#define | TESLA_TRANS_INIT 0x02 /* May need to initialise the class. */ |
#define | TESLA_TRANS_CLEANUP 0x04 /* Clean up the class now. */ |
#define | TESLA_KEY_SIZE 4 |
#define | SUBSET(x, y) ((x & y) == x) |
Is x a subset of y? More... | |
#define | __unused |
#define | tesla_panic(...) errx(1, __VA_ARGS__) |
errx() is the userspace equivalent of panic(). More... | |
#define | tesla_assert(condition,...) assert(condition) |
POSIX assert() doesn't let us provide an error message. More... | |
#define | tesla_malloc(len) calloc(1, len) |
#define | tesla_free(x) free(x) |
#define | tesla_lock(l) do { __debug int err = pthread_mutex_lock(l); assert(err == 0); } while(0) |
#define | tesla_unlock(l) do { __debug int err = pthread_mutex_unlock(l); assert(err == 0); } while(0) |
#define | TESLA_MAX_CLASSES 128 |
#define | TESLA_MAX_INSTANCES 128 |
#define | SAFE_SPRINTF(current, end,...) |
Do a sprintf() into a buffer, checking bounds appropriately. More... | |
#define | print(...) printf(__VA_ARGS__) |
#define | error(...) fprintf(stderr, __VA_ARGS__) |
#define | __debug |
#define | DEBUG(dclass,...) if (tesla_debugging(#dclass)) printf(__VA_ARGS__) |
Emit debugging information with a debug name (e.g., libtesla.event). More... | |
Typedefs | |
typedef void(* | tesla_ev_new_instance )(struct tesla_class *, struct tesla_instance *) |
A new tesla_instance has been created. More... | |
typedef void(* | tesla_ev_transition )(struct tesla_class *, struct tesla_instance *, const struct tesla_transition *) |
A tesla_instance has taken a transition. More... | |
typedef void(* | tesla_ev_clone )(struct tesla_class *, struct tesla_instance *orig, struct tesla_instance *copy, const struct tesla_transition *) |
An exisiting tesla_instance has been cloned because of an event. More... | |
typedef void(* | tesla_ev_no_instance )(struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
No tesla_class instance was found to match a tesla_key. More... | |
typedef void(* | tesla_ev_bad_transition )(struct tesla_class *, struct tesla_instance *, const struct tesla_transitions *) |
A tesla_instance is not in the right state to take a transition. More... | |
typedef void(* | tesla_ev_error )(struct tesla_class *, int32_t, const char *) |
Generic error handler. More... | |
typedef void(* | tesla_ev_accept )(struct tesla_class *, struct tesla_instance *) |
A tesla_instance has accepted a sequence of events. More... | |
typedef void(* | tesla_ev_ignored )(const struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
An event is being ignored. More... | |
typedef struct tesla_class | tesla_class |
typedef struct tesla_instance | tesla_instance |
typedef struct tesla_key | tesla_key |
typedef struct tesla_store | tesla_store |
typedef struct tesla_transition | tesla_transition |
typedef struct tesla_transitions | tesla_transitions |
Enumerations | |
enum | tesla_err_t { TESLA_SUCCESS, TESLA_ERROR_ENOENT, TESLA_ERROR_ENOMEM, TESLA_ERROR_EINVAL, TESLA_ERROR_UNKNOWN } |
Error values that can be returned by libtesla functions. More... | |
enum | tesla_context { TESLA_CONTEXT_GLOBAL, TESLA_CONTEXT_THREAD } |
A context where TESLA data is stored. More... | |
enum | tesla_action_t { UPDATE, FORK, JOIN, IGNORE, FAIL } |
Actions that can be taken by tesla_update_state. More... | |
Functions | |
const char * | tesla_strerror (int32_t error) |
Provide string versions of TESLA errors. More... | |
int32_t | tesla_store_get (enum tesla_context context, uint32_t classes, uint32_t instances, struct tesla_store **store) |
Retrieve the tesla_store for a context (e.g., a thread). More... | |
int32_t | tesla_class_get (struct tesla_store *store, uint32_t id, struct tesla_class **tclass, const char *name, const char *description) |
Retrieve (or create) a tesla_class from a tesla_store. More... | |
void | tesla_class_put (struct tesla_class *) |
Release resources (e.g., locks) associated with a tesla_class. More... | |
void | tesla_update_state (enum tesla_context context, uint32_t class_id, const struct tesla_key *key, const char *name, const char *description, const struct tesla_transitions *) |
Update all automata instances that match a given key to a new state. More... | |
int | tesla_set_event_handler (struct tesla_event_handlers *) |
Register an event handler vector. More... | |
int | tesla_set_event_handlers (struct tesla_event_metahandler *) |
Register a set of event handling vectors. More... | |
void | tesla_die (int32_t errno, const char *event) __attribute__((noreturn)) |
Call this if things go catastrophically, unrecoverably wrong. More... | |
int32_t | tesla_store_reset (struct tesla_store *store) |
Reset all automata in a store to the inactive state. More... | |
void | tesla_store_free (struct tesla_store *) |
Clean up a tesla_store. More... | |
void | tesla_class_reset (struct tesla_class *) |
Reset a tesla_class for re-use from a clean state. More... | |
void | tesla_class_destroy (struct tesla_class *) |
Clean up a tesla_class. More... | |
int32_t | tesla_instance_new (struct tesla_class *tclass, const struct tesla_key *name, uint32_t state, struct tesla_instance **out) |
Create a new tesla_instance. More... | |
int32_t | tesla_instance_active (const struct tesla_instance *i) |
Checks whether or not a TESLA automata instance is active (in use). More... | |
int32_t | tesla_instance_clone (struct tesla_class *tclass, const struct tesla_instance *orig, struct tesla_instance **copy) |
Clone an existing instance into a new instance. More... | |
void | tesla_instance_clear (struct tesla_instance *tip) |
Zero an instance for re-use. More... | |
int32_t | tesla_match (struct tesla_class *tclass, const struct tesla_key *key, struct tesla_instance **array, uint32_t *size) |
Find all automata instances in a class that match a particular key. More... | |
int32_t | tesla_key_matches (const struct tesla_key *pattern, const struct tesla_key *k) |
Check to see if a key matches a pattern. More... | |
enum tesla_action_t | tesla_action (const struct tesla_instance *, const struct tesla_key *, const struct tesla_transitions *, const struct tesla_transition **trigger) |
What is the correct action to perform on a given tesla_instance to satisfy a set of tesla_transitions? More... | |
int32_t | tesla_key_union (struct tesla_key *dest, const struct tesla_key *source) |
Copy new entries from source into dest. More... | |
int | tesla_store_init (tesla_store *, enum tesla_context context, uint32_t classes, uint32_t instances) |
Initialise tesla_store internals. More... | |
int | tesla_class_init (struct tesla_class *, enum tesla_context context, uint32_t instances) |
Initialize tesla_class internals. More... | |
int32_t | tesla_class_global_postinit (struct tesla_class *) |
void | tesla_class_global_acquire (struct tesla_class *) |
void | tesla_class_global_release (struct tesla_class *) |
void | tesla_class_global_destroy (struct tesla_class *) |
int32_t | tesla_class_perthread_postinit (struct tesla_class *) |
void | tesla_class_perthread_acquire (struct tesla_class *) |
void | tesla_class_perthread_release (struct tesla_class *) |
void | tesla_class_perthread_destroy (struct tesla_class *) |
void | ev_new_instance (struct tesla_class *, struct tesla_instance *) |
void | ev_transition (struct tesla_class *, struct tesla_instance *, const struct tesla_transition *) |
void | ev_clone (struct tesla_class *, struct tesla_instance *orig, struct tesla_instance *copy, const struct tesla_transition *) |
void | ev_no_instance (struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
void | ev_bad_transition (struct tesla_class *, struct tesla_instance *, const struct tesla_transitions *) |
void | ev_err (struct tesla_class *tcp, int errno, const char *message) |
void | ev_accept (struct tesla_class *, struct tesla_instance *) |
void | ev_ignored (const struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
int32_t | tesla_debugging (const char *) |
Are we in (verbose) debug mode? More... | |
void | assert_instanceof (struct tesla_instance *i, struct tesla_class *tclass) |
Assert that a tesla_instance is an instance of a tesla_class. More... | |
char * | key_string (char *buffer, const char *end, const struct tesla_key *) |
Print a key into a buffer. More... | |
void | print_key (const char *debug_name, const struct tesla_key *key) |
Print a tesla_key to stderr. More... | |
void | print_class (const struct tesla_class *) |
Print a tesla_class to stderr. More... | |
void | print_transition (const char *debug, const struct tesla_transition *) |
Print a human-readable version of a tesla_transition. More... | |
char * | sprint_transition (char *buffer, const char *end, const struct tesla_transition *) |
Print a human-readable version of a tesla_transition into a buffer. More... | |
void | print_transitions (const char *debug, const struct tesla_transitions *) |
Print a human-readable version of tesla_transitions. More... | |
char * | sprint_transitions (char *buffer, const char *end, const struct tesla_transitions *) |
Print a human-readable version of tesla_transitions into a buffer. More... | |
struct tesla_transition |
struct tesla_transitions |
Class Members | ||
---|---|---|
uint32_t | length | The number of possible transitions in transitions. |
struct tesla_transition * | transitions | Possible transitions: exactly one must be taken. |
struct tesla_key |
struct tesla_instance |
struct tesla_event_handlers |
Class Members | ||
---|---|---|
tesla_ev_accept | teh_accept | |
tesla_ev_bad_transition | teh_bad_transition | |
tesla_ev_clone | teh_clone | |
tesla_ev_error | teh_err | |
tesla_ev_no_instance | teh_fail_no_instance | |
tesla_ev_ignored | teh_ignored | |
tesla_ev_new_instance | teh_init | |
tesla_ev_transition | teh_transition |
struct tesla_event_metahandler |
Class Members | ||
---|---|---|
struct tesla_event_handlers *const * |
tem_handlers | The backend event handlers. |
const uint32_t | tem_length | The number of event handlers wrapped by this handler. |
uint32_t | tem_mask | Which backend handlers to use; may be modified dynamically. |
struct tesla_class |
Class Members | ||
---|---|---|
enum tesla_context | tc_context | |
const char * | tc_description | |
uint32_t | tc_free | |
struct tesla_instance * | tc_instances | |
uint32_t | tc_limit | |
pthread_mutex_t | tc_lock | |
const char * | tc_name |
struct tesla_store |
#define __debug |
Definition at line 351 of file tesla_internal.h.
Referenced by pthread_key(), and tesla_store_get().
#define __unused |
Definition at line 187 of file tesla_internal.h.
#define DEBUG | ( | dclass, | |
... | |||
) | if (tesla_debugging(#dclass)) printf(__VA_ARGS__) |
Emit debugging information with a debug name (e.g., libtesla.event).
Definition at line 363 of file tesla_internal.h.
Referenced by tesla_class_reset(), and tesla_store_free().
#define error | ( | ... | ) | fprintf(stderr, __VA_ARGS__) |
Definition at line 346 of file tesla_internal.h.
Referenced by tesla_set_event_handler(), and tesla_set_event_handlers().
#define print | ( | ... | ) | printf(__VA_ARGS__) |
Definition at line 341 of file tesla_internal.h.
Referenced by print_class(), print_key(), print_transition(), and print_transitions().
#define SAFE_SPRINTF | ( | current, | |
end, | |||
... | |||
) |
Do a sprintf() into a buffer, checking bounds appropriately.
Definition at line 335 of file tesla_internal.h.
Referenced by key_string(), sprint_transition(), and sprint_transitions().
#define SUBSET | ( | x, | |
y | |||
) | ((x & y) == x) |
Is x a subset of y?
Definition at line 71 of file tesla_internal.h.
Referenced by tesla_action(), and tesla_key_matches().
#define tesla_assert | ( | condition, | |
... | |||
) | assert(condition) |
POSIX assert() doesn't let us provide an error message.
Definition at line 215 of file tesla_internal.h.
Referenced by assert_instanceof(), and tesla_instance_new().
#define tesla_free | ( | x | ) | free(x) |
Definition at line 218 of file tesla_internal.h.
Referenced by tesla_class_destroy(), and tesla_store_free().
#define TESLA_KEY_SIZE 4 |
Definition at line 173 of file libtesla.h.
Referenced by key_string(), tesla::KeyType(), print_key(), tesla_key_matches(), and tesla_key_union().
#define tesla_lock | ( | l | ) | do { __debug int err = pthread_mutex_lock(l); assert(err == 0); } while(0) |
Definition at line 220 of file tesla_internal.h.
Referenced by tesla_class_global_acquire().
#define tesla_malloc | ( | len | ) | calloc(1, len) |
Definition at line 217 of file tesla_internal.h.
Referenced by tesla_class_init(), tesla_store_get(), and tesla_store_init().
#define TESLA_MAX_CLASSES 128 |
Definition at line 286 of file tesla_internal.h.
Referenced by tesla_update_state().
#define TESLA_MAX_INSTANCES 128 |
Definition at line 287 of file tesla_internal.h.
Referenced by tesla_update_state().
#define tesla_panic | ( | ... | ) | errx(1, __VA_ARGS__) |
errx() is the userspace equivalent of panic().
Definition at line 212 of file tesla_internal.h.
Referenced by tesla_die().
#define TESLA_TRANS_CLEANUP 0x04 /* Clean up the class now. */ |
Definition at line 158 of file libtesla.h.
Referenced by sprint_transition(), tesla_action(), and tesla_update_state().
#define TESLA_TRANS_INIT 0x02 /* May need to initialise the class. */ |
Definition at line 157 of file libtesla.h.
Referenced by sprint_transition(), and tesla_update_state().
#define tesla_unlock | ( | l | ) | do { __debug int err = pthread_mutex_unlock(l); assert(err == 0); } while(0) |
Definition at line 223 of file tesla_internal.h.
Referenced by tesla_class_global_release().
typedef struct tesla_class tesla_class |
Definition at line 249 of file tesla_internal.h.
typedef void(* tesla_ev_accept)(struct tesla_class *, struct tesla_instance *) |
A tesla_instance has accepted a sequence of events.
Definition at line 237 of file libtesla.h.
typedef void(* tesla_ev_bad_transition)(struct tesla_class *, struct tesla_instance *, const struct tesla_transitions *) |
A tesla_instance is not in the right state to take a transition.
Definition at line 230 of file libtesla.h.
typedef void(* tesla_ev_clone)(struct tesla_class *, struct tesla_instance *orig, struct tesla_instance *copy, const struct tesla_transition *) |
An exisiting tesla_instance has been cloned because of an event.
Definition at line 221 of file libtesla.h.
typedef void(* tesla_ev_error)(struct tesla_class *, int32_t, const char *) |
Generic error handler.
Definition at line 234 of file libtesla.h.
typedef void(* tesla_ev_ignored)(const struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
An event is being ignored.
Definition at line 241 of file libtesla.h.
typedef void(* tesla_ev_new_instance)(struct tesla_class *, struct tesla_instance *) |
A new tesla_instance has been created.
Definition at line 213 of file libtesla.h.
typedef void(* tesla_ev_no_instance)(struct tesla_class *, const struct tesla_key *, const struct tesla_transitions *) |
No tesla_class instance was found to match a tesla_key.
Definition at line 226 of file libtesla.h.
typedef void(* tesla_ev_transition)(struct tesla_class *, struct tesla_instance *, const struct tesla_transition *) |
A tesla_instance has taken a transition.
Definition at line 217 of file libtesla.h.
typedef struct tesla_instance tesla_instance |
Definition at line 250 of file tesla_internal.h.
Definition at line 251 of file tesla_internal.h.
typedef struct tesla_store tesla_store |
Definition at line 252 of file tesla_internal.h.
typedef struct tesla_transition tesla_transition |
Definition at line 253 of file tesla_internal.h.
typedef struct tesla_transitions tesla_transitions |
Definition at line 254 of file tesla_internal.h.
enum tesla_action_t |
Actions that can be taken by tesla_update_state.
Definition at line 152 of file tesla_internal.h.
enum tesla_context |
A context where TESLA data is stored.
TESLA data can be stored in a number of places that imply different synchronisation requirements. For instance, thread-local storage does not require synchronisation on access, whereas global storage does. On the other hand, thread-local storage cannot be used to track events across multiple threads.
Enumerator | |
---|---|
TESLA_CONTEXT_GLOBAL | |
TESLA_CONTEXT_THREAD |
Definition at line 86 of file libtesla.h.
enum tesla_err_t |
Error values that can be returned by libtesla functions.
libtesla functions mostly return error values, and therefore return pointers, etc, via call-by-reference arguments.
Enumerator | |
---|---|
TESLA_SUCCESS | |
TESLA_ERROR_ENOENT | |
TESLA_ERROR_ENOMEM | |
TESLA_ERROR_EINVAL | |
TESLA_ERROR_UNKNOWN |
Definition at line 55 of file libtesla.h.
void assert_instanceof | ( | struct tesla_instance * | i, |
struct tesla_class * | tclass | ||
) |
Assert that a tesla_instance is an instance of a tesla_class.
This could be expensive (a linear walk over all tesla_instance in tclass), so it should only be called from debug code.
i | the instance to test |
tclass | the expected class of i |
Definition at line 181 of file tesla_debug.c.
References tesla_class::tc_instances, tesla_class::tc_limit, tesla_class::tc_name, and tesla_assert.
void ev_accept | ( | struct tesla_class * | , |
struct tesla_instance * | |||
) |
Definition at line 161 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_bad_transition | ( | struct tesla_class * | , |
struct tesla_instance * | , | ||
const struct tesla_transitions * | |||
) |
Definition at line 146 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_clone | ( | struct tesla_class * | , |
struct tesla_instance * | orig, | ||
struct tesla_instance * | copy, | ||
const struct tesla_transition * | |||
) |
Definition at line 130 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_err | ( | struct tesla_class * | tcp, |
int | errno, | ||
const char * | message | ||
) |
Definition at line 154 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_ignored | ( | const struct tesla_class * | , |
const struct tesla_key * | , | ||
const struct tesla_transitions * | |||
) |
Definition at line 168 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_new_instance | ( | struct tesla_class * | , |
struct tesla_instance * | |||
) |
Definition at line 115 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_no_instance | ( | struct tesla_class * | , |
const struct tesla_key * | , | ||
const struct tesla_transitions * | |||
) |
Definition at line 138 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
void ev_transition | ( | struct tesla_class * | , |
struct tesla_instance * | , | ||
const struct tesla_transition * | |||
) |
Definition at line 122 of file tesla_notification.c.
References FOREACH_ERROR_HANDLER.
Referenced by tesla_update_state().
char* key_string | ( | char * | buffer, |
const char * | end, | ||
const struct tesla_key * | |||
) |
Print a key into a buffer.
Definition at line 111 of file tesla_debug.c.
References SAFE_SPRINTF, TESLA_KEY_SIZE, tesla_key::tk_keys, and tesla_key::tk_mask.
Referenced by print_key().
void print_class | ( | const struct tesla_class * | ) |
Print a tesla_class to stderr.
Definition at line 201 of file tesla_debug.c.
References DEBUG_NAME, print, print_key(), TESLA_CONTEXT_GLOBAL, TESLA_CONTEXT_THREAD, tesla_debugging(), tesla_instance_active(), tesla_instance::ti_key, and tesla_instance::ti_state.
Referenced by tesla_update_state().
void print_key | ( | const char * | debug_name, |
const struct tesla_key * | key | ||
) |
Print a tesla_key to stderr.
Definition at line 234 of file tesla_debug.c.
References key_string(), print, tesla_debugging(), and TESLA_KEY_SIZE.
Referenced by print_class(), and tesla_update_state().
void print_transition | ( | const char * | debug, |
const struct tesla_transition * | |||
) |
Print a human-readable version of a tesla_transition.
Definition at line 44 of file tesla_debug.c.
References print, sprint_transition(), and tesla_debugging().
void print_transitions | ( | const char * | debug, |
const struct tesla_transitions * | |||
) |
Print a human-readable version of tesla_transitions.
Definition at line 82 of file tesla_debug.c.
References print, sprint_transitions(), and tesla_debugging().
Referenced by tesla_update_state().
char* sprint_transition | ( | char * | buffer, |
const char * | end, | ||
const struct tesla_transition * | |||
) |
Print a human-readable version of a tesla_transition into a buffer.
Definition at line 57 of file tesla_debug.c.
References tesla_transition::flags, tesla_transition::from, tesla_transition::from_mask, SAFE_SPRINTF, TESLA_TRANS_CLEANUP, TESLA_TRANS_INIT, tesla_transition::to, and tesla_transition::to_mask.
Referenced by print_transition(), and sprint_transitions().
char* sprint_transitions | ( | char * | buffer, |
const char * | end, | ||
const struct tesla_transitions * | |||
) |
Print a human-readable version of tesla_transitions into a buffer.
Definition at line 95 of file tesla_debug.c.
References tesla_transitions::length, SAFE_SPRINTF, sprint_transition(), and tesla_transitions::transitions.
Referenced by print_transitions().
enum tesla_action_t tesla_action | ( | const struct tesla_instance * | , |
const struct tesla_key * | , | ||
const struct tesla_transitions * | , | ||
const struct tesla_transition ** | trigger | ||
) |
What is the correct action to perform on a given tesla_instance to satisfy a set of tesla_transitions?
[out] | trigger | the tesla_transition that triggered the action |
Referenced by tesla_update_state().
void tesla_class_destroy | ( | struct tesla_class * | ) |
Clean up a tesla_class.
Definition at line 77 of file tesla_class.c.
References tesla_class_global_destroy(), tesla_class_perthread_destroy(), TESLA_CONTEXT_GLOBAL, TESLA_CONTEXT_THREAD, and tesla_free.
Referenced by tesla_store_free().
int32_t tesla_class_get | ( | struct tesla_store * | store, |
uint32_t | id, | ||
struct tesla_class ** | tclass, | ||
const char * | name, | ||
const char * | description | ||
) |
Retrieve (or create) a tesla_class from a tesla_store.
Once the caller is done with the tesla_class, tesla_class_put must be called.
[in] | store | where the tesla_class is expected to be stored |
[in] | id | a client-generated handle (a small integer, used as an index into an array) |
[out] | tclass | the retrieved (or generated) tesla_class; only set if function returns TESLA_SUCCESS |
[in] | name | a user-readable name (e.g. an automata filename) |
[in] | description | a user-readable description (for error messages) |
Definition at line 155 of file tesla_store.c.
References tesla_store::classes, tesla_store::length, tesla_class::tc_context, tesla_class::tc_description, tesla_class::tc_instances, tesla_class::tc_name, TESLA_ERROR_EINVAL, and TESLA_SUCCESS.
Referenced by tesla_update_state().
void tesla_class_global_acquire | ( | struct tesla_class * | ) |
Definition at line 49 of file tesla_class_global.c.
References tesla_class::tc_context, tesla_class::tc_lock, TESLA_CONTEXT_GLOBAL, and tesla_lock.
void tesla_class_global_destroy | ( | struct tesla_class * | ) |
Definition at line 65 of file tesla_class_global.c.
Referenced by tesla_class_destroy().
int32_t tesla_class_global_postinit | ( | struct tesla_class * | ) |
Definition at line 40 of file tesla_class_global.c.
References tesla_class::tc_context, TESLA_CONTEXT_GLOBAL, and TESLA_SUCCESS.
Referenced by tesla_class_init().
void tesla_class_global_release | ( | struct tesla_class * | ) |
Definition at line 57 of file tesla_class_global.c.
References tesla_class::tc_context, tesla_class::tc_lock, TESLA_CONTEXT_GLOBAL, and tesla_unlock.
Referenced by tesla_class_put().
int tesla_class_init | ( | struct tesla_class * | , |
enum tesla_context | context, | ||
uint32_t | instances | ||
) |
Initialize tesla_class internals.
Locking is the responsibility of the caller.
Definition at line 46 of file tesla_class.c.
References tesla_class::tc_context, tesla_class::tc_free, tesla_class::tc_instances, tesla_class::tc_limit, tesla_class_global_postinit(), tesla_class_perthread_postinit(), TESLA_CONTEXT_GLOBAL, TESLA_CONTEXT_THREAD, TESLA_ERROR_UNKNOWN, and tesla_malloc.
Referenced by tesla_store_init().
void tesla_class_perthread_acquire | ( | struct tesla_class * | ) |
Definition at line 101 of file tesla_class_perthread.c.
void tesla_class_perthread_destroy | ( | struct tesla_class * | ) |
Definition at line 111 of file tesla_class_perthread.c.
Referenced by tesla_class_destroy().
int32_t tesla_class_perthread_postinit | ( | struct tesla_class * | ) |
Definition at line 95 of file tesla_class_perthread.c.
Referenced by tesla_class_init().
void tesla_class_perthread_release | ( | struct tesla_class * | ) |
Definition at line 106 of file tesla_class_perthread.c.
Referenced by tesla_class_put().
void tesla_class_put | ( | struct tesla_class * | ) |
Release resources (e.g., locks) associated with a tesla_class.
Definition at line 181 of file tesla_class.c.
References tesla_class::tc_context, tesla_class_global_release(), tesla_class_perthread_release(), TESLA_CONTEXT_GLOBAL, and TESLA_CONTEXT_THREAD.
Referenced by tesla_update_state().
void tesla_class_reset | ( | struct tesla_class * | ) |
Reset a tesla_class for re-use from a clean state.
Definition at line 196 of file tesla_class.c.
References DEBUG, tesla_class::tc_free, tesla_class::tc_instances, tesla_class::tc_limit, and tesla_class::tc_name.
Referenced by tesla_update_state().
int32_t tesla_debugging | ( | const char * | ) |
Are we in (verbose) debug mode?
Definition at line 132 of file tesla_debug.c.
References strnlen.
Referenced by print_class(), print_key(), print_transition(), print_transitions(), and tesla_update_state().
void tesla_die | ( | int32_t | errno, |
const char * | event | ||
) |
Call this if things go catastrophically, unrecoverably wrong.
Definition at line 38 of file tesla_util.c.
References tesla_panic, and tesla_strerror().
int32_t tesla_instance_active | ( | const struct tesla_instance * | i | ) |
Checks whether or not a TESLA automata instance is active (in use).
i | pointer to a valid tesla_instance |
Definition at line 123 of file tesla_class.c.
References tesla_instance::ti_key, tesla_instance::ti_state, and tesla_key::tk_mask.
Referenced by print_class(), tesla_action(), tesla_instance_clear(), tesla_instance_new(), tesla_match(), and tesla_update_state().
void tesla_instance_clear | ( | struct tesla_instance * | tip | ) |
Zero an instance for re-use.
Definition at line 173 of file tesla_class.c.
References tesla_instance_active().
Referenced by tesla_update_state().
int32_t tesla_instance_clone | ( | struct tesla_class * | tclass, |
const struct tesla_instance * | orig, | ||
struct tesla_instance ** | copy | ||
) |
Clone an existing instance into a new instance.
Definition at line 166 of file tesla_class.c.
References tesla_instance_new(), tesla_instance::ti_key, and tesla_instance::ti_state.
Referenced by tesla_update_state().
int32_t tesla_instance_new | ( | struct tesla_class * | tclass, |
const struct tesla_key * | name, | ||
uint32_t | state, | ||
struct tesla_instance ** | out | ||
) |
Create a new tesla_instance.
The caller is responsible for locking the class if needed.
Definition at line 132 of file tesla_class.c.
References tesla_class::tc_free, tesla_class::tc_instances, tesla_class::tc_limit, tesla_assert, TESLA_ERROR_EINVAL, TESLA_ERROR_ENOMEM, tesla_instance_active(), TESLA_SUCCESS, tesla_instance::ti_key, tesla_instance::ti_state, and tesla_key::tk_mask.
Referenced by tesla_instance_clone(), and tesla_update_state().
Check to see if a key matches a pattern.
Definition at line 44 of file tesla_key.c.
References SUBSET, TESLA_KEY_SIZE, tesla_key::tk_keys, and tesla_key::tk_mask.
Referenced by tesla_action(), and tesla_match().
Copy new entries from source into dest.
Referenced by tesla_update_state().
int32_t tesla_match | ( | struct tesla_class * | tclass, |
const struct tesla_key * | key, | ||
struct tesla_instance ** | array, | ||
uint32_t * | size | ||
) |
Find all automata instances in a class that match a particular key.
The caller is responsible for locking the class if necessary.
[in] | tclass | the class of automata to match |
[in] | key | must remain valid as long as the iterator is in use |
[out] | array | a caller-allocated array to store matches in |
[in,out] | size | in: size of array. out: number of instances. |
Definition at line 93 of file tesla_class.c.
References tesla_class::tc_instances, tesla_class::tc_limit, TESLA_ERROR_ENOMEM, tesla_instance_active(), tesla_key_matches(), TESLA_SUCCESS, and tesla_instance::ti_key.
int tesla_set_event_handler | ( | struct tesla_event_handlers * | ) |
Register an event handler vector.
Definition at line 59 of file tesla_notification.c.
References error, tesla_event_metahandler::tem_length, and TESLA_SUCCESS.
int tesla_set_event_handlers | ( | struct tesla_event_metahandler * | ) |
Register a set of event handling vectors.
Definition at line 79 of file tesla_notification.c.
References error, tesla_event_metahandler::tem_handlers, tesla_event_metahandler::tem_length, TESLA_ERROR_EINVAL, and TESLA_SUCCESS.
void tesla_store_free | ( | struct tesla_store * | ) |
Clean up a tesla_store.
Definition at line 143 of file tesla_store.c.
References tesla_store::classes, DEBUG, tesla_store::length, tesla_class_destroy(), and tesla_free.
Referenced by tesla_pthread_destructor().
int32_t tesla_store_get | ( | enum tesla_context | context, |
uint32_t | classes, | ||
uint32_t | instances, | ||
struct tesla_store ** | store | ||
) |
Retrieve the tesla_store for a context (e.g., a thread).
If the tesla_store does not exist yet, it will be created.
[in] | context | TESLA_CONTEXT_THREAD or TESLA_CONTEXT_GLOBAL |
[in] | classes | number of tesla_class'es to expect |
[in] | instances | tesla_instance count per tesla_class |
[out] | store | return parameter for tesla_store pointer |
Definition at line 65 of file tesla_store.c.
References __debug, tesla_store::classes, tesla_store::length, pthread_key(), TESLA_CONTEXT_GLOBAL, TESLA_CONTEXT_THREAD, TESLA_ERROR_EINVAL, tesla_malloc, tesla_store_init(), and TESLA_SUCCESS.
Referenced by tesla_update_state().
int tesla_store_init | ( | tesla_store * | , |
enum tesla_context | context, | ||
uint32_t | classes, | ||
uint32_t | instances | ||
) |
Initialise tesla_store internals.
Locking is the responsibility of the caller.
Definition at line 117 of file tesla_store.c.
References tesla_store::classes, tesla_store::length, tesla_class::tc_context, tesla_class_init(), TESLA_ERROR_ENOMEM, tesla_malloc, and TESLA_SUCCESS.
Referenced by tesla_store_get().
int32_t tesla_store_reset | ( | struct tesla_store * | store | ) |
Reset all automata in a store to the inactive state.
const char* tesla_strerror | ( | int32_t | error | ) |
Provide string versions of TESLA errors.
Referenced by tesla_die().
void tesla_update_state | ( | enum tesla_context | context, |
uint32_t | class_id, | ||
const struct tesla_key * | key, | ||
const char * | name, | ||
const char * | description, | ||
const struct tesla_transitions * | |||
) |
Update all automata instances that match a given key to a new state.