summaryrefslogtreecommitdiffstats
path: root/embeddedobj/test/MainThreadExecutor
diff options
context:
space:
mode:
Diffstat (limited to 'embeddedobj/test/MainThreadExecutor')
-rw-r--r--embeddedobj/test/MainThreadExecutor/exports.dxp2
-rw-r--r--embeddedobj/test/MainThreadExecutor/makefile.mk58
-rw-r--r--embeddedobj/test/MainThreadExecutor/register.cxx85
-rw-r--r--embeddedobj/test/MainThreadExecutor/xexecutor.cxx123
-rw-r--r--embeddedobj/test/MainThreadExecutor/xexecutor.hxx77
5 files changed, 345 insertions, 0 deletions
diff --git a/embeddedobj/test/MainThreadExecutor/exports.dxp b/embeddedobj/test/MainThreadExecutor/exports.dxp
new file mode 100644
index 0000000000..51703a0466
--- /dev/null
+++ b/embeddedobj/test/MainThreadExecutor/exports.dxp
@@ -0,0 +1,2 @@
+component_writeInfo
+component_getFactory
diff --git a/embeddedobj/test/MainThreadExecutor/makefile.mk b/embeddedobj/test/MainThreadExecutor/makefile.mk
new file mode 100644
index 0000000000..a8fef803e6
--- /dev/null
+++ b/embeddedobj/test/MainThreadExecutor/makefile.mk
@@ -0,0 +1,58 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed
+# with this work for additional information regarding copyright
+# ownership. The ASF licenses this file to you under the Apache
+# License, Version 2.0 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ=..$/..
+
+PRJNAME=embeddedobj
+TARGET=mainexec
+LIBTARGET=NO
+USE_DEFFILE=TRUE
+
+# --- Settings -----------------------------------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Files --------------------------------------------------------
+
+SHL1TARGET= $(TARGET)
+
+SHL1IMPLIB= i$(TARGET)
+SHL1OBJS= \
+ $(SLO)$/xexecutor.obj\
+ $(SLO)$/register.obj
+
+EXCEPTIONSFILES= \
+ $(SLO)$/xexecutor.obj\
+ $(SLO)$/register.obj
+
+SHL1STDLIBS=\
+ $(SALLIB)\
+ $(VCLLIB)\
+ $(CPPULIB)\
+ $(CPPUHELPERLIB)
+
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+
+DEF1NAME= $(SHL1TARGET)
+DEF1EXPORTFILE= exports.dxp
+
+# --- Targets -------------------------------------------------------------
+
+.INCLUDE : target.mk
+
+
diff --git a/embeddedobj/test/MainThreadExecutor/register.cxx b/embeddedobj/test/MainThreadExecutor/register.cxx
new file mode 100644
index 0000000000..777222e5d8
--- /dev/null
+++ b/embeddedobj/test/MainThreadExecutor/register.cxx
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <com/sun/star/registry/XRegistryKey.hpp>
+#include <com/sun/star/registry/InvalidRegistryException.hpp>
+#include <cppuhelper/factory.hxx>
+
+#include "xexecutor.hxx"
+
+using namespace ::com::sun::star;
+
+
+extern "C" {
+
+SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void * pRet = 0;
+
+ OUString aImplName( OUString::createFromAscii( pImplName ) );
+ uno::Reference< lang::XSingleServiceFactory > xFactory;
+
+ if ( pServiceManager && aImplName.equals( UNOMainThreadExecutor::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ UNOMainThreadExecutor::impl_staticGetImplementationName(),
+ UNOMainThreadExecutor::impl_staticCreateSelfInstance,
+ UNOMainThreadExecutor::impl_staticGetSupportedServiceNames() );
+ }
+
+ if ( xFactory.is() )
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+
+ return pRet;
+}
+
+sal_Bool SAL_CALL component_writeInfo( void * pServiceManager, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ uno::Reference< registry::XRegistryKey > xKey( reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ) );
+
+ uno::Reference< registry::XRegistryKey > xNewKey;
+
+ xNewKey = xKey->createKey( OUString("/") +
+ UNOMainThreadExecutor::impl_staticGetImplementationName() +
+ OUString( "/UNO/SERVICES") );
+
+ uno::Sequence< OUString > &rServices = UNOMainThreadExecutor::impl_staticGetSupportedServiceNames();
+ for( sal_Int32 ind = 0; ind < rServices.getLength(); ind++ )
+ xNewKey->createKey( rServices.getConstArray()[ind] );
+
+ return sal_True;
+ }
+ catch (registry::InvalidRegistryException &)
+ {
+ OSL_FAIL( "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+} // extern "C"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/MainThreadExecutor/xexecutor.cxx b/embeddedobj/test/MainThreadExecutor/xexecutor.cxx
new file mode 100644
index 0000000000..96dbd3771e
--- /dev/null
+++ b/embeddedobj/test/MainThreadExecutor/xexecutor.cxx
@@ -0,0 +1,123 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "xexecutor.hxx"
+#include <vcl/svapp.hxx>
+#include <osl/thread.hxx>
+#include <cppuhelper/supportsservice.hxx>
+
+using namespace ::com::sun::star;
+
+void MainThreadExecutor_Impl::execute()
+{
+ Application::PostUserEvent( LINK( this, MainThreadExecutor_Impl, executor ), NULL );
+}
+
+IMPL_LINK_NOARG( MainThreadExecutor_Impl, executor, void*, void )
+{
+ if ( m_xJob.is() )
+ {
+ try {
+ m_xJob->execute( m_aArgs );
+ } catch( uno::Exception& ) {}
+ }
+
+ m_bExecuted = sal_True;
+ delete this;
+}
+
+MainThreadExecutor_Impl::MainThreadExecutor_Impl( const uno::Reference< task::XJob >& xJob,
+ const uno::Sequence< beans::NamedValue >& aArguments )
+: m_xJob( xJob )
+, m_aArgs( aArguments )
+, m_bExecuted( sal_False )
+{
+}
+
+
+uno::Any SAL_CALL UNOMainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
+ throw ( lang::IllegalArgumentException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ uno::Reference< task::XJob > xJob;
+
+ if ( aArguments.getLength() > 0 && aArguments[0].Name == "JobToExecute" )
+ aArguments[0].Value >>= xJob;
+
+ if ( !xJob.is() )
+ throw lang::IllegalArgumentException();
+
+ uno::Sequence< beans::NamedValue > aArgsForJob;
+ if ( aArguments.getLength() > 1 )
+ aArgsForJob = uno::Sequence< beans::NamedValue >( aArguments.getConstArray() + 1, aArguments.getLength() - 1 );
+
+ MainThreadExecutor_Impl* pExecutor = new MainThreadExecutor_Impl( xJob, aArgsForJob );
+ pExecutor->execute();
+
+ // it is not a main thread, so it can be blocked
+ // while( !pExecutor->isExecuted() )
+ // ::osl::Thread::yield();
+
+ // TODO: implement transferring of the return values and exceptions
+
+ return uno::Any();
+}
+
+
+uno::Sequence< OUString > SAL_CALL UNOMainThreadExecutor::impl_staticGetSupportedServiceNames()
+{
+ uno::Sequence< OUString > aRet { "com.sun.star.comp.thread.MainThreadExecutor" };
+ return aRet;
+}
+
+
+OUString SAL_CALL UNOMainThreadExecutor::impl_staticGetImplementationName()
+{
+ return OUString("com.sun.star.comp.thread.MainThreadExecutor");
+}
+
+
+uno::Reference< uno::XInterface > SAL_CALL UNOMainThreadExecutor::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new UNOMainThreadExecutor( xServiceManager ) );
+}
+
+
+OUString SAL_CALL UNOMainThreadExecutor::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetImplementationName();
+}
+
+sal_Bool SAL_CALL UNOMainThreadExecutor::supportsService( const OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+
+uno::Sequence< OUString > SAL_CALL UNOMainThreadExecutor::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/MainThreadExecutor/xexecutor.hxx b/embeddedobj/test/MainThreadExecutor/xexecutor.hxx
new file mode 100644
index 0000000000..1c76105402
--- /dev/null
+++ b/embeddedobj/test/MainThreadExecutor/xexecutor.hxx
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/task/XJob.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <cppuhelper/implbase.hxx>
+
+#include <tools/link.hxx>
+
+class UNOMainThreadExecutor : public ::cppu::WeakImplHelper< css::task::XJob,
+ css::lang::XServiceInfo >
+{
+ css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
+
+public:
+ explicit UNOMainThreadExecutor(
+ const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
+ : m_xFactory( xFactory )
+ {
+ }
+
+ static css::uno::Sequence< OUString > SAL_CALL impl_staticGetSupportedServiceNames();
+
+ static OUString SAL_CALL impl_staticGetImplementationName();
+
+ static css::uno::Reference< css::uno::XInterface > SAL_CALL
+ impl_staticCreateSelfInstance(
+ const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
+
+ // XJob
+ virtual css::uno::Any SAL_CALL execute( const css::uno::Sequence< css::beans::NamedValue >& Arguments ) throw (css::lang::IllegalArgumentException, css::uno::Exception, css::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (css::uno::RuntimeException);
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
+
+};
+
+class MainThreadExecutor_Impl
+{
+ css::uno::Reference< css::task::XJob > m_xJob;
+ css::uno::Sequence< css::beans::NamedValue > m_aArgs;
+
+ sal_Bool m_bExecuted;
+public:
+ MainThreadExecutor_Impl( const css::uno::Reference< css::task::XJob >& xJob,
+ const css::uno::Sequence< css::beans::NamedValue >& aArguments );
+
+ void execute();
+
+ DECL_LINK( executor, void* );
+
+ sal_Bool isExecuted() const { return m_bExecuted; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */