summaryrefslogtreecommitdiff
path: root/apps/codecs/dumb/src/core/register.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/dumb/src/core/register.c')
-rw-r--r--apps/codecs/dumb/src/core/register.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/apps/codecs/dumb/src/core/register.c b/apps/codecs/dumb/src/core/register.c
new file mode 100644
index 0000000000..9eed45f796
--- /dev/null
+++ b/apps/codecs/dumb/src/core/register.c
@@ -0,0 +1,104 @@
1/* _______ ____ __ ___ ___
2 * \ _ \ \ / \ / \ \ / / ' ' '
3 * | | \ \ | | || | \/ | . .
4 * | | | | | | || ||\ /| |
5 * | | | | | | || || \/ | | ' ' '
6 * | | | | | | || || | | . .
7 * | |_/ / \ \__// || | |
8 * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
9 * / \
10 * / . \
11 * register.c - Signal type registration. / / \ \
12 * | < / \_
13 * By entheh. | \/ /\ /
14 * \_ / > /
15 * | \ / /
16 * | ' /
17 * \__/
18 */
19
20#include <stdlib.h>
21
22#include "dumb.h"
23#include "internal/dumb.h"
24
25
26
27static DUH_SIGTYPE_DESC_LINK *sigtype_desc = NULL;
28static DUH_SIGTYPE_DESC_LINK **sigtype_desc_tail = &sigtype_desc;
29
30
31
32/* destroy_sigtypes(): frees all memory allocated while registering signal
33 * types. This function is set up to be called by dumb_exit().
34 */
35static void destroy_sigtypes(void)
36{
37 DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc, *next;
38 sigtype_desc = NULL;
39 sigtype_desc_tail = &sigtype_desc;
40
41 while (desc_link) {
42 next = desc_link->next;
43 free(desc_link);
44 desc_link = next;
45 }
46}
47
48
49
50/* dumb_register_sigtype(): registers a new signal type with DUMB. The signal
51 * type is identified by a four-character string (e.g. "WAVE"), which you can
52 * encode using the the DUMB_ID() macro (e.g. DUMB_ID('W','A','V','E')). The
53 * signal's behaviour is defined by four functions, whose pointers you pass
54 * here. See the documentation for details.
55 *
56 * If a DUH tries to use a signal that has not been registered using this
57 * function, then the library will fail to load the DUH.
58 */
59void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc)
60{
61 DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
62
63 ASSERT((desc->load_sigdata && desc->unload_sigdata) || (!desc->load_sigdata && !desc->unload_sigdata));
64 ASSERT((desc->start_sigrenderer && desc->end_sigrenderer) || (!desc->start_sigrenderer && !desc->end_sigrenderer));
65 ASSERT(desc->sigrenderer_get_samples && desc->sigrenderer_get_current_sample);
66
67 if (desc_link) {
68 do {
69 if (desc_link->desc->type == desc->type) {
70 desc_link->desc = desc;
71 return;
72 }
73 desc_link = desc_link->next;
74 } while (desc_link);
75 } else
76 dumb_atexit(&destroy_sigtypes);
77
78 desc_link = *sigtype_desc_tail = malloc(sizeof(DUH_SIGTYPE_DESC_LINK));
79
80 if (!desc_link)
81 return;
82
83 desc_link->next = NULL;
84 sigtype_desc_tail = &desc_link->next;
85
86 desc_link->desc = desc;
87}
88
89
90
91/* _dumb_get_sigtype_desc(): searches the registered functions for a signal
92 * type matching the parameter. If such a sigtype is found, it returns a
93 * pointer to a sigtype descriptor containing the necessary functions to
94 * manage the signal. If none is found, it returns NULL.
95 */
96DUH_SIGTYPE_DESC *_dumb_get_sigtype_desc(long type)
97{
98 DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
99
100 while (desc_link && desc_link->desc->type != type)
101 desc_link = desc_link->next;
102
103 return desc_link->desc;
104}