Jack2 1.9.6

JackMessageBuffer.h

00001 /*
00002  * messagebuffer.h -- realtime-safe message interface for jackd.
00003  *
00004  *  This function is included in libjack so backend drivers can use
00005  *  it, *not* for external client processes.  The VERBOSE() and
00006  *  MESSAGE() macros are realtime-safe.
00007  */
00008 
00009 /*
00010  *  Copyright (C) 2004 Rui Nuno Capela, Steve Harris
00011  *  Copyright (C) 2008 Nedko Arnaudov
00012  *  Copyright (C) 2008 Grame
00013  *  
00014  *  This program is free software; you can redistribute it and/or modify
00015  *  it under the terms of the GNU Lesser General Public License as published by
00016  *  the Free Software Foundation; either version 2.1 of the License, or
00017  *  (at your option) any later version.
00018  *  
00019  *  This program is distributed in the hope that it will be useful,
00020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *  GNU Lesser General Public License for more details.
00023  *  
00024  *  You should have received a copy of the GNU Lesser General Public License
00025  *  along with this program; if not, write to the Free Software 
00026  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00027  *
00028  */
00029 
00030 #ifndef __JackMessageBuffer__
00031 #define __JackMessageBuffer__
00032 
00033 #include "JackPlatformPlug.h"
00034 #include "JackMutex.h"
00035 #include "JackAtomic.h"
00036 
00037 namespace Jack
00038 {
00039 
00040 /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
00041 #define MB_BUFFERS  128
00042 #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
00043 #define MB_BUFFERSIZE   256     /* message length limit */
00044 
00045 struct JackMessage
00046 {
00047     int level;
00048     char message[MB_BUFFERSIZE];
00049 };
00050 
00055 class JackMessageBuffer : public JackRunnableInterface
00056 {
00057 
00058     private:
00059     
00060         JackThreadInitCallback fInit;
00061         void* fInitArg;
00062         JackMessage fBuffers[MB_BUFFERS];
00063         JackThread fThread;
00064         JackProcessSync fGuard;
00065         volatile unsigned int fInBuffer;
00066         volatile unsigned int fOutBuffer;
00067         SInt32 fOverruns;
00068         bool fRunning;
00069 
00070         void Flush();
00071     
00072         void Start();
00073         void Stop();
00074             
00075     public:
00076     
00077         JackMessageBuffer();     
00078         ~JackMessageBuffer();
00079          
00080         // JackRunnableInterface interface
00081         bool Execute();
00082 
00083             void static Create();
00084             void static Destroy();
00085 
00086         void AddMessage(int level, const char *message);
00087         void SetInitCallback(JackThreadInitCallback callback, void *arg);
00088 
00089             static JackMessageBuffer* fInstance;
00090 };
00091 
00092 #ifdef __cplusplus
00093 extern "C" 
00094 {
00095 #endif
00096 
00097 void JackMessageBufferAdd(int level, const char *message);
00098 
00099 #ifdef __cplusplus
00100 } 
00101 #endif
00102 
00103 };
00104 
00105 #endif