1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svmainhook.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/tools.h>
37 BOOL
ImplSVMainHook( BOOL
* )
39 return FALSE
; // indicate that ImplSVMainHook is not implemented
43 // MACOSX cocoa implementation of ImplSVMainHook is in aqua/source/app/salinst.cxx
44 #ifndef QUARTZ // MACOSX (X11) needs the CFRunLoop()
45 #include <osl/thread.h>
47 #include <CoreFoundation/CoreFoundation.h>
51 extern BOOL
ImplSVMain();
53 // ============================================================================
56 static void SourceContextCallBack( void *pInfo
)
63 CFRunLoopRef
* pRunLoopRef
;
66 static void RunSVMain(void *pData
)
68 ThreadContext
* tcx
= reinterpret_cast<ThreadContext
*>(pData
);
70 // busy waiting (ok in this case) until the run loop is
72 while (!CFRunLoopIsWaiting(*tcx
->pRunLoopRef
))
75 *tcx
->pRet
= ImplSVMain();
77 // Force exit since some JVMs won't shutdown when only exit() is invoked
81 BOOL
ImplSVMainHook( BOOL
*pbInit
)
83 // Mac OS X requires that any Cocoa code have a CFRunLoop started in the
84 // primordial thread. Since all of the AWT classes in Java 1.4 and higher
85 // are written in Cocoa, we need to start the CFRunLoop here and run
86 // ImplSVMain() in a secondary thread.
87 // See http://developer.apple.com/samplecode/simpleJavaLauncher/listing3.html
88 // for further details and an example
90 CFRunLoopRef runLoopRef
= CFRunLoopGetCurrent();
92 tcx
.pRet
= pbInit
; // the return value
93 tcx
.pRunLoopRef
= &runLoopRef
;
94 oslThread hThreadID
= osl_createThread(RunSVMain
, &tcx
);
96 // Start the CFRunLoop
97 CFRunLoopSourceContext aSourceContext
;
98 aSourceContext
.version
= 0;
99 aSourceContext
.info
= NULL
;
100 aSourceContext
.retain
= NULL
;
101 aSourceContext
.release
= NULL
;
102 aSourceContext
.copyDescription
= NULL
;
103 aSourceContext
.equal
= NULL
;
104 aSourceContext
.hash
= NULL
;
105 aSourceContext
.schedule
= NULL
;
106 aSourceContext
.cancel
= NULL
;
107 aSourceContext
.perform
= &SourceContextCallBack
;
108 CFRunLoopSourceRef aSourceRef
= CFRunLoopSourceCreate(NULL
, 0, &aSourceContext
);
109 CFRunLoopAddSource(runLoopRef
, aSourceRef
, kCFRunLoopCommonModes
);
112 osl_joinWithThread( hThreadID
);
113 osl_destroyThread( hThreadID
);
115 return TRUE
; // indicate that ImplSVMainHook is implemented