TaskManager: allocate the task objects dynamically
[xcsoar.git] / src / Task / ProtectedTaskManager.hpp
blob2291877bde963b97ea618a3793cf6317de1565de
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef XCSOAR_PROTECTED_TASK_MANAGER_HPP
24 #define XCSOAR_PROTECTED_TASK_MANAGER_HPP
26 #include "Thread/Guard.hpp"
27 #include "Task/TaskManager.hpp"
28 #include "Engine/Task/Unordered/AbortIntersectionTest.hpp"
29 #include "Compiler.h"
31 #include <tchar.h>
33 class GlidePolar;
34 class RoutePlannerGlue;
35 struct RangeAndRadial;
37 class ReachIntersectionTest: public AbortIntersectionTest {
38 const RoutePlannerGlue *route;
40 public:
41 ReachIntersectionTest(): route(NULL) {};
43 void SetRoute(const RoutePlannerGlue *_route) {
44 route = _route;
47 virtual bool Intersects(const AGeoPoint& destination);
50 /**
51 * Facade to task/airspace/waypoints as used by threads,
52 * to manage locking
54 class ProtectedTaskManager: public Guard<TaskManager>
56 protected:
57 const TaskBehaviour &task_behaviour;
58 ReachIntersectionTest intersection_test;
60 static const TCHAR default_task_path[];
62 public:
63 ProtectedTaskManager(TaskManager &_task_manager, const TaskBehaviour &tb);
65 ~ProtectedTaskManager();
67 // common accessors for ui and calc clients
68 void SetGlidePolar(const GlidePolar &glide_polar);
70 gcc_pure
71 const OrderedTaskBehaviour GetOrderedTaskBehaviour() const;
73 gcc_pure
74 const Waypoint* GetActiveWaypoint() const;
76 void IncrementActiveTaskPoint(int offset);
77 void IncrementActiveTaskPointArm(int offset);
79 bool DoGoto(const Waypoint &wp);
81 gcc_pure
82 AircraftState GetStartState() const;
84 gcc_pure
85 fixed GetFinishHeight() const;
87 gcc_malloc
88 OrderedTask* TaskClone() const;
90 /**
91 * Copy task into this task
93 * @param other OrderedTask to copy
94 * @return True if this task changed
96 bool TaskCommit(const OrderedTask& that);
98 bool TaskSave(const TCHAR *path);
100 bool TaskSaveDefault();
103 * Creates an ordered task based on the Default.tsk file
104 * Consumer's responsibility to delete task
106 * @param waypoints waypoint structure
107 * @param failfactory default task type used if Default.tsk is invalid
108 * @return OrderedTask from Default.tsk file or if Default.tsk is invalid
109 * or non-existent, returns empty task with defaults set by
110 * config task defaults
112 gcc_malloc
113 OrderedTask* TaskCreateDefault(const Waypoints *waypoints,
114 TaskFactoryType factory);
116 bool TaskSave(const TCHAR* path, const OrderedTask& task);
118 /** Reset the tasks (as if never flown) */
119 void Reset();
122 * Lock/unlock the target from automatic shifts of specified tp
124 * @param index index of tp in task
125 * @param do_lock Whether to lock the target
127 bool TargetLock(const unsigned index, bool do_lock);
129 void SetRoutePlanner(const RoutePlannerGlue *_route);
131 short GetTerrainBase() const;
134 #endif