18590a0fdSAndre Fischer /**************************************************************
28590a0fdSAndre Fischer  *
38590a0fdSAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
48590a0fdSAndre Fischer  * or more contributor license agreements.  See the NOTICE file
58590a0fdSAndre Fischer  * distributed with this work for additional information
68590a0fdSAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
78590a0fdSAndre Fischer  * to you under the Apache License, Version 2.0 (the
88590a0fdSAndre Fischer  * "License"); you may not use this file except in compliance
98590a0fdSAndre Fischer  * with the License.  You may obtain a copy of the License at
108590a0fdSAndre Fischer  *
118590a0fdSAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
128590a0fdSAndre Fischer  *
138590a0fdSAndre Fischer  * Unless required by applicable law or agreed to in writing,
148590a0fdSAndre Fischer  * software distributed under the License is distributed on an
158590a0fdSAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
168590a0fdSAndre Fischer  * KIND, either express or implied.  See the License for the
178590a0fdSAndre Fischer  * specific language governing permissions and limitations
188590a0fdSAndre Fischer  * under the License.
198590a0fdSAndre Fischer  *
208590a0fdSAndre Fischer  *************************************************************/
218590a0fdSAndre Fischer 
228590a0fdSAndre Fischer 
238590a0fdSAndre Fischer #ifndef INCLUDED_SERFLOCKSTORE_HXX
248590a0fdSAndre Fischer #define INCLUDED_SERFLOCKSTORE_HXX
258590a0fdSAndre Fischer 
268590a0fdSAndre Fischer #include <map>
27c1c10f68SAriel Constenla-Haile #include <osl/mutex.hxx>
28c1c10f68SAriel Constenla-Haile #include <rtl/ref.hxx>
298590a0fdSAndre Fischer #include "SerfTypes.hxx"
30*3edf6992SAndrea Pescetti #include "SerfSession.hxx"
318590a0fdSAndre Fischer 
328590a0fdSAndre Fischer namespace http_dav_ucp
338590a0fdSAndre Fischer {
348590a0fdSAndre Fischer 
358590a0fdSAndre Fischer class TickerThread;
368590a0fdSAndre Fischer class SerfSession;
378590a0fdSAndre Fischer 
388590a0fdSAndre Fischer struct ltptr
398590a0fdSAndre Fischer {
operator ()http_dav_ucp::ltptr408590a0fdSAndre Fischer     bool operator()( const SerfLock * p1, const SerfLock * p2 ) const
418590a0fdSAndre Fischer     {
428590a0fdSAndre Fischer         return p1 < p2;
438590a0fdSAndre Fischer     }
448590a0fdSAndre Fischer };
458590a0fdSAndre Fischer 
468590a0fdSAndre Fischer typedef struct _LockInfo
478590a0fdSAndre Fischer {
488590a0fdSAndre Fischer     rtl::Reference< SerfSession > xSession;
498590a0fdSAndre Fischer     sal_Int32 nLastChanceToSendRefreshRequest;
508590a0fdSAndre Fischer 
_LockInfohttp_dav_ucp::_LockInfo518590a0fdSAndre Fischer     _LockInfo()
528590a0fdSAndre Fischer         : nLastChanceToSendRefreshRequest( -1 ) {}
538590a0fdSAndre Fischer 
_LockInfohttp_dav_ucp::_LockInfo548590a0fdSAndre Fischer     _LockInfo( rtl::Reference< SerfSession > const & _xSession,
558590a0fdSAndre Fischer               sal_Int32 _nLastChanceToSendRefreshRequest )
56*3edf6992SAndrea Pescetti         : xSession( _xSession )
57*3edf6992SAndrea Pescetti         , nLastChanceToSendRefreshRequest( _nLastChanceToSendRefreshRequest ) {}
588590a0fdSAndre Fischer 
598590a0fdSAndre Fischer } LockInfo;
608590a0fdSAndre Fischer 
618590a0fdSAndre Fischer typedef std::map< SerfLock *, LockInfo, ltptr > LockInfoMap;
628590a0fdSAndre Fischer 
638590a0fdSAndre Fischer class SerfLockStore
648590a0fdSAndre Fischer {
658590a0fdSAndre Fischer     osl::Mutex         m_aMutex;
668590a0fdSAndre Fischer     TickerThread     * m_pTickerThread;
678590a0fdSAndre Fischer     LockInfoMap        m_aLockInfoMap;
688590a0fdSAndre Fischer 
698590a0fdSAndre Fischer public:
708590a0fdSAndre Fischer     SerfLockStore();
718590a0fdSAndre Fischer     ~SerfLockStore();
728590a0fdSAndre Fischer 
73*3edf6992SAndrea Pescetti     void registerSession( SerfSession aSession );
748590a0fdSAndre Fischer 
758590a0fdSAndre Fischer     SerfLock * findByUri( rtl::OUString const & rUri );
768590a0fdSAndre Fischer 
778590a0fdSAndre Fischer     void addLock( SerfLock * pLock,
788590a0fdSAndre Fischer                   rtl::Reference< SerfSession > const & xSession,
798590a0fdSAndre Fischer                   // time in seconds since Jan 1 1970
808590a0fdSAndre Fischer                   // -1: infinite lock, no refresh
818590a0fdSAndre Fischer                   sal_Int32 nLastChanceToSendRefreshRequest );
828590a0fdSAndre Fischer 
838590a0fdSAndre Fischer     void updateLock( SerfLock * pLock,
848590a0fdSAndre Fischer                      sal_Int32 nLastChanceToSendRefreshRequest );
858590a0fdSAndre Fischer 
868590a0fdSAndre Fischer     void removeLock( SerfLock * pLock );
878590a0fdSAndre Fischer 
888590a0fdSAndre Fischer     void refreshLocks();
898590a0fdSAndre Fischer 
908590a0fdSAndre Fischer private:
918590a0fdSAndre Fischer     void startTicker();
928590a0fdSAndre Fischer     void stopTicker();
938590a0fdSAndre Fischer };
948590a0fdSAndre Fischer 
958590a0fdSAndre Fischer } // namespace http_dav_ucp
968590a0fdSAndre Fischer 
978590a0fdSAndre Fischer #endif // INCLUDED_SERFLOCKSTORE_HXX
98