1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "vcl/svapp.hxx" 32*cdf0e10cSrcweir #include "vos/mutex.hxx" 33*cdf0e10cSrcweir #include "sal/config.h" 34*cdf0e10cSrcweir #include "cppuhelper/factory.hxx" 35*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 36*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 37*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 38*cdf0e10cSrcweir #include "com/sun/star/awt/XRequestCallback.hpp" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // component helper namespace 42*cdf0e10cSrcweir namespace comp_AsyncCallback { 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace css = ::com::sun::star; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir // component and service helper functions: 47*cdf0e10cSrcweir ::rtl::OUString SAL_CALL _getImplementationName(); 48*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames(); 49*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context ); 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir } // closing component helper namespace 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir /// anonymous implementation namespace 56*cdf0e10cSrcweir namespace { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace css = ::com::sun::star; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir class AsyncCallback: 61*cdf0e10cSrcweir public ::cppu::WeakImplHelper2< 62*cdf0e10cSrcweir css::lang::XServiceInfo, 63*cdf0e10cSrcweir css::awt::XRequestCallback> 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir public: 66*cdf0e10cSrcweir explicit AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // ::com::sun::star::lang::XServiceInfo: 69*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException); 70*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException); 71*cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir // ::com::sun::star::awt::XRequestCallback: 74*cdf0e10cSrcweir virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir private: 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir struct CallbackData 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) : 81*cdf0e10cSrcweir xCallback( rCallback ), aData( rAny ) {} 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir css::uno::Reference< css::awt::XCallback > xCallback; 84*cdf0e10cSrcweir css::uno::Any aData; 85*cdf0e10cSrcweir }; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir DECL_STATIC_LINK( AsyncCallback, Notify_Impl, CallbackData* ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir AsyncCallback(AsyncCallback &); // not defined 90*cdf0e10cSrcweir void operator =(AsyncCallback &); // not defined 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir virtual ~AsyncCallback() {} 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_xContext; 95*cdf0e10cSrcweir }; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir AsyncCallback::AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context) : 98*cdf0e10cSrcweir m_xContext(context) 99*cdf0e10cSrcweir {} 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // com.sun.star.uno.XServiceInfo: 102*cdf0e10cSrcweir ::rtl::OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir return comp_AsyncCallback::_getImplementationName(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir ::sal_Bool SAL_CALL AsyncCallback::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString > serviceNames = comp_AsyncCallback::_getSupportedServiceNames(); 110*cdf0e10cSrcweir for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) { 111*cdf0e10cSrcweir if (serviceNames[i] == serviceName) 112*cdf0e10cSrcweir return sal_True; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir return sal_False; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir return comp_AsyncCallback::_getSupportedServiceNames(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // ::com::sun::star::awt::XRequestCallback: 123*cdf0e10cSrcweir void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir if ( Application::IsInMain() ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir osl::Guard< vos::IMutex > aSolarGuard( Application::GetSolarMutex() ); 128*cdf0e10cSrcweir CallbackData* pCallbackData = new CallbackData( xCallback, aData ); 129*cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // private asynchronous link to call reference to the callback object 134*cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir try 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir // Asynchronous execution 139*cdf0e10cSrcweir // Check pointer and reference before! 140*cdf0e10cSrcweir if ( pCallbackData && pCallbackData->xCallback.is() ) 141*cdf0e10cSrcweir pCallbackData->xCallback->notify( pCallbackData->aData ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir catch ( css::uno::Exception& ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir delete pCallbackData; 148*cdf0e10cSrcweir return 0; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir } // closing anonymous implementation namespace 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // component helper namespace 156*cdf0e10cSrcweir namespace comp_AsyncCallback { 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir ::rtl::OUString SAL_CALL _getImplementationName() { 159*cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 160*cdf0e10cSrcweir "com.sun.star.awt.comp.AsyncCallback")); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames() 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > s(1); 166*cdf0e10cSrcweir s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 167*cdf0e10cSrcweir "com.sun.star.awt.AsyncCallback")); 168*cdf0e10cSrcweir return s; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL _create( 172*cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext > & context) 173*cdf0e10cSrcweir SAL_THROW((css::uno::Exception)) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir return static_cast< ::cppu::OWeakObject * >(new AsyncCallback(context)); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir } // closing component helper namespace 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir static ::cppu::ImplementationEntry const entries[] = { 181*cdf0e10cSrcweir { &comp_AsyncCallback::_create, 182*cdf0e10cSrcweir &comp_AsyncCallback::_getImplementationName, 183*cdf0e10cSrcweir &comp_AsyncCallback::_getSupportedServiceNames, 184*cdf0e10cSrcweir &::cppu::createSingleComponentFactory, 0, 0 }, 185*cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 186*cdf0e10cSrcweir }; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void * SAL_CALL comp_AsyncCallback_component_getFactory( 189*cdf0e10cSrcweir const char * implName, void * serviceManager, void * registryKey) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir return ::cppu::component_getFactoryHelper( 192*cdf0e10cSrcweir implName, serviceManager, registryKey, entries); 193*cdf0e10cSrcweir } 194