2 * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
3 * Copyright (C) 2008 Nedko Arnaudov
4 * Copyright (C) 2008 Grame
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "JackMessageBuffer.h"
23 #include "JackGlobals.h"
24 #include "JackError.h"
29 JackMessageBuffer
* JackMessageBuffer::fInstance
= NULL
;
31 JackMessageBuffer::JackMessageBuffer()
32 :fThread(this),fInBuffer(0),fOutBuffer(0),fOverruns(0),fRunning(false)
35 JackMessageBuffer::~JackMessageBuffer()
38 void JackMessageBuffer::Start()
44 void JackMessageBuffer::Stop()
47 jack_error("WARNING: %d message buffer overruns!", fOverruns
);
49 jack_info("no message buffer overruns");
59 void JackMessageBuffer::Flush()
61 while (fOutBuffer
!= fInBuffer
) {
62 jack_log_function(fBuffers
[fOutBuffer
].level
, fBuffers
[fOutBuffer
].message
);
63 fOutBuffer
= MB_NEXT(fOutBuffer
);
67 void JackMessageBuffer::AddMessage(int level
, const char *message
)
69 if (fGuard
.Trylock()) {
70 fBuffers
[fInBuffer
].level
= level
;
71 strncpy(fBuffers
[fInBuffer
].message
, message
, MB_BUFFERSIZE
);
72 fInBuffer
= MB_NEXT(fInBuffer
);
75 } else { /* lock collision */
76 INC_ATOMIC(&fOverruns
);
80 bool JackMessageBuffer::Execute()
91 void JackMessageBuffer::Create()
93 if (fInstance
== NULL
) {
94 fInstance
= new JackMessageBuffer();
99 void JackMessageBuffer::Destroy()
101 if (fInstance
!= NULL
) {
108 void JackMessageBufferAdd(int level
, const char *message
)
110 if (Jack::JackMessageBuffer::fInstance
== NULL
) {
111 /* Unable to print message with realtime safety. Complain and print it anyway. */
112 jack_log_function(LOG_LEVEL_ERROR
, "messagebuffer not initialized, skip message");
114 Jack::JackMessageBuffer::fInstance
->AddMessage(level
, message
);