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: asynccallback.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_toolkit.hxx"
34 #include "vcl/svapp.hxx"
35 #include "vos/mutex.hxx"
36 #include "sal/config.h"
37 #include "cppuhelper/factory.hxx"
38 #include "cppuhelper/implementationentry.hxx"
39 #include "cppuhelper/implbase2.hxx"
40 #include "com/sun/star/lang/XServiceInfo.hpp"
41 #include "com/sun/star/awt/XRequestCallback.hpp"
44 // component helper namespace
45 namespace comp_AsyncCallback
{
47 namespace css
= ::com::sun::star
;
49 // component and service helper functions:
50 ::rtl::OUString SAL_CALL
_getImplementationName();
51 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames();
52 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create( css::uno::Reference
< css::uno::XComponentContext
> const & context
);
54 } // closing component helper namespace
58 /// anonymous implementation namespace
61 namespace css
= ::com::sun::star
;
64 public ::cppu::WeakImplHelper2
<
65 css::lang::XServiceInfo
,
66 css::awt::XRequestCallback
>
69 explicit AsyncCallback(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
71 // ::com::sun::star::lang::XServiceInfo:
72 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
73 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
74 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
76 // ::com::sun::star::awt::XRequestCallback:
77 virtual void SAL_CALL
addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
);
83 CallbackData( const css::uno::Reference
< css::awt::XCallback
>& rCallback
, const css::uno::Any
& rAny
) :
84 xCallback( rCallback
), aData( rAny
) {}
86 css::uno::Reference
< css::awt::XCallback
> xCallback
;
90 DECL_STATIC_LINK( AsyncCallback
, Notify_Impl
, CallbackData
* );
92 AsyncCallback(AsyncCallback
&); // not defined
93 void operator =(AsyncCallback
&); // not defined
95 virtual ~AsyncCallback() {}
97 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
100 AsyncCallback::AsyncCallback(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
104 // com.sun.star.uno.XServiceInfo:
105 ::rtl::OUString SAL_CALL
AsyncCallback::getImplementationName() throw (css::uno::RuntimeException
)
107 return comp_AsyncCallback::_getImplementationName();
110 ::sal_Bool SAL_CALL
AsyncCallback::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
112 const css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_AsyncCallback::_getSupportedServiceNames();
113 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
114 if (serviceNames
[i
] == serviceName
)
120 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException
)
122 return comp_AsyncCallback::_getSupportedServiceNames();
125 // ::com::sun::star::awt::XRequestCallback:
126 void SAL_CALL
AsyncCallback::addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
)
128 if ( Application::IsInMain() )
130 osl::Guard
< vos::IMutex
> aSolarGuard( Application::GetSolarMutex() );
131 CallbackData
* pCallbackData
= new CallbackData( xCallback
, aData
);
132 Application::PostUserEvent( STATIC_LINK( this, AsyncCallback
, Notify_Impl
), pCallbackData
);
136 // private asynchronous link to call reference to the callback object
137 IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback
, Notify_Impl
, CallbackData
*, pCallbackData
)
141 // Asynchronous execution
142 // Check pointer and reference before!
143 if ( pCallbackData
&& pCallbackData
->xCallback
.is() )
144 pCallbackData
->xCallback
->notify( pCallbackData
->aData
);
146 catch ( css::uno::Exception
& )
150 delete pCallbackData
;
154 } // closing anonymous implementation namespace
158 // component helper namespace
159 namespace comp_AsyncCallback
{
161 ::rtl::OUString SAL_CALL
_getImplementationName() {
162 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
163 "com.sun.star.awt.comp.AsyncCallback"));
166 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
168 css::uno::Sequence
< ::rtl::OUString
> s(1);
169 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
170 "com.sun.star.awt.AsyncCallback"));
174 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
175 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
176 SAL_THROW((css::uno::Exception
))
178 return static_cast< ::cppu::OWeakObject
* >(new AsyncCallback(context
));
181 } // closing component helper namespace
183 static ::cppu::ImplementationEntry
const entries
[] = {
184 { &comp_AsyncCallback::_create
,
185 &comp_AsyncCallback::_getImplementationName
,
186 &comp_AsyncCallback::_getSupportedServiceNames
,
187 &::cppu::createSingleComponentFactory
, 0, 0 },
191 void * SAL_CALL
comp_AsyncCallback_component_getFactory(
192 const char * implName
, void * serviceManager
, void * registryKey
)
194 return ::cppu::component_getFactoryHelper(
195 implName
, serviceManager
, registryKey
, entries
);
198 sal_Bool SAL_CALL
comp_AsyncCallback_component_writeInfo(
199 void * serviceManager
, void * registryKey
)
201 return ::cppu::component_writeInfoHelper(serviceManager
, registryKey
, entries
);