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.

99 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. void MessageManager::runDispatchLoop()
  18. {
  19. jassert (isThisTheMessageThread()); // must only be called by the message thread
  20. while (! quitMessagePosted)
  21. {
  22. JUCE_AUTORELEASEPOOL
  23. {
  24. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  25. beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]];
  26. }
  27. }
  28. }
  29. void MessageManager::stopDispatchLoop()
  30. {
  31. if (! SystemStats::isRunningInAppExtensionSandbox())
  32. [[[UIApplication sharedApplication] delegate] applicationWillTerminate: [UIApplication sharedApplication]];
  33. exit (0); // iOS apps get no mercy..
  34. }
  35. #if JUCE_MODAL_LOOPS_PERMITTED
  36. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  37. {
  38. JUCE_AUTORELEASEPOOL
  39. {
  40. jassert (isThisTheMessageThread()); // must only be called by the message thread
  41. uint32 startTime = Time::getMillisecondCounter();
  42. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  43. while (! quitMessagePosted)
  44. {
  45. JUCE_AUTORELEASEPOOL
  46. {
  47. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  48. beforeDate: endDate];
  49. if (millisecondsToRunFor >= 0
  50. && Time::getMillisecondCounter() >= startTime + (uint32) millisecondsToRunFor)
  51. break;
  52. }
  53. }
  54. return ! quitMessagePosted;
  55. }
  56. }
  57. #endif
  58. //==============================================================================
  59. static ScopedPointer<MessageQueue> messageQueue;
  60. void MessageManager::doPlatformSpecificInitialisation()
  61. {
  62. if (messageQueue == nullptr)
  63. messageQueue = new MessageQueue();
  64. }
  65. void MessageManager::doPlatformSpecificShutdown()
  66. {
  67. messageQueue = nullptr;
  68. }
  69. bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* const message)
  70. {
  71. if (messageQueue != nullptr)
  72. messageQueue->post (message);
  73. return true;
  74. }
  75. void MessageManager::broadcastMessage (const String&)
  76. {
  77. // N/A on current iOS
  78. }