xref: /aoo41x/main/vcl/source/app/svmainhook.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir #include <tools/tools.h>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifndef MACOSX
29cdf0e10cSrcweir 
ImplSVMainHook(sal_Bool *)30cdf0e10cSrcweir sal_Bool ImplSVMainHook( sal_Bool * )
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     return sal_False;   // indicate that ImplSVMainHook is not implemented
33cdf0e10cSrcweir }
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #else
36cdf0e10cSrcweir // MACOSX cocoa implementation of ImplSVMainHook is in aqua/source/app/salinst.cxx
37cdf0e10cSrcweir #ifndef QUARTZ  // MACOSX (X11) needs the CFRunLoop()
38cdf0e10cSrcweir #include <osl/thread.h>
39cdf0e10cSrcweir #include <premac.h>
40cdf0e10cSrcweir #include <CoreFoundation/CoreFoundation.h>
41cdf0e10cSrcweir #include <postmac.h>
42cdf0e10cSrcweir #include <unistd.h>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir extern sal_Bool ImplSVMain();
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ============================================================================
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
SourceContextCallBack(void * pInfo)49cdf0e10cSrcweir static void SourceContextCallBack( void *pInfo )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir struct ThreadContext
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     sal_Bool* pRet;
56cdf0e10cSrcweir     CFRunLoopRef* pRunLoopRef;
57cdf0e10cSrcweir };
58cdf0e10cSrcweir 
RunSVMain(void * pData)59cdf0e10cSrcweir static void RunSVMain(void *pData)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     ThreadContext* tcx = reinterpret_cast<ThreadContext*>(pData);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     // busy waiting (ok in this case) until the run loop is
64cdf0e10cSrcweir     // running
65cdf0e10cSrcweir     while (!CFRunLoopIsWaiting(*tcx->pRunLoopRef))
66cdf0e10cSrcweir         usleep(100);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     *tcx->pRet = ImplSVMain();
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     // Force exit since some JVMs won't shutdown when only exit() is invoked
71cdf0e10cSrcweir     _exit( 0 );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
ImplSVMainHook(sal_Bool * pbInit)74cdf0e10cSrcweir sal_Bool ImplSVMainHook( sal_Bool *pbInit )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     // Mac OS X requires that any Cocoa code have a CFRunLoop started in the
77cdf0e10cSrcweir     // primordial thread. Since all of the AWT classes in Java 1.4 and higher
78cdf0e10cSrcweir     // are written in Cocoa, we need to start the CFRunLoop here and run
79cdf0e10cSrcweir     // ImplSVMain() in a secondary thread.
80cdf0e10cSrcweir     // See http://developer.apple.com/samplecode/simpleJavaLauncher/listing3.html
81cdf0e10cSrcweir     // for further details and an example
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
84cdf0e10cSrcweir     ThreadContext tcx;
85cdf0e10cSrcweir     tcx.pRet = pbInit;  // the return value
86cdf0e10cSrcweir     tcx.pRunLoopRef = &runLoopRef;
87cdf0e10cSrcweir     oslThread hThreadID = osl_createThread(RunSVMain, &tcx);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     // Start the CFRunLoop
90cdf0e10cSrcweir     CFRunLoopSourceContext aSourceContext;
91cdf0e10cSrcweir     aSourceContext.version = 0;
92cdf0e10cSrcweir     aSourceContext.info = NULL;
93cdf0e10cSrcweir     aSourceContext.retain = NULL;
94cdf0e10cSrcweir     aSourceContext.release = NULL;
95cdf0e10cSrcweir     aSourceContext.copyDescription = NULL;
96cdf0e10cSrcweir     aSourceContext.equal = NULL;
97cdf0e10cSrcweir     aSourceContext.hash = NULL;
98cdf0e10cSrcweir     aSourceContext.schedule = NULL;
99cdf0e10cSrcweir     aSourceContext.cancel = NULL;
100cdf0e10cSrcweir     aSourceContext.perform = &SourceContextCallBack;
101cdf0e10cSrcweir     CFRunLoopSourceRef aSourceRef = CFRunLoopSourceCreate(NULL, 0, &aSourceContext);
102cdf0e10cSrcweir     CFRunLoopAddSource(runLoopRef, aSourceRef, kCFRunLoopCommonModes);
103cdf0e10cSrcweir     CFRunLoopRun();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     osl_joinWithThread( hThreadID );
106cdf0e10cSrcweir     osl_destroyThread( hThreadID );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     return sal_True;    // indicate that ImplSVMainHook is implemented
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir #endif // MACOSX
112cdf0e10cSrcweir #endif
113