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.

98 lines
2.5KB

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