jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.7KB

  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. * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
  10. * Copyright (C) 2008 Nedko Arnaudov
  11. * Copyright (C) 2008 Grame
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU Lesser General Public License as published by
  15. * the Free Software Foundation; either version 2.1 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Lesser General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Lesser General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. *
  27. */
  28. #ifndef __JackMessageBuffer__
  29. #define __JackMessageBuffer__
  30. #include "JackThread.h"
  31. #include "JackMutex.h"
  32. #include "JackAtomic.h"
  33. #include "JackSyncInterface.h"
  34. namespace Jack
  35. {
  36. /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
  37. #define MB_BUFFERS 128
  38. #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
  39. #define MB_BUFFERSIZE 256 /* message length limit */
  40. struct JackMessage
  41. {
  42. int level;
  43. char message[MB_BUFFERSIZE];
  44. };
  45. class JackMessageBuffer : public JackRunnableInterface
  46. {
  47. private:
  48. JackMessage fBuffers[MB_BUFFERS];
  49. JackMutex* fMutex;
  50. JackThread* fThread;
  51. JackSyncInterface* fSignal;
  52. volatile unsigned int fInBuffer;
  53. volatile unsigned int fOutBuffer;
  54. SInt32 fOverruns;
  55. void Flush();
  56. public:
  57. JackMessageBuffer();
  58. ~JackMessageBuffer();
  59. // JackRunnableInterface interface
  60. bool Execute();
  61. void static Create();
  62. void static Destroy();
  63. void AddMessage(int level, const char *message);
  64. static JackMessageBuffer* fInstance;
  65. };
  66. #ifdef __cplusplus
  67. extern "C"
  68. {
  69. #endif
  70. void JackMessageBufferAdd(int level, const char *message);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. };
  75. #endif
  76. /*
  77. * messagebuffer.h -- realtime-safe message interface for jackd.
  78. *
  79. * This function is included in libjack so backend drivers can use
  80. * it, *not* for external client processes. The VERBOSE() and
  81. * MESSAGE() macros are realtime-safe.
  82. */
  83. /*
  84. * Copyright (C) 2004 Rui Nuno Capela, Steve Harris
  85. * Copyright (C) 2008 Nedko Arnaudov
  86. * Copyright (C) 2008 Grame
  87. *
  88. * This program is free software; you can redistribute it and/or modify
  89. * it under the terms of the GNU Lesser General Public License as published by
  90. * the Free Software Foundation; either version 2.1 of the License, or
  91. * (at your option) any later version.
  92. *
  93. * This program is distributed in the hope that it will be useful,
  94. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  95. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  96. * GNU Lesser General Public License for more details.
  97. *
  98. * You should have received a copy of the GNU Lesser General Public License
  99. * along with this program; if not, write to the Free Software
  100. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  101. *
  102. */
  103. #ifndef __JackMessageBuffer__
  104. #define __JackMessageBuffer__
  105. #include "JackThread.h"
  106. #include "JackMutex.h"
  107. #include "JackAtomic.h"
  108. #include "JackSyncInterface.h"
  109. namespace Jack
  110. {
  111. /* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
  112. #define MB_BUFFERS 128
  113. #define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
  114. #define MB_BUFFERSIZE 256 /* message length limit */
  115. struct JackMessage
  116. {
  117. int level;
  118. char message[MB_BUFFERSIZE];
  119. };
  120. class JackMessageBuffer : public JackRunnableInterface
  121. {
  122. private:
  123. JackMessage fBuffers[MB_BUFFERS];
  124. JackMutex* fMutex;
  125. JackThread* fThread;
  126. JackSyncInterface* fSignal;
  127. volatile unsigned int fInBuffer;
  128. volatile unsigned int fOutBuffer;
  129. SInt32 fOverruns;
  130. void Flush();
  131. public:
  132. JackMessageBuffer();
  133. ~JackMessageBuffer();
  134. // JackRunnableInterface interface
  135. bool Execute();
  136. void static Create();
  137. void static Destroy();
  138. void AddMessage(int level, const char *message);
  139. static JackMessageBuffer* fInstance;
  140. };
  141. #ifdef __cplusplus
  142. extern "C"
  143. {
  144. #endif
  145. void JackMessageBufferAdd(int level, const char *message);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. };
  150. #endif