Debian Codegraph @

ucb/source/ucp/webdav-curl/SerfLockStore.hxx

raw
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
21 #pragma once
22
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>
29 #include <comphelper/lok.hxx>
30 #include <condition_variable>
31
32 #include "CurlSession.hxx"
33
34 namespace http_dav_ucp
35 {
36
37 class TickerThread;
38
39 struct LockInfo
40 {
41 OUString m_sToken;
42 css::ucb::Lock m_Lock;
43 rtl::Reference<CurlSession> m_xSession;
44 sal_Int32 m_nLastChanceToSendRefreshRequest;
45
46 LockInfo()
47 : m_nLastChanceToSendRefreshRequest( -1 ) {}
48
49 LockInfo( OUString sToken,
50 css::ucb::Lock aLock,
51 rtl::Reference<CurlSession> xSession,
52 sal_Int32 nLastChanceToSendRefreshRequest )
53 : m_sToken(std::move(sToken))
54 , m_Lock(std::move(aLock))
55 , m_xSession(std::move(xSession))
56 , m_nLastChanceToSendRefreshRequest(nLastChanceToSendRefreshRequest)
57 {}
58 };
59
60 typedef std::map< OUString, LockInfo > LockInfoMap;
61
62 class SerfLockStore : public comphelper::LibreOfficeKit::ThreadJoinable
63 {
64 public:
65 std::mutex m_aMutex;
66 std::condition_variable m_aCondition;
67 std::chrono::milliseconds refreshLocks(std::unique_lock<std::mutex>& rGuard);
68 rtl::Reference< TickerThread > m_pTickerThread;
69 LockInfoMap m_aLockInfoMap;
70
71 public:
72 SerfLockStore();
73 ~SerfLockStore();
74
75 OUString const* getLockTokenForURI(OUString const& rURI, css::ucb::Lock const* pLock);
76
77 void addLock( const OUString& rURI,
78 css::ucb::Lock const& rLock,
79 const OUString& sToken,
80 rtl::Reference<CurlSession> const & xSession,
81 // time in seconds since Jan 1 1970
82 // -1: infinite lock, no refresh
83 sal_Int32 nLastChanceToSendRefreshRequest );
84
85 void removeLock(const OUString& rURI);
86
87 // comphelper::LibreOfficeKit::ThreadJoinable
88 virtual bool joinThreads() override;
89 virtual void startThreads() override;
90
91 private:
92 void removeLockImpl(std::unique_lock<std::mutex> & rGuard, const OUString& rURI);
93 void startTicker(std::unique_lock<std::mutex> & rGuard);
94 void stopTicker(std::unique_lock<std::mutex> & rGuard);
95 };
96
97 } // namespace http_dav_ucp
98
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */