Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / embeddedobj / test / mtexecutor / mainthreadexecutor.cxx
blob1fc7d2e3cc31b9f5bc05ca3c704dab5fac335300
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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()
30 uno::Sequence< OUString > aRet(2);
31 aRet[0] = "com.sun.star.thread.MainThreadExecutor";
32 aRet[1] = "com.sun.star.comp.thread.MainThreadExecutor";
33 return aRet;
37 OUString SAL_CALL MainThreadExecutor::impl_staticGetImplementationName()
39 return OUString("com.sun.star.comp.thread.MainThreadExecutor");
43 uno::Reference< uno::XInterface > SAL_CALL MainThreadExecutor::impl_staticCreateSelfInstance(
44 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
46 return uno::Reference< uno::XInterface >( *new MainThreadExecutor( xServiceManager ) );
50 uno::Any SAL_CALL MainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
51 throw ( lang::IllegalArgumentException,
52 uno::Exception,
53 uno::RuntimeException )
55 uno::Reference< task::XJob > xJob;
56 uno::Sequence< beans::NamedValue > aValues;
57 sal_Int32 nValuesSize = 0;
59 for ( sal_Int32 nInd = 0; nInd < aArguments.getLength(); nInd++ )
60 if ( aArguments[nInd].Name == "JobToExecute" )
61 aArguments[nInd].Value >>= xJob;
62 else
64 aValues.realloc( ++nValuesSize );
65 aValues[nValuesSize-1].Name = aArguments[nInd].Name;
66 aValues[nValuesSize-1].Value = aArguments[nInd].Value;
69 if ( xJob.is() )
71 MainThreadExecutorRequest* pMainThreadExecutorRequest = new MainThreadExecutorRequest( xJob, aValues );
72 Application::PostUserEvent( LINK( NULL, MainThreadExecutor, worker ), pMainThreadExecutorRequest );
75 // TODO: wait for result
76 return uno::Any();
80 IMPL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, pThreadExecutorRequest, void )
82 pThreadExecutorRequest->doIt();
84 delete pThreadExecutorRequest;
88 OUString SAL_CALL MainThreadExecutor::getImplementationName()
89 throw ( uno::RuntimeException )
91 return impl_staticGetImplementationName();
94 sal_Bool SAL_CALL MainThreadExecutor::supportsService( const OUString& ServiceName )
95 throw ( uno::RuntimeException )
97 return cppu::supportsService(this, ServiceName);
101 uno::Sequence< OUString > SAL_CALL MainThreadExecutor::getSupportedServiceNames()
102 throw ( uno::RuntimeException )
104 return impl_staticGetSupportedServiceNames();
108 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference< task::XJob >& xJob,
109 const uno::Sequence< beans::NamedValue >& aValues )
110 : m_xJob( xJob )
111 , m_aValues( aValues )
116 void MainThreadExecutorRequest::doIt()
118 if ( m_xJob.is() )
119 m_xJob->execute( m_aValues );
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */