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