Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / task.hxx
blob41c73bf39644688986fec4fd62de1772f54a930a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_TASK_HXX
21 #define INCLUDED_VCL_TASK_HXX
23 #include <vcl/dllapi.h>
25 struct ImplSchedulerData;
27 enum class TaskPriority
29 HIGHEST, ///< These events should run very fast!
30 DEFAULT, ///< Default priority used, e.g. the default timer priority
31 // Input from the OS event queue is processed before HIGH_IDLE tasks.
32 HIGH_IDLE, ///< Important idle events to be run before processing drawing events
33 RESIZE, ///< Resize runs before repaint, so we won't paint twice
34 REPAINT, ///< All repaint events should go in here
35 POST_PAINT, ///< Everything running directly after painting
36 DEFAULT_IDLE, ///< Default idle priority
37 LOWEST, ///< Low, very idle cleanup tasks
38 TOOLKIT_DEBUG ///< Do not use. Solely for IdleTask::waitUntilIdleDispatched
41 #define PRIO_COUNT (static_cast<int>(TaskPriority::TOOLKIT_DEBUG) + 1)
43 class VCL_DLLPUBLIC Task
45 friend class Scheduler;
46 friend struct ImplSchedulerData;
48 ImplSchedulerData *mpSchedulerData; ///< Pointer to the element in scheduler list
49 const char *mpDebugName; ///< Useful for debugging
50 TaskPriority mePriority; ///< Task priority
51 bool mbActive; ///< Currently in the scheduler
52 bool mbStatic; ///< Is a static object
54 protected:
55 static void StartTimer( sal_uInt64 nMS );
57 const ImplSchedulerData* GetSchedulerData() const { return mpSchedulerData; }
59 virtual void SetDeletionFlags();
61 /**
62 * How long (in MS) until the Task is ready to be dispatched?
64 * Simply return Scheduler::ImmediateTimeoutMs if you're ready, like an
65 * Idle. If you have to return Scheduler::InfiniteTimeoutMs, you probably
66 * need another mechanism to wake up the Scheduler or rely on other
67 * Tasks to be scheduled, or simply use a polling Timer.
69 * @param nTimeNow the current time
70 * @return the sleep time of the Task to become ready
72 virtual sal_uInt64 UpdateMinPeriod( sal_uInt64 nTimeNow ) const = 0;
74 public:
75 Task( const char *pDebugName );
76 Task( const Task& rTask );
77 virtual ~Task() COVERITY_NOEXCEPT_FALSE;
78 Task& operator=( const Task& rTask );
80 void SetPriority(TaskPriority ePriority);
81 TaskPriority GetPriority() const { return mePriority; }
83 const char *GetDebugName() const { return mpDebugName; }
85 // Call handler
86 virtual void Invoke() = 0;
88 /**
89 * Schedules the task for execution
91 * If the timer is already active, it's reset!
92 * Check with Task::IsActive() to prevent reset.
94 * If you unset bStartTimer, the Task must call Task::StartTimer(...) to be correctly scheduled!
95 * Otherwise it might just be picked up when the Scheduler runs the next time.
97 * @param bStartTimer if false, don't schedule the Task by calling Task::StartTimer(0).
99 virtual void Start(bool bStartTimer = true);
100 void Stop();
102 bool IsActive() const { return mbActive; }
105 * This function must be called for static tasks, so the Task destructor
106 * ignores the scheduler mutex, as it may not be available anymore.
107 * The cleanup is still correct, as it has already happened in
108 * DeInitScheduler call well before the static destructor calls.
110 void SetStatic() { mbStatic = true; }
111 bool IsStatic() const { return mbStatic; }
114 #endif // INCLUDED_VCL_TASK_HXX
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */