Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / webdav-curl / SerfLockStore.hxx
blob8b54901e1fb8003f09253f98467454eef941a61d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #pragma once
23 #include <map>
24 #include <mutex>
25 #include <rtl/ref.hxx>
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/ucb/Lock.hpp>
28 #include <utility>
30 #include "CurlSession.hxx"
32 namespace http_dav_ucp
35 class TickerThread;
37 struct LockInfo
39 OUString m_sToken;
40 css::ucb::Lock m_Lock;
41 rtl::Reference<CurlSession> m_xSession;
42 sal_Int32 m_nLastChanceToSendRefreshRequest;
44 LockInfo()
45 : m_nLastChanceToSendRefreshRequest( -1 ) {}
47 LockInfo( OUString sToken,
48 css::ucb::Lock aLock,
49 rtl::Reference<CurlSession> xSession,
50 sal_Int32 nLastChanceToSendRefreshRequest )
51 : m_sToken(std::move(sToken))
52 , m_Lock(std::move(aLock))
53 , m_xSession(std::move(xSession))
54 , m_nLastChanceToSendRefreshRequest(nLastChanceToSendRefreshRequest)
58 typedef std::map< OUString, LockInfo > LockInfoMap;
60 class SerfLockStore
62 std::mutex m_aMutex;
63 rtl::Reference< TickerThread > m_pTickerThread;
64 LockInfoMap m_aLockInfoMap;
66 public:
67 SerfLockStore();
68 ~SerfLockStore();
70 OUString const* getLockTokenForURI(OUString const& rURI, css::ucb::Lock const* pLock);
72 void addLock( const OUString& rURI,
73 css::ucb::Lock const& rLock,
74 const OUString& sToken,
75 rtl::Reference<CurlSession> const & xSession,
76 // time in seconds since Jan 1 1970
77 // -1: infinite lock, no refresh
78 sal_Int32 nLastChanceToSendRefreshRequest );
80 void removeLock(const OUString& rURI);
82 void refreshLocks();
84 private:
85 void removeLockImpl(std::unique_lock<std::mutex> & rGuard, const OUString& rURI);
86 void startTicker();
87 void stopTicker(std::unique_lock<std::mutex> & rGuard);
90 } // namespace http_dav_ucp
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */