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 General Public License as published by
  5. the Free Software Foundation; either version 2 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 General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 "JackGraphManager.h"
  25. #include "JackTime.h"
  26. #include <assert.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. #ifdef __APPLE__
  39. std::map<mach_port_t, JackClient*> fClientTable; /*! Client table */
  40. #endif
  41. static int fClientCount;
  42. static JackLibGlobals* fGlobals;
  43. JackLibGlobals()
  44. {
  45. JackLog("JackLibGlobals\n");
  46. for (int i = 0; i < CLIENT_NUM; i++)
  47. fSynchroTable[i] = JackGlobals::MakeSynchro();
  48. fGraphManager = -1;
  49. fEngineControl = -1;
  50. }
  51. virtual ~JackLibGlobals()
  52. {
  53. JackLog("~JackLibGlobals\n");
  54. for (int i = 0; i < CLIENT_NUM; i++) {
  55. fSynchroTable[i]->Disconnect();
  56. delete fSynchroTable[i];
  57. }
  58. }
  59. static void Init()
  60. {
  61. if (fClientCount++ == 0 && !fGlobals) {
  62. JackLog("JackLibGlobals Init %x\n", fGlobals);
  63. JackGlobals::InitClient();
  64. InitTime();
  65. fGlobals = new JackLibGlobals();
  66. }
  67. }
  68. static void Destroy()
  69. {
  70. if (--fClientCount == 0 && fGlobals) {
  71. JackLog("JackLibGlobals Destroy %x\n", fGlobals);
  72. delete fGlobals;
  73. fGlobals = NULL;
  74. JackGlobals::Destroy();
  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