summaryrefslogtreecommitdiffstats
path: root/embeddedobj/test/mtexecutor
diff options
context:
space:
mode:
Diffstat (limited to 'embeddedobj/test/mtexecutor')
-rw-r--r--embeddedobj/test/mtexecutor/bitmapcreator.cxx107
-rw-r--r--embeddedobj/test/mtexecutor/bitmapcreator.hxx57
-rw-r--r--embeddedobj/test/mtexecutor/exports.dxp2
-rw-r--r--embeddedobj/test/mtexecutor/mainthreadexecutor.cxx123
-rw-r--r--embeddedobj/test/mtexecutor/mainthreadexecutor.hxx73
-rw-r--r--embeddedobj/test/mtexecutor/makefile.mk69
-rw-r--r--embeddedobj/test/mtexecutor/mteregister.cxx107
7 files changed, 538 insertions, 0 deletions
diff --git a/embeddedobj/test/mtexecutor/bitmapcreator.cxx b/embeddedobj/test/mtexecutor/bitmapcreator.cxx
new file mode 100644
index 000000000..60a89f8cd
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/bitmapcreator.cxx
@@ -0,0 +1,107 @@
+/* -*- 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 "bitmapcreator.hxx"
+
+#include <cppuhelper/supportsservice.hxx>
+#include <vcl/bitmapex.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <tools/stream.hxx>
+
+using namespace ::com::sun::star;
+
+
+uno::Sequence< OUString > SAL_CALL VCLBitmapCreator::impl_staticGetSupportedServiceNames()
+{
+ return
+ {
+ "com.sun.star.embed.BitmapCreator",
+ "com.sun.star.comp.embed.BitmapCreator"
+ };
+}
+
+
+OUString SAL_CALL VCLBitmapCreator::impl_staticGetImplementationName()
+{
+ return OUString("com.sun.star.comp.embed.BitmapCreator");
+}
+
+
+uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new VCLBitmapCreator( xServiceManager ) );
+}
+
+
+uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstance()
+ throw ( uno::Exception,
+ uno::RuntimeException)
+{
+ BitmapEx aBitmap;
+ uno::Reference< uno::XInterface> aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
+
+ return aResult;
+}
+
+
+uno::Reference< uno::XInterface > SAL_CALL VCLBitmapCreator::createInstanceWithArguments(
+ const uno::Sequence< uno::Any >& aArguments )
+ throw ( uno::Exception,
+ uno::RuntimeException)
+{
+ if ( aArguments.getLength() != 1 )
+ throw uno::Exception(); // TODO
+
+ uno::Sequence< sal_Int8 > aOrigBitmap;
+ if ( !( aArguments[0] >>= aOrigBitmap ) )
+ throw uno::Exception(); // TODO
+
+ BitmapEx aBitmap;
+ SvMemoryStream aStream( aOrigBitmap.getArray(), aOrigBitmap.getLength(), StreamMode::READ );
+ aStream >> aBitmap;
+ if ( aStream.GetError() )
+ throw uno::Exception(); // TODO
+
+ uno::Reference< uno::XInterface > aResult( VCLUnoHelper::CreateBitmap( aBitmap ), uno::UNO_QUERY );
+
+ return aResult;
+}
+
+
+OUString SAL_CALL VCLBitmapCreator::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetImplementationName();
+}
+
+sal_Bool SAL_CALL VCLBitmapCreator::supportsService( const OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+
+uno::Sequence< OUString > SAL_CALL VCLBitmapCreator::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/mtexecutor/bitmapcreator.hxx b/embeddedobj/test/mtexecutor/bitmapcreator.hxx
new file mode 100644
index 000000000..0faed31cc
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/bitmapcreator.hxx
@@ -0,0 +1,57 @@
+/* -*- 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/task/XJob.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+
+#include <cppuhelper/implbase.hxx>
+
+class VCLBitmapCreator : public ::cppu::WeakImplHelper<
+ css::lang::XSingleServiceFactory,
+ css::lang::XServiceInfo >
+
+{
+public:
+ explicit VCLBitmapCreator(
+ const css::uno::Reference< css::lang::XMultiServiceFactory >& 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 );
+
+ // XSingleServiceFactory
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( ) throw (css::uno::Exception, css::uno::RuntimeException);
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (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);
+
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/mtexecutor/exports.dxp b/embeddedobj/test/mtexecutor/exports.dxp
new file mode 100644
index 000000000..51703a046
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/exports.dxp
@@ -0,0 +1,2 @@
+component_writeInfo
+component_getFactory
diff --git a/embeddedobj/test/mtexecutor/mainthreadexecutor.cxx b/embeddedobj/test/mtexecutor/mainthreadexecutor.cxx
new file mode 100644
index 000000000..82a124a2c
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/mainthreadexecutor.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 "mainthreadexecutor.hxx"
+
+#include <cppuhelper/supportsservice.hxx>
+#include <vcl/svapp.hxx>
+
+using namespace ::com::sun::star;
+
+
+uno::Sequence< OUString > SAL_CALL MainThreadExecutor::impl_staticGetSupportedServiceNames()
+{
+ return
+ {
+ "com.sun.star.thread.MainThreadExecutor",
+ "com.sun.star.comp.thread.MainThreadExecutor"
+ }
+}
+
+
+OUString SAL_CALL MainThreadExecutor::impl_staticGetImplementationName()
+{
+ return OUString("com.sun.star.comp.thread.MainThreadExecutor");
+}
+
+
+uno::Reference< uno::XInterface > SAL_CALL MainThreadExecutor::impl_staticCreateSelfInstance(
+ const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
+{
+ return uno::Reference< uno::XInterface >( *new MainThreadExecutor( xServiceManager ) );
+}
+
+
+uno::Any SAL_CALL MainThreadExecutor::execute( const uno::Sequence< beans::NamedValue >& aArguments )
+ throw ( lang::IllegalArgumentException,
+ uno::Exception,
+ uno::RuntimeException )
+{
+ uno::Reference< task::XJob > xJob;
+ uno::Sequence< beans::NamedValue > aValues;
+ sal_Int32 nValuesSize = 0;
+
+ for ( sal_Int32 nInd = 0; nInd < aArguments.getLength(); nInd++ )
+ if ( aArguments[nInd].Name == "JobToExecute" )
+ aArguments[nInd].Value >>= xJob;
+ else
+ {
+ aValues.realloc( ++nValuesSize );
+ aValues[nValuesSize-1].Name = aArguments[nInd].Name;
+ aValues[nValuesSize-1].Value = aArguments[nInd].Value;
+ }
+
+ if ( xJob.is() )
+ {
+ MainThreadExecutorRequest* pMainThreadExecutorRequest = new MainThreadExecutorRequest( xJob, aValues );
+ Application::PostUserEvent( LINK( NULL, MainThreadExecutor, worker ), pMainThreadExecutorRequest );
+ }
+
+ // TODO: wait for result
+ return uno::Any();
+}
+
+
+IMPL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, pThreadExecutorRequest, void )
+{
+ pThreadExecutorRequest->doIt();
+
+ delete pThreadExecutorRequest;
+}
+
+
+OUString SAL_CALL MainThreadExecutor::getImplementationName()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetImplementationName();
+}
+
+sal_Bool SAL_CALL MainThreadExecutor::supportsService( const OUString& ServiceName )
+ throw ( uno::RuntimeException )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+
+uno::Sequence< OUString > SAL_CALL MainThreadExecutor::getSupportedServiceNames()
+ throw ( uno::RuntimeException )
+{
+ return impl_staticGetSupportedServiceNames();
+}
+
+
+MainThreadExecutorRequest::MainThreadExecutorRequest( const uno::Reference< task::XJob >& xJob,
+ const uno::Sequence< beans::NamedValue >& aValues )
+: m_xJob( xJob )
+, m_aValues( aValues )
+{
+}
+
+
+void MainThreadExecutorRequest::doIt()
+{
+ if ( m_xJob.is() )
+ m_xJob->execute( m_aValues );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/mtexecutor/mainthreadexecutor.hxx b/embeddedobj/test/mtexecutor/mainthreadexecutor.hxx
new file mode 100644
index 000000000..1bb98ee91
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/mainthreadexecutor.hxx
@@ -0,0 +1,73 @@
+/* -*- 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/task/XJob.hpp>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+
+#include <cppuhelper/implbase.hxx>
+
+#include <tools/link.hxx>
+
+class MainThreadExecutorRequest
+{
+ css::uno::Reference< css::task::XJob > m_xJob;
+ css::uno::Sequence< css::beans::NamedValue > m_aValues;
+
+ public:
+ MainThreadExecutorRequest(
+ const css::uno::Reference< css::task::XJob >& xJob,
+ const css::uno::Sequence< css::beans::NamedValue >& aValues );
+
+ void doIt();
+};
+
+class MainThreadExecutor : public ::cppu::WeakImplHelper<
+ css::task::XJob,
+ css::lang::XServiceInfo >
+
+{
+public:
+ explicit MainThreadExecutor(
+ const css::uno::Reference< css::lang::XMultiServiceFactory >& 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 );
+
+ DECL_STATIC_LINK( MainThreadExecutor, worker, MainThreadExecutorRequest*, void );
+
+ // 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);
+
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/test/mtexecutor/makefile.mk b/embeddedobj/test/mtexecutor/makefile.mk
new file mode 100644
index 000000000..061f1ecb0
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/makefile.mk
@@ -0,0 +1,69 @@
+#
+# 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=mainthrexec
+
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+LIBTARGET=NO
+USE_DEFFILE=NO
+INCPRE+=$(ATL_INCLUDE)
+
+# --- Files --------------------------------------------------------
+
+SHL1TARGET= $(TARGET)
+
+SHL1IMPLIB= i$(TARGET)
+
+SLOFILES = \
+ $(SLO)$/mainthreadexecutor.obj\
+ $(SLO)$/bitmapcreator.obj\
+ $(SLO)$/mteregister.obj
+
+EXCEPTIONSFILES = \
+ $(SLO)$/mainthreadexecutor.obj\
+ $(SLO)$/bitmapcreator.obj\
+ $(SLO)$/mteregister.obj
+
+SHL1OBJS= $(SLOFILES)
+
+SHL1STDLIBS=\
+ $(SALLIB)\
+ $(CPPULIB)\
+ $(CPPUHELPERLIB)\
+ $(TOOLSLIB)\
+ $(VCLLIB)\
+ itk.lib
+
+DEF1EXPORTFILE= exports.dxp
+
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+
+DEF1NAME= $(SHL1TARGET)
+
+
+# --- Targets -------------------------------------------------------
+
+.INCLUDE : target.mk
+
diff --git a/embeddedobj/test/mtexecutor/mteregister.cxx b/embeddedobj/test/mtexecutor/mteregister.cxx
new file mode 100644
index 000000000..76d820055
--- /dev/null
+++ b/embeddedobj/test/mtexecutor/mteregister.cxx
@@ -0,0 +1,107 @@
+/* -*- 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 "mainthreadexecutor.hxx"
+#include "bitmapcreator.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 )
+ {
+ if ( aImplName.equals( MainThreadExecutor::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ MainThreadExecutor::impl_staticGetImplementationName(),
+ MainThreadExecutor::impl_staticCreateSelfInstance,
+ MainThreadExecutor::impl_staticGetSupportedServiceNames() );
+ }
+ else if ( aImplName.equals( VCLBitmapCreator::impl_staticGetImplementationName() ) )
+ {
+ xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ),
+ VCLBitmapCreator::impl_staticGetImplementationName(),
+ VCLBitmapCreator::impl_staticCreateSelfInstance,
+ VCLBitmapCreator::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;
+ uno::Sequence< OUString > rServices;
+ sal_Int32 ind = 0;
+
+ xNewKey = xKey->createKey( OUString("/") +
+ MainThreadExecutor::impl_staticGetImplementationName() +
+ OUString( "/UNO/SERVICES") );
+
+ rServices = MainThreadExecutor::impl_staticGetSupportedServiceNames();
+ for( ind = 0; ind < rServices.getLength(); ind++ )
+ xNewKey->createKey( rServices.getConstArray()[ind] );
+
+ xNewKey = xKey->createKey( OUString("/") +
+ VCLBitmapCreator::impl_staticGetImplementationName() +
+ OUString( "/UNO/SERVICES") );
+
+ rServices = VCLBitmapCreator::impl_staticGetSupportedServiceNames();
+ for( 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: */