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 "xexecutor.hxx"
21 #include <vcl/svapp.hxx>
22 #include <osl/thread.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 using namespace ::com::sun::star
;
27 void MainThreadExecutor_Impl::execute()
29 Application::PostUserEvent( LINK( this, MainThreadExecutor_Impl
, executor
), NULL
);
32 IMPL_LINK_NOARG( MainThreadExecutor_Impl
, executor
, void*, void )
37 m_xJob
->execute( m_aArgs
);
38 } catch( uno::Exception
& ) {}
41 m_bExecuted
= sal_True
;
45 MainThreadExecutor_Impl::MainThreadExecutor_Impl( const uno::Reference
< task::XJob
>& xJob
,
46 const uno::Sequence
< beans::NamedValue
>& aArguments
)
48 , m_aArgs( aArguments
)
49 , m_bExecuted( sal_False
)
54 uno::Any SAL_CALL
UNOMainThreadExecutor::execute( const uno::Sequence
< beans::NamedValue
>& aArguments
)
55 throw ( lang::IllegalArgumentException
,
57 uno::RuntimeException
)
59 uno::Reference
< task::XJob
> xJob
;
61 if ( aArguments
.getLength() > 0 && aArguments
[0].Name
== "JobToExecute" )
62 aArguments
[0].Value
>>= xJob
;
65 throw lang::IllegalArgumentException();
67 uno::Sequence
< beans::NamedValue
> aArgsForJob
;
68 if ( aArguments
.getLength() > 1 )
69 aArgsForJob
= uno::Sequence
< beans::NamedValue
>( aArguments
.getConstArray() + 1, aArguments
.getLength() - 1 );
71 MainThreadExecutor_Impl
* pExecutor
= new MainThreadExecutor_Impl( xJob
, aArgsForJob
);
74 // it is not a main thread, so it can be blocked
75 // while( !pExecutor->isExecuted() )
76 // ::osl::Thread::yield();
78 // TODO: implement transferring of the return values and exceptions
84 uno::Sequence
< OUString
> SAL_CALL
UNOMainThreadExecutor::impl_staticGetSupportedServiceNames()
86 uno::Sequence
< OUString
> aRet
{ "com.sun.star.comp.thread.MainThreadExecutor" };
91 OUString SAL_CALL
UNOMainThreadExecutor::impl_staticGetImplementationName()
93 return OUString("com.sun.star.comp.thread.MainThreadExecutor");
97 uno::Reference
< uno::XInterface
> SAL_CALL
UNOMainThreadExecutor::impl_staticCreateSelfInstance(
98 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
100 return uno::Reference
< uno::XInterface
>( *new UNOMainThreadExecutor( xServiceManager
) );
104 OUString SAL_CALL
UNOMainThreadExecutor::getImplementationName()
105 throw ( uno::RuntimeException
)
107 return impl_staticGetImplementationName();
110 sal_Bool SAL_CALL
UNOMainThreadExecutor::supportsService( const OUString
& ServiceName
)
111 throw ( uno::RuntimeException
)
113 return cppu::supportsService(this, ServiceName
);
117 uno::Sequence
< OUString
> SAL_CALL
UNOMainThreadExecutor::getSupportedServiceNames()
118 throw ( uno::RuntimeException
)
120 return impl_staticGetSupportedServiceNames();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */