1*bfd08df8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*bfd08df8SAndrew Rist * distributed with this work for additional information
6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance
9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at
10*bfd08df8SAndrew Rist *
11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*bfd08df8SAndrew Rist *
13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an
15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the
17*bfd08df8SAndrew Rist * specific language governing permissions and limitations
18*bfd08df8SAndrew Rist * under the License.
19*bfd08df8SAndrew Rist *
20*bfd08df8SAndrew Rist *************************************************************/
21*bfd08df8SAndrew Rist
22*bfd08df8SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "mainthreadexecutor.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir
33cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()34cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL MainThreadExecutor::impl_staticGetSupportedServiceNames()
35cdf0e10cSrcweir {
36cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(2);
37cdf0e10cSrcweir aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.thread.MainThreadExecutor");
38cdf0e10cSrcweir aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.thread.MainThreadExecutor");
39cdf0e10cSrcweir return aRet;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir
42cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticGetImplementationName()43cdf0e10cSrcweir ::rtl::OUString SAL_CALL MainThreadExecutor::impl_staticGetImplementationName()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.thread.MainThreadExecutor");
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)49cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL MainThreadExecutor::impl_staticCreateSelfInstance(
50cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir return uno::Reference< uno::XInterface >( *new MainThreadExecutor( xServiceManager ) );
53cdf0e10cSrcweir }
54cdf0e10cSrcweir
55cdf0e10cSrcweir //-------------------------------------------------------------------------
execute(const uno::Sequence<beans::NamedValue> & aArguments)56cdf0e10cSrcweir uno::Any SAL_CALL MainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
57cdf0e10cSrcweir throw ( lang::IllegalArgumentException,
58cdf0e10cSrcweir uno::Exception,
59cdf0e10cSrcweir uno::RuntimeException )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir uno::Reference< task::XJob > xJob;
62cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aValues;
63cdf0e10cSrcweir sal_Int32 nValuesSize = 0;
64cdf0e10cSrcweir
65cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aArguments.getLength(); nInd++ )
66cdf0e10cSrcweir if ( aArguments[nInd].Name.equalsAscii( "JobToExecute" ) )
67cdf0e10cSrcweir aArguments[nInd].Value >>= xJob;
68cdf0e10cSrcweir else
69cdf0e10cSrcweir {
70cdf0e10cSrcweir aValues.realloc( ++nValuesSize );
71cdf0e10cSrcweir aValues[nValuesSize-1].Name = aArguments[nInd].Name;
72cdf0e10cSrcweir aValues[nValuesSize-1].Value = aArguments[nInd].Value;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir if ( xJob.is() )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir MainThreadExecutorRequest* pMainThreadExecutorRequest = new MainThreadExecutorRequest( xJob, aValues );
78cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( NULL, MainThreadExecutor, worker ), pMainThreadExecutorRequest );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir // TODO: wait for result
82cdf0e10cSrcweir return uno::Any();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir //-------------------------------------------------------------------------
IMPL_STATIC_LINK(MainThreadExecutor,worker,MainThreadExecutorRequest *,pThreadExecutorRequest)86cdf0e10cSrcweir IMPL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, pThreadExecutorRequest )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir pThreadExecutorRequest->doIt();
89cdf0e10cSrcweir
90cdf0e10cSrcweir delete pThreadExecutorRequest;
91cdf0e10cSrcweir return 0;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir //-------------------------------------------------------------------------
getImplementationName()95cdf0e10cSrcweir ::rtl::OUString SAL_CALL MainThreadExecutor::getImplementationName()
96cdf0e10cSrcweir throw ( uno::RuntimeException )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir return impl_staticGetImplementationName();
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)102cdf0e10cSrcweir sal_Bool SAL_CALL MainThreadExecutor::supportsService( const ::rtl::OUString& ServiceName )
103cdf0e10cSrcweir throw ( uno::RuntimeException )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
106cdf0e10cSrcweir
107cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
108cdf0e10cSrcweir if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
109cdf0e10cSrcweir return sal_True;
110cdf0e10cSrcweir
111cdf0e10cSrcweir return sal_False;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir //-------------------------------------------------------------------------
getSupportedServiceNames()115cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL MainThreadExecutor::getSupportedServiceNames()
116cdf0e10cSrcweir throw ( uno::RuntimeException )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return impl_staticGetSupportedServiceNames();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir //-------------------------------------------------------------------------
MainThreadExecutorRequest(const uno::Reference<task::XJob> & xJob,const uno::Sequence<beans::NamedValue> & aValues)122cdf0e10cSrcweir MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference< task::XJob >& xJob,
123cdf0e10cSrcweir const uno::Sequence< beans::NamedValue >& aValues )
124cdf0e10cSrcweir : m_xJob( xJob )
125cdf0e10cSrcweir , m_aValues( aValues )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir //-------------------------------------------------------------------------
doIt()130cdf0e10cSrcweir void MainThreadExecutorRequest::doIt()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir if ( m_xJob.is() )
133cdf0e10cSrcweir m_xJob->execute( m_aValues );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
136