2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 // (This file gets included by juce_android_NativeCode.cpp, rather than being
27 // compiled on its own).
28 #if JUCE_INCLUDED_FILE
31 //==============================================================================
32 void MessageManager::doPlatformSpecificInitialisation() {}
33 void MessageManager::doPlatformSpecificShutdown() {}
35 //==============================================================================
36 bool MessageManager::dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages
)
38 Logger::outputDebugString ("*** Modal loops are not possible in Android!! Exiting...");
44 //==============================================================================
45 bool MessageManager::postMessageToSystemQueue (Message
* message
)
47 message
->incReferenceCount();
48 getEnv()->CallVoidMethod (android
.activity
, android
.postMessage
, (jlong
) (pointer_sized_uint
) message
);
52 JUCE_JNI_CALLBACK (JuceAppActivity
, deliverMessage
, void, (jobject activity
, jlong value
))
54 Message
* const message
= (Message
*) (pointer_sized_uint
) value
;
55 MessageManager::getInstance()->deliverMessage (message
);
56 message
->decReferenceCount();
59 //==============================================================================
60 class AsyncFunctionCaller
: public AsyncUpdater
63 static void* call (MessageCallbackFunction
* func_
, void* parameter_
)
65 if (MessageManager::getInstance()->isThisTheMessageThread())
66 return func_ (parameter_
);
68 AsyncFunctionCaller
caller (func_
, parameter_
);
69 caller
.triggerAsyncUpdate();
70 caller
.finished
.wait();
74 void handleAsyncUpdate()
76 result
= (*func
) (parameter
);
81 WaitableEvent finished
;
82 MessageCallbackFunction
* func
;
84 void* volatile result
;
86 AsyncFunctionCaller (MessageCallbackFunction
* func_
, void* parameter_
)
87 : result (0), func (func_
), parameter (parameter_
)
90 JUCE_DECLARE_NON_COPYABLE (AsyncFunctionCaller
);
93 void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction
* func
, void* parameter
)
95 return AsyncFunctionCaller::call (func
, parameter
);
98 //==============================================================================
99 void MessageManager::broadcastMessage (const String
&)
103 void MessageManager::runDispatchLoop()
107 class QuitCallback
: public CallbackMessage
112 void messageCallback()
114 android
.activity
.callVoidMethod (android
.finish
);
118 void MessageManager::stopDispatchLoop()
120 (new QuitCallback())->post();
121 quitMessagePosted
= true;