1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <sal/config.h>
22 #include <vcl/svapp.hxx>
23 #include "osl/mutex.hxx"
24 #include "cppuhelper/factory.hxx"
25 #include "cppuhelper/implementationentry.hxx"
26 #include <cppuhelper/implbase.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include "com/sun/star/lang/XServiceInfo.hpp"
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include "com/sun/star/awt/XRequestCallback.hpp"
32 /// anonymous implementation namespace
36 public ::cppu::WeakImplHelper
<
37 css::lang::XServiceInfo
,
38 css::awt::XRequestCallback
>
42 AsyncCallback(const AsyncCallback
&) = delete;
43 AsyncCallback
& operator=(const AsyncCallback
&) = delete;
45 // css::lang::XServiceInfo:
46 virtual OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
, std::exception
) override
;
47 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (css::uno::RuntimeException
, std::exception
) override
;
48 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
) override
;
50 // css::awt::XRequestCallback:
51 virtual void SAL_CALL
addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const css::uno::Any
& aData
) throw (css::uno::RuntimeException
, std::exception
) override
;
57 CallbackData( const css::uno::Reference
< css::awt::XCallback
>& rCallback
, const css::uno::Any
& rAny
) :
58 xCallback( rCallback
), aData( rAny
) {}
60 css::uno::Reference
< css::awt::XCallback
> xCallback
;
64 DECL_STATIC_LINK( AsyncCallback
, Notify_Impl
, void*, void );
66 virtual ~AsyncCallback() override
{}
69 // com.sun.star.uno.XServiceInfo:
70 OUString SAL_CALL
AsyncCallback::getImplementationName() throw (css::uno::RuntimeException
, std::exception
)
72 return OUString("com.sun.star.awt.comp.AsyncCallback");
75 sal_Bool SAL_CALL
AsyncCallback::supportsService(OUString
const & serviceName
) throw (css::uno::RuntimeException
, std::exception
)
77 return cppu::supportsService(this, serviceName
);
80 css::uno::Sequence
< OUString
> SAL_CALL
AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
)
82 css::uno::Sequence
< OUString
> s
{ "com.sun.star.awt.AsyncCallback" };
86 // css::awt::XRequestCallback:
87 void SAL_CALL
AsyncCallback::addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const css::uno::Any
& aData
) throw (css::uno::RuntimeException
, std::exception
)
89 if ( Application::IsInMain() )
91 // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe
92 CallbackData
* pCallbackData
= new CallbackData( xCallback
, aData
);
93 Application::PostUserEvent( LINK( this, AsyncCallback
, Notify_Impl
), pCallbackData
);
97 // private asynchronous link to call reference to the callback object
98 IMPL_STATIC_LINK( AsyncCallback
, Notify_Impl
, void*, p
, void )
100 CallbackData
* pCallbackData
= static_cast<CallbackData
*>(p
);
103 // Asynchronous execution
104 // Check pointer and reference before!
105 if ( pCallbackData
&& pCallbackData
->xCallback
.is() )
106 pCallbackData
->xCallback
->notify( pCallbackData
->aData
);
108 catch ( css::uno::Exception
& )
112 delete pCallbackData
;
115 } // closing anonymous implementation namespace
117 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
118 com_sun_star_awt_comp_AsyncCallback_get_implementation(
119 css::uno::XComponentContext
*,
120 css::uno::Sequence
<css::uno::Any
> const &)
122 return cppu::acquire(new AsyncCallback());
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */