Computer Laboratory

Detailed Description

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...
 

Class Documentation

struct tesla_transition
+ Collaboration diagram for tesla_transition:
Class Members
int flags Things we may need to do on this transition.
uint32_t from The state we are moving from.
uint32_t from_mask The mask of the state we're moving from.
uint32_t to The state we are moving to.
uint32_t to_mask A mask of the keys that the 'to' state should have set.
struct tesla_transitions
+ Collaboration diagram for 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
+ Collaboration diagram for tesla_key:
Class Members
uintptr_t tk_keys[4] The keys / event parameters that name this automata instance.
uint32_t tk_mask A bitmask of the keys that are actually set.
struct tesla_instance
+ Collaboration diagram for tesla_instance:
Class Members
struct tesla_key ti_key
uint32_t ti_state
struct tesla_event_handlers
+ Collaboration diagram for 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
+ Collaboration diagram for 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
+ Collaboration diagram for 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
+ Collaboration diagram for tesla_store:
Class Members
struct tesla_class * classes
uint32_t length

Macro Definition Documentation

#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,
  ... 
)
Value:
do { \
int written = snprintf(current, end - current, __VA_ARGS__); \
if ((written > 0) && (current + written < end)) \
current += written; \
} while (0)

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,
 
)    ((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 Documentation

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.

Definition at line 250 of file tesla_internal.h.

typedef struct tesla_key tesla_key

Definition at line 251 of file tesla_internal.h.

typedef struct tesla_store tesla_store

Definition at line 252 of file tesla_internal.h.

Definition at line 253 of file tesla_internal.h.

Definition at line 254 of file tesla_internal.h.

Enumeration Type Documentation

Actions that can be taken by tesla_update_state.

Enumerator
UPDATE 

The instance's state should be updated.

FORK 

The instance should be copied to a new instance.

JOIN 

The instance should be merged into another instance.

IGNORE 

The instance is irrelevant to the given transitions.

FAIL 

The instance matches, but there are no valid transitions for it.

Definition at line 152 of file tesla_internal.h.

152  {
154  UPDATE,
155 
157  FORK,
158 
160  JOIN,
161 
163  IGNORE,
164 
166  FAIL
167 };

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.

86  {
89 };

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.

55  {
56  TESLA_SUCCESS, /* Success. */
57  TESLA_ERROR_ENOENT, /* Entry not found. */
58  TESLA_ERROR_ENOMEM, /* Insufficient memory. */
59  TESLA_ERROR_EINVAL, /* Invalid parameters. */
60  TESLA_ERROR_UNKNOWN, /* An unknown (e.g. platform) error. */
61 };

Function Documentation

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.

Parameters
ithe instance to test
tclassthe 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.

182 {
183  assert(instance != NULL);
184  assert(tclass != NULL);
185 
186  int32_t instance_belongs_to_class = 0;
187  for (uint32_t i = 0; i < tclass->tc_limit; i++) {
188  if (instance == &tclass->tc_instances[i]) {
189  instance_belongs_to_class = 1;
190  break;
191  }
192  }
193 
194  tesla_assert(instance_belongs_to_class,
195  ("tesla_instance %x not of class '%s'",
196  instance, tclass->tc_name)
197  );
198 }
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().

162 {
163 
164  FOREACH_ERROR_HANDLER()->teh_accept(tcp, tip);
165 }

+ Here is the caller graph for this function:

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().

148 {
149 
150  FOREACH_ERROR_HANDLER()->teh_bad_transition(tcp, tip, ttp);
151 }

+ Here is the caller graph for this function:

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().

132 {
133 
134  FOREACH_ERROR_HANDLER()->teh_clone(tcp, orig, copy, ttp);
135 }

+ Here is the caller graph for this function:

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().

155 {
156 
157  FOREACH_ERROR_HANDLER()->teh_err(tcp, errno, message);
158 }

+ Here is the caller graph for this function:

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().

170 {
171 
172  FOREACH_ERROR_HANDLER()->teh_ignored(tcp, tkp, ttp);
173 }

+ Here is the caller graph for this function:

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().

116 {
117 
118  FOREACH_ERROR_HANDLER()->teh_init(tcp, tip);
119 }

+ Here is the caller graph for this function:

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().

140 {
141 
142  FOREACH_ERROR_HANDLER()->teh_fail_no_instance(tcp, tkp, ttp);
143 }

+ Here is the caller graph for this function:

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().

124 {
125 
126  FOREACH_ERROR_HANDLER()->teh_transition(tcp, tip, ttp);
127 }

+ Here is the caller graph for this function:

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().

112 {
113  char *c = buffer;
114 
115  SAFE_SPRINTF(c, end, "0x%tx [ ", key->tk_mask);
116 
117  for (int32_t i = 0; i < TESLA_KEY_SIZE; i++) {
118  if (key->tk_mask & (1 << i))
119  SAFE_SPRINTF(c, end, "%tx ", key->tk_keys[i]);
120  else
121  SAFE_SPRINTF(c, end, "X ");
122  }
123 
124  SAFE_SPRINTF(c, end, "]");
125 
126  return c;
127 }

+ Here is the caller graph for this function:

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().

202 {
203  static const char *DEBUG_NAME = "libtesla.class.state";
204  if (!tesla_debugging(DEBUG_NAME))
205  return;
206 
207  print("----\n");
208  print("struct tesla_class @ 0x%tx {\n", (intptr_t) c);
209  print(" name: '%s',\n", c->tc_name);
210  print(" description: '[...]',\n"); // TL;DR
211  print(" scope: ");
212  switch (c->tc_context) {
213  case TESLA_CONTEXT_THREAD: print("thread-local\n"); break;
214  case TESLA_CONTEXT_GLOBAL: print("global\n"); break;
215  default:
216  print("UNKNOWN (0x%x)\n", c->tc_context);
217  }
218  print(" limit: %d\n", c->tc_limit);
219  print(" %d/%d instances\n", c->tc_limit - c->tc_free, c->tc_limit);
220  for (uint32_t i = 0; i < c->tc_limit; i++) {
221  const struct tesla_instance *inst = c->tc_instances + i;
222  if (!tesla_instance_active(inst))
223  continue;
224 
225  print(" %2u: state %d, ", i, inst->ti_state);
226  print_key(DEBUG_NAME, &inst->ti_key);
227  print("\n");
228  }
229  print("}\n");
230  print("----\n");
231 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

235 {
236  if (!tesla_debugging(debug_name))
237  return;
238 
239  static const size_t LEN = 15 * TESLA_KEY_SIZE + 10;
240  char buffer[LEN];
241  char *end = buffer + LEN;
242 
243  char *e = key_string(buffer, end, key);
244  assert(e < end);
245 
246  print("%s", buffer);
247 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

45 {
46  if (!tesla_debugging(debug))
47  return;
48 
49  char buffer[1024];
50  char *end = buffer + sizeof(buffer);
51 
52  sprint_transition(buffer, end, t);
53  print("%s", buffer);
54 }

+ Here is the call graph for this function:

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().

83 {
84  if (!tesla_debugging(debug))
85  return;
86 
87  char buffer[1024];
88  char *end = buffer + sizeof(buffer);
89 
90  sprint_transitions(buffer, end, transp);
91  print("%s", buffer);
92 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

58 {
59  char *c = buf;
60 
61  /* Note: On at least one Mac, combining the following
62  * into a single snprintf() causes the wrong thing
63  * to be printed (instead of t->mask, we get an address!).
64  */
65  SAFE_SPRINTF(c, end, "(%d:", t->from);
66  SAFE_SPRINTF(c, end, "0x%tx", t->from_mask);
67  SAFE_SPRINTF(c, end, " -> %d:", t->to);
68  SAFE_SPRINTF(c, end, "0x%tx", t->to_mask);
69 
70  if (t->flags & TESLA_TRANS_INIT)
71  SAFE_SPRINTF(c, end, " <init>");
72 
73  if (t->flags & TESLA_TRANS_CLEANUP)
74  SAFE_SPRINTF(c, end, " <clean>");
75 
76  SAFE_SPRINTF(c, end, ") ");
77 
78  return c;
79 }

+ Here is the caller graph for this function:

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().

97 {
98  char *c = buffer;
99 
100  SAFE_SPRINTF(c, end, "[ ");
101 
102  for (size_t i = 0; i < tp->length; i++)
103  c = sprint_transition(c, end, tp->transitions + i);
104 
105  SAFE_SPRINTF(c, end, "]");
106 
107  return c;
108 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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?

Parameters
[out]triggerthe tesla_transition that triggered the action

Referenced by tesla_update_state().

+ Here is the caller graph for this function:

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().

78 {
79  tesla_free(class->tc_instances);
80  switch (class->tc_context) {
83  break;
84 
87  break;
88  }
89 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Parameters
[in]storewhere the tesla_class is expected to be stored
[in]ida client-generated handle (a small integer, used as an index into an array)
[out]tclassthe retrieved (or generated) tesla_class; only set if function returns TESLA_SUCCESS
[in]namea user-readable name (e.g. an automata filename)
[in]descriptiona user-readable description (for error messages)
Returns
a TESLA error code (TESLA_SUCCESS, TESLA_ERROR_EINVAL, etc.)

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().

157 {
158  assert(store != NULL);
159  assert(tclassp != NULL);
160 
161  if (id >= store->length)
162  return (TESLA_ERROR_EINVAL);
163 
164  tesla_class *tclass = &store->classes[id];
165  assert(tclass != NULL);
166  assert(tclass->tc_instances != NULL);
167  assert(tclass->tc_context >= 0);
168 
169  if (tclass->tc_name == NULL) tclass->tc_name = name;
170  if (tclass->tc_description == NULL)
171  tclass->tc_description = description;
172 
173  tesla_class_acquire(tclass);
174 
175  *tclassp = tclass;
176  return (TESLA_SUCCESS);
177 }

+ Here is the caller graph for this function:

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.

50 {
51 
52  assert(tsp->tc_context == TESLA_CONTEXT_GLOBAL);
53  tesla_lock(&tsp->tc_lock);
54 }
void tesla_class_global_destroy ( struct tesla_class )

Definition at line 65 of file tesla_class_global.c.

Referenced by tesla_class_destroy().

66 {
67 
68  tesla_class_global_lock_destroy(tsp);
69 }

+ Here is the caller graph for this function:

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().

41 {
42 
43  assert(tsp->tc_context == TESLA_CONTEXT_GLOBAL);
44  tesla_class_global_lock_init(tsp);
45  return (TESLA_SUCCESS);
46 }

+ Here is the caller graph for this function:

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().

58 {
59 
60  assert(tsp->tc_context == TESLA_CONTEXT_GLOBAL);
61  tesla_unlock(&tsp->tc_lock);
62 }

+ Here is the caller graph for this function:

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().

48 {
49  assert(tclass != NULL);
50  assert(context >= 0);
51  assert(instances > 0);
52  // TODO: write a TESLA assertion about locking here.
53 
54  tclass->tc_limit = instances;
55 
56  tclass->tc_context = context;
57  tclass->tc_limit = instances;
58  tclass->tc_free = instances;
59  tclass->tc_instances =
60  tesla_malloc(instances * sizeof(tclass->tc_instances[0]));
61 
62  switch (context) {
64  return tesla_class_global_postinit(tclass);
65 
67  return tesla_class_perthread_postinit(tclass);
68 
69  default:
70  assert(0 && "unhandled TESLA context");
71  return (TESLA_ERROR_UNKNOWN);
72  }
73 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void tesla_class_perthread_acquire ( struct tesla_class )

Definition at line 101 of file tesla_class_perthread.c.

102 {
103 }
void tesla_class_perthread_destroy ( struct tesla_class )

Definition at line 111 of file tesla_class_perthread.c.

Referenced by tesla_class_destroy().

112 {
113 }

+ Here is the caller graph for this function:

int32_t tesla_class_perthread_postinit ( struct tesla_class )

Definition at line 95 of file tesla_class_perthread.c.

Referenced by tesla_class_init().

96 {
97  return 0;
98 }

+ Here is the caller graph for this function:

void tesla_class_perthread_release ( struct tesla_class )

Definition at line 106 of file tesla_class_perthread.c.

Referenced by tesla_class_put().

107 {
108 }

+ Here is the caller graph for this function:

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().

182 {
183  switch (tsp->tc_context) {
185  return tesla_class_global_release(tsp);
186 
188  return tesla_class_perthread_release(tsp);
189 
190  default:
191  assert(0 && "unhandled TESLA context");
192  }
193 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

197 {
198 
199  DEBUG(libtesla.class.reset, "tesla_class_reset %s\n", c->tc_name);
200 
201  bzero(c->tc_instances, sizeof(c->tc_instances[0]) * c->tc_limit);
202  c->tc_free = c->tc_limit;
203 }

+ Here is the caller graph for this function:

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().

133 {
134 #ifdef _KERNEL
135  /*
136  * In the kernel, only print 'libtesla.{event,instance}*' output.
137  */
138  static const char* allowed[] = {
139  "libtesla.event",
140  "libtesla.instance",
141  NULL,
142  };
143  const size_t len = sizeof(allowed) / sizeof(allowed[0]);
144 
145  for (size_t i = 0; (i < len) && (allowed[i] != NULL); i++) {
146  const char *s = allowed[i];
147  const size_t len = strlen(s);
148 
149  if (strncmp(s, name, len) == 0)
150  return 1;
151  }
152 
153  return 0;
154 #else
155 #ifdef HAVE_ISSETUGID
156  /*
157  * Debugging paths could be more vulnerable to format string problems
158  * than other code; don't allow when running setuid or setgid.
159  */
160  if (issetugid())
161  return 0;
162 #endif
163 
164  const char *env = getenv("TESLA_DEBUG");
165 
166  /* If TESLA_DEBUG is not set, we're definitely not debugging. */
167  if (env == NULL)
168  return 0;
169 
170  /* Allow e.g. 'libtesla' to match 'libtesla.foo'. */
171  size_t envlen = strnlen(env, 100);
172  if ((strncmp(env, name, envlen) == 0) && (name[envlen] == '.'))
173  return 1;
174 
175  /* Otherwise, use fnmatch's normal star-matching. */
176  return (fnmatch(env, name, 0) == 0);
177 #endif
178 }

+ Here is the caller graph for this function:

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().

39 {
40 
41  tesla_panic("tesla_die: fatal error in event '%s'; %s\n",
42  event, tesla_strerror(code));
43 }

+ Here is the call graph for this function:

int32_t tesla_instance_active ( const struct tesla_instance i)

Checks whether or not a TESLA automata instance is active (in use).

Parameters
ipointer to a valid tesla_instance
Returns
1 if active, 0 if inactive

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().

124 {
125  assert(i != NULL);
126 
127  return ((i->ti_state != 0) || (i->ti_key.tk_mask != 0));
128 }

+ Here is the caller graph for this function:

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().

174 {
175 
176  bzero(tip, sizeof(*tip));
177  assert(!tesla_instance_active(tip));
178 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

168 {
169  return tesla_instance_new(tclass, &orig->ti_key, orig->ti_state, copy);
170 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

134 {
135  assert(tclass != NULL);
136  assert(name != NULL);
137  assert(out != NULL);
138 
139  // A new instance must not look inactive.
140  if ((state == 0) && (name->tk_mask == 0))
141  return (TESLA_ERROR_EINVAL);
142 
143  if (tclass->tc_free == 0)
144  return (TESLA_ERROR_ENOMEM);
145 
146  for (uint32_t i = 0; i < tclass->tc_limit; i++) {
147  struct tesla_instance *inst = tclass->tc_instances + i;
148  if (tesla_instance_active(inst))
149  continue;
150 
151  // Initialise the new instance.
152  inst->ti_key = *name;
153  inst->ti_state = state;
154 
155  tclass->tc_free--;
156  *out = inst;
157 
158  return (TESLA_SUCCESS);
159  }
160 
161  tesla_assert(*out != NULL, ("no free instances but tc_free was > 0"));
162  return (TESLA_ERROR_ENOMEM);
163 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32_t tesla_key_matches ( const struct tesla_key pattern,
const struct tesla_key k 
)

Check to see if a key matches a pattern.

Returns
1 if k matches pattern, 0 otherwise

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().

45 {
46  assert(pattern != NULL);
47  assert(k != NULL);
48 
49  // The pattern's mask must be a subset of the target's (ANY matches
50  // 42 but not the other way around).
51  if (!SUBSET(pattern->tk_mask, k->tk_mask))
52  return (0);
53 
54  for (uint32_t i = 0; i < TESLA_KEY_SIZE; i++) {
55  // Only check keys specified by the bitmasks.
56  uint32_t mask = (1 << i);
57  if ((pattern->tk_mask & mask) != mask)
58  continue;
59 
60  // A non-match of any sub-key implies a non-match of the key.
61  if (pattern->tk_keys[i] != k->tk_keys[i])
62  return (0);
63  }
64 
65  return (1);
66 }

+ Here is the caller graph for this function:

int32_t tesla_key_union ( struct tesla_key dest,
const struct tesla_key source 
)

Copy new entries from source into dest.

Referenced by tesla_update_state().

+ Here is the caller graph for this function:

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.

Parameters
[in]tclassthe class of automata to match
[in]keymust remain valid as long as the iterator is in use
[out]arraya caller-allocated array to store matches in
[in,out]sizein: size of array. out: number of instances.
Returns
a standard TESLA error code (e.g., TESLA_ERROR_ENOMEM)

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.

95 {
96  assert(tclass != NULL);
97  assert(pattern != NULL);
98  assert(array != NULL);
99  assert(size != NULL);
100 
101  // Assume that any and every instance could match.
102  if (*size < tclass->tc_limit) {
103  *size = tclass->tc_limit;
104  return (TESLA_ERROR_ENOMEM);
105  }
106 
107  // Copy matches into the array.
108  *size = 0;
109  for (uint32_t i = 0; i < tclass->tc_limit; i++) {
110  struct tesla_instance *inst = tclass->tc_instances + i;
111  if (tesla_instance_active(inst)
112  && tesla_key_matches(pattern, &inst->ti_key)) {
113  array[*size] = inst;
114  *size += 1;
115  }
116  }
117 
118  return (TESLA_SUCCESS);
119 }

+ Here is the call graph for this function:

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.

60 {
61  int error = check_event_handler(tehp);
62  if (error != TESLA_SUCCESS)
63  return (error);
64 
65  const static struct tesla_event_handlers* singleton[1];
66  static struct tesla_event_metahandler singleton_handler = {
67  .tem_length = 1,
68  .tem_mask = 1,
69  .tem_handlers = singleton,
70  };
71 
72  singleton[0] = tehp;
73  event_handlers = &singleton_handler;
74 
75  return (TESLA_SUCCESS);
76 }
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.

80 {
81  int error = TESLA_SUCCESS;
82 
83  if (!temp)
84  return (TESLA_ERROR_EINVAL);
85 
86  /*
87  * It's ok to disable event handlers dynamically using the bitmask,
88  * but all event handlers passed in must be valid.
89  */
90  for (uint32_t i = 0; i < temp->tem_length; i++) {
91  error = check_event_handler(temp->tem_handlers[i]);
92  if (error != TESLA_SUCCESS)
93  return (error);
94  }
95 
96  event_handlers = temp;
97  return (TESLA_SUCCESS);
98 }
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().

144 {
145  DEBUG(libtesla.store.free, "tesla_store_free %tx\n", store);
146 
147  for (uint32_t i = 0; i < store->length; i++)
148  tesla_class_destroy(store->classes + i);
149 
150  tesla_free(store);
151 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Parameters
[in]contextTESLA_CONTEXT_THREAD or TESLA_CONTEXT_GLOBAL
[in]classesnumber of tesla_class'es to expect
[in]instancestesla_instance count per tesla_class
[out]storereturn 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().

67 {
68  assert(storep);
69 
70  tesla_store *store;
71 
72  switch (context) {
74  store = &global_store;
75  break;
76 
77  case TESLA_CONTEXT_THREAD: {
78 #ifdef _KERNEL
79  store = curthread->td_tesla;
80 #else
81  pthread_key_t key = pthread_key();
82  store = pthread_getspecific(key);
83 #endif
84 
85  // Create a new store if we don't already have one.
86  if (store == NULL) {
87  store = tesla_malloc(sizeof(tesla_store));
88 #ifdef _KERNEL
89  curthread->td_tesla = store;
90 #else
91  __debug int err = pthread_setspecific(key, store);
92  assert(err == 0);
93 #endif
94  }
95  break;
96  }
97 
98  default:
99  return (TESLA_ERROR_EINVAL);
100  }
101 
102  if (store->length == 0) {
103  int32_t error =
104  tesla_store_init(store, context, classes, instances);
105 
106  if (error != TESLA_SUCCESS) return (error);
107 
108  assert(store->classes != NULL);
109  }
110 
111  *storep = store;
112  return (TESLA_SUCCESS);
113 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

119 {
120  assert(classes > 0);
121  assert(instances > 0);
122 
123  store->length = classes;
124  store->classes = tesla_malloc(classes * sizeof(tesla_class));
125  if (store->classes == NULL)
126  return (TESLA_ERROR_ENOMEM);
127 
128  int error = TESLA_SUCCESS;
129  for (uint32_t i = 0; i < classes; i++) {
130  error = tesla_class_init(store->classes + i, context, instances);
131  assert(error == TESLA_SUCCESS);
132  if (error != TESLA_SUCCESS)
133  break;
134 
135  assert(store->classes[i].tc_context >= 0);
136  }
137 
138  return (error);
139 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

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.