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.

118 lines
3.0KB

  1. /*
  2. Copyright (C) 2005 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __JackLibGlobals__
  16. #define __JackLibGlobals__
  17. #include "JackShmMem.h"
  18. #include "JackEngineControl.h"
  19. #include "JackGlobals.h"
  20. #include "JackPlatformPlug.h"
  21. #include "JackGraphManager.h"
  22. #include "JackMessageBuffer.h"
  23. #include "JackTime.h"
  24. #include "JackError.h"
  25. #include <assert.h>
  26. #include <signal.h>
  27. namespace Jack
  28. {
  29. class JackClient;
  30. /*!
  31. \brief Global library static structure: singleton kind of pattern.
  32. */
  33. struct JackLibGlobals
  34. {
  35. JackShmReadWritePtr<JackGraphManager> fGraphManager; /*! Shared memory Port manager */
  36. JackShmReadWritePtr<JackEngineControl> fEngineControl; /*! Shared engine control */ // transport engine has to be writable
  37. JackSynchro fSynchroTable[CLIENT_NUM]; /*! Shared synchro table */
  38. sigset_t fProcessSignals;
  39. static int fClientCount;
  40. static JackLibGlobals* fGlobals;
  41. JackLibGlobals()
  42. {
  43. jack_log("JackLibGlobals");
  44. JackMessageBuffer::Create();
  45. fGraphManager = -1;
  46. fEngineControl = -1;
  47. // Filter SIGPIPE to avoid having client get a SIGPIPE when trying to access a died server.
  48. #ifdef WIN32
  49. // TODO
  50. #else
  51. sigset_t signals;
  52. sigemptyset(&signals);
  53. sigaddset(&signals, SIGPIPE);
  54. sigprocmask(SIG_BLOCK, &signals, &fProcessSignals);
  55. #endif
  56. }
  57. ~JackLibGlobals()
  58. {
  59. jack_log("~JackLibGlobals");
  60. for (int i = 0; i < CLIENT_NUM; i++) {
  61. fSynchroTable[i].Disconnect();
  62. }
  63. JackMessageBuffer::Destroy();
  64. // Restore old signal mask
  65. #ifdef WIN32
  66. // TODO
  67. #else
  68. sigprocmask(SIG_BLOCK, &fProcessSignals, 0);
  69. #endif
  70. }
  71. static void Init()
  72. {
  73. if (fClientCount++ == 0 && !fGlobals) {
  74. jack_log("JackLibGlobals Init %x", fGlobals);
  75. InitTime();
  76. fGlobals = new JackLibGlobals();
  77. }
  78. }
  79. static void Destroy()
  80. {
  81. if (--fClientCount == 0 && fGlobals) {
  82. jack_log("JackLibGlobals Destroy %x", fGlobals);
  83. delete fGlobals;
  84. fGlobals = NULL;
  85. }
  86. }
  87. static void CheckContext()
  88. {
  89. if (!(fClientCount > 0 && fGlobals)) {
  90. jack_error("Error !!! : client accessing an already desallocated library context");
  91. }
  92. }
  93. };
  94. } // end of namespace
  95. #endif