merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / treecache / cachewritescheduler.hxx
blob853802b38fa8550c2ffd4440a81df59f78a7a2fb
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: cachewritescheduler.hxx,v $
10 * $Revision: 1.7 $
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_CACHEWRITESCHEDULER_HXX
32 #define CONFIGMGR_CACHEWRITESCHEDULER_HXX
34 #include "datalock.hxx"
35 #include "requestoptions.hxx"
36 #include "timestamp.hxx"
37 #include "utility.hxx"
39 #ifndef INCLUDED_SET
40 #include <set>
41 #define INCLUDED_SET
42 #endif
43 #include <vos/timer.hxx>
44 #ifndef _VOS_REF_HXX_
45 #include <vos/ref.hxx>
47 #endif
48 #include <osl/mutex.hxx>
50 // -----------------------------------------------------------------------------
51 namespace configmgr
53 class RequestOptions;
54 namespace backend { class ComponentRequest; class CacheController; }
56 // Write down the Cache, much less complex than caching Nodes
57 // (better control)
58 class OCacheWriteScheduler
60 typedef std::set< RequestOptions, lessRequestOptions > CacheWriteList; // fire and forget!
62 class Timer : public vos::OTimer
64 public:
65 OCacheWriteScheduler* pParent;
67 Timer(OCacheWriteScheduler& _rParent) : pParent(&_rParent) {};
69 // vos::OTimer
70 virtual void SAL_CALL onShot();
72 // stop the scheduling
73 void dispose() {
74 stop();
75 pParent = NULL;
79 friend void Timer::onShot();
80 private:
81 vos::ORef<Timer> m_xTimer;
82 backend::CacheController &m_rTreeManager;
83 CacheWriteList m_aWriteList;
84 TimeInterval m_aWriteInterval;
86 public:
87 //-------- Construction and destruction -----------------------------------
88 explicit
89 OCacheWriteScheduler(backend::CacheController& _rTreeManager, TimeInterval const& _aWriteInterval)
90 : m_rTreeManager(_rTreeManager)
91 , m_aWriteInterval(_aWriteInterval)
93 m_xTimer = new Timer(*this);
95 ~OCacheWriteScheduler();
97 //-------- Delay and Interval ---------------------------------------------
98 /// retrieves the recurrance interval used for cleanup
99 TimeInterval const& getWriteInterval() const
101 UnoApiLock aLock;
102 return m_aWriteInterval;
105 static TimeStamp implGetScheduleTime(TimeStamp const& aBaseTime, TimeInterval const& aDelay)
107 return aBaseTime + aDelay;
109 //-------- Control of execution ------------------------------------------
110 void scheduleWrite(backend::ComponentRequest _aComponent) SAL_THROW((com::sun::star::uno::Exception));
112 /// stop pending activities for one set of options (do not discard them)
113 bool clearTasks(RequestOptions const& _xOptions);
115 /// stop and discard pending activities
116 void stopAndWriteCache();
117 private:
118 // vos::OTimer
119 void onTimerShot();
121 void runWriter();
122 void implStartBefore(TimeStamp const& _aTime);
123 void writeOneTreeFoundByOption(RequestOptions const& _aOption) SAL_THROW((com::sun::star::uno::Exception));
125 } // namespace configmgr
127 #endif // CONFIGMGR_DISPOSETIMER_HXX