Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / test / mtexecutor / mainthreadexecutor.cxx
blob1a0b70f6fa64a2dc4f9f4ba2d937502e15412321
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;
27 //-------------------------------------------------------------------------
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;
36 //-------------------------------------------------------------------------
37 OUString SAL_CALL MainThreadExecutor::impl_staticGetImplementationName()
39 return OUString("com.sun.star.comp.thread.MainThreadExecutor");
42 //-------------------------------------------------------------------------
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 ) );
49 //-------------------------------------------------------------------------
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( STATIC_LINK( NULL, MainThreadExecutor, worker ), pMainThreadExecutorRequest );
75 // TODO: wait for result
76 return uno::Any();
79 //-------------------------------------------------------------------------
80 IMPL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, pThreadExecutorRequest )
82 pThreadExecutorRequest->doIt();
84 delete pThreadExecutorRequest;
85 return 0;
88 //-------------------------------------------------------------------------
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);
101 //-------------------------------------------------------------------------
102 uno::Sequence< OUString > SAL_CALL MainThreadExecutor::getSupportedServiceNames()
103 throw ( uno::RuntimeException )
105 return impl_staticGetSupportedServiceNames();
108 //-------------------------------------------------------------------------
109 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference< task::XJob >& xJob,
110 const uno::Sequence< beans::NamedValue >& aValues )
111 : m_xJob( xJob )
112 , m_aValues( aValues )
116 //-------------------------------------------------------------------------
117 void MainThreadExecutorRequest::doIt()
119 if ( m_xJob.is() )
120 m_xJob->execute( m_aValues );
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */