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.

CarlaPipeUtils.hpp 4.0KB

11 years ago
11 years ago
11 years ago
10 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
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 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
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Carla Pipe utils
  3. * Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_PIPE_UTILS_HPP_INCLUDED
  18. #define CARLA_PIPE_UTILS_HPP_INCLUDED
  19. #include "CarlaJuceUtils.hpp"
  20. #include "CarlaMutex.hpp"
  21. // -----------------------------------------------------------------------
  22. class CarlaPipeCommon
  23. {
  24. protected:
  25. CarlaPipeCommon() noexcept;
  26. virtual ~CarlaPipeCommon() noexcept;
  27. // returns true if msg handled
  28. virtual bool msgReceived(const char* const msg) noexcept = 0;
  29. // to possibly send errors somewhere
  30. virtual void fail(const char* const error) noexcept
  31. {
  32. carla_stderr2(error);
  33. }
  34. public:
  35. void idle() noexcept;
  36. bool isRunning() const noexcept;
  37. // -------------------------------------------------------------------
  38. // write lock
  39. void lock() const noexcept;
  40. bool tryLock() const noexcept;
  41. void unlock() const noexcept;
  42. CarlaMutex& getLock() noexcept;
  43. // -------------------------------------------------------------------
  44. bool readNextLineAsBool(bool& value) noexcept;
  45. bool readNextLineAsInt(int32_t& value) noexcept;
  46. bool readNextLineAsUInt(uint32_t& value) noexcept;
  47. bool readNextLineAsLong(int64_t& value) noexcept;
  48. bool readNextLineAsULong(uint64_t& value) noexcept;
  49. bool readNextLineAsFloat(float& value) noexcept;
  50. bool readNextLineAsDouble(double& value) noexcept;
  51. bool readNextLineAsString(const char*& value) noexcept;
  52. // -------------------------------------------------------------------
  53. // must be locked before calling
  54. bool writeMsg(const char* const msg) const noexcept;
  55. bool writeMsg(const char* const msg, std::size_t size) const noexcept;
  56. bool writeAndFixMsg(const char* const msg) const noexcept;
  57. bool flush() const noexcept;
  58. // -------------------------------------------------------------------
  59. protected:
  60. struct PrivateData;
  61. PrivateData* const pData;
  62. // -------------------------------------------------------------------
  63. // internal
  64. const char* readline() noexcept;
  65. const char* readlineblock(const uint32_t timeOutMilliseconds = 50) noexcept;
  66. bool writeMsgBuffer(const char* const msg, const std::size_t size) const noexcept;
  67. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeCommon)
  68. };
  69. // -----------------------------------------------------------------------
  70. class CarlaPipeServer : public CarlaPipeCommon
  71. {
  72. public:
  73. CarlaPipeServer() noexcept;
  74. ~CarlaPipeServer() noexcept override;
  75. bool start(const char* const filename, const char* const arg1, const char* const arg2) noexcept;
  76. void stop(const uint32_t timeOutMilliseconds) noexcept;
  77. void close() noexcept;
  78. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeServer)
  79. };
  80. // -----------------------------------------------------------------------
  81. class CarlaPipeClient : public CarlaPipeCommon
  82. {
  83. public:
  84. CarlaPipeClient() noexcept;
  85. ~CarlaPipeClient() noexcept override;
  86. bool init(const char* argv[]) noexcept;
  87. void close() noexcept;
  88. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClient)
  89. };
  90. // -----------------------------------------------------------------------
  91. class ScopedLocale {
  92. public:
  93. ScopedLocale() noexcept;
  94. ~ScopedLocale() noexcept;
  95. private:
  96. const char* const fLocale;
  97. CARLA_DECLARE_NON_COPY_CLASS(ScopedLocale)
  98. CARLA_PREVENT_HEAP_ALLOCATION
  99. };
  100. // -----------------------------------------------------------------------
  101. #endif // CARLA_PIPE_UTILS_HPP_INCLUDED