Merge branch 'master' into develop
[jack2.git] / common / JackMessageBuffer.h
blobfc0d7177ef3d67c53b7e48064fe19ea872d79c4e
1 /*
2 * messagebuffer.h -- realtime-safe message interface for jackd.
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 */
9 /*
10 * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
11 * Copyright (C) 2008 Nedko Arnaudov
12 * Copyright (C) 2008 Grame
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.
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.
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.
30 #ifndef __JackMessageBuffer__
31 #define __JackMessageBuffer__
33 #include "JackPlatformPlug.h"
34 #include "JackMutex.h"
35 #include "JackAtomic.h"
37 namespace Jack
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 */
45 struct JackMessage
47 int level;
48 char message[MB_BUFFERSIZE];
51 /*!
52 \brief Message buffer to be used from RT threads.
55 class JackMessageBuffer : public JackRunnableInterface
58 private:
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;
70 void Flush();
72 bool Start();
73 bool Stop();
75 public:
77 JackMessageBuffer();
78 ~JackMessageBuffer();
80 // JackRunnableInterface interface
81 bool Execute();
83 bool static Create();
84 bool static Destroy();
86 void AddMessage(int level, const char *message);
87 int SetInitCallback(JackThreadInitCallback callback, void *arg);
89 static JackMessageBuffer* fInstance;
92 #ifdef __cplusplus
93 extern "C"
95 #endif
97 void JackMessageBufferAdd(int level, const char *message);
99 #ifdef __cplusplus
101 #endif
105 #endif