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.

125 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // (This file gets included by juce_android_NativeCode.cpp, rather than being
  19. // compiled on its own).
  20. #if JUCE_INCLUDED_FILE
  21. //==============================================================================
  22. void MessageManager::doPlatformSpecificInitialisation() {}
  23. void MessageManager::doPlatformSpecificShutdown() {}
  24. //==============================================================================
  25. bool MessageManager::dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  26. {
  27. Logger::outputDebugString ("*** Modal loops are not possible in Android!! Exiting...");
  28. exit (1);
  29. return true;
  30. }
  31. //==============================================================================
  32. bool MessageManager::postMessageToSystemQueue (Message* message)
  33. {
  34. message->incReferenceCount();
  35. getEnv()->CallVoidMethod (android.activity, JuceAppActivity.postMessage, (jlong) (pointer_sized_uint) message);
  36. return true;
  37. }
  38. JUCE_JNI_CALLBACK (JuceAppActivity, deliverMessage, void, (jobject activity, jlong value))
  39. {
  40. Message* const message = (Message*) (pointer_sized_uint) value;
  41. MessageManager::getInstance()->deliverMessage (message);
  42. message->decReferenceCount();
  43. }
  44. //==============================================================================
  45. class AsyncFunctionCaller : public AsyncUpdater
  46. {
  47. public:
  48. static void* call (MessageCallbackFunction* func_, void* parameter_)
  49. {
  50. if (MessageManager::getInstance()->isThisTheMessageThread())
  51. return func_ (parameter_);
  52. AsyncFunctionCaller caller (func_, parameter_);
  53. caller.triggerAsyncUpdate();
  54. caller.finished.wait();
  55. return caller.result;
  56. }
  57. void handleAsyncUpdate()
  58. {
  59. result = (*func) (parameter);
  60. finished.signal();
  61. }
  62. private:
  63. WaitableEvent finished;
  64. MessageCallbackFunction* func;
  65. void* parameter;
  66. void* volatile result;
  67. AsyncFunctionCaller (MessageCallbackFunction* func_, void* parameter_)
  68. : result (0), func (func_), parameter (parameter_)
  69. {}
  70. JUCE_DECLARE_NON_COPYABLE (AsyncFunctionCaller);
  71. };
  72. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func, void* parameter)
  73. {
  74. return AsyncFunctionCaller::call (func, parameter);
  75. }
  76. //==============================================================================
  77. void MessageManager::broadcastMessage (const String&)
  78. {
  79. }
  80. void MessageManager::runDispatchLoop()
  81. {
  82. }
  83. class QuitCallback : public CallbackMessage
  84. {
  85. public:
  86. QuitCallback() {}
  87. void messageCallback()
  88. {
  89. android.activity.callVoidMethod (JuceAppActivity.finish);
  90. }
  91. };
  92. void MessageManager::stopDispatchLoop()
  93. {
  94. (new QuitCallback())->post();
  95. quitMessagePosted = true;
  96. }
  97. #endif