Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
AuxTaskNonRT.h
1/***** AuxTaskNonRT.h *****/
2#ifndef __AuxTaskNonRT_H_INCLUDED__
3#define __AuxTaskNonRT_H_INCLUDED__
4
5#ifdef XENOMAI_SKIN_native
6#include <rtdk.h>
7#include <native/task.h>
8#include <native/pipe.h>
9#endif
10
11#ifdef XENOMAI_SKIN_posix
12#include <pthread.h>
13#endif
14
15#include <string>
16#include <functional>
17
18#define AUX_MAX_BUFFER_SIZE 500000
19
20class AuxTaskNonRT{
21 public:
22 AuxTaskNonRT(){}
23 AuxTaskNonRT(std::string _name, std::function<void()> callback){ create(_name, callback); }
24 AuxTaskNonRT(std::string _name, std::function<void(std::string str)> callback){ create(_name, callback); }
25 AuxTaskNonRT(std::string _name, std::function<void(void* buf, int size)> callback){ create(_name, callback); }
26 ~AuxTaskNonRT(){ cleanup(); }
27
28 void create(std::string _name, std::function<void()> callback);
29 void create(std::string _name, std::function<void(std::string str)> callback);
30 void create(std::string _name, std::function<void(void* buf, int size)> callback);
31
32 int schedule(const void* ptr, size_t size);
33 int schedule(const char* str);
34 int schedule();
35
36 private:
37 bool lShouldStop = false;
38 bool shouldStop();
39 void cleanup();
40
41#ifdef XENOMAI_SKIN_native
42 RT_TASK task;
43 RT_PIPE pipe;
44#endif
45#ifdef XENOMAI_SKIN_posix
46 pthread_t thread;
47 int pipeSocket;
48#endif
49
50 std::string name;
51 int pipe_fd;
52 int mode;
53
54 void __create();
55 int openPipe();
56
57 std::function<void()> empty_callback;
58 std::function<void(std::string str)> str_callback;
59 std::function<void(void* buf, int size)> buf_callback;
60
61 void empty_loop();
62 void str_loop();
63 void buf_loop();
64
65 static void thread_func(void* ptr);
66};
67
68#endif