1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mainthreadexecutor.cxx,v $
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 "mainthreadexecutor.hxx"
36 #include <vcl/svapp.hxx>
38 using namespace ::com::sun::star
;
40 //-------------------------------------------------------------------------
41 uno::Sequence
< ::rtl::OUString
> SAL_CALL
MainThreadExecutor::impl_staticGetSupportedServiceNames()
43 uno::Sequence
< ::rtl::OUString
> aRet(2);
44 aRet
[0] = ::rtl::OUString::createFromAscii("com.sun.star.thread.MainThreadExecutor");
45 aRet
[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.thread.MainThreadExecutor");
49 //-------------------------------------------------------------------------
50 ::rtl::OUString SAL_CALL
MainThreadExecutor::impl_staticGetImplementationName()
52 return ::rtl::OUString::createFromAscii("com.sun.star.comp.thread.MainThreadExecutor");
55 //-------------------------------------------------------------------------
56 uno::Reference
< uno::XInterface
> SAL_CALL
MainThreadExecutor::impl_staticCreateSelfInstance(
57 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
59 return uno::Reference
< uno::XInterface
>( *new MainThreadExecutor( xServiceManager
) );
62 //-------------------------------------------------------------------------
63 uno::Any SAL_CALL
MainThreadExecutor::execute( const uno::Sequence
< beans::NamedValue
>& aArguments
)
64 throw ( lang::IllegalArgumentException
,
66 uno::RuntimeException
)
68 uno::Reference
< task::XJob
> xJob
;
69 uno::Sequence
< beans::NamedValue
> aValues
;
70 sal_Int32 nValuesSize
= 0;
72 for ( sal_Int32 nInd
= 0; nInd
< aArguments
.getLength(); nInd
++ )
73 if ( aArguments
[nInd
].Name
.equalsAscii( "JobToExecute" ) )
74 aArguments
[nInd
].Value
>>= xJob
;
77 aValues
.realloc( ++nValuesSize
);
78 aValues
[nValuesSize
-1].Name
= aArguments
[nInd
].Name
;
79 aValues
[nValuesSize
-1].Value
= aArguments
[nInd
].Value
;
84 MainThreadExecutorRequest
* pMainThreadExecutorRequest
= new MainThreadExecutorRequest( xJob
, aValues
);
85 Application::PostUserEvent( STATIC_LINK( NULL
, MainThreadExecutor
, worker
), pMainThreadExecutorRequest
);
88 // TODO: wait for result
92 //-------------------------------------------------------------------------
93 IMPL_STATIC_LINK( MainThreadExecutor
, worker
, MainThreadExecutorRequest
*, pThreadExecutorRequest
)
95 pThreadExecutorRequest
->doIt();
97 delete pThreadExecutorRequest
;
101 //-------------------------------------------------------------------------
102 ::rtl::OUString SAL_CALL
MainThreadExecutor::getImplementationName()
103 throw ( uno::RuntimeException
)
105 return impl_staticGetImplementationName();
108 //-------------------------------------------------------------------------
109 sal_Bool SAL_CALL
MainThreadExecutor::supportsService( const ::rtl::OUString
& ServiceName
)
110 throw ( uno::RuntimeException
)
112 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_staticGetSupportedServiceNames();
114 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
115 if ( ServiceName
.compareTo( aSeq
[nInd
] ) == 0 )
121 //-------------------------------------------------------------------------
122 uno::Sequence
< ::rtl::OUString
> SAL_CALL
MainThreadExecutor::getSupportedServiceNames()
123 throw ( uno::RuntimeException
)
125 return impl_staticGetSupportedServiceNames();
128 //-------------------------------------------------------------------------
129 MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference
< task::XJob
>& xJob
,
130 const uno::Sequence
< beans::NamedValue
>& aValues
)
132 , m_aValues( aValues
)
136 //-------------------------------------------------------------------------
137 void MainThreadExecutorRequest::doIt()
140 m_xJob
->execute( m_aValues
);