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 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFLOCKSTORE_HXX
22 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFLOCKSTORE_HXX
23 
24 #include <map>
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
27 #include <rtl/ustring.hxx>
28 #include "SerfSession.hxx"
29 
30 namespace http_dav_ucp
31 {
32 
33 class TickerThread;
34 
35 struct LockInfo
36 {
37     OUString m_sToken;
38     rtl::Reference< SerfSession > m_xSession;
39     sal_Int32 m_nLastChanceToSendRefreshRequest;
40 
LockInfohttp_dav_ucp::LockInfo41     LockInfo()
42         : m_nLastChanceToSendRefreshRequest( -1 ) {}
43 
LockInfohttp_dav_ucp::LockInfo44     LockInfo( const OUString& sToken,
45               rtl::Reference< SerfSession > const & xSession,
46               sal_Int32 nLastChanceToSendRefreshRequest )
47     : m_sToken( sToken ),
48       m_xSession( xSession ),
49       m_nLastChanceToSendRefreshRequest( nLastChanceToSendRefreshRequest ) {}
50 };
51 
52 typedef std::map< OUString, LockInfo > LockInfoMap;
53 
54 class SerfLockStore
55 {
56     osl::Mutex         m_aMutex;
57     TickerThread     * m_pTickerThread;
58     bool               m_bFinishing;
59     LockInfoMap        m_aLockInfoMap;
60 
61 public:
62     SerfLockStore();
63     ~SerfLockStore();
64 
65     bool finishing() const;
66     OUString getLockToken( const OUString& rLock );
67 
68     void addLock( const OUString& rLock,
69                   const OUString& sToken,
70                   rtl::Reference< SerfSession > const & xSession,
71                   // time in seconds since Jan 1 1970
72                   // -1: infinite lock, no refresh
73                   sal_Int32 nLastChanceToSendRefreshRequest );
74 
75     void updateLock( const OUString& rLock,
76                      sal_Int32 nLastChanceToSendRefreshRequest );
77 
78     void removeLock( const OUString& rLock );
79 
80     void refreshLocks();
81 
82 private:
83     void startTicker();
84     void stopTicker();
85 };
86 
87 } // namespace http_dav_ucp
88 
89 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_SERFLOCKSTORE_HXX
90 
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
92