1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: disposetimer.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef CONFIGMGR_DISPOSETIMER_HXX
32 #define CONFIGMGR_DISPOSETIMER_HXX
34 #include "timestamp.hxx"
35 #include "requestoptions.hxx"
36 #include <osl/mutex.hxx>
37 #include <vos/timer.hxx>
38 #include <vos/ref.hxx>
39 #include <com/sun/star/lang/WrappedTargetException.hpp>
40 #include <com/sun/star/uno/RuntimeException.hpp>
42 #ifndef INCLUDED_UTILITY
44 #define INCLUDED_UTILITY
51 namespace uno
= ::com::sun::star::uno
;
52 namespace lang
= ::com::sun::star::lang
;
56 namespace backend
{ class CacheController
; }
57 ////////////////////////////////////////////////////////////////////////////////
58 /* OTreeDisposeScheduler:
59 does something special????
62 class OTreeDisposeScheduler
64 typedef std::multimap
< TimeStamp
, RequestOptions
, ltTimeStamp
> Agenda
;
66 class Timer
: public vos::OTimer
69 OTreeDisposeScheduler
* pParent
;
71 Timer(OTreeDisposeScheduler
& _rParent
) : pParent(&_rParent
) {};
74 virtual void SAL_CALL
onShot();
76 // stop the scheduling
77 void dispose() {stop(); pParent
= NULL
;}
79 friend void Timer::onShot();
83 vos::ORef
<Timer
> m_xTimer
;
84 backend::CacheController
& m_rTreeManager
;
86 TimeInterval m_aCleanupDelay
;
87 TimeInterval m_aCleanupInterval
;
89 //-------- Construction and destruction -----------------------------------
91 OTreeDisposeScheduler(backend::CacheController
& _rTreeManager
, TimeInterval
const& _aCleanupDelay
)
92 : m_rTreeManager(_rTreeManager
)
93 , m_aCleanupDelay(_aCleanupDelay
)
94 , m_aCleanupInterval(_aCleanupDelay
)
96 m_xTimer
= new Timer(*this);
100 OTreeDisposeScheduler(backend::CacheController
& _rTreeManager
, TimeInterval
const& _aCleanupDelay
, TimeInterval
const& _aCleanupInterval
)
101 : m_rTreeManager(_rTreeManager
)
102 , m_aCleanupDelay(_aCleanupDelay
)
103 , m_aCleanupInterval(_aCleanupInterval
)
105 m_xTimer
= new Timer(*this);
108 ~OTreeDisposeScheduler() { stopAndClearTasks(); }
110 //-------- Delay and Interval ---------------------------------------------
111 /// sets the initial delay to be used for cleanup in the future, does not affect an already started process
112 void setCleanupDelay(TimeInterval
const& _aCleanupDelay
)
114 m_aCleanupDelay
= _aCleanupDelay
;
117 /// sets the initial delay and recurrance interval to be used for cleanup in the future, does not affect an already started process
118 void setCleanupDelay(TimeInterval
const& _aCleanupDelay
, TimeInterval
const& _aCleanupInterval
)
120 m_aCleanupDelay
= _aCleanupDelay
;
121 m_aCleanupInterval
= _aCleanupInterval
;
124 /// sets the recurrance interval to be used for cleanup in the future, does not affect an already started process
125 void setCleanupInterval(TimeInterval
const& _aCleanupInterval
)
127 m_aCleanupInterval
= _aCleanupInterval
;
130 /// retrieves the initial delay used for cleanup
131 TimeInterval
const& getCleanupDelay() const
133 return m_aCleanupDelay
;
136 /// retrieves the recurrance interval used for cleanup
137 TimeInterval
const& getCleanupInterval() const
139 return m_aCleanupInterval
;
142 //-------- Control of execution ------------------------------------------
143 /// ensure this will execute cleanup duties for _xOptions (no later than after getCleanupDelay() has elapsed)
144 void scheduleCleanup(RequestOptions
const & _aOptions
);
146 /// stop and discard pending activities
147 void stopAndClearTasks();
153 std::pair
<bool,RequestOptions
> getTask(TimeStamp
const& _aActualTime
, TimeStamp
& _aNextTime
);
155 /// ensure this will execute cleanup duties for _xOptions (no later than after getCleanupDelay() has elapsed)
156 // TimeStamp fillDisposeList(CacheLoadingAccess & _aCache, DisposeList& _rList, TimeStamp const& aLimitTime)
158 TimeStamp
runDisposer(TimeStamp
const& _aActualTime
);
160 TimeStamp
implAddTask(RequestOptions
const& _xOptions
, TimeStamp
const& _aTime
);
161 void implStartBefore(TimeStamp
const& _aTime
);
163 static TimeStamp
implGetCleanupTime(TimeStamp
const& aPostingTime
, TimeInterval
const& aDelay
)
164 { return aPostingTime
+ aDelay
; }
168 ////////////////////////////////////////////////////////////////////////////////
169 } // namespace configmgr
171 #endif // CONFIGMGR_DISPOSETIMER_HXX