The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

119 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce::midi_ci
  19. {
  20. /**
  21. Contains data returned by a responder in response to a request.
  22. PropertyExchangeResult::kind indicates whether the transaction resulted in
  23. a well-formed message; however, it's possible that the message is a
  24. well-formed message indicating an error in the responder, so it's important
  25. to check the 'status' field of the header before attempting to do anything
  26. with the payload.
  27. @tags{Audio}
  28. */
  29. class PropertyExchangeResult
  30. {
  31. public:
  32. enum class Error
  33. {
  34. partial, ///< Got a response, but the responder terminated it before
  35. ///< sending a well-formed message.
  36. notify, ///< Got a notify message terminating the transaction.
  37. tooManyTransactions, ///< Unable to send the request because doing so would
  38. ///< exceed the number of simultaneous inquiries that were declared.
  39. ///< @see PropertyDelegate::getNumSimultaneousRequestsSupported().
  40. invalidPayload, ///< The payload couldn't be encoded for transmission. If you're
  41. ///< using the ASCII encoding, maybe some bytes have their most
  42. ///< significant bit set.
  43. };
  44. /** Creates a result denoting an error state. */
  45. explicit PropertyExchangeResult (Error errorIn)
  46. : PropertyExchangeResult (errorIn, {}, {}) {}
  47. /** Creates a result denoting a successful transmission. */
  48. PropertyExchangeResult (var headerIn, Span<const std::byte> bodyIn)
  49. : PropertyExchangeResult (std::nullopt, headerIn, bodyIn) {}
  50. /** Returns the result kind, either nullopt for a successful transmission, or
  51. an error code if something went wrong.
  52. */
  53. std::optional<Error> getError() const { return error; }
  54. /** Parses the header as a subscription header.
  55. This may only be called for messages of kind 'full'.
  56. */
  57. PropertySubscriptionHeader getHeaderAsSubscriptionHeader() const
  58. {
  59. jassert (header != var());
  60. return PropertySubscriptionHeader::parseCondensed (header);
  61. }
  62. /** Parses the header as a request header.
  63. This may only be called for messages of kind 'full'.
  64. */
  65. PropertyRequestHeader getHeaderAsRequestHeader() const
  66. {
  67. jassert (header != var());
  68. return PropertyRequestHeader::parseCondensed (header);
  69. }
  70. /** Parses the header as a reply header.
  71. This may only be called for messages of kind 'full'.
  72. */
  73. PropertyReplyHeader getHeaderAsReplyHeader() const
  74. {
  75. jassert (header != var());
  76. return PropertyReplyHeader::parseCondensed (header);
  77. }
  78. /** When getKind returns 'full', this is the message payload.
  79. Note that this is not stored internally; if you need to keep this data
  80. around and reference it in the future, you should copy it into a
  81. vector or some other suitable container.
  82. */
  83. Span<const std::byte> getBody() const { return body; }
  84. private:
  85. PropertyExchangeResult (std::optional<Error> errorIn, var headerIn, Span<const std::byte> bodyIn)
  86. : error (errorIn), header (headerIn), body (bodyIn) {}
  87. std::optional<Error> error;
  88. var header;
  89. Span<const std::byte> body;
  90. };
  91. } // namespace juce::midi_ci