LibreOffice Module embedserv (master) 1
servprov.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <stdafx.h>
21#include <servprov.hxx>
22#include <embeddoc.hxx>
23#include <com/sun/star/lang/XMultiServiceFactory.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
26#include <osl/diagnose.h>
27#include <osl/mutex.hxx>
28#include <osl/thread.h>
29#include <sal/log.hxx>
30
31using namespace com::sun::star;
32
33const GUID* const guidList[ SUPPORTED_FACTORIES_NUM ] = {
44};
45
47{
48 [[maybe_unused]] static thread_local bool aInit = []
49 {
50 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
51 if (!SUCCEEDED(hr))
52 { // FIXME: is it a problem that this ends up in STA currently?
53 assert(RPC_E_CHANGED_MODE == hr);
54 SAL_INFO("embedserv.ole",
55 "CoInitializeEx fail: probably thread is in STA already?");
56 }
57 return SUCCEEDED(hr);
58 }();
59}
60
61
62// EmbedServer_Impl
63
64EmbedServer_Impl::EmbedServer_Impl( const uno::Reference<lang::XMultiServiceFactory>& xFactory):
65 m_xFactory( xFactory)
66{
67 for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
68 {
70 m_pOLEFactories[nInd]->registerClass();
71 }
72}
73
75{
76 for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
77 {
78 if ( m_pOLEFactories[nInd] )
79 m_pOLEFactories[nInd]->deregisterClass();
80 }
81}
82
84{
85 return "com.sun.star.comp.ole.EmbedServer";
86}
87
88sal_Bool EmbedServer_Impl::supportsService(OUString const & ServiceName)
89{
91}
92
93css::uno::Sequence<OUString> EmbedServer_Impl::getSupportedServiceNames()
94{
95 return css::uno::Sequence<OUString>{
96 "com.sun.star.document.OleEmbeddedServerRegistration"};
97}
98
99// EmbedProviderFactory_Impl
100
101EmbedProviderFactory_Impl::EmbedProviderFactory_Impl(const uno::Reference<lang::XMultiServiceFactory>& xFactory, const GUID* pGuid)
102 : m_refCount( 0 )
103 , m_guid( *pGuid )
104 , m_xFactory( xFactory )
105{
106}
107
109{
110}
111
113{
114 HRESULT hresult;
115
117
118 hresult = CoRegisterClassObject(
119 m_guid,
120 this,
121 CLSCTX_LOCAL_SERVER,
122 REGCLS_MULTIPLEUSE,
124
125 return (hresult == NOERROR);
126}
127
129{
130 HRESULT hresult = CoRevokeClassObject( m_factoryHandle );
131
132 return (hresult == NOERROR);
133}
134
135COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedProviderFactory_Impl::QueryInterface(REFIID riid, void** ppv)
136{
137 if(IsEqualIID(riid, IID_IUnknown))
138 {
139 AddRef();
140 *ppv = static_cast<IUnknown*>(static_cast<IClassFactory*>(this));
141 return NOERROR;
142 }
143 else if (IsEqualIID(riid, IID_IClassFactory))
144 {
145 AddRef();
146 *ppv = static_cast<IClassFactory*>(this);
147 return NOERROR;
148 }
149
150 *ppv = nullptr;
151 return ResultFromScode(E_NOINTERFACE);
152}
153
154COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) EmbedProviderFactory_Impl::AddRef()
155{
156 return osl_atomic_increment( &m_refCount);
157}
158
159COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) EmbedProviderFactory_Impl::Release()
160{
161 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex());
162 sal_Int32 nCount = --m_refCount;
163 if ( nCount == 0 )
164 {
165 delete this;
166 }
167
168 return nCount;
169}
170
171COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedProviderFactory_Impl::CreateInstance(IUnknown*,
172 REFIID riid, void** ppv)
173{
174 IUnknown* pEmbedDocument = static_cast<IPersistStorage*>( new EmbedDocument_Impl( m_xFactory, &m_guid ) );
175
176 return pEmbedDocument->QueryInterface( riid, ppv );
177}
178
179COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedProviderFactory_Impl::LockServer( int /*fLock*/ )
180{
181 return NOERROR;
182}
183
184
185extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
187 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
188{
189 auto msf = uno::Reference<lang::XMultiServiceFactory>(context->getServiceManager(), css::uno::UNO_QUERY_THROW);
190 return cppu::acquire(new EmbedServer_Impl(msf));
191}
192
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~EmbedProviderFactory_Impl()
Definition: servprov.cxx:108
STDMETHOD() QueryInterface(REFIID riid, LPVOID *ppvObj) override
Definition: servprov.cxx:135
oslInterlockedCount m_refCount
Definition: servprov.hxx:72
css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory
Definition: servprov.hxx:76
EmbedProviderFactory_Impl(const css::uno::Reference< css::lang::XMultiServiceFactory > &xFactory, const GUID *pGuid)
Definition: servprov.cxx:101
STDMETHOD() CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv) override
Definition: servprov.cxx:171
STDMETHOD() LockServer(int fLock) override
Definition: servprov.cxx:179
CComPtr< EmbedProviderFactory_Impl > m_pOLEFactories[SUPPORTED_FACTORIES_NUM]
Definition: servprov.hxx:47
OUString SAL_CALL getImplementationName() override
Definition: servprov.cxx:83
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: servprov.cxx:93
css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory
Definition: servprov.hxx:48
virtual ~EmbedServer_Impl() override
Definition: servprov.cxx:74
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
Definition: servprov.cxx:88
EmbedServer_Impl(const css::uno::Reference< css::lang::XMultiServiceFactory > &xFactory)
Definition: servprov.cxx:64
int nCount
ULONG m_refCount
Definition: dllentry.cxx:155
GUID m_guid
Definition: dllentry.cxx:156
#define SUPPORTED_FACTORIES_NUM
Definition: embservconst.h:27
const GUID DECLSPEC_SELECTANY OID_PresentationServer
Definition: embservconst.h:39
const GUID DECLSPEC_SELECTANY OID_MathServer
Definition: embservconst.h:43
const GUID DECLSPEC_SELECTANY OID_DrawingServer
Definition: embservconst.h:35
const GUID DECLSPEC_SELECTANY OID_CalcServer
Definition: embservconst.h:32
const GUID DECLSPEC_SELECTANY OID_MathOASISServer
Definition: embservconst.h:44
const GUID DECLSPEC_SELECTANY OID_WriterTextServer
Definition: embservconst.h:29
const GUID DECLSPEC_SELECTANY OID_WriterOASISTextServer
Definition: embservconst.h:30
const GUID DECLSPEC_SELECTANY OID_CalcOASISServer
Definition: embservconst.h:33
const GUID DECLSPEC_SELECTANY OID_DrawingOASISServer
Definition: embservconst.h:36
const GUID DECLSPEC_SELECTANY OID_PresentationOASISServer
Definition: embservconst.h:41
Reference< XSingleServiceFactory > xFactory
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static void o2u_attachCurrentThread()
Definition: servprov.cxx:46
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * embedserv_EmbedServer(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: servprov.cxx:186
const GUID *const guidList[SUPPORTED_FACTORIES_NUM]
Definition: servprov.cxx:33
COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) EmbedProviderFactory_Impl
Definition: servprov.cxx:154
return hr
unsigned char sal_Bool