bump product version to 4.1.6.2
[LibreOffice.git] / toolkit / source / awt / asynccallback.cxx
blob1f30e8fd598aa1ef2e0ffa2a587a1df8a194b533
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "vcl/svapp.hxx"
22 #include "osl/mutex.hxx"
23 #include "sal/config.h"
24 #include "cppuhelper/factory.hxx"
25 #include "cppuhelper/implementationentry.hxx"
26 #include "cppuhelper/implbase2.hxx"
27 #include "com/sun/star/lang/XServiceInfo.hpp"
28 #include "com/sun/star/awt/XRequestCallback.hpp"
31 // component helper namespace
32 namespace comp_AsyncCallback {
34 // component and service helper functions:
35 OUString SAL_CALL _getImplementationName();
36 css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames();
37 css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context );
39 } // closing component helper namespace
43 /// anonymous implementation namespace
44 namespace {
46 class AsyncCallback:
47 public ::cppu::WeakImplHelper2<
48 css::lang::XServiceInfo,
49 css::awt::XRequestCallback>
51 public:
52 explicit AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context);
54 // ::com::sun::star::lang::XServiceInfo:
55 virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
56 virtual ::sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException);
57 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
59 // ::com::sun::star::awt::XRequestCallback:
60 virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException);
62 private:
64 struct CallbackData
66 CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
67 xCallback( rCallback ), aData( rAny ) {}
69 css::uno::Reference< css::awt::XCallback > xCallback;
70 css::uno::Any aData;
73 DECL_STATIC_LINK( AsyncCallback, Notify_Impl, CallbackData* );
75 AsyncCallback(AsyncCallback &); // not defined
76 void operator =(AsyncCallback &); // not defined
78 virtual ~AsyncCallback() {}
80 css::uno::Reference< css::uno::XComponentContext > m_xContext;
83 AsyncCallback::AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context) :
84 m_xContext(context)
87 // com.sun.star.uno.XServiceInfo:
88 OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException)
90 return comp_AsyncCallback::_getImplementationName();
93 ::sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException)
95 const css::uno::Sequence< OUString > serviceNames = comp_AsyncCallback::_getSupportedServiceNames();
96 for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
97 if (serviceNames[i] == serviceName)
98 return sal_True;
100 return sal_False;
103 css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException)
105 return comp_AsyncCallback::_getSupportedServiceNames();
108 // ::com::sun::star::awt::XRequestCallback:
109 void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException)
111 if ( Application::IsInMain() )
113 SolarMutexGuard aSolarGuard;
115 CallbackData* pCallbackData = new CallbackData( xCallback, aData );
116 Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
120 // private asynchronous link to call reference to the callback object
121 IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData )
125 // Asynchronous execution
126 // Check pointer and reference before!
127 if ( pCallbackData && pCallbackData->xCallback.is() )
128 pCallbackData->xCallback->notify( pCallbackData->aData );
130 catch ( css::uno::Exception& )
134 delete pCallbackData;
135 return 0;
138 } // closing anonymous implementation namespace
142 // component helper namespace
143 namespace comp_AsyncCallback {
145 OUString SAL_CALL _getImplementationName() {
146 return OUString("com.sun.star.awt.comp.AsyncCallback");
149 css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
151 css::uno::Sequence< OUString > s(1);
152 s[0] = "com.sun.star.awt.AsyncCallback";
153 return s;
156 css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
157 const css::uno::Reference< css::uno::XComponentContext > & context)
158 SAL_THROW((css::uno::Exception))
160 return static_cast< ::cppu::OWeakObject * >(new AsyncCallback(context));
163 } // closing component helper namespace
165 static ::cppu::ImplementationEntry const entries[] = {
166 { &comp_AsyncCallback::_create,
167 &comp_AsyncCallback::_getImplementationName,
168 &comp_AsyncCallback::_getSupportedServiceNames,
169 &::cppu::createSingleComponentFactory, 0, 0 },
170 { 0, 0, 0, 0, 0, 0 }
173 void * SAL_CALL comp_AsyncCallback_component_getFactory(
174 const char * implName, void * serviceManager, void * registryKey)
176 return ::cppu::component_getFactoryHelper(
177 implName, serviceManager, registryKey, entries);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */