Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / gvfs / gvfs_provider.cxx
blob442468f7dc783050163a92cae641e56113f67776
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 .
21 #include <comphelper/processfactory.hxx>
22 #include <ucbhelper/contentidentifier.hxx>
23 #include <libgnomevfs/gnome-vfs-init.h>
24 #include "gvfs_provider.hxx"
25 #include "gvfs_content.hxx"
27 using namespace com::sun::star;
28 using namespace gvfs;
30 //=========================================================================
31 //=========================================================================
33 // ContentProvider Implementation.
35 //=========================================================================
36 //=========================================================================
38 ContentProvider::ContentProvider(
39 const uno::Reference< uno::XComponentContext >& rxContext )
40 : ::ucbhelper::ContentProviderImplHelper( rxContext )
43 // sdafas
44 //=========================================================================
45 // virtual
46 ContentProvider::~ContentProvider()
50 //=========================================================================
52 // XInterface methods.
54 //=========================================================================
56 XINTERFACE_IMPL_3( ContentProvider,
57 lang::XTypeProvider,
58 lang::XServiceInfo,
59 com::sun::star::ucb::XContentProvider );
61 //=========================================================================
63 // XTypeProvider methods.
65 //=========================================================================
67 XTYPEPROVIDER_IMPL_3( ContentProvider,
68 lang::XTypeProvider,
69 lang::XServiceInfo,
70 com::sun::star::ucb::XContentProvider );
72 //=========================================================================
74 // XServiceInfo methods.
76 //=========================================================================
78 XSERVICEINFO_IMPL_1_CTX( ContentProvider,
79 rtl::OUString( "com.sun.star.comp.GnomeVFSContentProvider" ),
80 rtl::OUString( "com.sun.star.ucb.GnomeVFSContentProvider" ) );
81 //=========================================================================
83 // Service factory implementation.
85 //=========================================================================
87 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
89 //=========================================================================
91 // XContentProvider methods.
93 //=========================================================================
95 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
96 ContentProvider::queryContent(
97 const uno::Reference<
98 com::sun::star::ucb::XContentIdentifier >& Identifier )
99 throw( com::sun::star::ucb::IllegalIdentifierException,
100 uno::RuntimeException )
102 #if OSL_DEBUG_LEVEL > 1
103 g_warning ("QueryContent: '%s'",
104 rtl::OUStringToOString (Identifier->getContentIdentifier(),
105 RTL_TEXTENCODING_UTF8).getStr() );
106 #endif
108 osl::MutexGuard aGuard( m_aMutex );
110 // Check, if a content with given id already exists...
111 uno::Reference< com::sun::star::ucb::XContent > xContent
112 = queryExistingContent( Identifier ).get();
113 if ( xContent.is() )
114 return xContent;
118 xContent = new ::gvfs::Content( m_xContext, this, Identifier );
119 registerNewContent( xContent );
121 catch ( com::sun::star::ucb::ContentCreationException const & )
123 throw com::sun::star::ucb::IllegalIdentifierException();
126 if ( !xContent->getIdentifier().is() )
127 throw com::sun::star::ucb::IllegalIdentifierException();
129 return xContent;
133 //============================ shlib entry points =============================================
135 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL ucpgvfs1_component_getFactory( const sal_Char *pImplName,
136 void *pServiceManager,
137 void */*pRegistryKey*/ )
139 void * pRet = 0;
142 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
143 if (!gnome_vfs_initialized ())
144 gnome_vfs_init ();
145 if (!auth_queue)
146 auth_queue = g_private_new( auth_queue_destroy );
149 uno::Reference< lang::XMultiServiceFactory > xSMgr
150 (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
151 uno::Reference< lang::XSingleServiceFactory > xFactory;
153 if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
154 xFactory = ::gvfs::ContentProvider::createServiceFactory( xSMgr );
156 if ( xFactory.is() ) {
157 xFactory->acquire();
158 pRet = xFactory.get();
161 return pRet;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */