Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / embeddedobj / test / mtexecutor / mainthreadexecutor.cxx
blob7612156feea0410aa3c956d84461616aa1d20b15
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "mainthreadexecutor.hxx"
31 #include <vcl/svapp.hxx>
33 using namespace ::com::sun::star;
35 //-------------------------------------------------------------------------
36 uno::Sequence< ::rtl::OUString > SAL_CALL MainThreadExecutor::impl_staticGetSupportedServiceNames()
38 uno::Sequence< ::rtl::OUString > aRet(2);
39 aRet[0] = "com.sun.star.thread.MainThreadExecutor";
40 aRet[1] = "com.sun.star.comp.thread.MainThreadExecutor";
41 return aRet;
44 //-------------------------------------------------------------------------
45 ::rtl::OUString SAL_CALL MainThreadExecutor::impl_staticGetImplementationName()
47 return ::rtl::OUString("com.sun.star.comp.thread.MainThreadExecutor");
50 //-------------------------------------------------------------------------
51 uno::Reference< uno::XInterface > SAL_CALL MainThreadExecutor::impl_staticCreateSelfInstance(
52 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
54 return uno::Reference< uno::XInterface >( *new MainThreadExecutor( xServiceManager ) );
57 //-------------------------------------------------------------------------
58 uno::Any SAL_CALL MainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
59 throw ( lang::IllegalArgumentException,
60 uno::Exception,
61 uno::RuntimeException )
63 uno::Reference< task::XJob > xJob;
64 uno::Sequence< beans::NamedValue > aValues;
65 sal_Int32 nValuesSize = 0;
67 for ( sal_Int32 nInd = 0; nInd < aArguments.getLength(); nInd++ )
68 if ( aArguments[nInd].Name == "JobToExecute" )
69 aArguments[nInd].Value >>= xJob;
70 else
72 aValues.realloc( ++nValuesSize );
73 aValues[nValuesSize-1].Name = aArguments[nInd].Name;
74 aValues[nValuesSize-1].Value = aArguments[nInd].Value;
77 if ( xJob.is() )
79 MainThreadExecutorRequest* pMainThreadExecutorRequest = new MainThreadExecutorRequest( xJob, aValues );
80 Application::PostUserEvent( STATIC_LINK( NULL, MainThreadExecutor, worker ), pMainThreadExecutorRequest );
83 // TODO: wait for result
84 return uno::Any();
87 //-------------------------------------------------------------------------
88 IMPL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, pThreadExecutorRequest )
90 pThreadExecutorRequest->doIt();
92 delete pThreadExecutorRequest;
93 return 0;
96 //-------------------------------------------------------------------------
97 ::rtl::OUString SAL_CALL MainThreadExecutor::getImplementationName()
98 throw ( uno::RuntimeException )
100 return impl_staticGetImplementationName();
103 //-------------------------------------------------------------------------
104 sal_Bool SAL_CALL MainThreadExecutor::supportsService( const ::rtl::OUString& ServiceName )
105 throw ( uno::RuntimeException )
107 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
109 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
110 if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
111 return sal_True;
113 return sal_False;
116 //-------------------------------------------------------------------------
117 uno::Sequence< ::rtl::OUString > SAL_CALL MainThreadExecutor::getSupportedServiceNames()
118 throw ( uno::RuntimeException )
120 return impl_staticGetSupportedServiceNames();
123 //-------------------------------------------------------------------------
124 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference< task::XJob >& xJob,
125 const uno::Sequence< beans::NamedValue >& aValues )
126 : m_xJob( xJob )
127 , m_aValues( aValues )
131 //-------------------------------------------------------------------------
132 void MainThreadExecutorRequest::doIt()
134 if ( m_xJob.is() )
135 m_xJob->execute( m_aValues );
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */