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.

JackBridge2.cpp 3.7KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept
  56. {
  57. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  58. #ifdef JACKBRIDGE_DUMMY
  59. return false;
  60. #else
  61. return carla_sem_timedwait(*(carla_sem_t*)sem, msecs, server);
  62. #endif
  63. }
  64. // -----------------------------------------------------------------------------
  65. bool jackbridge_shm_is_valid(const void* shm) noexcept
  66. {
  67. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  68. #ifdef JACKBRIDGE_DUMMY
  69. return false;
  70. #else
  71. return carla_is_shm_valid(*(const carla_shm_t*)shm);
  72. #endif
  73. }
  74. void jackbridge_shm_init(void* shm) noexcept
  75. {
  76. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  77. #ifndef JACKBRIDGE_DUMMY
  78. carla_shm_init(*(carla_shm_t*)shm);
  79. #endif
  80. }
  81. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  82. {
  83. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  84. #ifndef JACKBRIDGE_DUMMY
  85. *(carla_shm_t*)shm = carla_shm_attach(name);
  86. #endif
  87. }
  88. void jackbridge_shm_close(void* shm) noexcept
  89. {
  90. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  91. #ifndef JACKBRIDGE_DUMMY
  92. carla_shm_close(*(carla_shm_t*)shm);
  93. #endif
  94. }
  95. void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
  96. {
  97. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  98. #ifdef JACKBRIDGE_DUMMY
  99. return nullptr;
  100. #else
  101. return carla_shm_map(*(carla_shm_t*)shm, static_cast<std::size_t>(size));
  102. #endif
  103. }
  104. void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
  105. {
  106. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  107. #ifndef JACKBRIDGE_DUMMY
  108. return carla_shm_unmap(*(carla_shm_t*)shm, ptr);
  109. #endif
  110. }
  111. // -----------------------------------------------------------------------------
  112. void jackbridge_parent_deathsig(bool kill) noexcept
  113. {
  114. #ifndef JACKBRIDGE_DUMMY
  115. carla_terminateProcessOnParentExit(kill);
  116. #endif
  117. }
  118. // -----------------------------------------------------------------------------