ProtectedTaskManager: derive from the Guard class
[xcsoar.git] / src / Task / ProtectedTaskManager.hpp
blobd4696b74e2101e838bb74f742b9280cdc0fe3693
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
6 M Roberts (original release)
7 Robin Birch <robinb@ruffnready.co.uk>
8 Samuel Gisiger <samuel.gisiger@triadis.ch>
9 Jeff Goodenough <jeff@enborne.f2s.com>
10 Alastair Harrison <aharrison@magic.force9.co.uk>
11 Scott Penrose <scottp@dd.com.au>
12 John Wharington <jwharington@gmail.com>
13 Lars H <lars_hn@hotmail.com>
14 Rob Dunning <rob@raspberryridgesheepfarm.com>
15 Russell King <rmk@arm.linux.org.uk>
16 Paolo Ventafridda <coolwind@email.it>
17 Tobias Lohner <tobias@lohner-net.de>
18 Mirek Jezek <mjezek@ipplc.cz>
19 Max Kellermann <max@duempel.org>
20 Tobias Bieniek <tobias.bieniek@gmx.de>
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License
24 as published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #ifndef XCSOAR_PROTECTED_TASK_MANAGER_HPP
39 #define XCSOAR_PROTECTED_TASK_MANAGER_HPP
41 #include "Thread/Guard.hpp"
42 #include "GlideSolvers/GlidePolar.hpp"
43 #include "Task/TaskManager.hpp"
44 #include "Task/TaskAdvance.hpp"
46 class TaskStats;
47 class CommonStats;
48 class RasterTerrain;
50 /**
51 * Facade to task/airspace/waypoints as used by threads,
52 * to manage locking
54 class ProtectedTaskManager : public Guard<TaskManager> {
55 protected:
56 const TaskBehaviour &task_behaviour;
57 TaskEvents &task_events;
58 GlidePolar glide_polar;
60 static const TCHAR default_task_path[];
62 public:
63 ProtectedTaskManager(TaskManager &_task_manager, const TaskBehaviour& tb,
64 TaskEvents& te)
65 :Guard<TaskManager>(_task_manager),
66 task_behaviour(tb), task_events(te),
67 glide_polar(_task_manager.get_glide_polar()) {}
69 // common accessors for ui and calc clients
70 GlidePolar get_glide_polar() const;
71 void set_glide_polar(const GlidePolar& glide_polar);
73 bool check_task() const;
74 TaskManager::TaskMode_t get_mode() const;
76 // trace points
77 TracePointVector find_trace_points(const GEOPOINT &loc,
78 const fixed range,
79 const unsigned mintime,
80 const fixed resolution) const;
82 void CAccept(TaskVisitor &visitor) const;
83 void ordered_CAccept(TaskVisitor &visitor) const;
84 const OrderedTaskBehaviour get_ordered_task_behaviour() const;
87 TaskAdvance::TaskAdvanceState_t get_advance_state() const;
89 GlidePolar get_safety_polar() const;
91 const Waypoint* getActiveWaypoint() const;
93 void incrementActiveTaskPoint(int offset);
95 bool do_goto(const Waypoint & wp);
97 AIRCRAFT_STATE get_start_state() const;
98 fixed get_finish_height() const;
100 const TracePointVector get_trace_points();
101 const TracePointVector get_olc_points();
103 bool check_ordered_task() const;
105 GEOPOINT get_task_center(const GEOPOINT& fallback_location) const;
106 fixed get_task_radius(const GEOPOINT& fallback_location) const;
108 // waypoints
109 bool read_waypoints(const RasterTerrain *terrain);
110 void save_waypoints();
111 void close_waypoints();
112 bool check_duplicate_waypoints(OrderedTask& ordered_task,
113 Waypoints &way_points);
116 OrderedTask* task_clone();
117 OrderedTask* task_blank();
120 * Copy task into this task
122 * @param other OrderedTask to copy
123 * @return True if this task changed
125 bool task_commit(const OrderedTask& that);
127 bool task_save(const TCHAR* path);
128 bool task_load(const TCHAR* path);
129 bool task_save_default();
130 bool task_load_default();
131 OrderedTask* task_copy(const OrderedTask& that);
132 OrderedTask* task_create(const TCHAR* path);
133 bool task_save(const TCHAR* path, const OrderedTask& task);
137 /** Reset the tasks (as if never flown) */
138 void reset();
140 bool update(const AIRCRAFT_STATE &state_now,
141 const AIRCRAFT_STATE &state_last);
143 bool update_idle(const AIRCRAFT_STATE &state);
145 bool update_auto_mc(const AIRCRAFT_STATE& state_now,
146 const fixed fallback_mc);
148 void set_task_behaviour(const TaskBehaviour& behaviour);
150 const TaskStats& get_stats() const;
151 const CommonStats& get_common_stats() const;
157 #endif