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 <vcl/svapp.hxx>
24 using namespace ::com::sun::star
;
26 //-------------------------------------------------------------------------
27 uno::Sequence
< ::rtl::OUString
> SAL_CALL
MainThreadExecutor::impl_staticGetSupportedServiceNames()
29 uno::Sequence
< ::rtl::OUString
> aRet(2);
30 aRet
[0] = "com.sun.star.thread.MainThreadExecutor";
31 aRet
[1] = "com.sun.star.comp.thread.MainThreadExecutor";
35 //-------------------------------------------------------------------------
36 ::rtl::OUString SAL_CALL
MainThreadExecutor::impl_staticGetImplementationName()
38 return ::rtl::OUString("com.sun.star.comp.thread.MainThreadExecutor");
41 //-------------------------------------------------------------------------
42 uno::Reference
< uno::XInterface
> SAL_CALL
MainThreadExecutor::impl_staticCreateSelfInstance(
43 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
45 return uno::Reference
< uno::XInterface
>( *new MainThreadExecutor( xServiceManager
) );
48 //-------------------------------------------------------------------------
49 uno::Any SAL_CALL
MainThreadExecutor::execute( const uno::Sequence
< beans::NamedValue
>& aArguments
)
50 throw ( lang::IllegalArgumentException
,
52 uno::RuntimeException
)
54 uno::Reference
< task::XJob
> xJob
;
55 uno::Sequence
< beans::NamedValue
> aValues
;
56 sal_Int32 nValuesSize
= 0;
58 for ( sal_Int32 nInd
= 0; nInd
< aArguments
.getLength(); nInd
++ )
59 if ( aArguments
[nInd
].Name
== "JobToExecute" )
60 aArguments
[nInd
].Value
>>= xJob
;
63 aValues
.realloc( ++nValuesSize
);
64 aValues
[nValuesSize
-1].Name
= aArguments
[nInd
].Name
;
65 aValues
[nValuesSize
-1].Value
= aArguments
[nInd
].Value
;
70 MainThreadExecutorRequest
* pMainThreadExecutorRequest
= new MainThreadExecutorRequest( xJob
, aValues
);
71 Application::PostUserEvent( STATIC_LINK( NULL
, MainThreadExecutor
, worker
), pMainThreadExecutorRequest
);
74 // TODO: wait for result
78 //-------------------------------------------------------------------------
79 IMPL_STATIC_LINK( MainThreadExecutor
, worker
, MainThreadExecutorRequest
*, pThreadExecutorRequest
)
81 pThreadExecutorRequest
->doIt();
83 delete pThreadExecutorRequest
;
87 //-------------------------------------------------------------------------
88 ::rtl::OUString SAL_CALL
MainThreadExecutor::getImplementationName()
89 throw ( uno::RuntimeException
)
91 return impl_staticGetImplementationName();
94 //-------------------------------------------------------------------------
95 sal_Bool SAL_CALL
MainThreadExecutor::supportsService( const ::rtl::OUString
& ServiceName
)
96 throw ( uno::RuntimeException
)
98 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_staticGetSupportedServiceNames();
100 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
101 if ( ServiceName
.compareTo( aSeq
[nInd
] ) == 0 )
107 //-------------------------------------------------------------------------
108 uno::Sequence
< ::rtl::OUString
> SAL_CALL
MainThreadExecutor::getSupportedServiceNames()
109 throw ( uno::RuntimeException
)
111 return impl_staticGetSupportedServiceNames();
114 //-------------------------------------------------------------------------
115 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference
< task::XJob
>& xJob
,
116 const uno::Sequence
< beans::NamedValue
>& aValues
)
118 , m_aValues( aValues
)
122 //-------------------------------------------------------------------------
123 void MainThreadExecutorRequest::doIt()
126 m_xJob
->execute( m_aValues
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */