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.4KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * JackBridge (Part 2, Semaphore + Shared memory functions)
  3. * Copyright (C) 2013-2015 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 "CarlaSemUtils.hpp"
  21. # include "CarlaShmUtils.hpp"
  22. #endif // ! JACKBRIDGE_DUMMY
  23. // -----------------------------------------------------------------------------
  24. bool jackbridge_sem_init(void* sem) noexcept
  25. {
  26. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  27. #ifndef JACKBRIDGE_DUMMY
  28. return carla_sem_create2(*(carla_sem_t*)sem);
  29. #endif
  30. }
  31. void jackbridge_sem_destroy(void* sem) noexcept
  32. {
  33. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  34. #ifndef JACKBRIDGE_DUMMY
  35. carla_sem_destroy2(*(carla_sem_t*)sem);
  36. #endif
  37. }
  38. bool jackbridge_sem_connect(void* sem) noexcept
  39. {
  40. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  41. #ifdef JACKBRIDGE_DUMMY
  42. return false;
  43. #else
  44. return carla_sem_connect(*(carla_sem_t*)sem);
  45. #endif
  46. }
  47. void jackbridge_sem_post(void* sem, bool server) noexcept
  48. {
  49. CARLA_SAFE_ASSERT_RETURN(sem != nullptr,);
  50. #ifndef JACKBRIDGE_DUMMY
  51. carla_sem_post(*(carla_sem_t*)sem, server);
  52. #endif
  53. }
  54. bool jackbridge_sem_timedwait(void* sem, uint msecs, bool server) noexcept
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(sem != nullptr, false);
  57. #ifdef JACKBRIDGE_DUMMY
  58. return false;
  59. #else
  60. return carla_sem_timedwait(*(carla_sem_t*)sem, msecs, server);
  61. #endif
  62. }
  63. // -----------------------------------------------------------------------------
  64. bool jackbridge_shm_is_valid(const void* shm) noexcept
  65. {
  66. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, false);
  67. #ifdef JACKBRIDGE_DUMMY
  68. return false;
  69. #else
  70. return carla_is_shm_valid(*(const carla_shm_t*)shm);
  71. #endif
  72. }
  73. void jackbridge_shm_init(void* shm) noexcept
  74. {
  75. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  76. #ifndef JACKBRIDGE_DUMMY
  77. carla_shm_init(*(carla_shm_t*)shm);
  78. #endif
  79. }
  80. void jackbridge_shm_attach(void* shm, const char* name) noexcept
  81. {
  82. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  83. #ifndef JACKBRIDGE_DUMMY
  84. *(carla_shm_t*)shm = carla_shm_attach(name);
  85. #endif
  86. }
  87. void jackbridge_shm_close(void* shm) noexcept
  88. {
  89. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  90. #ifndef JACKBRIDGE_DUMMY
  91. carla_shm_close(*(carla_shm_t*)shm);
  92. #endif
  93. }
  94. void* jackbridge_shm_map(void* shm, uint64_t size) noexcept
  95. {
  96. CARLA_SAFE_ASSERT_RETURN(shm != nullptr, nullptr);
  97. #ifdef JACKBRIDGE_DUMMY
  98. return nullptr;
  99. #else
  100. return carla_shm_map(*(carla_shm_t*)shm, size);
  101. #endif
  102. }
  103. void jackbridge_shm_unmap(void* shm, void* ptr) noexcept
  104. {
  105. CARLA_SAFE_ASSERT_RETURN(shm != nullptr,);
  106. #ifndef JACKBRIDGE_DUMMY
  107. return carla_shm_unmap(*(carla_shm_t*)shm, ptr);
  108. #endif
  109. }
  110. // -----------------------------------------------------------------------------