Jack2 1.9.12

JackMessageBuffer.h
1 /*
2 * messagebuffer.h -- realtime-safe message interface for jackd.
3 *
4 * This function is included in libjack so backend drivers can use
5 * it, *not* for external client processes. The VERBOSE() and
6 * MESSAGE() macros are realtime-safe.
7 */
8
9 /*
10 * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
11 * Copyright (C) 2008 Nedko Arnaudov
12 * Copyright (C) 2008 Grame
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published by
16 * the Free Software Foundation; either version 2.1 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 *
28 */
29
30 #ifndef __JackMessageBuffer__
31 #define __JackMessageBuffer__
32
33 #include "JackPlatformPlug.h"
34 #include "JackMutex.h"
35 #include "JackAtomic.h"
36
37 namespace Jack
38 {
39
40 /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
41 #define MB_BUFFERS 128
42 #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
43 #define MB_BUFFERSIZE 256 /* message length limit */
44
45 struct JackMessage
46 {
47 int level;
48 char message[MB_BUFFERSIZE];
49 };
50
55 class JackMessageBuffer : public JackRunnableInterface
56 {
57
58 private:
59
60 volatile JackThreadInitCallback fInit;
61 void* fInitArg;
62 JackMessage fBuffers[MB_BUFFERS];
63 JackThread fThread;
64 JackProcessSync fGuard;
65 volatile unsigned int fInBuffer;
66 volatile unsigned int fOutBuffer;
67 SInt32 fOverruns;
68 bool fRunning;
69
70 void Flush();
71
72 bool Start();
73 bool Stop();
74
75 public:
76
77 JackMessageBuffer();
78 ~JackMessageBuffer();
79
80 // JackRunnableInterface interface
81 bool Execute();
82
83 bool static Create();
84 bool static Destroy();
85
86 void AddMessage(int level, const char *message);
87 int SetInitCallback(JackThreadInitCallback callback, void *arg);
88
89 static JackMessageBuffer* fInstance;
90 };
91
92 #ifdef __cplusplus
93 extern "C"
94 {
95 #endif
96
97 void JackMessageBufferAdd(int level, const char *message);
98
99 #ifdef __cplusplus
100 }
101 #endif
102
103 };
104
105 #endif
Jack::JackPosixProcessSync
A synchronization primitive built using a condition variable.
Definition: JackPosixProcessSync.h:35
Jack::JackRunnableInterface
The base class for runnable objects, that have an Init and Execute method to be called in a threa...
Definition: JackThread.h:34
Jack::JackMessage
Definition: JackMessageBuffer.h:45
Jack::JackMessageBuffer
Message buffer to be used from RT threads.
Definition: JackMessageBuffer.h:55
Jack::JackMachThread
Darwin threads. Real-time threads are actually "time constraint" threads.
Definition: JackMachThread.h:92