Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / ole / servprov.hxx
blob2fcf2ceac83e285dccfcc37c3e71382dddaad22c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_OLE_SERVPROV_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_OLE_SERVPROV_HXX
23 #include <functional>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/implbase.hxx>
29 #include "ole2uno.hxx"
30 #include "unoconversionutilities.hxx"
32 using namespace com::sun::star::bridge;
33 using namespace cppu;
34 using namespace std;
36 /// @throws Exception
37 Reference< XInterface> ConverterProvider_CreateInstance2( const Reference<XMultiServiceFactory> & xSMgr);
38 /// @throws Exception
39 Reference< XInterface> ConverterProvider_CreateInstanceVar1( const Reference<XMultiServiceFactory> & xSMgr);
40 /// @throws Exception
41 Reference<XInterface> OleClient_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr);
42 /// @throws Exception
43 Reference<XInterface> OleServer_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr);
45 /*****************************************************************************
47 OneInstanceOleWrapper
49 Provides a single UNO object as OLE object.
51 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
52 then it maps the XInstance member it to a COM object.
54 *****************************************************************************/
56 class OneInstanceOleWrapper : public IClassFactory
58 public:
60 OneInstanceOleWrapper( const Reference<XMultiServiceFactory>& smgr,
61 std::function<const Reference<XInterface>()> xInstFunction );
62 virtual ~OneInstanceOleWrapper();
64 bool registerClass(GUID const * pGuid);
65 bool deregisterClass();
67 /* IUnknown methods */
68 STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj) override;
69 STDMETHOD_(ULONG, AddRef)() override;
70 STDMETHOD_(ULONG, Release)() override;
72 /* IClassFactory methods */
73 STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv) override;
74 STDMETHOD(LockServer)(BOOL fLock) override;
76 protected:
77 oslInterlockedCount m_refCount;
78 std::function<const Reference<XInterface>()> m_xInstFunction;
79 DWORD m_factoryHandle;
80 Reference<XBridgeSupplier2> m_bridgeSupplier;
81 Reference<XMultiServiceFactory> m_smgr;
84 // Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
86 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
87 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2 which
88 // interface does not need a Maschine Id in its createBridge function anymore,
89 // If a UNO interface is to be converted then the member m_nUnoWrapperClass determines
90 // what wrapper class is to be used. There are currently InterfaceOleWrapper and
91 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
92 // latter for OleBridgeSupplierVar1.
93 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
94 // Currently there is only one class available (IUnknownWrapper).
95 class OleConverter : public WeakImplHelper<XBridgeSupplier2, XInitialization, css::lang::XServiceInfo>,
96 public UnoConversionUtilities<OleConverter>
98 public:
99 explicit OleConverter( const Reference<XMultiServiceFactory>& smgr);
100 OleConverter( const Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass );
101 virtual ~OleConverter() override;
103 // XBridgeSupplier2 ---------------------------------------------------
105 Any SAL_CALL createBridge(const Any& modelDepObject,
106 const Sequence<sal_Int8>& ProcessId,
107 sal_Int16 sourceModelType,
108 sal_Int16 destModelType) override;
110 // XInitialization
111 void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
113 OUString SAL_CALL getImplementationName() override;
115 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
117 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
119 // UnoConversionUtilities
120 Reference< XInterface > createUnoWrapperInstance() override;
121 Reference< XInterface > createComWrapperInstance() override;
122 protected:
126 // Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
128 class OleClient : public WeakImplHelper<XMultiServiceFactory, css::lang::XServiceInfo>,
129 public UnoConversionUtilities<OleClient>
131 public:
132 explicit OleClient( const Reference<XMultiServiceFactory>& smgr);
133 ~OleClient() override;
135 // XMultiServiceFactory
136 Reference<XInterface> SAL_CALL createInstance(const OUString& ServiceSpecifier) override;
137 Reference<XInterface> SAL_CALL createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& Arguments) override;
138 Sequence< OUString > SAL_CALL getAvailableServiceNames() override;
140 OUString SAL_CALL getImplementationName() override;
142 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
144 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
146 // UnoConversionUtilities
147 Reference< XInterface > createUnoWrapperInstance() override;
148 Reference< XInterface > createComWrapperInstance() override;
150 protected:
151 Reference<XBridgeSupplier2> m_bridgeSupplier;
154 /*****************************************************************************
156 OleServer
158 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
159 Register the calling application as OLE automation server for
160 standard OLE object. The objects will be registered while instantiating
161 this implementation and deregistered, if this implementation is destroyed.
163 *****************************************************************************/
165 class OleServer : public cppu::WeakImplHelper<css::lang::XServiceInfo>
167 public:
168 explicit OleServer( const Reference<XMultiServiceFactory> &smgr);
169 ~OleServer() override;
171 OUString SAL_CALL getImplementationName() override;
173 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
175 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
177 protected:
178 bool provideInstance(std::function<const Reference<XInterface>()> xInstFunction, GUID const * guid);
180 list< OneInstanceOleWrapper* > m_wrapperList;
181 Reference< XBridgeSupplier2 > m_bridgeSupplier;
183 Reference<XMultiServiceFactory> m_smgr;
186 #endif
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */