LibreOffice Module ucb (master) 1
DAVSessionFactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include "DAVSessionFactory.hxx"
22#include "CurlSession.hxx"
23#include "CurlUri.hxx"
24
25using namespace http_dav_ucp;
26using namespace com::sun::star;
27
28DAVSessionFactory::~DAVSessionFactory()
29{
30}
31
33 const OUString & inUri,
34 const uno::Sequence< beans::NamedValue >& rFlags,
35 const uno::Reference< uno::XComponentContext > & rxContext )
36{
37 std::unique_lock aGuard( m_aMutex );
38
39 if (!m_xProxyDecider)
40 m_xProxyDecider.reset( new ucbhelper::InternetProxyDecider( rxContext ) );
41
42 Map::iterator aIt = std::find_if(m_aMap.begin(), m_aMap.end(),
43 [&inUri, &rFlags](const Map::value_type& rEntry) { return rEntry.second->CanUse( inUri, rFlags ); });
44
45 if ( aIt == m_aMap.end() )
46 {
48 new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider) );
49
50 aIt = m_aMap.emplace( inUri, xElement.get() ).first;
51
52 aIt->second->m_aContainerIt = aIt;
53 return aIt->second;
54 }
55 else if ( osl_atomic_increment( &aIt->second->m_nRefCount ) > 1 )
56 {
57 rtl::Reference< DAVSession > xElement( aIt->second );
58 osl_atomic_decrement( &aIt->second->m_nRefCount );
59 return xElement;
60 }
61 else
62 {
63 osl_atomic_decrement( &aIt->second->m_nRefCount );
64 aIt->second->m_aContainerIt = m_aMap.end();
65
66 rtl::Reference< CurlSession > xNewStorage = new CurlSession(rxContext, this, inUri, rFlags, *m_xProxyDecider);
67 aIt->second = xNewStorage.get();
68 aIt->second->m_aContainerIt = aIt;
69 return xNewStorage;
70 }
71}
72
74{
75 assert( pElement );
76 std::unique_lock aGuard( m_aMutex );
77 if ( pElement->m_aContainerIt != m_aMap.end() )
78 m_aMap.erase( pElement->m_aContainerIt );
79}
80
81/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
implementation of libcurl HTTP/DAV back-end
Definition: CurlSession.hxx:24
rtl::Reference< DAVSession > createDAVSession(const OUString &inUri, const ::com::sun::star::uno::Sequence<::com::sun::star::beans::NamedValue > &rFlags, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
void releaseElement(const DAVSession *pElement)
std::unique_ptr< ucbhelper::InternetProxyDecider > m_xProxyDecider
DAVSessionFactory::Map::iterator m_aContainerIt
Definition: DAVSession.hxx:187