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
)
37 m_xJob
->execute( m_aArgs
);
38 } catch( uno::Exception
& ) {}
41 m_bExecuted
= sal_True
;
47 MainThreadExecutor_Impl::MainThreadExecutor_Impl( const uno::Reference
< task::XJob
>& xJob
,
48 const uno::Sequence
< beans::NamedValue
>& aArguments
)
50 , m_aArgs( aArguments
)
51 , m_bExecuted( sal_False
)
56 uno::Any SAL_CALL
UNOMainThreadExecutor::execute( const uno::Sequence
< beans::NamedValue
>& aArguments
)
57 throw ( lang::IllegalArgumentException
,
59 uno::RuntimeException
)
61 uno::Reference
< task::XJob
> xJob
;
63 if ( aArguments
.getLength() > 0 && aArguments
[0].Name
== "JobToExecute" )
64 aArguments
[0].Value
>>= xJob
;
67 throw lang::IllegalArgumentException();
69 uno::Sequence
< beans::NamedValue
> aArgsForJob
;
70 if ( aArguments
.getLength() > 1 )
71 aArgsForJob
= uno::Sequence
< beans::NamedValue
>( aArguments
.getConstArray() + 1, aArguments
.getLength() - 1 );
73 MainThreadExecutor_Impl
* pExecutor
= new MainThreadExecutor_Impl( xJob
, aArgsForJob
);
76 // it is not a main thread, so it can be blocked
77 // while( !pExecutor->isExecuted() )
78 // ::osl::Thread::yield();
80 // TODO: implement transferring of the return values and exceptions
86 uno::Sequence
< OUString
> SAL_CALL
UNOMainThreadExecutor::impl_staticGetSupportedServiceNames()
88 uno::Sequence
< OUString
> aRet(1);
89 aRet
[0] = "com.sun.star.comp.thread.MainThreadExecutor";
94 OUString SAL_CALL
UNOMainThreadExecutor::impl_staticGetImplementationName()
96 return OUString("com.sun.star.comp.thread.MainThreadExecutor");
100 uno::Reference
< uno::XInterface
> SAL_CALL
UNOMainThreadExecutor::impl_staticCreateSelfInstance(
101 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
103 return uno::Reference
< uno::XInterface
>( *new UNOMainThreadExecutor( xServiceManager
) );
107 OUString SAL_CALL
UNOMainThreadExecutor::getImplementationName()
108 throw ( uno::RuntimeException
)
110 return impl_staticGetImplementationName();
113 sal_Bool SAL_CALL
UNOMainThreadExecutor::supportsService( const OUString
& ServiceName
)
114 throw ( uno::RuntimeException
)
116 return cppu::supportsService(this, ServiceName
);
120 uno::Sequence
< OUString
> SAL_CALL
UNOMainThreadExecutor::getSupportedServiceNames()
121 throw ( uno::RuntimeException
)
123 return impl_staticGetSupportedServiceNames();
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */