Audio plugin host https://kx.studio/carla
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.

150 lines
3.7KB

  1. /*
  2. * JackBridge (Part 2, Semaphore + Shared memory and other misc functions)
  3. * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "JackBridge.hpp"
  17. #ifdef JACKBRIDGE_DUMMY
  18. # include "CarlaUtils.hpp"
  19. #else
  20. # include "CarlaProcessUtils.hpp"
  21. # include "CarlaSemUtils.hpp"
  22. # include "CarlaShmUtils.hpp"
  23. #endif // ! JACKBRIDGE_DUMMY
  24. // -----------------------------------------------------------------------------
  25. bool jackbridge_sem_init(void* sem) noexcept
  26. {
  27. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  28. #ifndef JACKBRIDGE_DUMMY
  29. return carla_sem_create2(*(carla_sem_t*)sem, true);
  30. #endif
  31. }
  32. void jackbridge_sem_destroy(void* sem) noexcept
  33. {
  34. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  35. #ifndef JACKBRIDGE_DUMMY
  36. carla_sem_destroy2(*(carla_sem_t*)sem);
  37. #endif
  38. }
  39. bool jackbridge_sem_connect(void* sem) noexcept
  40. {
  41. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  42. #ifdef JACKBRIDGE_DUMMY
  43. return false;
  44. #else
  45. return carla_sem_connect(*(carla_sem_t*)sem);
  46. #endif
  47. }
  48. void jackbridge_sem_post(void* sem, bool server) noexcept
  49. {
  50. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  51. #ifndef JACKBRIDGE_DUMMY
  52. carla_sem_post(*(carla_sem_t*)sem, server);
  53. #endif
  54. }
  55. #ifndef CARLA_OS_WASM
  56. bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept
  57. {
  58. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  59. #ifdef JACKBRIDGE_DUMMY
  60. return false;
  61. #else
  62. return carla_sem_timedwait(*(carla_sem_t*)sem, msecs, server);
  63. #endif
  64. }
  65. #endif
  66. // -----------------------------------------------------------------------------
  67. bool jackbridge_shm_is_valid(const void* shm) noexcept
  68. {
  69. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  70. #ifdef JACKBRIDGE_DUMMY
  71. return false;
  72. #else
  73. return carla_is_shm_valid(*(const carla_shm_t*)shm);
  74. #endif
  75. }
  76. void jackbridge_shm_init(void* shm) noexcept
  77. {
  78. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  79. #ifndef JACKBRIDGE_DUMMY
  80. carla_shm_init(*(carla_shm_t*)shm);
  81. #endif
  82. }
  83. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  84. {
  85. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  86. #ifndef JACKBRIDGE_DUMMY
  87. *(carla_shm_t*)shm = carla_shm_attach(name);
  88. #endif
  89. }
  90. void jackbridge_shm_close(void* shm) noexcept
  91. {
  92. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  93. #ifndef JACKBRIDGE_DUMMY
  94. carla_shm_close(*(carla_shm_t*)shm);
  95. #endif
  96. }
  97. void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
  98. {
  99. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  100. #ifdef JACKBRIDGE_DUMMY
  101. return nullptr;
  102. #else
  103. return carla_shm_map(*(carla_shm_t*)shm, static_cast<std::size_t>(size));
  104. #endif
  105. }
  106. void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
  107. {
  108. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  109. #ifndef JACKBRIDGE_DUMMY
  110. return carla_shm_unmap(*(carla_shm_t*)shm, ptr);
  111. #endif
  112. }
  113. // -----------------------------------------------------------------------------
  114. void jackbridge_parent_deathsig(bool kill) noexcept
  115. {
  116. #ifndef JACKBRIDGE_DUMMY
  117. carla_terminateProcessOnParentExit(kill);
  118. #endif
  119. }
  120. // -----------------------------------------------------------------------------