xref: /trunk/main/extensions/source/ole/servprov.hxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SERVPROV_HXX
25 #define _SERVPROV_HXX
26 
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
29 #include <cppuhelper/implbase2.hxx>
30 #endif
31 
32 #include "ole2uno.hxx"
33 #include "unoconversionutilities.hxx"
34 
35 
36 using namespace com::sun::star::bridge;
37 using namespace cppu;
38 using namespace std;
39 
40 namespace ole_adapter
41 {
42 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance(   const Reference<XMultiServiceFactory> & xSMgr);
43 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance2(  const Reference<XMultiServiceFactory> & xSMgr);
44 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstanceVar1(   const Reference<XMultiServiceFactory> & xSMgr);
45 Reference<XInterface> SAL_CALL OleClient_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr);
46 Reference<XInterface> SAL_CALL OleServer_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr);
47 /*****************************************************************************
48 
49     class declaration IClassFactoryWrapper
50 
51     Specify abstract helper methods on class factories, which provide
52     UNO objects. These methods are used by objects of class OleServer_Impl,
53     to handle the OLE registration of different class factories.
54 
55 *****************************************************************************/
56 
57 class IClassFactoryWrapper : public IClassFactory
58 {
59 public:
60 
61     virtual sal_Bool registerClass() = 0;
62     virtual sal_Bool deregisterClass() = 0;
63 };
64 
65 /*****************************************************************************
66 
67     class declaration ProviderOleWrapper_Impl
68 
69     Provides an UNO service provider as OLE class factory. Handle the
70     OLE registration by overloading the abstract methods from
71     IClassFactoryWrapper.
72 
73     Acts as a COM class factory. When IClassFactory::CreateInstance is being called
74     then it creates an service by help of the XSingleServiceFactory member and maps
75     maps it to a COM object.
76 
77 *****************************************************************************/
78 
79 class ProviderOleWrapper_Impl : public IClassFactoryWrapper
80 {
81 public:
82 
83     ProviderOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr,
84                              const Reference<XSingleServiceFactory>& xSFactory, GUID* pGuid);
85     virtual ~ProviderOleWrapper_Impl();
86 
87     sal_Bool registerClass();
88     sal_Bool deregisterClass();
89 
90     /* IUnknown methods */
91     STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
92     STDMETHOD_(ULONG, AddRef)();
93     STDMETHOD_(ULONG, Release)();
94 
95     /* IClassFactory methods */
96     STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
97     STDMETHOD(LockServer)(int fLock);
98 
99 protected:
100 
101     oslInterlockedCount m_refCount;
102     Reference<XSingleServiceFactory> m_xSingleServiceFactory;
103     GUID                m_guid;
104     DWORD               m_factoryHandle;
105     Reference<XBridgeSupplier2> m_bridgeSupplier;
106     Reference<XMultiServiceFactory> m_smgr;
107 };
108 
109 /*****************************************************************************
110 
111     class declaration OneInstanceOleWrapper_Impl
112 
113     Provides an single UNO object as OLE object. Handle the
114     OLE registration by overloading the abstract methods from
115     IClassFactoryWrapper.
116 
117     Acts as a COM class factory. When IClassFactory::CreateInstance is being called
118     then it maps the XInstance member it to a COM object.
119 
120 *****************************************************************************/
121 
122 class OneInstanceOleWrapper_Impl : public IClassFactoryWrapper
123 {
124 public:
125 
126     OneInstanceOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, const Reference<XInterface>& xInst, GUID* pGuid, sal_Bool bAsApplication );
127     virtual ~OneInstanceOleWrapper_Impl();
128 
129     sal_Bool registerClass();
130     sal_Bool deregisterClass();
131 
132     /* IUnknown methods */
133     STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
134     STDMETHOD_(ULONG, AddRef)();
135     STDMETHOD_(ULONG, Release)();
136 
137     /* IClassFactory methods */
138     STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
139     STDMETHOD(LockServer)(int fLock);
140 
141 protected:
142 
143     //ORefCount         m_refCount;
144     oslInterlockedCount m_refCount;
145     Reference<XInterface>       m_xInst;
146     GUID                m_guid;
147     DWORD               m_factoryHandle;
148     Reference<XBridgeSupplier2> m_bridgeSupplier;
149     Reference<XMultiServiceFactory> m_smgr;
150     unsigned long       m_nApplRegHandle;
151     sal_Bool            m_bAsApplication;
152 };
153 
154 /*****************************************************************************
155 
156     class declaration OleConverter_Impl2
157 
158     Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
159 
160 *****************************************************************************/
161 
162 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
163 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2
164 // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2
165 // interface does not need a Maschine Id in its createBridge function anymore,
166 // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines
167 // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and
168 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
169 // latter for OleBridgeSupplierVar1.
170 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
171 // Currently there is only one class available ( IUnknownWrapper_Impl).
172 class OleConverter_Impl2 : public WeakImplHelper2<XBridgeSupplier2, XInitialization>,
173                             public UnoConversionUtilities<OleConverter_Impl2>
174 {
175 public:
176     OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr);
177     OleConverter_Impl2( const  Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass );
178     virtual ~OleConverter_Impl2();
179 
180     // XBridgeSupplier2 ---------------------------------------------------
181 
182     virtual Any SAL_CALL createBridge(const Any& modelDepObject,
183                                 const Sequence<sal_Int8>& ProcessId,
184                                 sal_Int16 sourceModelType,
185                                 sal_Int16 destModelType);
186 
187     // XInitialization
188     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments );
189 
190     // Abstract struct UnoConversionUtilities
191     virtual Reference< XInterface > createUnoWrapperInstance();
192     virtual Reference< XInterface > createComWrapperInstance();
193 protected:
194 
195 };
196 
197 
198 /*****************************************************************************
199 
200     class declaration OleClient_Impl
201 
202     Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
203 
204 *****************************************************************************/
205 
206 
207 class OleClient_Impl : public WeakImplHelper1<XMultiServiceFactory>,
208                        public UnoConversionUtilities<OleClient_Impl>
209 {
210 public:
211     OleClient_Impl( const Reference<XMultiServiceFactory>& smgr);
212     ~OleClient_Impl();
213 
214     // XMultiServiceFactory
215     virtual Reference<XInterface> SAL_CALL createInstance(const OUString& ServiceSpecifier);
216     virtual Reference<XInterface> SAL_CALL createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& Arguments);
217     Sequence< OUString >    SAL_CALL getAvailableServiceNames();
218 
219     // Abstract struct UnoConversionUtilities
220     virtual Reference< XInterface > createUnoWrapperInstance();
221     virtual Reference< XInterface > createComWrapperInstance();
222 
223 
224     OUString getImplementationName();
225 protected:
226     Reference<XBridgeSupplier2> m_bridgeSupplier;
227 };
228 
229 /*****************************************************************************
230 
231     class declaration OleServer_Impl
232 
233     Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
234     Register the calling application as OLE automation server for
235     standard OLE object. The objects will be registered while instantiating
236     this implementation and deregistrated, if this implementation is destroyed.
237 
238 *****************************************************************************/
239 
240 class OleServer_Impl : public OWeakObject, XTypeProvider
241 {
242 public:
243     OleServer_Impl( const Reference<XMultiServiceFactory> &smgr);
244     ~OleServer_Impl();
245 
246     // XInterface
247     virtual Any SAL_CALL queryInterface( const Type& aType );
248     virtual void SAL_CALL acquire(  ) throw ();
249     virtual void SAL_CALL release(  ) throw ();
250 
251     // XTypeProvider
252     virtual Sequence< Type > SAL_CALL getTypes( );
253     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId();
254 
255 protected:
256 
257     sal_Bool provideService(const Reference<XSingleServiceFactory>& xMulFact, GUID* guid);
258     sal_Bool provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication );
259 
260     list< IClassFactoryWrapper* > m_wrapperList;
261     Reference< XBridgeSupplier2 >   m_bridgeSupplier;
262 
263     Reference<XMultiServiceFactory> m_smgr;
264 };
265 
266 } // end namespace
267 #endif
268