| SerfLockStore.cxx (5f30f85e) | SerfLockStore.cxx (3edf6992) |
|---|---|
| 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 --- 10 unchanged lines hidden (view full) --- 19 * 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_ucb.hxx" 26 | 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 --- 10 unchanged lines hidden (view full) --- 19 * 20 *************************************************************/ 21 22 23 24// MARKER(update_precomp.py): autogen include statement, do not remove 25#include "precompiled_ucb.hxx" 26 |
| 27#include <ne_locks.h> 28#include <ne_uri.h> | |
| 29#include <rtl/ustring.hxx> 30#include <osl/time.h> 31#include <osl/thread.hxx> | 27#include <rtl/ustring.hxx> 28#include <osl/time.h> 29#include <osl/thread.hxx> |
| 30#include "SerfTypes.hxx" |
|
| 32#include "SerfSession.hxx" 33#include "SerfLockStore.hxx" 34 35using namespace http_dav_ucp; 36 37namespace http_dav_ucp { 38 39class TickerThread : public osl::Thread --- 13 unchanged lines hidden (view full) --- 53 virtual void SAL_CALL run(); 54}; 55 56} // namespace http_dav_ucp 57 58// ------------------------------------------------------------------- 59void TickerThread::run() 60{ | 31#include "SerfSession.hxx" 32#include "SerfLockStore.hxx" 33 34using namespace http_dav_ucp; 35 36namespace http_dav_ucp { 37 38class TickerThread : public osl::Thread --- 13 unchanged lines hidden (view full) --- 52 virtual void SAL_CALL run(); 53}; 54 55} // namespace http_dav_ucp 56 57// ------------------------------------------------------------------- 58void TickerThread::run() 59{ |
| 61 OSL_TRACE( "TickerThread: start." ); | 60 OSL_TRACE( "TickerThread::run: start." ); |
| 62 63 // we have to go through the loop more often to be able to finish ~quickly 64 const int nNth = 25; 65 66 int nCount = nNth; 67 while ( !m_bFinish ) 68 { 69 if ( nCount-- <= 0 ) --- 8 unchanged lines hidden (view full) --- 78 wait( aTV ); 79 } 80 81 OSL_TRACE( "TickerThread: stop." ); 82} 83 84// ------------------------------------------------------------------- 85SerfLockStore::SerfLockStore() | 61 62 // we have to go through the loop more often to be able to finish ~quickly 63 const int nNth = 25; 64 65 int nCount = nNth; 66 while ( !m_bFinish ) 67 { 68 if ( nCount-- <= 0 ) --- 8 unchanged lines hidden (view full) --- 77 wait( aTV ); 78 } 79 80 OSL_TRACE( "TickerThread: stop." ); 81} 82 83// ------------------------------------------------------------------- 84SerfLockStore::SerfLockStore() |
| 86 : m_pSerfLockStore( ne_lockstore_create() ), 87 m_pTickerThread( 0 ) | 85 : m_pTickerThread( 0 ) |
| 88{ | 86{ |
| 89 OSL_ENSURE( m_pSerfLockStore, "Unable to create neon lock store!" ); | |
| 90} 91 92// ------------------------------------------------------------------- 93SerfLockStore::~SerfLockStore() 94{ 95 stopTicker(); 96 97 // release active locks, if any. 98 OSL_ENSURE( m_aLockInfoMap.size() == 0, 99 "SerfLockStore::~SerfLockStore - Releasing active locks!" ); 100 101 LockInfoMap::const_iterator it( m_aLockInfoMap.begin() ); 102 const LockInfoMap::const_iterator end( m_aLockInfoMap.end() ); 103 while ( it != end ) 104 { 105 SerfLock * pLock = (*it).first; | 87} 88 89// ------------------------------------------------------------------- 90SerfLockStore::~SerfLockStore() 91{ 92 stopTicker(); 93 94 // release active locks, if any. 95 OSL_ENSURE( m_aLockInfoMap.size() == 0, 96 "SerfLockStore::~SerfLockStore - Releasing active locks!" ); 97 98 LockInfoMap::const_iterator it( m_aLockInfoMap.begin() ); 99 const LockInfoMap::const_iterator end( m_aLockInfoMap.end() ); 100 while ( it != end ) 101 { 102 SerfLock * pLock = (*it).first; |
| 106 (*it).second.xSession->UNLOCK( pLock ); 107 108 ne_lockstore_remove( m_pSerfLockStore, pLock ); 109 ne_lock_destroy( pLock ); 110 | 103 try 104 { 105 (*it).second.xSession->UNLOCK( pLock ); 106 (*it).second.xSession->release(); 107 } 108 catch (DAVException & ) 109 {} |
| 111 ++it; 112 } | 110 ++it; 111 } |
| 113 114 ne_lockstore_destroy( m_pSerfLockStore ); | |
| 115} 116 117// ------------------------------------------------------------------- 118void SerfLockStore::startTicker() 119{ 120 osl::MutexGuard aGuard( m_aMutex ); 121 122 if ( !m_pTickerThread ) --- 12 unchanged lines hidden (view full) --- 135 { 136 m_pTickerThread->finish(); 137 m_pTickerThread->join(); 138 delete m_pTickerThread; 139 m_pTickerThread = 0; 140 } 141} 142 | 112} 113 114// ------------------------------------------------------------------- 115void SerfLockStore::startTicker() 116{ 117 osl::MutexGuard aGuard( m_aMutex ); 118 119 if ( !m_pTickerThread ) --- 12 unchanged lines hidden (view full) --- 132 { 133 m_pTickerThread->finish(); 134 m_pTickerThread->join(); 135 delete m_pTickerThread; 136 m_pTickerThread = 0; 137 } 138} 139 |
| 140#if 0 //not currently used |
|
| 143// ------------------------------------------------------------------- | 141// ------------------------------------------------------------------- |
| 144void SerfLockStore::registerSession( HttpSession * pHttpSession ) | 142void SerfLockStore::registerSession( SerfSession /* aSession */ ) |
| 145{ 146 osl::MutexGuard aGuard( m_aMutex ); 147 | 143{ 144 osl::MutexGuard aGuard( m_aMutex ); 145 |
| 148 ne_lockstore_register( m_pSerfLockStore, pHttpSession ); | |
| 149} | 146} |
| 147#endif |
|
| 150 151// ------------------------------------------------------------------- | 148 149// ------------------------------------------------------------------- |
| 152SerfLock * SerfLockStore::findByUri( rtl::OUString const & rUri ) | 150SerfLock * SerfLockStore::findByUri( rtl::OUString const & rUri) |
| 153{ 154 osl::MutexGuard aGuard( m_aMutex ); 155 | 151{ 152 osl::MutexGuard aGuard( m_aMutex ); 153 |
| 156 ne_uri aUri; 157 ne_uri_parse( rtl::OUStringToOString( 158 rUri, RTL_TEXTENCODING_UTF8 ).getStr(), &aUri ); 159 return ne_lockstore_findbyuri( m_pSerfLockStore, &aUri ); | 154 LockInfoMap::const_iterator it( m_aLockInfoMap.begin() ); 155 const LockInfoMap::const_iterator end( m_aLockInfoMap.end() ); 156 157 while ( it != end ) 158 { 159 SerfLock * pLock = (*it).first; 160 if( pLock->getResourceUri().equals( rUri ) ) 161 { 162 return pLock; 163 } 164 ++it; 165 } 166 167 return static_cast<SerfLock*>(0); |
| 160} 161 162// ------------------------------------------------------------------- 163void SerfLockStore::addLock( SerfLock * pLock, 164 rtl::Reference< SerfSession > const & xSession, 165 sal_Int32 nLastChanceToSendRefreshRequest ) 166{ 167 osl::MutexGuard aGuard( m_aMutex ); 168 | 168} 169 170// ------------------------------------------------------------------- 171void SerfLockStore::addLock( SerfLock * pLock, 172 rtl::Reference< SerfSession > const & xSession, 173 sal_Int32 nLastChanceToSendRefreshRequest ) 174{ 175 osl::MutexGuard aGuard( m_aMutex ); 176 |
| 169 ne_lockstore_add( m_pSerfLockStore, pLock ); | |
| 170 m_aLockInfoMap[ pLock ] 171 = LockInfo( xSession, nLastChanceToSendRefreshRequest ); | 177 m_aLockInfoMap[ pLock ] 178 = LockInfo( xSession, nLastChanceToSendRefreshRequest ); |
| 179 //acquire this session, needed to manage the lock refresh 180 xSession->acquire(); |
|
| 172 | 181 |
| 182#if OSL_DEBUG_LEVEL > 0 183 rtl::OUString aOwner; 184 pLock->getLock().Owner >>= aOwner; 185 rtl::OUString aToken; 186 aToken = pLock->getLock().LockTokens[0]; 187 OSL_TRACE("SerfLockStore::addLock: new lock added aOwner '%s', token '%s'", 188 rtl::OUStringToOString(aOwner, RTL_TEXTENCODING_UTF8).getStr(), 189 rtl::OUStringToOString(aToken, RTL_TEXTENCODING_UTF8).getStr() ); 190#endif |
|
| 173 startTicker(); 174} 175 | 191 startTicker(); 192} 193 |
| 194#if 0 //not currently used |
|
| 176// ------------------------------------------------------------------- 177void SerfLockStore::updateLock( SerfLock * pLock, 178 sal_Int32 nLastChanceToSendRefreshRequest ) 179{ 180 osl::MutexGuard aGuard( m_aMutex ); 181 182 LockInfoMap::iterator it( m_aLockInfoMap.find( pLock ) ); 183 OSL_ENSURE( it != m_aLockInfoMap.end(), 184 "SerfLockStore::updateLock: lock not found!" ); 185 186 if ( it != m_aLockInfoMap.end() ) 187 { 188 (*it).second.nLastChanceToSendRefreshRequest 189 = nLastChanceToSendRefreshRequest; 190 } 191} | 195// ------------------------------------------------------------------- 196void SerfLockStore::updateLock( SerfLock * pLock, 197 sal_Int32 nLastChanceToSendRefreshRequest ) 198{ 199 osl::MutexGuard aGuard( m_aMutex ); 200 201 LockInfoMap::iterator it( m_aLockInfoMap.find( pLock ) ); 202 OSL_ENSURE( it != m_aLockInfoMap.end(), 203 "SerfLockStore::updateLock: lock not found!" ); 204 205 if ( it != m_aLockInfoMap.end() ) 206 { 207 (*it).second.nLastChanceToSendRefreshRequest 208 = nLastChanceToSendRefreshRequest; 209 } 210} |
| 211#endif |
|
| 192 193// ------------------------------------------------------------------- 194void SerfLockStore::removeLock( SerfLock * pLock ) 195{ 196 osl::MutexGuard aGuard( m_aMutex ); 197 | 212 213// ------------------------------------------------------------------- 214void SerfLockStore::removeLock( SerfLock * pLock ) 215{ 216 osl::MutexGuard aGuard( m_aMutex ); 217 |
| 198 m_aLockInfoMap.erase( pLock ); 199 ne_lockstore_remove( m_pSerfLockStore, pLock ); 200 201 if ( m_aLockInfoMap.size() == 0 ) 202 stopTicker(); | 218 LockInfoMap::iterator it( m_aLockInfoMap.find( pLock ) ); 219 if(it != m_aLockInfoMap.end()) 220 { 221 LockInfo & rInfo = (*it).second; 222 rInfo.xSession->release(); 223 m_aLockInfoMap.erase( pLock ); 224 //the caller should deallocate SerfLock class after the call! 225 if ( m_aLockInfoMap.size() == 0 ) 226 stopTicker(); 227 } |
| 203} 204 205// ------------------------------------------------------------------- 206void SerfLockStore::refreshLocks() 207{ 208 osl::MutexGuard aGuard( m_aMutex ); 209 210 LockInfoMap::iterator it( m_aLockInfoMap.begin() ); --- 5 unchanged lines hidden (view full) --- 216 { 217 // 30 seconds or less remaining until lock expires? 218 TimeValue t1; 219 osl_getSystemTime( &t1 ); 220 if ( rInfo.nLastChanceToSendRefreshRequest - 30 221 <= sal_Int32( t1.Seconds ) ) 222 { 223 // refresh the lock. | 228} 229 230// ------------------------------------------------------------------- 231void SerfLockStore::refreshLocks() 232{ 233 osl::MutexGuard aGuard( m_aMutex ); 234 235 LockInfoMap::iterator it( m_aLockInfoMap.begin() ); --- 5 unchanged lines hidden (view full) --- 241 { 242 // 30 seconds or less remaining until lock expires? 243 TimeValue t1; 244 osl_getSystemTime( &t1 ); 245 if ( rInfo.nLastChanceToSendRefreshRequest - 30 246 <= sal_Int32( t1.Seconds ) ) 247 { 248 // refresh the lock. |
| 249#if OSL_DEBUG_LEVEL > 0 250 ucb::Lock aLock = (*it).first->getLock(); 251 rtl::OUString aOwner; 252 aLock.Owner >>= aOwner; 253 rtl::OUString aToken; 254 aToken = aLock.LockTokens[0]; 255 OSL_TRACE( "SerfLockStore::refreshLocks: refresh started for lock: aOwner '%s', token '%s'", 256 rtl::OUStringToOString(aOwner, RTL_TEXTENCODING_UTF8).getStr(), 257 rtl::OUStringToOString(aToken, RTL_TEXTENCODING_UTF8).getStr() ); 258#endif |
|
| 224 sal_Int32 nlastChanceToSendRefreshRequest = -1; | 259 sal_Int32 nlastChanceToSendRefreshRequest = -1; |
| 225 if ( rInfo.xSession->LOCK( 226 (*it).first, 227 /* out param */ nlastChanceToSendRefreshRequest ) ) | 260 try |
| 228 { | 261 { |
| 262 rInfo.xSession->LOCK( (*it).first, 263 /* out param */ nlastChanceToSendRefreshRequest ); |
|
| 229 rInfo.nLastChanceToSendRefreshRequest 230 = nlastChanceToSendRefreshRequest; | 264 rInfo.nLastChanceToSendRefreshRequest 265 = nlastChanceToSendRefreshRequest; |
| 266#if OSL_DEBUG_LEVEL > 0 267 OSL_TRACE( "Lock '%s' successfully refreshed." , 268 rtl::OUStringToOString(aToken, RTL_TEXTENCODING_UTF8).getStr() ); 269#endif |
|
| 231 } | 270 } |
| 232 else | 271 catch ( DAVException & e ) |
| 233 { 234 // refresh failed. stop auto-refresh. | 272 { 273 // refresh failed. stop auto-refresh. |
| 274 // TODO i126305 discuss: 275 // probably not a good idea to stop the refresh? 276 // may be just ignore and go on, it's possible the net is temporary down? |
|
| 235 rInfo.nLastChanceToSendRefreshRequest = -1; | 277 rInfo.nLastChanceToSendRefreshRequest = -1; |
| 278#if OSL_DEBUG_LEVEL > 0 279 OSL_TRACE( "SerfLockStore::refreshLocks: Lock '%s' not refreshed! (error: DAVException.mStatusCode %d)", 280 rtl::OUStringToOString(aToken, RTL_TEXTENCODING_UTF8).getStr(), e.getStatus() ); 281#endif |
|
| 236 } 237 } 238 } 239 ++it; 240 } 241} | 282 } 283 } 284 } 285 ++it; 286 } 287} |