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 .
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <cppuhelper/implbase2.hxx>
26 #include "ole2uno.hxx"
27 #include "unoconversionutilities.hxx"
29 using namespace com::sun::star::bridge
;
35 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
37 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstance2( const Reference
<XMultiServiceFactory
> & xSMgr
)
39 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstanceVar1( const Reference
<XMultiServiceFactory
> & xSMgr
)
41 Reference
<XInterface
> SAL_CALL
OleClient_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
43 Reference
<XInterface
> SAL_CALL
OleServer_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
45 /*****************************************************************************
47 class declaration IClassFactoryWrapper
49 Specify abstract helper methods on class factories, which provide
50 UNO objects. These methods are used by objects of class OleServer_Impl,
51 to handle the OLE registration of different class factories.
53 *****************************************************************************/
55 class IClassFactoryWrapper
: public IClassFactory
59 virtual sal_Bool
registerClass() = 0;
60 virtual sal_Bool
deregisterClass() = 0;
63 /*****************************************************************************
65 class declaration ProviderOleWrapper_Impl
67 Provides an UNO service provider as OLE class factory. Handle the
68 OLE registration by overloading the abstract methods from
71 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
72 then it creates an service by help of the XSingleServiceFactory member and maps
73 maps it to a COM object.
75 *****************************************************************************/
77 class ProviderOleWrapper_Impl
: public IClassFactoryWrapper
81 ProviderOleWrapper_Impl( const Reference
<XMultiServiceFactory
>& smgr
,
82 const Reference
<XSingleServiceFactory
>& xSFactory
, GUID
* pGuid
);
83 virtual ~ProviderOleWrapper_Impl();
85 sal_Bool
registerClass();
86 sal_Bool
deregisterClass();
88 /* IUnknown methods */
89 STDMETHOD(QueryInterface
)(REFIID riid
, LPVOID FAR
* ppvObj
);
90 STDMETHOD_(ULONG
, AddRef
)();
91 STDMETHOD_(ULONG
, Release
)();
93 /* IClassFactory methods */
94 STDMETHOD(CreateInstance
)(IUnknown FAR
* punkOuter
, REFIID riid
, void FAR
* FAR
* ppv
);
95 STDMETHOD(LockServer
)(int fLock
);
99 oslInterlockedCount m_refCount
;
100 Reference
<XSingleServiceFactory
> m_xSingleServiceFactory
;
102 DWORD m_factoryHandle
;
103 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
104 Reference
<XMultiServiceFactory
> m_smgr
;
107 /*****************************************************************************
109 class declaration OneInstanceOleWrapper_Impl
111 Provides an single UNO object as OLE object. Handle the
112 OLE registration by overloading the abstract methods from
113 IClassFactoryWrapper.
115 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
116 then it maps the XInstance member it to a COM object.
118 *****************************************************************************/
120 class OneInstanceOleWrapper_Impl
: public IClassFactoryWrapper
124 OneInstanceOleWrapper_Impl( const Reference
<XMultiServiceFactory
>& smgr
, const Reference
<XInterface
>& xInst
, GUID
* pGuid
);
125 virtual ~OneInstanceOleWrapper_Impl();
127 sal_Bool
registerClass();
128 sal_Bool
deregisterClass();
130 /* IUnknown methods */
131 STDMETHOD(QueryInterface
)(REFIID riid
, LPVOID FAR
* ppvObj
);
132 STDMETHOD_(ULONG
, AddRef
)();
133 STDMETHOD_(ULONG
, Release
)();
135 /* IClassFactory methods */
136 STDMETHOD(CreateInstance
)(IUnknown FAR
* punkOuter
, REFIID riid
, void FAR
* FAR
* ppv
);
137 STDMETHOD(LockServer
)(int fLock
);
141 oslInterlockedCount m_refCount
;
142 Reference
<XInterface
> m_xInst
;
144 DWORD m_factoryHandle
;
145 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
146 Reference
<XMultiServiceFactory
> m_smgr
;
149 /*****************************************************************************
151 class declaration OleConverter_Impl2
153 Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
155 *****************************************************************************/
157 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
158 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2
159 // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2
160 // interface does not need a Maschine Id in its createBridge function anymore,
161 // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines
162 // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and
163 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
164 // latter for OleBridgeSupplierVar1.
165 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
166 // Currently there is only one class available ( IUnknownWrapper_Impl).
167 class OleConverter_Impl2
: public WeakImplHelper2
<XBridgeSupplier2
, XInitialization
>,
168 public UnoConversionUtilities
<OleConverter_Impl2
>
171 OleConverter_Impl2( const Reference
<XMultiServiceFactory
>& smgr
);
172 OleConverter_Impl2( const Reference
<XMultiServiceFactory
>& smgr
, sal_uInt8 unoWrapperClass
, sal_uInt8 comWrapperClass
);
173 virtual ~OleConverter_Impl2();
175 // XBridgeSupplier2 ---------------------------------------------------
177 virtual Any SAL_CALL
createBridge(const Any
& modelDepObject
,
178 const Sequence
<sal_Int8
>& ProcessId
,
179 sal_Int16 sourceModelType
,
180 sal_Int16 destModelType
)
181 throw (IllegalArgumentException
, RuntimeException
);
184 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
186 // Abstract struct UnoConversionUtilities
187 virtual Reference
< XInterface
> createUnoWrapperInstance();
188 virtual Reference
< XInterface
> createComWrapperInstance();
194 /*****************************************************************************
196 class declaration OleClient_Impl
198 Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
200 *****************************************************************************/
203 class OleClient_Impl
: public WeakImplHelper1
<XMultiServiceFactory
>,
204 public UnoConversionUtilities
<OleClient_Impl
>
207 OleClient_Impl( const Reference
<XMultiServiceFactory
>& smgr
);
210 // XMultiServiceFactory
211 virtual Reference
<XInterface
> SAL_CALL
createInstance(const OUString
& ServiceSpecifier
) throw( Exception
, RuntimeException
);
212 virtual Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const OUString
& ServiceSpecifier
, const Sequence
< Any
>& Arguments
) throw (Exception
, RuntimeException
);
213 Sequence
< OUString
> SAL_CALL
getAvailableServiceNames() throw (RuntimeException
);
215 // Abstract struct UnoConversionUtilities
216 virtual Reference
< XInterface
> createUnoWrapperInstance();
217 virtual Reference
< XInterface
> createComWrapperInstance();
220 OUString
getImplementationName();
222 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
225 /*****************************************************************************
227 class declaration OleServer_Impl
229 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
230 Register the calling application as OLE automation server for
231 standard OLE object. The objects will be registered while instanciating
232 this implementation and deregistrated, if this implementation is destroyed.
234 *****************************************************************************/
236 class OleServer_Impl
: public OWeakObject
, XTypeProvider
239 OleServer_Impl( const Reference
<XMultiServiceFactory
> &smgr
);
243 virtual Any SAL_CALL
queryInterface( const Type
& aType
) throw(RuntimeException
);
244 virtual void SAL_CALL
acquire( ) throw ();
245 virtual void SAL_CALL
release( ) throw ();
248 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
);
249 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(RuntimeException
);
253 sal_Bool
provideService(const Reference
<XSingleServiceFactory
>& xMulFact
, GUID
* guid
);
254 sal_Bool
provideInstance(const Reference
<XInterface
>& xInst
, GUID
* guid
);
256 list
< IClassFactoryWrapper
* > m_wrapperList
;
257 Reference
< XBridgeSupplier2
> m_bridgeSupplier
;
259 Reference
<XMultiServiceFactory
> m_smgr
;
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */