1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #include <com/sun/star/lang/XInitialization.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <cppuhelper/implbase.hxx>
28 #include "ole2uno.hxx"
29 #include "unoconversionutilities.hxx"
31 using namespace com::sun::star::bridge
;
35 Reference
< XInterface
> ConverterProvider_CreateInstance2( const Reference
<XMultiServiceFactory
> & xSMgr
);
37 Reference
< XInterface
> ConverterProvider_CreateInstanceVar1( const Reference
<XMultiServiceFactory
> & xSMgr
);
39 Reference
<XInterface
> OleClient_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
);
41 Reference
<XInterface
> OleServer_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
);
43 /*****************************************************************************
47 Provides a single UNO object as OLE object.
49 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
50 then it maps the XInstance member it to a COM object.
52 *****************************************************************************/
54 class OneInstanceOleWrapper
: public IClassFactory
58 OneInstanceOleWrapper( const Reference
<XMultiServiceFactory
>& smgr
,
59 std::function
<const Reference
<XInterface
>()> xInstFunction
);
60 virtual ~OneInstanceOleWrapper();
62 bool registerClass(GUID
const * pGuid
);
63 bool deregisterClass();
65 /* IUnknown methods */
66 STDMETHOD(QueryInterface
)(REFIID riid
, void ** ppvObj
) override
;
67 STDMETHOD_(ULONG
, AddRef
)() override
;
68 STDMETHOD_(ULONG
, Release
)() override
;
70 /* IClassFactory methods */
71 STDMETHOD(CreateInstance
)(IUnknown
* punkOuter
, REFIID riid
, void** ppv
) override
;
72 STDMETHOD(LockServer
)(BOOL fLock
) override
;
75 oslInterlockedCount m_refCount
;
76 std::function
<const Reference
<XInterface
>()> m_xInstFunction
;
77 DWORD m_factoryHandle
;
78 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
79 Reference
<XMultiServiceFactory
> m_smgr
;
82 // Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
84 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
85 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2 which
86 // interface does not need a Machine Id in its createBridge function anymore,
87 // If a UNO interface is to be converted then the member m_nUnoWrapperClass determines
88 // what wrapper class is to be used. There are currently InterfaceOleWrapper and
89 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
90 // latter for OleBridgeSupplierVar1.
91 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
92 // Currently there is only one class available (IUnknownWrapper).
93 class OleConverter
: public WeakImplHelper
<XBridgeSupplier2
, XInitialization
, css::lang::XServiceInfo
>,
94 public UnoConversionUtilities
<OleConverter
>
97 explicit OleConverter( const Reference
<XMultiServiceFactory
>& smgr
);
98 OleConverter( const Reference
<XMultiServiceFactory
>& smgr
, sal_uInt8 unoWrapperClass
, sal_uInt8 comWrapperClass
);
99 virtual ~OleConverter() override
;
101 // XBridgeSupplier2 ---------------------------------------------------
103 Any SAL_CALL
createBridge(const Any
& modelDepObject
,
104 const Sequence
<sal_Int8
>& ProcessId
,
105 sal_Int16 sourceModelType
,
106 sal_Int16 destModelType
) override
;
109 void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) override
;
111 OUString SAL_CALL
getImplementationName() override
;
113 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
;
115 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
117 // UnoConversionUtilities
118 Reference
< XInterface
> createUnoWrapperInstance() override
;
119 Reference
< XInterface
> createComWrapperInstance() override
;
124 // Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
126 class OleClient
: public WeakImplHelper
<XMultiServiceFactory
, css::lang::XServiceInfo
>,
127 public UnoConversionUtilities
<OleClient
>
130 explicit OleClient( const Reference
<XMultiServiceFactory
>& smgr
);
131 ~OleClient() override
;
133 // XMultiServiceFactory
134 Reference
<XInterface
> SAL_CALL
createInstance(const OUString
& ServiceSpecifier
) override
;
135 Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const OUString
& ServiceSpecifier
, const Sequence
< Any
>& Arguments
) override
;
136 Sequence
< OUString
> SAL_CALL
getAvailableServiceNames() override
;
138 OUString SAL_CALL
getImplementationName() override
;
140 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
;
142 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
144 // UnoConversionUtilities
145 Reference
< XInterface
> createUnoWrapperInstance() override
;
146 Reference
< XInterface
> createComWrapperInstance() override
;
149 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
152 /*****************************************************************************
156 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
157 Register the calling application as OLE automation server for
158 standard OLE object. The objects will be registered while instantiating
159 this implementation and deregistered, if this implementation is destroyed.
161 *****************************************************************************/
163 class OleServer
: public cppu::WeakImplHelper
<css::lang::XServiceInfo
>
166 explicit OleServer( const Reference
<XMultiServiceFactory
> &smgr
);
167 ~OleServer() override
;
169 OUString SAL_CALL
getImplementationName() override
;
171 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
;
173 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
176 bool provideInstance(std::function
<const Reference
<XInterface
>()> xInstFunction
, GUID
const * guid
);
178 std::list
< OneInstanceOleWrapper
* > m_wrapperList
;
179 Reference
< XBridgeSupplier2
> m_bridgeSupplier
;
181 Reference
<XMultiServiceFactory
> m_smgr
;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */