xref: /trunk/main/ucb/source/ucp/gvfs/gvfs_provider.cxx (revision 2f86921c)
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                (const sal_Char *)rtl::OUStringToOString
112                (Identifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8));
113 #endif
114 
115     osl::MutexGuard aGuard( m_aMutex );
116 
117     // Check, if a content with given id already exists...
118     uno::Reference< com::sun::star::ucb::XContent > xContent
119         = queryExistingContent( Identifier ).get();
120     if ( xContent.is() )
121         return xContent;
122 
123     try
124     {
125         xContent = new ::gvfs::Content(m_xSMgr, this, Identifier );
126         registerNewContent( xContent );
127     }
128     catch ( com::sun::star::ucb::ContentCreationException const & )
129     {
130         throw com::sun::star::ucb::IllegalIdentifierException();
131     }
132 
133     if ( !xContent->getIdentifier().is() )
134         throw com::sun::star::ucb::IllegalIdentifierException();
135 
136     return xContent;
137 }
138 
139 
140 //============================ shlib entry points =============================================
141 
142 extern "C" void SAL_CALL
143 component_getImplementationEnvironment( const sal_Char  **ppEnvTypeName,
144                     uno_Environment **/*ppEnv*/ )
145 {
146     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
147 }
148 
149 extern "C" void * SAL_CALL
150 component_getFactory( const sal_Char *pImplName,
151               void           *pServiceManager,
152               void           */*pRegistryKey*/ )
153 {
154     void * pRet = 0;
155 
156     {
157         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
158         if (!gnome_vfs_initialized ())
159             gnome_vfs_init ();
160         if (!auth_queue)
161             auth_queue = g_private_new( auth_queue_destroy );
162     }
163 
164     uno::Reference< lang::XMultiServiceFactory > xSMgr
165         (reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
166     uno::Reference< lang::XSingleServiceFactory > xFactory;
167 
168     if ( !::gvfs::ContentProvider::getImplementationName_Static().compareToAscii( pImplName ) )
169         xFactory = ::gvfs::ContentProvider::createServiceFactory( xSMgr );
170 
171     if ( xFactory.is() ) {
172         xFactory->acquire();
173         pRet = xFactory.get();
174     }
175 
176     return pRet;
177 }
178 
179 
180