Android release v6.7_preview1
[xcsoar.git] / src / Protection.cpp
blobc0280a5c2a00c018915c4efd58fafa76b125af67
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Protection.hpp"
25 #include "MainWindow.hpp"
26 #include "Gauge/GlueGaugeVario.hpp"
27 #include "Interface.hpp"
28 #include "Components.hpp"
29 #include "Computer/GlideComputer.hpp"
30 #include "CalculationThread.hpp"
31 #include "MergeThread.hpp"
32 #include "DrawThread.hpp"
33 #include "Blackboard/DeviceBlackboard.hpp"
35 #include <assert.h>
37 bool global_running;
39 void
40 TriggerMergeThread()
42 if (merge_thread != NULL)
43 merge_thread->Trigger();
46 /**
47 * Triggers a GPS update resulting in a run of the calculation thread
49 void
50 TriggerGPSUpdate()
52 if (calculation_thread == NULL)
53 return;
55 calculation_thread->Trigger();
58 void
59 ForceCalculation()
61 if (calculation_thread != NULL)
62 calculation_thread->ForceTrigger();
65 void
66 TriggerVarioUpdate()
68 assert(CommonInterface::main_window != NULL);
70 CommonInterface::main_window->SendGPSUpdate();
73 void
74 TriggerMapUpdate()
76 assert(CommonInterface::main_window != NULL);
78 CommonInterface::main_window->FullRedraw();
81 void
82 TriggerCalculatedUpdate()
84 assert(CommonInterface::main_window != NULL);
86 CommonInterface::main_window->SendCalculatedUpdate();
89 void
90 TriggerAirspaceWarning()
92 assert(CommonInterface::main_window != NULL);
94 CommonInterface::main_window->SendAirspaceWarning();
97 void
98 CreateCalculationThread()
100 assert(glide_computer != NULL);
102 /* copy settings to DeviceBlackboard */
103 device_blackboard->ReadComputerSettings(CommonInterface::GetComputerSettings());
105 /* create and run MergeThread, because GlideComputer's first
106 iteration depends on MergeThread's results */
107 merge_thread = new MergeThread(*device_blackboard);
108 merge_thread->FirstRun();
110 /* initialise the GlideComputer and run the first iteration */
111 glide_computer->ReadBlackboard(device_blackboard->Basic());
112 glide_computer->ReadComputerSettings(device_blackboard->GetComputerSettings());
113 glide_computer->ProcessGPS(true);
115 /* copy GlideComputer results to DeviceBlackboard */
116 device_blackboard->ReadBlackboard(glide_computer->Calculated());
118 calculation_thread = new CalculationThread(*glide_computer);
119 calculation_thread->SetComputerSettings(CommonInterface::GetComputerSettings());
122 void
123 SuspendAllThreads()
125 assert(CommonInterface::main_window != NULL);
126 assert(calculation_thread != NULL);
128 /* not suspending MergeThread, because it does not access shared
129 unprotected data structures */
131 CommonInterface::main_window->SuspendThreads();
132 calculation_thread->Suspend();
135 void
136 ResumeAllThreads()
138 assert(calculation_thread != NULL);
139 assert(CommonInterface::main_window != NULL);
141 calculation_thread->Resume();
142 CommonInterface::main_window->ResumeThreads();