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