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.

132 lines
5.8KB

  1. //------------------------------------------------------------------------
  2. // Project : SDK Base
  3. // Version : 1.0
  4. //
  5. // Category : Helpers
  6. // Filename : base/source/updatehandler.h
  7. // Created by : Steinberg, 2008
  8. // Description :
  9. //
  10. //-----------------------------------------------------------------------------
  11. // LICENSE
  12. // (c) 2017, Steinberg Media Technologies GmbH, All Rights Reserved
  13. //-----------------------------------------------------------------------------
  14. // Redistribution and use in source and binary forms, with or without modification,
  15. // are permitted provided that the following conditions are met:
  16. //
  17. // * Redistributions of source code must retain the above copyright notice,
  18. // this list of conditions and the following disclaimer.
  19. // * Redistributions in binary form must reproduce the above copyright notice,
  20. // this list of conditions and the following disclaimer in the documentation
  21. // and/or other materials provided with the distribution.
  22. // * Neither the name of the Steinberg Media Technologies nor the names of its
  23. // contributors may be used to endorse or promote products derived from this
  24. // software without specific prior written permission.
  25. //
  26. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  27. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  28. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  29. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  30. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  34. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  35. // OF THE POSSIBILITY OF SUCH DAMAGE.
  36. //-----------------------------------------------------------------------------
  37. #pragma once
  38. #include "base/source/fobject.h"
  39. #include "base/source/flock.h"
  40. #include "pluginterfaces/base/iupdatehandler.h"
  41. namespace Steinberg {
  42. /// @cond ignore
  43. namespace Update { struct Table; }
  44. /// @endcond
  45. //------------------------------------------------------------------------
  46. /** Handle Send and Cancel pending message for a given object*/
  47. //------------------------------------------------------------------------
  48. class IUpdateManager : public FUnknown
  49. {
  50. public:
  51. //------------------------------------------------------------------------
  52. /** cancel pending messages send by \param object or by any if object is 0 */
  53. virtual tresult PLUGIN_API cancelUpdates (FUnknown* object) = 0;
  54. /** send pending messages send by \param object or by any if object is 0 */
  55. virtual tresult PLUGIN_API triggerDeferedUpdates (FUnknown* object = 0) = 0;
  56. static const FUID iid;
  57. };
  58. DECLARE_CLASS_IID (IUpdateManager, 0x030B780C, 0xD6E6418D, 0x8CE00BC2, 0x09C834D4)
  59. //------------------------------------------------------------------------------
  60. /**
  61. UpdateHandler implements IUpdateManager and IUpdateHandler to handle dependencies
  62. between objects to store and forward messages to dependent objects.
  63. This implementation is thread save, so objects can send message, add or remove
  64. dependents from different threads.
  65. Do do so it uses mutex, so be aware of locking.
  66. */
  67. //------------------------------------------------------------------------------
  68. class UpdateHandler : public FObject, public IUpdateHandler, public IUpdateManager
  69. {
  70. public:
  71. //------------------------------------------------------------------------------
  72. UpdateHandler ();
  73. ~UpdateHandler ();
  74. // IUpdateHandler
  75. /** register \param dependent to get messages from \param object */
  76. virtual tresult PLUGIN_API addDependent (FUnknown* object, IDependent* dependent) SMTG_OVERRIDE;
  77. /** unregister \param dependent to get no messages from \param object */
  78. virtual tresult PLUGIN_API removeDependent (FUnknown* object,
  79. IDependent* dependent) SMTG_OVERRIDE;
  80. /** send \param message to all dependents of \param object immediately */
  81. virtual tresult PLUGIN_API triggerUpdates (FUnknown* object, int32 message) SMTG_OVERRIDE;
  82. /** send \param message to all dependents of \param object when idle */
  83. virtual tresult PLUGIN_API deferUpdates (FUnknown* object, int32 message) SMTG_OVERRIDE;
  84. // IUpdateManager
  85. /** cancel pending messages send by \param object or by any if object is 0 */
  86. virtual tresult PLUGIN_API cancelUpdates (FUnknown* object) SMTG_OVERRIDE;
  87. /** send pending messages send by \param object or by any if object is 0 */
  88. virtual tresult PLUGIN_API triggerDeferedUpdates (FUnknown* object = 0) SMTG_OVERRIDE;
  89. /// @cond ignore
  90. // obsolete functions kept for compatibility
  91. void checkUpdates (FObject* object = 0) { triggerDeferedUpdates (object->unknownCast ()); }
  92. void flushUpdates (FObject* object) { cancelUpdates (object->unknownCast ()); }
  93. void deferUpdate (FObject* object, int32 message)
  94. {
  95. deferUpdates (object->unknownCast (), message);
  96. }
  97. void signalChange (FObject* object, int32 message, bool suppressUpdateDone = false)
  98. {
  99. doTriggerUpdates (object->unknownCast (), message, suppressUpdateDone);
  100. }
  101. #if DEVELOPMENT
  102. bool checkDeferred (FUnknown* object);
  103. bool hasDependencies (FUnknown* object);
  104. void printForObject (FObject* object) const;
  105. #endif
  106. /// @endcond
  107. OBJ_METHODS (UpdateHandler, FObject)
  108. FUNKNOWN_METHODS2 (IUpdateHandler, IUpdateManager, FObject)
  109. SINGLETON (UpdateHandler)
  110. //------------------------------------------------------------------------------
  111. private:
  112. tresult doTriggerUpdates (FUnknown* object, int32 message, bool suppressUpdateDone);
  113. FLock lock;
  114. Update::Table* table;
  115. };
  116. //------------------------------------------------------------------------
  117. } // namespace Steinberg