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 #ifndef INCLUDED_CURLLOCKSTORE_HXX
24 #define INCLUDED_CURLLOCKSTORE_HXX
25 
26 #include <map>
27 #include <osl/mutex.hxx>
28 #include <rtl/ref.hxx>
29 #include "CurlTypes.hxx"
30 #include "CurlSession.hxx"
31 
32 namespace http_dav_ucp
33 {
34 
35 class TickerThread;
36 class CurlSession;
37 
38 struct ltptr
39 {
operator ()http_dav_ucp::ltptr40     bool operator()( const CurlLock * p1, const CurlLock * p2 ) const
41     {
42         return p1 < p2;
43     }
44 };
45 
46 typedef struct _LockInfo
47 {
48     rtl::Reference< CurlSession > xSession;
49     sal_Int32 nLastChanceToSendRefreshRequest;
50 
_LockInfohttp_dav_ucp::_LockInfo51     _LockInfo()
52         : nLastChanceToSendRefreshRequest( -1 ) {}
53 
_LockInfohttp_dav_ucp::_LockInfo54     _LockInfo( rtl::Reference< CurlSession > const & _xSession,
55               sal_Int32 _nLastChanceToSendRefreshRequest )
56         : xSession( _xSession )
57         , nLastChanceToSendRefreshRequest( _nLastChanceToSendRefreshRequest ) {}
58 
59 } LockInfo;
60 
61 typedef std::map< CurlLock *, LockInfo, ltptr > LockInfoMap;
62 
63 class CurlLockStore
64 {
65     osl::Mutex         m_aMutex;
66     TickerThread     * m_pTickerThread;
67     LockInfoMap        m_aLockInfoMap;
68 
69 public:
70     CurlLockStore();
71     ~CurlLockStore();
72 
73     void registerSession( CurlSession aSession );
74 
75     CurlLock * findByUri( rtl::OUString const & rUri );
76 
77     void addLock( CurlLock * pLock,
78                   rtl::Reference< CurlSession > const & xSession,
79                   // time in seconds since Jan 1 1970
80                   // -1: infinite lock, no refresh
81                   sal_Int32 nLastChanceToSendRefreshRequest );
82 
83     void updateLock( CurlLock * pLock,
84                      sal_Int32 nLastChanceToSendRefreshRequest );
85 
86     void removeLock( CurlLock * pLock );
87 
88     void refreshLocks();
89 
90 private:
91     void startTicker();
92     void stopTicker();
93 };
94 
95 } // namespace http_dav_ucp
96 
97 #endif // INCLUDED_CURLLOCKSTORE_HXX
98