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.

130 lines
2.6KB

  1. /*
  2. Copyright (C) 2004-2008 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. #if defined(HAVE_CONFIG_H)
  16. #include "config.h"
  17. #endif
  18. #include "JackGlobals.h"
  19. #include "JackError.h"
  20. namespace Jack
  21. {
  22. JackFactoryImpl* JackGlobals::fInstance;
  23. void JackGlobals::InitServer()
  24. {
  25. jack_log("JackGlobals InitServer");
  26. if (!fInstance) {
  27. #ifdef __APPLE__
  28. fInstance = new JackFactoryOSXServer();
  29. #endif
  30. #ifdef WIN32
  31. fInstance = new JackFactoryWindowsServer();
  32. #endif
  33. #ifdef __linux__
  34. fInstance = new JackFactoryLinuxServer();
  35. #endif
  36. }
  37. }
  38. void JackGlobals::InitClient()
  39. {
  40. jack_log("JackGlobals InitClient");
  41. if (!fInstance) {
  42. #ifdef __APPLE__
  43. fInstance = new JackFactoryOSXClient();
  44. #endif
  45. #ifdef WIN32
  46. fInstance = new JackFactoryWindowsClient();
  47. #endif
  48. #ifdef __linux__
  49. fInstance = new JackFactoryLinuxClient();
  50. #endif
  51. }
  52. }
  53. void JackGlobals::Destroy()
  54. {
  55. jack_log("JackGlobals Destroy");
  56. if (fInstance) {
  57. delete fInstance;
  58. fInstance = NULL;
  59. }
  60. }
  61. } // end of namespace
  62. static bool gKeyRealtimeInitialized = false;
  63. static bool g_key_log_function_initialized = false;
  64. jack_tls_key gRealTime;
  65. jack_tls_key g_key_log_function;
  66. void jack_init()
  67. {
  68. if (!gKeyRealtimeInitialized) {
  69. gKeyRealtimeInitialized = jack_tls_allocate_key(&gRealTime);
  70. }
  71. if (!g_key_log_function_initialized)
  72. g_key_log_function_initialized = jack_tls_allocate_key(&g_key_log_function);
  73. }
  74. void jack_uninit()
  75. {
  76. if (gKeyRealtimeInitialized) {
  77. jack_tls_free_key(gRealTime);
  78. gKeyRealtimeInitialized = false;
  79. }
  80. if (g_key_log_function_initialized) {
  81. jack_tls_free_key(g_key_log_function);
  82. g_key_log_function_initialized = false;
  83. }
  84. }
  85. // Initialisation at library load time
  86. #ifdef WIN32
  87. BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  88. {
  89. switch (fdwReason) {
  90. case DLL_PROCESS_ATTACH:
  91. jack_init();
  92. break;
  93. case DLL_PROCESS_DETACH:
  94. jack_uninit();
  95. break;
  96. }
  97. return TRUE;
  98. }
  99. #endif