| 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 <sal/log.hxx> |
| 21 |
#include <ucbhelper/contenthelper.hxx> |
| 22 |
#include <ucbhelper/macros.hxx> |
| 23 |
#include <cppuhelper/queryinterface.hxx> |
| 24 |
#include <cppuhelper/weak.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" |
| 29 |
|
| 30 |
namespace gio |
| 31 |
{ |
| 32 |
css::uno::Reference< css::ucb::XContent > SAL_CALL |
| 33 |
ContentProvider::queryContent( |
| 34 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier ) |
| 35 |
{ |
| 36 |
SAL_INFO("ucb.ucp.gio", "QueryContent: " << Identifier->getContentIdentifier()); |
| 37 |
osl::MutexGuard aGuard( m_aMutex ); |
| 38 |
|
| 39 |
// Check, if a content with given id already exists... |
| 40 |
rtl::Reference< ucbhelper::ContentImplHelper > xContent = queryExistingContent( Identifier ); |
| 41 |
if ( xContent.is() ) |
| 42 |
return xContent; |
| 43 |
|
| 44 |
try |
| 45 |
{ |
| 46 |
xContent = new ::gio::Content(m_xContext, this, Identifier); |
| 47 |
} |
| 48 |
catch ( css::ucb::ContentCreationException const & ) |
| 49 |
{ |
| 50 |
throw css::ucb::IllegalIdentifierException(); |
| 51 |
} |
| 52 |
|
| 53 |
if ( !xContent->getIdentifier().is() ) |
| 54 |
throw css::ucb::IllegalIdentifierException(); |
| 55 |
|
| 56 |
return xContent; |
| 57 |
} |
| 58 |
|
| 59 |
ContentProvider::ContentProvider( |
| 60 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext ) |
| 61 |
: ::ucbhelper::ContentProviderImplHelper( rxContext ) |
| 62 |
{ |
| 63 |
} |
| 64 |
|
| 65 |
ContentProvider::~ContentProvider() |
| 66 |
{ |
| 67 |
} |
| 68 |
|
| 69 |
// XInterface |
| 70 |
void SAL_CALL ContentProvider::acquire() |
| 71 |
noexcept |
| 72 |
{ |
| 73 |
OWeakObject::acquire(); |
| 74 |
} |
| 75 |
|
| 76 |
void SAL_CALL ContentProvider::release() |
| 77 |
noexcept |
| 78 |
{ |
| 79 |
OWeakObject::release(); |
| 80 |
} |
| 81 |
|
| 82 |
css::uno::Any SAL_CALL ContentProvider::queryInterface( const css::uno::Type & rType ) |
| 83 |
{ |
| 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) |
| 88 |
); |
| 89 |
return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); |
| 90 |
} |
| 91 |
|
| 92 |
XTYPEPROVIDER_IMPL_3( ContentProvider, |
| 93 |
css::lang::XTypeProvider, |
| 94 |
css::lang::XServiceInfo, |
| 95 |
css::ucb::XContentProvider ); |
| 96 |
|
| 97 |
css::uno::Sequence< OUString > SAL_CALL ContentProvider::getSupportedServiceNames() |
| 98 |
{ |
| 99 |
return { u"com.sun.star.ucb.GIOContentProvider"_ustr }; |
| 100 |
} |
| 101 |
|
| 102 |
OUString SAL_CALL ContentProvider::getImplementationName() |
| 103 |
{ |
| 104 |
return u"com.sun.star.comp.GIOContentProvider"_ustr; |
| 105 |
} |
| 106 |
|
| 107 |
sal_Bool SAL_CALL ContentProvider::supportsService(const OUString& aServiceName) |
| 108 |
{ |
| 109 |
return cppu::supportsService(this, aServiceName); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
// gio creates threads we don't want in online's forkit |
| 116 |
static bool isDisabled() |
| 117 |
{ |
| 118 |
const char *pDisable = getenv("UNODISABLELIBRARY"); |
| 119 |
if (!pDisable) |
| 120 |
return false; |
| 121 |
OString aDisable(pDisable, strlen(pDisable)); |
| 122 |
return aDisable.indexOf("ucpgio1") >= 0; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 128 |
ucb_gio_ContentProvider_get_implementation( |
| 129 |
css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) |
| 130 |
{ |
| 131 |
if (isDisabled()) |
| 132 |
return nullptr; |
| 133 |
#if !GLIB_CHECK_VERSION(2,36,0) |
| 134 |
g_type_init(); |
| 135 |
#endif |
| 136 |
return cppu::acquire(new gio::ContentProvider(context)); |
| 137 |
} |
| 138 |
|
| 139 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |