Update ooo320-m1
[ooovba.git] / configmgr / source / treecache / disposetimer.hxx
blobb9ee0583213fc7cac8689bf1c222398c6870f5f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: disposetimer.hxx,v $
10 * $Revision: 1.15 $
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
43 #include <utility>
44 #define INCLUDED_UTILITY
45 #endif
46 #ifndef INCLUDED_MAP
47 #include <map>
48 #define INCLUDED_MAP
49 #endif
51 namespace uno = ::com::sun::star::uno;
52 namespace lang = ::com::sun::star::lang;
54 namespace configmgr
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
68 public:
69 OTreeDisposeScheduler* pParent;
71 Timer(OTreeDisposeScheduler& _rParent) : pParent(&_rParent) {};
73 // vos::OTimer
74 virtual void SAL_CALL onShot();
76 // stop the scheduling
77 void dispose() {stop(); pParent = NULL;}
79 friend void Timer::onShot();
81 private:
82 Agenda m_aAgenda;
83 vos::ORef<Timer> m_xTimer;
84 backend::CacheController& m_rTreeManager;
86 TimeInterval m_aCleanupDelay;
87 TimeInterval m_aCleanupInterval;
88 public:
89 //-------- Construction and destruction -----------------------------------
90 explicit
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);
99 explicit
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();
149 private:
150 // vos::OTimer
151 void onTimerShot();
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);
159 private:
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