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.

106 lines
2.7KB

  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. #ifdef __APPLE__
  20. #include "JackMachPort.h"
  21. #include <map>
  22. #endif
  23. #include "JackGlobals.h"
  24. #include "JackPlatformSynchro.h"
  25. #include "JackGraphManager.h"
  26. #include "JackMessageBuffer.h"
  27. #include "JackTime.h"
  28. #include "JackError.h"
  29. #include <assert.h>
  30. namespace Jack
  31. {
  32. class JackClient;
  33. /*!
  34. \brief Global library static structure: singleton kind of pattern.
  35. */
  36. struct JackLibGlobals
  37. {
  38. JackShmReadWritePtr<JackGraphManager> fGraphManager; /*! Shared memory Port manager */
  39. JackShmReadWritePtr<JackEngineControl> fEngineControl; /*! Shared engine control */ // transport engine has to be writable
  40. JackSynchro fSynchroTable[CLIENT_NUM]; /*! Shared synchro table */
  41. #ifdef __APPLE__
  42. std::map<mach_port_t, JackClient*> fClientTable; /*! Client table */
  43. #endif
  44. static int fClientCount;
  45. static JackLibGlobals* fGlobals;
  46. JackLibGlobals()
  47. {
  48. jack_log("JackLibGlobals");
  49. JackMessageBuffer::Create();
  50. fGraphManager = -1;
  51. fEngineControl = -1;
  52. }
  53. virtual ~JackLibGlobals()
  54. {
  55. jack_log("~JackLibGlobals");
  56. for (int i = 0; i < CLIENT_NUM; i++) {
  57. fSynchroTable[i].Disconnect();
  58. }
  59. JackMessageBuffer::Destroy();
  60. }
  61. static void Init()
  62. {
  63. if (fClientCount++ == 0 && !fGlobals) {
  64. jack_log("JackLibGlobals Init %x", fGlobals);
  65. InitTime();
  66. fGlobals = new JackLibGlobals();
  67. }
  68. }
  69. static void Destroy()
  70. {
  71. if (--fClientCount == 0 && fGlobals) {
  72. jack_log("JackLibGlobals Destroy %x", fGlobals);
  73. delete fGlobals;
  74. fGlobals = NULL;
  75. }
  76. }
  77. static void CheckContext()
  78. {
  79. if (!(fClientCount > 0 && fGlobals)) {
  80. jack_error("Error !!! : client accessing an already desallocated library context");
  81. }
  82. }
  83. };
  84. } // end of namespace
  85. #endif