move hand-written checks to their own file
[jack_interposer.git] / jack_interposer.c
blob954875f9c5b931cd9041b49be85a5ee30b9cd0b6
1 // needed to use RTLD_NEXT from dlfcn.h
2 #define _GNU_SOURCE
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdbool.h>
7 #include <dlfcn.h>
8 #include <poll.h>
9 #include <jack/jack.h>
10 #include <stdarg.h>
12 #define ABORT_ON_VIOLATION 1
14 // is set to 'true' when entering the process-callback and to 'false' when
15 // leaving it. When set to 'true', calls to non-realtime functions will
16 // cause warnings/errors.
17 //
18 // This assumes there is only 1 thread running at a time, thus introducing
19 // the limitation that jack_interposer is only usable on single-CPU machines
20 // (or machines configured to run the application under test on only 1 CPU).
21 bool in_rt = false;
23 #include "checkers.c"
24 #include "manual.c"
26 JackProcessCallback real_process_callback;
28 int interposed_process_callback(jack_nframes_t nframes, void* arg)
30 int result;
32 in_rt = true;
34 result = real_process_callback(nframes, arg);
36 in_rt = false;
38 return result;
41 int jack_set_process_callback(jack_client_t* client,
42 JackProcessCallback process_callback, void* arg)
44 static int (*func)() = NULL;
45 int result;
47 if(!func)
48 func = (int(*)()) dlsym(RTLD_NEXT, "jack_set_process_callback");
49 if(!func)
51 fprintf(stderr, "Error dlsym'ing jack_set_process_callback\n");
52 abort();
55 real_process_callback = process_callback;
57 result = func(client, interposed_process_callback, arg);
59 return result;