xref: /trunk/main/ucb/source/ucp/gvfs/gvfs_provider.cxx (revision 421ed02e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <ucbhelper/contentidentifier.hxx>
25 #include <libgnomevfs/gnome-vfs-init.h>
26 #include "gvfs_provider.hxx"
27 #include "gvfs_content.hxx"
28 
29 using namespace com::sun::star;
30 using namespace gvfs;
31 
32 //=========================================================================
33 //=========================================================================
34 //
35 // ContentProvider Implementation.
36 //
37 //=========================================================================
38 //=========================================================================
39 
ContentProvider(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)40 ContentProvider::ContentProvider(
41     const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
42 : ::ucbhelper::ContentProviderImplHelper( rSMgr )
43 {
44 }
45 // sdafas
46 //=========================================================================
47 // virtual
~ContentProvider()48 ContentProvider::~ContentProvider()
49 {
50 }
51 
52 //=========================================================================
53 //
54 // XInterface methods.
55 //
56 //=========================================================================
57 
58 XINTERFACE_IMPL_3( ContentProvider,
59                    lang::XTypeProvider,
60                    lang::XServiceInfo,
61                    com::sun::star::ucb::XContentProvider );
62 
63 //=========================================================================
64 //
65 // XTypeProvider methods.
66 //
67 //=========================================================================
68 
69 XTYPEPROVIDER_IMPL_3( ContentProvider,
70                       lang::XTypeProvider,
71                       lang::XServiceInfo,
72                       com::sun::star::ucb::XContentProvider );
73 
74 //=========================================================================
75 //
76 // XServiceInfo methods.
77 //
78 //=========================================================================
79 
80 XSERVICEINFO_IMPL_1( ContentProvider,
81                      rtl::OUString::createFromAscii(
82             "com.sun.star.comp.GnomeVFSContentProvider" ),
83                      rtl::OUString::createFromAscii(
84             "com.sun.star.ucb.GnomeVFSContentProvider" ) );
85 //=========================================================================
86 //
87 // Service factory implementation.
88 //
89 //=========================================================================
90 
91 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
92 
93 //=========================================================================
94 //
95 // XContentProvider methods.
96 //
97 //=========================================================================
98 
99 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
queryContent(const uno::Reference<com::sun::star::ucb::XContentIdentifier> & Identifier)100 ContentProvider::queryContent(
101             const uno::Reference<
102                     com::sun::star::ucb::XContentIdentifier >& Identifier )
103     throw( com::sun::star::ucb::IllegalIdentifierException,
104            uno::RuntimeException )
105 {
106 #ifdef DEBUG
107     g_warning ("QueryContent: '%s'",
108                rtl::OUStringToOString( Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr());
109 #endif
110 
111     osl::MutexGuard aGuard( m_aMutex );
112 
113     // Check, if a content with given id already exists...
114     uno::Reference< com::sun::star::ucb::XContent > xContent
115         = queryExistingContent( Identifier ).get();
116     if ( xContent.is() )
117         return xContent;
118 
119     try
120     {
121         xContent = new ::gvfs::Content(m_xSMgr, this, Identifier );
122         registerNewContent( xContent );
123     }
124     catch ( com::sun::star::ucb::ContentCreationException const & )
125     {
126         throw com::sun::star::ucb::IllegalIdentifierException();
127     }
128 
129     if ( !xContent->getIdentifier().is() )
130         throw com::sun::star::ucb::IllegalIdentifierException();
131 
132     return xContent;
133 }
134 
135 
136 //============================ shlib entry points =============================================
137 
138 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)139 component_getImplementationEnvironment( const sal_Char  **ppEnvTypeName,
140                     uno_Environment **/*ppEnv*/ )
141 {
142     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
143 }
144 
145 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)146 component_getFactory( const sal_Char *pImplName,
147               void           *pServiceManager,
148               void           */*pRegistryKey*/ )
149 {
150     void * pRet = 0;
151 
152     {
153         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
154         if (!gnome_vfs_initialized ())
155             gnome_vfs_init ();
156         if (!auth_queue)
157             auth_queue = g_private_new( auth_queue_destroy );
158     }
159 
160     uno::Reference< lang::XMultiServiceFactory > xSMgr
161         (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
162     uno::Reference< lang::XSingleServiceFactory > xFactory;
163 
164     if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
165         xFactory = ::gvfs::ContentProvider::createServiceFactory( xSMgr );
166 
167     if ( xFactory.is() ) {
168         xFactory->acquire();
169         pRet = xFactory.get();
170     }
171 
172     return pRet;
173 }
174 
175 
176