blob: 44550b69756a59d27d72672076769aedd4801491 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "til_tap.h"
/* A "tap" is a named binding of a local variable+pointer to that variable.
*
* It's purpose is to facilitate exposing local variables controlling rendering
* to potential external influence.
*
* While the tap alone does get named, this is mostly for ergonomic reasons since
* it's convenient and natural to name the tap while specifying its variable and
* pointer by name as well. Putting them all in once place.
*
* The tap itself is not a registry or otherwise discoverable entity by itself.
* This is strictly just the local glue, with a name. Other pieces must tie taps
* into streams or settings stuff for addressing them by name at a path or other
* means.
*
* Note the intended way for taps to work is that the caller will always access their
* local variables indirectly via the pointers they provided when creating the taps.
* There will be a function for managing the tap the caller must call before accessing
* the variable indirectly as well. It's that function which will update the indirection
* pointer to potentially point elsewhere if another tap is driving the variable.
*/
struct til_tap_t {
til_tap_type_t type;
void *ptr; /* points at the caller-provided tap-managed indirection pointer */
size_t n_elems; /* when > 1, *ptr is an array of n_elems elements. Otherwise individual variable. */
void *elems; /* points at the first element of type type, may or may not be an array of them */
char name[];
};
/* This is the raw tap creator but use the type-checked wrappers in the header and add one if one's missing */
til_tap_t * til_tap_new(til_tap_type_t type, void *ptr, const char *name, size_t n_elems, void *elems)
{
til_tap_t *tap;
assert(name);
assert(type < TIL_TAP_TYPE_MAX);
assert(ptr);
assert(n_elems);
assert(elems);
tap = calloc(1, sizeof(til_tap_t) + strlen(name) + 1);
if (!tap)
return NULL;
strcpy(tap->name, name);
tap->type = type;
tap->ptr = ptr;
tap->n_elems = n_elems;
tap->elems = elems;
*((void **)tap->ptr) = elems;
return tap;
}
til_tap_t * til_tap_free(til_tap_t *tap)
{
free(tap);
return NULL;
}
|