xref: /trunk/main/ucb/source/ucp/gvfs/gvfs_provider.cxx (revision 24c56ab9)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucb.hxx"
26 
27 #include <ucbhelper/contentidentifier.hxx>
28 #include <libgnomevfs/gnome-vfs-init.h>
29 #include "gvfs_provider.hxx"
30 #include "gvfs_content.hxx"
31 
32 using namespace com::sun::star;
33 using namespace gvfs;
34 
35 //=========================================================================
36 //=========================================================================
37 //
38 // ContentProvider Implementation.
39 //
40 //=========================================================================
41 //=========================================================================
42 
43 ContentProvider::ContentProvider(
44     const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
45 : ::ucbhelper::ContentProviderImplHelper( rSMgr )
46 {
47 }
48 // sdafas
49 //=========================================================================
50 // virtual
51 ContentProvider::~ContentProvider()
52 {
53 }
54 
55 //=========================================================================
56 //
57 // XInterface methods.
58 //
59 //=========================================================================
60 
61 XINTERFACE_IMPL_3( ContentProvider,
62                    lang::XTypeProvider,
63                    lang::XServiceInfo,
64                    com::sun::star::ucb::XContentProvider );
65 
66 //=========================================================================
67 //
68 // XTypeProvider methods.
69 //
70 //=========================================================================
71 
72 XTYPEPROVIDER_IMPL_3( ContentProvider,
73                       lang::XTypeProvider,
74                       lang::XServiceInfo,
75                       com::sun::star::ucb::XContentProvider );
76 
77 //=========================================================================
78 //
79 // XServiceInfo methods.
80 //
81 //=========================================================================
82 
83 XSERVICEINFO_IMPL_1( ContentProvider,
84                      rtl::OUString::createFromAscii(
85             "com.sun.star.comp.GnomeVFSContentProvider" ),
86                      rtl::OUString::createFromAscii(
87             "com.sun.star.ucb.GnomeVFSContentProvider" ) );
88 //=========================================================================
89 //
90 // Service factory implementation.
91 //
92 //=========================================================================
93 
94 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
95 
96 //=========================================================================
97 //
98 // XContentProvider methods.
99 //
100 //=========================================================================
101 
102 uno::Reference< com::sun::star::ucb::XContent > SAL_CALL
103 ContentProvider::queryContent(
104             const uno::Reference<
105                     com::sun::star::ucb::XContentIdentifier >& Identifier )
106     throw( com::sun::star::ucb::IllegalIdentifierException,
107            uno::RuntimeException )
108 {
109 #ifdef DEBUG
110     g_warning ("QueryContent: '%s'",
111                rtl::OUStringToOString( Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr());
112 #endif
113 
114     osl::MutexGuard aGuard( m_aMutex );
115 
116     // Check, if a content with given id already exists...
117     uno::Reference< com::sun::star::ucb::XContent > xContent
118         = queryExistingContent( Identifier ).get();
119     if ( xContent.is() )
120         return xContent;
121 
122     try
123     {
124         xContent = new ::gvfs::Content(m_xSMgr, this, Identifier );
125         registerNewContent( xContent );
126     }
127     catch ( com::sun::star::ucb::ContentCreationException const & )
128     {
129         throw com::sun::star::ucb::IllegalIdentifierException();
130     }
131 
132     if ( !xContent->getIdentifier().is() )
133         throw com::sun::star::ucb::IllegalIdentifierException();
134 
135     return xContent;
136 }
137 
138 
139 //============================ shlib entry points =============================================
140 
141 extern "C" void SAL_CALL
142 component_getImplementationEnvironment( const sal_Char  **ppEnvTypeName,
143                     uno_Environment **/*ppEnv*/ )
144 {
145     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
146 }
147 
148 extern "C" void * SAL_CALL
149 component_getFactory( const sal_Char *pImplName,
150               void           *pServiceManager,
151               void           */*pRegistryKey*/ )
152 {
153     void * pRet = 0;
154 
155     {
156         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
157         if (!gnome_vfs_initialized ())
158             gnome_vfs_init ();
159         if (!auth_queue)
160             auth_queue = g_private_new( auth_queue_destroy );
161     }
162 
163     uno::Reference< lang::XMultiServiceFactory > xSMgr
164         (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
165     uno::Reference< lang::XSingleServiceFactory > xFactory;
166 
167     if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
168         xFactory = ::gvfs::ContentProvider::createServiceFactory( xSMgr );
169 
170     if ( xFactory.is() ) {
171         xFactory->acquire();
172         pRet = xFactory.get();
173     }
174 
175     return pRet;
176 }
177 
178 
179