update dev300-m58
[ooovba.git] / embeddedobj / test / MainThreadExecutor / xexecutor.cxx
blob78dec2c3e97027a85ba777a1309635940fb59879
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xexecutor.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
34 #include "xexecutor.hxx"
35 #include <vcl/svapp.hxx>
36 #include <osl/thread.hxx>
38 using namespace ::com::sun::star;
40 void MainThreadExecutor_Impl::execute()
42 Application::PostUserEvent( LINK( this, MainThreadExecutor_Impl, executor ), NULL );
45 IMPL_LINK( MainThreadExecutor_Impl, executor, void*, pDummyParam )
47 if ( m_xJob.is() )
49 try {
50 m_xJob->execute( m_aArgs );
51 } catch( uno::Exception& ) {}
54 m_bExecuted = sal_True;
55 delete this;
57 return 0;
60 MainThreadExecutor_Impl::MainThreadExecutor_Impl( const uno::Reference< task::XJob >& xJob,
61 const uno::Sequence< beans::NamedValue >& aArguments )
62 : m_xJob( xJob )
63 , m_aArgs( aArguments )
64 , m_bExecuted( sal_False )
68 //-------------------------------------------------------------------------
69 uno::Any SAL_CALL UNOMainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
70 throw ( lang::IllegalArgumentException,
71 uno::Exception,
72 uno::RuntimeException )
74 uno::Reference< task::XJob > xJob;
76 if ( aArguments.getLength() > 0 && aArguments[0].Name.equalsAscii( "JobToExecute" ) )
77 aArguments[0].Value >>= xJob;
79 if ( !xJob.is() )
80 throw lang::IllegalArgumentException();
82 uno::Sequence< beans::NamedValue > aArgsForJob;
83 if ( aArguments.getLength() > 1 )
84 aArgsForJob = uno::Sequence< beans::NamedValue >( aArguments.getConstArray() + 1, aArguments.getLength() - 1 );
86 MainThreadExecutor_Impl* pExecutor = new MainThreadExecutor_Impl( xJob, aArgsForJob );
87 pExecutor->execute();
89 // it is not a main thread, so it can be blocked
90 // while( !pExecutor->isExecuted() )
91 // ::osl::Thread::yield();
93 // TODO: implement transfering of the return values and exceptions
95 return uno::Any();
98 //-------------------------------------------------------------------------
99 uno::Sequence< ::rtl::OUString > SAL_CALL UNOMainThreadExecutor::impl_staticGetSupportedServiceNames()
101 uno::Sequence< ::rtl::OUString > aRet(1);
102 aRet[0] = ::rtl::OUString::createFromAscii( "com.sun.star.comp.thread.MainThreadExecutor" );
103 return aRet;
106 //-------------------------------------------------------------------------
107 ::rtl::OUString SAL_CALL UNOMainThreadExecutor::impl_staticGetImplementationName()
109 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.thread.MainThreadExecutor" );
112 //-------------------------------------------------------------------------
113 uno::Reference< uno::XInterface > SAL_CALL UNOMainThreadExecutor::impl_staticCreateSelfInstance(
114 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
116 return uno::Reference< uno::XInterface >( *new UNOMainThreadExecutor( xServiceManager ) );
119 //-------------------------------------------------------------------------
120 ::rtl::OUString SAL_CALL UNOMainThreadExecutor::getImplementationName()
121 throw ( uno::RuntimeException )
123 return impl_staticGetImplementationName();
126 //-------------------------------------------------------------------------
127 sal_Bool SAL_CALL UNOMainThreadExecutor::supportsService( const ::rtl::OUString& ServiceName )
128 throw ( uno::RuntimeException )
130 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
132 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
133 if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
134 return sal_True;
136 return sal_False;
139 //-------------------------------------------------------------------------
140 uno::Sequence< ::rtl::OUString > SAL_CALL UNOMainThreadExecutor::getSupportedServiceNames()
141 throw ( uno::RuntimeException )
143 return impl_staticGetSupportedServiceNames();