1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
33 #include <cppuhelper/implbase2.hxx>
36 #include "ole2uno.hxx"
37 #include "unoconversionutilities.hxx"
40 using namespace com::sun::star::bridge
;
46 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
48 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstance2( const Reference
<XMultiServiceFactory
> & xSMgr
)
50 Reference
< XInterface
> SAL_CALL
ConverterProvider_CreateInstanceVar1( const Reference
<XMultiServiceFactory
> & xSMgr
)
52 Reference
<XInterface
> SAL_CALL
OleClient_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
54 Reference
<XInterface
> SAL_CALL
OleServer_CreateInstance( const Reference
<XMultiServiceFactory
> & xSMgr
)
56 /*****************************************************************************
58 class declaration IClassFactoryWrapper
60 Specify abstract helper methods on class factories, which provide
61 UNO objects. These methods are used by objects of class OleServer_Impl,
62 to handle the OLE registration of different class factories.
64 *****************************************************************************/
66 class IClassFactoryWrapper
: public IClassFactory
70 virtual sal_Bool
registerClass() = 0;
71 virtual sal_Bool
deregisterClass() = 0;
74 /*****************************************************************************
76 class declaration ProviderOleWrapper_Impl
78 Provides an UNO service provider as OLE class factory. Handle the
79 OLE registration by overloading the abstract methods from
82 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
83 then it creates an service by help of the XSingleServiceFactory member and maps
84 maps it to a COM object.
86 *****************************************************************************/
88 class ProviderOleWrapper_Impl
: public IClassFactoryWrapper
92 ProviderOleWrapper_Impl( const Reference
<XMultiServiceFactory
>& smgr
,
93 const Reference
<XSingleServiceFactory
>& xSFactory
, GUID
* pGuid
);
94 virtual ~ProviderOleWrapper_Impl();
96 sal_Bool
registerClass();
97 sal_Bool
deregisterClass();
99 /* IUnknown methods */
100 STDMETHOD(QueryInterface
)(REFIID riid
, LPVOID FAR
* ppvObj
);
101 STDMETHOD_(ULONG
, AddRef
)();
102 STDMETHOD_(ULONG
, Release
)();
104 /* IClassFactory methods */
105 STDMETHOD(CreateInstance
)(IUnknown FAR
* punkOuter
, REFIID riid
, void FAR
* FAR
* ppv
);
106 STDMETHOD(LockServer
)(int fLock
);
110 oslInterlockedCount m_refCount
;
111 Reference
<XSingleServiceFactory
> m_xSingleServiceFactory
;
113 DWORD m_factoryHandle
;
114 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
115 Reference
<XMultiServiceFactory
> m_smgr
;
118 /*****************************************************************************
120 class declaration OneInstanceOleWrapper_Impl
122 Provides an single UNO object as OLE object. Handle the
123 OLE registration by overloading the abstract methods from
124 IClassFactoryWrapper.
126 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
127 then it maps the XInstance member it to a COM object.
129 *****************************************************************************/
131 class OneInstanceOleWrapper_Impl
: public IClassFactoryWrapper
135 OneInstanceOleWrapper_Impl( const Reference
<XMultiServiceFactory
>& smgr
, const Reference
<XInterface
>& xInst
, GUID
* pGuid
, sal_Bool bAsApplication
);
136 virtual ~OneInstanceOleWrapper_Impl();
138 sal_Bool
registerClass();
139 sal_Bool
deregisterClass();
141 /* IUnknown methods */
142 STDMETHOD(QueryInterface
)(REFIID riid
, LPVOID FAR
* ppvObj
);
143 STDMETHOD_(ULONG
, AddRef
)();
144 STDMETHOD_(ULONG
, Release
)();
146 /* IClassFactory methods */
147 STDMETHOD(CreateInstance
)(IUnknown FAR
* punkOuter
, REFIID riid
, void FAR
* FAR
* ppv
);
148 STDMETHOD(LockServer
)(int fLock
);
152 //ORefCount m_refCount;
153 oslInterlockedCount m_refCount
;
154 Reference
<XInterface
> m_xInst
;
156 DWORD m_factoryHandle
;
157 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
158 Reference
<XMultiServiceFactory
> m_smgr
;
159 unsigned long m_nApplRegHandle
;
160 sal_Bool m_bAsApplication
;
163 /*****************************************************************************
165 class declaration OleConverter_Impl2
167 Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
169 *****************************************************************************/
171 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
172 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2
173 // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2
174 // interface does not need a Maschine Id in its createBridge function anymore,
175 // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines
176 // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and
177 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
178 // latter for OleBridgeSupplierVar1.
179 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
180 // Currently there is only one class available ( IUnknownWrapper_Impl).
181 class OleConverter_Impl2
: public WeakImplHelper2
<XBridgeSupplier2
, XInitialization
>,
182 public UnoConversionUtilities
<OleConverter_Impl2
>
185 OleConverter_Impl2( const Reference
<XMultiServiceFactory
>& smgr
);
186 OleConverter_Impl2( const Reference
<XMultiServiceFactory
>& smgr
, sal_uInt8 unoWrapperClass
, sal_uInt8 comWrapperClass
);
187 virtual ~OleConverter_Impl2();
189 // XBridgeSupplier2 ---------------------------------------------------
191 virtual Any SAL_CALL
createBridge(const Any
& modelDepObject
,
192 const Sequence
<sal_Int8
>& ProcessId
,
193 sal_Int16 sourceModelType
,
194 sal_Int16 destModelType
)
195 throw (IllegalArgumentException
, RuntimeException
);
198 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
200 // Abstract struct UnoConversionUtilities
201 virtual Reference
< XInterface
> createUnoWrapperInstance();
202 virtual Reference
< XInterface
> createComWrapperInstance();
208 /*****************************************************************************
210 class declaration OleClient_Impl
212 Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
214 *****************************************************************************/
217 class OleClient_Impl
: public WeakImplHelper1
<XMultiServiceFactory
>,
218 public UnoConversionUtilities
<OleClient_Impl
>
221 OleClient_Impl( const Reference
<XMultiServiceFactory
>& smgr
);
224 // XMultiServiceFactory
225 virtual Reference
<XInterface
> SAL_CALL
createInstance(const OUString
& ServiceSpecifier
) throw( Exception
, RuntimeException
);
226 virtual Reference
<XInterface
> SAL_CALL
createInstanceWithArguments(const OUString
& ServiceSpecifier
, const Sequence
< Any
>& Arguments
) throw (Exception
, RuntimeException
);
227 Sequence
< OUString
> SAL_CALL
getAvailableServiceNames() throw (RuntimeException
);
229 // Abstract struct UnoConversionUtilities
230 virtual Reference
< XInterface
> createUnoWrapperInstance();
231 virtual Reference
< XInterface
> createComWrapperInstance();
234 OUString
getImplementationName();
236 Reference
<XBridgeSupplier2
> m_bridgeSupplier
;
239 /*****************************************************************************
241 class declaration OleServer_Impl
243 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
244 Register the calling application as OLE automation server for
245 standard OLE object. The objects will be registered while instanciating
246 this implementation and deregistrated, if this implementation is destroyed.
248 *****************************************************************************/
250 class OleServer_Impl
: public OWeakObject
, XTypeProvider
253 OleServer_Impl( const Reference
<XMultiServiceFactory
> &smgr
);
257 virtual Any SAL_CALL
queryInterface( const Type
& aType
) throw(RuntimeException
);
258 virtual void SAL_CALL
acquire( ) throw ();
259 virtual void SAL_CALL
release( ) throw ();
262 virtual Sequence
< Type
> SAL_CALL
getTypes( ) throw(RuntimeException
);
263 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(RuntimeException
);
267 sal_Bool
provideService(const Reference
<XSingleServiceFactory
>& xMulFact
, GUID
* guid
);
268 sal_Bool
provideInstance(const Reference
<XInterface
>& xInst
, GUID
* guid
, sal_Bool bAsApplication
);
270 list
< IClassFactoryWrapper
* > m_wrapperList
;
271 Reference
< XBridgeSupplier2
> m_bridgeSupplier
;
273 Reference
<XMultiServiceFactory
> m_smgr
;