Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / gio / gio_provider.cxx
blob912de0e8e0088fde9edf59a361086e9bf018c143
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/log.hxx>
21 #include <ucbhelper/contenthelper.hxx>
22 #include <ucbhelper/getcomponentcontext.hxx>
23 #include <ucbhelper/macros.hxx>
24 #include <cppuhelper/queryinterface.hxx>
25 #include <com/sun/star/ucb/ContentCreationException.hpp>
26 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
27 #include "gio_provider.hxx"
28 #include "gio_content.hxx"
30 namespace gio
32 css::uno::Reference< css::ucb::XContent > SAL_CALL
33 ContentProvider::queryContent(
34 const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier )
36 SAL_INFO("ucb.ucp.gio", "QueryContent: " << Identifier->getContentIdentifier());
37 osl::MutexGuard aGuard( m_aMutex );
39 // Check, if a content with given id already exists...
40 css::uno::Reference< css::ucb::XContent > xContent = queryExistingContent( Identifier ).get();
41 if ( xContent.is() )
42 return xContent;
44 try
46 xContent = new ::gio::Content(m_xContext, this, Identifier);
48 catch ( css::ucb::ContentCreationException const & )
50 throw css::ucb::IllegalIdentifierException();
53 if ( !xContent->getIdentifier().is() )
54 throw css::ucb::IllegalIdentifierException();
56 return xContent;
59 ContentProvider::ContentProvider(
60 const css::uno::Reference< css::uno::XComponentContext >& rxContext )
61 : ::ucbhelper::ContentProviderImplHelper( rxContext )
65 ContentProvider::~ContentProvider()
69 // XInterface
70 void SAL_CALL ContentProvider::acquire()
71 throw()
73 OWeakObject::acquire();
76 void SAL_CALL ContentProvider::release()
77 throw()
79 OWeakObject::release();
82 css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType )
84 css::uno::Any aRet = cppu::queryInterface( rType,
85 static_cast< css::lang::XTypeProvider* >(this),
86 static_cast< css::lang::XServiceInfo* >(this),
87 static_cast< css::ucb::XContentProvider* >(this)
89 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
92 XTYPEPROVIDER_IMPL_3( ContentProvider,
93 css::lang::XTypeProvider,
94 css::lang::XServiceInfo,
95 css::ucb::XContentProvider );
97 XSERVICEINFO_COMMOM_IMPL( ContentProvider,
98 "com.sun.star.comp.GIOContentProvider" )
99 /// @throws css::uno::Exception
100 static css::uno::Reference< css::uno::XInterface >
101 ContentProvider_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
103 css::lang::XServiceInfo* pX = new ContentProvider( ucbhelper::getComponentContext(rSMgr) );
104 return css::uno::Reference< css::uno::XInterface >::query( pX );
107 css::uno::Sequence< OUString >
108 ContentProvider::getSupportedServiceNames_Static()
110 css::uno::Sequence< OUString > aSNS { "com.sun.star.ucb.GIOContentProvider" };
111 return aSNS;
114 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
118 extern "C" SAL_DLLPUBLIC_EXPORT void * ucpgio1_component_getFactory( const sal_Char *pImplName,
119 void *pServiceManager, void * )
121 void * pRet = nullptr;
123 css::uno::Reference< css::lang::XMultiServiceFactory > xSMgr
124 (static_cast< css::lang::XMultiServiceFactory * >( pServiceManager ) );
125 css::uno::Reference< css::lang::XSingleServiceFactory > xFactory;
126 #if !GLIB_CHECK_VERSION(2,36,0)
127 g_type_init();
128 #endif
129 if ( ::gio::ContentProvider::getImplementationName_Static().equalsAscii( pImplName ) )
130 xFactory = ::gio::ContentProvider::createServiceFactory( xSMgr );
132 if ( xFactory.is() )
134 xFactory->acquire();
135 pRet = xFactory.get();
138 return pRet;
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */