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 "mainthreadexecutor.hxx"
22 #include <cppuhelper/supportsservice.hxx>
23 #include <vcl/svapp.hxx>
25 using namespace ::com::sun::star
;
28 uno::Sequence
< OUString
> SAL_CALL
MainThreadExecutor::impl_staticGetSupportedServiceNames()
32 "com.sun.star.thread.MainThreadExecutor",
33 "com.sun.star.comp.thread.MainThreadExecutor"
38 OUString SAL_CALL
MainThreadExecutor::impl_staticGetImplementationName()
40 return OUString("com.sun.star.comp.thread.MainThreadExecutor");
44 uno::Reference
< uno::XInterface
> SAL_CALL
MainThreadExecutor::impl_staticCreateSelfInstance(
45 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
47 return uno::Reference
< uno::XInterface
>( *new MainThreadExecutor( xServiceManager
) );
51 uno::Any SAL_CALL
MainThreadExecutor::execute( const uno::Sequence
< beans::NamedValue
>& aArguments
)
52 throw ( lang::IllegalArgumentException
,
54 uno::RuntimeException
)
56 uno::Reference
< task::XJob
> xJob
;
57 uno::Sequence
< beans::NamedValue
> aValues
;
58 sal_Int32 nValuesSize
= 0;
60 for ( sal_Int32 nInd
= 0; nInd
< aArguments
.getLength(); nInd
++ )
61 if ( aArguments
[nInd
].Name
== "JobToExecute" )
62 aArguments
[nInd
].Value
>>= xJob
;
65 aValues
.realloc( ++nValuesSize
);
66 aValues
[nValuesSize
-1].Name
= aArguments
[nInd
].Name
;
67 aValues
[nValuesSize
-1].Value
= aArguments
[nInd
].Value
;
72 MainThreadExecutorRequest
* pMainThreadExecutorRequest
= new MainThreadExecutorRequest( xJob
, aValues
);
73 Application::PostUserEvent( LINK( NULL
, MainThreadExecutor
, worker
), pMainThreadExecutorRequest
);
76 // TODO: wait for result
81 IMPL_STATIC_LINK( MainThreadExecutor
, worker
, MainThreadExecutorRequest
*, pThreadExecutorRequest
, void )
83 pThreadExecutorRequest
->doIt();
85 delete pThreadExecutorRequest
;
89 OUString SAL_CALL
MainThreadExecutor::getImplementationName()
90 throw ( uno::RuntimeException
)
92 return impl_staticGetImplementationName();
95 sal_Bool SAL_CALL
MainThreadExecutor::supportsService( const OUString
& ServiceName
)
96 throw ( uno::RuntimeException
)
98 return cppu::supportsService(this, ServiceName
);
102 uno::Sequence
< OUString
> SAL_CALL
MainThreadExecutor::getSupportedServiceNames()
103 throw ( uno::RuntimeException
)
105 return impl_staticGetSupportedServiceNames();
109 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference
< task::XJob
>& xJob
,
110 const uno::Sequence
< beans::NamedValue
>& aValues
)
112 , m_aValues( aValues
)
117 void MainThreadExecutorRequest::doIt()
120 m_xJob
->execute( m_aValues
);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */