1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: provider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 #include <ucbhelper/contentidentifier.hxx>
35 #include <osl/mutex.hxx>
36 #include <vcl/svapp.hxx>
38 #include <libgnomevfs/gnome-vfs-init.h>
39 #include "provider.hxx"
40 #include "content.hxx"
42 using namespace com::sun::star
;
45 //=========================================================================
46 //=========================================================================
48 // ContentProvider Implementation.
50 //=========================================================================
51 //=========================================================================
53 ContentProvider::ContentProvider(
54 const uno::Reference
< lang::XMultiServiceFactory
>& rSMgr
)
55 : ::ucbhelper::ContentProviderImplHelper( rSMgr
)
59 //=========================================================================
61 ContentProvider::~ContentProvider()
65 //=========================================================================
67 // XInterface methods.
69 //=========================================================================
71 XINTERFACE_IMPL_3( ContentProvider
,
74 com::sun::star::ucb::XContentProvider
);
76 //=========================================================================
78 // XTypeProvider methods.
80 //=========================================================================
82 XTYPEPROVIDER_IMPL_3( ContentProvider
,
85 com::sun::star::ucb::XContentProvider
);
87 //=========================================================================
89 // XServiceInfo methods.
91 //=========================================================================
93 XSERVICEINFO_IMPL_1( ContentProvider
,
94 rtl::OUString::createFromAscii(
95 "com.sun.star.comp.GnomeVFSContentProvider" ),
96 rtl::OUString::createFromAscii(
97 "com.sun.star.ucb.GnomeVFSContentProvider" ) );
98 //=========================================================================
100 // Service factory implementation.
102 //=========================================================================
104 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider
);
106 //=========================================================================
108 // XContentProvider methods.
110 //=========================================================================
112 uno::Reference
< com::sun::star::ucb::XContent
> SAL_CALL
113 ContentProvider::queryContent(
114 const uno::Reference
<
115 com::sun::star::ucb::XContentIdentifier
>& Identifier
)
116 throw( com::sun::star::ucb::IllegalIdentifierException
,
117 uno::RuntimeException
)
120 g_warning ("QueryContent: '%s'",
121 (const sal_Char
*)rtl::OUStringToOString
122 (Identifier
->getContentIdentifier(), RTL_TEXTENCODING_UTF8
));
125 osl::MutexGuard
aGuard( m_aMutex
);
127 // Check, if a content with given id already exists...
128 uno::Reference
< com::sun::star::ucb::XContent
> xContent
129 = queryExistingContent( Identifier
).get();
135 xContent
= new ::gvfs::Content(m_xSMgr
, this, Identifier
);
136 registerNewContent( xContent
);
138 catch ( com::sun::star::ucb::ContentCreationException
const & )
140 throw com::sun::star::ucb::IllegalIdentifierException();
143 if ( !xContent
->getIdentifier().is() )
144 throw com::sun::star::ucb::IllegalIdentifierException();
150 //============================ shlib entry points =============================================
153 // cut and paste verbatim from webdav (that sucks).
155 writeInfo( void *pRegistryKey
,
156 const rtl::OUString
&rImplementationName
,
157 uno::Sequence
< rtl::OUString
> const &rServiceNames
)
159 rtl::OUString
aKeyName( rtl::OUString::createFromAscii( "/" ) );
160 aKeyName
+= rImplementationName
;
161 aKeyName
+= rtl::OUString::createFromAscii( "/UNO/SERVICES" );
163 uno::Reference
< registry::XRegistryKey
> xKey
;
165 xKey
= static_cast< registry::XRegistryKey
* >
166 (pRegistryKey
)->createKey( aKeyName
);
168 catch ( registry::InvalidRegistryException
const & ) {
174 sal_Bool bSuccess
= sal_True
;
176 for ( sal_Int32 n
= 0; n
< rServiceNames
.getLength(); ++n
) {
178 xKey
->createKey( rServiceNames
[ n
] );
180 } catch ( registry::InvalidRegistryException
const & ) {
181 bSuccess
= sal_False
;
188 extern "C" void SAL_CALL
189 component_getImplementationEnvironment( const sal_Char
**ppEnvTypeName
,
190 uno_Environment
**/
*ppEnv*/
)
192 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
195 extern "C" sal_Bool SAL_CALL
196 component_writeInfo( void */
*pServiceManager*/
,
199 return pRegistryKey
&&
200 writeInfo( pRegistryKey
,
201 ::gvfs::ContentProvider::getImplementationName_Static(),
202 ::gvfs::ContentProvider::getSupportedServiceNames_Static() );
205 /* This class is here to be able to initialize gnome-vfs in the main thread */
206 class GnomeVFSInitializator
213 GnomeVFSInitializator() : m_bInitialized( false ) {}
217 Application::PostUserEvent( LINK( this, GnomeVFSInitializator
, ImplInitializeGnomeVFS
) );
219 // cannot use a condition variable here, leads to a deadlock
223 osl::MutexGuard
aGuard( m_aLock
);
224 if ( m_bInitialized
)
227 Application::Yield();
232 DECL_LINK( ImplInitializeGnomeVFS
, void* );
235 IMPL_LINK( GnomeVFSInitializator
, ImplInitializeGnomeVFS
, void*, EMPTYARG
)
237 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() );
239 // this must be performed in the same thread where we initialized
241 if ( !gnome_vfs_initialized () )
244 auth_queue
= g_private_new( auth_queue_destroy
);
247 m_bInitialized
= true;
253 extern "C" void * SAL_CALL
254 component_getFactory( const sal_Char
*pImplName
,
255 void *pServiceManager
,
256 void */
*pRegistryKey*/
)
260 GnomeVFSInitializator aInitializator
;
261 aInitializator
.init();
263 uno::Reference
< lang::XMultiServiceFactory
> xSMgr
264 (reinterpret_cast< lang::XMultiServiceFactory
* >( pServiceManager
) );
265 uno::Reference
< lang::XSingleServiceFactory
> xFactory
;
267 if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName
) )
268 xFactory
= ::gvfs::ContentProvider::createServiceFactory( xSMgr
);
270 if ( xFactory
.is() ) {
272 pRet
= xFactory
.get();